summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl_pkt.c
diff options
context:
space:
mode:
authorjsing <>2021-08-30 19:25:43 +0000
committerjsing <>2021-08-30 19:25:43 +0000
commita376b9cd8ffd396f270e597131a83af4f639bd93 (patch)
tree8e3bea79ab1dea102b95252a7e2c36c06522e41d /src/lib/libssl/ssl_pkt.c
parentcedbde20c0ecfb870c00ce4fe4401f89a9397b6d (diff)
downloadopenbsd-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/libssl/ssl_pkt.c')
-rw-r--r--src/lib/libssl/ssl_pkt.c45
1 files changed, 12 insertions, 33 deletions
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)
714int 714int
715ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) 715ssl3_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)
1224int 1209int
1225ssl3_dispatch_alert(SSL *s) 1210ssl3_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}