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