ssl_stat.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /* ====================================================================
  10. * Copyright 2005 Nokia. All rights reserved.
  11. *
  12. * The portions of the attached software ("Contribution") is developed by
  13. * Nokia Corporation and is licensed pursuant to the OpenSSL open source
  14. * license.
  15. *
  16. * The Contribution, originally written by Mika Kousa and Pasi Eronen of
  17. * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
  18. * support (see RFC 4279) to OpenSSL.
  19. *
  20. * No patent licenses or other rights except those expressly stated in
  21. * the OpenSSL open source license shall be deemed granted or received
  22. * expressly, by implication, estoppel, or otherwise.
  23. *
  24. * No assurances are provided by Nokia that the Contribution does not
  25. * infringe the patent or other intellectual property rights of any third
  26. * party or that the license provides you with all the necessary rights
  27. * to make use of the Contribution.
  28. *
  29. * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
  30. * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
  31. * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
  32. * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
  33. * OTHERWISE.
  34. */
  35. #include <stdio.h>
  36. #include "ssl_locl.h"
  37. const char *SSL_state_string_long(const SSL *s)
  38. {
  39. if (ossl_statem_in_error(s))
  40. return "error";
  41. switch (SSL_get_state(s)) {
  42. case TLS_ST_CR_CERT_STATUS:
  43. return "SSLv3/TLS read certificate status";
  44. case TLS_ST_CW_NEXT_PROTO:
  45. return "SSLv3/TLS write next proto";
  46. case TLS_ST_SR_NEXT_PROTO:
  47. return "SSLv3/TLS write next proto";
  48. case TLS_ST_SW_CERT_STATUS:
  49. return "SSLv3/TLS write next proto";
  50. case TLS_ST_BEFORE:
  51. return "before SSL initialization";
  52. case TLS_ST_OK:
  53. return "SSL negotiation finished successfully";
  54. case TLS_ST_CW_CLNT_HELLO:
  55. return "SSLv3/TLS write client hello";
  56. case TLS_ST_CR_SRVR_HELLO:
  57. return "SSLv3/TLS read server hello";
  58. case TLS_ST_CR_CERT:
  59. return "SSLv3/TLS read server certificate";
  60. case TLS_ST_CR_KEY_EXCH:
  61. return "SSLv3/TLS read server key exchange";
  62. case TLS_ST_CR_CERT_REQ:
  63. return "SSLv3/TLS read server certificate request";
  64. case TLS_ST_CR_SESSION_TICKET:
  65. return "SSLv3/TLS read server session ticket";
  66. case TLS_ST_CR_SRVR_DONE:
  67. return "SSLv3/TLS read server done";
  68. case TLS_ST_CW_CERT:
  69. return "SSLv3/TLS write client certificate";
  70. case TLS_ST_CW_KEY_EXCH:
  71. return "SSLv3/TLS write client key exchange";
  72. case TLS_ST_CW_CERT_VRFY:
  73. return "SSLv3/TLS write certificate verify";
  74. case TLS_ST_CW_CHANGE:
  75. case TLS_ST_SW_CHANGE:
  76. return "SSLv3/TLS write change cipher spec";
  77. case TLS_ST_CW_FINISHED:
  78. case TLS_ST_SW_FINISHED:
  79. return "SSLv3/TLS write finished";
  80. case TLS_ST_CR_CHANGE:
  81. case TLS_ST_SR_CHANGE:
  82. return "SSLv3/TLS read change cipher spec";
  83. case TLS_ST_CR_FINISHED:
  84. case TLS_ST_SR_FINISHED:
  85. return "SSLv3/TLS read finished";
  86. case TLS_ST_SR_CLNT_HELLO:
  87. return "SSLv3/TLS read client hello";
  88. case TLS_ST_SW_HELLO_REQ:
  89. return "SSLv3/TLS write hello request";
  90. case TLS_ST_SW_SRVR_HELLO:
  91. return "SSLv3/TLS write server hello";
  92. case TLS_ST_SW_CERT:
  93. return "SSLv3/TLS write certificate";
  94. case TLS_ST_SW_KEY_EXCH:
  95. return "SSLv3/TLS write key exchange";
  96. case TLS_ST_SW_CERT_REQ:
  97. return "SSLv3/TLS write certificate request";
  98. case TLS_ST_SW_SESSION_TICKET:
  99. return "SSLv3/TLS write session ticket";
  100. case TLS_ST_SW_SRVR_DONE:
  101. return "SSLv3/TLS write server done";
  102. case TLS_ST_SR_CERT:
  103. return "SSLv3/TLS read client certificate";
  104. case TLS_ST_SR_KEY_EXCH:
  105. return "SSLv3/TLS read client key exchange";
  106. case TLS_ST_SR_CERT_VRFY:
  107. return "SSLv3/TLS read certificate verify";
  108. case DTLS_ST_CR_HELLO_VERIFY_REQUEST:
  109. return "DTLS1 read hello verify request";
  110. case DTLS_ST_SW_HELLO_VERIFY_REQUEST:
  111. return "DTLS1 write hello verify request";
  112. default:
  113. return "unknown state";
  114. }
  115. }
  116. const char *SSL_state_string(const SSL *s)
  117. {
  118. if (ossl_statem_in_error(s))
  119. return "SSLERR";
  120. switch (SSL_get_state(s)) {
  121. case TLS_ST_SR_NEXT_PROTO:
  122. return "TRNP";
  123. case TLS_ST_SW_SESSION_TICKET:
  124. return "TWST";
  125. case TLS_ST_SW_CERT_STATUS:
  126. return "TWCS";
  127. case TLS_ST_CR_CERT_STATUS:
  128. return "TRCS";
  129. case TLS_ST_CR_SESSION_TICKET:
  130. return "TRST";
  131. case TLS_ST_CW_NEXT_PROTO:
  132. return "TWNP";
  133. case TLS_ST_BEFORE:
  134. return "PINIT ";
  135. case TLS_ST_OK:
  136. return "SSLOK ";
  137. case TLS_ST_CW_CLNT_HELLO:
  138. return "TWCH";
  139. case TLS_ST_CR_SRVR_HELLO:
  140. return "TRSH";
  141. case TLS_ST_CR_CERT:
  142. return "TRSC";
  143. case TLS_ST_CR_KEY_EXCH:
  144. return "TRSKE";
  145. case TLS_ST_CR_CERT_REQ:
  146. return "TRCR";
  147. case TLS_ST_CR_SRVR_DONE:
  148. return "TRSD";
  149. case TLS_ST_CW_CERT:
  150. return "TWCC";
  151. case TLS_ST_CW_KEY_EXCH:
  152. return "TWCKE";
  153. case TLS_ST_CW_CERT_VRFY:
  154. return "TWCV";
  155. case TLS_ST_SW_CHANGE:
  156. case TLS_ST_CW_CHANGE:
  157. return "TWCCS";
  158. case TLS_ST_SW_FINISHED:
  159. case TLS_ST_CW_FINISHED:
  160. return "TWFIN";
  161. case TLS_ST_SR_CHANGE:
  162. case TLS_ST_CR_CHANGE:
  163. return "TRCCS";
  164. case TLS_ST_SR_FINISHED:
  165. case TLS_ST_CR_FINISHED:
  166. return "TRFIN";
  167. case TLS_ST_SW_HELLO_REQ:
  168. return "TWHR";
  169. case TLS_ST_SR_CLNT_HELLO:
  170. return "TRCH";
  171. case TLS_ST_SW_SRVR_HELLO:
  172. return "TWSH";
  173. case TLS_ST_SW_CERT:
  174. return "TWSC";
  175. case TLS_ST_SW_KEY_EXCH:
  176. return "TWSKE";
  177. case TLS_ST_SW_CERT_REQ:
  178. return "TWCR";
  179. case TLS_ST_SW_SRVR_DONE:
  180. return "TWSD";
  181. case TLS_ST_SR_CERT:
  182. return "TRCC";
  183. case TLS_ST_SR_KEY_EXCH:
  184. return "TRCKE";
  185. case TLS_ST_SR_CERT_VRFY:
  186. return "TRCV";
  187. case DTLS_ST_CR_HELLO_VERIFY_REQUEST:
  188. return "DRCHV";
  189. case DTLS_ST_SW_HELLO_VERIFY_REQUEST:
  190. return "DWCHV";
  191. default:
  192. return "UNKWN ";
  193. }
  194. }
  195. const char *SSL_alert_type_string_long(int value)
  196. {
  197. switch (value >> 8) {
  198. case SSL3_AL_WARNING:
  199. return "warning";
  200. case SSL3_AL_FATAL:
  201. return "fatal";
  202. default:
  203. return "unknown";
  204. }
  205. }
  206. const char *SSL_alert_type_string(int value)
  207. {
  208. switch (value >> 8) {
  209. case SSL3_AL_WARNING:
  210. return "W";
  211. case SSL3_AL_FATAL:
  212. return "F";
  213. default:
  214. return "U";
  215. }
  216. }
  217. const char *SSL_alert_desc_string(int value)
  218. {
  219. switch (value & 0xff) {
  220. case SSL3_AD_CLOSE_NOTIFY:
  221. return "CN";
  222. case SSL3_AD_UNEXPECTED_MESSAGE:
  223. return "UM";
  224. case SSL3_AD_BAD_RECORD_MAC:
  225. return "BM";
  226. case SSL3_AD_DECOMPRESSION_FAILURE:
  227. return "DF";
  228. case SSL3_AD_HANDSHAKE_FAILURE:
  229. return "HF";
  230. case SSL3_AD_NO_CERTIFICATE:
  231. return "NC";
  232. case SSL3_AD_BAD_CERTIFICATE:
  233. return "BC";
  234. case SSL3_AD_UNSUPPORTED_CERTIFICATE:
  235. return "UC";
  236. case SSL3_AD_CERTIFICATE_REVOKED:
  237. return "CR";
  238. case SSL3_AD_CERTIFICATE_EXPIRED:
  239. return "CE";
  240. case SSL3_AD_CERTIFICATE_UNKNOWN:
  241. return "CU";
  242. case SSL3_AD_ILLEGAL_PARAMETER:
  243. return "IP";
  244. case TLS1_AD_DECRYPTION_FAILED:
  245. return "DC";
  246. case TLS1_AD_RECORD_OVERFLOW:
  247. return "RO";
  248. case TLS1_AD_UNKNOWN_CA:
  249. return "CA";
  250. case TLS1_AD_ACCESS_DENIED:
  251. return "AD";
  252. case TLS1_AD_DECODE_ERROR:
  253. return "DE";
  254. case TLS1_AD_DECRYPT_ERROR:
  255. return "CY";
  256. case TLS1_AD_EXPORT_RESTRICTION:
  257. return "ER";
  258. case TLS1_AD_PROTOCOL_VERSION:
  259. return "PV";
  260. case TLS1_AD_INSUFFICIENT_SECURITY:
  261. return "IS";
  262. case TLS1_AD_INTERNAL_ERROR:
  263. return "IE";
  264. case TLS1_AD_USER_CANCELLED:
  265. return "US";
  266. case TLS1_AD_NO_RENEGOTIATION:
  267. return "NR";
  268. case TLS1_AD_UNSUPPORTED_EXTENSION:
  269. return "UE";
  270. case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
  271. return "CO";
  272. case TLS1_AD_UNRECOGNIZED_NAME:
  273. return "UN";
  274. case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
  275. return "BR";
  276. case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
  277. return "BH";
  278. case TLS1_AD_UNKNOWN_PSK_IDENTITY:
  279. return "UP";
  280. default:
  281. return "UK";
  282. }
  283. }
  284. const char *SSL_alert_desc_string_long(int value)
  285. {
  286. switch (value & 0xff) {
  287. case SSL3_AD_CLOSE_NOTIFY:
  288. return "close notify";
  289. case SSL3_AD_UNEXPECTED_MESSAGE:
  290. return "unexpected_message";
  291. case SSL3_AD_BAD_RECORD_MAC:
  292. return "bad record mac";
  293. case SSL3_AD_DECOMPRESSION_FAILURE:
  294. return "decompression failure";
  295. case SSL3_AD_HANDSHAKE_FAILURE:
  296. return "handshake failure";
  297. case SSL3_AD_NO_CERTIFICATE:
  298. return "no certificate";
  299. case SSL3_AD_BAD_CERTIFICATE:
  300. return "bad certificate";
  301. case SSL3_AD_UNSUPPORTED_CERTIFICATE:
  302. return "unsupported certificate";
  303. case SSL3_AD_CERTIFICATE_REVOKED:
  304. return "certificate revoked";
  305. case SSL3_AD_CERTIFICATE_EXPIRED:
  306. return "certificate expired";
  307. case SSL3_AD_CERTIFICATE_UNKNOWN:
  308. return "certificate unknown";
  309. case SSL3_AD_ILLEGAL_PARAMETER:
  310. return "illegal parameter";
  311. case TLS1_AD_DECRYPTION_FAILED:
  312. return "decryption failed";
  313. case TLS1_AD_RECORD_OVERFLOW:
  314. return "record overflow";
  315. case TLS1_AD_UNKNOWN_CA:
  316. return "unknown CA";
  317. case TLS1_AD_ACCESS_DENIED:
  318. return "access denied";
  319. case TLS1_AD_DECODE_ERROR:
  320. return "decode error";
  321. case TLS1_AD_DECRYPT_ERROR:
  322. return "decrypt error";
  323. case TLS1_AD_EXPORT_RESTRICTION:
  324. return "export restriction";
  325. case TLS1_AD_PROTOCOL_VERSION:
  326. return "protocol version";
  327. case TLS1_AD_INSUFFICIENT_SECURITY:
  328. return "insufficient security";
  329. case TLS1_AD_INTERNAL_ERROR:
  330. return "internal error";
  331. case TLS1_AD_USER_CANCELLED:
  332. return "user canceled";
  333. case TLS1_AD_NO_RENEGOTIATION:
  334. return "no renegotiation";
  335. case TLS1_AD_UNSUPPORTED_EXTENSION:
  336. return "unsupported extension";
  337. case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
  338. return "certificate unobtainable";
  339. case TLS1_AD_UNRECOGNIZED_NAME:
  340. return "unrecognized name";
  341. case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
  342. return "bad certificate status response";
  343. case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
  344. return "bad certificate hash value";
  345. case TLS1_AD_UNKNOWN_PSK_IDENTITY:
  346. return "unknown PSK identity";
  347. case TLS1_AD_NO_APPLICATION_PROTOCOL:
  348. return "no application protocol";
  349. default:
  350. return "unknown";
  351. }
  352. }