2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2005 Nokia. All rights reserved.
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
12 #include <openssl/buffer.h>
15 #ifndef OPENSSL_NO_STDIO
16 int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x)
21 if ((b = BIO_new(BIO_s_file())) == NULL) {
22 SSLerr(SSL_F_SSL_SESSION_PRINT_FP, ERR_R_BUF_LIB);
25 BIO_set_fp(b, fp, BIO_NOCLOSE);
26 ret = SSL_SESSION_print(b, x);
32 int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
39 if (BIO_puts(bp, "SSL-Session:\n") <= 0)
41 s = ssl_protocol_to_string(x->ssl_version);
42 if (BIO_printf(bp, " Protocol : %s\n", s) <= 0)
45 if (x->cipher == NULL) {
46 if (((x->cipher_id) & 0xff000000) == 0x02000000) {
47 if (BIO_printf(bp, " Cipher : %06lX\n",
48 x->cipher_id & 0xffffff) <= 0)
51 if (BIO_printf(bp, " Cipher : %04lX\n",
52 x->cipher_id & 0xffff) <= 0)
56 if (BIO_printf(bp, " Cipher : %s\n",
57 ((x->cipher->name == NULL) ? "unknown"
58 : x->cipher->name)) <= 0)
61 if (BIO_puts(bp, " Session-ID: ") <= 0)
63 for (i = 0; i < x->session_id_length; i++) {
64 if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0)
67 if (BIO_puts(bp, "\n Session-ID-ctx: ") <= 0)
69 for (i = 0; i < x->sid_ctx_length; i++) {
70 if (BIO_printf(bp, "%02X", x->sid_ctx[i]) <= 0)
73 if (BIO_puts(bp, "\n Master-Key: ") <= 0)
75 for (i = 0; i < x->master_key_length; i++) {
76 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
79 #ifndef OPENSSL_NO_PSK
80 if (BIO_puts(bp, "\n PSK identity: ") <= 0)
82 if (BIO_printf(bp, "%s", x->psk_identity ? x->psk_identity : "None") <= 0)
84 if (BIO_puts(bp, "\n PSK identity hint: ") <= 0)
87 (bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0)
90 #ifndef OPENSSL_NO_SRP
91 if (BIO_puts(bp, "\n SRP username: ") <= 0)
93 if (BIO_printf(bp, "%s", x->srp_username ? x->srp_username : "None") <= 0)
96 if (x->ext.tick_lifetime_hint) {
98 "\n TLS session ticket lifetime hint: %ld (seconds)",
99 x->ext.tick_lifetime_hint) <= 0)
103 if (BIO_puts(bp, "\n TLS session ticket:\n") <= 0)
105 /* TODO(size_t): Convert this call */
107 (bp, (const char *)x->ext.tick, (int)x->ext.ticklen, 4)
111 #ifndef OPENSSL_NO_COMP
112 if (x->compress_meth != 0) {
113 SSL_COMP *comp = NULL;
115 if (!ssl_cipher_get_evp(x, NULL, NULL, NULL, NULL, &comp, 0))
118 if (BIO_printf(bp, "\n Compression: %d", x->compress_meth) <= 0)
121 if (BIO_printf(bp, "\n Compression: %d (%s)", comp->id,
128 if (BIO_printf(bp, "\n Start Time: %ld", x->time) <= 0)
131 if (x->timeout != 0L) {
132 if (BIO_printf(bp, "\n Timeout : %ld (sec)", x->timeout) <= 0)
135 if (BIO_puts(bp, "\n") <= 0)
138 if (BIO_puts(bp, " Verify return code: ") <= 0)
140 if (BIO_printf(bp, "%ld (%s)\n", x->verify_result,
141 X509_verify_cert_error_string(x->verify_result)) <= 0)
144 if (BIO_printf(bp, " Extended master secret: %s\n",
145 x->flags & SSL_SESS_FLAG_EXTMS ? "yes" : "no") <= 0)
154 * print session id and master key in NSS keylog format (RSA
155 * Session-ID:<session id> Master-Key:<master key>)
157 int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x)
163 if (x->session_id_length == 0 || x->master_key_length == 0)
167 * the RSA prefix is required by the format's definition although there's
168 * nothing RSA-specific in the output, therefore, we don't have to check if
169 * the cipher suite is based on RSA
171 if (BIO_puts(bp, "RSA ") <= 0)
174 if (BIO_puts(bp, "Session-ID:") <= 0)
176 for (i = 0; i < x->session_id_length; i++) {
177 if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0)
180 if (BIO_puts(bp, " Master-Key:") <= 0)
182 for (i = 0; i < x->master_key_length; i++) {
183 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
186 if (BIO_puts(bp, "\n") <= 0)