summaryrefslogtreecommitdiff
path: root/src/lib/libssl/tls13_record_layer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/tls13_record_layer.c')
-rw-r--r--src/lib/libssl/tls13_record_layer.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/lib/libssl/tls13_record_layer.c b/src/lib/libssl/tls13_record_layer.c
index ce6327b694..9ea1a820ce 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.36 2020/05/09 15:47:11 jsing Exp $ */ 1/* $OpenBSD: tls13_record_layer.c,v 1.37 2020/05/10 16:56:11 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 *
@@ -268,13 +268,13 @@ tls13_record_layer_process_alert(struct tls13_record_layer *rl)
268 return TLS13_IO_FAILURE; 268 return TLS13_IO_FAILURE;
269 269
270 if (!CBS_get_u8(&rl->rbuf_cbs, &alert_level)) 270 if (!CBS_get_u8(&rl->rbuf_cbs, &alert_level))
271 return tls13_send_alert(rl, TLS1_AD_DECODE_ERROR); 271 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
272 272
273 if (!CBS_get_u8(&rl->rbuf_cbs, &alert_desc)) 273 if (!CBS_get_u8(&rl->rbuf_cbs, &alert_desc))
274 return tls13_send_alert(rl, TLS1_AD_DECODE_ERROR); 274 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
275 275
276 if (CBS_len(&rl->rbuf_cbs) != 0) 276 if (CBS_len(&rl->rbuf_cbs) != 0)
277 return tls13_send_alert(rl, TLS1_AD_DECODE_ERROR); 277 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
278 278
279 tls13_record_layer_rbuf_free(rl); 279 tls13_record_layer_rbuf_free(rl);
280 280
@@ -283,21 +283,22 @@ tls13_record_layer_process_alert(struct tls13_record_layer *rl)
283 * however for error alerts (RFC 8446 section 6.2), the alert level 283 * however for error alerts (RFC 8446 section 6.2), the alert level
284 * must be specified as fatal. 284 * must be specified as fatal.
285 */ 285 */
286 if (alert_desc == SSL_AD_CLOSE_NOTIFY) { 286 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY) {
287 rl->read_closed = 1; 287 rl->read_closed = 1;
288 ret = TLS13_IO_EOF; 288 ret = TLS13_IO_EOF;
289 } else if (alert_desc == SSL_AD_USER_CANCELLED) { 289 } else if (alert_desc == TLS13_ALERT_USER_CANCELED) {
290 /* Ignored at the record layer. */ 290 /* Ignored at the record layer. */
291 ret = TLS13_IO_WANT_RETRY; 291 ret = TLS13_IO_WANT_RETRY;
292 } else if (alert_level == SSL3_AL_FATAL) { 292 } else if (alert_level == TLS13_ALERT_LEVEL_FATAL) {
293 rl->read_closed = 1; 293 rl->read_closed = 1;
294 rl->write_closed = 1; 294 rl->write_closed = 1;
295 ret = TLS13_IO_ALERT; 295 ret = TLS13_IO_ALERT;
296 } else if (rl->legacy_alerts_allowed && alert_level == SSL3_AL_WARNING) { 296 } else if (rl->legacy_alerts_allowed &&
297 alert_level == TLS13_ALERT_LEVEL_WARNING) {
297 /* Ignored and not passed to the callback. */ 298 /* Ignored and not passed to the callback. */
298 return TLS13_IO_WANT_RETRY; 299 return TLS13_IO_WANT_RETRY;
299 } else { 300 } else {
300 return tls13_send_alert(rl, SSL_AD_ILLEGAL_PARAMETER); 301 return tls13_send_alert(rl, TLS13_ALERT_ILLEGAL_PARAMETER);
301 } 302 }
302 303
303 rl->alert_cb(alert_desc, rl->cb_arg); 304 rl->alert_cb(alert_desc, rl->cb_arg);
@@ -322,10 +323,10 @@ tls13_record_layer_send_alert(struct tls13_record_layer *rl)
322 rl->alert_data = NULL; 323 rl->alert_data = NULL;
323 rl->alert_len = 0; 324 rl->alert_len = 0;
324 325
325 if (rl->alert_desc == SSL_AD_CLOSE_NOTIFY) { 326 if (rl->alert_desc == TLS13_ALERT_CLOSE_NOTIFY) {
326 rl->write_closed = 1; 327 rl->write_closed = 1;
327 ret = TLS13_IO_SUCCESS; 328 ret = TLS13_IO_SUCCESS;
328 } else if (rl->alert_desc == SSL_AD_USER_CANCELLED) { 329 } else if (rl->alert_desc == TLS13_ALERT_USER_CANCELED) {
329 /* Ignored at the record layer. */ 330 /* Ignored at the record layer. */
330 ret = TLS13_IO_SUCCESS; 331 ret = TLS13_IO_SUCCESS;
331 } else { 332 } else {
@@ -796,13 +797,13 @@ tls13_record_layer_read_record(struct tls13_record_layer *rl)
796 */ 797 */
797 if (content_type == SSL3_RT_CHANGE_CIPHER_SPEC) { 798 if (content_type == SSL3_RT_CHANGE_CIPHER_SPEC) {
798 if (!rl->ccs_allowed || rl->ccs_seen >= 2) 799 if (!rl->ccs_allowed || rl->ccs_seen >= 2)
799 return tls13_send_alert(rl, SSL_AD_UNEXPECTED_MESSAGE); 800 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
800 if (!tls13_record_content(rl->rrec, &cbs)) 801 if (!tls13_record_content(rl->rrec, &cbs))
801 return tls13_send_alert(rl, TLS1_AD_DECODE_ERROR); 802 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
802 if (!CBS_get_u8(&cbs, &ccs)) 803 if (!CBS_get_u8(&cbs, &ccs))
803 return tls13_send_alert(rl, TLS1_AD_DECODE_ERROR); 804 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
804 if (ccs != 1) 805 if (ccs != 1)
805 return tls13_send_alert(rl, SSL_AD_ILLEGAL_PARAMETER); 806 return tls13_send_alert(rl, TLS13_ALERT_ILLEGAL_PARAMETER);
806 rl->ccs_seen++; 807 rl->ccs_seen++;
807 tls13_record_layer_rrec_free(rl); 808 tls13_record_layer_rrec_free(rl);
808 return TLS13_IO_WANT_RETRY; 809 return TLS13_IO_WANT_RETRY;
@@ -814,7 +815,7 @@ tls13_record_layer_read_record(struct tls13_record_layer *rl)
814 * dummy ChangeCipherSpec messages, handled above). 815 * dummy ChangeCipherSpec messages, handled above).
815 */ 816 */
816 if (rl->aead != NULL && content_type != SSL3_RT_APPLICATION_DATA) 817 if (rl->aead != NULL && content_type != SSL3_RT_APPLICATION_DATA)
817 return tls13_send_alert(rl, SSL3_AD_UNEXPECTED_MESSAGE); 818 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
818 819
819 if (!tls13_record_layer_open_record(rl)) 820 if (!tls13_record_layer_open_record(rl))
820 goto err; 821 goto err;
@@ -829,7 +830,7 @@ tls13_record_layer_read_record(struct tls13_record_layer *rl)
829 if (CBS_len(&rl->rbuf_cbs) == 0 && 830 if (CBS_len(&rl->rbuf_cbs) == 0 &&
830 (rl->rbuf_content_type == SSL3_RT_ALERT || 831 (rl->rbuf_content_type == SSL3_RT_ALERT ||
831 rl->rbuf_content_type == SSL3_RT_HANDSHAKE)) 832 rl->rbuf_content_type == SSL3_RT_HANDSHAKE))
832 return tls13_send_alert(rl, SSL3_AD_UNEXPECTED_MESSAGE); 833 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
833 834
834 switch (rl->rbuf_content_type) { 835 switch (rl->rbuf_content_type) {
835 case SSL3_RT_ALERT: 836 case SSL3_RT_ALERT:
@@ -840,11 +841,11 @@ tls13_record_layer_read_record(struct tls13_record_layer *rl)
840 841
841 case SSL3_RT_APPLICATION_DATA: 842 case SSL3_RT_APPLICATION_DATA:
842 if (!rl->handshake_completed) 843 if (!rl->handshake_completed)
843 return tls13_send_alert(rl, SSL3_AD_UNEXPECTED_MESSAGE); 844 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
844 break; 845 break;
845 846
846 default: 847 default:
847 return tls13_send_alert(rl, SSL3_AD_UNEXPECTED_MESSAGE); 848 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
848 } 849 }
849 850
850 return TLS13_IO_SUCCESS; 851 return TLS13_IO_SUCCESS;
@@ -887,7 +888,7 @@ tls13_record_layer_read_internal(struct tls13_record_layer *rl,
887 * any record type that isn't a handshake until we are done. 888 * any record type that isn't a handshake until we are done.
888 */ 889 */
889 if (rl->phh && rl->rbuf_content_type != SSL3_RT_HANDSHAKE) 890 if (rl->phh && rl->rbuf_content_type != SSL3_RT_HANDSHAKE)
890 return tls13_send_alert(rl, SSL3_AD_UNEXPECTED_MESSAGE); 891 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
891 892
892 if (rl->rbuf_content_type != content_type) { 893 if (rl->rbuf_content_type != content_type) {
893 /* 894 /*
@@ -941,7 +942,7 @@ tls13_record_layer_read_internal(struct tls13_record_layer *rl,
941 } 942 }
942 } 943 }
943 944
944 return tls13_send_alert(rl, SSL3_AD_UNEXPECTED_MESSAGE); 945 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
945 } 946 }
946 947
947 if (n > CBS_len(&rl->rbuf_cbs)) 948 if (n > CBS_len(&rl->rbuf_cbs))
@@ -1151,12 +1152,12 @@ tls13_write_application_data(struct tls13_record_layer *rl, const uint8_t *buf,
1151ssize_t 1152ssize_t
1152tls13_send_alert(struct tls13_record_layer *rl, uint8_t alert_desc) 1153tls13_send_alert(struct tls13_record_layer *rl, uint8_t alert_desc)
1153{ 1154{
1154 uint8_t alert_level = SSL3_AL_FATAL; 1155 uint8_t alert_level = TLS13_ALERT_LEVEL_FATAL;
1155 ssize_t ret; 1156 ssize_t ret;
1156 1157
1157 if (alert_desc == SSL_AD_CLOSE_NOTIFY || 1158 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY ||
1158 alert_desc == SSL_AD_USER_CANCELLED) 1159 alert_desc == TLS13_ALERT_USER_CANCELED)
1159 alert_level = SSL3_AL_WARNING; 1160 alert_level = TLS13_ALERT_LEVEL_WARNING;
1160 1161
1161 do { 1162 do {
1162 ret = tls13_record_layer_alert(rl, alert_level, alert_desc); 1163 ret = tls13_record_layer_alert(rl, alert_level, alert_desc);