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 <assert.h>
87
88 #include "internal.h"
89
90
ssl_state(const SSL * ssl)91 static int ssl_state(const SSL *ssl) {
92 if (ssl->s3->hs == NULL) {
93 assert(ssl->s3->initial_handshake_complete);
94 return SSL_ST_OK;
95 }
96
97 return ssl->s3->hs->state;
98 }
99
SSL_state_string_long(const SSL * ssl)100 const char *SSL_state_string_long(const SSL *ssl) {
101 switch (ssl_state(ssl)) {
102 case SSL_ST_ACCEPT:
103 return "before accept initialization";
104
105 case SSL_ST_CONNECT:
106 return "before connect initialization";
107
108 case SSL_ST_OK:
109 return "SSL negotiation finished successfully";
110
111 case SSL_ST_RENEGOTIATE:
112 return "SSL renegotiate ciphers";
113
114 /* SSLv3 additions */
115 case SSL3_ST_CW_CLNT_HELLO_A:
116 return "SSLv3 write client hello A";
117
118 case SSL3_ST_CR_SRVR_HELLO_A:
119 return "SSLv3 read server hello A";
120
121 case SSL3_ST_CR_CERT_A:
122 return "SSLv3 read server certificate A";
123
124 case SSL3_ST_CR_KEY_EXCH_A:
125 return "SSLv3 read server key exchange A";
126
127 case SSL3_ST_CR_CERT_REQ_A:
128 return "SSLv3 read server certificate request A";
129
130 case SSL3_ST_CR_SESSION_TICKET_A:
131 return "SSLv3 read server session ticket A";
132
133 case SSL3_ST_CR_SRVR_DONE_A:
134 return "SSLv3 read server done A";
135
136 case SSL3_ST_CW_CERT_A:
137 return "SSLv3 write client certificate A";
138
139 case SSL3_ST_CW_KEY_EXCH_A:
140 return "SSLv3 write client key exchange A";
141
142 case SSL3_ST_CW_CERT_VRFY_A:
143 return "SSLv3 write certificate verify A";
144
145 case SSL3_ST_CW_CERT_VRFY_B:
146 return "SSLv3 write certificate verify B";
147
148 case SSL3_ST_CW_CHANGE:
149 case SSL3_ST_SW_CHANGE:
150 return "SSLv3 write change cipher spec";
151
152 case SSL3_ST_CW_FINISHED_A:
153 case SSL3_ST_SW_FINISHED_A:
154 return "SSLv3 write finished A";
155
156 case SSL3_ST_CR_CHANGE:
157 case SSL3_ST_SR_CHANGE:
158 return "SSLv3 read change cipher spec";
159
160 case SSL3_ST_CR_FINISHED_A:
161 case SSL3_ST_SR_FINISHED_A:
162 return "SSLv3 read finished A";
163
164 case SSL3_ST_CW_FLUSH:
165 case SSL3_ST_SW_FLUSH:
166 return "SSLv3 flush data";
167
168 case SSL3_ST_SR_CLNT_HELLO_A:
169 return "SSLv3 read client hello A";
170
171 case SSL3_ST_SR_CLNT_HELLO_B:
172 return "SSLv3 read client hello B";
173
174 case SSL3_ST_SR_CLNT_HELLO_C:
175 return "SSLv3 read client hello C";
176
177 case SSL3_ST_SW_SRVR_HELLO_A:
178 return "SSLv3 write server hello A";
179
180 case SSL3_ST_SW_CERT_A:
181 return "SSLv3 write certificate A";
182
183 case SSL3_ST_SW_KEY_EXCH_A:
184 return "SSLv3 write key exchange A";
185
186 case SSL3_ST_SW_CERT_REQ_A:
187 return "SSLv3 write certificate request A";
188
189 case SSL3_ST_SW_SESSION_TICKET_A:
190 return "SSLv3 write session ticket A";
191
192 case SSL3_ST_SW_SRVR_DONE_A:
193 return "SSLv3 write server done A";
194
195 case SSL3_ST_SR_CERT_A:
196 return "SSLv3 read client certificate A";
197
198 case SSL3_ST_SR_KEY_EXCH_A:
199 return "SSLv3 read client key exchange A";
200
201 case SSL3_ST_SR_KEY_EXCH_B:
202 return "SSLv3 read client key exchange B";
203
204 case SSL3_ST_SR_CERT_VRFY_A:
205 return "SSLv3 read certificate verify A";
206
207 /* DTLS */
208 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
209 return "DTLS1 read hello verify request A";
210
211 default:
212 return "unknown state";
213 }
214 }
215
SSL_state_string(const SSL * ssl)216 const char *SSL_state_string(const SSL *ssl) {
217 switch (ssl_state(ssl)) {
218 case SSL_ST_ACCEPT:
219 return "AINIT ";
220
221 case SSL_ST_CONNECT:
222 return "CINIT ";
223
224 case SSL_ST_OK:
225 return "SSLOK ";
226
227 /* SSLv3 additions */
228 case SSL3_ST_SW_FLUSH:
229 case SSL3_ST_CW_FLUSH:
230 return "3FLUSH";
231
232 case SSL3_ST_CW_CLNT_HELLO_A:
233 return "3WCH_A";
234
235 case SSL3_ST_CR_SRVR_HELLO_A:
236 return "3RSH_A";
237
238 case SSL3_ST_CR_CERT_A:
239 return "3RSC_A";
240
241 case SSL3_ST_CR_KEY_EXCH_A:
242 return "3RSKEA";
243
244 case SSL3_ST_CR_CERT_REQ_A:
245 return "3RCR_A";
246
247 case SSL3_ST_CR_SRVR_DONE_A:
248 return "3RSD_A";
249
250 case SSL3_ST_CW_CERT_A:
251 return "3WCC_A";
252
253 case SSL3_ST_CW_KEY_EXCH_A:
254 return "3WCKEA";
255
256 case SSL3_ST_CW_CERT_VRFY_A:
257 return "3WCV_A";
258
259 case SSL3_ST_CW_CERT_VRFY_B:
260 return "3WCV_B";
261
262 case SSL3_ST_SW_CHANGE:
263 case SSL3_ST_CW_CHANGE:
264 return "3WCCS_";
265
266 case SSL3_ST_SW_FINISHED_A:
267 case SSL3_ST_CW_FINISHED_A:
268 return "3WFINA";
269
270 case SSL3_ST_CR_CHANGE:
271 case SSL3_ST_SR_CHANGE:
272 return "3RCCS_";
273
274 case SSL3_ST_SR_FINISHED_A:
275 case SSL3_ST_CR_FINISHED_A:
276 return "3RFINA";
277
278 case SSL3_ST_SR_CLNT_HELLO_A:
279 return "3RCH_A";
280
281 case SSL3_ST_SR_CLNT_HELLO_B:
282 return "3RCH_B";
283
284 case SSL3_ST_SR_CLNT_HELLO_C:
285 return "3RCH_C";
286
287 case SSL3_ST_SW_SRVR_HELLO_A:
288 return "3WSH_A";
289
290 case SSL3_ST_SW_CERT_A:
291 return "3WSC_A";
292
293 case SSL3_ST_SW_KEY_EXCH_A:
294 return "3WSKEA";
295
296 case SSL3_ST_SW_KEY_EXCH_B:
297 return "3WSKEB";
298
299 case SSL3_ST_SW_CERT_REQ_A:
300 return "3WCR_A";
301
302 case SSL3_ST_SW_SRVR_DONE_A:
303 return "3WSD_A";
304
305 case SSL3_ST_SR_CERT_A:
306 return "3RCC_A";
307
308 case SSL3_ST_SR_KEY_EXCH_A:
309 return "3RCKEA";
310
311 case SSL3_ST_SR_CERT_VRFY_A:
312 return "3RCV_A";
313
314 /* DTLS */
315 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
316 return "DRCHVA";
317
318 default:
319 return "UNKWN ";
320 }
321 }
322
SSL_alert_type_string_long(int value)323 const char *SSL_alert_type_string_long(int value) {
324 value >>= 8;
325 if (value == SSL3_AL_WARNING) {
326 return "warning";
327 } else if (value == SSL3_AL_FATAL) {
328 return "fatal";
329 }
330
331 return "unknown";
332 }
333
SSL_alert_type_string(int value)334 const char *SSL_alert_type_string(int value) {
335 return "!";
336 }
337
SSL_alert_desc_string(int value)338 const char *SSL_alert_desc_string(int value) {
339 return "!!";
340 }
341
SSL_alert_desc_string_long(int value)342 const char *SSL_alert_desc_string_long(int value) {
343 switch (value & 0xff) {
344 case SSL3_AD_CLOSE_NOTIFY:
345 return "close notify";
346
347 case SSL3_AD_UNEXPECTED_MESSAGE:
348 return "unexpected_message";
349
350 case SSL3_AD_BAD_RECORD_MAC:
351 return "bad record mac";
352
353 case SSL3_AD_DECOMPRESSION_FAILURE:
354 return "decompression failure";
355
356 case SSL3_AD_HANDSHAKE_FAILURE:
357 return "handshake failure";
358
359 case SSL3_AD_NO_CERTIFICATE:
360 return "no certificate";
361
362 case SSL3_AD_BAD_CERTIFICATE:
363 return "bad certificate";
364
365 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
366 return "unsupported certificate";
367
368 case SSL3_AD_CERTIFICATE_REVOKED:
369 return "certificate revoked";
370
371 case SSL3_AD_CERTIFICATE_EXPIRED:
372 return "certificate expired";
373
374 case SSL3_AD_CERTIFICATE_UNKNOWN:
375 return "certificate unknown";
376
377 case SSL3_AD_ILLEGAL_PARAMETER:
378 return "illegal parameter";
379
380 case TLS1_AD_DECRYPTION_FAILED:
381 return "decryption failed";
382
383 case TLS1_AD_RECORD_OVERFLOW:
384 return "record overflow";
385
386 case TLS1_AD_UNKNOWN_CA:
387 return "unknown CA";
388
389 case TLS1_AD_ACCESS_DENIED:
390 return "access denied";
391
392 case TLS1_AD_DECODE_ERROR:
393 return "decode error";
394
395 case TLS1_AD_DECRYPT_ERROR:
396 return "decrypt error";
397
398 case TLS1_AD_EXPORT_RESTRICTION:
399 return "export restriction";
400
401 case TLS1_AD_PROTOCOL_VERSION:
402 return "protocol version";
403
404 case TLS1_AD_INSUFFICIENT_SECURITY:
405 return "insufficient security";
406
407 case TLS1_AD_INTERNAL_ERROR:
408 return "internal error";
409
410 case SSL3_AD_INAPPROPRIATE_FALLBACK:
411 return "inappropriate fallback";
412
413 case TLS1_AD_USER_CANCELLED:
414 return "user canceled";
415
416 case TLS1_AD_NO_RENEGOTIATION:
417 return "no renegotiation";
418
419 case TLS1_AD_UNSUPPORTED_EXTENSION:
420 return "unsupported extension";
421
422 case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
423 return "certificate unobtainable";
424
425 case TLS1_AD_UNRECOGNIZED_NAME:
426 return "unrecognized name";
427
428 case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
429 return "bad certificate status response";
430
431 case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
432 return "bad certificate hash value";
433
434 case TLS1_AD_UNKNOWN_PSK_IDENTITY:
435 return "unknown PSK identity";
436
437 case TLS1_AD_CERTIFICATE_REQUIRED:
438 return "certificate required";
439
440 default:
441 return "unknown";
442 }
443 }
444