Fix typo in SSL_pending docs
[openssl.git] / ssl / ssl_stat.c
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to.  The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  *    must display the following acknowledgement:
32  *    "This product includes cryptographic software written by
33  *     Eric Young (eay@cryptsoft.com)"
34  *    The word 'cryptographic' can be left out if the rouines from the library
35  *    being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  *    the apps directory (application code) you must include an acknowledgement:
38  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed.  i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.]
56  */
57 /* ====================================================================
58  * Copyright 2005 Nokia. All rights reserved.
59  *
60  * The portions of the attached software ("Contribution") is developed by
61  * Nokia Corporation and is licensed pursuant to the OpenSSL open source
62  * license.
63  *
64  * The Contribution, originally written by Mika Kousa and Pasi Eronen of
65  * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
66  * support (see RFC 4279) to OpenSSL.
67  *
68  * No patent licenses or other rights except those expressly stated in
69  * the OpenSSL open source license shall be deemed granted or received
70  * expressly, by implication, estoppel, or otherwise.
71  *
72  * No assurances are provided by Nokia that the Contribution does not
73  * infringe the patent or other intellectual property rights of any third
74  * party or that the license provides you with all the necessary rights
75  * to make use of the Contribution.
76  *
77  * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
78  * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
79  * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
80  * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
81  * OTHERWISE.
82  */
83
84 #include <stdio.h>
85 #include "ssl_locl.h"
86
87 const char *SSL_state_string_long(const SSL *s)
88 {
89     const char *str;
90
91     if (ossl_statem_in_error(s)) {
92         return "error";
93     }
94
95     switch (SSL_get_state(s)) {
96     case TLS_ST_BEFORE:
97         str = "before SSL initialization";
98         break;
99     case TLS_ST_OK:
100         str = "SSL negotiation finished successfully";
101         break;
102
103 /* SSLv3 additions */
104     case TLS_ST_CW_CLNT_HELLO:
105         str = "SSLv3/TLS write client hello";
106         break;
107     case TLS_ST_CR_SRVR_HELLO:
108         str = "SSLv3/TLS read server hello";
109         break;
110     case TLS_ST_CR_CERT:
111         str = "SSLv3/TLS read server certificate";
112         break;
113     case TLS_ST_CR_KEY_EXCH:
114         str = "SSLv3/TLS read server key exchange";
115         break;
116     case TLS_ST_CR_CERT_REQ:
117         str = "SSLv3/TLS read server certificate request";
118         break;
119     case TLS_ST_CR_SESSION_TICKET:
120         str = "SSLv3/TLS read server session ticket";
121         break;
122     case TLS_ST_CR_SRVR_DONE:
123         str = "SSLv3/TLS read server done";
124         break;
125     case TLS_ST_CW_CERT:
126         str = "SSLv3/TLS write client certificate";
127         break;
128     case TLS_ST_CW_KEY_EXCH:
129         str = "SSLv3/TLS write client key exchange";
130         break;
131     case TLS_ST_CW_CERT_VRFY:
132         str = "SSLv3/TLS write certificate verify";
133         break;
134
135     case TLS_ST_CW_CHANGE:
136     case TLS_ST_SW_CHANGE:
137         str = "SSLv3/TLS write change cipher spec";
138         break;
139     case TLS_ST_CW_FINISHED:
140     case TLS_ST_SW_FINISHED:
141         str = "SSLv3/TLS write finished";
142         break;
143     case TLS_ST_CR_CHANGE:
144     case TLS_ST_SR_CHANGE:
145         str = "SSLv3/TLS read change cipher spec";
146         break;
147     case TLS_ST_CR_FINISHED:
148     case TLS_ST_SR_FINISHED:
149         str = "SSLv3/TLS read finished";
150         break;
151
152     case TLS_ST_SR_CLNT_HELLO:
153         str = "SSLv3/TLS read client hello";
154         break;
155     case TLS_ST_SW_HELLO_REQ:
156         str = "SSLv3/TLS write hello request";
157         break;
158     case TLS_ST_SW_SRVR_HELLO:
159         str = "SSLv3/TLS write server hello";
160         break;
161     case TLS_ST_SW_CERT:
162         str = "SSLv3/TLS write certificate";
163         break;
164     case TLS_ST_SW_KEY_EXCH:
165         str = "SSLv3/TLS write key exchange";
166         break;
167     case TLS_ST_SW_CERT_REQ:
168         str = "SSLv3/TLS write certificate request";
169         break;
170     case TLS_ST_SW_SESSION_TICKET:
171         str = "SSLv3/TLS write session ticket";
172         break;
173     case TLS_ST_SW_SRVR_DONE:
174         str = "SSLv3/TLS write server done";
175         break;
176     case TLS_ST_SR_CERT:
177         str = "SSLv3/TLS read client certificate";
178         break;
179     case TLS_ST_SR_KEY_EXCH:
180         str = "SSLv3/TLS read client key exchange";
181         break;
182     case TLS_ST_SR_CERT_VRFY:
183         str = "SSLv3/TLS read certificate verify";
184         break;
185
186 /* DTLS */
187     case DTLS_ST_CR_HELLO_VERIFY_REQUEST:
188         str = "DTLS1 read hello verify request";
189         break;
190     case DTLS_ST_SW_HELLO_VERIFY_REQUEST:
191         str = "DTLS1 write hello verify request";
192         break;
193
194     default:
195         str = "unknown state";
196         break;
197     }
198     return (str);
199 }
200
201
202 const char *SSL_state_string(const SSL *s)
203 {
204     const char *str;
205
206     if (ossl_statem_in_error(s)) {
207         return "SSLERR";
208     }
209
210     switch (SSL_get_state(s)) {
211     case TLS_ST_BEFORE:
212         str = "PINIT ";
213         break;
214     case TLS_ST_OK:
215         str = "SSLOK ";
216         break;
217
218     case TLS_ST_CW_CLNT_HELLO:
219         str = "TWCH";
220         break;
221     case TLS_ST_CR_SRVR_HELLO:
222         str = "TRSH";
223         break;
224     case TLS_ST_CR_CERT:
225         str = "TRSC";
226         break;
227     case TLS_ST_CR_KEY_EXCH:
228         str = "TRSKE";
229         break;
230     case TLS_ST_CR_CERT_REQ:
231         str = "TRCR";
232         break;
233     case TLS_ST_CR_SRVR_DONE:
234         str = "TRSD";
235         break;
236     case TLS_ST_CW_CERT:
237         str = "TWCC";
238         break;
239     case TLS_ST_CW_KEY_EXCH:
240         str = "TWCKE";
241         break;
242     case TLS_ST_CW_CERT_VRFY:
243         str = "TWCV";
244         break;
245
246     case TLS_ST_SW_CHANGE:
247     case TLS_ST_CW_CHANGE:
248         str = "TWCCS";
249         break;
250     case TLS_ST_SW_FINISHED:
251     case TLS_ST_CW_FINISHED:
252         str = "TWFIN";
253         break;
254     case TLS_ST_SR_CHANGE:
255     case TLS_ST_CR_CHANGE:
256         str = "TRCCS";
257         break;
258     case TLS_ST_SR_FINISHED:
259     case TLS_ST_CR_FINISHED:
260         str = "TRFIN";
261         break;
262
263     case TLS_ST_SW_HELLO_REQ:
264         str = "TWHR";
265         break;
266     case TLS_ST_SR_CLNT_HELLO:
267         str = "TRCH";
268         break;
269     case TLS_ST_SW_SRVR_HELLO:
270         str = "TWSH";
271         break;
272     case TLS_ST_SW_CERT:
273         str = "TWSC";
274         break;
275     case TLS_ST_SW_KEY_EXCH:
276         str = "TWSKE";
277         break;
278     case TLS_ST_SW_CERT_REQ:
279         str = "TWCR";
280         break;
281     case TLS_ST_SW_SRVR_DONE:
282         str = "TWSD";
283         break;
284     case TLS_ST_SR_CERT:
285         str = "TRCC";
286         break;
287     case TLS_ST_SR_KEY_EXCH:
288         str = "TRCKE";
289         break;
290     case TLS_ST_SR_CERT_VRFY:
291         str = "TRCV";
292         break;
293
294 /* DTLS */
295     case DTLS_ST_CR_HELLO_VERIFY_REQUEST:
296         str = "DRCHV";
297         break;
298     case DTLS_ST_SW_HELLO_VERIFY_REQUEST:
299         str = "DWCHV";
300         break;
301
302     default:
303         str = "UNKWN ";
304         break;
305     }
306     return (str);
307 }
308
309 const char *SSL_alert_type_string_long(int value)
310 {
311     value >>= 8;
312     if (value == SSL3_AL_WARNING)
313         return ("warning");
314     else if (value == SSL3_AL_FATAL)
315         return ("fatal");
316     else
317         return ("unknown");
318 }
319
320 const char *SSL_alert_type_string(int value)
321 {
322     value >>= 8;
323     if (value == SSL3_AL_WARNING)
324         return ("W");
325     else if (value == SSL3_AL_FATAL)
326         return ("F");
327     else
328         return ("U");
329 }
330
331 const char *SSL_alert_desc_string(int value)
332 {
333     const char *str;
334
335     switch (value & 0xff) {
336     case SSL3_AD_CLOSE_NOTIFY:
337         str = "CN";
338         break;
339     case SSL3_AD_UNEXPECTED_MESSAGE:
340         str = "UM";
341         break;
342     case SSL3_AD_BAD_RECORD_MAC:
343         str = "BM";
344         break;
345     case SSL3_AD_DECOMPRESSION_FAILURE:
346         str = "DF";
347         break;
348     case SSL3_AD_HANDSHAKE_FAILURE:
349         str = "HF";
350         break;
351     case SSL3_AD_NO_CERTIFICATE:
352         str = "NC";
353         break;
354     case SSL3_AD_BAD_CERTIFICATE:
355         str = "BC";
356         break;
357     case SSL3_AD_UNSUPPORTED_CERTIFICATE:
358         str = "UC";
359         break;
360     case SSL3_AD_CERTIFICATE_REVOKED:
361         str = "CR";
362         break;
363     case SSL3_AD_CERTIFICATE_EXPIRED:
364         str = "CE";
365         break;
366     case SSL3_AD_CERTIFICATE_UNKNOWN:
367         str = "CU";
368         break;
369     case SSL3_AD_ILLEGAL_PARAMETER:
370         str = "IP";
371         break;
372     case TLS1_AD_DECRYPTION_FAILED:
373         str = "DC";
374         break;
375     case TLS1_AD_RECORD_OVERFLOW:
376         str = "RO";
377         break;
378     case TLS1_AD_UNKNOWN_CA:
379         str = "CA";
380         break;
381     case TLS1_AD_ACCESS_DENIED:
382         str = "AD";
383         break;
384     case TLS1_AD_DECODE_ERROR:
385         str = "DE";
386         break;
387     case TLS1_AD_DECRYPT_ERROR:
388         str = "CY";
389         break;
390     case TLS1_AD_EXPORT_RESTRICTION:
391         str = "ER";
392         break;
393     case TLS1_AD_PROTOCOL_VERSION:
394         str = "PV";
395         break;
396     case TLS1_AD_INSUFFICIENT_SECURITY:
397         str = "IS";
398         break;
399     case TLS1_AD_INTERNAL_ERROR:
400         str = "IE";
401         break;
402     case TLS1_AD_USER_CANCELLED:
403         str = "US";
404         break;
405     case TLS1_AD_NO_RENEGOTIATION:
406         str = "NR";
407         break;
408     case TLS1_AD_UNSUPPORTED_EXTENSION:
409         str = "UE";
410         break;
411     case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
412         str = "CO";
413         break;
414     case TLS1_AD_UNRECOGNIZED_NAME:
415         str = "UN";
416         break;
417     case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
418         str = "BR";
419         break;
420     case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
421         str = "BH";
422         break;
423     case TLS1_AD_UNKNOWN_PSK_IDENTITY:
424         str = "UP";
425         break;
426     default:
427         str = "UK";
428         break;
429     }
430     return (str);
431 }
432
433 const char *SSL_alert_desc_string_long(int value)
434 {
435     const char *str;
436
437     switch (value & 0xff) {
438     case SSL3_AD_CLOSE_NOTIFY:
439         str = "close notify";
440         break;
441     case SSL3_AD_UNEXPECTED_MESSAGE:
442         str = "unexpected_message";
443         break;
444     case SSL3_AD_BAD_RECORD_MAC:
445         str = "bad record mac";
446         break;
447     case SSL3_AD_DECOMPRESSION_FAILURE:
448         str = "decompression failure";
449         break;
450     case SSL3_AD_HANDSHAKE_FAILURE:
451         str = "handshake failure";
452         break;
453     case SSL3_AD_NO_CERTIFICATE:
454         str = "no certificate";
455         break;
456     case SSL3_AD_BAD_CERTIFICATE:
457         str = "bad certificate";
458         break;
459     case SSL3_AD_UNSUPPORTED_CERTIFICATE:
460         str = "unsupported certificate";
461         break;
462     case SSL3_AD_CERTIFICATE_REVOKED:
463         str = "certificate revoked";
464         break;
465     case SSL3_AD_CERTIFICATE_EXPIRED:
466         str = "certificate expired";
467         break;
468     case SSL3_AD_CERTIFICATE_UNKNOWN:
469         str = "certificate unknown";
470         break;
471     case SSL3_AD_ILLEGAL_PARAMETER:
472         str = "illegal parameter";
473         break;
474     case TLS1_AD_DECRYPTION_FAILED:
475         str = "decryption failed";
476         break;
477     case TLS1_AD_RECORD_OVERFLOW:
478         str = "record overflow";
479         break;
480     case TLS1_AD_UNKNOWN_CA:
481         str = "unknown CA";
482         break;
483     case TLS1_AD_ACCESS_DENIED:
484         str = "access denied";
485         break;
486     case TLS1_AD_DECODE_ERROR:
487         str = "decode error";
488         break;
489     case TLS1_AD_DECRYPT_ERROR:
490         str = "decrypt error";
491         break;
492     case TLS1_AD_EXPORT_RESTRICTION:
493         str = "export restriction";
494         break;
495     case TLS1_AD_PROTOCOL_VERSION:
496         str = "protocol version";
497         break;
498     case TLS1_AD_INSUFFICIENT_SECURITY:
499         str = "insufficient security";
500         break;
501     case TLS1_AD_INTERNAL_ERROR:
502         str = "internal error";
503         break;
504     case TLS1_AD_USER_CANCELLED:
505         str = "user canceled";
506         break;
507     case TLS1_AD_NO_RENEGOTIATION:
508         str = "no renegotiation";
509         break;
510     case TLS1_AD_UNSUPPORTED_EXTENSION:
511         str = "unsupported extension";
512         break;
513     case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
514         str = "certificate unobtainable";
515         break;
516     case TLS1_AD_UNRECOGNIZED_NAME:
517         str = "unrecognized name";
518         break;
519     case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
520         str = "bad certificate status response";
521         break;
522     case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
523         str = "bad certificate hash value";
524         break;
525     case TLS1_AD_UNKNOWN_PSK_IDENTITY:
526         str = "unknown PSK identity";
527         break;
528     default:
529         str = "unknown";
530         break;
531     }
532     return (str);
533 }