Skip to content
Snippets Groups Projects
Commit 6fab8599 authored by rswindell's avatar rswindell
Browse files

Create and use is_crypt_initialized() - we can't call any cruptlib functions

(e.g. to query the version) until/unless the library has been successfully
initialized (and that could happen from the web server or the terminal/SSH
server or a secure service that uses TLS).
parent d3661e19
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,7 @@ static bool get_error_string(int status, CRYPT_SESSION sess, char estr[SSL_ESTR_
static pthread_once_t crypt_init_once = PTHREAD_ONCE_INIT;
static pthread_mutex_t ssl_cert_mutex;
static bool cryptlib_initialized;
static void do_cryptEnd(void)
{
......@@ -66,6 +67,7 @@ static void internal_do_cryptInit(void)
if((ret=cryptInit())==CRYPT_OK) {
cryptAddRandom(NULL,CRYPT_RANDOM_SLOWPOLL);
atexit(do_cryptEnd);
cryptlib_initialized = true;
}
else {
lprintf(LOG_ERR,"cryptInit() returned %d", ret);
......@@ -81,6 +83,11 @@ int DLLCALL do_cryptInit(void)
return 0;
}
bool DLLCALL is_crypt_initialized(void)
{
return cryptlib_initialized;
}
#define DO(x) get_error_string(x, ssl_context, estr, __FILE__, __LINE__)
CRYPT_CONTEXT DLLCALL get_ssl_cert(scfg_t *cfg, char estr[SSL_ESTR_LEN])
......
......@@ -4,6 +4,7 @@
#include "sbbs.h" // For DLLEXPORT
#include <cryptlib.h>
#include "scfgdefs.h"
#include <stdbool.h>
#ifdef DLLEXPORT
#undef DLLEXPORT
......@@ -38,6 +39,7 @@ DLLEXPORT char* DLLCALL get_crypt_attribute(CRYPT_SESSION sess, C_IN CRYPT_ATTRI
DLLEXPORT char* DLLCALL get_crypt_error(CRYPT_SESSION sess);
DLLEXPORT CRYPT_CONTEXT DLLCALL get_ssl_cert(scfg_t *cfg, char estr[SSL_ESTR_LEN]);
DLLEXPORT int DLLCALL do_cryptInit(void);
DLLEXPORT bool DLLCALL is_crypt_initialized(void);
#if defined(__cplusplus)
}
......
......@@ -37,6 +37,7 @@
****************************************************************************/
#include "sbbs.h"
#include "ssl.h"
const char* beta_version = " "; /* Space if non-beta, " beta" otherwise */
......@@ -109,7 +110,7 @@ void sbbs_t::ver()
socklib_version(str,SOCKLIB_DESC);
#ifdef USE_CRYPTLIB
{
if(is_crypt_initialized()) {
int cl_major=0, cl_minor=0, cl_step=0;
int result;
result = cryptGetAttribute(CRYPT_UNUSED, CRYPT_OPTION_INFO_MAJORVERSION, &cl_major);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment