ssl_stat.c 14.9 KB
Newer Older
1
/* ssl/ssl_stat.c */
2
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 4 5 6 7
 * All rights reserved.
 *
 * This package is an SSL implementation written
 * by Eric Young (eay@cryptsoft.com).
 * The implementation was written so as to conform with Netscapes SSL.
8
 *
9 10 11 12 13 14
 * This library is free for commercial and non-commercial use as long as
 * the following conditions are aheared to.  The following conditions
 * apply to all code found in this distribution, be it the RC4, RSA,
 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
 * included with this distribution is covered by the same copyright terms
 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15
 *
16 17 18 19 20 21
 * Copyright remains Eric Young's, and as such any Copyright notices in
 * the code are not to be removed.
 * If this package is used in a product, Eric Young should be given attribution
 * as the author of the parts of the library used.
 * This can be in the form of a textual message at program startup or
 * in documentation (online or textual) provided with the package.
22
 *
23 24 25 26 27 28 29 30 31 32 33 34 35 36
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *    "This product includes cryptographic software written by
 *     Eric Young (eay@cryptsoft.com)"
 *    The word 'cryptographic' can be left out if the rouines from the library
 *    being used are not cryptographic related :-).
37
 * 4. If you include any Windows specific code (or a derivative thereof) from
38 39
 *    the apps directory (application code) you must include an acknowledgement:
 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40
 *
41 42 43 44 45 46 47 48 49 50 51
 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
52
 *
53 54 55 56 57
 * The licence and distribution terms for any publically available version or
 * derivative of this code cannot be changed.  i.e. this code cannot simply be
 * copied and put under another distribution licence
 * [including the GNU Public Licence.]
 */
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
/* ====================================================================
 * Copyright 2005 Nokia. All rights reserved.
 *
 * The portions of the attached software ("Contribution") is developed by
 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
 * license.
 *
 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
 * support (see RFC 4279) to OpenSSL.
 *
 * No patent licenses or other rights except those expressly stated in
 * the OpenSSL open source license shall be deemed granted or received
 * expressly, by implication, estoppel, or otherwise.
 *
 * No assurances are provided by Nokia that the Contribution does not
 * infringe the patent or other intellectual property rights of any third
 * party or that the license provides you with all the necessary rights
 * to make use of the Contribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
 * OTHERWISE.
 */
84 85 86 87

#include <stdio.h>
#include "ssl_locl.h"

B
Ben Laurie 已提交
88
const char *SSL_state_string_long(const SSL *s)
89 90
{
    const char *str;
91

M
Matt Caswell 已提交
92
    if (ossl_statem_in_error(s)) {
M
Matt Caswell 已提交
93 94 95 96 97
        return "error";
    }

    switch (SSL_state(s)) {
    case TLS_ST_BEFORE:
98 99
        str = "before SSL initialization";
        break;
M
Matt Caswell 已提交
100
    case TLS_ST_OK:
101 102
        str = "SSL negotiation finished successfully";
        break;
103 104

/* SSLv3 additions */
M
Matt Caswell 已提交
105 106
    case TLS_ST_CW_CLNT_HELLO:
        str = "SSLv3/TLS write client hello";
107
        break;
M
Matt Caswell 已提交
108 109
    case TLS_ST_CR_SRVR_HELLO:
        str = "SSLv3/TLS read server hello";
110
        break;
M
Matt Caswell 已提交
111 112
    case TLS_ST_CR_CERT:
        str = "SSLv3/TLS read server certificate";
113
        break;
M
Matt Caswell 已提交
114 115
    case TLS_ST_CR_KEY_EXCH:
        str = "SSLv3/TLS read server key exchange";
116
        break;
M
Matt Caswell 已提交
117 118
    case TLS_ST_CR_CERT_REQ:
        str = "SSLv3/TLS read server certificate request";
119
        break;
M
Matt Caswell 已提交
120 121
    case TLS_ST_CR_SESSION_TICKET:
        str = "SSLv3/TLS read server session ticket";
122
        break;
M
Matt Caswell 已提交
123 124
    case TLS_ST_CR_SRVR_DONE:
        str = "SSLv3/TLS read server done";
125
        break;
M
Matt Caswell 已提交
126 127
    case TLS_ST_CW_CERT:
        str = "SSLv3/TLS write client certificate";
128
        break;
M
Matt Caswell 已提交
129 130
    case TLS_ST_CW_KEY_EXCH:
        str = "SSLv3/TLS write client key exchange";
131
        break;
M
Matt Caswell 已提交
132 133
    case TLS_ST_CW_CERT_VRFY:
        str = "SSLv3/TLS write certificate verify";
134
        break;
135

M
Matt Caswell 已提交
136 137 138
    case TLS_ST_CW_CHANGE:
    case TLS_ST_SW_CHANGE:
        str = "SSLv3/TLS write change cipher spec";
139
        break;
M
Matt Caswell 已提交
140 141 142
    case TLS_ST_CW_FINISHED:
    case TLS_ST_SW_FINISHED:
        str = "SSLv3/TLS write finished";
143
        break;
M
Matt Caswell 已提交
144 145 146
    case TLS_ST_CR_CHANGE:
    case TLS_ST_SR_CHANGE:
        str = "SSLv3/TLS read change cipher spec";
147
        break;
M
Matt Caswell 已提交
148 149 150
    case TLS_ST_CR_FINISHED:
    case TLS_ST_SR_FINISHED:
        str = "SSLv3/TLS read finished";
151
        break;
152

M
Matt Caswell 已提交
153 154
    case TLS_ST_SR_CLNT_HELLO:
        str = "SSLv3/TLS read client hello";
155
        break;
M
Matt Caswell 已提交
156 157
    case TLS_ST_SW_HELLO_REQ:
        str = "SSLv3/TLS write hello request";
158
        break;
M
Matt Caswell 已提交
159 160
    case TLS_ST_SW_SRVR_HELLO:
        str = "SSLv3/TLS write server hello";
161
        break;
M
Matt Caswell 已提交
162 163
    case TLS_ST_SW_CERT:
        str = "SSLv3/TLS write certificate";
164
        break;
M
Matt Caswell 已提交
165 166
    case TLS_ST_SW_KEY_EXCH:
        str = "SSLv3/TLS write key exchange";
167
        break;
M
Matt Caswell 已提交
168 169
    case TLS_ST_SW_CERT_REQ:
        str = "SSLv3/TLS write certificate request";
170
        break;
M
Matt Caswell 已提交
171 172
    case TLS_ST_SW_SESSION_TICKET:
        str = "SSLv3/TLS write session ticket";
173
        break;
M
Matt Caswell 已提交
174 175
    case TLS_ST_SW_SRVR_DONE:
        str = "SSLv3/TLS write server done";
176
        break;
M
Matt Caswell 已提交
177 178
    case TLS_ST_SR_CERT:
        str = "SSLv3/TLS read client certificate";
179
        break;
M
Matt Caswell 已提交
180 181
    case TLS_ST_SR_KEY_EXCH:
        str = "SSLv3/TLS read client key exchange";
182
        break;
M
Matt Caswell 已提交
183 184
    case TLS_ST_SR_CERT_VRFY:
        str = "SSLv3/TLS read certificate verify";
185
        break;
186

D
Dr. Stephen Henson 已提交
187
/* DTLS */
M
Matt Caswell 已提交
188 189
    case DTLS_ST_CR_HELLO_VERIFY_REQUEST:
        str = "DTLS1 read hello verify request";
190
        break;
M
Matt Caswell 已提交
191 192
    case DTLS_ST_SW_HELLO_VERIFY_REQUEST:
        str = "DTLS1 write hello verify request";
193
        break;
D
Dr. Stephen Henson 已提交
194

195 196 197 198 199 200
    default:
        str = "unknown state";
        break;
    }
    return (str);
}
201 202


B
Ben Laurie 已提交
203
const char *SSL_state_string(const SSL *s)
204 205
{
    const char *str;
206

M
Matt Caswell 已提交
207
    if (ossl_statem_in_error(s)) {
M
Matt Caswell 已提交
208 209 210 211 212
        return "SSLERR";
    }

    switch (SSL_state(s)) {
    case TLS_ST_BEFORE:
213 214
        str = "PINIT ";
        break;
M
Matt Caswell 已提交
215
    case TLS_ST_OK:
216 217
        str = "SSLOK ";
        break;
218

M
Matt Caswell 已提交
219 220
    case TLS_ST_CW_CLNT_HELLO:
        str = "3WCH";
221
        break;
M
Matt Caswell 已提交
222 223
    case TLS_ST_CR_SRVR_HELLO:
        str = "3RSH";
224
        break;
M
Matt Caswell 已提交
225 226
    case TLS_ST_CR_CERT:
        str = "3RSC";
227
        break;
M
Matt Caswell 已提交
228 229
    case TLS_ST_CR_KEY_EXCH:
        str = "3RSKE";
230
        break;
M
Matt Caswell 已提交
231 232
    case TLS_ST_CR_CERT_REQ:
        str = "3RCR";
233
        break;
M
Matt Caswell 已提交
234 235
    case TLS_ST_CR_SRVR_DONE:
        str = "3RSD";
236
        break;
M
Matt Caswell 已提交
237 238
    case TLS_ST_CW_CERT:
        str = "3WCC";
239
        break;
M
Matt Caswell 已提交
240 241
    case TLS_ST_CW_KEY_EXCH:
        str = "3WCKE";
242
        break;
M
Matt Caswell 已提交
243 244
    case TLS_ST_CW_CERT_VRFY:
        str = "3WCV";
245
        break;
246

M
Matt Caswell 已提交
247 248 249
    case TLS_ST_SW_CHANGE:
    case TLS_ST_CW_CHANGE:
        str = "3WCCS";
250
        break;
M
Matt Caswell 已提交
251 252 253
    case TLS_ST_SW_FINISHED:
    case TLS_ST_CW_FINISHED:
        str = "3WFIN";
254
        break;
M
Matt Caswell 已提交
255 256 257
    case TLS_ST_SR_CHANGE:
    case TLS_ST_CR_CHANGE:
        str = "3RCCS";
258
        break;
M
Matt Caswell 已提交
259 260 261
    case TLS_ST_SR_FINISHED:
    case TLS_ST_CR_FINISHED:
        str = "3RFIN";
262
        break;
263

M
Matt Caswell 已提交
264 265
    case TLS_ST_SW_HELLO_REQ:
        str = "3WHR";
266
        break;
M
Matt Caswell 已提交
267 268
    case TLS_ST_SR_CLNT_HELLO:
        str = "3RCH";
269
        break;
M
Matt Caswell 已提交
270 271
    case TLS_ST_SW_SRVR_HELLO:
        str = "3WSH";
272
        break;
M
Matt Caswell 已提交
273 274
    case TLS_ST_SW_CERT:
        str = "3WSC";
275
        break;
M
Matt Caswell 已提交
276 277
    case TLS_ST_SW_KEY_EXCH:
        str = "3WSKE";
278
        break;
M
Matt Caswell 已提交
279 280
    case TLS_ST_SW_CERT_REQ:
        str = "3WCR";
281
        break;
M
Matt Caswell 已提交
282 283
    case TLS_ST_SW_SRVR_DONE:
        str = "3WSD";
284
        break;
M
Matt Caswell 已提交
285 286
    case TLS_ST_SR_CERT:
        str = "3RCC";
287
        break;
M
Matt Caswell 已提交
288 289
    case TLS_ST_SR_KEY_EXCH:
        str = "3RCKE";
290
        break;
M
Matt Caswell 已提交
291 292
    case TLS_ST_SR_CERT_VRFY:
        str = "3RCV";
293
        break;
294

D
Dr. Stephen Henson 已提交
295
/* DTLS */
M
Matt Caswell 已提交
296 297
    case DTLS_ST_CR_HELLO_VERIFY_REQUEST:
        str = "DRCHV";
298
        break;
M
Matt Caswell 已提交
299 300
    case DTLS_ST_SW_HELLO_VERIFY_REQUEST:
        str = "DWCHV";
301
        break;
302

303 304 305 306 307 308
    default:
        str = "UNKWN ";
        break;
    }
    return (str);
}
309

L
Lutz Jänicke 已提交
310
const char *SSL_alert_type_string_long(int value)
311 312 313 314 315 316 317 318 319
{
    value >>= 8;
    if (value == SSL3_AL_WARNING)
        return ("warning");
    else if (value == SSL3_AL_FATAL)
        return ("fatal");
    else
        return ("unknown");
}
320

L
Lutz Jänicke 已提交
321
const char *SSL_alert_type_string(int value)
322 323 324 325 326 327 328 329 330
{
    value >>= 8;
    if (value == SSL3_AL_WARNING)
        return ("W");
    else if (value == SSL3_AL_FATAL)
        return ("F");
    else
        return ("U");
}
331

