xref: /openbsd-src/lib/libssl/ssl_stat.c (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1 /* $OpenBSD: ssl_stat.c,v 1.11 2014/07/13 00:08:44 jsing Exp $ */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3  * All rights reserved.
4  *
5  * This package is an SSL implementation written
6  * by Eric Young (eay@cryptsoft.com).
7  * The implementation was written so as to conform with Netscapes SSL.
8  *
9  * This library is free for commercial and non-commercial use as long as
10  * the following conditions are aheared to.  The following conditions
11  * apply to all code found in this distribution, be it the RC4, RSA,
12  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13  * included with this distribution is covered by the same copyright terms
14  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15  *
16  * Copyright remains Eric Young's, and as such any Copyright notices in
17  * the code are not to be removed.
18  * If this package is used in a product, Eric Young should be given attribution
19  * as the author of the parts of the library used.
20  * This can be in the form of a textual message at program startup or
21  * in documentation (online or textual) provided with the package.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  * 1. Redistributions of source code must retain the copyright
27  *    notice, this list of conditions and the following disclaimer.
28  * 2. Redistributions in binary form must reproduce the above copyright
29  *    notice, this list of conditions and the following disclaimer in the
30  *    documentation and/or other materials provided with the distribution.
31  * 3. All advertising materials mentioning features or use of this software
32  *    must display the following acknowledgement:
33  *    "This product includes cryptographic software written by
34  *     Eric Young (eay@cryptsoft.com)"
35  *    The word 'cryptographic' can be left out if the rouines from the library
36  *    being used are not cryptographic related :-).
37  * 4. If you include any Windows specific code (or a derivative thereof) from
38  *    the apps directory (application code) you must include an acknowledgement:
39  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40  *
41  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  *
53  * The licence and distribution terms for any publically available version or
54  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55  * copied and put under another distribution licence
56  * [including the GNU Public Licence.]
57  */
58 /* ====================================================================
59  * Copyright 2005 Nokia. All rights reserved.
60  *
61  * The portions of the attached software ("Contribution") is developed by
62  * Nokia Corporation and is licensed pursuant to the OpenSSL open source
63  * license.
64  *
65  * The Contribution, originally written by Mika Kousa and Pasi Eronen of
66  * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
67  * support (see RFC 4279) to OpenSSL.
68  *
69  * No patent licenses or other rights except those expressly stated in
70  * the OpenSSL open source license shall be deemed granted or received
71  * expressly, by implication, estoppel, or otherwise.
72  *
73  * No assurances are provided by Nokia that the Contribution does not
74  * infringe the patent or other intellectual property rights of any third
75  * party or that the license provides you with all the necessary rights
76  * to make use of the Contribution.
77  *
78  * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
79  * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
80  * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
81  * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
82  * OTHERWISE.
83  */
84 
85 #include <stdio.h>
86 #include "ssl_locl.h"
87 
88 const char *
89 SSL_state_string_long(const SSL *s)
90 {
91 	const char *str;
92 
93 	switch (s->state) {
94 	case SSL_ST_BEFORE:
95 		str = "before SSL initialization";
96 		break;
97 	case SSL_ST_ACCEPT:
98 		str = "before accept initialization";
99 		break;
100 	case SSL_ST_CONNECT:
101 		str = "before connect initialization";
102 		break;
103 	case SSL_ST_OK:
104 		str = "SSL negotiation finished successfully";
105 		break;
106 	case SSL_ST_RENEGOTIATE:
107 		str = "SSL renegotiate ciphers";
108 		break;
109 	case SSL_ST_BEFORE|SSL_ST_CONNECT:
110 		str = "before/connect initialization";
111 		break;
112 	case SSL_ST_OK|SSL_ST_CONNECT:
113 		str = "ok/connect SSL initialization";
114 		break;
115 	case SSL_ST_BEFORE|SSL_ST_ACCEPT:
116 		str = "before/accept initialization";
117 		break;
118 	case SSL_ST_OK|SSL_ST_ACCEPT:
119 		str = "ok/accept SSL initialization";
120 		break;
121 
122 	/* SSLv3 additions */
123 	case SSL3_ST_CW_CLNT_HELLO_A:
124 		str = "SSLv3 write client hello A";
125 		break;
126 	case SSL3_ST_CW_CLNT_HELLO_B:
127 		str = "SSLv3 write client hello B";
128 		break;
129 	case SSL3_ST_CR_SRVR_HELLO_A:
130 		str = "SSLv3 read server hello A";
131 		break;
132 	case SSL3_ST_CR_SRVR_HELLO_B:
133 		str = "SSLv3 read server hello B";
134 		break;
135 	case SSL3_ST_CR_CERT_A:
136 		str = "SSLv3 read server certificate A";
137 		break;
138 	case SSL3_ST_CR_CERT_B:
139 		str = "SSLv3 read server certificate B";
140 		break;
141 	case SSL3_ST_CR_KEY_EXCH_A:
142 		str = "SSLv3 read server key exchange A";
143 		break;
144 	case SSL3_ST_CR_KEY_EXCH_B:
145 		str = "SSLv3 read server key exchange B";
146 		break;
147 	case SSL3_ST_CR_CERT_REQ_A:
148 		str = "SSLv3 read server certificate request A";
149 		break;
150 	case SSL3_ST_CR_CERT_REQ_B:
151 		str = "SSLv3 read server certificate request B";
152 		break;
153 	case SSL3_ST_CR_SESSION_TICKET_A:
154 		str = "SSLv3 read server session ticket A";
155 		break;
156 	case SSL3_ST_CR_SESSION_TICKET_B:
157 		str = "SSLv3 read server session ticket B";
158 		break;
159 	case SSL3_ST_CR_SRVR_DONE_A:
160 		str = "SSLv3 read server done A";
161 		break;
162 	case SSL3_ST_CR_SRVR_DONE_B:
163 		str = "SSLv3 read server done B";
164 		break;
165 	case SSL3_ST_CW_CERT_A:
166 		str = "SSLv3 write client certificate A";
167 		break;
168 	case SSL3_ST_CW_CERT_B:
169 		str = "SSLv3 write client certificate B";
170 		break;
171 	case SSL3_ST_CW_CERT_C:
172 		str = "SSLv3 write client certificate C";
173 		break;
174 	case SSL3_ST_CW_CERT_D:
175 		str = "SSLv3 write client certificate D";
176 		break;
177 	case SSL3_ST_CW_KEY_EXCH_A:
178 		str = "SSLv3 write client key exchange A";
179 		break;
180 	case SSL3_ST_CW_KEY_EXCH_B:
181 		str = "SSLv3 write client key exchange B";
182 		break;
183 	case SSL3_ST_CW_CERT_VRFY_A:
184 		str = "SSLv3 write certificate verify A";
185 		break;
186 	case SSL3_ST_CW_CERT_VRFY_B:
187 		str = "SSLv3 write certificate verify B";
188 		break;
189 
190 	case SSL3_ST_CW_CHANGE_A:
191 	case SSL3_ST_SW_CHANGE_A:
192 		str = "SSLv3 write change cipher spec A";
193 		break;
194 	case SSL3_ST_CW_CHANGE_B:
195 	case SSL3_ST_SW_CHANGE_B:
196 		str = "SSLv3 write change cipher spec B";
197 		break;
198 	case SSL3_ST_CW_FINISHED_A:
199 	case SSL3_ST_SW_FINISHED_A:
200 		str = "SSLv3 write finished A";
201 		break;
202 	case SSL3_ST_CW_FINISHED_B:
203 	case SSL3_ST_SW_FINISHED_B:
204 		str = "SSLv3 write finished B";
205 		break;
206 	case SSL3_ST_CR_CHANGE_A:
207 	case SSL3_ST_SR_CHANGE_A:
208 		str = "SSLv3 read change cipher spec A";
209 		break;
210 	case SSL3_ST_CR_CHANGE_B:
211 	case SSL3_ST_SR_CHANGE_B:
212 		str = "SSLv3 read change cipher spec B";
213 		break;
214 	case SSL3_ST_CR_FINISHED_A:
215 	case SSL3_ST_SR_FINISHED_A:
216 		str = "SSLv3 read finished A";
217 		break;
218 	case SSL3_ST_CR_FINISHED_B:
219 	case SSL3_ST_SR_FINISHED_B:
220 		str = "SSLv3 read finished B";
221 		break;
222 
223 	case SSL3_ST_CW_FLUSH:
224 	case SSL3_ST_SW_FLUSH:
225 		str = "SSLv3 flush data";
226 		break;
227 
228 	case SSL3_ST_SR_CLNT_HELLO_A:
229 		str = "SSLv3 read client hello A";
230 		break;
231 	case SSL3_ST_SR_CLNT_HELLO_B:
232 		str = "SSLv3 read client hello B";
233 		break;
234 	case SSL3_ST_SR_CLNT_HELLO_C:
235 		str = "SSLv3 read client hello C";
236 		break;
237 	case SSL3_ST_SW_HELLO_REQ_A:
238 		str = "SSLv3 write hello request A";
239 		break;
240 	case SSL3_ST_SW_HELLO_REQ_B:
241 		str = "SSLv3 write hello request B";
242 		break;
243 	case SSL3_ST_SW_HELLO_REQ_C:
244 		str = "SSLv3 write hello request C";
245 		break;
246 	case SSL3_ST_SW_SRVR_HELLO_A:
247 		str = "SSLv3 write server hello A";
248 		break;
249 	case SSL3_ST_SW_SRVR_HELLO_B:
250 		str = "SSLv3 write server hello B";
251 		break;
252 	case SSL3_ST_SW_CERT_A:
253 		str = "SSLv3 write certificate A";
254 		break;
255 	case SSL3_ST_SW_CERT_B:
256 		str = "SSLv3 write certificate B";
257 		break;
258 	case SSL3_ST_SW_KEY_EXCH_A:
259 		str = "SSLv3 write key exchange A";
260 		break;
261 	case SSL3_ST_SW_KEY_EXCH_B:
262 		str = "SSLv3 write key exchange B";
263 		break;
264 	case SSL3_ST_SW_CERT_REQ_A:
265 		str = "SSLv3 write certificate request A";
266 		break;
267 	case SSL3_ST_SW_CERT_REQ_B:
268 		str = "SSLv3 write certificate request B";
269 		break;
270 	case SSL3_ST_SW_SESSION_TICKET_A:
271 		str = "SSLv3 write session ticket A";
272 		break;
273 	case SSL3_ST_SW_SESSION_TICKET_B:
274 		str = "SSLv3 write session ticket B";
275 		break;
276 	case SSL3_ST_SW_SRVR_DONE_A:
277 		str = "SSLv3 write server done A";
278 		break;
279 	case SSL3_ST_SW_SRVR_DONE_B:
280 		str = "SSLv3 write server done B";
281 		break;
282 	case SSL3_ST_SR_CERT_A:
283 		str = "SSLv3 read client certificate A";
284 		break;
285 	case SSL3_ST_SR_CERT_B:
286 		str = "SSLv3 read client certificate B";
287 		break;
288 	case SSL3_ST_SR_KEY_EXCH_A:
289 		str = "SSLv3 read client key exchange A";
290 		break;
291 	case SSL3_ST_SR_KEY_EXCH_B:
292 		str = "SSLv3 read client key exchange B";
293 		break;
294 	case SSL3_ST_SR_CERT_VRFY_A:
295 		str = "SSLv3 read certificate verify A";
296 		break;
297 	case SSL3_ST_SR_CERT_VRFY_B:
298 		str = "SSLv3 read certificate verify B";
299 		break;
300 
301 	/* DTLS */
302 	case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
303 		str = "DTLS1 read hello verify request A";
304 		break;
305 	case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
306 		str = "DTLS1 read hello verify request B";
307 		break;
308 	case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
309 		str = "DTLS1 write hello verify request A";
310 		break;
311 	case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
312 		str = "DTLS1 write hello verify request B";
313 		break;
314 
315 	default:
316 		str = "unknown state";
317 		break;
318 	}
319 	return (str);
320 }
321 
322 const char *
323 SSL_rstate_string_long(const SSL *s)
324 {
325 	const char *str;
326 
327 	switch (s->rstate) {
328 	case SSL_ST_READ_HEADER:
329 		str = "read header";
330 		break;
331 	case SSL_ST_READ_BODY:
332 		str = "read body";
333 		break;
334 	case SSL_ST_READ_DONE:
335 		str = "read done";
336 		break;
337 	default:
338 		str = "unknown";
339 		break;
340 	}
341 	return (str);
342 }
343 
344 const char *
345 SSL_state_string(const SSL *s)
346 {
347 	const char *str;
348 
349 	switch (s->state) {
350 	case SSL_ST_BEFORE:
351 		str = "PINIT ";
352 		break;
353 	case SSL_ST_ACCEPT:
354 		str = "AINIT ";
355 		break;
356 	case SSL_ST_CONNECT:
357 		str = "CINIT ";
358 		break;
359 	case SSL_ST_OK:
360 		str = "SSLOK ";
361 		break;
362 
363 	/* SSLv3 additions */
364 	case SSL3_ST_SW_FLUSH:
365 	case SSL3_ST_CW_FLUSH:
366 		str = "3FLUSH";
367 		break;
368 	case SSL3_ST_CW_CLNT_HELLO_A:
369 		str = "3WCH_A";
370 		break;
371 	case SSL3_ST_CW_CLNT_HELLO_B:
372 		str = "3WCH_B";
373 		break;
374 	case SSL3_ST_CR_SRVR_HELLO_A:
375 		str = "3RSH_A";
376 		break;
377 	case SSL3_ST_CR_SRVR_HELLO_B:
378 		str = "3RSH_B";
379 		break;
380 	case SSL3_ST_CR_CERT_A:
381 		str = "3RSC_A";
382 		break;
383 	case SSL3_ST_CR_CERT_B:
384 		str = "3RSC_B";
385 		break;
386 	case SSL3_ST_CR_KEY_EXCH_A:
387 		str = "3RSKEA";
388 		break;
389 	case SSL3_ST_CR_KEY_EXCH_B:
390 		str = "3RSKEB";
391 		break;
392 	case SSL3_ST_CR_CERT_REQ_A:
393 		str = "3RCR_A";
394 		break;
395 	case SSL3_ST_CR_CERT_REQ_B:
396 		str = "3RCR_B";
397 		break;
398 	case SSL3_ST_CR_SRVR_DONE_A:
399 		str = "3RSD_A";
400 		break;
401 	case SSL3_ST_CR_SRVR_DONE_B:
402 		str = "3RSD_B";
403 		break;
404 	case SSL3_ST_CW_CERT_A:
405 		str = "3WCC_A";
406 		break;
407 	case SSL3_ST_CW_CERT_B:
408 		str = "3WCC_B";
409 		break;
410 	case SSL3_ST_CW_CERT_C:
411 		str = "3WCC_C";
412 		break;
413 	case SSL3_ST_CW_CERT_D:
414 		str = "3WCC_D";
415 		break;
416 	case SSL3_ST_CW_KEY_EXCH_A:
417 		str = "3WCKEA";
418 		break;
419 	case SSL3_ST_CW_KEY_EXCH_B:
420 		str = "3WCKEB";
421 		break;
422 	case SSL3_ST_CW_CERT_VRFY_A:
423 		str = "3WCV_A";
424 		break;
425 	case SSL3_ST_CW_CERT_VRFY_B:
426 		str = "3WCV_B";
427 		break;
428 
429 	case SSL3_ST_SW_CHANGE_A:
430 	case SSL3_ST_CW_CHANGE_A:
431 		str = "3WCCSA";
432 		break;
433 	case SSL3_ST_SW_CHANGE_B:
434 	case SSL3_ST_CW_CHANGE_B:
435 		str = "3WCCSB";
436 		break;
437 	case SSL3_ST_SW_FINISHED_A:
438 	case SSL3_ST_CW_FINISHED_A:
439 		str = "3WFINA";
440 		break;
441 	case SSL3_ST_SW_FINISHED_B:
442 	case SSL3_ST_CW_FINISHED_B:
443 		str = "3WFINB";
444 		break;
445 	case SSL3_ST_SR_CHANGE_A:
446 	case SSL3_ST_CR_CHANGE_A:
447 		str = "3RCCSA";
448 		break;
449 	case SSL3_ST_SR_CHANGE_B:
450 	case SSL3_ST_CR_CHANGE_B:
451 		str = "3RCCSB";
452 		break;
453 	case SSL3_ST_SR_FINISHED_A:
454 	case SSL3_ST_CR_FINISHED_A:
455 		str = "3RFINA";
456 		break;
457 	case SSL3_ST_SR_FINISHED_B:
458 	case SSL3_ST_CR_FINISHED_B:
459 		str = "3RFINB";
460 		break;
461 
462 	case SSL3_ST_SW_HELLO_REQ_A:
463 		str = "3WHR_A";
464 		break;
465 	case SSL3_ST_SW_HELLO_REQ_B:
466 		str = "3WHR_B";
467 		break;
468 	case SSL3_ST_SW_HELLO_REQ_C:
469 		str = "3WHR_C";
470 		break;
471 	case SSL3_ST_SR_CLNT_HELLO_A:
472 		str = "3RCH_A";
473 		break;
474 	case SSL3_ST_SR_CLNT_HELLO_B:
475 		str = "3RCH_B";
476 		break;
477 	case SSL3_ST_SR_CLNT_HELLO_C:
478 		str = "3RCH_C";
479 		break;
480 	case SSL3_ST_SW_SRVR_HELLO_A:
481 		str = "3WSH_A";
482 		break;
483 	case SSL3_ST_SW_SRVR_HELLO_B:
484 		str = "3WSH_B";
485 		break;
486 	case SSL3_ST_SW_CERT_A:
487 		str = "3WSC_A";
488 		break;
489 	case SSL3_ST_SW_CERT_B:
490 		str = "3WSC_B";
491 		break;
492 	case SSL3_ST_SW_KEY_EXCH_A:
493 		str = "3WSKEA";
494 		break;
495 	case SSL3_ST_SW_KEY_EXCH_B:
496 		str = "3WSKEB";
497 		break;
498 	case SSL3_ST_SW_CERT_REQ_A:
499 		str = "3WCR_A";
500 		break;
501 	case SSL3_ST_SW_CERT_REQ_B:
502 		str = "3WCR_B";
503 		break;
504 	case SSL3_ST_SW_SRVR_DONE_A:
505 		str = "3WSD_A";
506 		break;
507 	case SSL3_ST_SW_SRVR_DONE_B:
508 		str = "3WSD_B";
509 		break;
510 	case SSL3_ST_SR_CERT_A:
511 		str = "3RCC_A";
512 		break;
513 	case SSL3_ST_SR_CERT_B:
514 		str = "3RCC_B";
515 		break;
516 	case SSL3_ST_SR_KEY_EXCH_A:
517 		str = "3RCKEA";
518 		break;
519 	case SSL3_ST_SR_KEY_EXCH_B:
520 		str = "3RCKEB";
521 		break;
522 	case SSL3_ST_SR_CERT_VRFY_A:
523 		str = "3RCV_A";
524 		break;
525 	case SSL3_ST_SR_CERT_VRFY_B:
526 		str = "3RCV_B";
527 		break;
528 
529 	/* DTLS */
530 	case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
531 		str = "DRCHVA";
532 		break;
533 	case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
534 		str = "DRCHVB";
535 		break;
536 	case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
537 		str = "DWCHVA";
538 		break;
539 	case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
540 		str = "DWCHVB";
541 		break;
542 
543 	default:
544 		str = "UNKWN ";
545 		break;
546 	}
547 	return (str);
548 }
549 
550 const char *
551 SSL_alert_type_string_long(int value)
552 {
553 	value >>= 8;
554 	if (value == SSL3_AL_WARNING)
555 		return ("warning");
556 	else if (value == SSL3_AL_FATAL)
557 		return ("fatal");
558 	else
559 		return ("unknown");
560 }
561 
562 const char *
563 SSL_alert_type_string(int value)
564 {
565 	value >>= 8;
566 	if (value == SSL3_AL_WARNING)
567 		return ("W");
568 	else if (value == SSL3_AL_FATAL)
569 		return ("F");
570 	else
571 		return ("U");
572 }
573 
574 const char *
575 SSL_alert_desc_string(int value)
576 {
577 	const char *str;
578 
579 	switch (value & 0xff) {
580 	case SSL3_AD_CLOSE_NOTIFY:
581 		str = "CN";
582 		break;
583 	case SSL3_AD_UNEXPECTED_MESSAGE:
584 		str = "UM";
585 		break;
586 	case SSL3_AD_BAD_RECORD_MAC:
587 		str = "BM";
588 		break;
589 	case SSL3_AD_DECOMPRESSION_FAILURE:
590 		str = "DF";
591 		break;
592 	case SSL3_AD_HANDSHAKE_FAILURE:
593 		str = "HF";
594 		break;
595 	case SSL3_AD_NO_CERTIFICATE:
596 		str = "NC";
597 		break;
598 	case SSL3_AD_BAD_CERTIFICATE:
599 		str = "BC";
600 		break;
601 	case SSL3_AD_UNSUPPORTED_CERTIFICATE:
602 		str = "UC";
603 		break;
604 	case SSL3_AD_CERTIFICATE_REVOKED:
605 		str = "CR";
606 		break;
607 	case SSL3_AD_CERTIFICATE_EXPIRED:
608 		str = "CE";
609 		break;
610 	case SSL3_AD_CERTIFICATE_UNKNOWN:
611 		str = "CU";
612 		break;
613 	case SSL3_AD_ILLEGAL_PARAMETER:
614 		str = "IP";
615 		break;
616 	case TLS1_AD_DECRYPTION_FAILED:
617 		str = "DC";
618 		break;
619 	case TLS1_AD_RECORD_OVERFLOW:
620 		str = "RO";
621 		break;
622 	case TLS1_AD_UNKNOWN_CA:
623 		str = "CA";
624 		break;
625 	case TLS1_AD_ACCESS_DENIED:
626 		str = "AD";
627 		break;
628 	case TLS1_AD_DECODE_ERROR:
629 		str = "DE";
630 		break;
631 	case TLS1_AD_DECRYPT_ERROR:
632 		str = "CY";
633 		break;
634 	case TLS1_AD_EXPORT_RESTRICTION:
635 		str = "ER";
636 		break;
637 	case TLS1_AD_PROTOCOL_VERSION:
638 		str = "PV";
639 		break;
640 	case TLS1_AD_INSUFFICIENT_SECURITY:
641 		str = "IS";
642 		break;
643 	case TLS1_AD_INTERNAL_ERROR:
644 		str = "IE";
645 		break;
646 	case TLS1_AD_USER_CANCELLED:
647 		str = "US";
648 		break;
649 	case TLS1_AD_NO_RENEGOTIATION:
650 		str = "NR";
651 		break;
652 	case TLS1_AD_UNSUPPORTED_EXTENSION:
653 		str = "UE";
654 		break;
655 	case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
656 		str = "CO";
657 		break;
658 	case TLS1_AD_UNRECOGNIZED_NAME:
659 		str = "UN";
660 		break;
661 	case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
662 		str = "BR";
663 		break;
664 	case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
665 		str = "BH";
666 		break;
667 	case TLS1_AD_UNKNOWN_PSK_IDENTITY:
668 		str = "UP";
669 		break;
670 	default:
671 		str = "UK";
672 		break;
673 	}
674 	return (str);
675 }
676 
677 const char *
678 SSL_alert_desc_string_long(int value)
679 {
680 	const char *str;
681 
682 	switch (value & 0xff) {
683 	case SSL3_AD_CLOSE_NOTIFY:
684 		str = "close notify";
685 		break;
686 	case SSL3_AD_UNEXPECTED_MESSAGE:
687 		str = "unexpected_message";
688 		break;
689 	case SSL3_AD_BAD_RECORD_MAC:
690 		str = "bad record mac";
691 		break;
692 	case SSL3_AD_DECOMPRESSION_FAILURE:
693 		str = "decompression failure";
694 		break;
695 	case SSL3_AD_HANDSHAKE_FAILURE:
696 		str = "handshake failure";
697 		break;
698 	case SSL3_AD_NO_CERTIFICATE:
699 		str = "no certificate";
700 		break;
701 	case SSL3_AD_BAD_CERTIFICATE:
702 		str = "bad certificate";
703 		break;
704 	case SSL3_AD_UNSUPPORTED_CERTIFICATE:
705 		str = "unsupported certificate";
706 		break;
707 	case SSL3_AD_CERTIFICATE_REVOKED:
708 		str = "certificate revoked";
709 		break;
710 	case SSL3_AD_CERTIFICATE_EXPIRED:
711 		str = "certificate expired";
712 		break;
713 	case SSL3_AD_CERTIFICATE_UNKNOWN:
714 		str = "certificate unknown";
715 		break;
716 	case SSL3_AD_ILLEGAL_PARAMETER:
717 		str = "illegal parameter";
718 		break;
719 	case TLS1_AD_DECRYPTION_FAILED:
720 		str = "decryption failed";
721 		break;
722 	case TLS1_AD_RECORD_OVERFLOW:
723 		str = "record overflow";
724 		break;
725 	case TLS1_AD_UNKNOWN_CA:
726 		str = "unknown CA";
727 		break;
728 	case TLS1_AD_ACCESS_DENIED:
729 		str = "access denied";
730 		break;
731 	case TLS1_AD_DECODE_ERROR:
732 		str = "decode error";
733 		break;
734 	case TLS1_AD_DECRYPT_ERROR:
735 		str = "decrypt error";
736 		break;
737 	case TLS1_AD_EXPORT_RESTRICTION:
738 		str = "export restriction";
739 		break;
740 	case TLS1_AD_PROTOCOL_VERSION:
741 		str = "protocol version";
742 		break;
743 	case TLS1_AD_INSUFFICIENT_SECURITY:
744 		str = "insufficient security";
745 		break;
746 	case TLS1_AD_INTERNAL_ERROR:
747 		str = "internal error";
748 		break;
749 	case TLS1_AD_USER_CANCELLED:
750 		str = "user canceled";
751 		break;
752 	case TLS1_AD_NO_RENEGOTIATION:
753 		str = "no renegotiation";
754 		break;
755 	case TLS1_AD_UNSUPPORTED_EXTENSION:
756 		str = "unsupported extension";
757 		break;
758 	case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
759 		str = "certificate unobtainable";
760 		break;
761 	case TLS1_AD_UNRECOGNIZED_NAME:
762 		str = "unrecognized name";
763 		break;
764 	case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
765 		str = "bad certificate status response";
766 		break;
767 	case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
768 		str = "bad certificate hash value";
769 		break;
770 	case TLS1_AD_UNKNOWN_PSK_IDENTITY:
771 		str = "unknown PSK identity";
772 		break;
773 	default:
774 		str = "unknown";
775 		break;
776 	}
777 	return (str);
778 }
779 
780 const char *
781 SSL_rstate_string(const SSL *s)
782 {
783 	const char *str;
784 
785 	switch (s->rstate) {
786 	case SSL_ST_READ_HEADER:
787 		str = "RH";
788 		break;
789 	case SSL_ST_READ_BODY:
790 		str = "RB";
791 		break;
792 	case SSL_ST_READ_DONE:
793 		str = "RD";
794 		break;
795 	default:
796 		str = "unknown";
797 		break;
798 	}
799 	return (str);
800 }
801