Coverage Report

Created: 2025-06-13 06:58

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