/src/openssl/ssl/d1_msg.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright 2005-2025 The OpenSSL Project Authors. All Rights Reserved.  | 
3  |  |  *  | 
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  | 
8  |  |  */  | 
9  |  |  | 
10  |  | #include "ssl_local.h"  | 
11  |  | #include "internal/ssl_unwrap.h"  | 
12  |  |  | 
13  |  | int dtls1_write_app_data_bytes(SSL *s, uint8_t type, const void *buf_,  | 
14  |  |                                size_t len, size_t *written)  | 
15  | 0  | { | 
16  | 0  |     int i;  | 
17  | 0  |     SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL_ONLY(s);  | 
18  |  | 
  | 
19  | 0  |     if (sc == NULL)  | 
20  | 0  |         return -1;  | 
21  |  |  | 
22  | 0  |     if (SSL_in_init(s) && !ossl_statem_get_in_handshake(sc)) { | 
23  | 0  |         i = sc->handshake_func(s);  | 
24  | 0  |         if (i < 0)  | 
25  | 0  |             return i;  | 
26  | 0  |         if (i == 0) { | 
27  | 0  |             ERR_raise(ERR_LIB_SSL, SSL_R_SSL_HANDSHAKE_FAILURE);  | 
28  | 0  |             return -1;  | 
29  | 0  |         }  | 
30  | 0  |     }  | 
31  |  |  | 
32  | 0  |     if (len > SSL3_RT_MAX_PLAIN_LENGTH) { | 
33  | 0  |         ERR_raise(ERR_LIB_SSL, SSL_R_DTLS_MESSAGE_TOO_BIG);  | 
34  | 0  |         return -1;  | 
35  | 0  |     }  | 
36  |  |  | 
37  | 0  |     return dtls1_write_bytes(sc, type, buf_, len, written);  | 
38  | 0  | }  | 
39  |  |  | 
40  |  | int dtls1_dispatch_alert(SSL *ssl)  | 
41  | 0  | { | 
42  | 0  |     int i, j;  | 
43  | 0  |     void (*cb) (const SSL *ssl, int type, int val) = NULL;  | 
44  | 0  |     unsigned char buf[DTLS1_AL_HEADER_LENGTH];  | 
45  | 0  |     unsigned char *ptr = &buf[0];  | 
46  | 0  |     size_t written;  | 
47  | 0  |     SSL_CONNECTION *s = SSL_CONNECTION_FROM_SSL_ONLY(ssl);  | 
48  |  | 
  | 
49  | 0  |     if (s == NULL)  | 
50  | 0  |         return 0;  | 
51  |  |  | 
52  | 0  |     s->s3.alert_dispatch = SSL_ALERT_DISPATCH_NONE;  | 
53  |  | 
  | 
54  | 0  |     memset(buf, 0, sizeof(buf));  | 
55  | 0  |     *ptr++ = s->s3.send_alert[0];  | 
56  | 0  |     *ptr++ = s->s3.send_alert[1];  | 
57  |  | 
  | 
58  | 0  |     i = do_dtls1_write(s, SSL3_RT_ALERT, &buf[0], sizeof(buf), &written);  | 
59  | 0  |     if (i <= 0) { | 
60  | 0  |         s->s3.alert_dispatch = 1;  | 
61  |  |         /* fprintf(stderr, "not done with alert\n"); */  | 
62  | 0  |     } else { | 
63  | 0  |         (void)BIO_flush(s->wbio);  | 
64  |  | 
  | 
65  | 0  |         if (s->msg_callback)  | 
66  | 0  |             s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3.send_alert,  | 
67  | 0  |                             2, ssl, s->msg_callback_arg);  | 
68  |  | 
  | 
69  | 0  |         if (s->info_callback != NULL)  | 
70  | 0  |             cb = s->info_callback;  | 
71  | 0  |         else if (ssl->ctx->info_callback != NULL)  | 
72  | 0  |             cb = ssl->ctx->info_callback;  | 
73  |  | 
  | 
74  | 0  |         if (cb != NULL) { | 
75  | 0  |             j = (s->s3.send_alert[0] << 8) | s->s3.send_alert[1];  | 
76  | 0  |             cb(ssl, SSL_CB_WRITE_ALERT, j);  | 
77  | 0  |         }  | 
78  | 0  |     }  | 
79  | 0  |     return i;  | 
80  | 0  | }  |