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