2 * Copyright 2005-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include "ssl_local.h"
12 int dtls1_write_app_data_bytes(SSL
*s
, int type
, const void *buf_
, size_t len
,
16 SSL_CONNECTION
*sc
= SSL_CONNECTION_FROM_SSL_ONLY(s
);
21 if (SSL_in_init(s
) && !ossl_statem_get_in_handshake(sc
)) {
22 i
= sc
->handshake_func(s
);
26 ERR_raise(ERR_LIB_SSL
, SSL_R_SSL_HANDSHAKE_FAILURE
);
31 if (len
> SSL3_RT_MAX_PLAIN_LENGTH
) {
32 ERR_raise(ERR_LIB_SSL
, SSL_R_DTLS_MESSAGE_TOO_BIG
);
36 return dtls1_write_bytes(sc
, type
, buf_
, len
, written
);
39 int dtls1_dispatch_alert(SSL
*ssl
)
42 void (*cb
) (const SSL
*ssl
, int type
, int val
) = NULL
;
43 unsigned char buf
[DTLS1_AL_HEADER_LENGTH
];
44 unsigned char *ptr
= &buf
[0];
46 SSL_CONNECTION
*s
= SSL_CONNECTION_FROM_SSL_ONLY(ssl
);
51 s
->s3
.alert_dispatch
= SSL_ALERT_DISPATCH_NONE
;
53 memset(buf
, 0, sizeof(buf
));
54 *ptr
++ = s
->s3
.send_alert
[0];
55 *ptr
++ = s
->s3
.send_alert
[1];
57 i
= do_dtls1_write(s
, SSL3_RT_ALERT
, &buf
[0], sizeof(buf
), &written
);
59 s
->s3
.alert_dispatch
= 1;
60 /* fprintf(stderr, "not done with alert\n"); */
62 (void)BIO_flush(s
->wbio
);
65 s
->msg_callback(1, s
->version
, SSL3_RT_ALERT
, s
->s3
.send_alert
,
66 2, ssl
, s
->msg_callback_arg
);
68 if (s
->info_callback
!= NULL
)
69 cb
= s
->info_callback
;
70 else if (ssl
->ctx
->info_callback
!= NULL
)
71 cb
= ssl
->ctx
->info_callback
;
74 j
= (s
->s3
.send_alert
[0] << 8) | s
->s3
.send_alert
[1];
75 cb(ssl
, SSL_CB_WRITE_ALERT
, j
);