Missing OPENSSL_free on error path.
[openssl.git] / ssl / ssl_stat.c
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 "ssl_locl.h"
87
88 const char *SSL_state_string_long(const SSL *s)
89 {
90     const char *str;
91
92     switch (s->state) {
93     case SSL_ST_BEFORE:
94         str = "before SSL initialization";
95         break;
96     case SSL_ST_ACCEPT:
97         str = "before accept initialization";
98         break;
99     case SSL_ST_CONNECT:
100         str = "before connect initialization";
101         break;
102     case SSL_ST_OK:
103         str = "SSL negotiation finished successfully";
104         break;
105     case SSL_ST_RENEGOTIATE:
106         str = "SSL renegotiate ciphers";
107         break;
108     case SSL_ST_BEFORE | SSL_ST_CONNECT:
109         str = "before/connect initialization";
110         break;
111     case SSL_ST_OK | SSL_ST_CONNECT:
112         str = "ok/connect SSL initialization";
113         break;
114     case SSL_ST_BEFORE | SSL_ST_ACCEPT:
115         str = "before/accept initialization";
116         break;
117     case SSL_ST_OK | SSL_ST_ACCEPT:
118         str = "ok/accept SSL initialization";
119         break;
120
121 #ifndef OPENSSL_NO_SSL3
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 #endif
301
302 /* SSLv2/v3 compatibility states */
303 /* client */
304     case SSL23_ST_CW_CLNT_HELLO_A:
305         str = "SSLv2/v3 write client hello A";
306         break;
307     case SSL23_ST_CW_CLNT_HELLO_B:
308         str = "SSLv2/v3 write client hello B";
309         break;
310     case SSL23_ST_CR_SRVR_HELLO_A:
311         str = "SSLv2/v3 read server hello A";
312         break;
313     case SSL23_ST_CR_SRVR_HELLO_B:
314         str = "SSLv2/v3 read server hello B";
315         break;
316 /* server */
317     case SSL23_ST_SR_CLNT_HELLO_A:
318         str = "SSLv2/v3 read client hello A";
319         break;
320     case SSL23_ST_SR_CLNT_HELLO_B:
321         str = "SSLv2/v3 read client hello B";
322         break;
323
324 /* DTLS */
325     case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
326         str = "DTLS1 read hello verify request A";
327         break;
328     case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
329         str = "DTLS1 read hello verify request B";
330         break;
331     case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
332         str = "DTLS1 write hello verify request A";
333         break;
334     case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
335         str = "DTLS1 write hello verify request B";
336         break;
337
338     default:
339         str = "unknown state";
340         break;
341     }
342     return (str);
343 }
344
345 const char *SSL_rstate_string_long(const SSL *s)
346 {
347     const char *str;
348
349     switch (s->rstate) {
350     case SSL_ST_READ_HEADER:
351         str = "read header";
352         break;
353     case SSL_ST_READ_BODY:
354         str = "read body";
355         break;
356     case SSL_ST_READ_DONE:
357         str = "read done";
358         break;
359     default:
360         str = "unknown";
361         break;
362     }
363     return (str);
364 }
365
366 const char *SSL_state_string(const SSL *s)
367 {
368     const char *str;
369
370     switch (s->state) {
371     case SSL_ST_BEFORE:
372         str = "PINIT ";
373         break;
374     case SSL_ST_ACCEPT:
375         str = "AINIT ";
376         break;
377     case SSL_ST_CONNECT:
378         str = "CINIT ";
379         break;
380     case SSL_ST_OK:
381         str = "SSLOK ";
382         break;
383
384 #ifndef OPENSSL_NO_SSL3
385 /* SSLv3 additions */
386     case SSL3_ST_SW_FLUSH:
387     case SSL3_ST_CW_FLUSH:
388         str = "3FLUSH";
389         break;
390     case SSL3_ST_CW_CLNT_HELLO_A:
391         str = "3WCH_A";
392         break;
393     case SSL3_ST_CW_CLNT_HELLO_B:
394         str = "3WCH_B";
395         break;
396     case SSL3_ST_CR_SRVR_HELLO_A:
397         str = "3RSH_A";
398         break;
399     case SSL3_ST_CR_SRVR_HELLO_B:
400         str = "3RSH_B";
401         break;
402     case SSL3_ST_CR_CERT_A:
403         str = "3RSC_A";
404         break;
405     case SSL3_ST_CR_CERT_B:
406         str = "3RSC_B";
407         break;
408     case SSL3_ST_CR_KEY_EXCH_A:
409         str = "3RSKEA";
410         break;
411     case SSL3_ST_CR_KEY_EXCH_B:
412         str = "3RSKEB";
413         break;
414     case SSL3_ST_CR_CERT_REQ_A:
415         str = "3RCR_A";
416         break;
417     case SSL3_ST_CR_CERT_REQ_B:
418         str = "3RCR_B";
419         break;
420     case SSL3_ST_CR_SRVR_DONE_A:
421         str = "3RSD_A";
422         break;
423     case SSL3_ST_CR_SRVR_DONE_B:
424         str = "3RSD_B";
425         break;
426     case SSL3_ST_CW_CERT_A:
427         str = "3WCC_A";
428         break;
429     case SSL3_ST_CW_CERT_B:
430         str = "3WCC_B";
431         break;
432     case SSL3_ST_CW_CERT_C:
433         str = "3WCC_C";
434         break;
435     case SSL3_ST_CW_CERT_D:
436         str = "3WCC_D";
437         break;
438     case SSL3_ST_CW_KEY_EXCH_A:
439         str = "3WCKEA";
440         break;
441     case SSL3_ST_CW_KEY_EXCH_B:
442         str = "3WCKEB";
443         break;
444     case SSL3_ST_CW_CERT_VRFY_A:
445         str = "3WCV_A";
446         break;
447     case SSL3_ST_CW_CERT_VRFY_B:
448         str = "3WCV_B";
449         break;
450
451     case SSL3_ST_SW_CHANGE_A:
452     case SSL3_ST_CW_CHANGE_A:
453         str = "3WCCSA";
454         break;
455     case SSL3_ST_SW_CHANGE_B:
456     case SSL3_ST_CW_CHANGE_B:
457         str = "3WCCSB";
458         break;
459     case SSL3_ST_SW_FINISHED_A:
460     case SSL3_ST_CW_FINISHED_A:
461         str = "3WFINA";
462         break;
463     case SSL3_ST_SW_FINISHED_B:
464     case SSL3_ST_CW_FINISHED_B:
465         str = "3WFINB";
466         break;
467     case SSL3_ST_SR_CHANGE_A:
468     case SSL3_ST_CR_CHANGE_A:
469         str = "3RCCSA";
470         break;
471     case SSL3_ST_SR_CHANGE_B:
472     case SSL3_ST_CR_CHANGE_B:
473         str = "3RCCSB";
474         break;
475     case SSL3_ST_SR_FINISHED_A:
476     case SSL3_ST_CR_FINISHED_A:
477         str = "3RFINA";
478         break;
479     case SSL3_ST_SR_FINISHED_B:
480     case SSL3_ST_CR_FINISHED_B:
481         str = "3RFINB";
482         break;
483
484     case SSL3_ST_SW_HELLO_REQ_A:
485         str = "3WHR_A";
486         break;
487     case SSL3_ST_SW_HELLO_REQ_B:
488         str = "3WHR_B";
489         break;
490     case SSL3_ST_SW_HELLO_REQ_C:
491         str = "3WHR_C";
492         break;
493     case SSL3_ST_SR_CLNT_HELLO_A:
494         str = "3RCH_A";
495         break;
496     case SSL3_ST_SR_CLNT_HELLO_B:
497         str = "3RCH_B";
498         break;
499     case SSL3_ST_SR_CLNT_HELLO_C:
500         str = "3RCH_C";
501         break;
502     case SSL3_ST_SW_SRVR_HELLO_A:
503         str = "3WSH_A";
504         break;
505     case SSL3_ST_SW_SRVR_HELLO_B:
506         str = "3WSH_B";
507         break;
508     case SSL3_ST_SW_CERT_A:
509         str = "3WSC_A";
510         break;
511     case SSL3_ST_SW_CERT_B:
512         str = "3WSC_B";
513         break;
514     case SSL3_ST_SW_KEY_EXCH_A:
515         str = "3WSKEA";
516         break;
517     case SSL3_ST_SW_KEY_EXCH_B:
518         str = "3WSKEB";
519         break;
520     case SSL3_ST_SW_CERT_REQ_A:
521         str = "3WCR_A";
522         break;
523     case SSL3_ST_SW_CERT_REQ_B:
524         str = "3WCR_B";
525         break;
526     case SSL3_ST_SW_SRVR_DONE_A:
527         str = "3WSD_A";
528         break;
529     case SSL3_ST_SW_SRVR_DONE_B:
530         str = "3WSD_B";
531         break;
532     case SSL3_ST_SR_CERT_A:
533         str = "3RCC_A";
534         break;
535     case SSL3_ST_SR_CERT_B:
536         str = "3RCC_B";
537         break;
538     case SSL3_ST_SR_KEY_EXCH_A:
539         str = "3RCKEA";
540         break;
541     case SSL3_ST_SR_KEY_EXCH_B:
542         str = "3RCKEB";
543         break;
544     case SSL3_ST_SR_CERT_VRFY_A:
545         str = "3RCV_A";
546         break;
547     case SSL3_ST_SR_CERT_VRFY_B:
548         str = "3RCV_B";
549         break;
550 #endif
551
552 /* SSLv2/v3 compatibility states */
553 /* client */
554     case SSL23_ST_CW_CLNT_HELLO_A:
555         str = "23WCHA";
556         break;
557     case SSL23_ST_CW_CLNT_HELLO_B:
558         str = "23WCHB";
559         break;
560     case SSL23_ST_CR_SRVR_HELLO_A:
561         str = "23RSHA";
562         break;
563     case SSL23_ST_CR_SRVR_HELLO_B:
564         str = "23RSHA";
565         break;
566 /* server */
567     case SSL23_ST_SR_CLNT_HELLO_A:
568         str = "23RCHA";
569         break;
570     case SSL23_ST_SR_CLNT_HELLO_B:
571         str = "23RCHB";
572         break;
573
574 /* DTLS */
575     case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
576         str = "DRCHVA";
577         break;
578     case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
579         str = "DRCHVB";
580         break;
581     case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
582         str = "DWCHVA";
583         break;
584     case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
585         str = "DWCHVB";
586         break;
587
588     default:
589         str = "UNKWN ";
590         break;
591     }
592     return (str);
593 }
594
595 const char *SSL_alert_type_string_long(int value)
596 {
597     value >>= 8;
598     if (value == SSL3_AL_WARNING)
599         return ("warning");
600     else if (value == SSL3_AL_FATAL)
601         return ("fatal");
602     else
603         return ("unknown");
604 }
605
606 const char *SSL_alert_type_string(int value)
607 {
608     value >>= 8;
609     if (value == SSL3_AL_WARNING)
610         return ("W");
611     else if (value == SSL3_AL_FATAL)
612         return ("F");
613     else
614         return ("U");
615 }
616
617 const char *SSL_alert_desc_string(int value)
618 {
619     const char *str;
620
621     switch (value & 0xff) {
622     case SSL3_AD_CLOSE_NOTIFY:
623         str = "CN";
624         break;
625     case SSL3_AD_UNEXPECTED_MESSAGE:
626         str = "UM";
627         break;
628     case SSL3_AD_BAD_RECORD_MAC:
629         str = "BM";
630         break;
631     case SSL3_AD_DECOMPRESSION_FAILURE:
632         str = "DF";
633         break;
634     case SSL3_AD_HANDSHAKE_FAILURE:
635         str = "HF";
636         break;
637     case SSL3_AD_NO_CERTIFICATE:
638         str = "NC";
639         break;
640     case SSL3_AD_BAD_CERTIFICATE:
641         str = "BC";
642         break;
643     case SSL3_AD_UNSUPPORTED_CERTIFICATE:
644         str = "UC";
645         break;
646     case SSL3_AD_CERTIFICATE_REVOKED:
647         str = "CR";
648         break;
649     case SSL3_AD_CERTIFICATE_EXPIRED:
650         str = "CE";
651         break;
652     case SSL3_AD_CERTIFICATE_UNKNOWN:
653         str = "CU";
654         break;
655     case SSL3_AD_ILLEGAL_PARAMETER:
656         str = "IP";
657         break;
658     case TLS1_AD_DECRYPTION_FAILED:
659         str = "DC";
660         break;
661     case TLS1_AD_RECORD_OVERFLOW:
662         str = "RO";
663         break;
664     case TLS1_AD_UNKNOWN_CA:
665         str = "CA";
666         break;
667     case TLS1_AD_ACCESS_DENIED:
668         str = "AD";
669         break;
670     case TLS1_AD_DECODE_ERROR:
671         str = "DE";
672         break;
673     case TLS1_AD_DECRYPT_ERROR:
674         str = "CY";
675         break;
676     case TLS1_AD_EXPORT_RESTRICTION:
677         str = "ER";
678         break;
679     case TLS1_AD_PROTOCOL_VERSION:
680         str = "PV";
681         break;
682     case TLS1_AD_INSUFFICIENT_SECURITY:
683         str = "IS";
684         break;
685     case TLS1_AD_INTERNAL_ERROR:
686         str = "IE";
687         break;
688     case TLS1_AD_USER_CANCELLED:
689         str = "US";
690         break;
691     case TLS1_AD_NO_RENEGOTIATION:
692         str = "NR";
693         break;
694     case TLS1_AD_UNSUPPORTED_EXTENSION:
695         str = "UE";
696         break;
697     case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
698         str = "CO";
699         break;
700     case TLS1_AD_UNRECOGNIZED_NAME:
701         str = "UN";
702         break;
703     case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
704         str = "BR";
705         break;
706     case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
707         str = "BH";
708         break;
709     case TLS1_AD_UNKNOWN_PSK_IDENTITY:
710         str = "UP";
711         break;
712     default:
713         str = "UK";
714         break;
715     }
716     return (str);
717 }
718
719 const char *SSL_alert_desc_string_long(int value)
720 {
721     const char *str;
722
723     switch (value & 0xff) {
724     case SSL3_AD_CLOSE_NOTIFY:
725         str = "close notify";
726         break;
727     case SSL3_AD_UNEXPECTED_MESSAGE:
728         str = "unexpected_message";
729         break;
730     case SSL3_AD_BAD_RECORD_MAC:
731         str = "bad record mac";
732         break;
733     case SSL3_AD_DECOMPRESSION_FAILURE:
734         str = "decompression failure";
735         break;
736     case SSL3_AD_HANDSHAKE_FAILURE:
737         str = "handshake failure";
738         break;
739     case SSL3_AD_NO_CERTIFICATE:
740         str = "no certificate";
741         break;
742     case SSL3_AD_BAD_CERTIFICATE:
743         str = "bad certificate";
744         break;
745     case SSL3_AD_UNSUPPORTED_CERTIFICATE:
746         str = "unsupported certificate";
747         break;
748     case SSL3_AD_CERTIFICATE_REVOKED:
749         str = "certificate revoked";
750         break;
751     case SSL3_AD_CERTIFICATE_EXPIRED:
752         str = "certificate expired";
753         break;
754     case SSL3_AD_CERTIFICATE_UNKNOWN:
755         str = "certificate unknown";
756         break;
757     case SSL3_AD_ILLEGAL_PARAMETER:
758         str = "illegal parameter";
759         break;
760     case TLS1_AD_DECRYPTION_FAILED:
761         str = "decryption failed";
762         break;
763     case TLS1_AD_RECORD_OVERFLOW:
764         str = "record overflow";
765         break;
766     case TLS1_AD_UNKNOWN_CA:
767         str = "unknown CA";
768         break;
769     case TLS1_AD_ACCESS_DENIED:
770         str = "access denied";
771         break;
772     case TLS1_AD_DECODE_ERROR:
773         str = "decode error";
774         break;
775     case TLS1_AD_DECRYPT_ERROR:
776         str = "decrypt error";
777         break;
778     case TLS1_AD_EXPORT_RESTRICTION:
779         str = "export restriction";
780         break;
781     case TLS1_AD_PROTOCOL_VERSION:
782         str = "protocol version";
783         break;
784     case TLS1_AD_INSUFFICIENT_SECURITY:
785         str = "insufficient security";
786         break;
787     case TLS1_AD_INTERNAL_ERROR:
788         str = "internal error";
789         break;
790     case TLS1_AD_USER_CANCELLED:
791         str = "user canceled";
792         break;
793     case TLS1_AD_NO_RENEGOTIATION:
794         str = "no renegotiation";
795         break;
796     case TLS1_AD_UNSUPPORTED_EXTENSION:
797         str = "unsupported extension";
798         break;
799     case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
800         str = "certificate unobtainable";
801         break;
802     case TLS1_AD_UNRECOGNIZED_NAME:
803         str = "unrecognized name";
804         break;
805     case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
806         str = "bad certificate status response";
807         break;
808     case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
809         str = "bad certificate hash value";
810         break;
811     case TLS1_AD_UNKNOWN_PSK_IDENTITY:
812         str = "unknown PSK identity";
813         break;
814     default:
815         str = "unknown";
816         break;
817     }
818     return (str);
819 }
820
821 const char *SSL_rstate_string(const SSL *s)
822 {
823     const char *str;
824
825     switch (s->rstate) {
826     case SSL_ST_READ_HEADER:
827         str = "RH";
828         break;
829     case SSL_ST_READ_BODY:
830         str = "RB";
831         break;
832     case SSL_ST_READ_DONE:
833         str = "RD";
834         break;
835     default:
836         str = "unknown";
837         break;
838     }
839     return (str);
840 }