Coverage Report

Created: 2025-06-13 06:58

/src/openssl32/ssl/ssl_txt.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
3
 * Copyright 2005 Nokia. All rights reserved.
4
 *
5
 * Licensed under the Apache License 2.0 (the "License").  You may not use
6
 * this file except in compliance with the License.  You can obtain a copy
7
 * in the file LICENSE in the source distribution or at
8
 * https://www.openssl.org/source/license.html
9
 */
10
11
#include <stdio.h>
12
#include <openssl/buffer.h>
13
#include "ssl_local.h"
14
15
#ifndef OPENSSL_NO_STDIO
16
int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x)
17
0
{
18
0
    BIO *b;
19
0
    int ret;
20
21
0
    if ((b = BIO_new(BIO_s_file())) == NULL) {
22
0
        ERR_raise(ERR_LIB_SSL, ERR_R_BUF_LIB);
23
0
        return 0;
24
0
    }
25
0
    BIO_set_fp(b, fp, BIO_NOCLOSE);
26
0
    ret = SSL_SESSION_print(b, x);
27
0
    BIO_free(b);
28
0
    return ret;
29
0
}
30
#endif
31
32
int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
33
787
{
34
787
    size_t i;
35
787
    const char *s;
36
787
    int istls13;
37
38
787
    if (x == NULL)
39
0
        goto err;
40
787
    istls13 = (x->ssl_version == TLS1_3_VERSION);
41
787
    if (BIO_puts(bp, "SSL-Session:\n") <= 0)
42
0
        goto err;
43
787
    s = ssl_protocol_to_string(x->ssl_version);
44
787
    if (BIO_printf(bp, "    Protocol  : %s\n", s) <= 0)
45
0
        goto err;
46
47
787
    if (x->cipher == NULL) {
48
0
        if (((x->cipher_id) & 0xff000000) == 0x02000000) {
49
0
            if (BIO_printf(bp, "    Cipher    : %06lX\n",
50
0
                           x->cipher_id & 0xffffff) <= 0)
51
0
                goto err;
52
0
        } else {
53
0
            if (BIO_printf(bp, "    Cipher    : %04lX\n",
54
0
                           x->cipher_id & 0xffff) <= 0)
55
0
                goto err;
56
0
        }
57
787
    } else {
58
787
        if (BIO_printf(bp, "    Cipher    : %s\n",
59
787
                       ((x->cipher->name == NULL) ? "unknown"
60
787
                                                  : x->cipher->name)) <= 0)
61
0
            goto err;
62
787
    }
63
787
    if (BIO_puts(bp, "    Session-ID: ") <= 0)
64
0
        goto err;
65
1.36k
    for (i = 0; i < x->session_id_length; i++) {
66
575
        if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0)
67
0
            goto err;
68
575
    }
69
787
    if (BIO_puts(bp, "\n    Session-ID-ctx: ") <= 0)
70
0
        goto err;
71
937
    for (i = 0; i < x->sid_ctx_length; i++) {
72
150
        if (BIO_printf(bp, "%02X", x->sid_ctx[i]) <= 0)
73
0
            goto err;
74
150
    }
75
787
    if (istls13) {
76
18
        if (BIO_puts(bp, "\n    Resumption PSK: ") <= 0)
77
0
            goto err;
78
769
    } else if (BIO_puts(bp, "\n    Master-Key: ") <= 0)
79
0
        goto err;
80
8.74k
    for (i = 0; i < x->master_key_length; i++) {
81
7.95k
        if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
82
0
            goto err;
83
7.95k
    }
84
787
#ifndef OPENSSL_NO_PSK
85
787
    if (BIO_puts(bp, "\n    PSK identity: ") <= 0)
86
0
        goto err;
87
787
    if (BIO_printf(bp, "%s", x->psk_identity ? x->psk_identity : "None") <= 0)
88
2
        goto err;
89
785
    if (BIO_puts(bp, "\n    PSK identity hint: ") <= 0)
90
0
        goto err;
