summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2021-03-11 17:14:47 +0000
committerjsing <>2021-03-11 17:14:47 +0000
commit7a96ea5b5a6bd9d1c199cb3f2b39f58b318330e0 (patch)
tree812227b9eac6204c336048feeaa5d32e3db2f552 /src
parent9718c009ebd714a8cb224839233e9267bf1471d8 (diff)
downloadopenbsd-7a96ea5b5a6bd9d1c199cb3f2b39f58b318330e0.tar.gz
openbsd-7a96ea5b5a6bd9d1c199cb3f2b39f58b318330e0.tar.bz2
openbsd-7a96ea5b5a6bd9d1c199cb3f2b39f58b318330e0.zip
Remove ssl_downgrade_max_version().
Now that we store our maximum TLS version at the start of the handshake, we can check against that directly. ok inoguchi@ tb@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/ssl_ciphers.c9
-rw-r--r--src/lib/libssl/ssl_clnt.c11
-rw-r--r--src/lib/libssl/ssl_locl.h3
-rw-r--r--src/lib/libssl/ssl_srvr.c12
-rw-r--r--src/lib/libssl/ssl_versions.c34
5 files changed, 15 insertions, 54 deletions
diff --git a/src/lib/libssl/ssl_ciphers.c b/src/lib/libssl/ssl_ciphers.c
index 85c60b1abb..4e4a0d93a4 100644
--- a/src/lib/libssl/ssl_ciphers.c
+++ b/src/lib/libssl/ssl_ciphers.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_ciphers.c,v 1.10 2021/02/25 17:06:05 jsing Exp $ */ 1/* $OpenBSD: ssl_ciphers.c,v 1.11 2021/03/11 17:14:46 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2015-2017 Doug Hogan <doug@openbsd.org> 3 * Copyright (c) 2015-2017 Doug Hogan <doug@openbsd.org>
4 * Copyright (c) 2015-2018, 2020 Joel Sing <jsing@openbsd.org> 4 * Copyright (c) 2015-2018, 2020 Joel Sing <jsing@openbsd.org>
@@ -93,7 +93,7 @@ ssl_bytes_to_cipher_list(SSL *s, CBS *cbs)
93{ 93{
94 STACK_OF(SSL_CIPHER) *ciphers = NULL; 94 STACK_OF(SSL_CIPHER) *ciphers = NULL;
95 const SSL_CIPHER *cipher; 95 const SSL_CIPHER *cipher;
96 uint16_t cipher_value, max_version; 96 uint16_t cipher_value;
97 unsigned long cipher_id; 97 unsigned long cipher_id;
98 98
99 S3I(s)->send_connection_binding = 0; 99 S3I(s)->send_connection_binding = 0;
@@ -134,9 +134,8 @@ ssl_bytes_to_cipher_list(SSL *s, CBS *cbs)
134 * Fail if the current version is an unexpected 134 * Fail if the current version is an unexpected
135 * downgrade. 135 * downgrade.
136 */ 136 */
137 if (!ssl_downgrade_max_version(s, &max_version)) 137 if (S3I(s)->hs.negotiated_tls_version <
138 goto err; 138 S3I(s)->hs.our_max_tls_version) {
139 if (s->version < max_version) {
140 SSLerror(s, SSL_R_INAPPROPRIATE_FALLBACK); 139 SSLerror(s, SSL_R_INAPPROPRIATE_FALLBACK);
141 ssl3_send_alert(s, SSL3_AL_FATAL, 140 ssl3_send_alert(s, SSL3_AL_FATAL,
142 SSL_AD_INAPPROPRIATE_FALLBACK); 141 SSL_AD_INAPPROPRIATE_FALLBACK);
diff --git a/src/lib/libssl/ssl_clnt.c b/src/lib/libssl/ssl_clnt.c
index 97418f1ac7..06941530c6 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.85 2021/03/10 18:27:01 jsing Exp $ */ 1/* $OpenBSD: ssl_clnt.c,v 1.86 2021/03/11 17:14:46 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 *
@@ -859,7 +859,6 @@ ssl3_get_server_hello(SSL *s)
859{ 859{
860 CBS cbs, server_random, session_id; 860 CBS cbs, server_random, session_id;
861 uint16_t server_version, cipher_suite; 861 uint16_t server_version, cipher_suite;
862 uint16_t max_version;
863 uint8_t compression_method; 862 uint8_t compression_method;
864 const SSL_CIPHER *cipher; 863 const SSL_CIPHER *cipher;
865 const SSL_METHOD *method; 864 const SSL_METHOD *method;
@@ -930,10 +929,8 @@ ssl3_get_server_hello(SSL *s)
930 sizeof(s->s3->server_random), NULL)) 929 sizeof(s->s3->server_random), NULL))
931 goto err; 930 goto err;
932 931
933 if (!ssl_downgrade_max_version(s, &max_version)) 932 if (S3I(s)->hs.our_max_tls_version >= TLS1_2_VERSION &&
934 goto err; 933 S3I(s)->hs.negotiated_tls_version < S3I(s)->hs.our_max_tls_version) {
935 if (!SSL_is_dtls(s) && max_version >= TLS1_2_VERSION &&
936 s->version < max_version) {
937 /* 934 /*
938 * RFC 8446 section 4.1.3. We must not downgrade if the server 935 * RFC 8446 section 4.1.3. We must not downgrade if the server
939 * random value contains the TLS 1.2 or TLS 1.1 magical value. 936 * random value contains the TLS 1.2 or TLS 1.1 magical value.
@@ -941,7 +938,7 @@ ssl3_get_server_hello(SSL *s)
941 if (!CBS_skip(&server_random, 938 if (!CBS_skip(&server_random,
942 CBS_len(&server_random) - sizeof(tls13_downgrade_12))) 939 CBS_len(&server_random) - sizeof(tls13_downgrade_12)))
943 goto err; 940 goto err;
944 if (s->version == TLS1_2_VERSION && 941 if (S3I(s)->hs.negotiated_tls_version == TLS1_2_VERSION &&
945 CBS_mem_equal(&server_random, tls13_downgrade_12, 942 CBS_mem_equal(&server_random, tls13_downgrade_12,
946 sizeof(tls13_downgrade_12))) { 943 sizeof(tls13_downgrade_12))) {
947 al = SSL_AD_ILLEGAL_PARAMETER; 944 al = SSL_AD_ILLEGAL_PARAMETER;
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index 6f66a8932e..fed14b4b19 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.325 2021/03/10 18:27:01 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.326 2021/03/11 17:14:47 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 *
@@ -1131,7 +1131,6 @@ int ssl_enabled_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver);
1131int ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver); 1131int ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver);
1132uint16_t ssl_tls_version(uint16_t version); 1132uint16_t ssl_tls_version(uint16_t version);
1133uint16_t ssl_effective_tls_version(SSL *s); 1133uint16_t ssl_effective_tls_version(SSL *s);
1134int ssl_downgrade_max_version(SSL *s, uint16_t *max_ver);
1135int ssl_max_supported_version(SSL *s, uint16_t *max_ver); 1134int ssl_max_supported_version(SSL *s, uint16_t *max_ver);
1136int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver); 1135int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver);
1137int ssl_check_version_from_server(SSL *s, uint16_t server_version); 1136int ssl_check_version_from_server(SSL *s, uint16_t server_version);
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c
index 373a20d61b..19fedde87a 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.96 2021/03/10 18:27:02 jsing Exp $ */ 1/* $OpenBSD: ssl_srvr.c,v 1.97 2021/03/11 17:14:47 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 *
@@ -799,7 +799,7 @@ ssl3_get_client_hello(SSL *s)
799 STACK_OF(SSL_CIPHER) *ciphers = NULL; 799 STACK_OF(SSL_CIPHER) *ciphers = NULL;
800 unsigned long alg_k; 800 unsigned long alg_k;
801 const SSL_METHOD *method; 801 const SSL_METHOD *method;
802 uint16_t max_version, shared_version; 802 uint16_t shared_version;
803 803
804 /* 804 /*
805 * We do this so that we will respond with our native type. 805 * We do this so that we will respond with our native type.
@@ -850,8 +850,6 @@ ssl3_get_client_hello(SSL *s)
850 * Use version from inside client hello, not from record header. 850 * Use version from inside client hello, not from record header.
851 * (may differ: see RFC 2246, Appendix E, second paragraph) 851 * (may differ: see RFC 2246, Appendix E, second paragraph)
852 */ 852 */
853 if (!ssl_downgrade_max_version(s, &max_version))
854 goto err;
855 if (!ssl_max_shared_version(s, client_version, &shared_version)) { 853 if (!ssl_max_shared_version(s, client_version, &shared_version)) {
856 if ((s->client_version >> 8) == SSL3_VERSION_MAJOR && 854 if ((s->client_version >> 8) == SSL3_VERSION_MAJOR &&
857 !tls12_record_layer_write_protected(s->internal->rl)) { 855 !tls12_record_layer_write_protected(s->internal->rl)) {
@@ -1051,8 +1049,8 @@ ssl3_get_client_hello(SSL *s)
1051 */ 1049 */
1052 arc4random_buf(s->s3->server_random, SSL3_RANDOM_SIZE); 1050 arc4random_buf(s->s3->server_random, SSL3_RANDOM_SIZE);
1053 1051
1054 if (!SSL_is_dtls(s) && max_version >= TLS1_2_VERSION && 1052 if (S3I(s)->hs.our_max_tls_version >= TLS1_2_VERSION &&
1055 s->version < max_version) { 1053 S3I(s)->hs.negotiated_tls_version < S3I(s)->hs.our_max_tls_version) {
1056 /* 1054 /*
1057 * RFC 8446 section 4.1.3. If we are downgrading from TLS 1.3 1055 * RFC 8446 section 4.1.3. If we are downgrading from TLS 1.3
1058 * we must set the last 8 bytes of the server random to magical 1056 * we must set the last 8 bytes of the server random to magical
@@ -1061,7 +1059,7 @@ ssl3_get_client_hello(SSL *s)
1061 */ 1059 */
1062 size_t index = SSL3_RANDOM_SIZE - sizeof(tls13_downgrade_12); 1060 size_t index = SSL3_RANDOM_SIZE - sizeof(tls13_downgrade_12);
1063 uint8_t *magic = &s->s3->server_random[index]; 1061 uint8_t *magic = &s->s3->server_random[index];
1064 if (s->version == TLS1_2_VERSION) { 1062 if (S3I(s)->hs.negotiated_tls_version == TLS1_2_VERSION) {
1065 /* Indicate we chose to downgrade to 1.2. */ 1063 /* Indicate we chose to downgrade to 1.2. */
1066 memcpy(magic, tls13_downgrade_12, 1064 memcpy(magic, tls13_downgrade_12,
1067 sizeof(tls13_downgrade_12)); 1065 sizeof(tls13_downgrade_12));
diff --git a/src/lib/libssl/ssl_versions.c b/src/lib/libssl/ssl_versions.c
index 37957fd0ab..45e468f0d8 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.14 2021/03/10 18:27:02 jsing Exp $ */ 1/* $OpenBSD: ssl_versions.c,v 1.15 2021/03/11 17:14:47 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 *
@@ -252,38 +252,6 @@ ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver)
252} 252}
253 253
254int 254int
255ssl_downgrade_max_version(SSL *s, uint16_t *max_ver)
256{
257 uint16_t min_version, max_version;
258
259 /*
260 * The downgrade maximum version is based on the versions that are
261 * enabled, however we also have to then limit to the versions
262 * supported by the method. The SSL method will be changed during
263 * version negotiation and when switching from the new stack to
264 * the legacy context, as such we want to use the method from the
265 * context.
266 */
267
268 if (SSL_is_dtls(s)) {
269 *max_ver = DTLS1_VERSION;
270 return 1;
271 }
272
273 if (!ssl_enabled_tls_version_range(s, &min_version, &max_version))
274 return 0;
275
276 if (!ssl_clamp_tls_version_range(&min_version, &max_version,
277 s->ctx->method->internal->min_tls_version,
278 s->ctx->method->internal->max_tls_version))
279 return 0;
280
281 *max_ver = max_version;
282
283 return 1;
284}
285
286int
287ssl_check_version_from_server(SSL *s, uint16_t server_version) 255ssl_check_version_from_server(SSL *s, uint16_t server_version)
288{ 256{
289 uint16_t min_version, max_version; 257 uint16_t min_version, max_version;