fix wolfSSL_Init to only call new wolfCrypt_Init() once

This commit is contained in:
toddouska
2015-11-02 12:35:43 -08:00
parent a1d1155b0c
commit 54a0a3370a
4 changed files with 37 additions and 26 deletions

View File

@@ -159,8 +159,15 @@ WOLFSSL_CTX* wolfSSL_CTX_new(WOLFSSL_METHOD* method)
WOLFSSL_ENTER("WOLFSSL_CTX_new"); WOLFSSL_ENTER("WOLFSSL_CTX_new");
if (initRefCount == 0) if (initRefCount == 0) {
wolfSSL_Init(); /* user no longer forced to call Init themselves */ /* user no longer forced to call Init themselves */
int ret = wolfSSL_Init();
if (ret != SSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_Init failed");
WOLFSSL_LEAVE("WOLFSSL_CTX_new", 0);
return NULL;
}
}
if (method == NULL) if (method == NULL)
return ctx; return ctx;
@@ -2337,33 +2344,35 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, buffer der, int type, int verify)
int wolfSSL_Init(void) int wolfSSL_Init(void)
{ {
int ret = SSL_SUCCESS;
WOLFSSL_ENTER("wolfSSL_Init"); WOLFSSL_ENTER("wolfSSL_Init");
if (initRefCount == 0) { if (initRefCount == 0) {
/* Initialize crypto for use with TLS connection */
if (wolfCrypt_Init() != 0) {
WOLFSSL_MSG("Bad wolfCrypt Init");
return WC_INIT_E;
}
#ifndef NO_SESSION_CACHE #ifndef NO_SESSION_CACHE
if (InitMutex(&session_mutex) != 0) if (InitMutex(&session_mutex) != 0) {
ret = BAD_MUTEX_E; WOLFSSL_MSG("Bad Init Mutex session");
#endif return BAD_MUTEX_E;
if (InitMutex(&count_mutex) != 0) }
ret = BAD_MUTEX_E; #endif
} if (InitMutex(&count_mutex) != 0) {
if (ret == SSL_SUCCESS) { WOLFSSL_MSG("Bad Init Mutex count");
if (LockMutex(&count_mutex) != 0) {
WOLFSSL_MSG("Bad Lock Mutex count");
return BAD_MUTEX_E; return BAD_MUTEX_E;
} }
/* Initialize crypto for use with TLS connection */
if (wolfcrypt_Init() != 0)
ret = WC_INIT_E;
initRefCount++;
UnLockMutex(&count_mutex);
} }
return ret; if (LockMutex(&count_mutex) != 0) {
WOLFSSL_MSG("Bad Lock Mutex count");
return BAD_MUTEX_E;
}
initRefCount++;
UnLockMutex(&count_mutex);
return SSL_SUCCESS;
} }
@@ -7352,8 +7361,10 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
int wolfSSL_add_all_algorithms(void) int wolfSSL_add_all_algorithms(void)
{ {
WOLFSSL_ENTER("wolfSSL_add_all_algorithms"); WOLFSSL_ENTER("wolfSSL_add_all_algorithms");
wolfSSL_Init(); if (wolfSSL_Init() == SSL_SUCCESS)
return SSL_SUCCESS; return SSL_SUCCESS;
else
return SSL_FATAL_ERROR;
} }

View File

@@ -244,7 +244,7 @@ int benchmark_test(void *args)
{ {
#endif #endif
wolfcrypt_Init(); wolfCrypt_Init();
#if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND) #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
wolfSSL_Debugging_ON(); wolfSSL_Debugging_ON();

View File

@@ -43,7 +43,7 @@
/* Used to initialize state for wolfcrypt /* Used to initialize state for wolfcrypt
return 0 on success return 0 on success
*/ */
int wolfcrypt_Init() int wolfCrypt_Init()
{ {
#if WOLFSSL_CRYPT_HW_MUTEX #if WOLFSSL_CRYPT_HW_MUTEX
/* If crypto hardware mutex protection is enabled, then initialize it */ /* If crypto hardware mutex protection is enabled, then initialize it */

View File

@@ -170,7 +170,7 @@ WOLFSSL_LOCAL int LockMutex(wolfSSL_Mutex*);
WOLFSSL_LOCAL int UnLockMutex(wolfSSL_Mutex*); WOLFSSL_LOCAL int UnLockMutex(wolfSSL_Mutex*);
/* main crypto initialization function */ /* main crypto initialization function */
WOLFSSL_API int wolfcrypt_Init(void); WOLFSSL_API int wolfCrypt_Init(void);
/* filesystem abstraction layer, used by ssl.c */ /* filesystem abstraction layer, used by ssl.c */
#ifndef NO_FILESYSTEM #ifndef NO_FILESYSTEM