91
785
    if (BIO_printf
92
785
        (bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0)
93
2
        goto err;
94
783
#endif
95
783
#ifndef OPENSSL_NO_SRP
96
783
    if (BIO_puts(bp, "\n    SRP username: ") <= 0)
97
0
        goto err;
98
783
    if (BIO_printf(bp, "%s", x->srp_username ? x->srp_username : "None") <= 0)
99
3
        goto err;
100
780
#endif
101
780
    if (x->ext.tick_lifetime_hint) {
102
236
        if (BIO_printf(bp,
103
236
                       "\n    TLS session ticket lifetime hint: %ld (seconds)",
104
236
                       x->ext.tick_lifetime_hint) <= 0)
105
0
            goto err;
106
236
    }
107
780
    if (x->ext.tick) {
108
10
        if (BIO_puts(bp, "\n    TLS session ticket:\n") <= 0)
109
0
            goto err;
110
10
        if (BIO_dump_indent
111
10
            (bp, (const char *)x->ext.tick, (int)x->ext.ticklen, 4)
112
10
            <= 0)
113
2
            goto err;
114
10
    }
115
778
#ifndef OPENSSL_NO_COMP
116
778
    if (x->compress_meth != 0) {
117
2
        SSL_COMP *comp = NULL;
118
119
2
        if (!ssl_cipher_get_evp(NULL, x, NULL, NULL, NULL, NULL, &comp, 0))
120
0
            goto err;
121
2
        if (comp == NULL) {
122
2
            if (BIO_printf(bp, "\n    Compression: %d", x->compress_meth) <= 0)
123
0
                goto err;
124
2
        } else {
125
0
            if (BIO_printf(bp, "\n    Compression: %d (%s)", comp->id,
126
0
                           comp->name) <= 0)
127
0
                goto err;
128
0
        }
129
2
    }
130
778
#endif
131
778
    if (!ossl_time_is_zero(x->time)) {
132
775
        if (BIO_printf(bp, "\n    Start Time: %lld",
133
775
                       (long long)ossl_time_to_time_t(x->time)) <= 0)
134
0
            goto err;
135
775
    }
136
778
    if (!ossl_time_is_zero(x->timeout)) {
137
776
        if (BIO_printf(bp, "\n    Timeout   : %lld (sec)",
138
776
                       (long long)ossl_time2seconds(x->timeout)) <= 0)
139
0
            goto err;
140
776
    }
141
778
    if (BIO_puts(bp, "\n") <= 0)
142
0
        goto err;
143
144
778
    if (BIO_puts(bp, "    Verify return code: ") <= 0)
145
0
        goto err;
146
778
    if (BIO_printf(bp, "%ld (%s)\n", x->verify_result,
147
778
                   X509_verify_cert_error_string(x->verify_result)) <= 0)
148
0
        goto err;
149
150
778
    if (BIO_printf(bp, "    Extended master secret: %s\n",
151
778
                   x->flags & SSL_SESS_FLAG_EXTMS ? "yes" : "no") <= 0)
152
0
        goto err;
153
154
778
    if (istls13) {
155
18
        if (BIO_printf(bp, "    Max Early Data: %u\n",
156
18
                       (unsigned int)x->ext.max_early_data) <= 0)
157
0
            goto err;
158
18
    }
159
160
778
    return 1;
161
9
 err:
162
9
    return 0;
163
778
}
164
165
/*
166
 * print session id and master key in NSS keylog format (RSA
167
 * Session-ID:<session id> Master-Key:<master key>)
168
 */
169
int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x)
170
0
{
171
0
    size_t i;
172
173
0
    if (x == NULL)
174
0
        goto err;
175
0
    if (x->session_id_length == 0 || x->master_key_length == 0)
176
0
        goto err;
177
178
    /*
179
     * the RSA prefix is required by the format's definition although there's
180
     * nothing RSA-specific in the output, therefore, we don't have to check if
181
     * the cipher suite is based on RSA
182
     */
183
0
    if (BIO_puts(bp, "RSA ") <= 0)
184
0
        goto err;
185
186
0
    if (BIO_puts(bp, "Session-ID:") <= 0)
187
0
        goto err;
188
0
    for (i = 0; i < x->session_id_length; i++) {
189
0
        if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0)
190
0
            goto err;
191
0
    }
192
0
    if (BIO_puts(bp, " Master-Key:") <= 0)
193
0
        goto err;
194
0
    for (i = 0; i < x->master_key_length; i++) {
195
0
        if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
196
0
            goto err;
197
0
    }
198
0
    if (BIO_puts(bp, "\n") <= 0)
199
0
        goto err;
200
201
0
    return 1;
202
0
 err:
203
0
    return 0;
204
0
}