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
|
|
|
*
|
2016-05-17 18:18:30 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
|
|
|
#define USE_SOCKETS
|
|
|
|
#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;
|
|
|
|
|
|
|
|
#ifndef OPENSSL_NO_SCTP
|
|
|
|
/*
|
|
|
|
* Check if we have to continue an interrupted handshake for reading
|
|
|
|
* belated app data with SCTP.
|
|
|
|
*/
|
2015-10-22 12:57:18 +00:00
|
|
|
if ((SSL_in_init(s) && !ossl_statem_get_in_handshake(s)) ||
|
2015-02-02 10:05:09 +00:00
|
|
|
(BIO_dgram_is_sctp(SSL_get_wbio(s)) &&
|
2015-10-05 09:39:54 +00:00
|
|
|
ossl_statem_in_sctp_read_sock(s)))
|
2015-02-02 10:05:09 +00:00
|
|
|
#else
|
2015-10-22 12:57:18 +00:00
|
|
|
if (SSL_in_init(s) && !ossl_statem_get_in_handshake(s))
|
2015-02-02 10:05:09 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
i = s->handshake_func(s);
|
|
|
|
if (i < 0)
|
|
|
|
return (i);
|
|
|
|
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
|
|
|
|
|
|
|
s->s3->alert_dispatch = 0;
|
|
|
|
|
2015-05-04 22:00:15 +00:00
|
|
|
memset(buf, 0, sizeof(buf));
|
2015-02-02 10:05:09 +00:00
|
|
|
*ptr++ = s->s3->send_alert[0];
|
|
|
|
*ptr++ = s->s3->send_alert[1];
|
|
|
|
|
|
|
|
#ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
|
|
|
|
if (s->s3->send_alert[1] == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE) {
|
|
|
|
s2n(s->d1->handshake_read_seq, ptr);
|
|
|
|
l2n3(s->d1->r_msg_hdr.frag_off, ptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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) {
|
|
|
|
s->s3->alert_dispatch = 1;
|
|
|
|
/* fprintf( stderr, "not done with alert\n" ); */
|
|
|
|
} else {
|
|
|
|
if (s->s3->send_alert[0] == SSL3_AL_FATAL
|
|
|
|
#ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
|
|
|
|
|| s->s3->send_alert[1] == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
(void)BIO_flush(s->wbio);
|
|
|
|
|
|
|
|
if (s->msg_callback)
|
|
|
|
s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3->send_alert,
|
|
|
|
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) {
|
|
|
|
j = (s->s3->send_alert[0] << 8) | s->s3->send_alert[1];
|
|
|
|
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
|
|
|
}
|