xref: /dragonfly/crypto/libressl/ssl/ssl_txt.c (revision de0e0e4d)
1*de0e0e4dSAntonio Huete Jimenez /* $OpenBSD: ssl_txt.c,v 1.35 2022/06/07 17:55:08 tb Exp $ */
2f5b1c8a1SJohn Marino /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3f5b1c8a1SJohn Marino  * All rights reserved.
4f5b1c8a1SJohn Marino  *
5f5b1c8a1SJohn Marino  * This package is an SSL implementation written
6f5b1c8a1SJohn Marino  * by Eric Young (eay@cryptsoft.com).
7f5b1c8a1SJohn Marino  * The implementation was written so as to conform with Netscapes SSL.
8f5b1c8a1SJohn Marino  *
9f5b1c8a1SJohn Marino  * This library is free for commercial and non-commercial use as long as
10f5b1c8a1SJohn Marino  * the following conditions are aheared to.  The following conditions
11f5b1c8a1SJohn Marino  * apply to all code found in this distribution, be it the RC4, RSA,
12f5b1c8a1SJohn Marino  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13f5b1c8a1SJohn Marino  * included with this distribution is covered by the same copyright terms
14f5b1c8a1SJohn Marino  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15f5b1c8a1SJohn Marino  *
16f5b1c8a1SJohn Marino  * Copyright remains Eric Young's, and as such any Copyright notices in
17f5b1c8a1SJohn Marino  * the code are not to be removed.
18f5b1c8a1SJohn Marino  * If this package is used in a product, Eric Young should be given attribution
19f5b1c8a1SJohn Marino  * as the author of the parts of the library used.
20f5b1c8a1SJohn Marino  * This can be in the form of a textual message at program startup or
21f5b1c8a1SJohn Marino  * in documentation (online or textual) provided with the package.
22f5b1c8a1SJohn Marino  *
23f5b1c8a1SJohn Marino  * Redistribution and use in source and binary forms, with or without
24f5b1c8a1SJohn Marino  * modification, are permitted provided that the following conditions
25f5b1c8a1SJohn Marino  * are met:
26f5b1c8a1SJohn Marino  * 1. Redistributions of source code must retain the copyright
27f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer.
28f5b1c8a1SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
29f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
30f5b1c8a1SJohn Marino  *    documentation and/or other materials provided with the distribution.
31f5b1c8a1SJohn Marino  * 3. All advertising materials mentioning features or use of this software
32f5b1c8a1SJohn Marino  *    must display the following acknowledgement:
33f5b1c8a1SJohn Marino  *    "This product includes cryptographic software written by
34f5b1c8a1SJohn Marino  *     Eric Young (eay@cryptsoft.com)"
35f5b1c8a1SJohn Marino  *    The word 'cryptographic' can be left out if the rouines from the library
36f5b1c8a1SJohn Marino  *    being used are not cryptographic related :-).
37f5b1c8a1SJohn Marino  * 4. If you include any Windows specific code (or a derivative thereof) from
38f5b1c8a1SJohn Marino  *    the apps directory (application code) you must include an acknowledgement:
39f5b1c8a1SJohn Marino  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40f5b1c8a1SJohn Marino  *
41f5b1c8a1SJohn Marino  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42f5b1c8a1SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43f5b1c8a1SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44f5b1c8a1SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45f5b1c8a1SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46f5b1c8a1SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47f5b1c8a1SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48f5b1c8a1SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49f5b1c8a1SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50f5b1c8a1SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51f5b1c8a1SJohn Marino  * SUCH DAMAGE.
52f5b1c8a1SJohn Marino  *
53f5b1c8a1SJohn Marino  * The licence and distribution terms for any publically available version or
54f5b1c8a1SJohn Marino  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55f5b1c8a1SJohn Marino  * copied and put under another distribution licence
56f5b1c8a1SJohn Marino  * [including the GNU Public Licence.]
57f5b1c8a1SJohn Marino  */
58f5b1c8a1SJohn Marino /* ====================================================================
59f5b1c8a1SJohn Marino  * Copyright 2005 Nokia. All rights reserved.
60f5b1c8a1SJohn Marino  *
61f5b1c8a1SJohn Marino  * The portions of the attached software ("Contribution") is developed by
62f5b1c8a1SJohn Marino  * Nokia Corporation and is licensed pursuant to the OpenSSL open source
63f5b1c8a1SJohn Marino  * license.
64f5b1c8a1SJohn Marino  *
65f5b1c8a1SJohn Marino  * The Contribution, originally written by Mika Kousa and Pasi Eronen of
66f5b1c8a1SJohn Marino  * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
67f5b1c8a1SJohn Marino  * support (see RFC 4279) to OpenSSL.
68f5b1c8a1SJohn Marino  *
69f5b1c8a1SJohn Marino  * No patent licenses or other rights except those expressly stated in
70f5b1c8a1SJohn Marino  * the OpenSSL open source license shall be deemed granted or received
71f5b1c8a1SJohn Marino  * expressly, by implication, estoppel, or otherwise.
72f5b1c8a1SJohn Marino  *
73f5b1c8a1SJohn Marino  * No assurances are provided by Nokia that the Contribution does not
74f5b1c8a1SJohn Marino  * infringe the patent or other intellectual property rights of any third
75f5b1c8a1SJohn Marino  * party or that the license provides you with all the necessary rights
76f5b1c8a1SJohn Marino  * to make use of the Contribution.
77f5b1c8a1SJohn Marino  *
78f5b1c8a1SJohn Marino  * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
79f5b1c8a1SJohn Marino  * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
80f5b1c8a1SJohn Marino  * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
81f5b1c8a1SJohn Marino  * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
82f5b1c8a1SJohn Marino  * OTHERWISE.
83f5b1c8a1SJohn Marino  */
84f5b1c8a1SJohn Marino 
85f5b1c8a1SJohn Marino #include <inttypes.h>
86f5b1c8a1SJohn Marino #include <stdio.h>
87f5b1c8a1SJohn Marino 
88f5b1c8a1SJohn Marino #include <openssl/buffer.h>
89f5b1c8a1SJohn Marino 
90f5b1c8a1SJohn Marino #include "ssl_locl.h"
91f5b1c8a1SJohn Marino 
92f5b1c8a1SJohn Marino int
SSL_SESSION_print_fp(FILE * fp,const SSL_SESSION * x)93f5b1c8a1SJohn Marino SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x)
94f5b1c8a1SJohn Marino {
95f5b1c8a1SJohn Marino 	BIO *b;
96f5b1c8a1SJohn Marino 	int ret;
97f5b1c8a1SJohn Marino 
98*de0e0e4dSAntonio Huete Jimenez 	if ((b = BIO_new(BIO_s_file())) == NULL) {
9972c33676SMaxim Ag 		SSLerrorx(ERR_R_BUF_LIB);
100*de0e0e4dSAntonio Huete Jimenez 		return 0;
101f5b1c8a1SJohn Marino 	}
102f5b1c8a1SJohn Marino 	BIO_set_fp(b, fp, BIO_NOCLOSE);
103f5b1c8a1SJohn Marino 	ret = SSL_SESSION_print(b, x);
104f5b1c8a1SJohn Marino 	BIO_free(b);
105*de0e0e4dSAntonio Huete Jimenez 	return ret;
106f5b1c8a1SJohn Marino }
107f5b1c8a1SJohn Marino 
108f5b1c8a1SJohn Marino int
SSL_SESSION_print(BIO * bp,const SSL_SESSION * x)109f5b1c8a1SJohn Marino SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
110f5b1c8a1SJohn Marino {
111*de0e0e4dSAntonio Huete Jimenez 	size_t i;
112*de0e0e4dSAntonio Huete Jimenez 	int ret = 0;
113f5b1c8a1SJohn Marino 
114f5b1c8a1SJohn Marino 	if (x == NULL)
115f5b1c8a1SJohn Marino 		goto err;
116*de0e0e4dSAntonio Huete Jimenez 
117f5b1c8a1SJohn Marino 	if (BIO_puts(bp, "SSL-Session:\n") <= 0)
118f5b1c8a1SJohn Marino 		goto err;
119f5b1c8a1SJohn Marino 
120*de0e0e4dSAntonio Huete Jimenez 	if (BIO_printf(bp, "    Protocol  : %s\n",
121*de0e0e4dSAntonio Huete Jimenez 	    ssl_version_string(x->ssl_version)) <= 0)
122f5b1c8a1SJohn Marino 		goto err;
123f5b1c8a1SJohn Marino 
124f5b1c8a1SJohn Marino 	if (x->cipher == NULL) {
125*de0e0e4dSAntonio Huete Jimenez 		if (BIO_printf(bp, "    Cipher    : %04lX\n",
126*de0e0e4dSAntonio Huete Jimenez 		    x->cipher_id & SSL3_CK_VALUE_MASK) <= 0)
127f5b1c8a1SJohn Marino 			goto err;
128f5b1c8a1SJohn Marino 	} else {
129*de0e0e4dSAntonio Huete Jimenez 		const char *cipher_name = "unknown";
130*de0e0e4dSAntonio Huete Jimenez 
131*de0e0e4dSAntonio Huete Jimenez 		if (x->cipher->name != NULL)
132*de0e0e4dSAntonio Huete Jimenez 			cipher_name = x->cipher->name;
133*de0e0e4dSAntonio Huete Jimenez 
134*de0e0e4dSAntonio Huete Jimenez 		if (BIO_printf(bp, "    Cipher    : %s\n", cipher_name) <= 0)
135f5b1c8a1SJohn Marino 			goto err;
136f5b1c8a1SJohn Marino 	}
137*de0e0e4dSAntonio Huete Jimenez 
138f5b1c8a1SJohn Marino 	if (BIO_puts(bp, "    Session-ID: ") <= 0)
139f5b1c8a1SJohn Marino 		goto err;
140*de0e0e4dSAntonio Huete Jimenez 
141f5b1c8a1SJohn Marino 	for (i = 0; i < x->session_id_length; i++) {
142f5b1c8a1SJohn Marino 		if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0)
143f5b1c8a1SJohn Marino 			goto err;
144f5b1c8a1SJohn Marino 	}
145*de0e0e4dSAntonio Huete Jimenez 
146f5b1c8a1SJohn Marino 	if (BIO_puts(bp, "\n    Session-ID-ctx: ") <= 0)
147f5b1c8a1SJohn Marino 		goto err;
148*de0e0e4dSAntonio Huete Jimenez 
149f5b1c8a1SJohn Marino 	for (i = 0; i < x->sid_ctx_length; i++) {
150f5b1c8a1SJohn Marino 		if (BIO_printf(bp, "%02X", x->sid_ctx[i]) <= 0)
151f5b1c8a1SJohn Marino 			goto err;
152f5b1c8a1SJohn Marino 	}
153*de0e0e4dSAntonio Huete Jimenez 
154f5b1c8a1SJohn Marino 	if (BIO_puts(bp, "\n    Master-Key: ") <= 0)
155f5b1c8a1SJohn Marino 		goto err;
156*de0e0e4dSAntonio Huete Jimenez 
157*de0e0e4dSAntonio Huete Jimenez 	for (i = 0; i < x->master_key_length; i++) {
158f5b1c8a1SJohn Marino 		if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
159f5b1c8a1SJohn Marino 			goto err;
160f5b1c8a1SJohn Marino 	}
161*de0e0e4dSAntonio Huete Jimenez 
162*de0e0e4dSAntonio Huete Jimenez 	if (x->tlsext_tick_lifetime_hint > 0) {
163f5b1c8a1SJohn Marino 		if (BIO_printf(bp,
164*de0e0e4dSAntonio Huete Jimenez 		    "\n    TLS session ticket lifetime hint: %u (seconds)",
165f5b1c8a1SJohn Marino 		    x->tlsext_tick_lifetime_hint) <= 0)
166f5b1c8a1SJohn Marino 			goto err;
167f5b1c8a1SJohn Marino 	}
168*de0e0e4dSAntonio Huete Jimenez 
169*de0e0e4dSAntonio Huete Jimenez 	if (x->tlsext_tick != NULL) {
170f5b1c8a1SJohn Marino 		if (BIO_puts(bp, "\n    TLS session ticket:\n") <= 0)
171f5b1c8a1SJohn Marino 			goto err;
172*de0e0e4dSAntonio Huete Jimenez 		if (BIO_dump_indent(bp, x->tlsext_tick, x->tlsext_ticklen,
173*de0e0e4dSAntonio Huete Jimenez 		    4) <= 0)
174f5b1c8a1SJohn Marino 			goto err;
175f5b1c8a1SJohn Marino 	}
176f5b1c8a1SJohn Marino 
177f5b1c8a1SJohn Marino 	if (x->time != 0) {
178*de0e0e4dSAntonio Huete Jimenez 		if (BIO_printf(bp, "\n    Start Time: %"PRId64,
179*de0e0e4dSAntonio Huete Jimenez 		    (int64_t)x->time) <= 0)
180f5b1c8a1SJohn Marino 			goto err;
181f5b1c8a1SJohn Marino 	}
182*de0e0e4dSAntonio Huete Jimenez 
183*de0e0e4dSAntonio Huete Jimenez 	if (x->timeout != 0) {
184*de0e0e4dSAntonio Huete Jimenez 		if (BIO_printf(bp, "\n    Timeout   : %ld (sec)",
185*de0e0e4dSAntonio Huete Jimenez 		    x->timeout) <= 0)
186f5b1c8a1SJohn Marino 			goto err;
187f5b1c8a1SJohn Marino 	}
188*de0e0e4dSAntonio Huete Jimenez 
189f5b1c8a1SJohn Marino 	if (BIO_puts(bp, "\n") <= 0)
190f5b1c8a1SJohn Marino 		goto err;
191f5b1c8a1SJohn Marino 
192*de0e0e4dSAntonio Huete Jimenez 	if (BIO_printf(bp, "    Verify return code: %ld (%s)\n",
193*de0e0e4dSAntonio Huete Jimenez 	    x->verify_result,
194f5b1c8a1SJohn Marino 	    X509_verify_cert_error_string(x->verify_result)) <= 0)
195f5b1c8a1SJohn Marino 		goto err;
196f5b1c8a1SJohn Marino 
197*de0e0e4dSAntonio Huete Jimenez 	ret = 1;
198f5b1c8a1SJohn Marino  err:
199*de0e0e4dSAntonio Huete Jimenez 	return ret;
200f5b1c8a1SJohn Marino }
201