diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libssl/ssl_clnt.c | 20 | ||||
-rw-r--r-- | src/lib/libssl/ssl_locl.h | 26 | ||||
-rw-r--r-- | src/lib/libssl/ssl_pkt.c | 7 | ||||
-rw-r--r-- | src/lib/libssl/ssl_sigalgs.c | 8 | ||||
-rw-r--r-- | src/lib/libssl/ssl_srvr.c | 21 | ||||
-rw-r--r-- | src/lib/libssl/ssl_tlsext.c | 116 | ||||
-rw-r--r-- | src/lib/libssl/ssl_versions.c | 26 | ||||
-rw-r--r-- | src/lib/libssl/tls13_client.c | 20 | ||||
-rw-r--r-- | src/lib/libssl/tls13_server.c | 9 |
9 files changed, 145 insertions, 108 deletions
diff --git a/src/lib/libssl/ssl_clnt.c b/src/lib/libssl/ssl_clnt.c index 70bda982c6..97418f1ac7 100644 --- a/src/lib/libssl/ssl_clnt.c +++ b/src/lib/libssl/ssl_clnt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_clnt.c,v 1.84 2021/02/22 15:59:10 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_clnt.c,v 1.85 2021/03/10 18:27:01 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 | * |
@@ -218,7 +218,14 @@ ssl3_connect(SSL *s) | |||
218 | goto end; | 218 | goto end; |
219 | } | 219 | } |
220 | 220 | ||
221 | /* s->version=SSL3_VERSION; */ | 221 | if (!ssl_supported_tls_version_range(s, |
222 | &S3I(s)->hs.our_min_tls_version, | ||
223 | &S3I(s)->hs.our_max_tls_version)) { | ||
224 | SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE); | ||
225 | ret = -1; | ||
226 | goto end; | ||
227 | } | ||
228 | |||
222 | s->internal->type = SSL_ST_CONNECT; | 229 | s->internal->type = SSL_ST_CONNECT; |
223 | 230 | ||
224 | if (!ssl3_setup_init_buffer(s)) { | 231 | if (!ssl3_setup_init_buffer(s)) { |
@@ -904,6 +911,12 @@ ssl3_get_server_hello(SSL *s) | |||
904 | } | 911 | } |
905 | s->version = server_version; | 912 | s->version = server_version; |
906 | 913 | ||
914 | S3I(s)->hs.negotiated_tls_version = ssl_tls_version(server_version); | ||
915 | if (S3I(s)->hs.negotiated_tls_version == 0) { | ||
916 | SSLerror(s, ERR_R_INTERNAL_ERROR); | ||
917 | goto err; | ||
918 | } | ||
919 | |||
907 | if ((method = ssl_get_method(server_version)) == NULL) { | 920 | if ((method = ssl_get_method(server_version)) == NULL) { |
908 | SSLerror(s, ERR_R_INTERNAL_ERROR); | 921 | SSLerror(s, ERR_R_INTERNAL_ERROR); |
909 | goto err; | 922 | goto err; |
@@ -1019,7 +1032,7 @@ ssl3_get_server_hello(SSL *s) | |||
1019 | 1032 | ||
1020 | /* TLS v1.2 only ciphersuites require v1.2 or later. */ | 1033 | /* TLS v1.2 only ciphersuites require v1.2 or later. */ |
1021 | if ((cipher->algorithm_ssl & SSL_TLSV1_2) && | 1034 | if ((cipher->algorithm_ssl & SSL_TLSV1_2) && |
1022 | (TLS1_get_version(s) < TLS1_2_VERSION)) { | 1035 | S3I(s)->hs.negotiated_tls_version < TLS1_2_VERSION) { |
1023 | al = SSL_AD_ILLEGAL_PARAMETER; | 1036 | al = SSL_AD_ILLEGAL_PARAMETER; |
1024 | SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED); | 1037 | SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED); |
1025 | goto fatal_err; | 1038 | goto fatal_err; |
@@ -1982,6 +1995,7 @@ ssl3_send_client_kex_rsa(SSL *s, SESS_CERT *sess_cert, CBB *cbb) | |||
1982 | goto err; | 1995 | goto err; |
1983 | } | 1996 | } |
1984 | 1997 | ||
1998 | /* XXX - our max protocol version. */ | ||
1985 | pms[0] = s->client_version >> 8; | 1999 | pms[0] = s->client_version >> 8; |
1986 | pms[1] = s->client_version & 0xff; | 2000 | pms[1] = s->client_version & 0xff; |
1987 | arc4random_buf(&pms[2], sizeof(pms) - 2); | 2001 | arc4random_buf(&pms[2], sizeof(pms) - 2); |
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index b2af8fd7c9..6f66a8932e 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.324 2021/02/27 14:20:50 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_locl.h,v 1.325 2021/03/10 18:27:01 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 | * |
@@ -407,6 +407,23 @@ typedef struct ssl_session_internal_st { | |||
407 | #define SSI(s) (s->session->internal) | 407 | #define SSI(s) (s->session->internal) |
408 | 408 | ||
409 | typedef struct ssl_handshake_st { | 409 | typedef struct ssl_handshake_st { |
410 | /* | ||
411 | * Minimum and maximum versions supported for this handshake. These are | ||
412 | * initialised at the start of a handshake based on the method in use | ||
413 | * and the current protocol version configuration. | ||
414 | */ | ||
415 | uint16_t our_min_tls_version; | ||
416 | uint16_t our_max_tls_version; | ||
417 | |||
418 | /* | ||
419 | * Version negotiated for this session. For a client this is set once | ||
420 | * the server selected version is parsed from the ServerHello (either | ||
421 | * from the legacy version or supported versions extension). For a | ||
422 | * server this is set once we select the version we will use with the | ||
423 | * client. | ||
424 | */ | ||
425 | uint16_t negotiated_tls_version; | ||
426 | |||
410 | /* state contains one of the SSL3_ST_* values. */ | 427 | /* state contains one of the SSL3_ST_* values. */ |
411 | int state; | 428 | int state; |
412 | 429 | ||
@@ -435,10 +452,6 @@ typedef struct cert_pkey_st { | |||
435 | } CERT_PKEY; | 452 | } CERT_PKEY; |
436 | 453 | ||
437 | typedef struct ssl_handshake_tls13_st { | 454 | typedef struct ssl_handshake_tls13_st { |
438 | uint16_t min_version; | ||
439 | uint16_t max_version; | ||
440 | uint16_t version; | ||
441 | |||
442 | int use_legacy; | 455 | int use_legacy; |
443 | int hrr; | 456 | int hrr; |
444 | 457 | ||
@@ -468,7 +481,6 @@ typedef struct ssl_handshake_tls13_st { | |||
468 | EVP_MD_CTX *clienthello_md_ctx; | 481 | EVP_MD_CTX *clienthello_md_ctx; |
469 | unsigned char *clienthello_hash; | 482 | unsigned char *clienthello_hash; |
470 | unsigned int clienthello_hash_len; | 483 | unsigned int clienthello_hash_len; |
471 | |||
472 | } SSL_HANDSHAKE_TLS13; | 484 | } SSL_HANDSHAKE_TLS13; |
473 | 485 | ||
474 | struct tls12_record_layer; | 486 | struct tls12_record_layer; |
@@ -1117,6 +1129,8 @@ int ssl_version_set_max(const SSL_METHOD *meth, uint16_t proto_ver, | |||
1117 | uint16_t min_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver); | 1129 | uint16_t min_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver); |
1118 | int ssl_enabled_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver); | 1130 | int ssl_enabled_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver); |
1119 | int ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver); | 1131 | int ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver); |
1132 | uint16_t ssl_tls_version(uint16_t version); | ||
1133 | uint16_t ssl_effective_tls_version(SSL *s); | ||
1120 | int ssl_downgrade_max_version(SSL *s, uint16_t *max_ver); | 1134 | int ssl_downgrade_max_version(SSL *s, uint16_t *max_ver); |
1121 | int ssl_max_supported_version(SSL *s, uint16_t *max_ver); | 1135 | int ssl_max_supported_version(SSL *s, uint16_t *max_ver); |
1122 | int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver); | 1136 | int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver); |
diff --git a/src/lib/libssl/ssl_pkt.c b/src/lib/libssl/ssl_pkt.c index 894064c817..5b1af504fb 100644 --- a/src/lib/libssl/ssl_pkt.c +++ b/src/lib/libssl/ssl_pkt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_pkt.c,v 1.36 2021/02/20 14:14:16 tb Exp $ */ | 1 | /* $OpenBSD: ssl_pkt.c,v 1.37 2021/03/10 18:27:02 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 | * |
@@ -561,8 +561,9 @@ do_ssl3_write(SSL *s, int type, const unsigned char *buf, unsigned int len) | |||
561 | * bytes and record version number > TLS 1.0. | 561 | * bytes and record version number > TLS 1.0. |
562 | */ | 562 | */ |
563 | version = s->version; | 563 | version = s->version; |
564 | if (S3I(s)->hs.state == SSL3_ST_CW_CLNT_HELLO_B && !s->internal->renegotiate && | 564 | if (S3I(s)->hs.state == SSL3_ST_CW_CLNT_HELLO_B && |
565 | TLS1_get_version(s) > TLS1_VERSION) | 565 | !s->internal->renegotiate && |
566 | S3I(s)->hs.our_max_tls_version > TLS1_VERSION) | ||
566 | version = TLS1_VERSION; | 567 | version = TLS1_VERSION; |
567 | 568 | ||
568 | /* | 569 | /* |
diff --git a/src/lib/libssl/ssl_sigalgs.c b/src/lib/libssl/ssl_sigalgs.c index 1b5aad72f7..68bb6a3889 100644 --- a/src/lib/libssl/ssl_sigalgs.c +++ b/src/lib/libssl/ssl_sigalgs.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_sigalgs.c,v 1.22 2020/10/11 01:13:04 guenther Exp $ */ | 1 | /* $OpenBSD: ssl_sigalgs.c,v 1.23 2021/03/10 18:27:02 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018-2020 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2018-2020 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -265,7 +265,7 @@ ssl_sigalg_select(SSL *s, EVP_PKEY *pkey) | |||
265 | int check_curve = 0; | 265 | int check_curve = 0; |
266 | CBS cbs; | 266 | CBS cbs; |
267 | 267 | ||
268 | if (TLS1_get_version(s) >= TLS1_3_VERSION) { | 268 | if (S3I(s)->hs.negotiated_tls_version >= TLS1_3_VERSION) { |
269 | tls_sigalgs = tls13_sigalgs; | 269 | tls_sigalgs = tls13_sigalgs; |
270 | tls_sigalgs_len = tls13_sigalgs_len; | 270 | tls_sigalgs_len = tls13_sigalgs_len; |
271 | check_curve = 1; | 271 | check_curve = 1; |
@@ -291,7 +291,7 @@ ssl_sigalg_select(SSL *s, EVP_PKEY *pkey) | |||
291 | * RFC 5246 allows a TLS 1.2 client to send no sigalgs, in | 291 | * RFC 5246 allows a TLS 1.2 client to send no sigalgs, in |
292 | * which case the server must use the the default. | 292 | * which case the server must use the the default. |
293 | */ | 293 | */ |
294 | if (TLS1_get_version(s) < TLS1_3_VERSION && | 294 | if (S3I(s)->hs.negotiated_tls_version < TLS1_3_VERSION && |
295 | S3I(s)->hs.sigalgs == NULL) { | 295 | S3I(s)->hs.sigalgs == NULL) { |
296 | switch (pkey->type) { | 296 | switch (pkey->type) { |
297 | case EVP_PKEY_RSA: | 297 | case EVP_PKEY_RSA: |
@@ -323,7 +323,7 @@ ssl_sigalg_select(SSL *s, EVP_PKEY *pkey) | |||
323 | continue; | 323 | continue; |
324 | 324 | ||
325 | /* RSA cannot be used without PSS in TLSv1.3. */ | 325 | /* RSA cannot be used without PSS in TLSv1.3. */ |
326 | if (TLS1_get_version(s) >= TLS1_3_VERSION && | 326 | if (S3I(s)->hs.negotiated_tls_version >= TLS1_3_VERSION && |
327 | sigalg->key_type == EVP_PKEY_RSA && | 327 | sigalg->key_type == EVP_PKEY_RSA && |
328 | (sigalg->flags & SIGALG_FLAG_RSA_PSS) == 0) | 328 | (sigalg->flags & SIGALG_FLAG_RSA_PSS) == 0) |
329 | continue; | 329 | continue; |
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c index be9c27f73f..373a20d61b 100644 --- a/src/lib/libssl/ssl_srvr.c +++ b/src/lib/libssl/ssl_srvr.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_srvr.c,v 1.95 2021/02/20 14:16:56 tb Exp $ */ | 1 | /* $OpenBSD: ssl_srvr.c,v 1.96 2021/03/10 18:27:02 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 | * |
@@ -219,6 +219,14 @@ ssl3_accept(SSL *s) | |||
219 | goto end; | 219 | goto end; |
220 | } | 220 | } |
221 | 221 | ||
222 | if (!ssl_supported_tls_version_range(s, | ||
223 | &S3I(s)->hs.our_min_tls_version, | ||
224 | &S3I(s)->hs.our_max_tls_version)) { | ||
225 | SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE); | ||
226 | ret = -1; | ||
227 | goto end; | ||
228 | } | ||
229 | |||
222 | s->internal->type = SSL_ST_ACCEPT; | 230 | s->internal->type = SSL_ST_ACCEPT; |
223 | 231 | ||
224 | if (!ssl3_setup_init_buffer(s)) { | 232 | if (!ssl3_setup_init_buffer(s)) { |
@@ -844,7 +852,7 @@ ssl3_get_client_hello(SSL *s) | |||
844 | */ | 852 | */ |
845 | if (!ssl_downgrade_max_version(s, &max_version)) | 853 | if (!ssl_downgrade_max_version(s, &max_version)) |
846 | goto err; | 854 | goto err; |
847 | if (ssl_max_shared_version(s, client_version, &shared_version) != 1) { | 855 | if (!ssl_max_shared_version(s, client_version, &shared_version)) { |
848 | if ((s->client_version >> 8) == SSL3_VERSION_MAJOR && | 856 | if ((s->client_version >> 8) == SSL3_VERSION_MAJOR && |
849 | !tls12_record_layer_write_protected(s->internal->rl)) { | 857 | !tls12_record_layer_write_protected(s->internal->rl)) { |
850 | /* | 858 | /* |
@@ -860,6 +868,12 @@ ssl3_get_client_hello(SSL *s) | |||
860 | s->client_version = client_version; | 868 | s->client_version = client_version; |
861 | s->version = shared_version; | 869 | s->version = shared_version; |
862 | 870 | ||
871 | S3I(s)->hs.negotiated_tls_version = ssl_tls_version(shared_version); | ||
872 | if (S3I(s)->hs.negotiated_tls_version == 0) { | ||
873 | SSLerror(s, ERR_R_INTERNAL_ERROR); | ||
874 | goto err; | ||
875 | } | ||
876 | |||
863 | if ((method = ssl_get_method(shared_version)) == NULL) { | 877 | if ((method = ssl_get_method(shared_version)) == NULL) { |
864 | SSLerror(s, ERR_R_INTERNAL_ERROR); | 878 | SSLerror(s, ERR_R_INTERNAL_ERROR); |
865 | goto err; | 879 | goto err; |
@@ -1718,6 +1732,8 @@ ssl3_get_client_kex_rsa(SSL *s, CBS *cbs) | |||
1718 | int al = -1; | 1732 | int al = -1; |
1719 | 1733 | ||
1720 | arc4random_buf(fakekey, sizeof(fakekey)); | 1734 | arc4random_buf(fakekey, sizeof(fakekey)); |
1735 | |||
1736 | /* XXX - peer max protocol version. */ | ||
1721 | fakekey[0] = s->client_version >> 8; | 1737 | fakekey[0] = s->client_version >> 8; |
1722 | fakekey[1] = s->client_version & 0xff; | 1738 | fakekey[1] = s->client_version & 0xff; |
1723 | 1739 | ||
@@ -1754,6 +1770,7 @@ ssl3_get_client_kex_rsa(SSL *s, CBS *cbs) | |||
1754 | /* SSLerror(s, SSL_R_BAD_RSA_DECRYPT); */ | 1770 | /* SSLerror(s, SSL_R_BAD_RSA_DECRYPT); */ |
1755 | } | 1771 | } |
1756 | 1772 | ||
1773 | /* XXX - peer max version. */ | ||
1757 | if ((al == -1) && !((pms[0] == (s->client_version >> 8)) && | 1774 | if ((al == -1) && !((pms[0] == (s->client_version >> 8)) && |
1758 | (pms[1] == (s->client_version & 0xff)))) { | 1775 | (pms[1] == (s->client_version & 0xff)))) { |
1759 | /* | 1776 | /* |
diff --git a/src/lib/libssl/ssl_tlsext.c b/src/lib/libssl/ssl_tlsext.c index dca9de0305..4f4a39d4bb 100644 --- a/src/lib/libssl/ssl_tlsext.c +++ b/src/lib/libssl/ssl_tlsext.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_tlsext.c,v 1.86 2021/02/08 17:20:47 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_tlsext.c,v 1.87 2021/03/10 18:27:02 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2016, 2017, 2019 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2016, 2017, 2019 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> | 4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> |
@@ -174,7 +174,7 @@ int | |||
174 | tlsext_supportedgroups_client_needs(SSL *s, uint16_t msg_type) | 174 | tlsext_supportedgroups_client_needs(SSL *s, uint16_t msg_type) |
175 | { | 175 | { |
176 | return ssl_has_ecc_ciphers(s) || | 176 | return ssl_has_ecc_ciphers(s) || |
177 | (S3I(s)->hs_tls13.max_version >= TLS1_3_VERSION); | 177 | (S3I(s)->hs.our_max_tls_version >= TLS1_3_VERSION); |
178 | } | 178 | } |
179 | 179 | ||
180 | int | 180 | int |
@@ -472,7 +472,8 @@ tlsext_ri_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
472 | int | 472 | int |
473 | tlsext_ri_server_needs(SSL *s, uint16_t msg_type) | 473 | tlsext_ri_server_needs(SSL *s, uint16_t msg_type) |
474 | { | 474 | { |
475 | return (s->version < TLS1_3_VERSION && S3I(s)->send_connection_binding); | 475 | return (S3I(s)->hs.negotiated_tls_version < TLS1_3_VERSION && |
476 | S3I(s)->send_connection_binding); | ||
476 | } | 477 | } |
477 | 478 | ||
478 | int | 479 | int |
@@ -554,7 +555,7 @@ tlsext_ri_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
554 | int | 555 | int |
555 | tlsext_sigalgs_client_needs(SSL *s, uint16_t msg_type) | 556 | tlsext_sigalgs_client_needs(SSL *s, uint16_t msg_type) |
556 | { | 557 | { |
557 | return (TLS1_get_client_version(s) >= TLS1_2_VERSION); | 558 | return (S3I(s)->hs.our_max_tls_version >= TLS1_2_VERSION); |
558 | } | 559 | } |
559 | 560 | ||
560 | int | 561 | int |
@@ -564,8 +565,7 @@ tlsext_sigalgs_client_build(SSL *s, uint16_t msg_type, CBB *cbb) | |||
564 | size_t tls_sigalgs_len = tls12_sigalgs_len; | 565 | size_t tls_sigalgs_len = tls12_sigalgs_len; |
565 | CBB sigalgs; | 566 | CBB sigalgs; |
566 | 567 | ||
567 | if (TLS1_get_client_version(s) >= TLS1_3_VERSION && | 568 | if (S3I(s)->hs.our_min_tls_version >= TLS1_3_VERSION) { |
568 | S3I(s)->hs_tls13.min_version >= TLS1_3_VERSION) { | ||
569 | tls_sigalgs = tls13_sigalgs; | 569 | tls_sigalgs = tls13_sigalgs; |
570 | tls_sigalgs_len = tls13_sigalgs_len; | 570 | tls_sigalgs_len = tls13_sigalgs_len; |
571 | } | 571 | } |
@@ -600,7 +600,7 @@ tlsext_sigalgs_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
600 | int | 600 | int |
601 | tlsext_sigalgs_server_needs(SSL *s, uint16_t msg_type) | 601 | tlsext_sigalgs_server_needs(SSL *s, uint16_t msg_type) |
602 | { | 602 | { |
603 | return (s->version >= TLS1_3_VERSION); | 603 | return (S3I(s)->hs.negotiated_tls_version >= TLS1_3_VERSION); |
604 | } | 604 | } |
605 | 605 | ||
606 | int | 606 | int |
@@ -610,7 +610,7 @@ tlsext_sigalgs_server_build(SSL *s, uint16_t msg_type, CBB *cbb) | |||
610 | size_t tls_sigalgs_len = tls12_sigalgs_len; | 610 | size_t tls_sigalgs_len = tls12_sigalgs_len; |
611 | CBB sigalgs; | 611 | CBB sigalgs; |
612 | 612 | ||
613 | if (s->version >= TLS1_3_VERSION) { | 613 | if (S3I(s)->hs.negotiated_tls_version >= TLS1_3_VERSION) { |
614 | tls_sigalgs = tls13_sigalgs; | 614 | tls_sigalgs = tls13_sigalgs; |
615 | tls_sigalgs_len = tls13_sigalgs_len; | 615 | tls_sigalgs_len = tls13_sigalgs_len; |
616 | } | 616 | } |
@@ -632,7 +632,7 @@ tlsext_sigalgs_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
632 | { | 632 | { |
633 | CBS sigalgs; | 633 | CBS sigalgs; |
634 | 634 | ||
635 | if (s->version < TLS1_3_VERSION) | 635 | if (ssl_effective_tls_version(s) < TLS1_3_VERSION) |
636 | return 0; | 636 | return 0; |
637 | 637 | ||
638 | if (!CBS_get_u16_length_prefixed(cbs, &sigalgs)) | 638 | if (!CBS_get_u16_length_prefixed(cbs, &sigalgs)) |
@@ -981,7 +981,7 @@ tlsext_ocsp_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
981 | int | 981 | int |
982 | tlsext_ocsp_server_needs(SSL *s, uint16_t msg_type) | 982 | tlsext_ocsp_server_needs(SSL *s, uint16_t msg_type) |
983 | { | 983 | { |
984 | if (s->version >= TLS1_3_VERSION && | 984 | if (S3I(s)->hs.negotiated_tls_version >= TLS1_3_VERSION && |
985 | s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp && | 985 | s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp && |
986 | s->ctx->internal->tlsext_status_cb != NULL) { | 986 | s->ctx->internal->tlsext_status_cb != NULL) { |
987 | s->internal->tlsext_status_expected = 0; | 987 | s->internal->tlsext_status_expected = 0; |
@@ -998,7 +998,7 @@ tlsext_ocsp_server_build(SSL *s, uint16_t msg_type, CBB *cbb) | |||
998 | { | 998 | { |
999 | CBB ocsp_response; | 999 | CBB ocsp_response; |
1000 | 1000 | ||
1001 | if (s->version >= TLS1_3_VERSION) { | 1001 | if (S3I(s)->hs.negotiated_tls_version >= TLS1_3_VERSION) { |
1002 | if (!CBB_add_u8(cbb, TLSEXT_STATUSTYPE_ocsp)) | 1002 | if (!CBB_add_u8(cbb, TLSEXT_STATUSTYPE_ocsp)) |
1003 | return 0; | 1003 | return 0; |
1004 | if (!CBB_add_u24_length_prefixed(cbb, &ocsp_response)) | 1004 | if (!CBB_add_u24_length_prefixed(cbb, &ocsp_response)) |
@@ -1016,11 +1016,10 @@ tlsext_ocsp_server_build(SSL *s, uint16_t msg_type, CBB *cbb) | |||
1016 | int | 1016 | int |
1017 | tlsext_ocsp_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | 1017 | tlsext_ocsp_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) |
1018 | { | 1018 | { |
1019 | CBS response; | ||
1020 | uint16_t version = TLS1_get_client_version(s); | ||
1021 | uint8_t status_type; | 1019 | uint8_t status_type; |
1020 | CBS response; | ||
1022 | 1021 | ||
1023 | if (version >= TLS1_3_VERSION) { | 1022 | if (ssl_effective_tls_version(s) >= TLS1_3_VERSION) { |
1024 | if (msg_type == SSL_TLSEXT_MSG_CR) { | 1023 | if (msg_type == SSL_TLSEXT_MSG_CR) { |
1025 | /* | 1024 | /* |
1026 | * RFC 8446, 4.4.2.1 - the server may request an OCSP | 1025 | * RFC 8446, 4.4.2.1 - the server may request an OCSP |
@@ -1406,11 +1405,7 @@ tlsext_srtp_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1406 | int | 1405 | int |
1407 | tlsext_keyshare_client_needs(SSL *s, uint16_t msg_type) | 1406 | tlsext_keyshare_client_needs(SSL *s, uint16_t msg_type) |
1408 | { | 1407 | { |
1409 | /* XXX once this gets initialized when we get tls13_client.c */ | 1408 | return (S3I(s)->hs.our_max_tls_version >= TLS1_3_VERSION); |
1410 | if (S3I(s)->hs_tls13.max_version == 0) | ||
1411 | return 0; | ||
1412 | return (!SSL_is_dtls(s) && S3I(s)->hs_tls13.max_version >= | ||
1413 | TLS1_3_VERSION); | ||
1414 | } | 1409 | } |
1415 | 1410 | ||
1416 | int | 1411 | int |
@@ -1457,7 +1452,7 @@ tlsext_keyshare_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1457 | * Ignore this client share if we're using earlier than TLSv1.3 | 1452 | * Ignore this client share if we're using earlier than TLSv1.3 |
1458 | * or we've already selected a key share. | 1453 | * or we've already selected a key share. |
1459 | */ | 1454 | */ |
1460 | if (S3I(s)->hs_tls13.max_version < TLS1_3_VERSION) | 1455 | if (S3I(s)->hs.our_max_tls_version < TLS1_3_VERSION) |
1461 | continue; | 1456 | continue; |
1462 | if (S3I(s)->hs_tls13.key_share != NULL) | 1457 | if (S3I(s)->hs_tls13.key_share != NULL) |
1463 | continue; | 1458 | continue; |
@@ -1485,10 +1480,8 @@ tlsext_keyshare_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1485 | int | 1480 | int |
1486 | tlsext_keyshare_server_needs(SSL *s, uint16_t msg_type) | 1481 | tlsext_keyshare_server_needs(SSL *s, uint16_t msg_type) |
1487 | { | 1482 | { |
1488 | if (SSL_is_dtls(s) || s->version < TLS1_3_VERSION) | 1483 | return (S3I(s)->hs.negotiated_tls_version >= TLS1_3_VERSION && |
1489 | return 0; | 1484 | tlsext_extension_seen(s, TLSEXT_TYPE_key_share)); |
1490 | |||
1491 | return tlsext_extension_seen(s, TLSEXT_TYPE_key_share); | ||
1492 | } | 1485 | } |
1493 | 1486 | ||
1494 | int | 1487 | int |
@@ -1550,9 +1543,7 @@ tlsext_keyshare_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1550 | int | 1543 | int |
1551 | tlsext_versions_client_needs(SSL *s, uint16_t msg_type) | 1544 | tlsext_versions_client_needs(SSL *s, uint16_t msg_type) |
1552 | { | 1545 | { |
1553 | if (SSL_is_dtls(s)) | 1546 | return (S3I(s)->hs.our_max_tls_version >= TLS1_3_VERSION); |
1554 | return 0; | ||
1555 | return (S3I(s)->hs_tls13.max_version >= TLS1_3_VERSION); | ||
1556 | } | 1547 | } |
1557 | 1548 | ||
1558 | int | 1549 | int |
@@ -1562,11 +1553,8 @@ tlsext_versions_client_build(SSL *s, uint16_t msg_type, CBB *cbb) | |||
1562 | uint16_t version; | 1553 | uint16_t version; |
1563 | CBB versions; | 1554 | CBB versions; |
1564 | 1555 | ||
1565 | max = S3I(s)->hs_tls13.max_version; | 1556 | max = S3I(s)->hs.our_max_tls_version; |
1566 | min = S3I(s)->hs_tls13.min_version; | 1557 | min = S3I(s)->hs.our_min_tls_version; |
1567 | |||
1568 | if (min < TLS1_VERSION) | ||
1569 | return 0; | ||
1570 | 1558 | ||
1571 | if (!CBB_add_u8_length_prefixed(cbb, &versions)) | 1559 | if (!CBB_add_u8_length_prefixed(cbb, &versions)) |
1572 | return 0; | 1560 | return 0; |
@@ -1591,8 +1579,8 @@ tlsext_versions_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1591 | uint16_t max, min; | 1579 | uint16_t max, min; |
1592 | uint16_t matched_version = 0; | 1580 | uint16_t matched_version = 0; |
1593 | 1581 | ||
1594 | max = S3I(s)->hs_tls13.max_version; | 1582 | max = S3I(s)->hs.our_max_tls_version; |
1595 | min = S3I(s)->hs_tls13.min_version; | 1583 | min = S3I(s)->hs.our_min_tls_version; |
1596 | 1584 | ||
1597 | if (!CBS_get_u8_length_prefixed(cbs, &versions)) | 1585 | if (!CBS_get_u8_length_prefixed(cbs, &versions)) |
1598 | goto err; | 1586 | goto err; |
@@ -1608,16 +1596,8 @@ tlsext_versions_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1608 | matched_version = version; | 1596 | matched_version = version; |
1609 | } | 1597 | } |
1610 | 1598 | ||
1611 | /* | 1599 | if (matched_version > 0) { |
1612 | * XXX if we haven't matched a version we should | 1600 | /* XXX - this should be stored for later processing. */ |
1613 | * fail - but we currently need to succeed to | ||
1614 | * ignore this before the server code for 1.3 | ||
1615 | * is set up and initialized. | ||
1616 | */ | ||
1617 | if (max == 0) | ||
1618 | return 1; /* XXX */ | ||
1619 | |||
1620 | if (matched_version != 0) { | ||
1621 | s->version = matched_version; | 1601 | s->version = matched_version; |
1622 | return 1; | 1602 | return 1; |
1623 | } | 1603 | } |
@@ -1633,17 +1613,13 @@ tlsext_versions_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1633 | int | 1613 | int |
1634 | tlsext_versions_server_needs(SSL *s, uint16_t msg_type) | 1614 | tlsext_versions_server_needs(SSL *s, uint16_t msg_type) |
1635 | { | 1615 | { |
1636 | return (!SSL_is_dtls(s) && s->version >= TLS1_3_VERSION); | 1616 | return (S3I(s)->hs.negotiated_tls_version >= TLS1_3_VERSION); |
1637 | } | 1617 | } |
1638 | 1618 | ||
1639 | int | 1619 | int |
1640 | tlsext_versions_server_build(SSL *s, uint16_t msg_type, CBB *cbb) | 1620 | tlsext_versions_server_build(SSL *s, uint16_t msg_type, CBB *cbb) |
1641 | { | 1621 | { |
1642 | if (!CBB_add_u16(cbb, TLS1_3_VERSION)) | 1622 | return CBB_add_u16(cbb, TLS1_3_VERSION); |
1643 | return 0; | ||
1644 | /* XXX set 1.2 in legacy version? */ | ||
1645 | |||
1646 | return 1; | ||
1647 | } | 1623 | } |
1648 | 1624 | ||
1649 | int | 1625 | int |
@@ -1656,6 +1632,7 @@ tlsext_versions_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1656 | return 0; | 1632 | return 0; |
1657 | } | 1633 | } |
1658 | 1634 | ||
1635 | /* XXX - need to fix for DTLS 1.3 */ | ||
1659 | if (selected_version < TLS1_3_VERSION) { | 1636 | if (selected_version < TLS1_3_VERSION) { |
1660 | *alert = SSL_AD_ILLEGAL_PARAMETER; | 1637 | *alert = SSL_AD_ILLEGAL_PARAMETER; |
1661 | return 0; | 1638 | return 0; |
@@ -1675,12 +1652,8 @@ tlsext_versions_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1675 | int | 1652 | int |
1676 | tlsext_cookie_client_needs(SSL *s, uint16_t msg_type) | 1653 | tlsext_cookie_client_needs(SSL *s, uint16_t msg_type) |
1677 | { | 1654 | { |
1678 | if (SSL_is_dtls(s)) | 1655 | return (S3I(s)->hs.our_max_tls_version >= TLS1_3_VERSION && |
1679 | return 0; | 1656 | S3I(s)->hs_tls13.cookie_len > 0 && S3I(s)->hs_tls13.cookie != NULL); |
1680 | if (S3I(s)->hs_tls13.max_version < TLS1_3_VERSION) | ||
1681 | return 0; | ||
1682 | return (S3I(s)->hs_tls13.cookie_len > 0 && | ||
1683 | S3I(s)->hs_tls13.cookie != NULL); | ||
1684 | } | 1657 | } |
1685 | 1658 | ||
1686 | int | 1659 | int |
@@ -1734,17 +1707,12 @@ tlsext_cookie_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert) | |||
1734 | int | 1707 | int |
1735 | tlsext_cookie_server_needs(SSL *s, uint16_t msg_type) | 1708 | tlsext_cookie_server_needs(SSL *s, uint16_t msg_type) |
1736 | { | 1709 | { |
1737 | |||
1738 | if (SSL_is_dtls(s)) | ||
1739 | return 0; | ||
1740 | if (S3I(s)->hs_tls13.max_version < TLS1_3_VERSION) | ||
1741 | return 0; | ||
1742 | /* | 1710 | /* |
1743 | * Server needs to set cookie value in tls13 handshake | 1711 | * Server needs to set cookie value in tls13 handshake |
1744 | * in order to send one, should only be sent with HRR. | 1712 | * in order to send one, should only be sent with HRR. |
1745 | */ | 1713 | */ |
1746 | return (S3I(s)->hs_tls13.cookie_len > 0 && | 1714 | return (S3I(s)->hs.our_max_tls_version >= TLS1_3_VERSION && |
1747 | S3I(s)->hs_tls13.cookie != NULL); | 1715 | S3I(s)->hs_tls13.cookie_len > 0 && S3I(s)->hs_tls13.cookie != NULL); |
1748 | } | 1716 | } |
1749 | 1717 | ||
1750 | int | 1718 | int |
@@ -2033,13 +2001,10 @@ tlsext_build(SSL *s, int is_server, uint16_t msg_type, CBB *cbb) | |||
2033 | const struct tls_extension *tlsext; | 2001 | const struct tls_extension *tlsext; |
2034 | CBB extensions, extension_data; | 2002 | CBB extensions, extension_data; |
2035 | int extensions_present = 0; | 2003 | int extensions_present = 0; |
2004 | uint16_t tls_version; | ||
2036 | size_t i; | 2005 | size_t i; |
2037 | uint16_t version; | ||
2038 | 2006 | ||
2039 | if (is_server) | 2007 | tls_version = ssl_effective_tls_version(s); |
2040 | version = s->version; | ||
2041 | else | ||
2042 | version = TLS1_get_client_version(s); | ||
2043 | 2008 | ||
2044 | if (!CBB_add_u16_length_prefixed(cbb, &extensions)) | 2009 | if (!CBB_add_u16_length_prefixed(cbb, &extensions)) |
2045 | return 0; | 2010 | return 0; |
@@ -2049,7 +2014,7 @@ tlsext_build(SSL *s, int is_server, uint16_t msg_type, CBB *cbb) | |||
2049 | ext = tlsext_funcs(tlsext, is_server); | 2014 | ext = tlsext_funcs(tlsext, is_server); |
2050 | 2015 | ||
2051 | /* RFC 8446 Section 4.2 */ | 2016 | /* RFC 8446 Section 4.2 */ |
2052 | if (version >= TLS1_3_VERSION && | 2017 | if (tls_version >= TLS1_3_VERSION && |
2053 | !(tlsext->messages & msg_type)) | 2018 | !(tlsext->messages & msg_type)) |
2054 | continue; | 2019 | continue; |
2055 | 2020 | ||
@@ -2112,15 +2077,12 @@ tlsext_parse(SSL *s, int is_server, uint16_t msg_type, CBS *cbs, int *alert) | |||
2112 | CBS extensions, extension_data; | 2077 | CBS extensions, extension_data; |
2113 | uint16_t type; | 2078 | uint16_t type; |
2114 | size_t idx; | 2079 | size_t idx; |
2115 | uint16_t version; | 2080 | uint16_t tls_version; |
2116 | int alert_desc; | 2081 | int alert_desc; |
2117 | 2082 | ||
2118 | S3I(s)->hs.extensions_seen = 0; | 2083 | tls_version = ssl_effective_tls_version(s); |
2119 | 2084 | ||
2120 | if (is_server) | 2085 | S3I(s)->hs.extensions_seen = 0; |
2121 | version = s->version; | ||
2122 | else | ||
2123 | version = TLS1_get_client_version(s); | ||
2124 | 2086 | ||
2125 | /* An empty extensions block is valid. */ | 2087 | /* An empty extensions block is valid. */ |
2126 | if (CBS_len(cbs) == 0) | 2088 | if (CBS_len(cbs) == 0) |
@@ -2143,7 +2105,7 @@ tlsext_parse(SSL *s, int is_server, uint16_t msg_type, CBS *cbs, int *alert) | |||
2143 | CBS_len(&extension_data), | 2105 | CBS_len(&extension_data), |
2144 | s->internal->tlsext_debug_arg); | 2106 | s->internal->tlsext_debug_arg); |
2145 | 2107 | ||
2146 | if (!SSL_is_dtls(s) && version >= TLS1_3_VERSION && is_server && | 2108 | if (tls_version >= TLS1_3_VERSION && is_server && |
2147 | msg_type == SSL_TLSEXT_MSG_CH) { | 2109 | msg_type == SSL_TLSEXT_MSG_CH) { |
2148 | if (!tlsext_clienthello_hash_extension(s, type, | 2110 | if (!tlsext_clienthello_hash_extension(s, type, |
2149 | &extension_data)) | 2111 | &extension_data)) |
@@ -2155,7 +2117,7 @@ tlsext_parse(SSL *s, int is_server, uint16_t msg_type, CBS *cbs, int *alert) | |||
2155 | continue; | 2117 | continue; |
2156 | 2118 | ||
2157 | /* RFC 8446 Section 4.2 */ | 2119 | /* RFC 8446 Section 4.2 */ |
2158 | if (version >= TLS1_3_VERSION && | 2120 | if (tls_version >= TLS1_3_VERSION && |
2159 | !(tlsext->messages & msg_type)) { | 2121 | !(tlsext->messages & msg_type)) { |
2160 | alert_desc = SSL_AD_ILLEGAL_PARAMETER; | 2122 | alert_desc = SSL_AD_ILLEGAL_PARAMETER; |
2161 | goto err; | 2123 | goto err; |
diff --git a/src/lib/libssl/ssl_versions.c b/src/lib/libssl/ssl_versions.c index a216de6e81..37957fd0ab 100644 --- a/src/lib/libssl/ssl_versions.c +++ b/src/lib/libssl/ssl_versions.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_versions.c,v 1.13 2021/02/25 17:06:05 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_versions.c,v 1.14 2021/03/10 18:27:02 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -171,6 +171,30 @@ ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver) | |||
171 | return 1; | 171 | return 1; |
172 | } | 172 | } |
173 | 173 | ||
174 | uint16_t | ||
175 | ssl_tls_version(uint16_t version) | ||
176 | { | ||
177 | if (version == TLS1_VERSION || version == TLS1_1_VERSION || | ||
178 | version == TLS1_2_VERSION || version == TLS1_3_VERSION) | ||
179 | return version; | ||
180 | |||
181 | if (version == DTLS1_VERSION) | ||
182 | return TLS1_1_VERSION; | ||
183 | if (version == DTLS1_2_VERSION) | ||
184 | return TLS1_2_VERSION; | ||
185 | |||
186 | return 0; | ||
187 | } | ||
188 | |||
189 | uint16_t | ||
190 | ssl_effective_tls_version(SSL *s) | ||
191 | { | ||
192 | if (S3I(s)->hs.negotiated_tls_version > 0) | ||
193 | return S3I(s)->hs.negotiated_tls_version; | ||
194 | |||
195 | return S3I(s)->hs.our_max_tls_version; | ||
196 | } | ||
197 | |||
174 | int | 198 | int |
175 | ssl_max_supported_version(SSL *s, uint16_t *max_ver) | 199 | ssl_max_supported_version(SSL *s, uint16_t *max_ver) |
176 | { | 200 | { |
diff --git a/src/lib/libssl/tls13_client.c b/src/lib/libssl/tls13_client.c index a7c3bf2c00..4de3d3693b 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.73 2021/02/25 17:06:05 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_client.c,v 1.74 2021/03/10 18:27:02 jsing 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 | * |
@@ -31,12 +31,12 @@ tls13_client_init(struct tls13_ctx *ctx) | |||
31 | size_t groups_len; | 31 | size_t groups_len; |
32 | SSL *s = ctx->ssl; | 32 | SSL *s = ctx->ssl; |
33 | 33 | ||
34 | if (!ssl_supported_tls_version_range(s, &ctx->hs->min_version, | 34 | if (!ssl_supported_tls_version_range(s, &S3I(s)->hs.our_min_tls_version, |
35 | &ctx->hs->max_version)) { | 35 | &S3I(s)->hs.our_max_tls_version)) { |
36 | SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE); | 36 | SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE); |
37 | return 0; | 37 | return 0; |
38 | } | 38 | } |
39 | s->client_version = s->version = ctx->hs->max_version; | 39 | s->client_version = s->version = S3I(s)->hs.our_max_tls_version; |
40 | 40 | ||
41 | tls13_record_layer_set_retry_after_phh(ctx->rl, | 41 | tls13_record_layer_set_retry_after_phh(ctx->rl, |
42 | (s->internal->mode & SSL_MODE_AUTO_RETRY) != 0); | 42 | (s->internal->mode & SSL_MODE_AUTO_RETRY) != 0); |
@@ -64,7 +64,8 @@ tls13_client_init(struct tls13_ctx *ctx) | |||
64 | * legacy session identifier triggers compatibility mode (see RFC 8446 | 64 | * legacy session identifier triggers compatibility mode (see RFC 8446 |
65 | * Appendix D.4). In the pre-TLSv1.3 case a zero length value is used. | 65 | * Appendix D.4). In the pre-TLSv1.3 case a zero length value is used. |
66 | */ | 66 | */ |
67 | if (ctx->middlebox_compat && ctx->hs->max_version >= TLS1_3_VERSION) { | 67 | if (ctx->middlebox_compat && |
68 | S3I(s)->hs.our_max_tls_version >= TLS1_3_VERSION) { | ||
68 | arc4random_buf(ctx->hs->legacy_session_id, | 69 | arc4random_buf(ctx->hs->legacy_session_id, |
69 | sizeof(ctx->hs->legacy_session_id)); | 70 | sizeof(ctx->hs->legacy_session_id)); |
70 | ctx->hs->legacy_session_id_len = | 71 | ctx->hs->legacy_session_id_len = |
@@ -91,7 +92,7 @@ tls13_client_hello_build(struct tls13_ctx *ctx, CBB *cbb) | |||
91 | SSL *s = ctx->ssl; | 92 | SSL *s = ctx->ssl; |
92 | 93 | ||
93 | /* Legacy client version is capped at TLS 1.2. */ | 94 | /* Legacy client version is capped at TLS 1.2. */ |
94 | client_version = ctx->hs->max_version; | 95 | client_version = S3I(s)->hs.our_max_tls_version; |
95 | if (client_version > TLS1_2_VERSION) | 96 | if (client_version > TLS1_2_VERSION) |
96 | client_version = TLS1_2_VERSION; | 97 | client_version = TLS1_2_VERSION; |
97 | 98 | ||
@@ -133,7 +134,9 @@ tls13_client_hello_build(struct tls13_ctx *ctx, CBB *cbb) | |||
133 | int | 134 | int |
134 | tls13_client_hello_send(struct tls13_ctx *ctx, CBB *cbb) | 135 | tls13_client_hello_send(struct tls13_ctx *ctx, CBB *cbb) |
135 | { | 136 | { |
136 | if (ctx->hs->min_version < TLS1_2_VERSION) | 137 | SSL *s = ctx->ssl; |
138 | |||
139 | if (S3I(s)->hs.our_min_tls_version < TLS1_2_VERSION) | ||
137 | tls13_record_layer_set_legacy_version(ctx->rl, TLS1_VERSION); | 140 | tls13_record_layer_set_legacy_version(ctx->rl, TLS1_VERSION); |
138 | 141 | ||
139 | /* We may receive a pre-TLSv1.3 alert in response to the client hello. */ | 142 | /* We may receive a pre-TLSv1.3 alert in response to the client hello. */ |
@@ -228,7 +231,7 @@ tls13_server_hello_process(struct tls13_ctx *ctx, CBS *cbs) | |||
228 | goto err; | 231 | goto err; |
229 | 232 | ||
230 | if (tls13_server_hello_is_legacy(cbs)) { | 233 | if (tls13_server_hello_is_legacy(cbs)) { |
231 | if (ctx->hs->max_version >= TLS1_3_VERSION) { | 234 | if (S3I(s)->hs.our_max_tls_version >= TLS1_3_VERSION) { |
232 | /* | 235 | /* |
233 | * RFC 8446 section 4.1.3: we must not downgrade if | 236 | * RFC 8446 section 4.1.3: we must not downgrade if |
234 | * the server random value contains the TLS 1.2 or 1.1 | 237 | * the server random value contains the TLS 1.2 or 1.1 |
@@ -280,6 +283,7 @@ tls13_server_hello_process(struct tls13_ctx *ctx, CBS *cbs) | |||
280 | ctx->alert = TLS13_ALERT_PROTOCOL_VERSION; | 283 | ctx->alert = TLS13_ALERT_PROTOCOL_VERSION; |
281 | goto err; | 284 | goto err; |
282 | } | 285 | } |
286 | S3I(s)->hs.negotiated_tls_version = ctx->hs->server_version; | ||
283 | 287 | ||
284 | /* The session_id must match. */ | 288 | /* The session_id must match. */ |
285 | if (!CBS_mem_equal(&session_id, ctx->hs->legacy_session_id, | 289 | if (!CBS_mem_equal(&session_id, ctx->hs->legacy_session_id, |
diff --git a/src/lib/libssl/tls13_server.c b/src/lib/libssl/tls13_server.c index 715066fb59..29c63bcd06 100644 --- a/src/lib/libssl/tls13_server.c +++ b/src/lib/libssl/tls13_server.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_server.c,v 1.70 2021/02/25 17:06:05 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_server.c,v 1.71 2021/03/10 18:27:02 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2020 Bob Beck <beck@openbsd.org> | 4 | * Copyright (c) 2020 Bob Beck <beck@openbsd.org> |
@@ -29,12 +29,12 @@ tls13_server_init(struct tls13_ctx *ctx) | |||
29 | { | 29 | { |
30 | SSL *s = ctx->ssl; | 30 | SSL *s = ctx->ssl; |
31 | 31 | ||
32 | if (!ssl_supported_tls_version_range(s, &ctx->hs->min_version, | 32 | if (!ssl_supported_tls_version_range(s, &S3I(s)->hs.our_min_tls_version, |
33 | &ctx->hs->max_version)) { | 33 | &S3I(s)->hs.our_max_tls_version)) { |
34 | SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE); | 34 | SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE); |
35 | return 0; | 35 | return 0; |
36 | } | 36 | } |
37 | s->version = ctx->hs->max_version; | 37 | s->version = S3I(s)->hs.our_max_tls_version; |
38 | 38 | ||
39 | tls13_record_layer_set_retry_after_phh(ctx->rl, | 39 | tls13_record_layer_set_retry_after_phh(ctx->rl, |
40 | (s->internal->mode & SSL_MODE_AUTO_RETRY) != 0); | 40 | (s->internal->mode & SSL_MODE_AUTO_RETRY) != 0); |
@@ -163,6 +163,7 @@ tls13_client_hello_process(struct tls13_ctx *ctx, CBS *cbs) | |||
163 | goto err; | 163 | goto err; |
164 | return tls13_use_legacy_server(ctx); | 164 | return tls13_use_legacy_server(ctx); |
165 | } | 165 | } |
166 | S3I(s)->hs.negotiated_tls_version = TLS1_3_VERSION; | ||
166 | 167 | ||
167 | /* Add decoded values to the current ClientHello hash */ | 168 | /* Add decoded values to the current ClientHello hash */ |
168 | if (!tls13_clienthello_hash_init(ctx)) { | 169 | if (!tls13_clienthello_hash_init(ctx)) { |