1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59: #include <stdio.h>
60: #include <openssl/buffer.h>
61: #include "ssl_locl.h"
62:
63: #ifndef OPENSSL_NO_FP_API
64: int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x)
65: {
66: BIO *b;
67: int ret;
68:
69: if ((b=BIO_new(BIO_s_file_internal())) == NULL)
70: {
71: SSLerr(SSL_F_SSL_SESSION_PRINT_FP,ERR_R_BUF_LIB);
72: return(0);
73: }
74: BIO_set_fp(b,fp,BIO_NOCLOSE);
75: ret=SSL_SESSION_print(b,x);
76: BIO_free(b);
77: return(ret);
78: }
79: #endif
80:
81: int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
82: {
83: unsigned int i;
84: const char *s;
85:
86: if (x == NULL) goto err;
87: if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err;
88: if (x->ssl_version == SSL2_VERSION)
89: s="SSLv2";
90: else if (x->ssl_version == SSL3_VERSION)
91: s="SSLv3";
92: else if (x->ssl_version == TLS1_VERSION)
93: s="TLSv1";
94: else
95: s="unknown";
96: if (BIO_printf(bp," Protocol : %s\n",s) <= 0) goto err;
97:
98: if (x->cipher == NULL)
99: {
100: if (((x->cipher_id) & 0xff000000) == 0x02000000)
101: {
102: if (BIO_printf(bp," Cipher : %06lX\n",x->cipher_id&0xffffff) <= 0)
103: goto err;
104: }
105: else
106: {
107: if (BIO_printf(bp," Cipher : %04lX\n",x->cipher_id&0xffff) <= 0)
108: goto err;
109: }
110: }
111: else
112: {
113: if (BIO_printf(bp," Cipher : %s\n",((x->cipher == NULL)?"unknown":x->cipher->name)) <= 0)
114: goto err;
115: }
116: if (BIO_puts(bp," Session-ID: ") <= 0) goto err;
117: for (i=0; i<x->session_id_length; i++)
118: {
119: if (BIO_printf(bp,"%02X",x->session_id[i]) <= 0) goto err;
120: }
121: if (BIO_puts(bp,"\n Session-ID-ctx: ") <= 0) goto err;
122: for (i=0; i<x->sid_ctx_length; i++)
123: {
124: if (BIO_printf(bp,"%02X",x->sid_ctx[i]) <= 0)
125: goto err;
126: }
127: if (BIO_puts(bp,"\n Master-Key: ") <= 0) goto err;
128: for (i=0; i<(unsigned int)x->master_key_length; i++)
129: {
130: if (BIO_printf(bp,"%02X",x->master_key[i]) <= 0) goto err;
131: }
132: if (BIO_puts(bp,"\n Key-Arg : ") <= 0) goto err;
133: if (x->key_arg_length == 0)
134: {
135: if (BIO_puts(bp,"None") <= 0) goto err;
136: }
137: else
138: for (i=0; i<x->key_arg_length; i++)
139: {
140: if (BIO_printf(bp,"%02X",x->key_arg[i]) <= 0) goto err;
141: }
142: #ifndef OPENSSL_NO_KRB5
143: if (BIO_puts(bp,"\n Krb5 Principal: ") <= 0) goto err;
144: if (x->krb5_client_princ_len == 0)
145: {
146: if (BIO_puts(bp,"None") <= 0) goto err;
147: }
148: else
149: for (i=0; i<x->krb5_client_princ_len; i++)
150: {
151: if (BIO_printf(bp,"%02X",x->krb5_client_princ[i]) <= 0) goto err;
152: }
153: #endif
154: #ifndef OPENSSL_NO_TLSEXT
155: if (x->tlsext_tick_lifetime_hint)
156: {
157: if (BIO_printf(bp,
158: "\n TLS session ticket lifetime hint: %ld (seconds)",
159: x->tlsext_tick_lifetime_hint) <=0)
160: goto err;
161: }
162: if (x->tlsext_tick)
163: {
164: if (BIO_puts(bp, "\n TLS session ticket:\n") <= 0) goto err;
165: if (BIO_dump_indent(bp, (char *)x->tlsext_tick, x->tlsext_ticklen, 4) <= 0)
166: goto err;
167: }
168: #endif
169: #ifndef OPENSSL_NO_COMP
170: if (x->compress_meth != 0)
171: {
172: SSL_COMP *comp = NULL;
173:
174: ssl_cipher_get_evp(x,NULL,NULL,&comp);
175: if (comp == NULL)
176: {
177: if (BIO_printf(bp,"\n Compression: %d",x->compress_meth) <= 0) goto err;
178: }
179: else
180: {
181: if (BIO_printf(bp,"\n Compression: %d (%s)", comp->id,comp->method->name) <= 0) goto err;
182: }
183: }
184: #endif
185: if (x->time != 0L)
186: {
187: if (BIO_printf(bp, "\n Start Time: %ld",x->time) <= 0) goto err;
188: }
189: if (x->timeout != 0L)
190: {
191: if (BIO_printf(bp, "\n Timeout : %ld (sec)",x->timeout) <= 0) goto err;
192: }
193: if (BIO_puts(bp,"\n") <= 0) goto err;
194:
195: if (BIO_puts(bp, " Verify return code: ") <= 0) goto err;
196: if (BIO_printf(bp, "%ld (%s)\n", x->verify_result,
197: X509_verify_cert_error_string(x->verify_result)) <= 0) goto err;
198:
199: return(1);
200: err:
201: return(0);
202: }
203: