diff options
author | tb <> | 2020-01-22 02:39:45 +0000 |
---|---|---|
committer | tb <> | 2020-01-22 02:39:45 +0000 |
commit | e841f2e08f8bcc62f31051874b1b2a491665e7c6 (patch) | |
tree | e3b7e917f86898f6c4c09cc95fd58779cf635a2f | |
parent | e42a9af6bede5e8c30f66cf9013f858a29caed3e (diff) | |
download | openbsd-e841f2e08f8bcc62f31051874b1b2a491665e7c6.tar.gz openbsd-e841f2e08f8bcc62f31051874b1b2a491665e7c6.tar.bz2 openbsd-e841f2e08f8bcc62f31051874b1b2a491665e7c6.zip |
The legacy_record_version must be set to TLS1_2_VERSION except
in the ClientHello where it may be set to TLS1_VERSION. Use
the minimal supported version to decide whether we choose to do
so or not. Use a sent hook to set it back TLS1_2_VERSION right
after the ClientHello message is on the wire.
ok beck jsing
-rw-r--r-- | src/lib/libssl/tls13_client.c | 13 | ||||
-rw-r--r-- | src/lib/libssl/tls13_handshake.c | 3 | ||||
-rw-r--r-- | src/lib/libssl/tls13_internal.h | 5 | ||||
-rw-r--r-- | src/lib/libssl/tls13_record_layer.c | 18 |
4 files changed, 30 insertions, 9 deletions
diff --git a/src/lib/libssl/tls13_client.c b/src/lib/libssl/tls13_client.c index ed9a69918a..e0041eadae 100644 --- a/src/lib/libssl/tls13_client.c +++ b/src/lib/libssl/tls13_client.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_client.c,v 1.23 2020/01/22 02:21:05 beck Exp $ */ | 1 | /* $OpenBSD: tls13_client.c,v 1.24 2020/01/22 02:39:45 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -199,6 +199,9 @@ tls13_client_hello_send(struct tls13_ctx *ctx) | |||
199 | { | 199 | { |
200 | CBB body; | 200 | CBB body; |
201 | 201 | ||
202 | if (ctx->hs->min_version < TLS1_2_VERSION) | ||
203 | tls13_record_layer_set_legacy_version(ctx->rl, TLS1_VERSION); | ||
204 | |||
202 | if (!tls13_handshake_msg_start(ctx->hs_msg, &body, TLS13_MT_CLIENT_HELLO)) | 205 | if (!tls13_handshake_msg_start(ctx->hs_msg, &body, TLS13_MT_CLIENT_HELLO)) |
203 | return 0; | 206 | return 0; |
204 | if (!tls13_client_hello_build(ctx->ssl, &body)) | 207 | if (!tls13_client_hello_build(ctx->ssl, &body)) |
@@ -209,6 +212,14 @@ tls13_client_hello_send(struct tls13_ctx *ctx) | |||
209 | return 1; | 212 | return 1; |
210 | } | 213 | } |
211 | 214 | ||
215 | int | ||
216 | tls13_client_hello_sent(struct tls13_ctx *ctx) | ||
217 | { | ||
218 | tls13_record_layer_set_legacy_version(ctx->rl, TLS1_2_VERSION); | ||
219 | |||
220 | return 1; | ||
221 | } | ||
222 | |||
212 | /* | 223 | /* |
213 | * HelloRetryRequest hash - RFC 8446 section 4.1.3. | 224 | * HelloRetryRequest hash - RFC 8446 section 4.1.3. |
214 | */ | 225 | */ |
diff --git a/src/lib/libssl/tls13_handshake.c b/src/lib/libssl/tls13_handshake.c index 48a01d3ca4..ca36f879b4 100644 --- a/src/lib/libssl/tls13_handshake.c +++ b/src/lib/libssl/tls13_handshake.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_handshake.c,v 1.38 2020/01/21 03:40:05 beck Exp $ */ | 1 | /* $OpenBSD: tls13_handshake.c,v 1.39 2020/01/22 02:39:45 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org> | 3 | * Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org> |
4 | * Copyright (c) 2019 Joel Sing <jsing@openbsd.org> | 4 | * Copyright (c) 2019 Joel Sing <jsing@openbsd.org> |
@@ -53,6 +53,7 @@ struct tls13_handshake_action state_machine[] = { | |||
53 | .handshake_type = TLS13_MT_CLIENT_HELLO, | 53 | .handshake_type = TLS13_MT_CLIENT_HELLO, |
54 | .sender = TLS13_HS_CLIENT, | 54 | .sender = TLS13_HS_CLIENT, |
55 | .send = tls13_client_hello_send, | 55 | .send = tls13_client_hello_send, |
56 | .sent = tls13_client_hello_sent, | ||
56 | .recv = tls13_client_hello_recv, | 57 | .recv = tls13_client_hello_recv, |
57 | }, | 58 | }, |
58 | [CLIENT_HELLO_RETRY] = { | 59 | [CLIENT_HELLO_RETRY] = { |
diff --git a/src/lib/libssl/tls13_internal.h b/src/lib/libssl/tls13_internal.h index 167ed1f254..1eb05b7100 100644 --- a/src/lib/libssl/tls13_internal.h +++ b/src/lib/libssl/tls13_internal.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_internal.h,v 1.41 2020/01/22 02:21:05 beck Exp $ */ | 1 | /* $OpenBSD: tls13_internal.h,v 1.42 2020/01/22 02:39:45 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2018 Bob Beck <beck@openbsd.org> |
4 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> |
@@ -122,6 +122,8 @@ void tls13_record_layer_set_aead(struct tls13_record_layer *rl, | |||
122 | const EVP_AEAD *aead); | 122 | const EVP_AEAD *aead); |
123 | void tls13_record_layer_set_hash(struct tls13_record_layer *rl, | 123 | void tls13_record_layer_set_hash(struct tls13_record_layer *rl, |
124 | const EVP_MD *hash); | 124 | const EVP_MD *hash); |
125 | void tls13_record_layer_set_legacy_version(struct tls13_record_layer *rl, | ||
126 | uint16_t version); | ||
125 | void tls13_record_layer_handshake_completed(struct tls13_record_layer *rl); | 127 | void tls13_record_layer_handshake_completed(struct tls13_record_layer *rl); |
126 | int tls13_record_layer_set_read_traffic_key(struct tls13_record_layer *rl, | 128 | int tls13_record_layer_set_read_traffic_key(struct tls13_record_layer *rl, |
127 | struct tls13_secret *read_key); | 129 | struct tls13_secret *read_key); |
@@ -253,6 +255,7 @@ int tls13_legacy_shutdown(SSL *ssl); | |||
253 | int tls13_handshake_perform(struct tls13_ctx *ctx); | 255 | int tls13_handshake_perform(struct tls13_ctx *ctx); |
254 | 256 | ||
255 | int tls13_client_hello_send(struct tls13_ctx *ctx); | 257 | int tls13_client_hello_send(struct tls13_ctx *ctx); |
258 | int tls13_client_hello_sent(struct tls13_ctx *ctx); | ||
256 | int tls13_client_hello_recv(struct tls13_ctx *ctx); | 259 | int tls13_client_hello_recv(struct tls13_ctx *ctx); |
257 | int tls13_client_hello_retry_send(struct tls13_ctx *ctx); | 260 | int tls13_client_hello_retry_send(struct tls13_ctx *ctx); |
258 | int tls13_client_hello_retry_recv(struct tls13_ctx *ctx); | 261 | int tls13_client_hello_retry_recv(struct tls13_ctx *ctx); |
diff --git a/src/lib/libssl/tls13_record_layer.c b/src/lib/libssl/tls13_record_layer.c index dff5cd2bbe..600990a878 100644 --- a/src/lib/libssl/tls13_record_layer.c +++ b/src/lib/libssl/tls13_record_layer.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_record_layer.c,v 1.19 2020/01/22 01:02:28 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_record_layer.c,v 1.20 2020/01/22 02:39:45 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -28,6 +28,7 @@ static ssize_t tls13_record_layer_write_record(struct tls13_record_layer *rl, | |||
28 | uint8_t content_type, const uint8_t *content, size_t content_len); | 28 | uint8_t content_type, const uint8_t *content, size_t content_len); |
29 | 29 | ||
30 | struct tls13_record_layer { | 30 | struct tls13_record_layer { |
31 | uint16_t legacy_version; | ||
31 | int change_cipher_spec_seen; | 32 | int change_cipher_spec_seen; |
32 | int handshake_completed; | 33 | int handshake_completed; |
33 | int phh; | 34 | int phh; |
@@ -124,6 +125,8 @@ tls13_record_layer_new(tls13_read_cb wire_read, tls13_write_cb wire_write, | |||
124 | if ((rl = calloc(1, sizeof(struct tls13_record_layer))) == NULL) | 125 | if ((rl = calloc(1, sizeof(struct tls13_record_layer))) == NULL) |
125 | return NULL; | 126 | return NULL; |
126 | 127 | ||
128 | rl->legacy_version = TLS1_2_VERSION; | ||
129 | |||
127 | rl->wire_read = wire_read; | 130 | rl->wire_read = wire_read; |
128 | rl->wire_write = wire_write; | 131 | rl->wire_write = wire_write; |
129 | rl->alert_cb = alert_cb; | 132 | rl->alert_cb = alert_cb; |
@@ -211,6 +214,13 @@ tls13_record_layer_set_hash(struct tls13_record_layer *rl, | |||
211 | } | 214 | } |
212 | 215 | ||
213 | void | 216 | void |
217 | tls13_record_layer_set_legacy_version(struct tls13_record_layer *rl, | ||
218 | uint16_t version) | ||
219 | { | ||
220 | rl->legacy_version = version; | ||
221 | } | ||
222 | |||
223 | void | ||
214 | tls13_record_layer_handshake_completed(struct tls13_record_layer *rl) | 224 | tls13_record_layer_handshake_completed(struct tls13_record_layer *rl) |
215 | { | 225 | { |
216 | rl->handshake_completed = 1; | 226 | rl->handshake_completed = 1; |
@@ -563,15 +573,11 @@ tls13_record_layer_seal_record_plaintext(struct tls13_record_layer *rl, | |||
563 | { | 573 | { |
564 | uint8_t *data = NULL; | 574 | uint8_t *data = NULL; |
565 | size_t data_len = 0; | 575 | size_t data_len = 0; |
566 | uint16_t version; | ||
567 | CBB cbb, body; | 576 | CBB cbb, body; |
568 | 577 | ||
569 | if (rl->aead != NULL) | 578 | if (rl->aead != NULL) |
570 | return 0; | 579 | return 0; |
571 | 580 | ||
572 | /* XXX - TLS1_VERSION for first client hello... */ | ||
573 | version = TLS1_2_VERSION; | ||
574 | |||
575 | /* | 581 | /* |
576 | * We're still operating in plaintext mode, so just copy the | 582 | * We're still operating in plaintext mode, so just copy the |
577 | * content into the record. | 583 | * content into the record. |
@@ -581,7 +587,7 @@ tls13_record_layer_seal_record_plaintext(struct tls13_record_layer *rl, | |||
581 | 587 | ||
582 | if (!CBB_add_u8(&cbb, content_type)) | 588 | if (!CBB_add_u8(&cbb, content_type)) |
583 | goto err; | 589 | goto err; |
584 | if (!CBB_add_u16(&cbb, version)) | 590 | if (!CBB_add_u16(&cbb, rl->legacy_version)) |
585 | goto err; | 591 | goto err; |
586 | if (!CBB_add_u16_length_prefixed(&cbb, &body)) | 592 | if (!CBB_add_u16_length_prefixed(&cbb, &body)) |
587 | goto err; | 593 | goto err; |