summaryrefslogtreecommitdiffstats
path: root/lib/libssl/ssl_versions.c
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2021-03-10 18:27:01 +0000
committerjsing <jsing@openbsd.org>2021-03-10 18:27:01 +0000
commitc5e6469d48821e65e529c0cc22a8e2488f1c75fe (patch)
treed9d607ff358c016d608848d92624de428bd26f32 /lib/libssl/ssl_versions.c
parentdo not request client certificate unless required (diff)
downloadwireguard-openbsd-c5e6469d48821e65e529c0cc22a8e2488f1c75fe.tar.xz
wireguard-openbsd-c5e6469d48821e65e529c0cc22a8e2488f1c75fe.zip
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@
Diffstat (limited to 'lib/libssl/ssl_versions.c')
-rw-r--r--lib/libssl/ssl_versions.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/libssl/ssl_versions.c b/lib/libssl/ssl_versions.c
index a216de6e811..37957fd0ab4 100644
--- a/lib/libssl/ssl_versions.c
+++ b/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 <jsing@openbsd.org>
*
@@ -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)
{