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_versions.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/lib/libssl/ssl_versions.c') 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 @@ -/* $OpenBSD: ssl_versions.c,v 1.13 2021/02/25 17:06:05 jsing Exp $ */ +/* $OpenBSD: ssl_versions.c,v 1.14 2021/03/10 18:27:02 jsing Exp $ */ /* * Copyright (c) 2016, 2017 Joel Sing * @@ -171,6 +171,30 @@ ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver) return 1; } +uint16_t +ssl_tls_version(uint16_t version) +{ + if (version == TLS1_VERSION || version == TLS1_1_VERSION || + version == TLS1_2_VERSION || version == TLS1_3_VERSION) + return version; + + if (version == DTLS1_VERSION) + return TLS1_1_VERSION; + if (version == DTLS1_2_VERSION) + return TLS1_2_VERSION; + + return 0; +} + +uint16_t +ssl_effective_tls_version(SSL *s) +{ + if (S3I(s)->hs.negotiated_tls_version > 0) + return S3I(s)->hs.negotiated_tls_version; + + return S3I(s)->hs.our_max_tls_version; +} + int ssl_max_supported_version(SSL *s, uint16_t *max_ver) { -- cgit v1.2.3-55-g6feb