]>
Commit | Line | Data |
---|---|---|
c103c7e2 | 1 | /* |
605856d7 | 2 | * Copyright 2005-2020 The OpenSSL Project Authors. All Rights Reserved. |
c103c7e2 | 3 | * |
2c18d164 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
846e33c7 RS |
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 | |
c103c7e2 MC |
8 | */ |
9 | ||
706457b7 | 10 | #include "ssl_local.h" |
0485d540 | 11 | |
7ee8627f MC |
12 | int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf_, size_t len, |
13 | size_t *written) | |
c103c7e2 MC |
14 | { |
15 | int i; | |
16 | ||
bd79bcb4 | 17 | if (SSL_in_init(s) && !ossl_statem_get_in_handshake(s)) { |
c103c7e2 MC |
18 | i = s->handshake_func(s); |
19 | if (i < 0) | |
26a7d938 | 20 | return i; |
c103c7e2 | 21 | if (i == 0) { |
6849b73c | 22 | ERR_raise(ERR_LIB_SSL, SSL_R_SSL_HANDSHAKE_FAILURE); |
c103c7e2 MC |
23 | return -1; |
24 | } | |
25 | } | |
26 | ||
27 | if (len > SSL3_RT_MAX_PLAIN_LENGTH) { | |
6849b73c | 28 | ERR_raise(ERR_LIB_SSL, SSL_R_DTLS_MESSAGE_TOO_BIG); |
c103c7e2 MC |
29 | return -1; |
30 | } | |
31 | ||
7ee8627f | 32 | return dtls1_write_bytes(s, type, buf_, len, written); |
c103c7e2 MC |
33 | } |
34 | ||
35 | int dtls1_dispatch_alert(SSL *s) | |
36 | { | |
37 | int i, j; | |
38 | void (*cb) (const SSL *ssl, int type, int val) = NULL; | |
39 | unsigned char buf[DTLS1_AL_HEADER_LENGTH]; | |
40 | unsigned char *ptr = &buf[0]; | |
7ee8627f | 41 | size_t written; |
c103c7e2 | 42 | |
555cbb32 | 43 | s->s3.alert_dispatch = 0; |
c103c7e2 | 44 | |
16f8d4eb | 45 | memset(buf, 0, sizeof(buf)); |
555cbb32 TS |
46 | *ptr++ = s->s3.send_alert[0]; |
47 | *ptr++ = s->s3.send_alert[1]; | |
c103c7e2 | 48 | |
7ee8627f | 49 | i = do_dtls1_write(s, SSL3_RT_ALERT, &buf[0], sizeof(buf), 0, &written); |
c103c7e2 | 50 | if (i <= 0) { |
555cbb32 | 51 | s->s3.alert_dispatch = 1; |
c103c7e2 MC |
52 | /* fprintf( stderr, "not done with alert\n" ); */ |
53 | } else { | |
03da376f | 54 | (void)BIO_flush(s->wbio); |
c103c7e2 MC |
55 | |
56 | if (s->msg_callback) | |
555cbb32 | 57 | s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3.send_alert, |
c103c7e2 MC |
58 | 2, s, s->msg_callback_arg); |
59 | ||
60 | if (s->info_callback != NULL) | |
61 | cb = s->info_callback; | |
62 | else if (s->ctx->info_callback != NULL) | |
63 | cb = s->ctx->info_callback; | |
64 | ||
65 | if (cb != NULL) { | |
555cbb32 | 66 | j = (s->s3.send_alert[0] << 8) | s->s3.send_alert[1]; |
c103c7e2 MC |
67 | cb(s, SSL_CB_WRITE_ALERT, j); |
68 | } | |
69 | } | |
7ee8627f | 70 | return i; |
c103c7e2 | 71 | } |