s3_enc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*
  2. * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright 2005 Nokia. All rights reserved.
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. #include <stdio.h>
  11. #include "ssl_local.h"
  12. #include <openssl/evp.h>
  13. #include <openssl/md5.h>
  14. #include <openssl/core_names.h>
  15. #include "internal/cryptlib.h"
  16. static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
  17. {
  18. const EVP_MD *md5 = NULL, *sha1 = NULL;
  19. EVP_MD_CTX *m5;
  20. EVP_MD_CTX *s1;
  21. unsigned char buf[16], smd[SHA_DIGEST_LENGTH];
  22. unsigned char c = 'A';
  23. unsigned int i, k;
  24. int ret = 0;
  25. #ifdef CHARSET_EBCDIC
  26. c = os_toascii[c]; /* 'A' in ASCII */
  27. #endif
  28. k = 0;
  29. md5 = ssl_evp_md_fetch(s->ctx->libctx, NID_md5, s->ctx->propq);
  30. sha1 = ssl_evp_md_fetch(s->ctx->libctx, NID_sha1, s->ctx->propq);
  31. m5 = EVP_MD_CTX_new();
  32. s1 = EVP_MD_CTX_new();
  33. if (md5 == NULL || sha1 == NULL || m5 == NULL || s1 == NULL) {
  34. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  35. goto err;
  36. }
  37. for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
  38. k++;
  39. if (k > sizeof(buf)) {
  40. /* bug: 'buf' is too small for this ciphersuite */
  41. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  42. goto err;
  43. }
  44. memset(buf, c, k);
  45. c++;
  46. if (!EVP_DigestInit_ex(s1, sha1, NULL)
  47. || !EVP_DigestUpdate(s1, buf, k)
  48. || !EVP_DigestUpdate(s1, s->session->master_key,
  49. s->session->master_key_length)
  50. || !EVP_DigestUpdate(s1, s->s3.server_random, SSL3_RANDOM_SIZE)
  51. || !EVP_DigestUpdate(s1, s->s3.client_random, SSL3_RANDOM_SIZE)
  52. || !EVP_DigestFinal_ex(s1, smd, NULL)
  53. || !EVP_DigestInit_ex(m5, md5, NULL)
  54. || !EVP_DigestUpdate(m5, s->session->master_key,
  55. s->session->master_key_length)
  56. || !EVP_DigestUpdate(m5, smd, SHA_DIGEST_LENGTH)) {
  57. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  58. goto err;
  59. }
  60. if ((int)(i + MD5_DIGEST_LENGTH) > num) {
  61. if (!EVP_DigestFinal_ex(m5, smd, NULL)) {
  62. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  63. goto err;
  64. }
  65. memcpy(km, smd, (num - i));
  66. } else {
  67. if (!EVP_DigestFinal_ex(m5, km, NULL)) {
  68. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  69. goto err;
  70. }
  71. }
  72. km += MD5_DIGEST_LENGTH;
  73. }
  74. OPENSSL_cleanse(smd, sizeof(smd));
  75. ret = 1;
  76. err:
  77. EVP_MD_CTX_free(m5);
  78. EVP_MD_CTX_free(s1);
  79. ssl_evp_md_free(md5);
  80. ssl_evp_md_free(sha1);
  81. return ret;
  82. }
  83. int ssl3_change_cipher_state(SSL *s, int which)
  84. {
  85. unsigned char *p, *mac_secret;
  86. unsigned char *ms, *key, *iv;
  87. EVP_CIPHER_CTX *dd;
  88. const EVP_CIPHER *c;
  89. #ifndef OPENSSL_NO_COMP
  90. COMP_METHOD *comp;
  91. #endif
  92. const EVP_MD *m;
  93. int mdi;
  94. size_t n, i, j, k, cl;
  95. int reuse_dd = 0;
  96. c = s->s3.tmp.new_sym_enc;
  97. m = s->s3.tmp.new_hash;
  98. /* m == NULL will lead to a crash later */
  99. if (!ossl_assert(m != NULL)) {
  100. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  101. goto err;
  102. }
  103. #ifndef OPENSSL_NO_COMP
  104. if (s->s3.tmp.new_compression == NULL)
  105. comp = NULL;
  106. else
  107. comp = s->s3.tmp.new_compression->method;
  108. #endif
  109. if (which & SSL3_CC_READ) {
  110. if (s->enc_read_ctx != NULL) {
  111. reuse_dd = 1;
  112. } else if ((s->enc_read_ctx = EVP_CIPHER_CTX_new()) == NULL) {
  113. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  114. goto err;
  115. } else {
  116. /*
  117. * make sure it's initialised in case we exit later with an error
  118. */
  119. EVP_CIPHER_CTX_reset(s->enc_read_ctx);
  120. }
  121. dd = s->enc_read_ctx;
  122. if (ssl_replace_hash(&s->read_hash, m) == NULL) {
  123. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  124. goto err;
  125. }
  126. #ifndef OPENSSL_NO_COMP
  127. /* COMPRESS */
  128. COMP_CTX_free(s->expand);
  129. s->expand = NULL;
  130. if (comp != NULL) {
  131. s->expand = COMP_CTX_new(comp);
  132. if (s->expand == NULL) {
  133. SSLfatal(s, SSL_AD_INTERNAL_ERROR,
  134. SSL_R_COMPRESSION_LIBRARY_ERROR);
  135. goto err;
  136. }
  137. }
  138. #endif
  139. RECORD_LAYER_reset_read_sequence(&s->rlayer);
  140. mac_secret = &(s->s3.read_mac_secret[0]);
  141. } else {
  142. s->statem.enc_write_state = ENC_WRITE_STATE_INVALID;
  143. if (s->enc_write_ctx != NULL) {
  144. reuse_dd = 1;
  145. } else if ((s->enc_write_ctx = EVP_CIPHER_CTX_new()) == NULL) {
  146. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  147. goto err;
  148. } else {
  149. /*
  150. * make sure it's initialised in case we exit later with an error
  151. */
  152. EVP_CIPHER_CTX_reset(s->enc_write_ctx);
  153. }
  154. dd = s->enc_write_ctx;
  155. if (ssl_replace_hash(&s->write_hash, m) == NULL) {
  156. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  157. goto err;
  158. }
  159. #ifndef OPENSSL_NO_COMP
  160. /* COMPRESS */
  161. COMP_CTX_free(s->compress);
  162. s->compress = NULL;
  163. if (comp != NULL) {
  164. s->compress = COMP_CTX_new(comp);
  165. if (s->compress == NULL) {
  166. SSLfatal(s, SSL_AD_INTERNAL_ERROR,
  167. SSL_R_COMPRESSION_LIBRARY_ERROR);
  168. goto err;
  169. }
  170. }
  171. #endif
  172. RECORD_LAYER_reset_write_sequence(&s->rlayer);
  173. mac_secret = &(s->s3.write_mac_secret[0]);
  174. }
  175. if (reuse_dd)
  176. EVP_CIPHER_CTX_reset(dd);
  177. p = s->s3.tmp.key_block;
  178. mdi = EVP_MD_size(m);
  179. if (mdi < 0) {
  180. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  181. goto err;
  182. }
  183. i = mdi;
  184. cl = EVP_CIPHER_key_length(c);
  185. j = cl;
  186. k = EVP_CIPHER_iv_length(c);
  187. if ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
  188. (which == SSL3_CHANGE_CIPHER_SERVER_READ)) {
  189. ms = &(p[0]);
  190. n = i + i;
  191. key = &(p[n]);
  192. n += j + j;
  193. iv = &(p[n]);
  194. n += k + k;
  195. } else {
  196. n = i;
  197. ms = &(p[n]);
  198. n += i + j;
  199. key = &(p[n]);
  200. n += j + k;
  201. iv = &(p[n]);
  202. n += k;
  203. }
  204. if (n > s->s3.tmp.key_block_length) {
  205. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  206. goto err;
  207. }
  208. memcpy(mac_secret, ms, i);
  209. if (!EVP_CipherInit_ex(dd, c, NULL, key, iv, (which & SSL3_CC_WRITE))) {
  210. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  211. goto err;
  212. }
  213. if (EVP_CIPHER_provider(c) != NULL
  214. && !tls_provider_set_tls_params(s, dd, c, m)) {
  215. /* SSLfatal already called */
  216. goto err;
  217. }
  218. s->statem.enc_write_state = ENC_WRITE_STATE_VALID;
  219. return 1;
  220. err:
  221. return 0;
  222. }
  223. int ssl3_setup_key_block(SSL *s)
  224. {
  225. unsigned char *p;
  226. const EVP_CIPHER *c;
  227. const EVP_MD *hash;
  228. int num;
  229. int ret = 0;
  230. SSL_COMP *comp;
  231. if (s->s3.tmp.key_block_length != 0)
  232. return 1;
  233. if (!ssl_cipher_get_evp(s->ctx, s->session, &c, &hash, NULL, NULL, &comp,
  234. 0)) {
  235. SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
  236. return 0;
  237. }
  238. ssl_evp_cipher_free(s->s3.tmp.new_sym_enc);
  239. s->s3.tmp.new_sym_enc = c;
  240. ssl_evp_md_free(s->s3.tmp.new_hash);
  241. s->s3.tmp.new_hash = hash;
  242. #ifdef OPENSSL_NO_COMP
  243. s->s3.tmp.new_compression = NULL;
  244. #else
  245. s->s3.tmp.new_compression = comp;
  246. #endif
  247. num = EVP_MD_size(hash);
  248. if (num < 0)
  249. return 0;
  250. num = EVP_CIPHER_key_length(c) + num + EVP_CIPHER_iv_length(c);
  251. num *= 2;
  252. ssl3_cleanup_key_block(s);
  253. if ((p = OPENSSL_malloc(num)) == NULL) {
  254. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  255. return 0;
  256. }
  257. s->s3.tmp.key_block_length = num;
  258. s->s3.tmp.key_block = p;
  259. /* Calls SSLfatal() as required */
  260. ret = ssl3_generate_key_block(s, p, num);
  261. if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)) {
  262. /*
  263. * enable vulnerability countermeasure for CBC ciphers with known-IV
  264. * problem (http://www.openssl.org/~bodo/tls-cbc.txt)
  265. */
  266. s->s3.need_empty_fragments = 1;
  267. if (s->session->cipher != NULL) {
  268. if (s->session->cipher->algorithm_enc == SSL_eNULL)
  269. s->s3.need_empty_fragments = 0;
  270. #ifndef OPENSSL_NO_RC4
  271. if (s->session->cipher->algorithm_enc == SSL_RC4)
  272. s->s3.need_empty_fragments = 0;
  273. #endif
  274. }
  275. }
  276. return ret;
  277. }
  278. void ssl3_cleanup_key_block(SSL *s)
  279. {
  280. OPENSSL_clear_free(s->s3.tmp.key_block, s->s3.tmp.key_block_length);
  281. s->s3.tmp.key_block = NULL;
  282. s->s3.tmp.key_block_length = 0;
  283. }
  284. int ssl3_init_finished_mac(SSL *s)
  285. {
  286. BIO *buf = BIO_new(BIO_s_mem());
  287. if (buf == NULL) {
  288. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  289. return 0;
  290. }
  291. ssl3_free_digest_list(s);
  292. s->s3.handshake_buffer = buf;
  293. (void)BIO_set_close(s->s3.handshake_buffer, BIO_CLOSE);
  294. return 1;
  295. }
  296. /*
  297. * Free digest list. Also frees handshake buffer since they are always freed
  298. * together.
  299. */
  300. void ssl3_free_digest_list(SSL *s)
  301. {
  302. BIO_free(s->s3.handshake_buffer);
  303. s->s3.handshake_buffer = NULL;
  304. EVP_MD_CTX_free(s->s3.handshake_dgst);
  305. s->s3.handshake_dgst = NULL;
  306. }
  307. int ssl3_finish_mac(SSL *s, const unsigned char *buf, size_t len)
  308. {
  309. int ret;
  310. if (s->s3.handshake_dgst == NULL) {
  311. /* Note: this writes to a memory BIO so a failure is a fatal error */
  312. if (len > INT_MAX) {
  313. SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_OVERFLOW_ERROR);
  314. return 0;
  315. }
  316. ret = BIO_write(s->s3.handshake_buffer, (void *)buf, (int)len);
  317. if (ret <= 0 || ret != (int)len) {
  318. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  319. return 0;
  320. }
  321. } else {
  322. ret = EVP_DigestUpdate(s->s3.handshake_dgst, buf, len);
  323. if (!ret) {
  324. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  325. return 0;
  326. }
  327. }
  328. return 1;
  329. }
  330. int ssl3_digest_cached_records(SSL *s, int keep)
  331. {
  332. const EVP_MD *md;
  333. long hdatalen;
  334. void *hdata;
  335. if (s->s3.handshake_dgst == NULL) {
  336. hdatalen = BIO_get_mem_data(s->s3.handshake_buffer, &hdata);
  337. if (hdatalen <= 0) {
  338. SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_HANDSHAKE_LENGTH);
  339. return 0;
  340. }
  341. s->s3.handshake_dgst = EVP_MD_CTX_new();
  342. if (s->s3.handshake_dgst == NULL) {
  343. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  344. return 0;
  345. }
  346. md = ssl_handshake_md(s);
  347. if (md == NULL) {
  348. SSLfatal(s, SSL_AD_INTERNAL_ERROR,
  349. SSL_R_NO_SUITABLE_DIGEST_ALGORITHM);
  350. return 0;
  351. }
  352. if (!EVP_DigestInit_ex(s->s3.handshake_dgst, md, NULL)
  353. || !EVP_DigestUpdate(s->s3.handshake_dgst, hdata, hdatalen)) {
  354. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  355. return 0;
  356. }
  357. }
  358. if (keep == 0) {
  359. BIO_free(s->s3.handshake_buffer);
  360. s->s3.handshake_buffer = NULL;
  361. }
  362. return 1;
  363. }
  364. void ssl3_digest_master_key_set_params(const SSL_SESSION *session,
  365. OSSL_PARAM params[])
  366. {
  367. int n = 0;
  368. params[n++] = OSSL_PARAM_construct_octet_string(OSSL_DIGEST_PARAM_SSL3_MS,
  369. (void *)session->master_key,
  370. session->master_key_length);
  371. params[n++] = OSSL_PARAM_construct_end();
  372. }
  373. size_t ssl3_final_finish_mac(SSL *s, const char *sender, size_t len,
  374. unsigned char *p)
  375. {
  376. int ret;
  377. EVP_MD_CTX *ctx = NULL;
  378. if (!ssl3_digest_cached_records(s, 0)) {
  379. /* SSLfatal() already called */
  380. return 0;
  381. }
  382. if (EVP_MD_CTX_type(s->s3.handshake_dgst) != NID_md5_sha1) {
  383. SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_NO_REQUIRED_DIGEST);
  384. return 0;
  385. }
  386. ctx = EVP_MD_CTX_new();
  387. if (ctx == NULL) {
  388. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  389. return 0;
  390. }
  391. if (!EVP_MD_CTX_copy_ex(ctx, s->s3.handshake_dgst)) {
  392. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  393. ret = 0;
  394. goto err;
  395. }
  396. ret = EVP_MD_CTX_size(ctx);
  397. if (ret < 0) {
  398. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  399. ret = 0;
  400. goto err;
  401. }
  402. if (sender != NULL) {
  403. OSSL_PARAM digest_cmd_params[3];
  404. ssl3_digest_master_key_set_params(s->session, digest_cmd_params);
  405. if (EVP_DigestUpdate(ctx, sender, len) <= 0
  406. || EVP_MD_CTX_set_params(ctx, digest_cmd_params) <= 0
  407. || EVP_DigestFinal_ex(ctx, p, NULL) <= 0) {
  408. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  409. ret = 0;
  410. }
  411. }
  412. err:
  413. EVP_MD_CTX_free(ctx);
  414. return ret;
  415. }
  416. int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
  417. size_t len, size_t *secret_size)
  418. {
  419. static const unsigned char *salt[3] = {
  420. #ifndef CHARSET_EBCDIC
  421. (const unsigned char *)"A",
  422. (const unsigned char *)"BB",
  423. (const unsigned char *)"CCC",
  424. #else
  425. (const unsigned char *)"\x41",
  426. (const unsigned char *)"\x42\x42",
  427. (const unsigned char *)"\x43\x43\x43",
  428. #endif
  429. };
  430. unsigned char buf[EVP_MAX_MD_SIZE];
  431. EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  432. int i, ret = 1;
  433. unsigned int n;
  434. size_t ret_secret_size = 0;
  435. if (ctx == NULL) {
  436. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  437. return 0;
  438. }
  439. for (i = 0; i < 3; i++) {
  440. if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
  441. || EVP_DigestUpdate(ctx, salt[i],
  442. strlen((const char *)salt[i])) <= 0
  443. || EVP_DigestUpdate(ctx, p, len) <= 0
  444. || EVP_DigestUpdate(ctx, &(s->s3.client_random[0]),
  445. SSL3_RANDOM_SIZE) <= 0
  446. || EVP_DigestUpdate(ctx, &(s->s3.server_random[0]),
  447. SSL3_RANDOM_SIZE) <= 0
  448. /* TODO(size_t) : convert me */
  449. || EVP_DigestFinal_ex(ctx, buf, &n) <= 0
  450. || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0
  451. || EVP_DigestUpdate(ctx, p, len) <= 0
  452. || EVP_DigestUpdate(ctx, buf, n) <= 0
  453. || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {
  454. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  455. ret = 0;
  456. break;
  457. }
  458. out += n;
  459. ret_secret_size += n;
  460. }
  461. EVP_MD_CTX_free(ctx);
  462. OPENSSL_cleanse(buf, sizeof(buf));
  463. if (ret)
  464. *secret_size = ret_secret_size;
  465. return ret;
  466. }
  467. int ssl3_alert_code(int code)
  468. {
  469. switch (code) {
  470. case SSL_AD_CLOSE_NOTIFY:
  471. return SSL3_AD_CLOSE_NOTIFY;
  472. case SSL_AD_UNEXPECTED_MESSAGE:
  473. return SSL3_AD_UNEXPECTED_MESSAGE;
  474. case SSL_AD_BAD_RECORD_MAC:
  475. return SSL3_AD_BAD_RECORD_MAC;
  476. case SSL_AD_DECRYPTION_FAILED:
  477. return SSL3_AD_BAD_RECORD_MAC;
  478. case SSL_AD_RECORD_OVERFLOW:
  479. return SSL3_AD_BAD_RECORD_MAC;
  480. case SSL_AD_DECOMPRESSION_FAILURE:
  481. return SSL3_AD_DECOMPRESSION_FAILURE;
  482. case SSL_AD_HANDSHAKE_FAILURE:
  483. return SSL3_AD_HANDSHAKE_FAILURE;
  484. case SSL_AD_NO_CERTIFICATE:
  485. return SSL3_AD_NO_CERTIFICATE;
  486. case SSL_AD_BAD_CERTIFICATE:
  487. return SSL3_AD_BAD_CERTIFICATE;
  488. case SSL_AD_UNSUPPORTED_CERTIFICATE:
  489. return SSL3_AD_UNSUPPORTED_CERTIFICATE;
  490. case SSL_AD_CERTIFICATE_REVOKED:
  491. return SSL3_AD_CERTIFICATE_REVOKED;
  492. case SSL_AD_CERTIFICATE_EXPIRED:
  493. return SSL3_AD_CERTIFICATE_EXPIRED;
  494. case SSL_AD_CERTIFICATE_UNKNOWN:
  495. return SSL3_AD_CERTIFICATE_UNKNOWN;
  496. case SSL_AD_ILLEGAL_PARAMETER:
  497. return SSL3_AD_ILLEGAL_PARAMETER;
  498. case SSL_AD_UNKNOWN_CA:
  499. return SSL3_AD_BAD_CERTIFICATE;
  500. case SSL_AD_ACCESS_DENIED:
  501. return SSL3_AD_HANDSHAKE_FAILURE;
  502. case SSL_AD_DECODE_ERROR:
  503. return SSL3_AD_HANDSHAKE_FAILURE;
  504. case SSL_AD_DECRYPT_ERROR:
  505. return SSL3_AD_HANDSHAKE_FAILURE;
  506. case SSL_AD_EXPORT_RESTRICTION:
  507. return SSL3_AD_HANDSHAKE_FAILURE;
  508. case SSL_AD_PROTOCOL_VERSION:
  509. return SSL3_AD_HANDSHAKE_FAILURE;
  510. case SSL_AD_INSUFFICIENT_SECURITY:
  511. return SSL3_AD_HANDSHAKE_FAILURE;
  512. case SSL_AD_INTERNAL_ERROR:
  513. return SSL3_AD_HANDSHAKE_FAILURE;
  514. case SSL_AD_USER_CANCELLED:
  515. return SSL3_AD_HANDSHAKE_FAILURE;
  516. case SSL_AD_NO_RENEGOTIATION:
  517. return -1; /* Don't send it :-) */
  518. case SSL_AD_UNSUPPORTED_EXTENSION:
  519. return SSL3_AD_HANDSHAKE_FAILURE;
  520. case SSL_AD_CERTIFICATE_UNOBTAINABLE:
  521. return SSL3_AD_HANDSHAKE_FAILURE;
  522. case SSL_AD_UNRECOGNIZED_NAME:
  523. return SSL3_AD_HANDSHAKE_FAILURE;
  524. case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
  525. return SSL3_AD_HANDSHAKE_FAILURE;
  526. case SSL_AD_BAD_CERTIFICATE_HASH_VALUE:
  527. return SSL3_AD_HANDSHAKE_FAILURE;
  528. case SSL_AD_UNKNOWN_PSK_IDENTITY:
  529. return TLS1_AD_UNKNOWN_PSK_IDENTITY;
  530. case SSL_AD_INAPPROPRIATE_FALLBACK:
  531. return TLS1_AD_INAPPROPRIATE_FALLBACK;
  532. case SSL_AD_NO_APPLICATION_PROTOCOL:
  533. return TLS1_AD_NO_APPLICATION_PROTOCOL;
  534. case SSL_AD_CERTIFICATE_REQUIRED:
  535. return SSL_AD_HANDSHAKE_FAILURE;
  536. default:
  537. return -1;
  538. }
  539. }