mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
TLS: Fix unsigned int underflow in internal TLS 1.0/1.1 implementation
Taking sizeof(ptr) is incorrect to determine size of passed in hash and results in hlen getting set to a very large value since MD5_MAC_LEN > sizeof(ptr). Provide the actual size of the hash buffer from the caller to fix this. tls_key_x_server_params_hash() callers src/tls/tlsv1_client_read.c and src/tls/tlsv1_server_write.c both pass in a large enough hash (hash[64] or hash[100]) that this does not appear to have an impact, though it is still wrong. Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
This commit is contained in:
parent
b58dbf2808
commit
b3e4aae7bb
@ -776,7 +776,8 @@ static int tlsv1_process_diffie_hellman(struct tlsv1_client *conn,
|
|||||||
hlen = tls_key_x_server_params_hash(
|
hlen = tls_key_x_server_params_hash(
|
||||||
conn->rl.tls_version, conn->client_random,
|
conn->rl.tls_version, conn->client_random,
|
||||||
conn->server_random, server_params,
|
conn->server_random, server_params,
|
||||||
server_params_end - server_params, hash);
|
server_params_end - server_params, hash,
|
||||||
|
sizeof(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hlen < 0)
|
if (hlen < 0)
|
||||||
|
@ -380,7 +380,7 @@ int tlsv12_key_x_server_params_hash(u16 tls_version, u8 hash_alg,
|
|||||||
int tls_key_x_server_params_hash(u16 tls_version, const u8 *client_random,
|
int tls_key_x_server_params_hash(u16 tls_version, const u8 *client_random,
|
||||||
const u8 *server_random,
|
const u8 *server_random,
|
||||||
const u8 *server_params,
|
const u8 *server_params,
|
||||||
size_t server_params_len, u8 *hash)
|
size_t server_params_len, u8 *hash, size_t hsz)
|
||||||
{
|
{
|
||||||
u8 *hpos;
|
u8 *hpos;
|
||||||
size_t hlen;
|
size_t hlen;
|
||||||
@ -395,6 +395,8 @@ int tls_key_x_server_params_hash(u16 tls_version, const u8 *client_random,
|
|||||||
crypto_hash_update(ctx, server_random, TLS_RANDOM_LEN);
|
crypto_hash_update(ctx, server_random, TLS_RANDOM_LEN);
|
||||||
crypto_hash_update(ctx, server_params, server_params_len);
|
crypto_hash_update(ctx, server_params, server_params_len);
|
||||||
hlen = MD5_MAC_LEN;
|
hlen = MD5_MAC_LEN;
|
||||||
|
if (hsz < hlen)
|
||||||
|
return -1;
|
||||||
if (crypto_hash_finish(ctx, hash, &hlen) < 0)
|
if (crypto_hash_finish(ctx, hash, &hlen) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
hpos += hlen;
|
hpos += hlen;
|
||||||
@ -405,7 +407,7 @@ int tls_key_x_server_params_hash(u16 tls_version, const u8 *client_random,
|
|||||||
crypto_hash_update(ctx, client_random, TLS_RANDOM_LEN);
|
crypto_hash_update(ctx, client_random, TLS_RANDOM_LEN);
|
||||||
crypto_hash_update(ctx, server_random, TLS_RANDOM_LEN);
|
crypto_hash_update(ctx, server_random, TLS_RANDOM_LEN);
|
||||||
crypto_hash_update(ctx, server_params, server_params_len);
|
crypto_hash_update(ctx, server_params, server_params_len);
|
||||||
hlen = hash + sizeof(hash) - hpos;
|
hlen = hsz - hlen;
|
||||||
if (crypto_hash_finish(ctx, hpos, &hlen) < 0)
|
if (crypto_hash_finish(ctx, hpos, &hlen) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
hpos += hlen;
|
hpos += hlen;
|
||||||
|
@ -267,7 +267,8 @@ int tlsv12_key_x_server_params_hash(u16 tls_version, u8 hash_Alg,
|
|||||||
int tls_key_x_server_params_hash(u16 tls_version, const u8 *client_random,
|
int tls_key_x_server_params_hash(u16 tls_version, const u8 *client_random,
|
||||||
const u8 *server_random,
|
const u8 *server_random,
|
||||||
const u8 *server_params,
|
const u8 *server_params,
|
||||||
size_t server_params_len, u8 *hash);
|
size_t server_params_len,
|
||||||
|
u8 *hash, size_t hsz);
|
||||||
int tls_verify_signature(u16 tls_version, struct crypto_public_key *pk,
|
int tls_verify_signature(u16 tls_version, struct crypto_public_key *pk,
|
||||||
const u8 *data, size_t data_len,
|
const u8 *data, size_t data_len,
|
||||||
const u8 *pos, size_t len, u8 *alert);
|
const u8 *pos, size_t len, u8 *alert);
|
||||||
|
@ -620,7 +620,7 @@ static int tls_write_server_key_exchange(struct tlsv1_server *conn,
|
|||||||
hlen = tls_key_x_server_params_hash(
|
hlen = tls_key_x_server_params_hash(
|
||||||
conn->rl.tls_version, conn->client_random,
|
conn->rl.tls_version, conn->client_random,
|
||||||
conn->server_random, server_params,
|
conn->server_random, server_params,
|
||||||
pos - server_params, hash);
|
pos - server_params, hash, sizeof(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hlen < 0) {
|
if (hlen < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user