diff options
-rw-r--r-- | lib/libssl/tls13_internal.h | 16 | ||||
-rw-r--r-- | lib/libssl/tls13_lib.c | 14 | ||||
-rw-r--r-- | lib/libssl/tls13_record_layer.c | 38 |
3 files changed, 33 insertions, 35 deletions
diff --git a/lib/libssl/tls13_internal.h b/lib/libssl/tls13_internal.h index 7ec166f3fa1..764b58b00b6 100644 --- a/lib/libssl/tls13_internal.h +++ b/lib/libssl/tls13_internal.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_internal.h,v 1.75 2020/05/10 17:13:30 tb Exp $ */ +/* $OpenBSD: tls13_internal.h,v 1.76 2020/05/11 17:28:33 jsing Exp $ */ /* * Copyright (c) 2018 Bob Beck <beck@openbsd.org> * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> @@ -174,10 +174,16 @@ int tls13_key_share_derive(struct tls13_key_share *ks, uint8_t **shared_key, */ struct tls13_record_layer; -struct tls13_record_layer *tls13_record_layer_new(tls13_read_cb wire_read, - tls13_write_cb wire_write, tls13_alert_cb alert_cb, - tls13_phh_recv_cb phh_recv_cb, - tls13_phh_sent_cb phh_sent_cb, void *cb_arg); +struct tls13_record_layer_callbacks { + tls13_read_cb wire_read; + tls13_write_cb wire_write; + tls13_alert_cb alert_recv; + tls13_phh_recv_cb phh_recv; + tls13_phh_sent_cb phh_sent; +}; + +struct tls13_record_layer *tls13_record_layer_new( + const struct tls13_record_layer_callbacks *callbacks, void *cb_arg); void tls13_record_layer_free(struct tls13_record_layer *rl); void tls13_record_layer_allow_ccs(struct tls13_record_layer *rl, int allow); void tls13_record_layer_allow_legacy_alerts(struct tls13_record_layer *rl, int allow); diff --git a/lib/libssl/tls13_lib.c b/lib/libssl/tls13_lib.c index d3e4050c1e0..f096fe633ec 100644 --- a/lib/libssl/tls13_lib.c +++ b/lib/libssl/tls13_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_lib.c,v 1.41 2020/05/10 16:56:11 jsing Exp $ */ +/* $OpenBSD: tls13_lib.c,v 1.42 2020/05/11 17:28:33 jsing Exp $ */ /* * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> * Copyright (c) 2019 Bob Beck <beck@openbsd.org> @@ -332,6 +332,14 @@ tls13_phh_received_cb(void *cb_arg, CBS *cbs) return ret; } +static const struct tls13_record_layer_callbacks rl_callbacks = { + .wire_read = tls13_legacy_wire_read_cb, + .wire_write = tls13_legacy_wire_write_cb, + .alert_recv = tls13_alert_received_cb, + .phh_recv = tls13_phh_received_cb, + .phh_sent = tls13_phh_done_cb, +}; + struct tls13_ctx * tls13_ctx_new(int mode) { @@ -342,9 +350,7 @@ tls13_ctx_new(int mode) ctx->mode = mode; - if ((ctx->rl = tls13_record_layer_new(tls13_legacy_wire_read_cb, - tls13_legacy_wire_write_cb, tls13_alert_received_cb, - tls13_phh_received_cb, tls13_phh_done_cb, ctx)) == NULL) + if ((ctx->rl = tls13_record_layer_new(&rl_callbacks, ctx)) == NULL) goto err; ctx->handshake_message_sent_cb = tls13_legacy_handshake_message_sent_cb; diff --git a/lib/libssl/tls13_record_layer.c b/lib/libssl/tls13_record_layer.c index 9ea1a820ce7..62b32e4631e 100644 --- a/lib/libssl/tls13_record_layer.c +++ b/lib/libssl/tls13_record_layer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_record_layer.c,v 1.37 2020/05/10 16:56:11 jsing Exp $ */ +/* $OpenBSD: tls13_record_layer.c,v 1.38 2020/05/11 17:28:33 jsing Exp $ */ /* * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> * @@ -80,14 +80,8 @@ struct tls13_record_layer { uint8_t read_seq_num[TLS13_RECORD_SEQ_NUM_LEN]; uint8_t write_seq_num[TLS13_RECORD_SEQ_NUM_LEN]; - /* Record callbacks. */ - tls13_alert_cb alert_cb; - tls13_phh_recv_cb phh_recv_cb; - tls13_phh_sent_cb phh_sent_cb; - - /* Wire read/write callbacks. */ - tls13_read_cb wire_read; - tls13_write_cb wire_write; + /* Callbacks. */ + struct tls13_record_layer_callbacks cb; void *cb_arg; }; @@ -116,10 +110,7 @@ tls13_record_layer_wrec_free(struct tls13_record_layer *rl) } struct tls13_record_layer * -tls13_record_layer_new(tls13_read_cb wire_read, tls13_write_cb wire_write, - tls13_alert_cb alert_cb, - tls13_phh_recv_cb phh_recv_cb, - tls13_phh_sent_cb phh_sent_cb, +tls13_record_layer_new(const struct tls13_record_layer_callbacks *callbacks, void *cb_arg) { struct tls13_record_layer *rl; @@ -128,12 +119,7 @@ tls13_record_layer_new(tls13_read_cb wire_read, tls13_write_cb wire_write, return NULL; rl->legacy_version = TLS1_2_VERSION; - - rl->wire_read = wire_read; - rl->wire_write = wire_write; - rl->alert_cb = alert_cb; - rl->phh_recv_cb = phh_recv_cb; - rl->phh_sent_cb = phh_sent_cb; + rl->cb = *callbacks; rl->cb_arg = cb_arg; return rl; @@ -301,7 +287,7 @@ tls13_record_layer_process_alert(struct tls13_record_layer *rl) return tls13_send_alert(rl, TLS13_ALERT_ILLEGAL_PARAMETER); } - rl->alert_cb(alert_desc, rl->cb_arg); + rl->cb.alert_recv(alert_desc, rl->cb_arg); return ret; } @@ -358,7 +344,7 @@ tls13_record_layer_send_phh(struct tls13_record_layer *rl) CBS_init(&rl->phh_cbs, rl->phh_data, rl->phh_len); - rl->phh_sent_cb(rl->cb_arg); + rl->cb.phh_sent(rl->cb_arg); return TLS13_IO_SUCCESS; } @@ -781,7 +767,7 @@ tls13_record_layer_read_record(struct tls13_record_layer *rl) goto err; } - if ((ret = tls13_record_recv(rl->rrec, rl->wire_read, rl->cb_arg)) <= 0) + if ((ret = tls13_record_recv(rl->rrec, rl->cb.wire_read, rl->cb_arg)) <= 0) return ret; /* XXX - record version checks. */ @@ -919,8 +905,8 @@ tls13_record_layer_read_internal(struct tls13_record_layer *rl, * * TLS13_IO_FAILURE -> something broke. */ - if (rl->phh_recv_cb != NULL) { - ret = rl->phh_recv_cb( + if (rl->cb.phh_recv != NULL) { + ret = rl->cb.phh_recv( rl->cb_arg, &rl->rbuf_cbs); } @@ -1013,7 +999,7 @@ tls13_record_layer_write_record(struct tls13_record_layer *rl, /* See if there is an existing record and attempt to push it out... */ if (rl->wrec != NULL) { - if ((ret = tls13_record_send(rl->wrec, rl->wire_write, + if ((ret = tls13_record_send(rl->wrec, rl->cb.wire_write, rl->cb_arg)) <= 0) return ret; tls13_record_layer_wrec_free(rl); @@ -1040,7 +1026,7 @@ tls13_record_layer_write_record(struct tls13_record_layer *rl, if (!tls13_record_layer_seal_record(rl, content_type, content, content_len)) goto err; - if ((ret = tls13_record_send(rl->wrec, rl->wire_write, rl->cb_arg)) <= 0) + if ((ret = tls13_record_send(rl->wrec, rl->cb.wire_write, rl->cb_arg)) <= 0) return ret; tls13_record_layer_wrec_free(rl); |