summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2020-01-25 09:20:56 +0000
committerjsing <>2020-01-25 09:20:56 +0000
commit6b9adcf89cc2130fb9b26ac8e68e18a16ae477b7 (patch)
treebcc235a6daebd39d649e02f89e58cc75116ad6c0 /src/lib
parent8ef6d5699390cd817ba24c3f8f8a670d68b744af (diff)
downloadopenbsd-6b9adcf89cc2130fb9b26ac8e68e18a16ae477b7.tar.gz
openbsd-6b9adcf89cc2130fb9b26ac8e68e18a16ae477b7.tar.bz2
openbsd-6b9adcf89cc2130fb9b26ac8e68e18a16ae477b7.zip
It is possible to receive a pre-TLSv1.3 alert in response to a TLSv1.3
client hello. Allow pre-TLSv1.3 alerts (including warnings) to be received before the server hello message. Disallow pre-TLSv1.3 alerts as soon as we know that we are using TLSv1.3. Noticed by ajacoutot@ while connecting to www.openprinting.org. ok tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/tls13_client.c8
-rw-r--r--src/lib/libssl/tls13_internal.h3
-rw-r--r--src/lib/libssl/tls13_record_layer.c17
3 files changed, 24 insertions, 4 deletions
diff --git a/src/lib/libssl/tls13_client.c b/src/lib/libssl/tls13_client.c
index 20b3038b93..737a1015a5 100644
--- a/src/lib/libssl/tls13_client.c
+++ b/src/lib/libssl/tls13_client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_client.c,v 1.32 2020/01/23 11:06:59 beck Exp $ */ 1/* $OpenBSD: tls13_client.c,v 1.33 2020/01/25 09:20:56 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -209,6 +209,9 @@ tls13_client_hello_send(struct tls13_ctx *ctx, CBB *cbb)
209 if (ctx->hs->min_version < TLS1_2_VERSION) 209 if (ctx->hs->min_version < TLS1_2_VERSION)
210 tls13_record_layer_set_legacy_version(ctx->rl, TLS1_VERSION); 210 tls13_record_layer_set_legacy_version(ctx->rl, TLS1_VERSION);
211 211
212 /* We may receive a pre-TLSv1.3 alert in response to the client hello. */
213 tls13_record_layer_allow_legacy_alerts(ctx->rl, 1);
214
212 if (!tls13_client_hello_build(ctx, cbb)) 215 if (!tls13_client_hello_build(ctx, cbb))
213 return 0; 216 return 0;
214 217
@@ -306,6 +309,9 @@ tls13_server_hello_process(struct tls13_ctx *ctx, CBS *cbs)
306 return tls13_use_legacy_client(ctx); 309 return tls13_use_legacy_client(ctx);
307 } 310 }
308 311
312 /* From here on in we know we are doing TLSv1.3. */
313 tls13_record_layer_allow_legacy_alerts(ctx->rl, 0);
314
309 if (!tlsext_client_parse(s, cbs, &alert_desc, SSL_TLSEXT_MSG_SH)) { 315 if (!tlsext_client_parse(s, cbs, &alert_desc, SSL_TLSEXT_MSG_SH)) {
310 ctx->alert = alert_desc; 316 ctx->alert = alert_desc;
311 goto err; 317 goto err;
diff --git a/src/lib/libssl/tls13_internal.h b/src/lib/libssl/tls13_internal.h
index 4ff2df6e97..9aabc409d8 100644
--- a/src/lib/libssl/tls13_internal.h
+++ b/src/lib/libssl/tls13_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_internal.h,v 1.53 2020/01/24 08:21:24 jsing Exp $ */ 1/* $OpenBSD: tls13_internal.h,v 1.54 2020/01/25 09:20:56 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org>
4 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
@@ -122,6 +122,7 @@ struct tls13_record_layer *tls13_record_layer_new(tls13_read_cb wire_read,
122 tls13_phh_sent_cb phh_sent_cb, void *cb_arg); 122 tls13_phh_sent_cb phh_sent_cb, void *cb_arg);
123void tls13_record_layer_free(struct tls13_record_layer *rl); 123void tls13_record_layer_free(struct tls13_record_layer *rl);
124void tls13_record_layer_allow_ccs(struct tls13_record_layer *rl, int allow); 124void tls13_record_layer_allow_ccs(struct tls13_record_layer *rl, int allow);
125void tls13_record_layer_allow_legacy_alerts(struct tls13_record_layer *rl, int allow);
125void tls13_record_layer_rbuf(struct tls13_record_layer *rl, CBS *cbs); 126void tls13_record_layer_rbuf(struct tls13_record_layer *rl, CBS *cbs);
126void tls13_record_layer_set_aead(struct tls13_record_layer *rl, 127void tls13_record_layer_set_aead(struct tls13_record_layer *rl,
127 const EVP_AEAD *aead); 128 const EVP_AEAD *aead);
diff --git a/src/lib/libssl/tls13_record_layer.c b/src/lib/libssl/tls13_record_layer.c
index e5f8ba8859..7d882924bc 100644
--- a/src/lib/libssl/tls13_record_layer.c
+++ b/src/lib/libssl/tls13_record_layer.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_record_layer.c,v 1.25 2020/01/24 04:36:29 beck Exp $ */ 1/* $OpenBSD: tls13_record_layer.c,v 1.26 2020/01/25 09:20:56 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -29,9 +29,11 @@ static ssize_t tls13_record_layer_write_record(struct tls13_record_layer *rl,
29 29
30struct tls13_record_layer { 30struct tls13_record_layer {
31 uint16_t legacy_version; 31 uint16_t legacy_version;
32
32 int ccs_allowed; 33 int ccs_allowed;
33 int ccs_seen; 34 int ccs_seen;
34 int handshake_completed; 35 int handshake_completed;
36 int legacy_alerts_allowed;
35 int phh; 37 int phh;
36 38
37 /* 39 /*
@@ -207,6 +209,12 @@ tls13_record_layer_allow_ccs(struct tls13_record_layer *rl, int allow)
207} 209}
208 210
209void 211void
212tls13_record_layer_allow_legacy_alerts(struct tls13_record_layer *rl, int allow)
213{
214 rl->legacy_alerts_allowed = allow;
215}
216
217void
210tls13_record_layer_set_aead(struct tls13_record_layer *rl, 218tls13_record_layer_set_aead(struct tls13_record_layer *rl,
211 const EVP_AEAD *aead) 219 const EVP_AEAD *aead)
212{ 220{
@@ -279,10 +287,15 @@ tls13_record_layer_process_alert(struct tls13_record_layer *rl)
279 rl->read_closed = 1; 287 rl->read_closed = 1;
280 rl->write_closed = 1; 288 rl->write_closed = 1;
281 ret = TLS13_IO_ALERT; 289 ret = TLS13_IO_ALERT;
282 } else 290 } else if (rl->legacy_alerts_allowed && alert_level == SSL3_AL_WARNING) {
291 /* Ignored and not passed to the callback. */
292 return TLS13_IO_WANT_RETRY;
293 } else {
283 return tls13_send_alert(rl, SSL_AD_ILLEGAL_PARAMETER); 294 return tls13_send_alert(rl, SSL_AD_ILLEGAL_PARAMETER);
295 }
284 296
285 rl->alert_cb(alert_desc, rl->cb_arg); 297 rl->alert_cb(alert_desc, rl->cb_arg);
298
286 return ret; 299 return ret;
287} 300}
288 301