2015-02-02 18:05:09 +08:00
|
|
|
/*
|
2020-11-26 22:18:57 +08:00
|
|
|
* Copyright 2005-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2015-02-02 18:05:09 +08:00
|
|
|
*
|
2018-12-06 20:08:51 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:18:30 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2015-02-02 18:05:09 +08:00
|
|
|
*/
|
|
|
|
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "ssl_local.h"
|
2016-06-29 04:51:27 +08:00
|
|
|
|
2016-09-07 18:34:39 +08:00
|
|
|
int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf_, size_t len,
|
|
|
|
size_t *written)
|
2015-02-02 18:05:09 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-04-20 22:13:28 +08:00
|
|
|
if (SSL_in_init(s) && !ossl_statem_get_in_handshake(s)) {
|
2015-02-02 18:05:09 +08:00
|
|
|
i = s->handshake_func(s);
|
|
|
|
if (i < 0)
|
2017-10-17 22:04:09 +08:00
|
|
|
return i;
|
2015-02-02 18:05:09 +08:00
|
|
|
if (i == 0) {
|
2020-11-04 19:18:33 +08:00
|
|
|
ERR_raise(ERR_LIB_SSL, SSL_R_SSL_HANDSHAKE_FAILURE);
|
2015-02-02 18:05:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > SSL3_RT_MAX_PLAIN_LENGTH) {
|
2020-11-04 19:18:33 +08:00
|
|
|
ERR_raise(ERR_LIB_SSL, SSL_R_DTLS_MESSAGE_TOO_BIG);
|
2015-02-02 18:05:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-09-07 18:34:39 +08:00
|
|
|
return dtls1_write_bytes(s, type, buf_, len, written);
|
2015-02-02 18:05:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int dtls1_dispatch_alert(SSL *s)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
void (*cb) (const SSL *ssl, int type, int val) = NULL;
|
|
|
|
unsigned char buf[DTLS1_AL_HEADER_LENGTH];
|
|
|
|
unsigned char *ptr = &buf[0];
|
2016-09-07 18:34:39 +08:00
|
|
|
size_t written;
|
2015-02-02 18:05:09 +08:00
|
|
|
|
2018-12-13 02:09:50 +08:00
|
|
|
s->s3.alert_dispatch = 0;
|
2015-02-02 18:05:09 +08:00
|
|
|
|
2015-05-05 06:00:15 +08:00
|
|
|
memset(buf, 0, sizeof(buf));
|
2018-12-13 02:09:50 +08:00
|
|
|
*ptr++ = s->s3.send_alert[0];
|
|
|
|
*ptr++ = s->s3.send_alert[1];
|
2015-02-02 18:05:09 +08:00
|
|
|
|
2016-09-07 18:34:39 +08:00
|
|
|
i = do_dtls1_write(s, SSL3_RT_ALERT, &buf[0], sizeof(buf), 0, &written);
|
2015-02-02 18:05:09 +08:00
|
|
|
if (i <= 0) {
|
2018-12-13 02:09:50 +08:00
|
|
|
s->s3.alert_dispatch = 1;
|
2015-02-02 18:05:09 +08:00
|
|
|
/* fprintf( stderr, "not done with alert\n" ); */
|
|
|
|
} else {
|
2019-05-29 23:27:26 +08:00
|
|
|
(void)BIO_flush(s->wbio);
|
2015-02-02 18:05:09 +08:00
|
|
|
|
|
|
|
if (s->msg_callback)
|
2018-12-13 02:09:50 +08:00
|
|
|
s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3.send_alert,
|
2015-02-02 18:05:09 +08:00
|
|
|
2, s, s->msg_callback_arg);
|
|
|
|
|
|
|
|
if (s->info_callback != NULL)
|
|
|
|
cb = s->info_callback;
|
|
|
|
else if (s->ctx->info_callback != NULL)
|
|
|
|
cb = s->ctx->info_callback;
|
|
|
|
|
|
|
|
if (cb != NULL) {
|
2018-12-13 02:09:50 +08:00
|
|
|
j = (s->s3.send_alert[0] << 8) | s->s3.send_alert[1];
|
2015-02-02 18:05:09 +08:00
|
|
|
cb(s, SSL_CB_WRITE_ALERT, j);
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 18:34:39 +08:00
|
|
|
return i;
|
2015-02-02 18:05:09 +08:00
|
|
|
}
|