diff options
author | jsing <> | 2021-01-07 15:32:59 +0000 |
---|---|---|
committer | jsing <> | 2021-01-07 15:32:59 +0000 |
commit | a44b8f51b28515300b7d351485e371c07311a9f4 (patch) | |
tree | d58094850feafb23ea66396721d16b400c034196 | |
parent | 35e7c2f41633d153898933e5ba6cf0580ce70f26 (diff) | |
download | openbsd-a44b8f51b28515300b7d351485e371c07311a9f4.tar.gz openbsd-a44b8f51b28515300b7d351485e371c07311a9f4.tar.bz2 openbsd-a44b8f51b28515300b7d351485e371c07311a9f4.zip |
Move the read MAC key into the TLSv1.2 record layer.
ok inoguchi@ tb@
-rw-r--r-- | src/lib/libssl/ssl_both.c | 9 | ||||
-rw-r--r-- | src/lib/libssl/ssl_locl.h | 4 | ||||
-rw-r--r-- | src/lib/libssl/t1_enc.c | 9 | ||||
-rw-r--r-- | src/lib/libssl/tls12_record_layer.c | 21 |
4 files changed, 20 insertions, 23 deletions
diff --git a/src/lib/libssl/ssl_both.c b/src/lib/libssl/ssl_both.c index 6480b45bec..ee69f9a121 100644 --- a/src/lib/libssl/ssl_both.c +++ b/src/lib/libssl/ssl_both.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_both.c,v 1.22 2021/01/05 17:14:46 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_both.c,v 1.23 2021/01/07 15:32:59 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -301,13 +301,6 @@ f_err: | |||
301 | return (0); | 301 | return (0); |
302 | } | 302 | } |
303 | 303 | ||
304 | /* for these 2 messages, we need to | ||
305 | * ssl->enc_read_ctx re-init | ||
306 | * ssl->s3->internal->read_sequence zero | ||
307 | * ssl->s3->internal->read_mac_secret re-init | ||
308 | * ssl->session->read_sym_enc assign | ||
309 | * ssl->session->read_hash assign | ||
310 | */ | ||
311 | int | 304 | int |
312 | ssl3_send_change_cipher_spec(SSL *s, int a, int b) | 305 | ssl3_send_change_cipher_spec(SSL *s, int a, int b) |
313 | { | 306 | { |
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index 312c18f7ca..5c646d2208 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_locl.h,v 1.310 2020/12/15 16:04:49 tb Exp $ */ | 1 | /* $OpenBSD: ssl_locl.h,v 1.311 2021/01/07 15:32:59 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -833,8 +833,6 @@ typedef struct ssl3_buffer_internal_st { | |||
833 | 833 | ||
834 | typedef struct ssl3_state_internal_st { | 834 | typedef struct ssl3_state_internal_st { |
835 | unsigned char read_sequence[SSL3_SEQUENCE_SIZE]; | 835 | unsigned char read_sequence[SSL3_SEQUENCE_SIZE]; |
836 | int read_mac_secret_size; | ||
837 | unsigned char read_mac_secret[EVP_MAX_MD_SIZE]; | ||
838 | unsigned char write_sequence[SSL3_SEQUENCE_SIZE]; | 836 | unsigned char write_sequence[SSL3_SEQUENCE_SIZE]; |
839 | 837 | ||
840 | SSL3_BUFFER_INTERNAL rbuf; /* read IO goes into here */ | 838 | SSL3_BUFFER_INTERNAL rbuf; /* read IO goes into here */ |
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c index d451ad531c..6c376be2e0 100644 --- a/src/lib/libssl/t1_enc.c +++ b/src/lib/libssl/t1_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: t1_enc.c,v 1.127 2020/11/11 18:14:12 jsing Exp $ */ | 1 | /* $OpenBSD: t1_enc.c,v 1.128 2021/01/07 15:32:59 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -434,7 +434,7 @@ tls1_change_cipher_state_cipher(SSL *s, char is_read, | |||
434 | goto err; | 434 | goto err; |
435 | 435 | ||
436 | if (!tls12_record_layer_set_read_mac_key(s->internal->rl, | 436 | if (!tls12_record_layer_set_read_mac_key(s->internal->rl, |
437 | S3I(s)->read_mac_secret, mac_secret_size)) | 437 | mac_secret, mac_secret_size)) |
438 | goto err; | 438 | goto err; |
439 | } else { | 439 | } else { |
440 | /* | 440 | /* |
@@ -565,11 +565,6 @@ tls1_change_cipher_state(SSL *s, int which) | |||
565 | goto err2; | 565 | goto err2; |
566 | } | 566 | } |
567 | 567 | ||
568 | if (is_read) { | ||
569 | memcpy(S3I(s)->read_mac_secret, mac_secret, mac_secret_size); | ||
570 | S3I(s)->read_mac_secret_size = mac_secret_size; | ||
571 | } | ||
572 | |||
573 | if (aead != NULL) { | 568 | if (aead != NULL) { |
574 | return tls1_change_cipher_state_aead(s, is_read, key, key_len, | 569 | return tls1_change_cipher_state_aead(s, is_read, key, key_len, |
575 | iv, iv_len); | 570 | iv, iv_len); |
diff --git a/src/lib/libssl/tls12_record_layer.c b/src/lib/libssl/tls12_record_layer.c index 56ff94d95c..32e3fcc813 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.5 2020/10/03 17:35:17 jsing Exp $ */ | 1 | /* $OpenBSD: tls12_record_layer.c,v 1.6 2021/01/07 15:32: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 | * |
@@ -33,6 +33,9 @@ struct tls12_record_layer { | |||
33 | int read_stream_mac; | 33 | int read_stream_mac; |
34 | int write_stream_mac; | 34 | int write_stream_mac; |
35 | 35 | ||
36 | uint8_t *read_mac_key; | ||
37 | size_t read_mac_key_len; | ||
38 | |||
36 | /* | 39 | /* |
37 | * XXX - for now these are just pointers to externally managed | 40 | * XXX - for now these are just pointers to externally managed |
38 | * structs/memory. These should eventually be owned by the record layer. | 41 | * structs/memory. These should eventually be owned by the record layer. |
@@ -45,9 +48,6 @@ struct tls12_record_layer { | |||
45 | EVP_CIPHER_CTX *write_cipher_ctx; | 48 | EVP_CIPHER_CTX *write_cipher_ctx; |
46 | EVP_MD_CTX *write_hash_ctx; | 49 | EVP_MD_CTX *write_hash_ctx; |
47 | 50 | ||
48 | const uint8_t *read_mac_key; | ||
49 | size_t read_mac_key_len; | ||
50 | |||
51 | uint8_t *read_seq_num; | 51 | uint8_t *read_seq_num; |
52 | uint8_t *write_seq_num; | 52 | uint8_t *write_seq_num; |
53 | }; | 53 | }; |
@@ -66,6 +66,7 @@ tls12_record_layer_new(void) | |||
66 | void | 66 | void |
67 | tls12_record_layer_free(struct tls12_record_layer *rl) | 67 | tls12_record_layer_free(struct tls12_record_layer *rl) |
68 | { | 68 | { |
69 | freezero(rl->read_mac_key, rl->read_mac_key_len); | ||
69 | freezero(rl, sizeof(struct tls12_record_layer)); | 70 | freezero(rl, sizeof(struct tls12_record_layer)); |
70 | } | 71 | } |
71 | 72 | ||
@@ -189,7 +190,17 @@ int | |||
189 | tls12_record_layer_set_read_mac_key(struct tls12_record_layer *rl, | 190 | tls12_record_layer_set_read_mac_key(struct tls12_record_layer *rl, |
190 | const uint8_t *mac_key, size_t mac_key_len) | 191 | const uint8_t *mac_key, size_t mac_key_len) |
191 | { | 192 | { |
192 | rl->read_mac_key = mac_key; | 193 | freezero(rl->read_mac_key, rl->read_mac_key_len); |
194 | rl->read_mac_key = NULL; | ||
195 | rl->read_mac_key_len = 0; | ||
196 | |||
197 | if (mac_key == NULL || mac_key_len == 0) | ||
198 | return 1; | ||
199 | |||
200 | if ((rl->read_mac_key = calloc(1, mac_key_len)) == NULL) | ||
201 | return 0; | ||
202 | |||
203 | memcpy(rl->read_mac_key, mac_key, mac_key_len); | ||
193 | rl->read_mac_key_len = mac_key_len; | 204 | rl->read_mac_key_len = mac_key_len; |
194 | 205 | ||
195 | return 1; | 206 | return 1; |