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 <openssl/ssl.h>
85
86 #include "internal.h"
87
88
SSL_state_string_long(const SSL * ssl)89 const char *SSL_state_string_long(const SSL *ssl) {
90 switch (ssl->state) {
91 case SSL_ST_ACCEPT:
92 return "before accept initialization";
93
94 case SSL_ST_CONNECT:
95 return "before connect initialization";
96
97 case SSL_ST_OK:
98 return "SSL negotiation finished successfully";
99
100 case SSL_ST_RENEGOTIATE:
101 return "SSL renegotiate ciphers";
102
103 /* SSLv3 additions */
104 case SSL3_ST_CW_CLNT_HELLO_A:
105 return "SSLv3 write client hello A";
106
107 case SSL3_ST_CW_CLNT_HELLO_B:
108 return "SSLv3 write client hello B";
109
110 case SSL3_ST_CR_SRVR_HELLO_A:
111 return "SSLv3 read server hello A";
112
113 case SSL3_ST_CR_SRVR_HELLO_B:
114 return "SSLv3 read server hello B";
115
116 case SSL3_ST_CR_CERT_A:
117 return "SSLv3 read server certificate A";
118
119 case SSL3_ST_CR_CERT_B:
120 return "SSLv3 read server certificate B";
121
122 case SSL3_ST_CR_KEY_EXCH_A:
123 return "SSLv3 read server key exchange A";
124
125 case SSL3_ST_CR_KEY_EXCH_B:
126 return "SSLv3 read server key exchange B";
127
128 case SSL3_ST_CR_CERT_REQ_A:
129 return "SSLv3 read server certificate request A";
130
131 case SSL3_ST_CR_CERT_REQ_B:
132 return "SSLv3 read server certificate request B";
133
134 case SSL3_ST_CR_SESSION_TICKET_A:
135 return "SSLv3 read server session ticket A";
136
137 case SSL3_ST_CR_SESSION_TICKET_B:
138 return "SSLv3 read server session ticket B";
139
140 case SSL3_ST_CR_SRVR_DONE_A:
141 return "SSLv3 read server done A";
142
143 case SSL3_ST_CR_SRVR_DONE_B:
144 return "SSLv3 read server done B";
145
146 case SSL3_ST_CW_CERT_A:
147 return "SSLv3 write client certificate A";
148
149 case SSL3_ST_CW_CERT_B:
150 return "SSLv3 write client certificate B";
151
152 case SSL3_ST_CW_CERT_C:
153 return "SSLv3 write client certificate C";
154
155 case SSL3_ST_CW_CERT_D:
156 return "SSLv3 write client certificate D";
157
158 case SSL3_ST_CW_KEY_EXCH_A:
159 return "SSLv3 write client key exchange A";
160
161 case SSL3_ST_CW_KEY_EXCH_B:
162 return "SSLv3 write client key exchange B";
163
164 case SSL3_ST_CW_CERT_VRFY_A:
165 return "SSLv3 write certificate verify A";
166
167 case SSL3_ST_CW_CERT_VRFY_B:
168 return "SSLv3 write certificate verify B";
169
170 case SSL3_ST_CW_CHANGE_A:
171 case SSL3_ST_SW_CHANGE_A:
172 return "SSLv3 write change cipher spec A";
173
174 case SSL3_ST_CW_CHANGE_B:
175 case SSL3_ST_SW_CHANGE_B:
176 return "SSLv3 write change cipher spec B";
177
178 case SSL3_ST_CW_FINISHED_A:
179 case SSL3_ST_SW_FINISHED_A:
180 return "SSLv3 write finished A";
181
182 case SSL3_ST_CW_FINISHED_B:
183 case SSL3_ST_SW_FINISHED_B:
184 return "SSLv3 write finished B";
185
186 case SSL3_ST_CR_CHANGE:
187 case SSL3_ST_SR_CHANGE:
188 return "SSLv3 read change cipher spec";
189
190 case SSL3_ST_CR_FINISHED_A:
191 case SSL3_ST_SR_FINISHED_A:
192 return "SSLv3 read finished A";
193
194 case SSL3_ST_CR_FINISHED_B:
195 case SSL3_ST_SR_FINISHED_B:
196 return "SSLv3 read finished B";
197
198 case SSL3_ST_CW_FLUSH:
199 case SSL3_ST_SW_FLUSH:
200 return "SSLv3 flush data";
201
202 case SSL3_ST_SR_CLNT_HELLO_A:
203 return "SSLv3 read client hello A";
204
205 case SSL3_ST_SR_CLNT_HELLO_B:
206 return "SSLv3 read client hello B";
207
208 case SSL3_ST_SR_CLNT_HELLO_C:
209 return "SSLv3 read client hello C";
210
211 case SSL3_ST_SR_CLNT_HELLO_D:
212 return "SSLv3 read client hello D";
213
214 case SSL3_ST_SW_HELLO_REQ_A:
215 return "SSLv3 write hello request A";
216
217 case SSL3_ST_SW_HELLO_REQ_B:
218 return "SSLv3 write hello request B";
219
220 case SSL3_ST_SW_HELLO_REQ_C:
221 return "SSLv3 write hello request C";
222
223 case SSL3_ST_SW_SRVR_HELLO_A:
224 return "SSLv3 write server hello A";
225
226 case SSL3_ST_SW_SRVR_HELLO_B:
227 return "SSLv3 write server hello B";
228
229 case SSL3_ST_SW_CERT_A:
230 return "SSLv3 write certificate A";
231
232 case SSL3_ST_SW_CERT_B:
233 return "SSLv3 write certificate B";
234
235 case SSL3_ST_SW_KEY_EXCH_A:
236 return "SSLv3 write key exchange A";
237
238 case SSL3_ST_SW_KEY_EXCH_B:
239 return "SSLv3 write key exchange B";
240
241 case SSL3_ST_SW_CERT_REQ_A:
242 return "SSLv3 write certificate request A";
243
244 case SSL3_ST_SW_CERT_REQ_B:
245 return "SSLv3 write certificate request B";
246
247 case SSL3_ST_SW_SESSION_TICKET_A:
248 return "SSLv3 write session ticket A";
249
250 case SSL3_ST_SW_SESSION_TICKET_B:
251 return "SSLv3 write session ticket B";
252
253 case SSL3_ST_SW_SRVR_DONE_A:
254 return "SSLv3 write server done A";
255
256 case SSL3_ST_SW_SRVR_DONE_B:
257 return "SSLv3 write server done B";
258
259 case SSL3_ST_SR_CERT_A:
260 return "SSLv3 read client certificate A";
261
262 case SSL3_ST_SR_CERT_B:
263 return "SSLv3 read client certificate B";
264
265 case SSL3_ST_SR_KEY_EXCH_A:
266 return "SSLv3 read client key exchange A";
267
268 case SSL3_ST_SR_KEY_EXCH_B:
269 return "SSLv3 read client key exchange B";
270
271 case SSL3_ST_SR_CERT_VRFY_A:
272 return "SSLv3 read certificate verify A";
273
274 case SSL3_ST_SR_CERT_VRFY_B:
275 return "SSLv3 read certificate verify B";
276
277 /* DTLS */
278 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
279 return "DTLS1 read hello verify request A";
280
281 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
282 return "DTLS1 read hello verify request B";
283
284 default:
285 return "unknown state";
286 }
287 }
288
SSL_state_string(const SSL * ssl)289 const char *SSL_state_string(const SSL *ssl) {
290 switch (ssl->state) {
291 case SSL_ST_ACCEPT:
292 return "AINIT ";
293
294 case SSL_ST_CONNECT:
295 return "CINIT ";
296
297 case SSL_ST_OK:
298 return "SSLOK ";
299
300 /* SSLv3 additions */
301 case SSL3_ST_SW_FLUSH:
302 case SSL3_ST_CW_FLUSH:
303 return "3FLUSH";
304
305 case SSL3_ST_CW_CLNT_HELLO_A:
306 return "3WCH_A";
307
308 case SSL3_ST_CW_CLNT_HELLO_B:
309 return "3WCH_B";
310
311 case SSL3_ST_CR_SRVR_HELLO_A:
312 return "3RSH_A";
313
314 case SSL3_ST_CR_SRVR_HELLO_B:
315 return "3RSH_B";
316
317 case SSL3_ST_CR_CERT_A:
318 return "3RSC_A";
319
320 case SSL3_ST_CR_CERT_B:
321 return "3RSC_B";
322
323 case SSL3_ST_CR_KEY_EXCH_A:
324 return "3RSKEA";
325
326 case SSL3_ST_CR_KEY_EXCH_B:
327 return "3RSKEB";
328
329 case SSL3_ST_CR_CERT_REQ_A:
330 return "3RCR_A";
331
332 case SSL3_ST_CR_CERT_REQ_B:
333 return "3RCR_B";
334
335 case SSL3_ST_CR_SRVR_DONE_A:
336 return "3RSD_A";
337
338 case SSL3_ST_CR_SRVR_DONE_B:
339 return "3RSD_B";
340
341 case SSL3_ST_CW_CERT_A:
342 return "3WCC_A";
343
344 case SSL3_ST_CW_CERT_B:
345 return "3WCC_B";
346
347 case SSL3_ST_CW_CERT_C:
348 return "3WCC_C";
349
350 case SSL3_ST_CW_CERT_D:
351 return "3WCC_D";
352
353 case SSL3_ST_CW_KEY_EXCH_A:
354 return "3WCKEA";
355
356 case SSL3_ST_CW_KEY_EXCH_B:
357 return "3WCKEB";
358
359 case SSL3_ST_CW_CERT_VRFY_A:
360 return "3WCV_A";
361
362 case SSL3_ST_CW_CERT_VRFY_B:
363 return "3WCV_B";
364
365 case SSL3_ST_SW_CHANGE_A:
366 case SSL3_ST_CW_CHANGE_A:
367 return "3WCCSA";
368
369 case SSL3_ST_SW_CHANGE_B:
370 case SSL3_ST_CW_CHANGE_B:
371 return "3WCCSB";
372
373 case SSL3_ST_SW_FINISHED_A:
374 case SSL3_ST_CW_FINISHED_A:
375 return "3WFINA";
376
377 case SSL3_ST_SW_FINISHED_B:
378 case SSL3_ST_CW_FINISHED_B:
379 return "3WFINB";
380
381 case SSL3_ST_CR_CHANGE:
382 case SSL3_ST_SR_CHANGE:
383 return "3RCCS_";
384
385 case SSL3_ST_SR_FINISHED_A:
386 case SSL3_ST_CR_FINISHED_A:
387 return "3RFINA";
388
389 case SSL3_ST_SR_FINISHED_B:
390 case SSL3_ST_CR_FINISHED_B:
391 return "3RFINB";
392
393 case SSL3_ST_SW_HELLO_REQ_A:
394 return "3WHR_A";
395
396 case SSL3_ST_SW_HELLO_REQ_B:
397 return "3WHR_B";
398
399 case SSL3_ST_SW_HELLO_REQ_C:
400 return "3WHR_C";
401
402 case SSL3_ST_SR_CLNT_HELLO_A:
403 return "3RCH_A";
404
405 case SSL3_ST_SR_CLNT_HELLO_B:
406 return "3RCH_B";
407
408 case SSL3_ST_SR_CLNT_HELLO_C:
409 return "3RCH_C";
410
411 case SSL3_ST_SR_CLNT_HELLO_D:
412 return "3RCH_D";
413
414 case SSL3_ST_SW_SRVR_HELLO_A:
415 return "3WSH_A";
416
417 case SSL3_ST_SW_SRVR_HELLO_B:
418 return "3WSH_B";
419
420 case SSL3_ST_SW_CERT_A:
421 return "3WSC_A";
422
423 case SSL3_ST_SW_CERT_B:
424 return "3WSC_B";
425
426 case SSL3_ST_SW_KEY_EXCH_A:
427 return "3WSKEA";
428
429 case SSL3_ST_SW_KEY_EXCH_B:
430 return "3WSKEB";
431
432 case SSL3_ST_SW_CERT_REQ_A:
433 return "3WCR_A";
434
435 case SSL3_ST_SW_CERT_REQ_B:
436 return "3WCR_B";
437
438 case SSL3_ST_SW_SRVR_DONE_A:
439 return "3WSD_A";
440
441 case SSL3_ST_SW_SRVR_DONE_B:
442 return "3WSD_B";
443
444 case SSL3_ST_SR_CERT_A:
445 return "3RCC_A";
446
447 case SSL3_ST_SR_CERT_B:
448 return "3RCC_B";
449
450 case SSL3_ST_SR_KEY_EXCH_A:
451 return "3RCKEA";
452
453 case SSL3_ST_SR_KEY_EXCH_B:
454 return "3RCKEB";
455
456 case SSL3_ST_SR_CERT_VRFY_A:
457 return "3RCV_A";
458
459 case SSL3_ST_SR_CERT_VRFY_B:
460 return "3RCV_B";
461
462 /* DTLS */
463 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
464 return "DRCHVA";
465
466 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
467 return "DRCHVB";
468
469 default:
470 return "UNKWN ";
471 }
472 }
473
SSL_alert_type_string_long(int value)474 const char *SSL_alert_type_string_long(int value) {
475 value >>= 8;
476 if (value == SSL3_AL_WARNING) {
477 return "warning";
478 } else if (value == SSL3_AL_FATAL) {
479 return "fatal";
480 }
481
482 return "unknown";
483 }
484
SSL_alert_type_string(int value)485 const char *SSL_alert_type_string(int value) {
486 return "!";
487 }
488
SSL_alert_desc_string(int value)489 const char *SSL_alert_desc_string(int value) {
490 return "!!";
491 }
492
SSL_alert_desc_string_long(int value)493 const char *SSL_alert_desc_string_long(int value) {
494 switch (value & 0xff) {
495 case SSL3_AD_CLOSE_NOTIFY:
496 return "close notify";
497
498 case SSL3_AD_UNEXPECTED_MESSAGE:
499 return "unexpected_message";
500
501 case SSL3_AD_BAD_RECORD_MAC:
502 return "bad record mac";
503
504 case SSL3_AD_DECOMPRESSION_FAILURE:
505 return "decompression failure";
506
507 case SSL3_AD_HANDSHAKE_FAILURE:
508 return "handshake failure";
509
510 case SSL3_AD_NO_CERTIFICATE:
511 return "no certificate";
512
513 case SSL3_AD_BAD_CERTIFICATE:
514 return "bad certificate";
515
516 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
517 return "unsupported certificate";
518
519 case SSL3_AD_CERTIFICATE_REVOKED:
520 return "certificate revoked";
521
522 case SSL3_AD_CERTIFICATE_EXPIRED:
523 return "certificate expired";
524
525 case SSL3_AD_CERTIFICATE_UNKNOWN:
526 return "certificate unknown";
527
528 case SSL3_AD_ILLEGAL_PARAMETER:
529 return "illegal parameter";
530
531 case TLS1_AD_DECRYPTION_FAILED:
532 return "decryption failed";
533
534 case TLS1_AD_RECORD_OVERFLOW:
535 return "record overflow";
536
537 case TLS1_AD_UNKNOWN_CA:
538 return "unknown CA";
539
540 case TLS1_AD_ACCESS_DENIED:
541 return "access denied";
542
543 case TLS1_AD_DECODE_ERROR:
544 return "decode error";
545
546 case TLS1_AD_DECRYPT_ERROR:
547 return "decrypt error";
548
549 case TLS1_AD_EXPORT_RESTRICTION:
550 return "export restriction";
551
552 case TLS1_AD_PROTOCOL_VERSION:
553 return "protocol version";
554
555 case TLS1_AD_INSUFFICIENT_SECURITY:
556 return "insufficient security";
557
558 case TLS1_AD_INTERNAL_ERROR:
559 return "internal error";
560
561 case TLS1_AD_USER_CANCELLED:
562 return "user canceled";
563
564 case TLS1_AD_NO_RENEGOTIATION:
565 return "no renegotiation";
566
567 case TLS1_AD_UNSUPPORTED_EXTENSION:
568 return "unsupported extension";
569
570 case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
571 return "certificate unobtainable";
572
573 case TLS1_AD_UNRECOGNIZED_NAME:
574 return "unrecognized name";
575
576 case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
577 return "bad certificate status response";
578
579 case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
580 return "bad certificate hash value";
581
582 case TLS1_AD_UNKNOWN_PSK_IDENTITY:
583 return "unknown PSK identity";
584
585 case SSL3_AD_INAPPROPRIATE_FALLBACK:
586 return "inappropriate fallback";
587
588 default:
589 return "unknown";
590 }
591 }
592