forked from wolfSSL/wolfssl
79
src/ssl.c
79
src/ssl.c
@@ -5451,11 +5451,10 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
|
||||
resetSuites = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
if (!rsaKey && !eccKey && !ed25519Key)
|
||||
return WOLFSSL_BAD_FILE;
|
||||
|
||||
#endif
|
||||
(void)ed25519Key;
|
||||
(void)devId;
|
||||
}
|
||||
@@ -7224,7 +7223,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_PUBKEY(WOLFSSL_EVP_PKEY** out, unsigned char** in,
|
||||
long inSz)
|
||||
{
|
||||
WOLFSSL_EVP_PKEY* pkey = NULL;
|
||||
const unsigned char* mem = *in;
|
||||
const unsigned char* mem;
|
||||
long memSz = inSz;
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_d2i_PUBKEY");
|
||||
@@ -7233,6 +7232,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_PUBKEY(WOLFSSL_EVP_PKEY** out, unsigned char** in,
|
||||
WOLFSSL_MSG("Bad argument");
|
||||
return NULL;
|
||||
}
|
||||
mem = *in;
|
||||
|
||||
#if !defined(NO_RSA)
|
||||
{
|
||||
@@ -7372,6 +7372,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_PrivateKey(int type, WOLFSSL_EVP_PKEY** out,
|
||||
if (local->pkey.ptr == NULL) {
|
||||
wolfSSL_EVP_PKEY_free(local);
|
||||
local = NULL;
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
XMEMCPY(local->pkey.ptr, *in + idx, inSz - idx);
|
||||
@@ -13594,8 +13595,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
const WOLFSSL_EVP_CIPHER* type, const byte* key,
|
||||
const byte* iv, int enc)
|
||||
{
|
||||
int ret = -1; /* failure local, during function 0 means success
|
||||
because internal functions work that way */
|
||||
int ret = 0;
|
||||
(void)key;
|
||||
(void)iv;
|
||||
(void)enc;
|
||||
@@ -13615,7 +13615,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
ctx->lastUsed = 0;
|
||||
ctx->flags = 0;
|
||||
}
|
||||
ret = 0;
|
||||
#ifndef NO_AES
|
||||
#ifdef HAVE_AES_CBC
|
||||
#ifdef WOLFSSL_AES_128
|
||||
@@ -13640,7 +13639,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_128 */
|
||||
#ifdef WOLFSSL_AES_192
|
||||
@@ -13665,7 +13663,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_192 */
|
||||
#ifdef WOLFSSL_AES_256
|
||||
@@ -13694,7 +13691,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_256 */
|
||||
#endif /* HAVE_AES_CBC */
|
||||
@@ -13721,7 +13717,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_128 */
|
||||
#ifdef WOLFSSL_AES_192
|
||||
@@ -13746,7 +13741,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_192 */
|
||||
#ifdef WOLFSSL_AES_256
|
||||
@@ -13771,7 +13765,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_256 */
|
||||
#endif /* WOLFSSL_AES_CTR */
|
||||
@@ -13792,7 +13785,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
}
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_128 */
|
||||
#ifdef WOLFSSL_AES_192
|
||||
@@ -13812,7 +13804,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
}
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_192 */
|
||||
#ifdef WOLFSSL_AES_256
|
||||
@@ -13832,7 +13823,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
}
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_256 */
|
||||
#endif /* NO_AES */
|
||||
@@ -13857,7 +13847,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
|
||||
if (iv && key == NULL)
|
||||
wc_Des_SetIV(&ctx->cipher.des, iv);
|
||||
ret = 0;
|
||||
}
|
||||
#ifdef WOLFSSL_DES_ECB
|
||||
else if (ctx->cipherType == DES_ECB_TYPE ||
|
||||
@@ -13877,7 +13866,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
#endif
|
||||
else if (ctx->cipherType == DES_EDE3_CBC_TYPE ||
|
||||
@@ -13903,7 +13891,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
else if (ctx->cipherType == DES_EDE3_ECB_TYPE ||
|
||||
(type &&
|
||||
@@ -13922,7 +13909,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* NO_DES3 */
|
||||
#ifndef NO_RC4
|
||||
@@ -13937,7 +13923,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
ctx->keyLen = 16; /* default to 128 */
|
||||
if (key)
|
||||
wc_Arc4SetKey(&ctx->cipher.arc4, key, ctx->keyLen);
|
||||
ret = 0; /* success */
|
||||
}
|
||||
#endif /* NO_RC4 */
|
||||
#ifdef HAVE_IDEA
|
||||
@@ -13961,7 +13946,6 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
|
||||
if (iv && key == NULL)
|
||||
wc_IdeaSetIV(&ctx->cipher.idea, iv);
|
||||
ret = 0;
|
||||
}
|
||||
#endif /* HAVE_IDEA */
|
||||
if (ctx->cipherType == NULL_CIPHER_TYPE || (type &&
|
||||
@@ -13970,13 +13954,9 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
ctx->cipherType = NULL_CIPHER_TYPE;
|
||||
ctx->keyLen = 0;
|
||||
ctx->block_size = 16;
|
||||
ret = 0; /* success */
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
return WOLFSSL_SUCCESS;
|
||||
else
|
||||
return 0; /* overall failure */
|
||||
(void)ret; /* remove warning. If execution reaches this point, ret=0 */
|
||||
return WOLFSSL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -14052,7 +14032,7 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
||||
case AES_192_CTR_TYPE :
|
||||
case AES_256_CTR_TYPE :
|
||||
WOLFSSL_MSG("AES CTR");
|
||||
wc_AesCtrEncrypt(&ctx->cipher.aes, dst, src, len);
|
||||
ret = wc_AesCtrEncrypt(&ctx->cipher.aes, dst, src, len);
|
||||
break;
|
||||
#endif /* WOLFSSL_AES_COUNTER */
|
||||
#endif /* NO_AES */
|
||||
@@ -16865,7 +16845,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_X509_get_pubkey(WOLFSSL_X509* x509)
|
||||
}
|
||||
|
||||
if (dataSz < 0) {
|
||||
sz = (int)XSTRLEN((const char*)data);
|
||||
sz = (int)XSTRLEN((const char*)data) + 1; /* +1 for null */
|
||||
}
|
||||
else {
|
||||
sz = dataSz;
|
||||
@@ -18345,7 +18325,7 @@ WC_PKCS12* wolfSSL_PKCS12_create(char* pass, char* name,
|
||||
{
|
||||
WC_PKCS12* pkcs12;
|
||||
WC_DerCertList* list = NULL;
|
||||
word32 passSz = (word32)XSTRLEN(pass);
|
||||
word32 passSz;
|
||||
byte* keyDer;
|
||||
word32 keyDerSz;
|
||||
byte* certDer;
|
||||
@@ -18359,6 +18339,7 @@ WC_PKCS12* wolfSSL_PKCS12_create(char* pass, char* name,
|
||||
WOLFSSL_LEAVE("wolfSSL_PKCS12_create()", BAD_FUNC_ARG);
|
||||
return NULL;
|
||||
}
|
||||
passSz = (word32)XSTRLEN(pass);
|
||||
|
||||
if ((ret = wolfSSL_i2d_PrivateKey(pkey, &keyDer)) < 0) {
|
||||
WOLFSSL_LEAVE("wolfSSL_PKCS12_create", ret);
|
||||
@@ -18387,7 +18368,7 @@ WC_PKCS12* wolfSSL_PKCS12_create(char* pass, char* name,
|
||||
}
|
||||
|
||||
curDer = (byte*)wolfSSL_X509_get_der(sk->data.x509, &curDerSz);
|
||||
if (certDer == NULL || curDerSz < 0) {
|
||||
if (curDer == NULL || curDerSz < 0) {
|
||||
XFREE(cur, NULL, DYNAMIC_TYPE_PKCS);
|
||||
wc_FreeCertList(list, NULL);
|
||||
return NULL;
|
||||
@@ -19580,7 +19561,7 @@ const char* wolfSSL_alert_desc_string_long(int alertID)
|
||||
*
|
||||
* ssl WOLFSSL structure to get state of
|
||||
*
|
||||
* Retruns a human readable string of the WOLFSSL structure state
|
||||
* Returns a human readable string of the WOLFSSL structure state
|
||||
*/
|
||||
const char* wolfSSL_state_string_long(const WOLFSSL* ssl)
|
||||
{
|
||||
@@ -21950,8 +21931,9 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
|
||||
|
||||
/* $RANDFILE was not set or is too large, check $HOME */
|
||||
if (rt == NULL) {
|
||||
WOLFSSL_MSG("Environment variable RANDFILE not set");
|
||||
if ((rt = XGETENV("HOME")) == NULL) {
|
||||
WOLFSSL_MSG("Unable to get HOME variable");
|
||||
WOLFSSL_MSG("Environment variable HOME not set");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -21962,16 +21944,11 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
|
||||
return fname;
|
||||
}
|
||||
else {
|
||||
WOLFSSL_MSG("Buffer too small");
|
||||
WOLFSSL_MSG("HOME too large for buffer");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (rt == NULL) {
|
||||
WOLFSSL_MSG("Enviroment variable RANDFILE or HOME not set");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fname;
|
||||
#else
|
||||
/* no filesystem defined */
|
||||
@@ -22066,7 +22043,7 @@ int wolfSSL_RAND_write_file(const char* fname)
|
||||
*
|
||||
* nm is the file path to the egd server
|
||||
*
|
||||
* Retruns the number of bytes read.
|
||||
* Returns the number of bytes read.
|
||||
*/
|
||||
int wolfSSL_RAND_egd(const char* nm)
|
||||
{
|
||||
@@ -22095,7 +22072,7 @@ int wolfSSL_RAND_egd(const char* nm)
|
||||
}
|
||||
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd <= 0) {
|
||||
if (fd < 0) {
|
||||
WOLFSSL_MSG("Error creating socket");
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
@@ -22104,7 +22081,7 @@ int wolfSSL_RAND_egd(const char* nm)
|
||||
}
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
rem.sun_family = AF_UNIX;
|
||||
XMEMCPY(rem.sun_path, nm, XSTRLEN(nm));
|
||||
XSTRNCPY(rem.sun_path, nm, sizeof(rem.sun_path));
|
||||
}
|
||||
|
||||
/* connect to egd server */
|
||||
@@ -25070,7 +25047,7 @@ int wolfSSL_RSA_verify(int type, const unsigned char* m,
|
||||
return WOLFSSL_FAILURE;
|
||||
}
|
||||
sigDec = (unsigned char *)XMALLOC(sigLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if(sigRet == NULL){
|
||||
if(sigDec == NULL){
|
||||
WOLFSSL_MSG("Memory failure");
|
||||
XFREE(sigRet, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
return WOLFSSL_FAILURE;
|
||||
@@ -25777,7 +25754,7 @@ void wolfSSL_aes_ctr_iv(WOLFSSL_EVP_CIPHER_CTX* ctx, int doset,
|
||||
}
|
||||
|
||||
if (doset)
|
||||
wc_AesSetIV(&ctx->cipher.aes, iv); /* OpenSSL compat, no ret */
|
||||
(void)wc_AesSetIV(&ctx->cipher.aes, iv); /* OpenSSL compat, no ret */
|
||||
else
|
||||
XMEMCPY(iv, &ctx->cipher.aes.reg, AES_BLOCK_SIZE);
|
||||
}
|
||||
@@ -29198,11 +29175,13 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl)
|
||||
i = XFTELL(bp->file);
|
||||
if (i < 0)
|
||||
return NULL;
|
||||
XFSEEK(bp->file, 0, SEEK_END);
|
||||
if (XFSEEK(bp->file, 0, SEEK_END) != 0)
|
||||
return NULL;
|
||||
l = XFTELL(bp->file);
|
||||
if (l < 0)
|
||||
return NULL;
|
||||
XFSEEK(bp->file, i, SEEK_SET);
|
||||
if (XFSEEK(bp->file, i, SEEK_SET) != 0)
|
||||
return NULL;
|
||||
#else
|
||||
WOLFSSL_MSG("Unable to read file with NO_FILESYSTEM defined");
|
||||
return NULL;
|
||||
@@ -29211,7 +29190,7 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl)
|
||||
else
|
||||
return NULL;
|
||||
|
||||
/* check calulated length */
|
||||
/* check calculated length */
|
||||
if (l - i < 0)
|
||||
return NULL;
|
||||
pem = (unsigned char*)XMALLOC(l - i, 0, DYNAMIC_TYPE_PEM);
|
||||
@@ -29227,8 +29206,8 @@ void* wolfSSL_GetDhAgreeCtx(WOLFSSL* ssl)
|
||||
if (i > 26 && XMEMCMP((char *)&pem[i-26], END_CERT, 25) == 0) {
|
||||
if (pem[i-1] == '\r') {
|
||||
/* found \r , Windows line ending is \r\n so try to read one
|
||||
* more byte for \n */
|
||||
wolfSSL_BIO_read(bp, (char *)&pem[i++], 1);
|
||||
* more byte for \n, ignoring return value */
|
||||
(void)wolfSSL_BIO_read(bp, (char *)&pem[i++], 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user