summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2021-09-10 09:25:29 +0000
committertb <>2021-09-10 09:25:29 +0000
commit47a94cad06ffc8bf1c64c7870f0dc905ed8485e4 (patch)
tree2fcdf6ff9ae24aab6ae8fc69b1f46e80b647dd92 /src/lib
parentd17eb2a4cbcb7c76bb5dd38f9d1c26044d64118f (diff)
downloadopenbsd-47a94cad06ffc8bf1c64c7870f0dc905ed8485e4.tar.gz
openbsd-47a94cad06ffc8bf1c64c7870f0dc905ed8485e4.tar.bz2
openbsd-47a94cad06ffc8bf1c64c7870f0dc905ed8485e4.zip
Do not ignore SSL_TLSEXT_ERR_FATAL from the ALPN callback
As reported by Jeremy Harris, we inherited a strange behavior from OpenSSL, in that we ignore the SSL_TLSEXT_ERR_FATAL return from the ALPN callback. RFC 7301, 3.2 states: 'In the event that the server supports no protocols that the client advertises, then the server SHALL respond with a fatal "no_application_protocol" alert.' Honor this requirement and succeed only on SSL_TLSEXT_ERR_{OK,NOACK} which is the current behavior of OpenSSL. The documentation change is taken from OpenSSL 1.1.1 as well. As pointed out by jsing, there is more to be fixed here: - ensure that the same protocol is selected on session resumption - should the callback be called even if no ALPN extension was sent? - ensure for TLSv1.2 and earlier that the SNI has already been processed ok beck jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_alpn_select_cb.310
-rw-r--r--src/lib/libssl/ssl.h5
-rw-r--r--src/lib/libssl/ssl_err.c3
-rw-r--r--src/lib/libssl/ssl_tlsext.c20
4 files changed, 31 insertions, 7 deletions
diff --git a/src/lib/libssl/man/SSL_CTX_set_alpn_select_cb.3 b/src/lib/libssl/man/SSL_CTX_set_alpn_select_cb.3
index 540fd011f5..683b6696e3 100644
--- a/src/lib/libssl/man/SSL_CTX_set_alpn_select_cb.3
+++ b/src/lib/libssl/man/SSL_CTX_set_alpn_select_cb.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: SSL_CTX_set_alpn_select_cb.3,v 1.7 2018/03/23 14:28:16 schwarze Exp $ 1.\" $OpenBSD: SSL_CTX_set_alpn_select_cb.3,v 1.8 2021/09/10 09:25:29 tb Exp $
2.\" OpenSSL 87b81496 Apr 19 12:38:27 2017 -0400 2.\" OpenSSL 87b81496 Apr 19 12:38:27 2017 -0400
3.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100 3.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
4.\" 4.\"
@@ -49,7 +49,7 @@
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE. 50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\" 51.\"
52.Dd $Mdocdate: March 23 2018 $ 52.Dd $Mdocdate: September 10 2021 $
53.Dt SSL_CTX_SET_ALPN_SELECT_CB 3 53.Dt SSL_CTX_SET_ALPN_SELECT_CB 3
54.Os 54.Os
55.Sh NAME 55.Sh NAME
@@ -252,8 +252,12 @@ must return one of the following:
252.Bl -tag -width Ds 252.Bl -tag -width Ds
253.It SSL_TLSEXT_ERR_OK 253.It SSL_TLSEXT_ERR_OK
254ALPN protocol selected. 254ALPN protocol selected.
255.It SSL_TLSEXT_ERR_ALERT_FATAL
256There was no overlap between the client's supplied list and the
257server configuration.
255.It SSL_TLSEXT_ERR_NOACK 258.It SSL_TLSEXT_ERR_NOACK
256ALPN protocol not selected. 259ALPN protocol not selected, e.g., because no ALPN protocols are
260configured for this connection.
257.El 261.El
258.Sh SEE ALSO 262.Sh SEE ALSO
259.Xr ssl 3 , 263.Xr ssl 3 ,
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
index 7da3658d3f..fba9ea243f 100644
--- a/src/lib/libssl/ssl.h
+++ b/src/lib/libssl/ssl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl.h,v 1.201 2021/09/10 08:59:56 tb Exp $ */ 1/* $OpenBSD: ssl.h,v 1.202 2021/09/10 09:25:29 tb 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 *
@@ -1995,6 +1995,9 @@ void ERR_load_SSL_strings(void);
1995#define SSL_R_MISSING_VERIFY_MESSAGE 174 1995#define SSL_R_MISSING_VERIFY_MESSAGE 174
1996#define SSL_R_MULTIPLE_SGC_RESTARTS 346 1996#define SSL_R_MULTIPLE_SGC_RESTARTS 346
1997#define SSL_R_NON_SSLV2_INITIAL_PACKET 175 1997#define SSL_R_NON_SSLV2_INITIAL_PACKET 175
1998#if defined(LIBRESSL_INTERNAL)
1999#define SSL_R_NO_APPLICATION_PROTOCOL 235
2000#endif
1998#define SSL_R_NO_CERTIFICATES_RETURNED 176 2001#define SSL_R_NO_CERTIFICATES_RETURNED 176
1999#define SSL_R_NO_CERTIFICATE_ASSIGNED 177 2002#define SSL_R_NO_CERTIFICATE_ASSIGNED 177
2000#define SSL_R_NO_CERTIFICATE_RETURNED 178 2003#define SSL_R_NO_CERTIFICATE_RETURNED 178
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c
index 8507690f79..9ea7cd469a 100644
--- a/src/lib/libssl/ssl_err.c
+++ b/src/lib/libssl/ssl_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_err.c,v 1.38 2021/05/16 08:24:21 jsing Exp $ */ 1/* $OpenBSD: ssl_err.c,v 1.39 2021/09/10 09:25:29 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -294,6 +294,7 @@ static ERR_STRING_DATA SSL_str_reasons[]= {
294 {ERR_REASON(SSL_R_MISSING_VERIFY_MESSAGE), "missing verify message"}, 294 {ERR_REASON(SSL_R_MISSING_VERIFY_MESSAGE), "missing verify message"},
295 {ERR_REASON(SSL_R_MULTIPLE_SGC_RESTARTS) , "multiple sgc restarts"}, 295 {ERR_REASON(SSL_R_MULTIPLE_SGC_RESTARTS) , "multiple sgc restarts"},
296 {ERR_REASON(SSL_R_NON_SSLV2_INITIAL_PACKET), "non sslv2 initial packet"}, 296 {ERR_REASON(SSL_R_NON_SSLV2_INITIAL_PACKET), "non sslv2 initial packet"},
297 {ERR_REASON(SSL_R_NO_APPLICATION_PROTOCOL), "no application protocol"},
297 {ERR_REASON(SSL_R_NO_CERTIFICATES_RETURNED), "no certificates returned"}, 298 {ERR_REASON(SSL_R_NO_CERTIFICATES_RETURNED), "no certificates returned"},
298 {ERR_REASON(SSL_R_NO_CERTIFICATE_ASSIGNED), "no certificate assigned"}, 299 {ERR_REASON(SSL_R_NO_CERTIFICATE_ASSIGNED), "no certificate assigned"},
299 {ERR_REASON(SSL_R_NO_CERTIFICATE_RETURNED), "no certificate returned"}, 300 {ERR_REASON(SSL_R_NO_CERTIFICATE_RETURNED), "no certificate returned"},
diff --git a/src/lib/libssl/ssl_tlsext.c b/src/lib/libssl/ssl_tlsext.c
index 4d426f1487..3ad564964d 100644
--- a/src/lib/libssl/ssl_tlsext.c
+++ b/src/lib/libssl/ssl_tlsext.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_tlsext.c,v 1.98 2021/09/02 11:10:43 beck Exp $ */ 1/* $OpenBSD: ssl_tlsext.c,v 1.99 2021/09/10 09:25:29 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2016, 2017, 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2016, 2017, 2019 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> 4 * Copyright (c) 2017 Doug Hogan <doug@openbsd.org>
@@ -85,9 +85,16 @@ tlsext_alpn_server_parse(SSL *s, uint16_t msg_types, CBS *cbs, int *alert)
85 if (s->ctx->internal->alpn_select_cb == NULL) 85 if (s->ctx->internal->alpn_select_cb == NULL)
86 return 1; 86 return 1;
87 87
88 /*
89 * XXX - A few things should be considered here:
90 * 1. Ensure that the same protocol is selected on session resumption.
91 * 2. Should the callback be called even if no ALPN extension was sent?
92 * 3. TLSv1.2 and earlier: ensure that SNI has already been processed.
93 */
88 r = s->ctx->internal->alpn_select_cb(s, &selected, &selected_len, 94 r = s->ctx->internal->alpn_select_cb(s, &selected, &selected_len,
89 CBS_data(&alpn), CBS_len(&alpn), 95 CBS_data(&alpn), CBS_len(&alpn),
90 s->ctx->internal->alpn_select_cb_arg); 96 s->ctx->internal->alpn_select_cb_arg);
97
91 if (r == SSL_TLSEXT_ERR_OK) { 98 if (r == SSL_TLSEXT_ERR_OK) {
92 free(S3I(s)->alpn_selected); 99 free(S3I(s)->alpn_selected);
93 if ((S3I(s)->alpn_selected = malloc(selected_len)) == NULL) { 100 if ((S3I(s)->alpn_selected = malloc(selected_len)) == NULL) {
@@ -97,9 +104,18 @@ tlsext_alpn_server_parse(SSL *s, uint16_t msg_types, CBS *cbs, int *alert)
97 } 104 }
98 memcpy(S3I(s)->alpn_selected, selected, selected_len); 105 memcpy(S3I(s)->alpn_selected, selected, selected_len);
99 S3I(s)->alpn_selected_len = selected_len; 106 S3I(s)->alpn_selected_len = selected_len;
107
108 return 1;
100 } 109 }
101 110
102 return 1; 111 /* On SSL_TLSEXT_ERR_NOACK behave as if no callback was present. */
112 if (r == SSL_TLSEXT_ERR_NOACK)
113 return 1;
114
115 *alert = SSL_AD_NO_APPLICATION_PROTOCOL;
116 SSLerror(s, SSL_R_NO_APPLICATION_PROTOCOL);
117
118 return 0;
103 119
104 err: 120 err:
105 *alert = SSL_AD_DECODE_ERROR; 121 *alert = SSL_AD_DECODE_ERROR;