2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /* ====================================================================
11 * Copyright 2005 Nokia. All rights reserved.
13 * The portions of the attached software ("Contribution") is developed by
14 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
17 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
18 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
19 * support (see RFC 4279) to OpenSSL.
21 * No patent licenses or other rights except those expressly stated in
22 * the OpenSSL open source license shall be deemed granted or received
23 * expressly, by implication, estoppel, or otherwise.
25 * No assurances are provided by Nokia that the Contribution does not
26 * infringe the patent or other intellectual property rights of any third
27 * party or that the license provides you with all the necessary rights
28 * to make use of the Contribution.
30 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
31 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
32 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
33 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
38 #include <openssl/buffer.h>
41 #ifndef OPENSSL_NO_STDIO
42 int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x)
47 if ((b = BIO_new(BIO_s_file())) == NULL) {
48 SSLerr(SSL_F_SSL_SESSION_PRINT_FP, ERR_R_BUF_LIB);
51 BIO_set_fp(b, fp, BIO_NOCLOSE);
52 ret = SSL_SESSION_print(b, x);
58 int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
65 if (BIO_puts(bp, "SSL-Session:\n") <= 0)
67 s = ssl_protocol_to_string(x->ssl_version);
68 if (BIO_printf(bp, " Protocol : %s\n", s) <= 0)
71 if (x->cipher == NULL) {
72 if (((x->cipher_id) & 0xff000000) == 0x02000000) {
74 (bp, " Cipher : %06lX\n", x->cipher_id & 0xffffff) <= 0)
78 (bp, " Cipher : %04lX\n", x->cipher_id & 0xffff) <= 0)
83 (bp, " Cipher : %s\n",
84 ((x->cipher == NULL) ? "unknown" : x->cipher->name)) <= 0)
87 if (BIO_puts(bp, " Session-ID: ") <= 0)
89 for (i = 0; i < x->session_id_length; i++) {
90 if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0)
93 if (BIO_puts(bp, "\n Session-ID-ctx: ") <= 0)
95 for (i = 0; i < x->sid_ctx_length; i++) {
96 if (BIO_printf(bp, "%02X", x->sid_ctx[i]) <= 0)
99 if (BIO_puts(bp, "\n Master-Key: ") <= 0)
101 for (i = 0; i < x->master_key_length; i++) {
102 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
105 #ifndef OPENSSL_NO_PSK
106 if (BIO_puts(bp, "\n PSK identity: ") <= 0)
108 if (BIO_printf(bp, "%s", x->psk_identity ? x->psk_identity : "None") <= 0)
110 if (BIO_puts(bp, "\n PSK identity hint: ") <= 0)
113 (bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0)
116 #ifndef OPENSSL_NO_SRP
117 if (BIO_puts(bp, "\n SRP username: ") <= 0)
119 if (BIO_printf(bp, "%s", x->srp_username ? x->srp_username : "None") <= 0)
122 if (x->tlsext_tick_lifetime_hint) {
124 "\n TLS session ticket lifetime hint: %ld (seconds)",
125 x->tlsext_tick_lifetime_hint) <= 0)
128 if (x->tlsext_tick) {
129 if (BIO_puts(bp, "\n TLS session ticket:\n") <= 0)
131 /* TODO(size_t): Convert this call */
133 (bp, (const char *)x->tlsext_tick, (int)x->tlsext_ticklen, 4)
137 #ifndef OPENSSL_NO_COMP
138 if (x->compress_meth != 0) {
139 SSL_COMP *comp = NULL;
141 if (!ssl_cipher_get_evp(x, NULL, NULL, NULL, NULL, &comp, 0))
144 if (BIO_printf(bp, "\n Compression: %d", x->compress_meth) <= 0)
147 if (BIO_printf(bp, "\n Compression: %d (%s)", comp->id,
154 if (BIO_printf(bp, "\n Start Time: %ld", x->time) <= 0)
157 if (x->timeout != 0L) {
158 if (BIO_printf(bp, "\n Timeout : %ld (sec)", x->timeout) <= 0)
161 if (BIO_puts(bp, "\n") <= 0)
164 if (BIO_puts(bp, " Verify return code: ") <= 0)
166 if (BIO_printf(bp, "%ld (%s)\n", x->verify_result,
167 X509_verify_cert_error_string(x->verify_result)) <= 0)
170 if (BIO_printf(bp, " Extended master secret: %s\n",
171 x->flags & SSL_SESS_FLAG_EXTMS ? "yes" : "no") <= 0)
180 * print session id and master key in NSS keylog format (RSA
181 * Session-ID:<session id> Master-Key:<master key>)
183 int SSL_SESSION_print_keylog(BIO *bp, const SSL_SESSION *x)
189 if (x->session_id_length == 0 || x->master_key_length == 0)
193 * the RSA prefix is required by the format's definition although there's
194 * nothing RSA-specific in the output, therefore, we don't have to check if
195 * the cipher suite is based on RSA
197 if (BIO_puts(bp, "RSA ") <= 0)
200 if (BIO_puts(bp, "Session-ID:") <= 0)
202 for (i = 0; i < x->session_id_length; i++) {
203 if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0)
206 if (BIO_puts(bp, " Master-Key:") <= 0)
208 for (i = 0; i < x->master_key_length; i++) {
209 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
212 if (BIO_puts(bp, "\n") <= 0)