xref: /dragonfly/crypto/libressl/ssl/ssl_stat.c (revision 6f5ec8b5)
1 /* $OpenBSD: ssl_stat.c,v 1.18 2022/02/05 14:54:10 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 
87 #include "ssl_locl.h"
88 
89 const char *
90 SSL_state_string_long(const SSL *s)
91 {
92 	const char *str;
93 
94 	switch (s->s3->hs.state) {
95 	case SSL_ST_BEFORE:
96 		str = "before SSL initialization";
97 		break;
98 	case SSL_ST_ACCEPT:
99 		str = "before accept initialization";
100 		break;
101 	case SSL_ST_CONNECT:
102 		str = "before connect initialization";
103 		break;
104 	case SSL_ST_OK:
105 		str = "SSL negotiation finished successfully";
106 		break;
107 	case SSL_ST_RENEGOTIATE:
108 		str = "SSL renegotiate ciphers";
109 		break;
110 	case SSL_ST_BEFORE|SSL_ST_CONNECT:
111 		str = "before/connect initialization";
112 		break;
113 	case SSL_ST_OK|SSL_ST_CONNECT:
114 		str = "ok/connect SSL initialization";
115 		break;
116 	case SSL_ST_BEFORE|SSL_ST_ACCEPT:
117 		str = "before/accept initialization";
118 		break;
119 	case SSL_ST_OK|SSL_ST_ACCEPT:
120 		str = "ok/accept SSL initialization";
121 		break;
122 
123 	/* SSLv3 additions */
124 	case SSL3_ST_CW_CLNT_HELLO_A:
125 		str = "SSLv3 write client hello A";
126 		break;
127 	case SSL3_ST_CW_CLNT_HELLO_B:
128 		str = "SSLv3 write client hello B";
129 		break;
130 	case SSL3_ST_CR_SRVR_HELLO_A:
131 		str = "SSLv3 read server hello A";
132 		break;
133 	case SSL3_ST_CR_SRVR_HELLO_B:
134 		str = "SSLv3 read server hello B";
135 		break;
136 	case SSL3_ST_CR_CERT_A:
137 		str = "SSLv3 read server certificate A";
138 		break;
139 	case SSL3_ST_CR_CERT_B:
140 		str = "SSLv3 read server certificate B";
141 		break;
142 	case SSL3_ST_CR_KEY_EXCH_A:
143 		str = "SSLv3 read server key exchange A";
144 		break;
145 	case SSL3_ST_CR_KEY_EXCH_B:
146 		str = "SSLv3 read server key exchange B";
147 		break;
148 	case SSL3_ST_CR_CERT_REQ_A:
149 		str = "SSLv3 read server certificate request A";
150 		break;
151 	case SSL3_ST_CR_CERT_REQ_B:
152 		str = "SSLv3 read server certificate request B";
153 		break;
154 	case SSL3_ST_CR_SESSION_TICKET_A:
155 		str = "SSLv3 read server session ticket A";
156 		break;
157 	case SSL3_ST_CR_SESSION_TICKET_B:
158 		str = "SSLv3 read server session ticket B";
159 		break;
160 	case SSL3_ST_CR_SRVR_DONE_A:
161 		str = "SSLv3 read server done A";
162 		break;
163 	case SSL3_ST_CR_SRVR_DONE_B:
164 		str = "SSLv3 read server done B";
165 		break;
166 	case SSL3_ST_CW_CERT_A:
167 		str = "SSLv3 write client certificate A";
168 		break;
169 	case SSL3_ST_CW_CERT_B:
170 		str = "SSLv3 write client certificate B";
171 		break;
172 	case SSL3_ST_CW_CERT_C:
173 		str = "SSLv3 write client certificate C";
174 		break;
175 	case SSL3_ST_CW_CERT_D:
176 		str = "SSLv3 write client certificate D";
177 		break;
178 	case SSL3_ST_CW_KEY_EXCH_A:
179 		str = "SSLv3 write client key exchange A";
180 		break;
181 	case SSL3_ST_CW_KEY_EXCH_B:
182 		str = "SSLv3 write client key exchange B";
183 		break;
184 	case SSL3_ST_CW_CERT_VRFY_A:
185 		str = "SSLv3 write certificate verify A";
186 		break;
187 	case SSL3_ST_CW_CERT_VRFY_B:
188 		str = "SSLv3 write certificate verify B";
189 		break;
190 
191 	case SSL3_ST_CW_CHANGE_A:
192 	case SSL3_ST_SW_CHANGE_A:
193 		str = "SSLv3 write change cipher spec A";
194 		break;
195 	case SSL3_ST_CW_CHANGE_B:
196 	case SSL3_ST_SW_CHANGE_B:
197 		str = "SSLv3 write change cipher spec B";
198 		break;
199 	case SSL3_ST_CW_FINISHED_A:
200 	case SSL3_ST_SW_FINISHED_A:
201 		str = "SSLv3 write finished A";
202 		break;
203 	case SSL3_ST_CW_FINISHED_B:
204 	case SSL3_ST_SW_FINISHED_B:
205 		str = "SSLv3 write finished B";
206 		break;
207 	case SSL3_ST_CR_CHANGE_A:
208 	case SSL3_ST_SR_CHANGE_A:
209 		str = "SSLv3 read change cipher spec A";
210 		break;
211 	case SSL3_ST_CR_CHANGE_B:
212 	case SSL3_ST_SR_CHANGE_B:
213 		str = "SSLv3 read change cipher spec B";
214 		break;
215 	case SSL3_ST_CR_FINISHED_A:
216 	case SSL3_ST_SR_FINISHED_A:
217 		str = "SSLv3 read finished A";
218 		break;
219 	case SSL3_ST_CR_FINISHED_B:
220 	case SSL3_ST_SR_FINISHED_B:
221 		str = "SSLv3 read finished B";
222 		break;
223 
224 	case SSL3_ST_CW_FLUSH:
225 	case SSL3_ST_SW_FLUSH:
226 		str = "SSLv3 flush data";
227 		break;
228 
229 	case SSL3_ST_SR_CLNT_HELLO_A:
230 		str = "SSLv3 read client hello A";
231 		break;
232 	case SSL3_ST_SR_CLNT_HELLO_B:
233 		str = "SSLv3 read client hello B";
234 		break;
235 	case SSL3_ST_SR_CLNT_HELLO_C:
236 		str = "SSLv3 read client hello C";
237 		break;
238 	case SSL3_ST_SW_HELLO_REQ_A:
239 		str = "SSLv3 write hello request A";
240 		break;
241 	case SSL3_ST_SW_HELLO_REQ_B:
242 		str = "SSLv3 write hello request B";
243 		break;
244 	case SSL3_ST_SW_HELLO_REQ_C:
245 		str = "SSLv3 write hello request C";
246 		break;
247 	case SSL3_ST_SW_SRVR_HELLO_A:
248 		str = "SSLv3 write server hello A";
249 		break;
250 	case SSL3_ST_SW_SRVR_HELLO_B:
251 		str = "SSLv3 write server hello B";
252 		break;
253 	case SSL3_ST_SW_CERT_A:
254 		str = "SSLv3 write certificate A";
255 		break;
256 	case SSL3_ST_SW_CERT_B:
257 		str = "SSLv3 write certificate B";
258 		break;
259 	case SSL3_ST_SW_KEY_EXCH_A:
260 		str = "SSLv3 write key exchange A";
261 		break;
262 	case SSL3_ST_SW_KEY_EXCH_B:
263 		str = "SSLv3 write key exchange B";
264 		break;
265 	case SSL3_ST_SW_CERT_REQ_A:
266 		str = "SSLv3 write certificate request A";
267 		break;
268 	case SSL3_ST_SW_CERT_REQ_B:
269 		str = "SSLv3 write certificate request B";
270 		break;
271 	case SSL3_ST_SW_SESSION_TICKET_A:
272 		str = "SSLv3 write session ticket A";
273 		break;
274 	case SSL3_ST_SW_SESSION_TICKET_B:
275 		str = "SSLv3 write session ticket B";
276 		break;
277 	case SSL3_ST_SW_SRVR_DONE_A:
278 		str = "SSLv3 write server done A";
279 		break;
280 	case SSL3_ST_SW_SRVR_DONE_B:
281 		str = "SSLv3 write server done B";
282 		break;
283 	case SSL3_ST_SR_CERT_A:
284 		str = "SSLv3 read client certificate A";
285 		break;
286 	case SSL3_ST_SR_CERT_B:
287 		str = "SSLv3 read client certificate B";
288 		break;
289 	case SSL3_ST_SR_KEY_EXCH_A:
290 		str = "SSLv3 read client key exchange A";
291 		break;
292 	case SSL3_ST_SR_KEY_EXCH_B:
293 		str = "SSLv3 read client key exchange B";
294 		break;
295 	case SSL3_ST_SR_CERT_VRFY_A:
296 		str = "SSLv3 read certificate verify A";
297 		break;
298 	case SSL3_ST_SR_CERT_VRFY_B:
299 		str = "SSLv3 read certificate verify B";
300 		break;
301 
302 	/* DTLS */
303 	case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
304 		str = "DTLS1 read hello verify request A";
305 		break;
306 	case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
307 		str = "DTLS1 read hello verify request B";
308 		break;
309 	case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
310 		str = "DTLS1 write hello verify request A";
311 		break;
312 	case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
313 		str = "DTLS1 write hello verify request B";
314 		break;
315 
316 	default:
317 		str = "unknown state";
318 		break;
319 	}
320 	return (str);
321 }
322 
323 const char *
324 SSL_rstate_string_long(const SSL *s)
325 {
326 	const char *str;
327 
328 	switch (s->internal->rstate) {
329 	case SSL_ST_READ_HEADER:
330 		str = "read header";
331 		break;
332 	case SSL_ST_READ_BODY:
333 		str = "read body";
334 		break;
335 	case SSL_ST_READ_DONE:
336 		str = "read done";
337 		break;
338 	default:
339 		str = "unknown";
340 		break;
341 	}
342 	return (str);
343 }
344 
345 const char *
346 SSL_state_string(const SSL *s)
347 {
348 	const char *str;
349 
350 	switch (s->s3->hs.state) {
351 	case SSL_ST_BEFORE:
352 		str = "PINIT ";
353 		break;
354 	case SSL_ST_ACCEPT:
355 		str = "AINIT ";
356 		break;
357 	case SSL_ST_CONNECT:
358 		str = "CINIT ";
359 		break;
360 	case SSL_ST_OK:
361 		str = "SSLOK ";
362 		break;
363 
364 	/* SSLv3 additions */
365 	case SSL3_ST_SW_FLUSH:
366 	case SSL3_ST_CW_FLUSH:
367 		str = "3FLUSH";
368 		break;
369 	case SSL3_ST_CW_CLNT_HELLO_A:
370 		str = "3WCH_A";
371 		break;
372 	case SSL3_ST_CW_CLNT_HELLO_B:
373 		str = "3WCH_B";
374 		break;
375 	case SSL3_ST_CR_SRVR_HELLO_A:
376 		str = "3RSH_A";
377 		break;
378 	case SSL3_ST_CR_SRVR_HELLO_B:
379 		str = "3RSH_B";
380 		break;
381 	case SSL3_ST_CR_CERT_A:
382 		str = "3RSC_A";
383 		break;
384 	case SSL3_ST_CR_CERT_B:
385 		str = "3RSC_B";
386 		break;
387 	case SSL3_ST_CR_KEY_EXCH_A:
388 		str = "3RSKEA";
389 		break;
390 	case SSL3_ST_CR_KEY_EXCH_B:
391 		str = "3RSKEB";
392 		break;
393 	case SSL3_ST_CR_CERT_REQ_A:
394 		str = "3RCR_A";
395 		break;
396 	case SSL3_ST_CR_CERT_REQ_B:
397 		str = "3RCR_B";
398 		break;
399 	case SSL3_ST_CR_SRVR_DONE_A:
400 		str = "3RSD_A";
401 		break;
402 	case SSL3_ST_CR_SRVR_DONE_B:
403 		str = "3RSD_B";
404 		break;
405 	case SSL3_ST_CW_CERT_A:
406 		str = "3WCC_A";
407 		break;
408 	case SSL3_ST_CW_CERT_B:
409 		str = "3WCC_B";
410 		break;
411 	case SSL3_ST_CW_CERT_C:
412 		str = "3WCC_C";
413 		break;
414 	case SSL3_ST_CW_CERT_D:
415 		str = "3WCC_D";
416 		break;
417 	case SSL3_ST_CW_KEY_EXCH_A:
418 		str = "3WCKEA";
419 		break;
420 	case SSL3_ST_CW_KEY_EXCH_B:
421 		str = "3WCKEB";
422 		break;
423 	case SSL3_ST_CW_CERT_VRFY_A:
424 		str = "3WCV_A";
425 		break;
426 	case SSL3_ST_CW_CERT_VRFY_B:
427 		str = "3WCV_B";
428 		break;
429 
430 	case SSL3_ST_SW_CHANGE_A:
431 	case SSL3_ST_CW_CHANGE_A:
432 		str = "3WCCSA";
433 		break;
434 	case SSL3_ST_SW_CHANGE_B:
435 	case SSL3_ST_CW_CHANGE_B:
436 		str = "3WCCSB";
437 		break;
438 	case SSL3_ST_SW_FINISHED_A:
439 	case SSL3_ST_CW_FINISHED_A:
440 		str = "3WFINA";
441 		break;
442 	case SSL3_ST_SW_FINISHED_B:
443 	case SSL3_ST_CW_FINISHED_B:
444 		str = "3WFINB";
445 		break;
446 	case SSL3_ST_SR_CHANGE_A:
447 	case SSL3_ST_CR_CHANGE_A:
448 		str = "3RCCSA";
449 		break;
450 	case SSL3_ST_SR_CHANGE_B:
451 	case SSL3_ST_CR_CHANGE_B:
452 		str = "3RCCSB";
453 		break;
454 	case SSL3_ST_SR_FINISHED_A:
455 	case SSL3_ST_CR_FINISHED_A:
456 		str = "3RFINA";
457 		break;
458 	case SSL3_ST_SR_FINISHED_B:
459 	case SSL3_ST_CR_FINISHED_B:
460 		str = "3RFINB";
461 		break;
462 
463 	case SSL3_ST_SW_HELLO_REQ_A:
464 		str = "3WHR_A";
465 		break;
466 	case SSL3_ST_SW_HELLO_REQ_B:
467 		str = "3WHR_B";
468 		break;
469 	case SSL3_ST_SW_HELLO_REQ_C:
470 		str = "3WHR_C";
471 		break;
472 	case SSL3_ST_SR_CLNT_HELLO_A:
473 		str = "3RCH_A";
474 		break;
475 	case SSL3_ST_SR_CLNT_HELLO_B:
476 		str = "3RCH_B";
477 		break;
478 	case SSL3_ST_SR_CLNT_HELLO_C:
479 		str = "3RCH_C";
480 		break;
481 	case SSL3_ST_SW_SRVR_HELLO_A:
482 		str = "3WSH_A";
483 		break;
484 	case SSL3_ST_SW_SRVR_HELLO_B:
485 		str = "3WSH_B";
486 		break;
487 	case SSL3_ST_SW_CERT_A:
488 		str = "3WSC_A";
489 		break;
490 	case SSL3_ST_SW_CERT_B:
491 		str = "3WSC_B";
492 		break;
493 	case SSL3_ST_SW_KEY_EXCH_A:
494 		str = "3WSKEA";
495 		break;
496 	case SSL3_ST_SW_KEY_EXCH_B:
497 		str = "3WSKEB";
498 		break;
499 	case SSL3_ST_SW_CERT_REQ_A:
500 		str = "3WCR_A";
501 		break;
502 	case SSL3_ST_SW_CERT_REQ_B:
503 		str = "3WCR_B";
504 		break;
505 	case SSL3_ST_SW_SRVR_DONE_A:
506 		str = "3WSD_A";
507 		break;
508 	case SSL3_ST_SW_SRVR_DONE_B:
509 		str = "3WSD_B";
510 		break;
511 	case SSL3_ST_SR_CERT_A:
512 		str = "3RCC_A";
513 		break;
514 	case SSL3_ST_SR_CERT_B:
515 		str = "3RCC_B";
516 		break;
517 	case SSL3_ST_SR_KEY_EXCH_A:
518 		str = "3RCKEA";
519 		break;
520 	case SSL3_ST_SR_KEY_EXCH_B:
521 		str = "3RCKEB";
522 		break;
523 	case SSL3_ST_SR_CERT_VRFY_A:
524 		str = "3RCV_A";
525 		break;
526 	case SSL3_ST_SR_CERT_VRFY_B:
527 		str = "3RCV_B";
528 		break;
529 
530 	/* DTLS */
531 	case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
532 		str = "DRCHVA";
533 		break;
534 	case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
535 		str = "DRCHVB";
536 		break;
537 	case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
538 		str = "DWCHVA";
539 		break;
540 	case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
541 		str = "DWCHVB";
542 		break;
543 
544 	default:
545 		str = "UNKWN ";
546 		break;
547 	}
548 	return (str);
549 }
550 
551 const char *
552 SSL_alert_type_string_long(int value)
553 {
554 	value >>= 8;
555 	if (value == SSL3_AL_WARNING)
556 		return ("warning");
557 	else if (value == SSL3_AL_FATAL)
558 		return ("fatal");
559 	else
560 		return ("unknown");
561 }
562 
563 const char *
564 SSL_alert_type_string(int value)
565 {
566 	value >>= 8;
567 	if (value == SSL3_AL_WARNING)
568 		return ("W");
569 	else if (value == SSL3_AL_FATAL)
570 		return ("F");
571 	else
572 		return ("U");
573 }
574 
575 const char *
576 SSL_alert_desc_string(int value)
577 {
578 	const char *str;
579 
580 	switch (value & 0xff) {
581 	case SSL_AD_CLOSE_NOTIFY:
582 		str = "CN";
583 		break;
584 	case SSL_AD_UNEXPECTED_MESSAGE:
585 		str = "UM";
586 		break;
587 	case SSL_AD_BAD_RECORD_MAC:
588 		str = "BM";
589 		break;
590 	case SSL_AD_DECOMPRESSION_FAILURE:
591 		str = "DF";
592 		break;
593 	case SSL_AD_HANDSHAKE_FAILURE:
594 		str = "HF";
595 		break;
596 	case SSL_AD_BAD_CERTIFICATE:
597 		str = "BC";
598 		break;
599 	case SSL_AD_UNSUPPORTED_CERTIFICATE:
600 		str = "UC";
601 		break;
602 	case SSL_AD_CERTIFICATE_REVOKED:
603 		str = "CR";
604 		break;
605 	case SSL_AD_CERTIFICATE_EXPIRED:
606 		str = "CE";
607 		break;
608 	case SSL_AD_CERTIFICATE_UNKNOWN:
609 		str = "CU";
610 		break;
611 	case SSL_AD_ILLEGAL_PARAMETER:
612 		str = "IP";
613 		break;
614 	case SSL_AD_RECORD_OVERFLOW:
615 		str = "RO";
616 		break;
617 	case SSL_AD_UNKNOWN_CA:
618 		str = "CA";
619 		break;
620 	case SSL_AD_ACCESS_DENIED:
621 		str = "AD";
622 		break;
623 	case SSL_AD_DECODE_ERROR:
624 		str = "DE";
625 		break;
626 	case SSL_AD_DECRYPT_ERROR:
627 		str = "CY";
628 		break;
629 	case SSL_AD_PROTOCOL_VERSION:
630 		str = "PV";
631 		break;
632 	case SSL_AD_INSUFFICIENT_SECURITY:
633 		str = "IS";
634 		break;
635 	case SSL_AD_INTERNAL_ERROR:
636 		str = "IE";
637 		break;
638 	case SSL_AD_USER_CANCELLED:
639 		str = "US";
640 		break;
641 	case SSL_AD_NO_RENEGOTIATION:
642 		str = "NR";
643 		break;
644 	case SSL_AD_MISSING_EXTENSION:
645 		str = "ME";
646 		break;
647 	case SSL_AD_UNSUPPORTED_EXTENSION:
648 		str = "UE";
649 		break;
650 	case SSL_AD_CERTIFICATE_UNOBTAINABLE:
651 		str = "CO";
652 		break;
653 	case SSL_AD_UNRECOGNIZED_NAME:
654 		str = "UN";
655 		break;
656 	case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
657 		str = "BR";
658 		break;
659 	case SSL_AD_BAD_CERTIFICATE_HASH_VALUE:
660 		str = "BH";
661 		break;
662 	case SSL_AD_UNKNOWN_PSK_IDENTITY:
663 		str = "UP";
664 		break;
665 	default:
666 		str = "UK";
667 		break;
668 	}
669 	return (str);
670 }
671 
672 const char *
673 SSL_alert_desc_string_long(int value)
674 {
675 	const char *str;
676 
677 	switch (value & 0xff) {
678 	case SSL_AD_CLOSE_NOTIFY:
679 		str = "close notify";
680 		break;
681 	case SSL_AD_UNEXPECTED_MESSAGE:
682 		str = "unexpected_message";
683 		break;
684 	case SSL_AD_BAD_RECORD_MAC:
685 		str = "bad record mac";
686 		break;
687 	case SSL_AD_DECOMPRESSION_FAILURE:
688 		str = "decompression failure";
689 		break;
690 	case SSL_AD_HANDSHAKE_FAILURE:
691 		str = "handshake failure";
692 		break;
693 	case SSL_AD_BAD_CERTIFICATE:
694 		str = "bad certificate";
695 		break;
696 	case SSL_AD_UNSUPPORTED_CERTIFICATE:
697 		str = "unsupported certificate";
698 		break;
699 	case SSL_AD_CERTIFICATE_REVOKED:
700 		str = "certificate revoked";
701 		break;
702 	case SSL_AD_CERTIFICATE_EXPIRED:
703 		str = "certificate expired";
704 		break;
705 	case SSL_AD_CERTIFICATE_UNKNOWN:
706 		str = "certificate unknown";
707 		break;
708 	case SSL_AD_ILLEGAL_PARAMETER:
709 		str = "illegal parameter";
710 		break;
711 	case SSL_AD_RECORD_OVERFLOW:
712 		str = "record overflow";
713 		break;
714 	case SSL_AD_UNKNOWN_CA:
715 		str = "unknown CA";
716 		break;
717 	case SSL_AD_ACCESS_DENIED:
718 		str = "access denied";
719 		break;
720 	case SSL_AD_DECODE_ERROR:
721 		str = "decode error";
722 		break;
723 	case SSL_AD_DECRYPT_ERROR:
724 		str = "decrypt error";
725 		break;
726 	case SSL_AD_PROTOCOL_VERSION:
727 		str = "protocol version";
728 		break;
729 	case SSL_AD_INSUFFICIENT_SECURITY:
730 		str = "insufficient security";
731 		break;
732 	case SSL_AD_INTERNAL_ERROR:
733 		str = "internal error";
734 		break;
735 	case SSL_AD_USER_CANCELLED:
736 		str = "user canceled";
737 		break;
738 	case SSL_AD_NO_RENEGOTIATION:
739 		str = "no renegotiation";
740 		break;
741 	case SSL_AD_MISSING_EXTENSION:
742 		str = "missing extension";
743 		break;
744 	case SSL_AD_UNSUPPORTED_EXTENSION:
745 		str = "unsupported extension";
746 		break;
747 	case SSL_AD_CERTIFICATE_UNOBTAINABLE:
748 		str = "certificate unobtainable";
749 		break;
750 	case SSL_AD_UNRECOGNIZED_NAME:
751 		str = "unrecognized name";
752 		break;
753 	case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
754 		str = "bad certificate status response";
755 		break;
756 	case SSL_AD_BAD_CERTIFICATE_HASH_VALUE:
757 		str = "bad certificate hash value";
758 		break;
759 	case SSL_AD_UNKNOWN_PSK_IDENTITY:
760 		str = "unknown PSK identity";
761 		break;
762 	default:
763 		str = "unknown";
764 		break;
765 	}
766 	return (str);
767 }
768 
769 const char *
770 SSL_rstate_string(const SSL *s)
771 {
772 	const char *str;
773 
774 	switch (s->internal->rstate) {
775 	case SSL_ST_READ_HEADER:
776 		str = "RH";
777 		break;
778 	case SSL_ST_READ_BODY:
779 		str = "RB";
780 		break;
781 	case SSL_ST_READ_DONE:
782 		str = "RD";
783 		break;
784 	default:
785 		str = "unknown";
786 		break;
787 	}
788 	return (str);
789 }
790