Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

510 рядки
14 KiB

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