ssl_stat.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /* ssl/ssl_stat.c */
  2. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young (eay@cryptsoft.com).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young (eay@cryptsoft.com)"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. /* ====================================================================
  59. * Copyright 2005 Nokia. All rights reserved.
  60. *
  61. * The portions of the attached software ("Contribution") is developed by
  62. * Nokia Corporation and is licensed pursuant to the OpenSSL open source
  63. * license.
  64. *
  65. * The Contribution, originally written by Mika Kousa and Pasi Eronen of
  66. * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
  67. * support (see RFC 4279) to OpenSSL.
  68. *
  69. * No patent licenses or other rights except those expressly stated in
  70. * the OpenSSL open source license shall be deemed granted or received
  71. * expressly, by implication, estoppel, or otherwise.
  72. *
  73. * No assurances are provided by Nokia that the Contribution does not
  74. * infringe the patent or other intellectual property rights of any third
  75. * party or that the license provides you with all the necessary rights
  76. * to make use of the Contribution.
  77. *
  78. * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
  79. * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
  80. * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
  81. * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
  82. * OTHERWISE.
  83. */
  84. #include <stdio.h>
  85. #include "ssl_locl.h"
  86. const char *SSL_state_string_long(const SSL *s)
  87. {
  88. const char *str;
  89. switch (s->state) {
  90. case SSL_ST_BEFORE:
  91. str = "before SSL initialization";
  92. break;
  93. case SSL_ST_ACCEPT:
  94. str = "before accept initialization";
  95. break;
  96. case SSL_ST_CONNECT:
  97. str = "before connect initialization";
  98. break;
  99. case SSL_ST_OK:
  100. str = "SSL negotiation finished successfully";
  101. break;
  102. case SSL_ST_RENEGOTIATE:
  103. str = "SSL renegotiate ciphers";
  104. break;
  105. case SSL_ST_BEFORE | SSL_ST_CONNECT:
  106. str = "before/connect initialization";
  107. break;
  108. case SSL_ST_OK | SSL_ST_CONNECT:
  109. str = "ok/connect SSL initialization";
  110. break;
  111. case SSL_ST_BEFORE | SSL_ST_ACCEPT:
  112. str = "before/accept initialization";
  113. break;
  114. case SSL_ST_OK | SSL_ST_ACCEPT:
  115. str = "ok/accept SSL initialization";
  116. break;
  117. case SSL_ST_ERR:
  118. str = "error";
  119. break;
  120. #ifndef OPENSSL_NO_SSL2
  121. case SSL2_ST_CLIENT_START_ENCRYPTION:
  122. str = "SSLv2 client start encryption";
  123. break;
  124. case SSL2_ST_SERVER_START_ENCRYPTION:
  125. str = "SSLv2 server start encryption";
  126. break;
  127. case SSL2_ST_SEND_CLIENT_HELLO_A:
  128. str = "SSLv2 write client hello A";
  129. break;
  130. case SSL2_ST_SEND_CLIENT_HELLO_B:
  131. str = "SSLv2 write client hello B";
  132. break;
  133. case SSL2_ST_GET_SERVER_HELLO_A:
  134. str = "SSLv2 read server hello A";
  135. break;
  136. case SSL2_ST_GET_SERVER_HELLO_B:
  137. str = "SSLv2 read server hello B";
  138. break;
  139. case SSL2_ST_SEND_CLIENT_MASTER_KEY_A:
  140. str = "SSLv2 write client master key A";
  141. break;
  142. case SSL2_ST_SEND_CLIENT_MASTER_KEY_B:
  143. str = "SSLv2 write client master key B";
  144. break;
  145. case SSL2_ST_SEND_CLIENT_FINISHED_A:
  146. str = "SSLv2 write client finished A";
  147. break;
  148. case SSL2_ST_SEND_CLIENT_FINISHED_B:
  149. str = "SSLv2 write client finished B";
  150. break;
  151. case SSL2_ST_SEND_CLIENT_CERTIFICATE_A:
  152. str = "SSLv2 write client certificate A";
  153. break;
  154. case SSL2_ST_SEND_CLIENT_CERTIFICATE_B:
  155. str = "SSLv2 write client certificate B";
  156. break;
  157. case SSL2_ST_SEND_CLIENT_CERTIFICATE_C:
  158. str = "SSLv2 write client certificate C";
  159. break;
  160. case SSL2_ST_SEND_CLIENT_CERTIFICATE_D:
  161. str = "SSLv2 write client certificate D";
  162. break;
  163. case SSL2_ST_GET_SERVER_VERIFY_A:
  164. str = "SSLv2 read server verify A";
  165. break;
  166. case SSL2_ST_GET_SERVER_VERIFY_B:
  167. str = "SSLv2 read server verify B";
  168. break;
  169. case SSL2_ST_GET_SERVER_FINISHED_A:
  170. str = "SSLv2 read server finished A";
  171. break;
  172. case SSL2_ST_GET_SERVER_FINISHED_B:
  173. str = "SSLv2 read server finished B";
  174. break;
  175. case SSL2_ST_GET_CLIENT_HELLO_A:
  176. str = "SSLv2 read client hello A";
  177. break;
  178. case SSL2_ST_GET_CLIENT_HELLO_B:
  179. str = "SSLv2 read client hello B";
  180. break;
  181. case SSL2_ST_GET_CLIENT_HELLO_C:
  182. str = "SSLv2 read client hello C";
  183. break;
  184. case SSL2_ST_SEND_SERVER_HELLO_A:
  185. str = "SSLv2 write server hello A";
  186. break;
  187. case SSL2_ST_SEND_SERVER_HELLO_B:
  188. str = "SSLv2 write server hello B";
  189. break;
  190. case SSL2_ST_GET_CLIENT_MASTER_KEY_A:
  191. str = "SSLv2 read client master key A";
  192. break;
  193. case SSL2_ST_GET_CLIENT_MASTER_KEY_B:
  194. str = "SSLv2 read client master key B";
  195. break;
  196. case SSL2_ST_SEND_SERVER_VERIFY_A:
  197. str = "SSLv2 write server verify A";
  198. break;
  199. case SSL2_ST_SEND_SERVER_VERIFY_B:
  200. str = "SSLv2 write server verify B";
  201. break;
  202. case SSL2_ST_SEND_SERVER_VERIFY_C:
  203. str = "SSLv2 write server verify C";
  204. break;
  205. case SSL2_ST_GET_CLIENT_FINISHED_A:
  206. str = "SSLv2 read client finished A";
  207. break;
  208. case SSL2_ST_GET_CLIENT_FINISHED_B:
  209. str = "SSLv2 read client finished B";
  210. break;
  211. case SSL2_ST_SEND_SERVER_FINISHED_A:
  212. str = "SSLv2 write server finished A";
  213. break;
  214. case SSL2_ST_SEND_SERVER_FINISHED_B:
  215. str = "SSLv2 write server finished B";
  216. break;
  217. case SSL2_ST_SEND_REQUEST_CERTIFICATE_A:
  218. str = "SSLv2 write request certificate A";
  219. break;
  220. case SSL2_ST_SEND_REQUEST_CERTIFICATE_B:
  221. str = "SSLv2 write request certificate B";
  222. break;
  223. case SSL2_ST_SEND_REQUEST_CERTIFICATE_C:
  224. str = "SSLv2 write request certificate C";
  225. break;
  226. case SSL2_ST_SEND_REQUEST_CERTIFICATE_D:
  227. str = "SSLv2 write request certificate D";
  228. break;
  229. case SSL2_ST_X509_GET_SERVER_CERTIFICATE:
  230. str = "SSLv2 X509 read server certificate";
  231. break;
  232. case SSL2_ST_X509_GET_CLIENT_CERTIFICATE:
  233. str = "SSLv2 X509 read client certificate";
  234. break;
  235. #endif
  236. #ifndef OPENSSL_NO_SSL3
  237. /* SSLv3 additions */
  238. case SSL3_ST_CW_CLNT_HELLO_A:
  239. str = "SSLv3 write client hello A";
  240. break;
  241. case SSL3_ST_CW_CLNT_HELLO_B:
  242. str = "SSLv3 write client hello B";
  243. break;
  244. case SSL3_ST_CR_SRVR_HELLO_A:
  245. str = "SSLv3 read server hello A";
  246. break;
  247. case SSL3_ST_CR_SRVR_HELLO_B:
  248. str = "SSLv3 read server hello B";
  249. break;
  250. case SSL3_ST_CR_CERT_A:
  251. str = "SSLv3 read server certificate A";
  252. break;
  253. case SSL3_ST_CR_CERT_B:
  254. str = "SSLv3 read server certificate B";
  255. break;
  256. case SSL3_ST_CR_KEY_EXCH_A:
  257. str = "SSLv3 read server key exchange A";
  258. break;
  259. case SSL3_ST_CR_KEY_EXCH_B:
  260. str = "SSLv3 read server key exchange B";
  261. break;
  262. case SSL3_ST_CR_CERT_REQ_A:
  263. str = "SSLv3 read server certificate request A";
  264. break;
  265. case SSL3_ST_CR_CERT_REQ_B:
  266. str = "SSLv3 read server certificate request B";
  267. break;
  268. case SSL3_ST_CR_SESSION_TICKET_A:
  269. str = "SSLv3 read server session ticket A";
  270. break;
  271. case SSL3_ST_CR_SESSION_TICKET_B:
  272. str = "SSLv3 read server session ticket B";
  273. break;
  274. case SSL3_ST_CR_SRVR_DONE_A:
  275. str = "SSLv3 read server done A";
  276. break;
  277. case SSL3_ST_CR_SRVR_DONE_B:
  278. str = "SSLv3 read server done B";
  279. break;
  280. case SSL3_ST_CW_CERT_A:
  281. str = "SSLv3 write client certificate A";
  282. break;
  283. case SSL3_ST_CW_CERT_B:
  284. str = "SSLv3 write client certificate B";
  285. break;
  286. case SSL3_ST_CW_CERT_C:
  287. str = "SSLv3 write client certificate C";
  288. break;
  289. case SSL3_ST_CW_CERT_D:
  290. str = "SSLv3 write client certificate D";
  291. break;
  292. case SSL3_ST_CW_KEY_EXCH_A:
  293. str = "SSLv3 write client key exchange A";
  294. break;
  295. case SSL3_ST_CW_KEY_EXCH_B:
  296. str = "SSLv3 write client key exchange B";
  297. break;
  298. case SSL3_ST_CW_CERT_VRFY_A:
  299. str = "SSLv3 write certificate verify A";
  300. break;
  301. case SSL3_ST_CW_CERT_VRFY_B:
  302. str = "SSLv3 write certificate verify B";
  303. break;
  304. case SSL3_ST_CW_CHANGE_A:
  305. case SSL3_ST_SW_CHANGE_A:
  306. str = "SSLv3 write change cipher spec A";
  307. break;
  308. case SSL3_ST_CW_CHANGE_B:
  309. case SSL3_ST_SW_CHANGE_B:
  310. str = "SSLv3 write change cipher spec B";
  311. break;
  312. case SSL3_ST_CW_FINISHED_A:
  313. case SSL3_ST_SW_FINISHED_A:
  314. str = "SSLv3 write finished A";
  315. break;
  316. case SSL3_ST_CW_FINISHED_B:
  317. case SSL3_ST_SW_FINISHED_B:
  318. str = "SSLv3 write finished B";
  319. break;
  320. case SSL3_ST_CR_CHANGE_A:
  321. case SSL3_ST_SR_CHANGE_A:
  322. str = "SSLv3 read change cipher spec A";
  323. break;
  324. case SSL3_ST_CR_CHANGE_B:
  325. case SSL3_ST_SR_CHANGE_B:
  326. str = "SSLv3 read change cipher spec B";
  327. break;
  328. case SSL3_ST_CR_FINISHED_A:
  329. case SSL3_ST_SR_FINISHED_A:
  330. str = "SSLv3 read finished A";
  331. break;
  332. case SSL3_ST_CR_FINISHED_B:
  333. case SSL3_ST_SR_FINISHED_B:
  334. str = "SSLv3 read finished B";
  335. break;
  336. case SSL3_ST_CW_FLUSH:
  337. case SSL3_ST_SW_FLUSH:
  338. str = "SSLv3 flush data";
  339. break;
  340. case SSL3_ST_SR_CLNT_HELLO_A:
  341. str = "SSLv3 read client hello A";
  342. break;
  343. case SSL3_ST_SR_CLNT_HELLO_B:
  344. str = "SSLv3 read client hello B";
  345. break;
  346. case SSL3_ST_SR_CLNT_HELLO_C:
  347. str = "SSLv3 read client hello C";
  348. break;
  349. case SSL3_ST_SW_HELLO_REQ_A:
  350. str = "SSLv3 write hello request A";
  351. break;
  352. case SSL3_ST_SW_HELLO_REQ_B:
  353. str = "SSLv3 write hello request B";
  354. break;
  355. case SSL3_ST_SW_HELLO_REQ_C:
  356. str = "SSLv3 write hello request C";
  357. break;
  358. case SSL3_ST_SW_SRVR_HELLO_A:
  359. str = "SSLv3 write server hello A";
  360. break;
  361. case SSL3_ST_SW_SRVR_HELLO_B:
  362. str = "SSLv3 write server hello B";
  363. break;
  364. case SSL3_ST_SW_CERT_A:
  365. str = "SSLv3 write certificate A";
  366. break;
  367. case SSL3_ST_SW_CERT_B:
  368. str = "SSLv3 write certificate B";
  369. break;
  370. case SSL3_ST_SW_KEY_EXCH_A:
  371. str = "SSLv3 write key exchange A";
  372. break;
  373. case SSL3_ST_SW_KEY_EXCH_B:
  374. str = "SSLv3 write key exchange B";
  375. break;
  376. case SSL3_ST_SW_CERT_REQ_A:
  377. str = "SSLv3 write certificate request A";
  378. break;
  379. case SSL3_ST_SW_CERT_REQ_B:
  380. str = "SSLv3 write certificate request B";
  381. break;
  382. case SSL3_ST_SW_SESSION_TICKET_A:
  383. str = "SSLv3 write session ticket A";
  384. break;
  385. case SSL3_ST_SW_SESSION_TICKET_B:
  386. str = "SSLv3 write session ticket B";
  387. break;
  388. case SSL3_ST_SW_SRVR_DONE_A:
  389. str = "SSLv3 write server done A";
  390. break;
  391. case SSL3_ST_SW_SRVR_DONE_B:
  392. str = "SSLv3 write server done B";
  393. break;
  394. case SSL3_ST_SR_CERT_A:
  395. str = "SSLv3 read client certificate A";
  396. break;
  397. case SSL3_ST_SR_CERT_B:
  398. str = "SSLv3 read client certificate B";
  399. break;
  400. case SSL3_ST_SR_KEY_EXCH_A:
  401. str = "SSLv3 read client key exchange A";
  402. break;
  403. case SSL3_ST_SR_KEY_EXCH_B:
  404. str = "SSLv3 read client key exchange B";
  405. break;
  406. case SSL3_ST_SR_CERT_VRFY_A:
  407. str = "SSLv3 read certificate verify A";
  408. break;
  409. case SSL3_ST_SR_CERT_VRFY_B:
  410. str = "SSLv3 read certificate verify B";
  411. break;
  412. #endif
  413. /* SSLv2/v3 compatibility states */
  414. /* client */
  415. case SSL23_ST_CW_CLNT_HELLO_A:
  416. str = "SSLv2/v3 write client hello A";
  417. break;
  418. case SSL23_ST_CW_CLNT_HELLO_B:
  419. str = "SSLv2/v3 write client hello B";
  420. break;
  421. case SSL23_ST_CR_SRVR_HELLO_A:
  422. str = "SSLv2/v3 read server hello A";
  423. break;
  424. case SSL23_ST_CR_SRVR_HELLO_B:
  425. str = "SSLv2/v3 read server hello B";
  426. break;
  427. /* server */
  428. case SSL23_ST_SR_CLNT_HELLO_A:
  429. str = "SSLv2/v3 read client hello A";
  430. break;
  431. case SSL23_ST_SR_CLNT_HELLO_B:
  432. str = "SSLv2/v3 read client hello B";
  433. break;
  434. /* DTLS */
  435. case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
  436. str = "DTLS1 read hello verify request A";
  437. break;
  438. case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
  439. str = "DTLS1 read hello verify request B";
  440. break;
  441. case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
  442. str = "DTLS1 write hello verify request A";
  443. break;
  444. case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
  445. str = "DTLS1 write hello verify request B";
  446. break;
  447. default:
  448. str = "unknown state";
  449. break;
  450. }
  451. return (str);
  452. }
  453. const char *SSL_rstate_string_long(const SSL *s)
  454. {
  455. const char *str;
  456. switch (s->rstate) {
  457. case SSL_ST_READ_HEADER:
  458. str = "read header";
  459. break;
  460. case SSL_ST_READ_BODY:
  461. str = "read body";
  462. break;
  463. case SSL_ST_READ_DONE:
  464. str = "read done";
  465. break;
  466. default:
  467. str = "unknown";
  468. break;
  469. }
  470. return (str);
  471. }
  472. const char *SSL_state_string(const SSL *s)
  473. {
  474. const char *str;
  475. switch (s->state) {
  476. case SSL_ST_BEFORE:
  477. str = "PINIT ";
  478. break;
  479. case SSL_ST_ACCEPT:
  480. str = "AINIT ";
  481. break;
  482. case SSL_ST_CONNECT:
  483. str = "CINIT ";
  484. break;
  485. case SSL_ST_OK:
  486. str = "SSLOK ";
  487. break;
  488. case SSL_ST_ERR:
  489. str = "SSLERR";
  490. break;
  491. #ifndef OPENSSL_NO_SSL2
  492. case SSL2_ST_CLIENT_START_ENCRYPTION:
  493. str = "2CSENC";
  494. break;
  495. case SSL2_ST_SERVER_START_ENCRYPTION:
  496. str = "2SSENC";
  497. break;
  498. case SSL2_ST_SEND_CLIENT_HELLO_A:
  499. str = "2SCH_A";
  500. break;
  501. case SSL2_ST_SEND_CLIENT_HELLO_B:
  502. str = "2SCH_B";
  503. break;
  504. case SSL2_ST_GET_SERVER_HELLO_A:
  505. str = "2GSH_A";
  506. break;
  507. case SSL2_ST_GET_SERVER_HELLO_B:
  508. str = "2GSH_B";
  509. break;
  510. case SSL2_ST_SEND_CLIENT_MASTER_KEY_A:
  511. str = "2SCMKA";
  512. break;
  513. case SSL2_ST_SEND_CLIENT_MASTER_KEY_B:
  514. str = "2SCMKB";
  515. break;
  516. case SSL2_ST_SEND_CLIENT_FINISHED_A:
  517. str = "2SCF_A";
  518. break;
  519. case SSL2_ST_SEND_CLIENT_FINISHED_B:
  520. str = "2SCF_B";
  521. break;
  522. case SSL2_ST_SEND_CLIENT_CERTIFICATE_A:
  523. str = "2SCC_A";
  524. break;
  525. case SSL2_ST_SEND_CLIENT_CERTIFICATE_B:
  526. str = "2SCC_B";
  527. break;
  528. case SSL2_ST_SEND_CLIENT_CERTIFICATE_C:
  529. str = "2SCC_C";
  530. break;
  531. case SSL2_ST_SEND_CLIENT_CERTIFICATE_D:
  532. str = "2SCC_D";
  533. break;
  534. case SSL2_ST_GET_SERVER_VERIFY_A:
  535. str = "2GSV_A";
  536. break;
  537. case SSL2_ST_GET_SERVER_VERIFY_B:
  538. str = "2GSV_B";
  539. break;
  540. case SSL2_ST_GET_SERVER_FINISHED_A:
  541. str = "2GSF_A";
  542. break;
  543. case SSL2_ST_GET_SERVER_FINISHED_B:
  544. str = "2GSF_B";
  545. break;
  546. case SSL2_ST_GET_CLIENT_HELLO_A:
  547. str = "2GCH_A";
  548. break;
  549. case SSL2_ST_GET_CLIENT_HELLO_B:
  550. str = "2GCH_B";
  551. break;
  552. case SSL2_ST_GET_CLIENT_HELLO_C:
  553. str = "2GCH_C";
  554. break;
  555. case SSL2_ST_SEND_SERVER_HELLO_A:
  556. str = "2SSH_A";
  557. break;
  558. case SSL2_ST_SEND_SERVER_HELLO_B:
  559. str = "2SSH_B";
  560. break;
  561. case SSL2_ST_GET_CLIENT_MASTER_KEY_A:
  562. str = "2GCMKA";
  563. break;
  564. case SSL2_ST_GET_CLIENT_MASTER_KEY_B:
  565. str = "2GCMKA";
  566. break;
  567. case SSL2_ST_SEND_SERVER_VERIFY_A:
  568. str = "2SSV_A";
  569. break;
  570. case SSL2_ST_SEND_SERVER_VERIFY_B:
  571. str = "2SSV_B";
  572. break;
  573. case SSL2_ST_SEND_SERVER_VERIFY_C:
  574. str = "2SSV_C";
  575. break;
  576. case SSL2_ST_GET_CLIENT_FINISHED_A:
  577. str = "2GCF_A";
  578. break;
  579. case SSL2_ST_GET_CLIENT_FINISHED_B:
  580. str = "2GCF_B";
  581. break;
  582. case SSL2_ST_SEND_SERVER_FINISHED_A:
  583. str = "2SSF_A";
  584. break;
  585. case SSL2_ST_SEND_SERVER_FINISHED_B:
  586. str = "2SSF_B";
  587. break;
  588. case SSL2_ST_SEND_REQUEST_CERTIFICATE_A:
  589. str = "2SRC_A";
  590. break;
  591. case SSL2_ST_SEND_REQUEST_CERTIFICATE_B:
  592. str = "2SRC_B";
  593. break;
  594. case SSL2_ST_SEND_REQUEST_CERTIFICATE_C:
  595. str = "2SRC_C";
  596. break;
  597. case SSL2_ST_SEND_REQUEST_CERTIFICATE_D:
  598. str = "2SRC_D";
  599. break;
  600. case SSL2_ST_X509_GET_SERVER_CERTIFICATE:
  601. str = "2X9GSC";
  602. break;
  603. case SSL2_ST_X509_GET_CLIENT_CERTIFICATE:
  604. str = "2X9GCC";
  605. break;
  606. #endif
  607. #ifndef OPENSSL_NO_SSL3
  608. /* SSLv3 additions */
  609. case SSL3_ST_SW_FLUSH:
  610. case SSL3_ST_CW_FLUSH:
  611. str = "3FLUSH";
  612. break;
  613. case SSL3_ST_CW_CLNT_HELLO_A:
  614. str = "3WCH_A";
  615. break;
  616. case SSL3_ST_CW_CLNT_HELLO_B:
  617. str = "3WCH_B";
  618. break;
  619. case SSL3_ST_CR_SRVR_HELLO_A:
  620. str = "3RSH_A";
  621. break;
  622. case SSL3_ST_CR_SRVR_HELLO_B:
  623. str = "3RSH_B";
  624. break;
  625. case SSL3_ST_CR_CERT_A:
  626. str = "3RSC_A";
  627. break;
  628. case SSL3_ST_CR_CERT_B:
  629. str = "3RSC_B";
  630. break;
  631. case SSL3_ST_CR_KEY_EXCH_A:
  632. str = "3RSKEA";
  633. break;
  634. case SSL3_ST_CR_KEY_EXCH_B:
  635. str = "3RSKEB";
  636. break;
  637. case SSL3_ST_CR_CERT_REQ_A:
  638. str = "3RCR_A";
  639. break;
  640. case SSL3_ST_CR_CERT_REQ_B:
  641. str = "3RCR_B";
  642. break;
  643. case SSL3_ST_CR_SRVR_DONE_A:
  644. str = "3RSD_A";
  645. break;
  646. case SSL3_ST_CR_SRVR_DONE_B:
  647. str = "3RSD_B";
  648. break;
  649. case SSL3_ST_CW_CERT_A:
  650. str = "3WCC_A";
  651. break;
  652. case SSL3_ST_CW_CERT_B:
  653. str = "3WCC_B";
  654. break;
  655. case SSL3_ST_CW_CERT_C:
  656. str = "3WCC_C";
  657. break;
  658. case SSL3_ST_CW_CERT_D:
  659. str = "3WCC_D";
  660. break;
  661. case SSL3_ST_CW_KEY_EXCH_A:
  662. str = "3WCKEA";
  663. break;
  664. case SSL3_ST_CW_KEY_EXCH_B:
  665. str = "3WCKEB";
  666. break;
  667. case SSL3_ST_CW_CERT_VRFY_A:
  668. str = "3WCV_A";
  669. break;
  670. case SSL3_ST_CW_CERT_VRFY_B:
  671. str = "3WCV_B";
  672. break;
  673. case SSL3_ST_SW_CHANGE_A:
  674. case SSL3_ST_CW_CHANGE_A:
  675. str = "3WCCSA";
  676. break;
  677. case SSL3_ST_SW_CHANGE_B:
  678. case SSL3_ST_CW_CHANGE_B:
  679. str = "3WCCSB";
  680. break;
  681. case SSL3_ST_SW_FINISHED_A:
  682. case SSL3_ST_CW_FINISHED_A:
  683. str = "3WFINA";
  684. break;
  685. case SSL3_ST_SW_FINISHED_B:
  686. case SSL3_ST_CW_FINISHED_B:
  687. str = "3WFINB";
  688. break;
  689. case SSL3_ST_SR_CHANGE_A:
  690. case SSL3_ST_CR_CHANGE_A:
  691. str = "3RCCSA";
  692. break;
  693. case SSL3_ST_SR_CHANGE_B:
  694. case SSL3_ST_CR_CHANGE_B:
  695. str = "3RCCSB";
  696. break;
  697. case SSL3_ST_SR_FINISHED_A:
  698. case SSL3_ST_CR_FINISHED_A:
  699. str = "3RFINA";
  700. break;
  701. case SSL3_ST_SR_FINISHED_B:
  702. case SSL3_ST_CR_FINISHED_B:
  703. str = "3RFINB";
  704. break;
  705. case SSL3_ST_SW_HELLO_REQ_A:
  706. str = "3WHR_A";
  707. break;
  708. case SSL3_ST_SW_HELLO_REQ_B:
  709. str = "3WHR_B";
  710. break;
  711. case SSL3_ST_SW_HELLO_REQ_C:
  712. str = "3WHR_C";
  713. break;
  714. case SSL3_ST_SR_CLNT_HELLO_A:
  715. str = "3RCH_A";
  716. break;
  717. case SSL3_ST_SR_CLNT_HELLO_B:
  718. str = "3RCH_B";
  719. break;
  720. case SSL3_ST_SR_CLNT_HELLO_C:
  721. str = "3RCH_C";
  722. break;
  723. case SSL3_ST_SW_SRVR_HELLO_A:
  724. str = "3WSH_A";
  725. break;
  726. case SSL3_ST_SW_SRVR_HELLO_B:
  727. str = "3WSH_B";
  728. break;
  729. case SSL3_ST_SW_CERT_A:
  730. str = "3WSC_A";
  731. break;
  732. case SSL3_ST_SW_CERT_B:
  733. str = "3WSC_B";
  734. break;
  735. case SSL3_ST_SW_KEY_EXCH_A:
  736. str = "3WSKEA";
  737. break;
  738. case SSL3_ST_SW_KEY_EXCH_B:
  739. str = "3WSKEB";
  740. break;
  741. case SSL3_ST_SW_CERT_REQ_A:
  742. str = "3WCR_A";
  743. break;
  744. case SSL3_ST_SW_CERT_REQ_B:
  745. str = "3WCR_B";
  746. break;
  747. case SSL3_ST_SW_SRVR_DONE_A:
  748. str = "3WSD_A";
  749. break;
  750. case SSL3_ST_SW_SRVR_DONE_B:
  751. str = "3WSD_B";
  752. break;
  753. case SSL3_ST_SR_CERT_A:
  754. str = "3RCC_A";
  755. break;
  756. case SSL3_ST_SR_CERT_B:
  757. str = "3RCC_B";
  758. break;
  759. case SSL3_ST_SR_KEY_EXCH_A:
  760. str = "3RCKEA";
  761. break;
  762. case SSL3_ST_SR_KEY_EXCH_B:
  763. str = "3RCKEB";
  764. break;
  765. case SSL3_ST_SR_CERT_VRFY_A:
  766. str = "3RCV_A";
  767. break;
  768. case SSL3_ST_SR_CERT_VRFY_B:
  769. str = "3RCV_B";
  770. break;
  771. #endif
  772. /* SSLv2/v3 compatibility states */
  773. /* client */
  774. case SSL23_ST_CW_CLNT_HELLO_A:
  775. str = "23WCHA";
  776. break;
  777. case SSL23_ST_CW_CLNT_HELLO_B:
  778. str = "23WCHB";
  779. break;
  780. case SSL23_ST_CR_SRVR_HELLO_A:
  781. str = "23RSHA";
  782. break;
  783. case SSL23_ST_CR_SRVR_HELLO_B:
  784. str = "23RSHA";
  785. break;
  786. /* server */
  787. case SSL23_ST_SR_CLNT_HELLO_A:
  788. str = "23RCHA";
  789. break;
  790. case SSL23_ST_SR_CLNT_HELLO_B:
  791. str = "23RCHB";
  792. break;
  793. /* DTLS */
  794. case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
  795. str = "DRCHVA";
  796. break;
  797. case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
  798. str = "DRCHVB";
  799. break;
  800. case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
  801. str = "DWCHVA";
  802. break;
  803. case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
  804. str = "DWCHVB";
  805. break;
  806. default:
  807. str = "UNKWN ";
  808. break;
  809. }
  810. return (str);
  811. }
  812. const char *SSL_alert_type_string_long(int value)
  813. {
  814. value >>= 8;
  815. if (value == SSL3_AL_WARNING)
  816. return ("warning");
  817. else if (value == SSL3_AL_FATAL)
  818. return ("fatal");
  819. else
  820. return ("unknown");
  821. }
  822. const char *SSL_alert_type_string(int value)
  823. {
  824. value >>= 8;
  825. if (value == SSL3_AL_WARNING)
  826. return ("W");
  827. else if (value == SSL3_AL_FATAL)
  828. return ("F");
  829. else
  830. return ("U");
  831. }
  832. const char *SSL_alert_desc_string(int value)
  833. {
  834. const char *str;
  835. switch (value & 0xff) {
  836. case SSL3_AD_CLOSE_NOTIFY:
  837. str = "CN";
  838. break;
  839. case SSL3_AD_UNEXPECTED_MESSAGE:
  840. str = "UM";
  841. break;
  842. case SSL3_AD_BAD_RECORD_MAC:
  843. str = "BM";
  844. break;
  845. case SSL3_AD_DECOMPRESSION_FAILURE:
  846. str = "DF";
  847. break;
  848. case SSL3_AD_HANDSHAKE_FAILURE:
  849. str = "HF";
  850. break;
  851. case SSL3_AD_NO_CERTIFICATE:
  852. str = "NC";
  853. break;
  854. case SSL3_AD_BAD_CERTIFICATE:
  855. str = "BC";
  856. break;
  857. case SSL3_AD_UNSUPPORTED_CERTIFICATE:
  858. str = "UC";
  859. break;
  860. case SSL3_AD_CERTIFICATE_REVOKED:
  861. str = "CR";
  862. break;
  863. case SSL3_AD_CERTIFICATE_EXPIRED:
  864. str = "CE";
  865. break;
  866. case SSL3_AD_CERTIFICATE_UNKNOWN:
  867. str = "CU";
  868. break;
  869. case SSL3_AD_ILLEGAL_PARAMETER:
  870. str = "IP";
  871. break;
  872. case TLS1_AD_DECRYPTION_FAILED:
  873. str = "DC";
  874. break;
  875. case TLS1_AD_RECORD_OVERFLOW:
  876. str = "RO";
  877. break;
  878. case TLS1_AD_UNKNOWN_CA:
  879. str = "CA";
  880. break;
  881. case TLS1_AD_ACCESS_DENIED:
  882. str = "AD";
  883. break;
  884. case TLS1_AD_DECODE_ERROR:
  885. str = "DE";
  886. break;
  887. case TLS1_AD_DECRYPT_ERROR:
  888. str = "CY";
  889. break;
  890. case TLS1_AD_EXPORT_RESTRICTION:
  891. str = "ER";
  892. break;
  893. case TLS1_AD_PROTOCOL_VERSION:
  894. str = "PV";
  895. break;
  896. case TLS1_AD_INSUFFICIENT_SECURITY:
  897. str = "IS";
  898. break;
  899. case TLS1_AD_INTERNAL_ERROR:
  900. str = "IE";
  901. break;
  902. case TLS1_AD_USER_CANCELLED:
  903. str = "US";
  904. break;
  905. case TLS1_AD_NO_RENEGOTIATION:
  906. str = "NR";
  907. break;
  908. case TLS1_AD_UNSUPPORTED_EXTENSION:
  909. str = "UE";
  910. break;
  911. case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
  912. str = "CO";
  913. break;
  914. case TLS1_AD_UNRECOGNIZED_NAME:
  915. str = "UN";
  916. break;
  917. case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
  918. str = "BR";
  919. break;
  920. case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
  921. str = "BH";
  922. break;
  923. case TLS1_AD_UNKNOWN_PSK_IDENTITY:
  924. str = "UP";
  925. break;
  926. default:
  927. str = "UK";
  928. break;
  929. }
  930. return (str);
  931. }
  932. const char *SSL_alert_desc_string_long(int value)
  933. {
  934. const char *str;
  935. switch (value & 0xff) {
  936. case SSL3_AD_CLOSE_NOTIFY:
  937. str = "close notify";
  938. break;
  939. case SSL3_AD_UNEXPECTED_MESSAGE:
  940. str = "unexpected_message";
  941. break;
  942. case SSL3_AD_BAD_RECORD_MAC:
  943. str = "bad record mac";
  944. break;
  945. case SSL3_AD_DECOMPRESSION_FAILURE:
  946. str = "decompression failure";
  947. break;
  948. case SSL3_AD_HANDSHAKE_FAILURE:
  949. str = "handshake failure";
  950. break;
  951. case SSL3_AD_NO_CERTIFICATE:
  952. str = "no certificate";
  953. break;
  954. case SSL3_AD_BAD_CERTIFICATE:
  955. str = "bad certificate";
  956. break;
  957. case SSL3_AD_UNSUPPORTED_CERTIFICATE:
  958. str = "unsupported certificate";
  959. break;
  960. case SSL3_AD_CERTIFICATE_REVOKED:
  961. str = "certificate revoked";
  962. break;
  963. case SSL3_AD_CERTIFICATE_EXPIRED:
  964. str = "certificate expired";
  965. break;
  966. case SSL3_AD_CERTIFICATE_UNKNOWN:
  967. str = "certificate unknown";
  968. break;
  969. case SSL3_AD_ILLEGAL_PARAMETER:
  970. str = "illegal parameter";
  971. break;
  972. case TLS1_AD_DECRYPTION_FAILED:
  973. str = "decryption failed";
  974. break;
  975. case TLS1_AD_RECORD_OVERFLOW:
  976. str = "record overflow";
  977. break;
  978. case TLS1_AD_UNKNOWN_CA:
  979. str = "unknown CA";
  980. break;
  981. case TLS1_AD_ACCESS_DENIED:
  982. str = "access denied";
  983. break;
  984. case TLS1_AD_DECODE_ERROR:
  985. str = "decode error";
  986. break;
  987. case TLS1_AD_DECRYPT_ERROR:
  988. str = "decrypt error";
  989. break;
  990. case TLS1_AD_EXPORT_RESTRICTION:
  991. str = "export restriction";
  992. break;
  993. case TLS1_AD_PROTOCOL_VERSION:
  994. str = "protocol version";
  995. break;
  996. case TLS1_AD_INSUFFICIENT_SECURITY:
  997. str = "insufficient security";
  998. break;
  999. case TLS1_AD_INTERNAL_ERROR:
  1000. str = "internal error";
  1001. break;
  1002. case TLS1_AD_USER_CANCELLED:
  1003. str = "user canceled";
  1004. break;
  1005. case TLS1_AD_NO_RENEGOTIATION:
  1006. str = "no renegotiation";
  1007. break;
  1008. case TLS1_AD_UNSUPPORTED_EXTENSION:
  1009. str = "unsupported extension";
  1010. break;
  1011. case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
  1012. str = "certificate unobtainable";
  1013. break;
  1014. case TLS1_AD_UNRECOGNIZED_NAME:
  1015. str = "unrecognized name";
  1016. break;
  1017. case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
  1018. str = "bad certificate status response";
  1019. break;
  1020. case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
  1021. str = "bad certificate hash value";
  1022. break;
  1023. case TLS1_AD_UNKNOWN_PSK_IDENTITY:
  1024. str = "unknown PSK identity";
  1025. break;
  1026. default:
  1027. str = "unknown";
  1028. break;
  1029. }
  1030. return (str);
  1031. }
  1032. const char *SSL_rstate_string(const SSL *s)
  1033. {
  1034. const char *str;
  1035. switch (s->rstate) {
  1036. case SSL_ST_READ_HEADER:
  1037. str = "RH";
  1038. break;
  1039. case SSL_ST_READ_BODY:
  1040. str = "RB";
  1041. break;
  1042. case SSL_ST_READ_DONE:
  1043. str = "RD";
  1044. break;
  1045. default:
  1046. str = "unknown";
  1047. break;
  1048. }
  1049. return (str);
  1050. }