diff options
author | jsing <> | 2021-08-30 19:25:43 +0000 |
---|---|---|
committer | jsing <> | 2021-08-30 19:25:43 +0000 |
commit | a376b9cd8ffd396f270e597131a83af4f639bd93 (patch) | |
tree | 8e3bea79ab1dea102b95252a7e2c36c06522e41d /src/lib | |
parent | cedbde20c0ecfb870c00ce4fe4401f89a9397b6d (diff) | |
download | openbsd-a376b9cd8ffd396f270e597131a83af4f639bd93.tar.gz openbsd-a376b9cd8ffd396f270e597131a83af4f639bd93.tar.bz2 openbsd-a376b9cd8ffd396f270e597131a83af4f639bd93.zip |
Clean up and simplify info and msg callbacks.
The info and msg callbacks result in duplication - both for code that
refers to the function pointers and for the call sites. Avoid this by
providing typedefs for the function pointers and pulling the calling
sequences into their own functions.
ok inoguchi@ tb@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libssl/d1_pkt.c | 29 | ||||
-rw-r--r-- | src/lib/libssl/ssl_both.c | 22 | ||||
-rw-r--r-- | src/lib/libssl/ssl_clnt.c | 24 | ||||
-rw-r--r-- | src/lib/libssl/ssl_lib.c | 30 | ||||
-rw-r--r-- | src/lib/libssl/ssl_locl.h | 27 | ||||
-rw-r--r-- | src/lib/libssl/ssl_pkt.c | 45 | ||||
-rw-r--r-- | src/lib/libssl/ssl_srvr.c | 24 | ||||
-rw-r--r-- | src/lib/libssl/tls13_lib.c | 14 |
8 files changed, 88 insertions, 127 deletions
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c index 4f0678f0b8..f99b8ff371 100644 --- a/src/lib/libssl/d1_pkt.c +++ b/src/lib/libssl/d1_pkt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: d1_pkt.c,v 1.106 2021/08/30 19:12:25 jsing Exp $ */ | 1 | /* $OpenBSD: d1_pkt.c,v 1.107 2021/08/30 19:25:43 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * DTLS implementation written by Nagendra Modadugu | 3 | * DTLS implementation written by Nagendra Modadugu |
4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. |
@@ -515,10 +515,9 @@ dtls1_get_record(SSL *s) | |||
515 | int | 515 | int |
516 | dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | 516 | dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) |
517 | { | 517 | { |
518 | int al, i, j, ret; | 518 | int al, i, ret; |
519 | unsigned int n; | 519 | unsigned int n; |
520 | SSL3_RECORD_INTERNAL *rr; | 520 | SSL3_RECORD_INTERNAL *rr; |
521 | void (*cb)(const SSL *ssl, int type2, int val) = NULL; | ||
522 | 521 | ||
523 | if (S3I(s)->rbuf.buf == NULL) /* Not initialized yet */ | 522 | if (S3I(s)->rbuf.buf == NULL) /* Not initialized yet */ |
524 | if (!ssl3_setup_buffers(s)) | 523 | if (!ssl3_setup_buffers(s)) |
@@ -727,9 +726,8 @@ dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | |||
727 | 726 | ||
728 | /* no need to check sequence number on HELLO REQUEST messages */ | 727 | /* no need to check sequence number on HELLO REQUEST messages */ |
729 | 728 | ||
730 | if (s->internal->msg_callback) | 729 | ssl_msg_callback(s, 0, SSL3_RT_HANDSHAKE, |
731 | s->internal->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, | 730 | D1I(s)->handshake_fragment, 4); |
732 | D1I(s)->handshake_fragment, 4, s, s->internal->msg_callback_arg); | ||
733 | 731 | ||
734 | if (SSL_is_init_finished(s) && | 732 | if (SSL_is_init_finished(s) && |
735 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) && | 733 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) && |
@@ -774,19 +772,10 @@ dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | |||
774 | 772 | ||
775 | D1I(s)->alert_fragment_len = 0; | 773 | D1I(s)->alert_fragment_len = 0; |
776 | 774 | ||
777 | if (s->internal->msg_callback) | 775 | ssl_msg_callback(s, 0, SSL3_RT_ALERT, D1I(s)->alert_fragment, 2); |
778 | s->internal->msg_callback(0, s->version, SSL3_RT_ALERT, | ||
779 | D1I(s)->alert_fragment, 2, s, s->internal->msg_callback_arg); | ||
780 | 776 | ||
781 | if (s->internal->info_callback != NULL) | 777 | ssl_info_callback(s, SSL_CB_READ_ALERT, |
782 | cb = s->internal->info_callback; | 778 | (alert_level << 8) | alert_descr); |
783 | else if (s->ctx->internal->info_callback != NULL) | ||
784 | cb = s->ctx->internal->info_callback; | ||
785 | |||
786 | if (cb != NULL) { | ||
787 | j = (alert_level << 8) | alert_descr; | ||
788 | cb(s, SSL_CB_READ_ALERT, j); | ||
789 | } | ||
790 | 779 | ||
791 | if (alert_level == SSL3_AL_WARNING) { | 780 | if (alert_level == SSL3_AL_WARNING) { |
792 | S3I(s)->warn_alert = alert_descr; | 781 | S3I(s)->warn_alert = alert_descr; |
@@ -832,9 +821,7 @@ dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | |||
832 | 821 | ||
833 | rr->length = 0; | 822 | rr->length = 0; |
834 | 823 | ||
835 | if (s->internal->msg_callback) | 824 | ssl_msg_callback(s, 0, SSL3_RT_CHANGE_CIPHER_SPEC, rr->data, 1); |
836 | s->internal->msg_callback(0, s->version, SSL3_RT_CHANGE_CIPHER_SPEC, | ||
837 | rr->data, 1, s, s->internal->msg_callback_arg); | ||
838 | 825 | ||
839 | /* We can't process a CCS now, because previous handshake | 826 | /* We can't process a CCS now, because previous handshake |
840 | * messages are still missing, so just drop it. | 827 | * messages are still missing, so just drop it. |
diff --git a/src/lib/libssl/ssl_both.c b/src/lib/libssl/ssl_both.c index 03c5a2f1e9..e4834f23dc 100644 --- a/src/lib/libssl/ssl_both.c +++ b/src/lib/libssl/ssl_both.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_both.c,v 1.33 2021/07/01 17:53:39 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_both.c,v 1.34 2021/08/30 19:25:43 jsing 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 | * |
@@ -150,10 +150,8 @@ ssl3_do_write(SSL *s, int type) | |||
150 | (unsigned char *)&s->internal->init_buf->data[s->internal->init_off], ret); | 150 | (unsigned char *)&s->internal->init_buf->data[s->internal->init_off], ret); |
151 | 151 | ||
152 | if (ret == s->internal->init_num) { | 152 | if (ret == s->internal->init_num) { |
153 | if (s->internal->msg_callback) | 153 | ssl_msg_callback(s, 1, type, s->internal->init_buf->data, |
154 | s->internal->msg_callback(1, s->version, type, s->internal->init_buf->data, | 154 | (size_t)(s->internal->init_off + s->internal->init_num)); |
155 | (size_t)(s->internal->init_off + s->internal->init_num), s, | ||
156 | s->internal->msg_callback_arg); | ||
157 | return (1); | 155 | return (1); |
158 | } | 156 | } |
159 | 157 | ||
@@ -456,10 +454,8 @@ ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | |||
456 | s->internal->init_num = 0; | 454 | s->internal->init_num = 0; |
457 | skip_message = 1; | 455 | skip_message = 1; |
458 | 456 | ||
459 | if (s->internal->msg_callback) | 457 | ssl_msg_callback(s, 0, |
460 | s->internal->msg_callback(0, s->version, | 458 | SSL3_RT_HANDSHAKE, p, 4); |
461 | SSL3_RT_HANDSHAKE, p, 4, s, | ||
462 | s->internal->msg_callback_arg); | ||
463 | } | 459 | } |
464 | } | 460 | } |
465 | } while (skip_message); | 461 | } while (skip_message); |
@@ -516,11 +512,9 @@ ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | |||
516 | tls1_transcript_record(s, (unsigned char *)s->internal->init_buf->data, | 512 | tls1_transcript_record(s, (unsigned char *)s->internal->init_buf->data, |
517 | s->internal->init_num + 4); | 513 | s->internal->init_num + 4); |
518 | 514 | ||
519 | if (s->internal->msg_callback) | 515 | ssl_msg_callback(s, 0, SSL3_RT_HANDSHAKE, |
520 | s->internal->msg_callback(0, s->version, | 516 | s->internal->init_buf->data, |
521 | SSL3_RT_HANDSHAKE, s->internal->init_buf->data, | 517 | (size_t)s->internal->init_num + 4); |
522 | (size_t)s->internal->init_num + 4, s, | ||
523 | s->internal->msg_callback_arg); | ||
524 | } | 518 | } |
525 | 519 | ||
526 | *ok = 1; | 520 | *ok = 1; |
diff --git a/src/lib/libssl/ssl_clnt.c b/src/lib/libssl/ssl_clnt.c index 8864909c9e..519e823354 100644 --- a/src/lib/libssl/ssl_clnt.c +++ b/src/lib/libssl/ssl_clnt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_clnt.c,v 1.107 2021/06/30 09:59:07 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_clnt.c,v 1.108 2021/08/30 19:25:43 jsing 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 | * |
@@ -179,18 +179,12 @@ static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b); | |||
179 | int | 179 | int |
180 | ssl3_connect(SSL *s) | 180 | ssl3_connect(SSL *s) |
181 | { | 181 | { |
182 | void (*cb)(const SSL *ssl, int type, int val) = NULL; | ||
183 | int ret = -1; | ||
184 | int new_state, state, skip = 0; | 182 | int new_state, state, skip = 0; |
183 | int ret = -1; | ||
185 | 184 | ||
186 | ERR_clear_error(); | 185 | ERR_clear_error(); |
187 | errno = 0; | 186 | errno = 0; |
188 | 187 | ||
189 | if (s->internal->info_callback != NULL) | ||
190 | cb = s->internal->info_callback; | ||
191 | else if (s->ctx->internal->info_callback != NULL) | ||
192 | cb = s->ctx->internal->info_callback; | ||
193 | |||
194 | s->internal->in_handshake++; | 188 | s->internal->in_handshake++; |
195 | if (!SSL_in_init(s) || SSL_in_before(s)) | 189 | if (!SSL_in_init(s) || SSL_in_before(s)) |
196 | SSL_clear(s); | 190 | SSL_clear(s); |
@@ -210,8 +204,8 @@ ssl3_connect(SSL *s) | |||
210 | case SSL_ST_OK|SSL_ST_CONNECT: | 204 | case SSL_ST_OK|SSL_ST_CONNECT: |
211 | 205 | ||
212 | s->server = 0; | 206 | s->server = 0; |
213 | if (cb != NULL) | 207 | |
214 | cb(s, SSL_CB_HANDSHAKE_START, 1); | 208 | ssl_info_callback(s, SSL_CB_HANDSHAKE_START, 1); |
215 | 209 | ||
216 | if (!ssl_legacy_stack_version(s, s->version)) { | 210 | if (!ssl_legacy_stack_version(s, s->version)) { |
217 | SSLerror(s, ERR_R_INTERNAL_ERROR); | 211 | SSLerror(s, ERR_R_INTERNAL_ERROR); |
@@ -597,8 +591,7 @@ ssl3_connect(SSL *s) | |||
597 | s->internal->handshake_func = ssl3_connect; | 591 | s->internal->handshake_func = ssl3_connect; |
598 | s->ctx->internal->stats.sess_connect_good++; | 592 | s->ctx->internal->stats.sess_connect_good++; |
599 | 593 | ||
600 | if (cb != NULL) | 594 | ssl_info_callback(s, SSL_CB_HANDSHAKE_DONE, 1); |
601 | cb(s, SSL_CB_HANDSHAKE_DONE, 1); | ||
602 | 595 | ||
603 | if (SSL_is_dtls(s)) { | 596 | if (SSL_is_dtls(s)) { |
604 | /* done with handshaking */ | 597 | /* done with handshaking */ |
@@ -623,10 +616,10 @@ ssl3_connect(SSL *s) | |||
623 | goto end; | 616 | goto end; |
624 | } | 617 | } |
625 | 618 | ||
626 | if ((cb != NULL) && (S3I(s)->hs.state != state)) { | 619 | if (S3I(s)->hs.state != state) { |
627 | new_state = S3I(s)->hs.state; | 620 | new_state = S3I(s)->hs.state; |
628 | S3I(s)->hs.state = state; | 621 | S3I(s)->hs.state = state; |
629 | cb(s, SSL_CB_CONNECT_LOOP, 1); | 622 | ssl_info_callback(s, SSL_CB_CONNECT_LOOP, 1); |
630 | S3I(s)->hs.state = new_state; | 623 | S3I(s)->hs.state = new_state; |
631 | } | 624 | } |
632 | } | 625 | } |
@@ -635,8 +628,7 @@ ssl3_connect(SSL *s) | |||
635 | 628 | ||
636 | end: | 629 | end: |
637 | s->internal->in_handshake--; | 630 | s->internal->in_handshake--; |
638 | if (cb != NULL) | 631 | ssl_info_callback(s, SSL_CB_CONNECT_EXIT, ret); |
639 | cb(s, SSL_CB_CONNECT_EXIT, ret); | ||
640 | 632 | ||
641 | return (ret); | 633 | return (ret); |
642 | } | 634 | } |
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index bb4b700e0b..c5cc6d05fa 100644 --- a/src/lib/libssl/ssl_lib.c +++ b/src/lib/libssl/ssl_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_lib.c,v 1.262 2021/07/01 17:53:39 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_lib.c,v 1.263 2021/08/30 19:25:43 jsing 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 | * |
@@ -1184,9 +1184,7 @@ SSL_callback_ctrl(SSL *s, int cmd, void (*fp)(void)) | |||
1184 | { | 1184 | { |
1185 | switch (cmd) { | 1185 | switch (cmd) { |
1186 | case SSL_CTRL_SET_MSG_CALLBACK: | 1186 | case SSL_CTRL_SET_MSG_CALLBACK: |
1187 | s->internal->msg_callback = (void (*)(int write_p, int version, | 1187 | s->internal->msg_callback = (ssl_msg_callback_fn *)(fp); |
1188 | int content_type, const void *buf, size_t len, | ||
1189 | SSL *ssl, void *arg))(fp); | ||
1190 | return (1); | 1188 | return (1); |
1191 | 1189 | ||
1192 | default: | 1190 | default: |
@@ -1284,9 +1282,7 @@ SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void)) | |||
1284 | { | 1282 | { |
1285 | switch (cmd) { | 1283 | switch (cmd) { |
1286 | case SSL_CTRL_SET_MSG_CALLBACK: | 1284 | case SSL_CTRL_SET_MSG_CALLBACK: |
1287 | ctx->internal->msg_callback = (void (*)(int write_p, int version, | 1285 | ctx->internal->msg_callback = (ssl_msg_callback_fn *)fp; |
1288 | int content_type, const void *buf, size_t len, SSL *ssl, | ||
1289 | void *arg))(fp); | ||
1290 | return (1); | 1286 | return (1); |
1291 | 1287 | ||
1292 | default: | 1288 | default: |
@@ -2622,6 +2618,26 @@ ssl_clear_cipher_write_state(SSL *s) | |||
2622 | tls12_record_layer_clear_write_state(s->internal->rl); | 2618 | tls12_record_layer_clear_write_state(s->internal->rl); |
2623 | } | 2619 | } |
2624 | 2620 | ||
2621 | void | ||
2622 | ssl_info_callback(const SSL *s, int type, int value) | ||
2623 | { | ||
2624 | ssl_info_callback_fn *cb; | ||
2625 | |||
2626 | if ((cb = s->internal->info_callback) == NULL) | ||
2627 | cb = s->ctx->internal->info_callback; | ||
2628 | if (cb != NULL) | ||
2629 | cb(s, type, value); | ||
2630 | } | ||
2631 | |||
2632 | void | ||
2633 | ssl_msg_callback(SSL *s, int is_write, int content_type, | ||
2634 | const void *msg_buf, size_t msg_len) | ||
2635 | { | ||
2636 | if (s->internal->msg_callback != NULL) | ||
2637 | s->internal->msg_callback(is_write, s->version, content_type, | ||
2638 | msg_buf, msg_len, s, s->internal->msg_callback_arg); | ||
2639 | } | ||
2640 | |||
2625 | /* Fix this function so that it takes an optional type parameter */ | 2641 | /* Fix this function so that it takes an optional type parameter */ |
2626 | X509 * | 2642 | X509 * |
2627 | SSL_get_certificate(const SSL *s) | 2643 | SSL_get_certificate(const SSL *s) |
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index d25ac1a1a6..7ff3e0713d 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_locl.h,v 1.357 2021/08/30 19:12:25 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_locl.h,v 1.358 2021/08/30 19:25:43 jsing 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 | * |
@@ -662,6 +662,10 @@ int tls12_record_layer_seal_record(struct tls12_record_layer *rl, | |||
662 | uint8_t content_type, const uint8_t *content, size_t content_len, | 662 | uint8_t content_type, const uint8_t *content, size_t content_len, |
663 | CBB *out); | 663 | CBB *out); |
664 | 664 | ||
665 | typedef void (ssl_info_callback_fn)(const SSL *s, int type, int val); | ||
666 | typedef void (ssl_msg_callback_fn)(int is_write, int version, int content_type, | ||
667 | const void *buf, size_t len, SSL *ssl, void *arg); | ||
668 | |||
665 | typedef struct ssl_ctx_internal_st { | 669 | typedef struct ssl_ctx_internal_st { |
666 | uint16_t min_tls_version; | 670 | uint16_t min_tls_version; |
667 | uint16_t max_tls_version; | 671 | uint16_t max_tls_version; |
@@ -704,11 +708,10 @@ typedef struct ssl_ctx_internal_st { | |||
704 | int (*app_verify_cookie_cb)(SSL *ssl, const unsigned char *cookie, | 708 | int (*app_verify_cookie_cb)(SSL *ssl, const unsigned char *cookie, |
705 | unsigned int cookie_len); | 709 | unsigned int cookie_len); |
706 | 710 | ||
707 | void (*info_callback)(const SSL *ssl,int type,int val); /* used if SSL's info_callback is NULL */ | 711 | ssl_info_callback_fn *info_callback; |
708 | 712 | ||
709 | /* callback that allows applications to peek at protocol messages */ | 713 | /* callback that allows applications to peek at protocol messages */ |
710 | void (*msg_callback)(int write_p, int version, int content_type, | 714 | ssl_msg_callback_fn *msg_callback; |
711 | const void *buf, size_t len, SSL *ssl, void *arg); | ||
712 | void *msg_callback_arg; | 715 | void *msg_callback_arg; |
713 | 716 | ||
714 | int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */ | 717 | int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */ |
@@ -854,17 +857,17 @@ typedef struct ssl_internal_st { | |||
854 | /* true when we are actually in SSL_accept() or SSL_connect() */ | 857 | /* true when we are actually in SSL_accept() or SSL_connect() */ |
855 | int in_handshake; | 858 | int in_handshake; |
856 | int (*handshake_func)(SSL *); | 859 | int (*handshake_func)(SSL *); |
860 | |||
861 | ssl_info_callback_fn *info_callback; | ||
862 | |||
857 | /* callback that allows applications to peek at protocol messages */ | 863 | /* callback that allows applications to peek at protocol messages */ |
858 | void (*msg_callback)(int write_p, int version, int content_type, | 864 | ssl_msg_callback_fn *msg_callback; |
859 | const void *buf, size_t len, SSL *ssl, void *arg); | ||
860 | void *msg_callback_arg; | 865 | void *msg_callback_arg; |
861 | 866 | ||
862 | /* Default generate session ID callback. */ | ||
863 | GEN_SESSION_CB generate_session_id; | ||
864 | |||
865 | int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */ | 867 | int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */ |
866 | 868 | ||
867 | void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */ | 869 | /* Default generate session ID callback. */ |
870 | GEN_SESSION_CB generate_session_id; | ||
868 | 871 | ||
869 | /* TLS extension debug callback */ | 872 | /* TLS extension debug callback */ |
870 | void (*tlsext_debug_cb)(SSL *s, int client_server, int type, | 873 | void (*tlsext_debug_cb)(SSL *s, int client_server, int type, |
@@ -1177,6 +1180,10 @@ void ssl_clear_cipher_read_state(SSL *s); | |||
1177 | void ssl_clear_cipher_write_state(SSL *s); | 1180 | void ssl_clear_cipher_write_state(SSL *s); |
1178 | int ssl_clear_bad_session(SSL *s); | 1181 | int ssl_clear_bad_session(SSL *s); |
1179 | 1182 | ||
1183 | void ssl_info_callback(const SSL *s, int type, int value); | ||
1184 | void ssl_msg_callback(SSL *s, int is_write, int content_type, | ||
1185 | const void *msg_buf, size_t msg_len); | ||
1186 | |||
1180 | CERT *ssl_cert_new(void); | 1187 | CERT *ssl_cert_new(void); |
1181 | CERT *ssl_cert_dup(CERT *cert); | 1188 | CERT *ssl_cert_dup(CERT *cert); |
1182 | void ssl_cert_free(CERT *c); | 1189 | void ssl_cert_free(CERT *c); |
diff --git a/src/lib/libssl/ssl_pkt.c b/src/lib/libssl/ssl_pkt.c index 9aa71f7d4f..049a7df3c3 100644 --- a/src/lib/libssl/ssl_pkt.c +++ b/src/lib/libssl/ssl_pkt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_pkt.c,v 1.49 2021/08/28 15:20:58 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_pkt.c,v 1.50 2021/08/30 19:25:43 jsing 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 | * |
@@ -714,8 +714,7 @@ ssl3_write_pending(SSL *s, int type, const unsigned char *buf, unsigned int len) | |||
714 | int | 714 | int |
715 | ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | 715 | ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) |
716 | { | 716 | { |
717 | void (*cb)(const SSL *ssl, int type2, int val) = NULL; | 717 | int al, i, ret, rrcount = 0; |
718 | int al, i, j, ret, rrcount = 0; | ||
719 | unsigned int n; | 718 | unsigned int n; |
720 | SSL3_RECORD_INTERNAL *rr; | 719 | SSL3_RECORD_INTERNAL *rr; |
721 | 720 | ||
@@ -914,10 +913,8 @@ ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | |||
914 | goto fatal_err; | 913 | goto fatal_err; |
915 | } | 914 | } |
916 | 915 | ||
917 | if (s->internal->msg_callback) | 916 | ssl_msg_callback(s, 0, SSL3_RT_HANDSHAKE, |
918 | s->internal->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, | 917 | S3I(s)->handshake_fragment, 4); |
919 | S3I(s)->handshake_fragment, 4, s, | ||
920 | s->internal->msg_callback_arg); | ||
921 | 918 | ||
922 | if (SSL_is_init_finished(s) && | 919 | if (SSL_is_init_finished(s) && |
923 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) && | 920 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) && |
@@ -978,19 +975,11 @@ ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | |||
978 | 975 | ||
979 | S3I(s)->alert_fragment_len = 0; | 976 | S3I(s)->alert_fragment_len = 0; |
980 | 977 | ||
981 | if (s->internal->msg_callback) | 978 | ssl_msg_callback(s, 0, SSL3_RT_ALERT, |
982 | s->internal->msg_callback(0, s->version, SSL3_RT_ALERT, | 979 | S3I(s)->alert_fragment, 2); |
983 | S3I(s)->alert_fragment, 2, s, s->internal->msg_callback_arg); | ||
984 | 980 | ||
985 | if (s->internal->info_callback != NULL) | 981 | ssl_info_callback(s, SSL_CB_READ_ALERT, |
986 | cb = s->internal->info_callback; | 982 | (alert_level << 8) | alert_descr); |
987 | else if (s->ctx->internal->info_callback != NULL) | ||
988 | cb = s->ctx->internal->info_callback; | ||
989 | |||
990 | if (cb != NULL) { | ||
991 | j = (alert_level << 8) | alert_descr; | ||
992 | cb(s, SSL_CB_READ_ALERT, j); | ||
993 | } | ||
994 | 983 | ||
995 | if (alert_level == SSL3_AL_WARNING) { | 984 | if (alert_level == SSL3_AL_WARNING) { |
996 | S3I(s)->warn_alert = alert_descr; | 985 | S3I(s)->warn_alert = alert_descr; |
@@ -1064,11 +1053,7 @@ ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | |||
1064 | 1053 | ||
1065 | rr->length = 0; | 1054 | rr->length = 0; |
1066 | 1055 | ||
1067 | if (s->internal->msg_callback) { | 1056 | ssl_msg_callback(s, 0, SSL3_RT_CHANGE_CIPHER_SPEC, rr->data, 1); |
1068 | s->internal->msg_callback(0, s->version, | ||
1069 | SSL3_RT_CHANGE_CIPHER_SPEC, rr->data, 1, s, | ||
1070 | s->internal->msg_callback_arg); | ||
1071 | } | ||
1072 | 1057 | ||
1073 | S3I(s)->change_cipher_spec = 1; | 1058 | S3I(s)->change_cipher_spec = 1; |
1074 | if (!ssl3_do_change_cipher_spec(s)) | 1059 | if (!ssl3_do_change_cipher_spec(s)) |
@@ -1224,7 +1209,6 @@ ssl3_send_alert(SSL *s, int level, int desc) | |||
1224 | int | 1209 | int |
1225 | ssl3_dispatch_alert(SSL *s) | 1210 | ssl3_dispatch_alert(SSL *s) |
1226 | { | 1211 | { |
1227 | void (*cb)(const SSL *ssl, int type, int val); | ||
1228 | int ret; | 1212 | int ret; |
1229 | 1213 | ||
1230 | S3I(s)->alert_dispatch = 0; | 1214 | S3I(s)->alert_dispatch = 0; |
@@ -1241,15 +1225,10 @@ ssl3_dispatch_alert(SSL *s) | |||
1241 | if (S3I(s)->send_alert[0] == SSL3_AL_FATAL) | 1225 | if (S3I(s)->send_alert[0] == SSL3_AL_FATAL) |
1242 | (void)BIO_flush(s->wbio); | 1226 | (void)BIO_flush(s->wbio); |
1243 | 1227 | ||
1244 | if (s->internal->msg_callback) | 1228 | ssl_msg_callback(s, 1, SSL3_RT_ALERT, S3I(s)->send_alert, 2); |
1245 | s->internal->msg_callback(1, s->version, SSL3_RT_ALERT, | ||
1246 | S3I(s)->send_alert, 2, s, s->internal->msg_callback_arg); | ||
1247 | 1229 | ||
1248 | if ((cb = s->internal->info_callback) == NULL) | 1230 | ssl_info_callback(s, SSL_CB_WRITE_ALERT, |
1249 | cb = s->ctx->internal->info_callback; | 1231 | (S3I(s)->send_alert[0] << 8) | S3I(s)->send_alert[1]); |
1250 | if (cb != NULL) | ||
1251 | cb(s, SSL_CB_WRITE_ALERT, (S3I(s)->send_alert[0] << 8) | | ||
1252 | S3I(s)->send_alert[1]); | ||
1253 | 1232 | ||
1254 | return ret; | 1233 | return ret; |
1255 | } | 1234 | } |
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c index 2097ccdebf..a473d5af05 100644 --- a/src/lib/libssl/ssl_srvr.c +++ b/src/lib/libssl/ssl_srvr.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_srvr.c,v 1.117 2021/06/29 19:43:15 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_srvr.c,v 1.118 2021/08/30 19:25:43 jsing 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 | * |
@@ -174,20 +174,14 @@ | |||
174 | int | 174 | int |
175 | ssl3_accept(SSL *s) | 175 | ssl3_accept(SSL *s) |
176 | { | 176 | { |
177 | void (*cb)(const SSL *ssl, int type, int val) = NULL; | ||
178 | unsigned long alg_k; | 177 | unsigned long alg_k; |
179 | int ret = -1; | ||
180 | int new_state, state, skip = 0; | 178 | int new_state, state, skip = 0; |
181 | int listen = 0; | 179 | int listen = 0; |
180 | int ret = -1; | ||
182 | 181 | ||
183 | ERR_clear_error(); | 182 | ERR_clear_error(); |
184 | errno = 0; | 183 | errno = 0; |
185 | 184 | ||
186 | if (s->internal->info_callback != NULL) | ||
187 | cb = s->internal->info_callback; | ||
188 | else if (s->ctx->internal->info_callback != NULL) | ||
189 | cb = s->ctx->internal->info_callback; | ||
190 | |||
191 | if (SSL_is_dtls(s)) | 185 | if (SSL_is_dtls(s)) |
192 | listen = D1I(s)->listen; | 186 | listen = D1I(s)->listen; |
193 | 187 | ||
@@ -212,8 +206,8 @@ ssl3_accept(SSL *s) | |||
212 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: | 206 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: |
213 | case SSL_ST_OK|SSL_ST_ACCEPT: | 207 | case SSL_ST_OK|SSL_ST_ACCEPT: |
214 | s->server = 1; | 208 | s->server = 1; |
215 | if (cb != NULL) | 209 | |
216 | cb(s, SSL_CB_HANDSHAKE_START, 1); | 210 | ssl_info_callback(s, SSL_CB_HANDSHAKE_START, 1); |
217 | 211 | ||
218 | if (!ssl_legacy_stack_version(s, s->version)) { | 212 | if (!ssl_legacy_stack_version(s, s->version)) { |
219 | SSLerror(s, ERR_R_INTERNAL_ERROR); | 213 | SSLerror(s, ERR_R_INTERNAL_ERROR); |
@@ -705,8 +699,7 @@ ssl3_accept(SSL *s) | |||
705 | /* s->server=1; */ | 699 | /* s->server=1; */ |
706 | s->internal->handshake_func = ssl3_accept; | 700 | s->internal->handshake_func = ssl3_accept; |
707 | 701 | ||
708 | if (cb != NULL) | 702 | ssl_info_callback(s, SSL_CB_HANDSHAKE_DONE, 1); |
709 | cb(s, SSL_CB_HANDSHAKE_DONE, 1); | ||
710 | } | 703 | } |
711 | 704 | ||
712 | ret = 1; | 705 | ret = 1; |
@@ -735,10 +728,10 @@ ssl3_accept(SSL *s) | |||
735 | } | 728 | } |
736 | 729 | ||
737 | 730 | ||
738 | if ((cb != NULL) && (S3I(s)->hs.state != state)) { | 731 | if (S3I(s)->hs.state != state) { |
739 | new_state = S3I(s)->hs.state; | 732 | new_state = S3I(s)->hs.state; |
740 | S3I(s)->hs.state = state; | 733 | S3I(s)->hs.state = state; |
741 | cb(s, SSL_CB_ACCEPT_LOOP, 1); | 734 | ssl_info_callback(s, SSL_CB_ACCEPT_LOOP, 1); |
742 | S3I(s)->hs.state = new_state; | 735 | S3I(s)->hs.state = new_state; |
743 | } | 736 | } |
744 | } | 737 | } |
@@ -747,8 +740,7 @@ ssl3_accept(SSL *s) | |||
747 | end: | 740 | end: |
748 | /* BIO_flush(s->wbio); */ | 741 | /* BIO_flush(s->wbio); */ |
749 | s->internal->in_handshake--; | 742 | s->internal->in_handshake--; |
750 | if (cb != NULL) | 743 | ssl_info_callback(s, SSL_CB_ACCEPT_EXIT, ret); |
751 | cb(s, SSL_CB_ACCEPT_EXIT, ret); | ||
752 | 744 | ||
753 | return (ret); | 745 | return (ret); |
754 | } | 746 | } |
diff --git a/src/lib/libssl/tls13_lib.c b/src/lib/libssl/tls13_lib.c index f064521c8b..77b4364f56 100644 --- a/src/lib/libssl/tls13_lib.c +++ b/src/lib/libssl/tls13_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_lib.c,v 1.59 2021/04/07 21:48:23 tb Exp $ */ | 1 | /* $OpenBSD: tls13_lib.c,v 1.60 2021/08/30 19:25:43 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 | * Copyright (c) 2019 Bob Beck <beck@openbsd.org> | 4 | * Copyright (c) 2019 Bob Beck <beck@openbsd.org> |
@@ -162,8 +162,7 @@ tls13_legacy_handshake_message_recv_cb(void *arg) | |||
162 | return; | 162 | return; |
163 | 163 | ||
164 | tls13_handshake_msg_data(ctx->hs_msg, &cbs); | 164 | tls13_handshake_msg_data(ctx->hs_msg, &cbs); |
165 | s->internal->msg_callback(0, TLS1_3_VERSION, SSL3_RT_HANDSHAKE, | 165 | ssl_msg_callback(s, 0, SSL3_RT_HANDSHAKE, CBS_data(&cbs), CBS_len(&cbs)); |
166 | CBS_data(&cbs), CBS_len(&cbs), s, s->internal->msg_callback_arg); | ||
167 | } | 166 | } |
168 | 167 | ||
169 | static void | 168 | static void |
@@ -177,8 +176,7 @@ tls13_legacy_handshake_message_sent_cb(void *arg) | |||
177 | return; | 176 | return; |
178 | 177 | ||
179 | tls13_handshake_msg_data(ctx->hs_msg, &cbs); | 178 | tls13_handshake_msg_data(ctx->hs_msg, &cbs); |
180 | s->internal->msg_callback(1, TLS1_3_VERSION, SSL3_RT_HANDSHAKE, | 179 | ssl_msg_callback(s, 1, SSL3_RT_HANDSHAKE, CBS_data(&cbs), CBS_len(&cbs)); |
181 | CBS_data(&cbs), CBS_len(&cbs), s, s->internal->msg_callback_arg); | ||
182 | } | 180 | } |
183 | 181 | ||
184 | static void | 182 | static void |
@@ -186,12 +184,8 @@ tls13_legacy_info_cb(void *arg, int state, int ret) | |||
186 | { | 184 | { |
187 | struct tls13_ctx *ctx = arg; | 185 | struct tls13_ctx *ctx = arg; |
188 | SSL *s = ctx->ssl; | 186 | SSL *s = ctx->ssl; |
189 | void (*cb)(const SSL *, int, int); | ||
190 | 187 | ||
191 | if ((cb = s->internal->info_callback) == NULL) | 188 | ssl_info_callback(s, state, ret); |
192 | cb = s->ctx->internal->info_callback; | ||
193 | if (cb != NULL) | ||
194 | cb(s, state, ret); | ||
195 | } | 189 | } |
196 | 190 | ||
197 | static int | 191 | static int |