155714Skris/* ssl/ssl_txt.c */
255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
355714Skris * All rights reserved.
455714Skris *
555714Skris * This package is an SSL implementation written
655714Skris * by Eric Young (eay@cryptsoft.com).
755714Skris * The implementation was written so as to conform with Netscapes SSL.
855714Skris *
955714Skris * This library is free for commercial and non-commercial use as long as
1055714Skris * the following conditions are aheared to.  The following conditions
1155714Skris * apply to all code found in this distribution, be it the RC4, RSA,
1255714Skris * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1355714Skris * included with this distribution is covered by the same copyright terms
1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1555714Skris *
1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in
1755714Skris * the code are not to be removed.
1855714Skris * If this package is used in a product, Eric Young should be given attribution
1955714Skris * as the author of the parts of the library used.
2055714Skris * This can be in the form of a textual message at program startup or
2155714Skris * in documentation (online or textual) provided with the package.
2255714Skris *
2355714Skris * Redistribution and use in source and binary forms, with or without
2455714Skris * modification, are permitted provided that the following conditions
2555714Skris * are met:
2655714Skris * 1. Redistributions of source code must retain the copyright
2755714Skris *    notice, this list of conditions and the following disclaimer.
2855714Skris * 2. Redistributions in binary form must reproduce the above copyright
2955714Skris *    notice, this list of conditions and the following disclaimer in the
3055714Skris *    documentation and/or other materials provided with the distribution.
3155714Skris * 3. All advertising materials mentioning features or use of this software
3255714Skris *    must display the following acknowledgement:
3355714Skris *    "This product includes cryptographic software written by
3455714Skris *     Eric Young (eay@cryptsoft.com)"
3555714Skris *    The word 'cryptographic' can be left out if the rouines from the library
3655714Skris *    being used are not cryptographic related :-).
3755714Skris * 4. If you include any Windows specific code (or a derivative thereof) from
3855714Skris *    the apps directory (application code) you must include an acknowledgement:
3955714Skris *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4055714Skris *
4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4455714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5155714Skris * SUCH DAMAGE.
5255714Skris *
5355714Skris * The licence and distribution terms for any publically available version or
5455714Skris * derivative of this code cannot be changed.  i.e. this code cannot simply be
5555714Skris * copied and put under another distribution licence
5655714Skris * [including the GNU Public Licence.]
5755714Skris */
58238405Sjkim/* ====================================================================
59238405Sjkim * Copyright 2005 Nokia. All rights reserved.
60238405Sjkim *
61238405Sjkim * The portions of the attached software ("Contribution") is developed by
62238405Sjkim * Nokia Corporation and is licensed pursuant to the OpenSSL open source
63238405Sjkim * license.
64238405Sjkim *
65238405Sjkim * The Contribution, originally written by Mika Kousa and Pasi Eronen of
66238405Sjkim * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
67238405Sjkim * support (see RFC 4279) to OpenSSL.
68238405Sjkim *
69238405Sjkim * No patent licenses or other rights except those expressly stated in
70238405Sjkim * the OpenSSL open source license shall be deemed granted or received
71238405Sjkim * expressly, by implication, estoppel, or otherwise.
72238405Sjkim *
73238405Sjkim * No assurances are provided by Nokia that the Contribution does not
74238405Sjkim * infringe the patent or other intellectual property rights of any third
75238405Sjkim * party or that the license provides you with all the necessary rights
76238405Sjkim * to make use of the Contribution.
77238405Sjkim *
78238405Sjkim * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
79238405Sjkim * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
80238405Sjkim * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
81238405Sjkim * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
82238405Sjkim * OTHERWISE.
83238405Sjkim */
8455714Skris
8555714Skris#include <stdio.h>
8655714Skris#include <openssl/buffer.h>
8755714Skris#include "ssl_locl.h"
8855714Skris
89109998Smarkm#ifndef OPENSSL_NO_FP_API
90160814Ssimonint SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x)
9155714Skris	{
9255714Skris	BIO *b;
9355714Skris	int ret;
9455714Skris
9555714Skris	if ((b=BIO_new(BIO_s_file_internal())) == NULL)
9655714Skris		{
9755714Skris		SSLerr(SSL_F_SSL_SESSION_PRINT_FP,ERR_R_BUF_LIB);
9855714Skris		return(0);
9955714Skris		}
10055714Skris	BIO_set_fp(b,fp,BIO_NOCLOSE);
10155714Skris	ret=SSL_SESSION_print(b,x);
10255714Skris	BIO_free(b);
10355714Skris	return(ret);
10455714Skris	}
10555714Skris#endif
10655714Skris
107160814Ssimonint SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
10855714Skris	{
10955714Skris	unsigned int i;
110160814Ssimon	const char *s;
11155714Skris
11255714Skris	if (x == NULL) goto err;
11355714Skris	if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err;
11455714Skris	if (x->ssl_version == SSL2_VERSION)
11555714Skris		s="SSLv2";
11655714Skris	else if (x->ssl_version == SSL3_VERSION)
11755714Skris		s="SSLv3";
118238405Sjkim	else if (x->ssl_version == TLS1_2_VERSION)
119238405Sjkim		s="TLSv1.2";
120238405Sjkim	else if (x->ssl_version == TLS1_1_VERSION)
121238405Sjkim		s="TLSv1.1";
12255714Skris	else if (x->ssl_version == TLS1_VERSION)
12355714Skris		s="TLSv1";
124205128Ssimon	else if (x->ssl_version == DTLS1_VERSION)
125205128Ssimon		s="DTLSv1";
126205128Ssimon	else if (x->ssl_version == DTLS1_BAD_VER)
127205128Ssimon		s="DTLSv1-bad";
12855714Skris	else
12955714Skris		s="unknown";
13068651Skris	if (BIO_printf(bp,"    Protocol  : %s\n",s) <= 0) goto err;
13155714Skris
13255714Skris	if (x->cipher == NULL)
13355714Skris		{
13455714Skris		if (((x->cipher_id) & 0xff000000) == 0x02000000)
13568651Skris			{
13668651Skris			if (BIO_printf(bp,"    Cipher    : %06lX\n",x->cipher_id&0xffffff) <= 0)
13768651Skris				goto err;
13868651Skris			}
13955714Skris		else
14068651Skris			{
14168651Skris			if (BIO_printf(bp,"    Cipher    : %04lX\n",x->cipher_id&0xffff) <= 0)
14268651Skris				goto err;
14368651Skris			}
14455714Skris		}
14555714Skris	else
14668651Skris		{
14768651Skris		if (BIO_printf(bp,"    Cipher    : %s\n",((x->cipher == NULL)?"unknown":x->cipher->name)) <= 0)
14868651Skris			goto err;
14968651Skris		}
15055714Skris	if (BIO_puts(bp,"    Session-ID: ") <= 0) goto err;
15155714Skris	for (i=0; i<x->session_id_length; i++)
15255714Skris		{
15368651Skris		if (BIO_printf(bp,"%02X",x->session_id[i]) <= 0) goto err;
15455714Skris		}
15559191Skris	if (BIO_puts(bp,"\n    Session-ID-ctx: ") <= 0) goto err;
15655714Skris	for (i=0; i<x->sid_ctx_length; i++)
15755714Skris		{
15868651Skris		if (BIO_printf(bp,"%02X",x->sid_ctx[i]) <= 0)
15968651Skris			goto err;
16055714Skris		}
16155714Skris	if (BIO_puts(bp,"\n    Master-Key: ") <= 0) goto err;
16255714Skris	for (i=0; i<(unsigned int)x->master_key_length; i++)
16355714Skris		{
16468651Skris		if (BIO_printf(bp,"%02X",x->master_key[i]) <= 0) goto err;
16555714Skris		}
16655714Skris	if (BIO_puts(bp,"\n    Key-Arg   : ") <= 0) goto err;
16755714Skris	if (x->key_arg_length == 0)
16855714Skris		{
16955714Skris		if (BIO_puts(bp,"None") <= 0) goto err;
17055714Skris		}
17155714Skris	else
17255714Skris		for (i=0; i<x->key_arg_length; i++)
17355714Skris			{
17468651Skris			if (BIO_printf(bp,"%02X",x->key_arg[i]) <= 0) goto err;
17555714Skris			}
176109998Smarkm#ifndef OPENSSL_NO_KRB5
177109998Smarkm       if (BIO_puts(bp,"\n    Krb5 Principal: ") <= 0) goto err;
178109998Smarkm            if (x->krb5_client_princ_len == 0)
179109998Smarkm            {
180109998Smarkm		if (BIO_puts(bp,"None") <= 0) goto err;
181109998Smarkm		}
182109998Smarkm	else
183109998Smarkm		for (i=0; i<x->krb5_client_princ_len; i++)
184109998Smarkm			{
185109998Smarkm			if (BIO_printf(bp,"%02X",x->krb5_client_princ[i]) <= 0) goto err;
186109998Smarkm			}
187109998Smarkm#endif /* OPENSSL_NO_KRB5 */
188238405Sjkim#ifndef OPENSSL_NO_PSK
189238405Sjkim	if (BIO_puts(bp,"\n    PSK identity: ") <= 0) goto err;
190238405Sjkim	if (BIO_printf(bp, "%s", x->psk_identity ? x->psk_identity : "None") <= 0) goto err;
191238405Sjkim	if (BIO_puts(bp,"\n    PSK identity hint: ") <= 0) goto err;
192238405Sjkim	if (BIO_printf(bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0) goto err;
193238405Sjkim#endif
194238405Sjkim#ifndef OPENSSL_NO_SRP
195238405Sjkim	if (BIO_puts(bp,"\n    SRP username: ") <= 0) goto err;
196238405Sjkim	if (BIO_printf(bp, "%s", x->srp_username ? x->srp_username : "None") <= 0) goto err;
197238405Sjkim#endif
198194206Ssimon#ifndef OPENSSL_NO_TLSEXT
199194206Ssimon	if (x->tlsext_tick_lifetime_hint)
200194206Ssimon		{
201194206Ssimon		if (BIO_printf(bp,
202194206Ssimon			"\n    TLS session ticket lifetime hint: %ld (seconds)",
203194206Ssimon			x->tlsext_tick_lifetime_hint) <=0)
204194206Ssimon			goto err;
205194206Ssimon		}
206194206Ssimon	if (x->tlsext_tick)
207194206Ssimon		{
208194206Ssimon		if (BIO_puts(bp, "\n    TLS session ticket:\n") <= 0) goto err;
209194206Ssimon		if (BIO_dump_indent(bp, (char *)x->tlsext_tick, x->tlsext_ticklen, 4) <= 0)
210194206Ssimon			goto err;
211194206Ssimon		}
212194206Ssimon#endif
213238405Sjkim
214160814Ssimon#ifndef OPENSSL_NO_COMP
21555714Skris	if (x->compress_meth != 0)
21655714Skris		{
217160814Ssimon		SSL_COMP *comp = NULL;
21855714Skris
219238405Sjkim		ssl_cipher_get_evp(x,NULL,NULL,NULL,NULL,&comp);
22055714Skris		if (comp == NULL)
22155714Skris			{
222205128Ssimon			if (BIO_printf(bp,"\n    Compression: %d",x->compress_meth) <= 0) goto err;
22355714Skris			}
22455714Skris		else
22555714Skris			{
226205128Ssimon			if (BIO_printf(bp,"\n    Compression: %d (%s)", comp->id,comp->method->name) <= 0) goto err;
22755714Skris			}
22855714Skris		}
229160814Ssimon#endif
23055714Skris	if (x->time != 0L)
23155714Skris		{
23268651Skris		if (BIO_printf(bp, "\n    Start Time: %ld",x->time) <= 0) goto err;
23355714Skris		}
23455714Skris	if (x->timeout != 0L)
23555714Skris		{
23668651Skris		if (BIO_printf(bp, "\n    Timeout   : %ld (sec)",x->timeout) <= 0) goto err;
23755714Skris		}
23855714Skris	if (BIO_puts(bp,"\n") <= 0) goto err;
23959191Skris
24059191Skris	if (BIO_puts(bp, "    Verify return code: ") <= 0) goto err;
24168651Skris	if (BIO_printf(bp, "%ld (%s)\n", x->verify_result,
24268651Skris		X509_verify_cert_error_string(x->verify_result)) <= 0) goto err;
24355714Skris
24455714Skris	return(1);
24555714Skriserr:
24655714Skris	return(0);
24755714Skris	}
24855714Skris
249