forked from wolfSSL/wolfssl
use memset for 0,NULL defaults on CTX init
This commit is contained in:
100
src/internal.c
100
src/internal.c
@@ -353,40 +353,25 @@ void InitSSL_Method(WOLFSSL_METHOD* method, ProtocolVersion pv)
|
|||||||
/* Initialze SSL context, return 0 on success */
|
/* Initialze SSL context, return 0 on success */
|
||||||
int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method)
|
int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method)
|
||||||
{
|
{
|
||||||
ctx->method = method;
|
XMEMSET(ctx, 0, sizeof(WOLFSSL_CTX));
|
||||||
|
|
||||||
|
ctx->method = method;
|
||||||
ctx->refCount = 1; /* so either CTX_free or SSL_free can release */
|
ctx->refCount = 1; /* so either CTX_free or SSL_free can release */
|
||||||
#ifndef NO_CERTS
|
ctx->heap = ctx; /* defaults to self */
|
||||||
ctx->certificate.buffer = 0;
|
ctx->timeout = WOLFSSL_SESSION_TIMEOUT;
|
||||||
ctx->certChain.buffer = 0;
|
|
||||||
ctx->privateKey.buffer = 0;
|
ctx->partialWrite = 0;
|
||||||
ctx->serverDH_P.buffer = 0;
|
ctx->verifyCallback = 0;
|
||||||
ctx->serverDH_G.buffer = 0;
|
|
||||||
#endif
|
if (InitMutex(&ctx->countMutex) < 0) {
|
||||||
ctx->haveDH = 0;
|
WOLFSSL_MSG("Mutex error on CTX init");
|
||||||
ctx->haveNTRU = 0; /* start off */
|
return BAD_MUTEX_E;
|
||||||
ctx->haveECDSAsig = 0; /* start off */
|
}
|
||||||
ctx->haveStaticECC = 0; /* start off */
|
|
||||||
ctx->heap = ctx; /* defaults to self */
|
|
||||||
#ifndef NO_PSK
|
|
||||||
ctx->havePSK = 0;
|
|
||||||
ctx->server_hint[0] = 0;
|
|
||||||
ctx->client_psk_cb = 0;
|
|
||||||
ctx->server_psk_cb = 0;
|
|
||||||
#endif /* NO_PSK */
|
|
||||||
#ifdef HAVE_ANON
|
|
||||||
ctx->haveAnon = 0;
|
|
||||||
#endif /* HAVE_ANON */
|
|
||||||
#ifdef HAVE_ECC
|
#ifdef HAVE_ECC
|
||||||
ctx->eccTempKeySz = ECDHE_SIZE;
|
ctx->eccTempKeySz = ECDHE_SIZE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
|
|
||||||
ctx->passwd_cb = 0;
|
|
||||||
ctx->userdata = 0;
|
|
||||||
#endif /* OPENSSL_EXTRA */
|
|
||||||
|
|
||||||
ctx->timeout = WOLFSSL_SESSION_TIMEOUT;
|
|
||||||
|
|
||||||
#ifndef WOLFSSL_USER_IO
|
#ifndef WOLFSSL_USER_IO
|
||||||
ctx->CBIORecv = EmbedReceive;
|
ctx->CBIORecv = EmbedReceive;
|
||||||
ctx->CBIOSend = EmbedSend;
|
ctx->CBIOSend = EmbedSend;
|
||||||
@@ -397,24 +382,13 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method)
|
|||||||
ctx->CBIOCookie = EmbedGenerateCookie;
|
ctx->CBIOCookie = EmbedGenerateCookie;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
|
||||||
/* user will set */
|
|
||||||
ctx->CBIORecv = NULL;
|
|
||||||
ctx->CBIOSend = NULL;
|
|
||||||
#ifdef WOLFSSL_DTLS
|
|
||||||
ctx->CBIOCookie = NULL;
|
|
||||||
#endif
|
|
||||||
#endif /* WOLFSSL_USER_IO */
|
#endif /* WOLFSSL_USER_IO */
|
||||||
|
|
||||||
#ifdef HAVE_NETX
|
#ifdef HAVE_NETX
|
||||||
ctx->CBIORecv = NetX_Receive;
|
ctx->CBIORecv = NetX_Receive;
|
||||||
ctx->CBIOSend = NetX_Send;
|
ctx->CBIOSend = NetX_Send;
|
||||||
#endif
|
#endif
|
||||||
ctx->partialWrite = 0;
|
|
||||||
ctx->verifyCallback = 0;
|
|
||||||
|
|
||||||
#ifndef NO_CERTS
|
|
||||||
ctx->cm = wolfSSL_CertManagerNew();
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_NTRU
|
#ifdef HAVE_NTRU
|
||||||
if (method->side == WOLFSSL_CLIENT_END)
|
if (method->side == WOLFSSL_CLIENT_END)
|
||||||
ctx->haveNTRU = 1; /* always on cliet side */
|
ctx->haveNTRU = 1; /* always on cliet side */
|
||||||
@@ -426,51 +400,23 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method)
|
|||||||
ctx->haveStaticECC = 1; /* server can turn on by loading key */
|
ctx->haveStaticECC = 1; /* server can turn on by loading key */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
ctx->suites.setSuites = 0; /* user hasn't set yet */
|
|
||||||
/* remove DH later if server didn't set, add psk later */
|
|
||||||
InitSuites(&ctx->suites, method->version, TRUE, FALSE, TRUE, ctx->haveNTRU,
|
|
||||||
ctx->haveECDSAsig, ctx->haveStaticECC, method->side);
|
|
||||||
ctx->verifyPeer = 0;
|
|
||||||
ctx->verifyNone = 0;
|
|
||||||
ctx->failNoCert = 0;
|
|
||||||
ctx->sessionCacheOff = 0; /* initially on */
|
|
||||||
ctx->sessionCacheFlushOff = 0; /* initially on */
|
|
||||||
ctx->sendVerify = 0;
|
|
||||||
ctx->quietShutdown = 0;
|
|
||||||
ctx->groupMessages = 0;
|
|
||||||
#ifdef HAVE_CAVIUM
|
#ifdef HAVE_CAVIUM
|
||||||
ctx->devId = NO_CAVIUM_DEVICE;
|
ctx->devId = NO_CAVIUM_DEVICE;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_TLS_EXTENSIONS
|
|
||||||
ctx->extensions = NULL;
|
|
||||||
#endif
|
|
||||||
#ifdef ATOMIC_USER
|
|
||||||
ctx->MacEncryptCb = NULL;
|
|
||||||
ctx->DecryptVerifyCb = NULL;
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_PK_CALLBACKS
|
|
||||||
#ifdef HAVE_ECC
|
|
||||||
ctx->EccSignCb = NULL;
|
|
||||||
ctx->EccVerifyCb = NULL;
|
|
||||||
#endif /* HAVE_ECC */
|
|
||||||
#ifndef NO_RSA
|
|
||||||
ctx->RsaSignCb = NULL;
|
|
||||||
ctx->RsaVerifyCb = NULL;
|
|
||||||
ctx->RsaEncCb = NULL;
|
|
||||||
ctx->RsaDecCb = NULL;
|
|
||||||
#endif /* NO_RSA */
|
|
||||||
#endif /* HAVE_PK_CALLBACKS */
|
|
||||||
|
|
||||||
if (InitMutex(&ctx->countMutex) < 0) {
|
|
||||||
WOLFSSL_MSG("Mutex error on CTX init");
|
|
||||||
return BAD_MUTEX_E;
|
|
||||||
}
|
|
||||||
#ifndef NO_CERTS
|
#ifndef NO_CERTS
|
||||||
|
ctx->cm = wolfSSL_CertManagerNew();
|
||||||
if (ctx->cm == NULL) {
|
if (ctx->cm == NULL) {
|
||||||
WOLFSSL_MSG("Bad Cert Manager New");
|
WOLFSSL_MSG("Bad Cert Manager New");
|
||||||
return BAD_CERT_MANAGER_ERROR;
|
return BAD_CERT_MANAGER_ERROR;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* remove DH later if server didn't set, add psk later */
|
||||||
|
InitSuites(&ctx->suites, method->version, TRUE, FALSE, TRUE, ctx->haveNTRU,
|
||||||
|
ctx->haveECDSAsig, ctx->haveStaticECC, method->side);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user