2015-02-02 10:05:09 +00:00
|
|
|
/*
|
2016-05-17 18:18:30 +00:00
|
|
|
* Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2015-02-02 10:05:09 +00:00
|
|
|
*
|
2018-12-06 12:08:51 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:18:30 +00: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 10:05:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ssl_locl.h"
|
2016-06-28 20:51:27 +00:00
|
|
|
|
2016-09-07 10:34:39 +00:00
|
|
|
int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf_, size_t len,
|
|
|
|
size_t *written)
|
2015-02-02 10:05:09 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-04-20 14:13:28 +00:00
|
|
|
if (SSL_in_init(s) && !ossl_statem_get_in_handshake(s)) {
|
2015-02-02 10:05:09 +00:00
|
|
|
i = s->handshake_func(s);
|
|
|
|
if (i < 0)
|
2017-10-17 14:04:09 +00:00
|
|
|
return i;
|
2015-02-02 10:05:09 +00:00
|
|
|
if (i == 0) {
|
|
|
|
SSLerr(SSL_F_DTLS1_WRITE_APP_DATA_BYTES,
|
|
|
|
SSL_R_SSL_HANDSHAKE_FAILURE);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > SSL3_RT_MAX_PLAIN_LENGTH) {
|
|
|
|
SSLerr(SSL_F_DTLS1_WRITE_APP_DATA_BYTES, SSL_R_DTLS_MESSAGE_TOO_BIG);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-09-07 10:34:39 +00:00
|
|
|
return dtls1_write_bytes(s, type, buf_, len, written);
|
2015-02-02 10:05:09 +00: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 10:34:39 +00:00
|
|
|
size_t written;
|
2015-02-02 10:05:09 +00:00
|
|
|
|
2018-12-12 18:09:50 +00:00
|
|
|
s->s3.alert_dispatch = 0;
|
2015-02-02 10:05:09 +00:00
|
|
|
|
2015-05-04 22:00:15 +00:00
|
|
|
memset(buf, 0, sizeof(buf));
|
2018-12-12 18:09:50 +00:00
|
|
|
*ptr++ = s->s3.send_alert[0];
|
|
|
|
*ptr++ = s->s3.send_alert[1];
|
2015-02-02 10:05:09 +00:00
|
|
|
|
2016-09-07 10:34:39 +00:00
|
|
|
i = do_dtls1_write(s, SSL3_RT_ALERT, &buf[0], sizeof(buf), 0, &written);
|
2015-02-02 10:05:09 +00:00
|
|
|
if (i <= 0) {
|
2018-12-12 18:09:50 +00:00
|
|
|
s->s3.alert_dispatch = 1;
|
2015-02-02 10:05:09 +00:00
|
|
|
/* fprintf( stderr, "not done with alert\n" ); */
|
|
|
|
} else {
|
2018-12-12 18:09:50 +00:00
|
|
|
if (s->s3.send_alert[0] == SSL3_AL_FATAL)
|
2015-02-02 10:05:09 +00:00
|
|
|
(void)BIO_flush(s->wbio);
|
|
|
|
|
|
|
|
if (s->msg_callback)
|
2018-12-12 18:09:50 +00:00
|
|
|
s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3.send_alert,
|
2015-02-02 10:05:09 +00: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-12 18:09:50 +00:00
|
|
|
j = (s->s3.send_alert[0] << 8) | s->s3.send_alert[1];
|
2015-02-02 10:05:09 +00:00
|
|
|
cb(s, SSL_CB_WRITE_ALERT, j);
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 10:34:39 +00:00
|
|
|
return i;
|
2015-02-02 10:05:09 +00:00
|
|
|
}
|