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. 8280304Sjkim * 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). 15280304Sjkim * 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. 22280304Sjkim * 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 :-). 37280304Sjkim * 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)" 40280304Sjkim * 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. 52280304Sjkim * 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) 91280304Sjkim{ 92280304Sjkim BIO *b; 93280304Sjkim int ret; 9455714Skris 95280304Sjkim if ((b = BIO_new(BIO_s_file_internal())) == NULL) { 96280304Sjkim SSLerr(SSL_F_SSL_SESSION_PRINT_FP, ERR_R_BUF_LIB); 97280304Sjkim return (0); 98280304Sjkim } 99280304Sjkim BIO_set_fp(b, fp, BIO_NOCLOSE); 100280304Sjkim ret = SSL_SESSION_print(b, x); 101280304Sjkim BIO_free(b); 102280304Sjkim return (ret); 103280304Sjkim} 10455714Skris#endif 10555714Skris 106160814Ssimonint SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) 107280304Sjkim{ 108280304Sjkim unsigned int i; 109280304Sjkim const char *s; 11055714Skris 111280304Sjkim if (x == NULL) 112280304Sjkim goto err; 113280304Sjkim if (BIO_puts(bp, "SSL-Session:\n") <= 0) 114280304Sjkim goto err; 115280304Sjkim if (x->ssl_version == SSL2_VERSION) 116280304Sjkim s = "SSLv2"; 117280304Sjkim else if (x->ssl_version == SSL3_VERSION) 118280304Sjkim s = "SSLv3"; 119280304Sjkim else if (x->ssl_version == TLS1_2_VERSION) 120280304Sjkim s = "TLSv1.2"; 121280304Sjkim else if (x->ssl_version == TLS1_1_VERSION) 122280304Sjkim s = "TLSv1.1"; 123280304Sjkim else if (x->ssl_version == TLS1_VERSION) 124280304Sjkim s = "TLSv1"; 125280304Sjkim else if (x->ssl_version == DTLS1_VERSION) 126280304Sjkim s = "DTLSv1"; 127280304Sjkim else if (x->ssl_version == DTLS1_BAD_VER) 128280304Sjkim s = "DTLSv1-bad"; 129280304Sjkim else 130280304Sjkim s = "unknown"; 131280304Sjkim if (BIO_printf(bp, " Protocol : %s\n", s) <= 0) 132280304Sjkim goto err; 13355714Skris 134280304Sjkim if (x->cipher == NULL) { 135280304Sjkim if (((x->cipher_id) & 0xff000000) == 0x02000000) { 136280304Sjkim if (BIO_printf 137280304Sjkim (bp, " Cipher : %06lX\n", x->cipher_id & 0xffffff) <= 0) 138280304Sjkim goto err; 139280304Sjkim } else { 140280304Sjkim if (BIO_printf 141280304Sjkim (bp, " Cipher : %04lX\n", x->cipher_id & 0xffff) <= 0) 142280304Sjkim goto err; 143280304Sjkim } 144280304Sjkim } else { 145280304Sjkim if (BIO_printf 146280304Sjkim (bp, " Cipher : %s\n", 147280304Sjkim ((x->cipher == NULL) ? "unknown" : x->cipher->name)) <= 0) 148280304Sjkim goto err; 149280304Sjkim } 150280304Sjkim if (BIO_puts(bp, " Session-ID: ") <= 0) 151280304Sjkim goto err; 152280304Sjkim for (i = 0; i < x->session_id_length; i++) { 153280304Sjkim if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0) 154280304Sjkim goto err; 155280304Sjkim } 156280304Sjkim if (BIO_puts(bp, "\n Session-ID-ctx: ") <= 0) 157280304Sjkim goto err; 158280304Sjkim for (i = 0; i < x->sid_ctx_length; i++) { 159280304Sjkim if (BIO_printf(bp, "%02X", x->sid_ctx[i]) <= 0) 160280304Sjkim goto err; 161280304Sjkim } 162280304Sjkim if (BIO_puts(bp, "\n Master-Key: ") <= 0) 163280304Sjkim goto err; 164280304Sjkim for (i = 0; i < (unsigned int)x->master_key_length; i++) { 165280304Sjkim if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0) 166280304Sjkim goto err; 167280304Sjkim } 168280304Sjkim if (BIO_puts(bp, "\n Key-Arg : ") <= 0) 169280304Sjkim goto err; 170280304Sjkim if (x->key_arg_length == 0) { 171280304Sjkim if (BIO_puts(bp, "None") <= 0) 172280304Sjkim goto err; 173280304Sjkim } else 174280304Sjkim for (i = 0; i < x->key_arg_length; i++) { 175280304Sjkim if (BIO_printf(bp, "%02X", x->key_arg[i]) <= 0) 176280304Sjkim goto err; 177280304Sjkim } 178109998Smarkm#ifndef OPENSSL_NO_KRB5 179280304Sjkim if (BIO_puts(bp, "\n Krb5 Principal: ") <= 0) 180280304Sjkim goto err; 181280304Sjkim if (x->krb5_client_princ_len == 0) { 182280304Sjkim if (BIO_puts(bp, "None") <= 0) 183280304Sjkim goto err; 184280304Sjkim } else 185280304Sjkim for (i = 0; i < x->krb5_client_princ_len; i++) { 186280304Sjkim if (BIO_printf(bp, "%02X", x->krb5_client_princ[i]) <= 0) 187280304Sjkim goto err; 188280304Sjkim } 189280304Sjkim#endif /* OPENSSL_NO_KRB5 */ 190238405Sjkim#ifndef OPENSSL_NO_PSK 191280304Sjkim if (BIO_puts(bp, "\n PSK identity: ") <= 0) 192280304Sjkim goto err; 193280304Sjkim if (BIO_printf(bp, "%s", x->psk_identity ? x->psk_identity : "None") <= 0) 194280304Sjkim goto err; 195280304Sjkim if (BIO_puts(bp, "\n PSK identity hint: ") <= 0) 196280304Sjkim goto err; 197280304Sjkim if (BIO_printf 198280304Sjkim (bp, "%s", x->psk_identity_hint ? x->psk_identity_hint : "None") <= 0) 199280304Sjkim goto err; 200238405Sjkim#endif 201238405Sjkim#ifndef OPENSSL_NO_SRP 202280304Sjkim if (BIO_puts(bp, "\n SRP username: ") <= 0) 203280304Sjkim goto err; 204280304Sjkim if (BIO_printf(bp, "%s", x->srp_username ? x->srp_username : "None") <= 0) 205280304Sjkim goto err; 206238405Sjkim#endif 207194206Ssimon#ifndef OPENSSL_NO_TLSEXT 208280304Sjkim if (x->tlsext_tick_lifetime_hint) { 209280304Sjkim if (BIO_printf(bp, 210280304Sjkim "\n TLS session ticket lifetime hint: %ld (seconds)", 211280304Sjkim x->tlsext_tick_lifetime_hint) <= 0) 212280304Sjkim goto err; 213280304Sjkim } 214280304Sjkim if (x->tlsext_tick) { 215280304Sjkim if (BIO_puts(bp, "\n TLS session ticket:\n") <= 0) 216280304Sjkim goto err; 217280304Sjkim if (BIO_dump_indent(bp, (char *)x->tlsext_tick, x->tlsext_ticklen, 4) 218280304Sjkim <= 0) 219280304Sjkim goto err; 220280304Sjkim } 221194206Ssimon#endif 222238405Sjkim 223160814Ssimon#ifndef OPENSSL_NO_COMP 224280304Sjkim if (x->compress_meth != 0) { 225280304Sjkim SSL_COMP *comp = NULL; 22655714Skris 227280304Sjkim ssl_cipher_get_evp(x, NULL, NULL, NULL, NULL, &comp); 228280304Sjkim if (comp == NULL) { 229280304Sjkim if (BIO_printf(bp, "\n Compression: %d", x->compress_meth) <= 230280304Sjkim 0) 231280304Sjkim goto err; 232280304Sjkim } else { 233280304Sjkim if (BIO_printf 234280304Sjkim (bp, "\n Compression: %d (%s)", comp->id, 235280304Sjkim comp->method->name) <= 0) 236280304Sjkim goto err; 237280304Sjkim } 238280304Sjkim } 239160814Ssimon#endif 240280304Sjkim if (x->time != 0L) { 241280304Sjkim if (BIO_printf(bp, "\n Start Time: %ld", x->time) <= 0) 242280304Sjkim goto err; 243280304Sjkim } 244280304Sjkim if (x->timeout != 0L) { 245280304Sjkim if (BIO_printf(bp, "\n Timeout : %ld (sec)", x->timeout) <= 0) 246280304Sjkim goto err; 247280304Sjkim } 248280304Sjkim if (BIO_puts(bp, "\n") <= 0) 249280304Sjkim goto err; 25059191Skris 251280304Sjkim if (BIO_puts(bp, " Verify return code: ") <= 0) 252280304Sjkim goto err; 253280304Sjkim if (BIO_printf(bp, "%ld (%s)\n", x->verify_result, 254280304Sjkim X509_verify_cert_error_string(x->verify_result)) <= 0) 255280304Sjkim goto err; 25655714Skris 257280304Sjkim return (1); 258280304Sjkim err: 259280304Sjkim return (0); 260280304Sjkim} 261