L
Lutz Jänicke 已提交
332
const char *SSL_alert_desc_string(int value)
333 334
{
    const char *str;
335

336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    switch (value & 0xff) {
    case SSL3_AD_CLOSE_NOTIFY:
        str = "CN";
        break;
    case SSL3_AD_UNEXPECTED_MESSAGE:
        str = "UM";
        break;
    case SSL3_AD_BAD_RECORD_MAC:
        str = "BM";
        break;
    case SSL3_AD_DECOMPRESSION_FAILURE:
        str = "DF";
        break;
    case SSL3_AD_HANDSHAKE_FAILURE:
        str = "HF";
        break;
    case SSL3_AD_NO_CERTIFICATE:
        str = "NC";
        break;
    case SSL3_AD_BAD_CERTIFICATE:
        str = "BC";
        break;
    case SSL3_AD_UNSUPPORTED_CERTIFICATE:
        str = "UC";
        break;
    case SSL3_AD_CERTIFICATE_REVOKED:
        str = "CR";
        break;
    case SSL3_AD_CERTIFICATE_EXPIRED:
        str = "CE";
        break;
    case SSL3_AD_CERTIFICATE_UNKNOWN:
        str = "CU";
        break;
    case SSL3_AD_ILLEGAL_PARAMETER:
        str = "IP";
        break;
    case TLS1_AD_DECRYPTION_FAILED:
        str = "DC";
        break;
    case TLS1_AD_RECORD_OVERFLOW:
        str = "RO";
        break;
    case TLS1_AD_UNKNOWN_CA:
        str = "CA";
        break;
    case TLS1_AD_ACCESS_DENIED:
        str = "AD";
        break;
    case TLS1_AD_DECODE_ERROR:
        str = "DE";
        break;
    case TLS1_AD_DECRYPT_ERROR:
        str = "CY";
        break;
    case TLS1_AD_EXPORT_RESTRICTION:
        str = "ER";
        break;
    case TLS1_AD_PROTOCOL_VERSION:
        str = "PV";
        break;
    case TLS1_AD_INSUFFICIENT_SECURITY:
        str = "IS";
        break;
    case TLS1_AD_INTERNAL_ERROR:
        str = "IE";
        break;
    case TLS1_AD_USER_CANCELLED:
        str = "US";
        break;
    case TLS1_AD_NO_RENEGOTIATION:
        str = "NR";
        break;
    case TLS1_AD_UNSUPPORTED_EXTENSION:
        str = "UE";
        break;
    case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
        str = "CO";
        break;
    case TLS1_AD_UNRECOGNIZED_NAME:
        str = "UN";
        break;
    case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
        str = "BR";
        break;
    case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
        str = "BH";
        break;
    case TLS1_AD_UNKNOWN_PSK_IDENTITY:
        str = "UP";
        break;
    default:
        str = "UK";
        break;
    }
    return (str);
}
433

L
Lutz Jänicke 已提交
434
const char *SSL_alert_desc_string_long(int value)
435 436
{
    const char *str;
437

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
    switch (value & 0xff) {
    case SSL3_AD_CLOSE_NOTIFY:
        str = "close notify";
        break;
    case SSL3_AD_UNEXPECTED_MESSAGE:
        str = "unexpected_message";
        break;
    case SSL3_AD_BAD_RECORD_MAC:
        str = "bad record mac";
        break;
    case SSL3_AD_DECOMPRESSION_FAILURE:
        str = "decompression failure";
        break;
    case SSL3_AD_HANDSHAKE_FAILURE:
        str = "handshake failure";
        break;
    case SSL3_AD_NO_CERTIFICATE:
        str = "no certificate";
        break;
    case SSL3_AD_BAD_CERTIFICATE:
        str = "bad certificate";
        break;
    case SSL3_AD_UNSUPPORTED_CERTIFICATE:
        str = "unsupported certificate";
        break;
    case SSL3_AD_CERTIFICATE_REVOKED:
        str = "certificate revoked";
        break;
    case SSL3_AD_CERTIFICATE_EXPIRED:
        str = "certificate expired";
        break;
    case SSL3_AD_CERTIFICATE_UNKNOWN:
        str = "certificate unknown";
        break;
    case SSL3_AD_ILLEGAL_PARAMETER:
        str = "illegal parameter";
        break;
    case TLS1_AD_DECRYPTION_FAILED:
        str = "decryption failed";
        break;
    case TLS1_AD_RECORD_OVERFLOW:
        str = "record overflow";
        break;
    case TLS1_AD_UNKNOWN_CA:
        str = "unknown CA";
        break;
    case TLS1_AD_ACCESS_DENIED:
        str = "access denied";
        break;
    case TLS1_AD_DECODE_ERROR:
        str = "decode error";
        break;
    case TLS1_AD_DECRYPT_ERROR:
        str = "decrypt error";
        break;
    case TLS1_AD_EXPORT_RESTRICTION:
        str = "export restriction";
        break;
    case TLS1_AD_PROTOCOL_VERSION:
        str = "protocol version";
        break;
    case TLS1_AD_INSUFFICIENT_SECURITY:
        str = "insufficient security";
        break;
    case TLS1_AD_INTERNAL_ERROR:
        str = "internal error";
        break;
    case TLS1_AD_USER_CANCELLED:
        str = "user canceled";
        break;
    case TLS1_AD_NO_RENEGOTIATION:
        str = "no renegotiation";
        break;
    case TLS1_AD_UNSUPPORTED_EXTENSION:
        str = "unsupported extension";
        break;
    case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
        str = "certificate unobtainable";
        break;
    case TLS1_AD_UNRECOGNIZED_NAME:
        str = "unrecognized name";
        break;
    case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
        str = "bad certificate status response";
        break;
    case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
        str = "bad certificate hash value";
        break;
    case TLS1_AD_UNKNOWN_PSK_IDENTITY:
        str = "unknown PSK identity";
        break;
    default:
        str = "unknown";
        break;
    }
    return (str);
}