-/* $OpenBSD: d1_pkt.c,v 1.103 2021/07/21 08:42:14 jsing Exp $ */
+/* $OpenBSD: d1_pkt.c,v 1.104 2021/07/26 03:17:38 jsing Exp $ */
/*
* DTLS implementation written by Nagendra Modadugu
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
#include "pqueue.h"
#include "ssl_locl.h"
-static int do_dtls1_write(SSL *s, int type, const unsigned char *buf,
- unsigned int len);
-
-
/* mod 128 saturating subtract of two 64-bit values in big-endian order */
static int
satsub64be(const unsigned char *v1, const unsigned char *v2)
/* If we have an alert to send, let's send it */
if (S3I(s)->alert_dispatch) {
- if ((ret = s->method->ssl_dispatch_alert(s)) <= 0)
+ if ((ret = ssl3_dispatch_alert(s)) <= 0)
return (ret);
/* If it went, fall through and send more stuff. */
}
}
}
-int
-dtls1_dispatch_alert(SSL *s)
-{
- int i, j;
- void (*cb)(const SSL *ssl, int type, int val) = NULL;
-
- S3I(s)->alert_dispatch = 0;
-
- i = do_dtls1_write(s, SSL3_RT_ALERT, &S3I(s)->send_alert[0], 2);
- if (i <= 0) {
- S3I(s)->alert_dispatch = 1;
- } else {
- if (S3I(s)->send_alert[0] == SSL3_AL_FATAL)
- (void)BIO_flush(s->wbio);
-
- if (s->internal->msg_callback)
- s->internal->msg_callback(1, s->version, SSL3_RT_ALERT,
- S3I(s)->send_alert, 2, s, s->internal->msg_callback_arg);
-
- if (s->internal->info_callback != NULL)
- cb = s->internal->info_callback;
- else if (s->ctx->internal->info_callback != NULL)
- cb = s->ctx->internal->info_callback;
-
- if (cb != NULL) {
- j = (S3I(s)->send_alert[0]<<8)|S3I(s)->send_alert[1];
- cb(s, SSL_CB_WRITE_ALERT, j);
- }
- }
- return (i);
-}
-
static DTLS1_BITMAP *
dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch)
{
-/* $OpenBSD: ssl_methods.c,v 1.27 2021/07/03 16:06:45 jsing Exp $ */
+/* $OpenBSD: ssl_methods.c,v 1.28 2021/07/26 03:17:38 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
.ssl_pending = ssl3_pending,
.ssl_read_bytes = dtls1_read_bytes,
.ssl_write_bytes = dtls1_write_app_data_bytes,
- .ssl_dispatch_alert = dtls1_dispatch_alert,
.get_cipher = dtls1_get_cipher,
.enc_flags = TLSV1_2_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = dtls1_read_bytes,
.ssl_write_bytes = dtls1_write_app_data_bytes,
- .ssl_dispatch_alert = dtls1_dispatch_alert,
.get_cipher = dtls1_get_cipher,
.enc_flags = TLSV1_2_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = dtls1_read_bytes,
.ssl_write_bytes = dtls1_write_app_data_bytes,
- .ssl_dispatch_alert = dtls1_dispatch_alert,
.get_cipher = dtls1_get_cipher,
.enc_flags = TLSV1_1_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = dtls1_read_bytes,
.ssl_write_bytes = dtls1_write_app_data_bytes,
- .ssl_dispatch_alert = dtls1_dispatch_alert,
.get_cipher = dtls1_get_cipher,
.enc_flags = TLSV1_1_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = dtls1_read_bytes,
.ssl_write_bytes = dtls1_write_app_data_bytes,
- .ssl_dispatch_alert = dtls1_dispatch_alert,
.get_cipher = dtls1_get_cipher,
.enc_flags = TLSV1_2_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = dtls1_read_bytes,
.ssl_write_bytes = dtls1_write_app_data_bytes,
- .ssl_dispatch_alert = dtls1_dispatch_alert,
.get_cipher = dtls1_get_cipher,
.enc_flags = TLSV1_2_ENC_FLAGS,
};
.ssl_pending = tls13_legacy_pending,
.ssl_read_bytes = tls13_legacy_read_bytes,
.ssl_write_bytes = tls13_legacy_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_3_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_2_ENC_FLAGS,
};
.ssl_pending = tls13_legacy_pending,
.ssl_read_bytes = tls13_legacy_read_bytes,
.ssl_write_bytes = tls13_legacy_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_3_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_2_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_1_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_1_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_2_ENC_FLAGS,
};
.ssl_pending = ssl3_pending,
.ssl_read_bytes = ssl3_read_bytes,
.ssl_write_bytes = ssl3_write_bytes,
- .ssl_dispatch_alert = ssl3_dispatch_alert,
.get_cipher = ssl3_get_cipher,
.enc_flags = TLSV1_2_ENC_FLAGS,
};
-/* $OpenBSD: ssl_pkt.c,v 1.45 2021/06/29 18:43:49 jsing Exp $ */
+/* $OpenBSD: ssl_pkt.c,v 1.46 2021/07/26 03:17:38 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include <openssl/evp.h>
#include "bytestring.h"
+#include "dtls_locl.h"
#include "ssl_locl.h"
static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
/* If we have an alert to send, let's send it. */
if (S3I(s)->alert_dispatch) {
- if ((ret = s->method->ssl_dispatch_alert(s)) <= 0)
+ if ((ret = ssl3_dispatch_alert(s)) <= 0)
return (ret);
/* If it went, fall through and send more stuff. */
return (1);
}
+static int
+ssl3_write_alert(SSL *s)
+{
+ if (SSL_is_dtls(s))
+ return do_dtls1_write(s, SSL3_RT_ALERT, S3I(s)->send_alert,
+ sizeof(S3I(s)->send_alert));
+
+ return do_ssl3_write(s, SSL3_RT_ALERT, S3I(s)->send_alert,
+ sizeof(S3I(s)->send_alert));
+}
+
int
ssl3_send_alert(SSL *s, int level, int desc)
{
S3I(s)->send_alert[0] = level;
S3I(s)->send_alert[1] = desc;
if (S3I(s)->wbuf.left == 0) /* data still being written out? */
- return s->method->ssl_dispatch_alert(s);
+ return ssl3_dispatch_alert(s);
/* else data is still being written out, we will get written
* some time in the future */
void (*cb)(const SSL *ssl, int type, int val) = NULL;
S3I(s)->alert_dispatch = 0;
- i = do_ssl3_write(s, SSL3_RT_ALERT, &S3I(s)->send_alert[0], 2);
+ i = ssl3_write_alert(s);
if (i <= 0) {
S3I(s)->alert_dispatch = 1;
} else {