• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ssl/ssl_stat.c */
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 "internal.h"
87 
SSL_state_string_long(const SSL * s)88 const char *SSL_state_string_long(const SSL *s) {
89   const char *str;
90 
91   switch (s->state) {
92     case SSL_ST_ACCEPT:
93       str = "before accept initialization";
94       break;
95 
96     case SSL_ST_CONNECT:
97       str = "before connect initialization";
98       break;
99 
100     case SSL_ST_OK:
101       str = "SSL negotiation finished successfully";
102       break;
103 
104     case SSL_ST_RENEGOTIATE:
105       str = "SSL renegotiate ciphers";
106       break;
107 
108     /* SSLv3 additions */
109     case SSL3_ST_CW_CLNT_HELLO_A:
110       str = "SSLv3 write client hello A";
111       break;
112 
113     case SSL3_ST_CW_CLNT_HELLO_B:
114       str = "SSLv3 write client hello B";
115       break;
116 
117     case SSL3_ST_CR_SRVR_HELLO_A:
118       str = "SSLv3 read server hello A";
119       break;
120 
121     case SSL3_ST_CR_SRVR_HELLO_B:
122       str = "SSLv3 read server hello B";
123       break;
124 
125     case SSL3_ST_CR_CERT_A:
126       str = "SSLv3 read server certificate A";
127       break;
128 
129     case SSL3_ST_CR_CERT_B:
130       str = "SSLv3 read server certificate B";
131       break;
132 
133     case SSL3_ST_CR_KEY_EXCH_A:
134       str = "SSLv3 read server key exchange A";
135       break;
136 
137     case SSL3_ST_CR_KEY_EXCH_B:
138       str = "SSLv3 read server key exchange B";
139       break;
140 
141     case SSL3_ST_CR_CERT_REQ_A:
142       str = "SSLv3 read server certificate request A";
143       break;
144 
145     case SSL3_ST_CR_CERT_REQ_B:
146       str = "SSLv3 read server certificate request B";
147       break;
148 
149     case SSL3_ST_CR_SESSION_TICKET_A:
150       str = "SSLv3 read server session ticket A";
151       break;
152 
153     case SSL3_ST_CR_SESSION_TICKET_B:
154       str = "SSLv3 read server session ticket B";
155       break;
156 
157     case SSL3_ST_CR_SRVR_DONE_A:
158       str = "SSLv3 read server done A";
159       break;
160 
161     case SSL3_ST_CR_SRVR_DONE_B:
162       str = "SSLv3 read server done B";
163       break;
164 
165     case SSL3_ST_CW_CERT_A:
166       str = "SSLv3 write client certificate A";
167       break;
168 
169     case SSL3_ST_CW_CERT_B:
170       str = "SSLv3 write client certificate B";
171       break;
172 
173     case SSL3_ST_CW_CERT_C:
174       str = "SSLv3 write client certificate C";
175       break;
176 
177     case SSL3_ST_CW_CERT_D:
178       str = "SSLv3 write client certificate D";
179       break;
180 
181     case SSL3_ST_CW_KEY_EXCH_A:
182       str = "SSLv3 write client key exchange A";
183       break;
184 
185     case SSL3_ST_CW_KEY_EXCH_B:
186       str = "SSLv3 write client key exchange B";
187       break;
188 
189     case SSL3_ST_CW_CERT_VRFY_A:
190       str = "SSLv3 write certificate verify A";
191       break;
192 
193     case SSL3_ST_CW_CERT_VRFY_B:
194       str = "SSLv3 write certificate verify B";
195       break;
196 
197     case SSL3_ST_CW_CHANGE_A:
198     case SSL3_ST_SW_CHANGE_A:
199       str = "SSLv3 write change cipher spec A";
200       break;
201 
202     case SSL3_ST_CW_CHANGE_B:
203     case SSL3_ST_SW_CHANGE_B:
204       str = "SSLv3 write change cipher spec B";
205       break;
206 
207     case SSL3_ST_CW_FINISHED_A:
208     case SSL3_ST_SW_FINISHED_A:
209       str = "SSLv3 write finished A";
210       break;
211 
212     case SSL3_ST_CW_FINISHED_B:
213     case SSL3_ST_SW_FINISHED_B:
214       str = "SSLv3 write finished B";
215       break;
216 
217     case SSL3_ST_CR_CHANGE:
218     case SSL3_ST_SR_CHANGE:
219       str = "SSLv3 read change cipher spec";
220       break;
221 
222     case SSL3_ST_CR_FINISHED_A:
223     case SSL3_ST_SR_FINISHED_A:
224       str = "SSLv3 read finished A";
225       break;
226 
227     case SSL3_ST_CR_FINISHED_B:
228     case SSL3_ST_SR_FINISHED_B:
229       str = "SSLv3 read finished B";
230       break;
231 
232     case SSL3_ST_CW_FLUSH:
233     case SSL3_ST_SW_FLUSH:
234       str = "SSLv3 flush data";
235       break;
236 
237     case SSL3_ST_SR_CLNT_HELLO_A:
238       str = "SSLv3 read client hello A";
239       break;
240 
241     case SSL3_ST_SR_CLNT_HELLO_B:
242       str = "SSLv3 read client hello B";
243       break;
244 
245     case SSL3_ST_SR_CLNT_HELLO_C:
246       str = "SSLv3 read client hello C";
247       break;
248 
249     case SSL3_ST_SR_CLNT_HELLO_D:
250       str = "SSLv3 read client hello D";
251       break;
252 
253     case SSL3_ST_SW_HELLO_REQ_A:
254       str = "SSLv3 write hello request A";
255       break;
256 
257     case SSL3_ST_SW_HELLO_REQ_B:
258       str = "SSLv3 write hello request B";
259       break;
260 
261     case SSL3_ST_SW_HELLO_REQ_C:
262       str = "SSLv3 write hello request C";
263       break;
264 
265     case SSL3_ST_SW_SRVR_HELLO_A:
266       str = "SSLv3 write server hello A";
267       break;
268 
269     case SSL3_ST_SW_SRVR_HELLO_B:
270       str = "SSLv3 write server hello B";
271       break;
272 
273     case SSL3_ST_SW_CERT_A:
274       str = "SSLv3 write certificate A";
275       break;
276 
277     case SSL3_ST_SW_CERT_B:
278       str = "SSLv3 write certificate B";
279       break;
280 
281     case SSL3_ST_SW_KEY_EXCH_A:
282       str = "SSLv3 write key exchange A";
283       break;
284 
285     case SSL3_ST_SW_KEY_EXCH_B:
286       str = "SSLv3 write key exchange B";
287       break;
288 
289     case SSL3_ST_SW_CERT_REQ_A:
290       str = "SSLv3 write certificate request A";
291       break;
292 
293     case SSL3_ST_SW_CERT_REQ_B:
294       str = "SSLv3 write certificate request B";
295       break;
296 
297     case SSL3_ST_SW_SESSION_TICKET_A:
298       str = "SSLv3 write session ticket A";
299       break;
300 
301     case SSL3_ST_SW_SESSION_TICKET_B:
302       str = "SSLv3 write session ticket B";
303       break;
304 
305     case SSL3_ST_SW_SRVR_DONE_A:
306       str = "SSLv3 write server done A";
307       break;
308 
309     case SSL3_ST_SW_SRVR_DONE_B:
310       str = "SSLv3 write server done B";
311       break;
312 
313     case SSL3_ST_SR_CERT_A:
314       str = "SSLv3 read client certificate A";
315       break;
316 
317     case SSL3_ST_SR_CERT_B:
318       str = "SSLv3 read client certificate B";
319       break;
320 
321     case SSL3_ST_SR_KEY_EXCH_A:
322       str = "SSLv3 read client key exchange A";
323       break;
324 
325     case SSL3_ST_SR_KEY_EXCH_B:
326       str = "SSLv3 read client key exchange B";
327       break;
328 
329     case SSL3_ST_SR_CERT_VRFY_A:
330       str = "SSLv3 read certificate verify A";
331       break;
332 
333     case SSL3_ST_SR_CERT_VRFY_B:
334       str = "SSLv3 read certificate verify B";
335       break;
336 
337     /* SSLv2/v3 compatibility states */
338     /* client */
339     case SSL23_ST_CW_CLNT_HELLO_A:
340       str = "SSLv2/v3 write client hello A";
341       break;
342 
343     case SSL23_ST_CW_CLNT_HELLO_B:
344       str = "SSLv2/v3 write client hello B";
345       break;
346 
347     case SSL23_ST_CR_SRVR_HELLO_A:
348       str = "SSLv2/v3 read server hello A";
349       break;
350 
351     case SSL23_ST_CR_SRVR_HELLO_B:
352       str = "SSLv2/v3 read server hello B";
353       break;
354 
355     /* server */
356     case SSL23_ST_SR_CLNT_HELLO:
357       str = "SSLv2/v3 read client hello";
358       break;
359 
360     case SSL23_ST_SR_V2_CLNT_HELLO:
361       str = "SSLv2/v3 read v2 client hello";
362       break;
363 
364     case SSL23_ST_SR_SWITCH_VERSION:
365       str = "SSLv2/v3 switch version";
366       break;
367 
368     /* DTLS */
369     case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
370       str = "DTLS1 read hello verify request A";
371       break;
372 
373     case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
374       str = "DTLS1 read hello verify request B";
375       break;
376 
377     default:
378       str = "unknown state";
379       break;
380   }
381 
382   return str;
383 }
384 
SSL_rstate_string_long(const SSL * s)385 const char *SSL_rstate_string_long(const SSL *s) {
386   const char *str;
387 
388   switch (s->rstate) {
389     case SSL_ST_READ_HEADER:
390       str = "read header";
391       break;
392 
393     case SSL_ST_READ_BODY:
394       str = "read body";
395       break;
396 
397     case SSL_ST_READ_DONE:
398       str = "read done";
399       break;
400 
401     default:
402       str = "unknown";
403       break;
404   }
405 
406   return str;
407 }
408 
SSL_state_string(const SSL * s)409 const char *SSL_state_string(const SSL *s) {
410   const char *str;
411 
412   switch (s->state) {
413     case SSL_ST_ACCEPT:
414       str = "AINIT ";
415       break;
416 
417     case SSL_ST_CONNECT:
418       str = "CINIT ";
419       break;
420 
421     case SSL_ST_OK:
422       str = "SSLOK ";
423       break;
424 
425     /* SSLv3 additions */
426     case SSL3_ST_SW_FLUSH:
427     case SSL3_ST_CW_FLUSH:
428       str = "3FLUSH";
429       break;
430 
431     case SSL3_ST_CW_CLNT_HELLO_A:
432       str = "3WCH_A";
433       break;
434 
435     case SSL3_ST_CW_CLNT_HELLO_B:
436       str = "3WCH_B";
437       break;
438 
439     case SSL3_ST_CR_SRVR_HELLO_A:
440       str = "3RSH_A";
441       break;
442 
443     case SSL3_ST_CR_SRVR_HELLO_B:
444       str = "3RSH_B";
445       break;
446 
447     case SSL3_ST_CR_CERT_A:
448       str = "3RSC_A";
449       break;
450 
451     case SSL3_ST_CR_CERT_B:
452       str = "3RSC_B";
453       break;
454 
455     case SSL3_ST_CR_KEY_EXCH_A:
456       str = "3RSKEA";
457       break;
458 
459     case SSL3_ST_CR_KEY_EXCH_B:
460       str = "3RSKEB";
461       break;
462 
463     case SSL3_ST_CR_CERT_REQ_A:
464       str = "3RCR_A";
465       break;
466 
467     case SSL3_ST_CR_CERT_REQ_B:
468       str = "3RCR_B";
469       break;
470 
471     case SSL3_ST_CR_SRVR_DONE_A:
472       str = "3RSD_A";
473       break;
474 
475     case SSL3_ST_CR_SRVR_DONE_B:
476       str = "3RSD_B";
477       break;
478 
479     case SSL3_ST_CW_CERT_A:
480       str = "3WCC_A";
481       break;
482 
483     case SSL3_ST_CW_CERT_B:
484       str = "3WCC_B";
485       break;
486 
487     case SSL3_ST_CW_CERT_C:
488       str = "3WCC_C";
489       break;
490 
491     case SSL3_ST_CW_CERT_D:
492       str = "3WCC_D";
493       break;
494 
495     case SSL3_ST_CW_KEY_EXCH_A:
496       str = "3WCKEA";
497       break;
498 
499     case SSL3_ST_CW_KEY_EXCH_B:
500       str = "3WCKEB";
501       break;
502 
503     case SSL3_ST_CW_CERT_VRFY_A:
504       str = "3WCV_A";
505       break;
506 
507     case SSL3_ST_CW_CERT_VRFY_B:
508       str = "3WCV_B";
509       break;
510 
511     case SSL3_ST_SW_CHANGE_A:
512     case SSL3_ST_CW_CHANGE_A:
513       str = "3WCCSA";
514       break;
515 
516     case SSL3_ST_SW_CHANGE_B:
517     case SSL3_ST_CW_CHANGE_B:
518       str = "3WCCSB";
519       break;
520 
521     case SSL3_ST_SW_FINISHED_A:
522     case SSL3_ST_CW_FINISHED_A:
523       str = "3WFINA";
524       break;
525 
526     case SSL3_ST_SW_FINISHED_B:
527     case SSL3_ST_CW_FINISHED_B:
528       str = "3WFINB";
529       break;
530 
531     case SSL3_ST_CR_CHANGE:
532     case SSL3_ST_SR_CHANGE:
533       str = "3RCCS_";
534       break;
535 
536     case SSL3_ST_SR_FINISHED_A:
537     case SSL3_ST_CR_FINISHED_A:
538       str = "3RFINA";
539       break;
540 
541     case SSL3_ST_SR_FINISHED_B:
542     case SSL3_ST_CR_FINISHED_B:
543       str = "3RFINB";
544       break;
545 
546     case SSL3_ST_SW_HELLO_REQ_A:
547       str = "3WHR_A";
548       break;
549 
550     case SSL3_ST_SW_HELLO_REQ_B:
551       str = "3WHR_B";
552       break;
553 
554     case SSL3_ST_SW_HELLO_REQ_C:
555       str = "3WHR_C";
556       break;
557 
558     case SSL3_ST_SR_CLNT_HELLO_A:
559       str = "3RCH_A";
560       break;
561 
562     case SSL3_ST_SR_CLNT_HELLO_B:
563       str = "3RCH_B";
564       break;
565 
566     case SSL3_ST_SR_CLNT_HELLO_C:
567       str = "3RCH_C";
568       break;
569 
570     case SSL3_ST_SR_CLNT_HELLO_D:
571       str = "3RCH_D";
572       break;
573 
574     case SSL3_ST_SW_SRVR_HELLO_A:
575       str = "3WSH_A";
576       break;
577 
578     case SSL3_ST_SW_SRVR_HELLO_B:
579       str = "3WSH_B";
580       break;
581 
582     case SSL3_ST_SW_CERT_A:
583       str = "3WSC_A";
584       break;
585 
586     case SSL3_ST_SW_CERT_B:
587       str = "3WSC_B";
588       break;
589 
590     case SSL3_ST_SW_KEY_EXCH_A:
591       str = "3WSKEA";
592       break;
593 
594     case SSL3_ST_SW_KEY_EXCH_B:
595       str = "3WSKEB";
596       break;
597 
598     case SSL3_ST_SW_CERT_REQ_A:
599       str = "3WCR_A";
600       break;
601 
602     case SSL3_ST_SW_CERT_REQ_B:
603       str = "3WCR_B";
604       break;
605 
606     case SSL3_ST_SW_SRVR_DONE_A:
607       str = "3WSD_A";
608       break;
609 
610     case SSL3_ST_SW_SRVR_DONE_B:
611       str = "3WSD_B";
612       break;
613 
614     case SSL3_ST_SR_CERT_A:
615       str = "3RCC_A";
616       break;
617 
618     case SSL3_ST_SR_CERT_B:
619       str = "3RCC_B";
620       break;
621 
622     case SSL3_ST_SR_KEY_EXCH_A:
623       str = "3RCKEA";
624       break;
625 
626     case SSL3_ST_SR_KEY_EXCH_B:
627       str = "3RCKEB";
628       break;
629 
630     case SSL3_ST_SR_CERT_VRFY_A:
631       str = "3RCV_A";
632       break;
633 
634     case SSL3_ST_SR_CERT_VRFY_B:
635       str = "3RCV_B";
636       break;
637 
638     /* SSLv2/v3 compatibility states */
639     /* client */
640     case SSL23_ST_CW_CLNT_HELLO_A:
641       str = "23WCHA";
642       break;
643 
644     case SSL23_ST_CW_CLNT_HELLO_B:
645       str = "23WCHB";
646       break;
647 
648     case SSL23_ST_CR_SRVR_HELLO_A:
649       str = "23RSHA";
650       break;
651 
652     case SSL23_ST_CR_SRVR_HELLO_B:
653       str = "23RSHA";
654       break;
655 
656     /* server */
657     case SSL23_ST_SR_CLNT_HELLO:
658       str = "23RCH_";
659       break;
660 
661     case SSL23_ST_SR_V2_CLNT_HELLO:
662       str = "23R2CH";
663       break;
664 
665     case SSL23_ST_SR_SWITCH_VERSION:
666       str = "23RSW_";
667       break;
668 
669     /* DTLS */
670     case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
671       str = "DRCHVA";
672       break;
673 
674     case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
675       str = "DRCHVB";
676       break;
677 
678     default:
679       str = "UNKWN ";
680       break;
681   }
682 
683   return str;
684 }
685 
SSL_alert_type_string_long(int value)686 const char *SSL_alert_type_string_long(int value) {
687   value >>= 8;
688   if (value == SSL3_AL_WARNING) {
689     return "warning";
690   } else if (value == SSL3_AL_FATAL) {
691     return "fatal";
692   }
693 
694   return "unknown";
695 }
696 
SSL_alert_type_string(int value)697 const char *SSL_alert_type_string(int value) {
698   value >>= 8;
699   if (value == SSL3_AL_WARNING) {
700     return "W";
701   } else if (value == SSL3_AL_FATAL) {
702     return "F";
703   }
704 
705   return "U";
706 }
707 
SSL_alert_desc_string(int value)708 const char *SSL_alert_desc_string(int value) {
709   const char *str;
710 
711   switch (value & 0xff) {
712     case SSL3_AD_CLOSE_NOTIFY:
713       str = "CN";
714       break;
715 
716     case SSL3_AD_UNEXPECTED_MESSAGE:
717       str = "UM";
718       break;
719 
720     case SSL3_AD_BAD_RECORD_MAC:
721       str = "BM";
722       break;
723 
724     case SSL3_AD_DECOMPRESSION_FAILURE:
725       str = "DF";
726       break;
727 
728     case SSL3_AD_HANDSHAKE_FAILURE:
729       str = "HF";
730       break;
731 
732     case SSL3_AD_NO_CERTIFICATE:
733       str = "NC";
734       break;
735 
736     case SSL3_AD_BAD_CERTIFICATE:
737       str = "BC";
738       break;
739 
740     case SSL3_AD_UNSUPPORTED_CERTIFICATE:
741       str = "UC";
742       break;
743 
744     case SSL3_AD_CERTIFICATE_REVOKED:
745       str = "CR";
746       break;
747 
748     case SSL3_AD_CERTIFICATE_EXPIRED:
749       str = "CE";
750       break;
751 
752     case SSL3_AD_CERTIFICATE_UNKNOWN:
753       str = "CU";
754       break;
755 
756     case SSL3_AD_ILLEGAL_PARAMETER:
757       str = "IP";
758       break;
759 
760     case TLS1_AD_DECRYPTION_FAILED:
761       str = "DC";
762       break;
763 
764     case TLS1_AD_RECORD_OVERFLOW:
765       str = "RO";
766       break;
767 
768     case TLS1_AD_UNKNOWN_CA:
769       str = "CA";
770       break;
771 
772     case TLS1_AD_ACCESS_DENIED:
773       str = "AD";
774       break;
775 
776     case TLS1_AD_DECODE_ERROR:
777       str = "DE";
778       break;
779 
780     case TLS1_AD_DECRYPT_ERROR:
781       str = "CY";
782       break;
783 
784     case TLS1_AD_EXPORT_RESTRICTION:
785       str = "ER";
786       break;
787 
788     case TLS1_AD_PROTOCOL_VERSION:
789       str = "PV";
790       break;
791 
792     case TLS1_AD_INSUFFICIENT_SECURITY:
793       str = "IS";
794       break;
795 
796     case TLS1_AD_INTERNAL_ERROR:
797       str = "IE";
798       break;
799 
800     case TLS1_AD_USER_CANCELLED:
801       str = "US";
802       break;
803 
804     case TLS1_AD_NO_RENEGOTIATION:
805       str = "NR";
806       break;
807 
808     case TLS1_AD_UNSUPPORTED_EXTENSION:
809       str = "UE";
810       break;
811 
812     case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
813       str = "CO";
814       break;
815 
816     case TLS1_AD_UNRECOGNIZED_NAME:
817       str = "UN";
818       break;
819 
820     case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
821       str = "BR";
822       break;
823 
824     case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
825       str = "BH";
826       break;
827 
828     case TLS1_AD_UNKNOWN_PSK_IDENTITY:
829       str = "UP";
830       break;
831 
832     default:
833       str = "UK";
834       break;
835   }
836 
837   return str;
838 }
839 
SSL_alert_desc_string_long(int value)840 const char *SSL_alert_desc_string_long(int value) {
841   const char *str;
842 
843   switch (value & 0xff) {
844     case SSL3_AD_CLOSE_NOTIFY:
845       str = "close notify";
846       break;
847 
848     case SSL3_AD_UNEXPECTED_MESSAGE:
849       str = "unexpected_message";
850       break;
851 
852     case SSL3_AD_BAD_RECORD_MAC:
853       str = "bad record mac";
854       break;
855 
856     case SSL3_AD_DECOMPRESSION_FAILURE:
857       str = "decompression failure";
858       break;
859 
860     case SSL3_AD_HANDSHAKE_FAILURE:
861       str = "handshake failure";
862       break;
863 
864     case SSL3_AD_NO_CERTIFICATE:
865       str = "no certificate";
866       break;
867 
868     case SSL3_AD_BAD_CERTIFICATE:
869       str = "bad certificate";
870       break;
871 
872     case SSL3_AD_UNSUPPORTED_CERTIFICATE:
873       str = "unsupported certificate";
874       break;
875 
876     case SSL3_AD_CERTIFICATE_REVOKED:
877       str = "certificate revoked";
878       break;
879 
880     case SSL3_AD_CERTIFICATE_EXPIRED:
881       str = "certificate expired";
882       break;
883 
884     case SSL3_AD_CERTIFICATE_UNKNOWN:
885       str = "certificate unknown";
886       break;
887 
888     case SSL3_AD_ILLEGAL_PARAMETER:
889       str = "illegal parameter";
890       break;
891 
892     case TLS1_AD_DECRYPTION_FAILED:
893       str = "decryption failed";
894       break;
895 
896     case TLS1_AD_RECORD_OVERFLOW:
897       str = "record overflow";
898       break;
899 
900     case TLS1_AD_UNKNOWN_CA:
901       str = "unknown CA";
902       break;
903 
904     case TLS1_AD_ACCESS_DENIED:
905       str = "access denied";
906       break;
907 
908     case TLS1_AD_DECODE_ERROR:
909       str = "decode error";
910       break;
911 
912     case TLS1_AD_DECRYPT_ERROR:
913       str = "decrypt error";
914       break;
915 
916     case TLS1_AD_EXPORT_RESTRICTION:
917       str = "export restriction";
918       break;
919 
920     case TLS1_AD_PROTOCOL_VERSION:
921       str = "protocol version";
922       break;
923 
924     case TLS1_AD_INSUFFICIENT_SECURITY:
925       str = "insufficient security";
926       break;
927 
928     case TLS1_AD_INTERNAL_ERROR:
929       str = "internal error";
930       break;
931 
932     case TLS1_AD_USER_CANCELLED:
933       str = "user canceled";
934       break;
935 
936     case TLS1_AD_NO_RENEGOTIATION:
937       str = "no renegotiation";
938       break;
939 
940     case TLS1_AD_UNSUPPORTED_EXTENSION:
941       str = "unsupported extension";
942       break;
943 
944     case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
945       str = "certificate unobtainable";
946       break;
947 
948     case TLS1_AD_UNRECOGNIZED_NAME:
949       str = "unrecognized name";
950       break;
951 
952     case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
953       str = "bad certificate status response";
954       break;
955 
956     case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
957       str = "bad certificate hash value";
958       break;
959 
960     case TLS1_AD_UNKNOWN_PSK_IDENTITY:
961       str = "unknown PSK identity";
962       break;
963 
964     default:
965       str = "unknown";
966       break;
967   }
968 
969   return str;
970 }
971 
SSL_rstate_string(const SSL * s)972 const char *SSL_rstate_string(const SSL *s) {
973   const char *str;
974 
975   switch (s->rstate) {
976     case SSL_ST_READ_HEADER:
977       str = "RH";
978       break;
979 
980     case SSL_ST_READ_BODY:
981       str = "RB";
982       break;
983 
984     case SSL_ST_READ_DONE:
985       str = "RD";
986       break;
987 
988     default:
989       str = "unknown";
990       break;
991   }
992 
993   return str;
994 }
995