From bec282ffa4cbd669be0dc9e8fab07c4c21ebcb66 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Wed, 10 Mar 2021 18:27:02 +0000 Subject: Improve internal version handling. Add handshake fields for our minimum TLS version, our maximum TLS version and the TLS version negotiated during the handshake. Initialise our min/max versions at the start of the handshake and leave these unchanged. The negotiated TLS version is set in the client once we receive the ServerHello and in the server at the point we select the highest shared version. Provide an ssl_effective_version() function that returns the negotiated TLS version if known, otherwise our maximum TLS version - this is effectively what is stored in s->version currently. Convert most of the internal code to use one of these three version fields, which greatly simplifies code (especially in the TLS extension handling code). ok tb@ --- src/lib/libssl/ssl_srvr.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/lib/libssl/ssl_srvr.c') 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 @@ -/* $OpenBSD: ssl_srvr.c,v 1.95 2021/02/20 14:16:56 tb Exp $ */ +/* $OpenBSD: ssl_srvr.c,v 1.96 2021/03/10 18:27:02 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -219,6 +219,14 @@ ssl3_accept(SSL *s) goto end; } + if (!ssl_supported_tls_version_range(s, + &S3I(s)->hs.our_min_tls_version, + &S3I(s)->hs.our_max_tls_version)) { + SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE); + ret = -1; + goto end; + } + s->internal->type = SSL_ST_ACCEPT; if (!ssl3_setup_init_buffer(s)) { @@ -844,7 +852,7 @@ ssl3_get_client_hello(SSL *s) */ if (!ssl_downgrade_max_version(s, &max_version)) goto err; - if (ssl_max_shared_version(s, client_version, &shared_version) != 1) { + if (!ssl_max_shared_version(s, client_version, &shared_version)) { if ((s->client_version >> 8) == SSL3_VERSION_MAJOR && !tls12_record_layer_write_protected(s->internal->rl)) { /* @@ -860,6 +868,12 @@ ssl3_get_client_hello(SSL *s) s->client_version = client_version; s->version = shared_version; + S3I(s)->hs.negotiated_tls_version = ssl_tls_version(shared_version); + if (S3I(s)->hs.negotiated_tls_version == 0) { + SSLerror(s, ERR_R_INTERNAL_ERROR); + goto err; + } + if ((method = ssl_get_method(shared_version)) == NULL) { SSLerror(s, ERR_R_INTERNAL_ERROR); goto err; @@ -1718,6 +1732,8 @@ ssl3_get_client_kex_rsa(SSL *s, CBS *cbs) int al = -1; arc4random_buf(fakekey, sizeof(fakekey)); + + /* XXX - peer max protocol version. */ fakekey[0] = s->client_version >> 8; fakekey[1] = s->client_version & 0xff; @@ -1754,6 +1770,7 @@ ssl3_get_client_kex_rsa(SSL *s, CBS *cbs) /* SSLerror(s, SSL_R_BAD_RSA_DECRYPT); */ } + /* XXX - peer max version. */ if ((al == -1) && !((pms[0] == (s->client_version >> 8)) && (pms[1] == (s->client_version & 0xff)))) { /* -- cgit v1.2.3-55-g6feb