]>
Commit | Line | Data |
---|---|---|
846e33c7 RS |
1 | /* |
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | |
c80149d9 | 3 | * Copyright 2005 Nokia. All rights reserved. |
d02b48c6 | 4 | * |
846e33c7 RS |
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 | |
d02b48c6 | 9 | */ |
846e33c7 | 10 | |
d02b48c6 | 11 | #include <stdio.h> |
ec577822 | 12 | #include <openssl/buffer.h> |
d02b48c6 RE |
13 | #include "ssl_locl.h" |
14 | ||
4b618848 | 15 | #ifndef OPENSSL_NO_STDIO |
0821bcd4 | 16 | int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x) |
0f113f3e MC |
17 | { |
18 | BIO *b; | |
19 | int ret; | |
d02b48c6 | 20 | |
9982cbbb | 21 | if ((b = BIO_new(BIO_s_file())) == NULL) { |
0f113f3e MC |
22 | SSLerr(SSL_F_SSL_SESSION_PRINT_FP, ERR_R_BUF_LIB); |
23 | return (0); | |
24 | } | |
25 | BIO_set_fp(b, fp, BIO_NOCLOSE); | |
26 | ret = SSL_SESSION_print(b, x); | |
27 | BIO_free(b); | |
28 | return (ret); | |
29 | } | |
d02b48c6 RE |
30 | #endif |
31 | ||
0821bcd4 | 32 | int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) |
0f113f3e | 33 | { |
ec60ccc1 | 34 | size_t i; |
0f113f3e | 35 | const char *s; |
d02b48c6 | 36 | |
0f113f3e MC |
37 | if (x == NULL) |
38 | goto err; | |
39 | if (BIO_puts(bp, "SSL-Session:\n") <= 0) | |
40 | goto err; | |
3eb2aff4 | 41 | s = ssl_protocol_to_string(x->ssl_version); |
0f113f3e MC |
42 | if (BIO_printf(bp, " Protocol : %s\n", s) <= 0) |
43 | goto err; | |
58964a49 | 44 | |
0f113f3e MC |
45 | if (x->cipher == NULL) { |
46 | if (((x->cipher_id) & 0xff000000) == 0x02000000) { | |
47 | if (BIO_printf | |
48 | (bp, " Cipher : %06lX\n", x->cipher_id & 0xffffff) <= 0) | |
49 | goto err; | |
50 | } else { | |
51 | if (BIO_printf | |
52 | (bp, " Cipher : %04lX\n", x->cipher_id & 0xffff) <= 0) | |
53 | goto err; | |
54 | } | |
55 | } else { | |
56 | if (BIO_printf | |
57 | (bp, " Cipher : %s\n", | |
58 | ((x->cipher == NULL) ? "unknown" : x->cipher->name)) <= 0) | |
59 | goto err; | |
60 | } | |
61 | if (BIO_puts(bp, " Session-ID: ") <= 0) | |
62 | goto err; | |
63 | for (i = 0; i < x->session_id_length; i++) { | |
64 | if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0) | |
65 | goto err; | |
66 | } | |
67 | if (BIO_puts(bp, "\n Session-ID-ctx: ") <= 0) | |
68 | goto err; | |
69 | for (i = 0; i < x->sid_ctx_length; i++) { | |
70 | if (BIO_printf(bp, "%02X", x->sid_ctx[i]) <= 0) | |
71 | goto err; | |
72 | } | |
73 | if (BIO_puts(bp, "\n Master-Key: ") <= 0) | |
74 | goto err; | |
ec60ccc1 | 75 | for (i = 0; i < x->master_key_length; i++) { |
0f113f3e MC |
76 | if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0) |
77 | goto err; | |
78 | } | |
ddac1974 | 79 | #ifndef OPENSSL_NO_PSK |
0f113f3e MC |
80 | if (BIO_puts(bp, "\n PSK identity: ") <= 0) |
81 | goto err; | |
82 | if (BIO_printf(bp, "%s", x->psk_identity ? x->psk_identity : "None") <= 0) | |
83 | goto err; | |
84 | if (BIO_puts(bp, "\n PSK identity hint: ") <= 0) | |
85 | goto err; | |
86 | if (BIO_printf | |
87 | (bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0) | |
88 | goto err; | |
ddac1974 | 89 | #endif |
edc032b5 | 90 | #ifndef OPENSSL_NO_SRP |
0f113f3e MC |
91 | if (BIO_puts(bp, "\n SRP username: ") <= 0) |
92 | goto err; | |
93 | if (BIO_printf(bp, "%s", x->srp_username ? x->srp_username : "None") <= 0) | |
94 | goto err; | |
edc032b5 | 95 | #endif |
aff8c126 | 96 | if (x->ext.tick_lifetime_hint) { |
0f113f3e MC |
97 | if (BIO_printf(bp, |
98 | "\n TLS session ticket lifetime hint: %ld (seconds)", | |
aff8c126 | 99 | x->ext.tick_lifetime_hint) <= 0) |
0f113f3e MC |
100 | goto err; |
101 | } | |
aff8c126 | 102 | if (x->ext.tick) { |
0f113f3e MC |
103 | if (BIO_puts(bp, "\n TLS session ticket:\n") <= 0) |
104 | goto err; | |
348240c6 | 105 | /* TODO(size_t): Convert this call */ |
a230b26e | 106 | if (BIO_dump_indent |
aff8c126 | 107 | (bp, (const char *)x->ext.tick, (int)x->ext.ticklen, 4) |
0f113f3e MC |
108 | <= 0) |
109 | goto err; | |
110 | } | |
09b6c2ef | 111 | #ifndef OPENSSL_NO_COMP |
0f113f3e MC |
112 | if (x->compress_meth != 0) { |
113 | SSL_COMP *comp = NULL; | |
413c4f45 | 114 | |
61986d32 | 115 | if (!ssl_cipher_get_evp(x, NULL, NULL, NULL, NULL, &comp, 0)) |
69f68237 | 116 | goto err; |
0f113f3e | 117 | if (comp == NULL) { |
a230b26e | 118 | if (BIO_printf(bp, "\n Compression: %d", x->compress_meth) <= 0) |
0f113f3e MC |
119 | goto err; |
120 | } else { | |
9a555706 | 121 | if (BIO_printf(bp, "\n Compression: %d (%s)", comp->id, |
a230b26e | 122 | comp->name) <= 0) |
0f113f3e MC |
123 | goto err; |
124 | } | |
125 | } | |
09b6c2ef | 126 | #endif |
0f113f3e MC |
127 | if (x->time != 0L) { |
128 | if (BIO_printf(bp, "\n Start Time: %ld", x->time) <= 0) | |
129 | goto err; | |
130 | } | |
131 | if (x->timeout != 0L) { | |
132 | if (BIO_printf(bp, "\n Timeout : %ld (sec)", x->timeout) <= 0) | |
133 | goto err; | |
134 | } | |
135 | if (BIO_puts(bp, "\n") <= 0) | |
136 | goto err; | |
137 | ||
138 | if (BIO_puts(bp, " Verify return code: ") <= 0) | |
139 | goto err; | |
140 | if (BIO_printf(bp, "%ld (%s)\n", x->verify_result, | |
141 | X509_verify_cert_error_string(x->verify_result)) <= 0) | |
142 | goto err; | |
25f923dd | 143 | |
ddc06b35 DSH |
144 | if (BIO_printf(bp, " Extended master secret: %s\n", |
145 | x->flags & SSL_SESS_FLAG_EXTMS ? "yes" : "no") <= 0) | |
146 | goto err; | |
147 | ||
208fb891 | 148 | return 1; |
0f113f3e MC |
149 | err: |
150 | return (0); | |
151 | } | |
d02b48c6 | 152 | |
0f113f3e MC |
153 | /* |
154 | * print session id and master key in NSS keylog format (RSA | |
155 | * Session-ID:<session id> Master-Key:<master key>) | |
156 | */ | |
189ae368 | 157 | int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x) |
0f113f3e | 158 | { |
ec60ccc1 | 159 | size_t i; |
189ae368 | 160 | |
0f113f3e MC |
161 | if (x == NULL) |
162 | goto err; | |
163 | if (x->session_id_length == 0 || x->master_key_length == 0) | |
164 | goto err; | |
189ae368 | 165 | |
0f113f3e MC |
166 | /* |
167 | * the RSA prefix is required by the format's definition although there's | |
8483a003 | 168 | * nothing RSA-specific in the output, therefore, we don't have to check if |
0f113f3e MC |
169 | * the cipher suite is based on RSA |
170 | */ | |
171 | if (BIO_puts(bp, "RSA ") <= 0) | |
172 | goto err; | |
189ae368 | 173 | |
0f113f3e MC |
174 | if (BIO_puts(bp, "Session-ID:") <= 0) |
175 | goto err; | |
176 | for (i = 0; i < x->session_id_length; i++) { | |
177 | if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0) | |
178 | goto err; | |
179 | } | |
180 | if (BIO_puts(bp, " Master-Key:") <= 0) | |
181 | goto err; | |
ec60ccc1 | 182 | for (i = 0; i < x->master_key_length; i++) { |
0f113f3e MC |
183 | if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0) |
184 | goto err; | |
185 | } | |
186 | if (BIO_puts(bp, "\n") <= 0) | |
187 | goto err; | |
189ae368 | 188 | |
208fb891 | 189 | return 1; |
0f113f3e MC |
190 | err: |
191 | return (0); | |
192 | } |