]>
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; | |
38b051a1 | 16 | SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL_ONLY(s); |
c103c7e2 | 17 | |
38b051a1 TM |
18 | if (sc == NULL) |
19 | return -1; | |
20 | ||
21 | if (SSL_in_init(s) && !ossl_statem_get_in_handshake(sc)) { | |
22 | i = sc->handshake_func(s); | |
c103c7e2 | 23 | if (i < 0) |
26a7d938 | 24 | return i; |
c103c7e2 | 25 | if (i == 0) { |
6849b73c | 26 | ERR_raise(ERR_LIB_SSL, SSL_R_SSL_HANDSHAKE_FAILURE); |
c103c7e2 MC |
27 | return -1; |
28 | } | |
29 | } | |
30 | ||
31 | if (len > SSL3_RT_MAX_PLAIN_LENGTH) { | |
6849b73c | 32 | ERR_raise(ERR_LIB_SSL, SSL_R_DTLS_MESSAGE_TOO_BIG); |
c103c7e2 MC |
33 | return -1; |
34 | } | |
35 | ||
38b051a1 | 36 | return dtls1_write_bytes(sc, type, buf_, len, written); |
c103c7e2 MC |
37 | } |
38 | ||
38b051a1 | 39 | int dtls1_dispatch_alert(SSL *ssl) |
c103c7e2 MC |
40 | { |
41 | int i, j; | |
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]; | |
7ee8627f | 45 | size_t written; |
38b051a1 TM |
46 | SSL_CONNECTION *s = SSL_CONNECTION_FROM_SSL_ONLY(ssl); |
47 | ||
48 | if (s == NULL) | |
49 | return 0; | |
c103c7e2 | 50 | |
555cbb32 | 51 | s->s3.alert_dispatch = 0; |
c103c7e2 | 52 | |
16f8d4eb | 53 | memset(buf, 0, sizeof(buf)); |
555cbb32 TS |
54 | *ptr++ = s->s3.send_alert[0]; |
55 | *ptr++ = s->s3.send_alert[1]; | |
c103c7e2 | 56 | |
7ee8627f | 57 | i = do_dtls1_write(s, SSL3_RT_ALERT, &buf[0], sizeof(buf), 0, &written); |
c103c7e2 | 58 | if (i <= 0) { |
555cbb32 | 59 | s->s3.alert_dispatch = 1; |
1287dabd | 60 | /* fprintf(stderr, "not done with alert\n"); */ |
c103c7e2 | 61 | } else { |
03da376f | 62 | (void)BIO_flush(s->wbio); |
c103c7e2 MC |
63 | |
64 | if (s->msg_callback) | |
555cbb32 | 65 | s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3.send_alert, |
38b051a1 | 66 | 2, ssl, s->msg_callback_arg); |
c103c7e2 MC |
67 | |
68 | if (s->info_callback != NULL) | |
69 | cb = s->info_callback; | |
38b051a1 TM |
70 | else if (ssl->ctx->info_callback != NULL) |
71 | cb = ssl->ctx->info_callback; | |
c103c7e2 MC |
72 | |
73 | if (cb != NULL) { | |
555cbb32 | 74 | j = (s->s3.send_alert[0] << 8) | s->s3.send_alert[1]; |
38b051a1 | 75 | cb(ssl, SSL_CB_WRITE_ALERT, j); |
c103c7e2 MC |
76 | } |
77 | } | |
7ee8627f | 78 | return i; |
c103c7e2 | 79 | } |