/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 | 3.62k | { |
42 | 3.62k | int i, j; |
43 | 3.62k | void (*cb) (const SSL *ssl, int type, int val) = NULL; |
44 | 3.62k | unsigned char buf[DTLS1_AL_HEADER_LENGTH]; |
45 | 3.62k | unsigned char *ptr = &buf[0]; |
46 | 3.62k | size_t written; |
47 | 3.62k | SSL_CONNECTION *s = SSL_CONNECTION_FROM_SSL_ONLY(ssl); |
48 | | |
49 | 3.62k | if (s == NULL) |
50 | 0 | return 0; |
51 | | |
52 | 3.62k | s->s3.alert_dispatch = SSL_ALERT_DISPATCH_NONE; |
53 | | |
54 | 3.62k | memset(buf, 0, sizeof(buf)); |
55 | 3.62k | *ptr++ = s->s3.send_alert[0]; |
56 | 3.62k | *ptr++ = s->s3.send_alert[1]; |
57 | | |
58 | 3.62k | i = do_dtls1_write(s, SSL3_RT_ALERT, &buf[0], sizeof(buf), &written); |
59 | 3.62k | if (i <= 0) { |
60 | 0 | s->s3.alert_dispatch = 1; |
61 | | /* fprintf(stderr, "not done with alert\n"); */ |
62 | 3.62k | } else { |
63 | 3.62k | (void)BIO_flush(s->wbio); |
64 | | |
65 | 3.62k | 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 | 3.62k | if (s->info_callback != NULL) |
70 | 0 | cb = s->info_callback; |
71 | 3.62k | else if (ssl->ctx->info_callback != NULL) |
72 | 0 | cb = ssl->ctx->info_callback; |
73 | | |
74 | 3.62k | 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 | 3.62k | } |
79 | 3.62k | return i; |
80 | 3.62k | } |