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