various spelling fixes
[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     if (ossl_statem_in_error(s))
90         return "error";
91
92     switch (SSL_get_state(s)) {
93     case TLS_ST_BEFORE:
94         return "before SSL initialization";
95     case TLS_ST_OK:
96         return "SSL negotiation finished successfully";
97     case TLS_ST_CW_CLNT_HELLO:
98         return "SSLv3/TLS write client hello";
99     case TLS_ST_CR_SRVR_HELLO:
100         return "SSLv3/TLS read server hello";
101     case TLS_ST_CR_CERT:
102         return "SSLv3/TLS read server certificate";
103     case TLS_ST_CR_KEY_EXCH:
104         return "SSLv3/TLS read server key exchange";
105     case TLS_ST_CR_CERT_REQ:
106         return "SSLv3/TLS read server certificate request";
107     case TLS_ST_CR_SESSION_TICKET:
108         return "SSLv3/TLS read server session ticket";
109     case TLS_ST_CR_SRVR_DONE:
110         return "SSLv3/TLS read server done";
111     case TLS_ST_CW_CERT:
112         return "SSLv3/TLS write client certificate";
113     case TLS_ST_CW_KEY_EXCH:
114         return "SSLv3/TLS write client key exchange";
115     case TLS_ST_CW_CERT_VRFY:
116         return "SSLv3/TLS write certificate verify";
117     case TLS_ST_CW_CHANGE:
118     case TLS_ST_SW_CHANGE:
119         return "SSLv3/TLS write change cipher spec";
120     case TLS_ST_CW_FINISHED:
121     case TLS_ST_SW_FINISHED:
122         return "SSLv3/TLS write finished";
123     case TLS_ST_CR_CHANGE:
124     case TLS_ST_SR_CHANGE:
125         return "SSLv3/TLS read change cipher spec";
126     case TLS_ST_CR_FINISHED:
127     case TLS_ST_SR_FINISHED:
128         return "SSLv3/TLS read finished";
129     case TLS_ST_SR_CLNT_HELLO:
130         return "SSLv3/TLS read client hello";
131     case TLS_ST_SW_HELLO_REQ:
132         return "SSLv3/TLS write hello request";
133     case TLS_ST_SW_SRVR_HELLO:
134         return "SSLv3/TLS write server hello";
135     case TLS_ST_SW_CERT:
136         return "SSLv3/TLS write certificate";
137     case TLS_ST_SW_KEY_EXCH:
138         return "SSLv3/TLS write key exchange";
139     case TLS_ST_SW_CERT_REQ:
140         return "SSLv3/TLS write certificate request";
141     case TLS_ST_SW_SESSION_TICKET:
142         return "SSLv3/TLS write session ticket";
143     case TLS_ST_SW_SRVR_DONE:
144         return "SSLv3/TLS write server done";
145     case TLS_ST_SR_CERT:
146         return "SSLv3/TLS read client certificate";
147     case TLS_ST_SR_KEY_EXCH:
148         return "SSLv3/TLS read client key exchange";
149     case TLS_ST_SR_CERT_VRFY:
150         return "SSLv3/TLS read certificate verify";
151     case DTLS_ST_CR_HELLO_VERIFY_REQUEST:
152         return "DTLS1 read hello verify request";
153     case DTLS_ST_SW_HELLO_VERIFY_REQUEST:
154         return "DTLS1 write hello verify request";
155     default:
156         return "unknown state";
157     }
158 }
159
160
161 const char *SSL_state_string(const SSL *s)
162 {
163     if (ossl_statem_in_error(s))
164         return "SSLERR";
165
166     switch (SSL_get_state(s)) {
167     case TLS_ST_BEFORE:
168         return "PINIT ";
169     case TLS_ST_OK:
170         return "SSLOK ";
171     case TLS_ST_CW_CLNT_HELLO:
172         return "TWCH";
173     case TLS_ST_CR_SRVR_HELLO:
174         return "TRSH";
175     case TLS_ST_CR_CERT:
176         return "TRSC";
177     case TLS_ST_CR_KEY_EXCH:
178         return "TRSKE";
179     case TLS_ST_CR_CERT_REQ:
180         return "TRCR";
181     case TLS_ST_CR_SRVR_DONE:
182         return "TRSD";
183     case TLS_ST_CW_CERT:
184         return "TWCC";
185     case TLS_ST_CW_KEY_EXCH:
186         return "TWCKE";
187     case TLS_ST_CW_CERT_VRFY:
188         return "TWCV";
189     case TLS_ST_SW_CHANGE:
190     case TLS_ST_CW_CHANGE:
191         return "TWCCS";
192     case TLS_ST_SW_FINISHED:
193     case TLS_ST_CW_FINISHED:
194         return "TWFIN";
195     case TLS_ST_SR_CHANGE:
196     case TLS_ST_CR_CHANGE:
197         return "TRCCS";
198     case TLS_ST_SR_FINISHED:
199     case TLS_ST_CR_FINISHED:
200         return "TRFIN";
201     case TLS_ST_SW_HELLO_REQ:
202         return "TWHR";
203     case TLS_ST_SR_CLNT_HELLO:
204         return "TRCH";
205     case TLS_ST_SW_SRVR_HELLO:
206         return "TWSH";
207     case TLS_ST_SW_CERT:
208         return "TWSC";
209     case TLS_ST_SW_KEY_EXCH:
210         return "TWSKE";
211     case TLS_ST_SW_CERT_REQ:
212         return "TWCR";
213     case TLS_ST_SW_SRVR_DONE:
214         return "TWSD";
215     case TLS_ST_SR_CERT:
216         return "TRCC";
217     case TLS_ST_SR_KEY_EXCH:
218         return "TRCKE";
219     case TLS_ST_SR_CERT_VRFY:
220         return "TRCV";
221     case DTLS_ST_CR_HELLO_VERIFY_REQUEST:
222         return "DRCHV";
223     case DTLS_ST_SW_HELLO_VERIFY_REQUEST:
224         return "DWCHV";
225     default:
226         return "UNKWN ";
227     }
228 }
229
230 const char *SSL_alert_type_string_long(int value)
231 {
232     switch (value >> 8) {
233     case SSL3_AL_WARNING:
234         return "warning";
235     case SSL3_AL_FATAL:
236         return "fatal";
237     default:
238         return "unknown";
239     }
240 }
241
242 const char *SSL_alert_type_string(int value)
243 {
244     switch (value >> 8) {
245     case SSL3_AL_WARNING:
246         return "W";
247     case SSL3_AL_FATAL:
248         return "F";
249     default:
250         return "U";
251     }
252 }
253
254 const char *SSL_alert_desc_string(int value)
255 {
256     switch (value & 0xff) {
257     case SSL3_AD_CLOSE_NOTIFY:
258         return "CN";
259     case SSL3_AD_UNEXPECTED_MESSAGE:
260         return "UM";
261     case SSL3_AD_BAD_RECORD_MAC:
262         return "BM";
263     case SSL3_AD_DECOMPRESSION_FAILURE:
264         return "DF";
265     case SSL3_AD_HANDSHAKE_FAILURE:
266         return "HF";
267     case SSL3_AD_NO_CERTIFICATE:
268         return "NC";
269     case SSL3_AD_BAD_CERTIFICATE:
270         return "BC";
271     case SSL3_AD_UNSUPPORTED_CERTIFICATE:
272         return "UC";
273     case SSL3_AD_CERTIFICATE_REVOKED:
274         return "CR";
275     case SSL3_AD_CERTIFICATE_EXPIRED:
276         return "CE";
277     case SSL3_AD_CERTIFICATE_UNKNOWN:
278         return "CU";
279     case SSL3_AD_ILLEGAL_PARAMETER:
280         return "IP";
281     case TLS1_AD_DECRYPTION_FAILED:
282         return "DC";
283     case TLS1_AD_RECORD_OVERFLOW:
284         return "RO";
285     case TLS1_AD_UNKNOWN_CA:
286         return "CA";
287     case TLS1_AD_ACCESS_DENIED:
288         return "AD";
289     case TLS1_AD_DECODE_ERROR:
290         return "DE";
291     case TLS1_AD_DECRYPT_ERROR:
292         return "CY";
293     case TLS1_AD_EXPORT_RESTRICTION:
294         return "ER";
295     case TLS1_AD_PROTOCOL_VERSION:
296         return "PV";
297     case TLS1_AD_INSUFFICIENT_SECURITY:
298         return "IS";
299     case TLS1_AD_INTERNAL_ERROR:
300         return "IE";
301     case TLS1_AD_USER_CANCELLED:
302         return "US";
303     case TLS1_AD_NO_RENEGOTIATION:
304         return "NR";
305     case TLS1_AD_UNSUPPORTED_EXTENSION:
306         return "UE";
307     case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
308         return "CO";
309     case TLS1_AD_UNRECOGNIZED_NAME:
310         return "UN";
311     case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
312         return "BR";
313     case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
314         return "BH";
315     case TLS1_AD_UNKNOWN_PSK_IDENTITY:
316         return "UP";
317     default:
318         return "UK";
319     }
320 }
321
322 const char *SSL_alert_desc_string_long(int value)
323 {
324     switch (value & 0xff) {
325     case SSL3_AD_CLOSE_NOTIFY:
326         return "close notify";
327     case SSL3_AD_UNEXPECTED_MESSAGE:
328         return "unexpected_message";
329     case SSL3_AD_BAD_RECORD_MAC:
330         return "bad record mac";
331     case SSL3_AD_DECOMPRESSION_FAILURE:
332         return "decompression failure";
333     case SSL3_AD_HANDSHAKE_FAILURE:
334         return "handshake failure";
335     case SSL3_AD_NO_CERTIFICATE:
336         return "no certificate";
337     case SSL3_AD_BAD_CERTIFICATE:
338         return "bad certificate";
339     case SSL3_AD_UNSUPPORTED_CERTIFICATE:
340         return "unsupported certificate";
341     case SSL3_AD_CERTIFICATE_REVOKED:
342         return "certificate revoked";
343     case SSL3_AD_CERTIFICATE_EXPIRED:
344         return "certificate expired";
345     case SSL3_AD_CERTIFICATE_UNKNOWN:
346         return "certificate unknown";
347     case SSL3_AD_ILLEGAL_PARAMETER:
348         return "illegal parameter";
349     case TLS1_AD_DECRYPTION_FAILED:
350         return "decryption failed";
351     case TLS1_AD_RECORD_OVERFLOW:
352         return "record overflow";
353     case TLS1_AD_UNKNOWN_CA:
354         return "unknown CA";
355     case TLS1_AD_ACCESS_DENIED:
356         return "access denied";
357     case TLS1_AD_DECODE_ERROR:
358         return "decode error";
359     case TLS1_AD_DECRYPT_ERROR:
360         return "decrypt error";
361     case TLS1_AD_EXPORT_RESTRICTION:
362         return "export restriction";
363     case TLS1_AD_PROTOCOL_VERSION:
364         return "protocol version";
365     case TLS1_AD_INSUFFICIENT_SECURITY:
366         return "insufficient security";
367     case TLS1_AD_INTERNAL_ERROR:
368         return "internal error";
369     case TLS1_AD_USER_CANCELLED:
370         return "user canceled";
371     case TLS1_AD_NO_RENEGOTIATION:
372         return "no renegotiation";
373     case TLS1_AD_UNSUPPORTED_EXTENSION:
374         return "unsupported extension";
375     case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
376         return "certificate unobtainable";
377     case TLS1_AD_UNRECOGNIZED_NAME:
378         return "unrecognized name";
379     case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
380         return "bad certificate status response";
381     case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
382         return "bad certificate hash value";
383     case TLS1_AD_UNKNOWN_PSK_IDENTITY:
384         return "unknown PSK identity";
385     default:
386         return "unknown";
387     }
388 }