summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl_versions.c
diff options
context:
space:
mode:
authorjsing <>2021-03-10 18:27:02 +0000
committerjsing <>2021-03-10 18:27:02 +0000
commitbec282ffa4cbd669be0dc9e8fab07c4c21ebcb66 (patch)
treed994b83bcf4c074517ad35a21855741c2995e67b /src/lib/libssl/ssl_versions.c
parent9108b7f38107e9f7ce1aaa33e615a7935b057ad0 (diff)
downloadopenbsd-bec282ffa4cbd669be0dc9e8fab07c4c21ebcb66.tar.gz
openbsd-bec282ffa4cbd669be0dc9e8fab07c4c21ebcb66.tar.bz2
openbsd-bec282ffa4cbd669be0dc9e8fab07c4c21ebcb66.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 'src/lib/libssl/ssl_versions.c')
-rw-r--r--src/lib/libssl/ssl_versions.c26
1 files changed, 25 insertions, 1 deletions
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
174uint16_t
175ssl_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
189uint16_t
190ssl_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
174int 198int
175ssl_max_supported_version(SSL *s, uint16_t *max_ver) 199ssl_max_supported_version(SSL *s, uint16_t *max_ver)
176{ 200{