diff options
| author | jsing <> | 2021-03-02 17:18:59 +0000 |
|---|---|---|
| committer | jsing <> | 2021-03-02 17:18:59 +0000 |
| commit | 7258e56c7aa397acdb39abc4341acceea6ce9edf (patch) | |
| tree | 7b454f07d5571004ef0539e559f7d5f5fa7ca487 /src | |
| parent | 68b26162c65eb51eeaf4e0ac5a09f160cd4a51b0 (diff) | |
| download | openbsd-7258e56c7aa397acdb39abc4341acceea6ce9edf.tar.gz openbsd-7258e56c7aa397acdb39abc4341acceea6ce9edf.tar.bz2 openbsd-7258e56c7aa397acdb39abc4341acceea6ce9edf.zip | |
Move key/IV length checks closer to usage sites.
Also add explicit checks against EVP_CIPHER_iv_length() and
EVP_CIPHER_key_length().
Requested by tb@ during review.
ok tb@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libssl/tls12_record_layer.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/lib/libssl/tls12_record_layer.c b/src/lib/libssl/tls12_record_layer.c index d69370d025..a7bd4ce35b 100644 --- a/src/lib/libssl/tls12_record_layer.c +++ b/src/lib/libssl/tls12_record_layer.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls12_record_layer.c,v 1.20 2021/03/02 17:16:44 jsing Exp $ */ | 1 | /* $OpenBSD: tls12_record_layer.c,v 1.21 2021/03/02 17:18:59 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2020 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2020 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -425,11 +425,18 @@ tls12_record_layer_ccs_cipher(struct tls12_record_layer *rl, | |||
| 425 | int ret = 0; | 425 | int ret = 0; |
| 426 | 426 | ||
| 427 | if (!tls12_record_protection_unused(rp)) | 427 | if (!tls12_record_protection_unused(rp)) |
| 428 | return 0; | 428 | goto err; |
| 429 | 429 | ||
| 430 | mac_type = EVP_PKEY_HMAC; | 430 | mac_type = EVP_PKEY_HMAC; |
| 431 | rp->stream_mac = 0; | 431 | rp->stream_mac = 0; |
| 432 | 432 | ||
| 433 | if (iv_len > INT_MAX || key_len > INT_MAX) | ||
| 434 | goto err; | ||
| 435 | if (EVP_CIPHER_iv_length(rl->cipher) != iv_len) | ||
| 436 | goto err; | ||
| 437 | if (EVP_CIPHER_key_length(rl->cipher) != key_len) | ||
| 438 | goto err; | ||
| 439 | |||
| 433 | /* Special handling for GOST... */ | 440 | /* Special handling for GOST... */ |
| 434 | if (EVP_MD_type(rl->mac_hash) == NID_id_Gost28147_89_MAC) { | 441 | if (EVP_MD_type(rl->mac_hash) == NID_id_Gost28147_89_MAC) { |
| 435 | if (mac_key_len != 32) | 442 | if (mac_key_len != 32) |
| @@ -437,6 +444,8 @@ tls12_record_layer_ccs_cipher(struct tls12_record_layer *rl, | |||
| 437 | mac_type = EVP_PKEY_GOSTIMIT; | 444 | mac_type = EVP_PKEY_GOSTIMIT; |
| 438 | rp->stream_mac = 1; | 445 | rp->stream_mac = 1; |
| 439 | } else { | 446 | } else { |
| 447 | if (mac_key_len > INT_MAX) | ||
| 448 | goto err; | ||
| 440 | if (EVP_MD_size(rl->mac_hash) != mac_key_len) | 449 | if (EVP_MD_size(rl->mac_hash) != mac_key_len) |
| 441 | goto err; | 450 | goto err; |
| 442 | } | 451 | } |
| @@ -492,9 +501,6 @@ tls12_record_layer_change_cipher_state(struct tls12_record_layer *rl, | |||
| 492 | size_t mac_key_len, const uint8_t *key, size_t key_len, const uint8_t *iv, | 501 | size_t mac_key_len, const uint8_t *key, size_t key_len, const uint8_t *iv, |
| 493 | size_t iv_len) | 502 | size_t iv_len) |
| 494 | { | 503 | { |
| 495 | if (mac_key_len > INT_MAX || key_len > INT_MAX || iv_len > INT_MAX) | ||
| 496 | return 0; | ||
| 497 | |||
| 498 | if (rl->aead != NULL) | 504 | if (rl->aead != NULL) |
| 499 | return tls12_record_layer_ccs_aead(rl, rp, is_write, mac_key, | 505 | return tls12_record_layer_ccs_aead(rl, rp, is_write, mac_key, |
| 500 | mac_key_len, key, key_len, iv, iv_len); | 506 | mac_key_len, key, key_len, iv, iv_len); |
