Ensure all EVP calls have their returns checked where appropriate
There are lots of calls to EVP functions from within libssl There were various places where we should probably check the return value but don't. This adds these checks. Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
@@ -2109,14 +2109,20 @@ int tls_construct_server_key_exchange(SSL *s)
|
||||
for (num = 2; num > 0; num--) {
|
||||
EVP_MD_CTX_set_flags(&md_ctx,
|
||||
EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
|
||||
EVP_DigestInit_ex(&md_ctx, (num == 2)
|
||||
? s->ctx->md5 : s->ctx->sha1, NULL);
|
||||
EVP_DigestUpdate(&md_ctx, &(s->s3->client_random[0]),
|
||||
SSL3_RANDOM_SIZE);
|
||||
EVP_DigestUpdate(&md_ctx, &(s->s3->server_random[0]),
|
||||
SSL3_RANDOM_SIZE);
|
||||
EVP_DigestUpdate(&md_ctx, d, n);
|
||||
EVP_DigestFinal_ex(&md_ctx, q, (unsigned int *)&i);
|
||||
if (EVP_DigestInit_ex(&md_ctx, (num == 2)
|
||||
? s->ctx->md5 : s->ctx->sha1, NULL) <= 0
|
||||
|| EVP_DigestUpdate(&md_ctx, &(s->s3->client_random[0]),
|
||||
SSL3_RANDOM_SIZE) <= 0
|
||||
|| EVP_DigestUpdate(&md_ctx, &(s->s3->server_random[0]),
|
||||
SSL3_RANDOM_SIZE) <= 0
|
||||
|| EVP_DigestUpdate(&md_ctx, d, n) <= 0
|
||||
|| EVP_DigestFinal_ex(&md_ctx, q,
|
||||
(unsigned int *)&i) <= 0) {
|
||||
SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,
|
||||
ERR_LIB_EVP);
|
||||
al = SSL_AD_INTERNAL_ERROR;
|
||||
goto f_err;
|
||||
}
|
||||
q += i;
|
||||
j += i;
|
||||
}
|
||||
@@ -2144,16 +2150,17 @@ int tls_construct_server_key_exchange(SSL *s)
|
||||
#ifdef SSL_DEBUG
|
||||
fprintf(stderr, "Using hash %s\n", EVP_MD_name(md));
|
||||
#endif
|
||||
EVP_SignInit_ex(&md_ctx, md, NULL);
|
||||
EVP_SignUpdate(&md_ctx, &(s->s3->client_random[0]),
|
||||
SSL3_RANDOM_SIZE);
|
||||
EVP_SignUpdate(&md_ctx, &(s->s3->server_random[0]),
|
||||
SSL3_RANDOM_SIZE);
|
||||
EVP_SignUpdate(&md_ctx, d, n);
|
||||
if (!EVP_SignFinal(&md_ctx, &(p[2]),
|
||||
(unsigned int *)&i, pkey)) {
|
||||
if (EVP_SignInit_ex(&md_ctx, md, NULL) <= 0
|
||||
|| EVP_SignUpdate(&md_ctx, &(s->s3->client_random[0]),
|
||||
SSL3_RANDOM_SIZE) <= 0
|
||||
|| EVP_SignUpdate(&md_ctx, &(s->s3->server_random[0]),
|
||||
SSL3_RANDOM_SIZE) <= 0
|
||||
|| EVP_SignUpdate(&md_ctx, d, n) <= 0
|
||||
|| EVP_SignFinal(&md_ctx, &(p[2]),
|
||||
(unsigned int *)&i, pkey) <= 0) {
|
||||
SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_LIB_EVP);
|
||||
goto err;
|
||||
al = SSL_AD_INTERNAL_ERROR;
|
||||
goto f_err;
|
||||
}
|
||||
s2n(i, p);
|
||||
n += i + 2;
|
||||
@@ -2812,7 +2819,11 @@ MSG_PROCESS_RETURN tls_process_client_key_exchange(SSL *s, PACKET *pkt)
|
||||
SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);
|
||||
goto f_err;
|
||||
}
|
||||
EVP_PKEY_decrypt_init(pkey_ctx);
|
||||
if (EVP_PKEY_decrypt_init(pkey_ctx) <= 0) {
|
||||
al = SSL_AD_INTERNAL_ERROR;
|
||||
SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
|
||||
goto f_err;
|
||||
}
|
||||
/*
|
||||
* If client certificate is present and is of the same type, maybe
|
||||
* use it for key exchange. Don't mind errors from
|
||||
@@ -2829,12 +2840,13 @@ MSG_PROCESS_RETURN tls_process_client_key_exchange(SSL *s, PACKET *pkt)
|
||||
if (!PACKET_get_bytes(pkt, &data, sess_key_len)) {
|
||||
al = SSL_AD_INTERNAL_ERROR;
|
||||
SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
|
||||
goto f_err;
|
||||
goto gerr;
|
||||
}
|
||||
if (ASN1_get_object ((const unsigned char **)&data, &Tlen, &Ttag,
|
||||
&Tclass, sess_key_len) != V_ASN1_CONSTRUCTED
|
||||
|| Ttag != V_ASN1_SEQUENCE
|
||||
|| Tclass != V_ASN1_UNIVERSAL) {
|
||||
al = SSL_AD_DECODE_ERROR;
|
||||
SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,
|
||||
SSL_R_DECRYPTION_FAILED);
|
||||
goto gerr;
|
||||
@@ -2852,7 +2864,7 @@ MSG_PROCESS_RETURN tls_process_client_key_exchange(SSL *s, PACKET *pkt)
|
||||
sizeof(premaster_secret), 0)) {
|
||||
al = SSL_AD_INTERNAL_ERROR;
|
||||
SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);
|
||||
goto f_err;
|
||||
goto gerr;
|
||||
}
|
||||
/* Check if pubkey from client certificate was used */
|
||||
if (EVP_PKEY_CTX_ctrl
|
||||
@@ -2865,7 +2877,7 @@ MSG_PROCESS_RETURN tls_process_client_key_exchange(SSL *s, PACKET *pkt)
|
||||
gerr:
|
||||
EVP_PKEY_free(client_pub_pkey);
|
||||
EVP_PKEY_CTX_free(pkey_ctx);
|
||||
goto err;
|
||||
goto f_err;
|
||||
} else {
|
||||
al = SSL_AD_HANDSHAKE_FAILURE;
|
||||
SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_UNKNOWN_CIPHER_TYPE);
|
||||
@@ -3150,7 +3162,11 @@ MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt)
|
||||
SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_MALLOC_FAILURE);
|
||||
goto f_err;
|
||||
}
|
||||
EVP_PKEY_verify_init(pctx);
|
||||
if (EVP_PKEY_verify_init(pctx) <= 0) {
|
||||
al = SSL_AD_INTERNAL_ERROR;
|
||||
SSLerr(SSL_F_TLS_PROCESS_CERT_VERIFY, ERR_R_INTERNAL_ERROR);
|
||||
goto f_err;
|
||||
}
|
||||
if (len != 64) {
|
||||
fprintf(stderr, "GOST signature length is %d", len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user