s3_enc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*
  2. * Copyright 1995-2021 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_get_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_get_key_length(c);
  185. j = cl;
  186. k = EVP_CIPHER_get_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_get0_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. /* Error is already recorded */
  236. SSLfatal_alert(s, SSL_AD_INTERNAL_ERROR);
  237. return 0;
  238. }
  239. ssl_evp_cipher_free(s->s3.tmp.new_sym_enc);
  240. s->s3.tmp.new_sym_enc = c;
  241. ssl_evp_md_free(s->s3.tmp.new_hash);
  242. s->s3.tmp.new_hash = hash;
  243. #ifdef OPENSSL_NO_COMP
  244. s->s3.tmp.new_compression = NULL;
  245. #else
  246. s->s3.tmp.new_compression = comp;
  247. #endif
  248. num = EVP_MD_get_size(hash);
  249. if (num < 0)
  250. return 0;
  251. num = EVP_CIPHER_get_key_length(c) + num + EVP_CIPHER_get_iv_length(c);
  252. num *= 2;
  253. ssl3_cleanup_key_block(s);
  254. if ((p = OPENSSL_malloc(num)) == NULL) {
  255. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  256. return 0;
  257. }
  258. s->s3.tmp.key_block_length = num;
  259. s->s3.tmp.key_block = p;
  260. /* Calls SSLfatal() as required */
  261. ret = ssl3_generate_key_block(s, p, num);
  262. if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)) {
  263. /*
  264. * enable vulnerability countermeasure for CBC ciphers with known-IV
  265. * problem (http://www.openssl.org/~bodo/tls-cbc.txt)
  266. */
  267. s->s3.need_empty_fragments = 1;
  268. if (s->session->cipher != NULL) {
  269. if (s->session->cipher->algorithm_enc == SSL_eNULL)
  270. s->s3.need_empty_fragments = 0;
  271. if (s->session->cipher->algorithm_enc == SSL_RC4)
  272. s->s3.need_empty_fragments = 0;
  273. }
  274. }
  275. return ret;
  276. }
  277. void ssl3_cleanup_key_block(SSL *s)
  278. {
  279. OPENSSL_clear_free(s->s3.tmp.key_block, s->s3.tmp.key_block_length);
  280. s->s3.tmp.key_block = NULL;
  281. s->s3.tmp.key_block_length = 0;
  282. }
  283. int ssl3_init_finished_mac(SSL *s)
  284. {
  285. BIO *buf = BIO_new(BIO_s_mem());
  286. if (buf == NULL) {
  287. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  288. return 0;
  289. }
  290. ssl3_free_digest_list(s);
  291. s->s3.handshake_buffer = buf;
  292. (void)BIO_set_close(s->s3.handshake_buffer, BIO_CLOSE);
  293. return 1;
  294. }
  295. /*
  296. * Free digest list. Also frees handshake buffer since they are always freed
  297. * together.
  298. */
  299. void ssl3_free_digest_list(SSL *s)
  300. {
  301. BIO_free(s->s3.handshake_buffer);
  302. s->s3.handshake_buffer = NULL;
  303. EVP_MD_CTX_free(s->s3.handshake_dgst);
  304. s->s3.handshake_dgst = NULL;
  305. }
  306. int ssl3_finish_mac(SSL *s, const unsigned char *buf, size_t len)
  307. {
  308. int ret;
  309. if (s->s3.handshake_dgst == NULL) {
  310. /* Note: this writes to a memory BIO so a failure is a fatal error */
  311. if (len > INT_MAX) {
  312. SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_OVERFLOW_ERROR);
  313. return 0;
  314. }
  315. ret = BIO_write(s->s3.handshake_buffer, (void *)buf, (int)len);
  316. if (ret <= 0 || ret != (int)len) {
  317. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  318. return 0;
  319. }
  320. } else {
  321. ret = EVP_DigestUpdate(s->s3.handshake_dgst, buf, len);
  322. if (!ret) {
  323. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  324. return 0;
  325. }
  326. }
  327. return 1;
  328. }
  329. int ssl3_digest_cached_records(SSL *s, int keep)
  330. {
  331. const EVP_MD *md;
  332. long hdatalen;
  333. void *hdata;
  334. if (s->s3.handshake_dgst == NULL) {
  335. hdatalen = BIO_get_mem_data(s->s3.handshake_buffer, &hdata);
  336. if (hdatalen <= 0) {
  337. SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_BAD_HANDSHAKE_LENGTH);
  338. return 0;
  339. }
  340. s->s3.handshake_dgst = EVP_MD_CTX_new();
  341. if (s->s3.handshake_dgst == NULL) {
  342. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  343. return 0;
  344. }
  345. md = ssl_handshake_md(s);
  346. if (md == NULL) {
  347. SSLfatal(s, SSL_AD_INTERNAL_ERROR,
  348. SSL_R_NO_SUITABLE_DIGEST_ALGORITHM);
  349. return 0;
  350. }
  351. if (!EVP_DigestInit_ex(s->s3.handshake_dgst, md, NULL)
  352. || !EVP_DigestUpdate(s->s3.handshake_dgst, hdata, hdatalen)) {
  353. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  354. return 0;
  355. }
  356. }
  357. if (keep == 0) {
  358. BIO_free(s->s3.handshake_buffer);
  359. s->s3.handshake_buffer = NULL;
  360. }
  361. return 1;
  362. }
  363. void ssl3_digest_master_key_set_params(const SSL_SESSION *session,
  364. OSSL_PARAM params[])
  365. {
  366. int n = 0;
  367. params[n++] = OSSL_PARAM_construct_octet_string(OSSL_DIGEST_PARAM_SSL3_MS,
  368. (void *)session->master_key,
  369. session->master_key_length);
  370. params[n++] = OSSL_PARAM_construct_end();
  371. }
  372. size_t ssl3_final_finish_mac(SSL *s, const char *sender, size_t len,
  373. unsigned char *p)
  374. {
  375. int ret;
  376. EVP_MD_CTX *ctx = NULL;
  377. if (!ssl3_digest_cached_records(s, 0)) {
  378. /* SSLfatal() already called */
  379. return 0;
  380. }
  381. if (EVP_MD_CTX_get_type(s->s3.handshake_dgst) != NID_md5_sha1) {
  382. SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_NO_REQUIRED_DIGEST);
  383. return 0;
  384. }
  385. ctx = EVP_MD_CTX_new();
  386. if (ctx == NULL) {
  387. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  388. return 0;
  389. }
  390. if (!EVP_MD_CTX_copy_ex(ctx, s->s3.handshake_dgst)) {
  391. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  392. ret = 0;
  393. goto err;
  394. }
  395. ret = EVP_MD_CTX_get_size(ctx);
  396. if (ret < 0) {
  397. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  398. ret = 0;
  399. goto err;
  400. }
  401. if (sender != NULL) {
  402. OSSL_PARAM digest_cmd_params[3];
  403. ssl3_digest_master_key_set_params(s->session, digest_cmd_params);
  404. if (EVP_DigestUpdate(ctx, sender, len) <= 0
  405. || EVP_MD_CTX_set_params(ctx, digest_cmd_params) <= 0
  406. || EVP_DigestFinal_ex(ctx, p, NULL) <= 0) {
  407. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  408. ret = 0;
  409. }
  410. }
  411. err:
  412. EVP_MD_CTX_free(ctx);
  413. return ret;
  414. }
  415. int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
  416. size_t len, size_t *secret_size)
  417. {
  418. static const unsigned char *salt[3] = {
  419. #ifndef CHARSET_EBCDIC
  420. (const unsigned char *)"A",
  421. (const unsigned char *)"BB",
  422. (const unsigned char *)"CCC",
  423. #else
  424. (const unsigned char *)"\x41",
  425. (const unsigned char *)"\x42\x42",
  426. (const unsigned char *)"\x43\x43\x43",
  427. #endif
  428. };
  429. unsigned char buf[EVP_MAX_MD_SIZE];
  430. EVP_MD_CTX *ctx = EVP_MD_CTX_new();
  431. int i, ret = 1;
  432. unsigned int n;
  433. size_t ret_secret_size = 0;
  434. if (ctx == NULL) {
  435. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
  436. return 0;
  437. }
  438. for (i = 0; i < 3; i++) {
  439. if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
  440. || EVP_DigestUpdate(ctx, salt[i],
  441. strlen((const char *)salt[i])) <= 0
  442. || EVP_DigestUpdate(ctx, p, len) <= 0
  443. || EVP_DigestUpdate(ctx, &(s->s3.client_random[0]),
  444. SSL3_RANDOM_SIZE) <= 0
  445. || EVP_DigestUpdate(ctx, &(s->s3.server_random[0]),
  446. SSL3_RANDOM_SIZE) <= 0
  447. || EVP_DigestFinal_ex(ctx, buf, &n) <= 0
  448. || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0
  449. || EVP_DigestUpdate(ctx, p, len) <= 0
  450. || EVP_DigestUpdate(ctx, buf, n) <= 0
  451. || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {
  452. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  453. ret = 0;
  454. break;
  455. }
  456. out += n;
  457. ret_secret_size += n;
  458. }
  459. EVP_MD_CTX_free(ctx);
  460. OPENSSL_cleanse(buf, sizeof(buf));
  461. if (ret)
  462. *secret_size = ret_secret_size;
  463. return ret;
  464. }
  465. int ssl3_alert_code(int code)
  466. {
  467. switch (code) {
  468. case SSL_AD_CLOSE_NOTIFY:
  469. return SSL3_AD_CLOSE_NOTIFY;
  470. case SSL_AD_UNEXPECTED_MESSAGE:
  471. return SSL3_AD_UNEXPECTED_MESSAGE;
  472. case SSL_AD_BAD_RECORD_MAC:
  473. return SSL3_AD_BAD_RECORD_MAC;
  474. case SSL_AD_DECRYPTION_FAILED:
  475. return SSL3_AD_BAD_RECORD_MAC;
  476. case SSL_AD_RECORD_OVERFLOW:
  477. return SSL3_AD_BAD_RECORD_MAC;
  478. case SSL_AD_DECOMPRESSION_FAILURE:
  479. return SSL3_AD_DECOMPRESSION_FAILURE;
  480. case SSL_AD_HANDSHAKE_FAILURE:
  481. return SSL3_AD_HANDSHAKE_FAILURE;
  482. case SSL_AD_NO_CERTIFICATE:
  483. return SSL3_AD_NO_CERTIFICATE;
  484. case SSL_AD_BAD_CERTIFICATE:
  485. return SSL3_AD_BAD_CERTIFICATE;
  486. case SSL_AD_UNSUPPORTED_CERTIFICATE:
  487. return SSL3_AD_UNSUPPORTED_CERTIFICATE;
  488. case SSL_AD_CERTIFICATE_REVOKED:
  489. return SSL3_AD_CERTIFICATE_REVOKED;
  490. case SSL_AD_CERTIFICATE_EXPIRED:
  491. return SSL3_AD_CERTIFICATE_EXPIRED;
  492. case SSL_AD_CERTIFICATE_UNKNOWN:
  493. return SSL3_AD_CERTIFICATE_UNKNOWN;
  494. case SSL_AD_ILLEGAL_PARAMETER:
  495. return SSL3_AD_ILLEGAL_PARAMETER;
  496. case SSL_AD_UNKNOWN_CA:
  497. return SSL3_AD_BAD_CERTIFICATE;
  498. case SSL_AD_ACCESS_DENIED:
  499. return SSL3_AD_HANDSHAKE_FAILURE;
  500. case SSL_AD_DECODE_ERROR:
  501. return SSL3_AD_HANDSHAKE_FAILURE;
  502. case SSL_AD_DECRYPT_ERROR:
  503. return SSL3_AD_HANDSHAKE_FAILURE;
  504. case SSL_AD_EXPORT_RESTRICTION:
  505. return SSL3_AD_HANDSHAKE_FAILURE;
  506. case SSL_AD_PROTOCOL_VERSION:
  507. return SSL3_AD_HANDSHAKE_FAILURE;
  508. case SSL_AD_INSUFFICIENT_SECURITY:
  509. return SSL3_AD_HANDSHAKE_FAILURE;
  510. case SSL_AD_INTERNAL_ERROR:
  511. return SSL3_AD_HANDSHAKE_FAILURE;
  512. case SSL_AD_USER_CANCELLED:
  513. return SSL3_AD_HANDSHAKE_FAILURE;
  514. case SSL_AD_NO_RENEGOTIATION:
  515. return -1; /* Don't send it :-) */
  516. case SSL_AD_UNSUPPORTED_EXTENSION:
  517. return SSL3_AD_HANDSHAKE_FAILURE;
  518. case SSL_AD_CERTIFICATE_UNOBTAINABLE:
  519. return SSL3_AD_HANDSHAKE_FAILURE;
  520. case SSL_AD_UNRECOGNIZED_NAME:
  521. return SSL3_AD_HANDSHAKE_FAILURE;
  522. case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
  523. return SSL3_AD_HANDSHAKE_FAILURE;
  524. case SSL_AD_BAD_CERTIFICATE_HASH_VALUE:
  525. return SSL3_AD_HANDSHAKE_FAILURE;
  526. case SSL_AD_UNKNOWN_PSK_IDENTITY:
  527. return TLS1_AD_UNKNOWN_PSK_IDENTITY;
  528. case SSL_AD_INAPPROPRIATE_FALLBACK:
  529. return TLS1_AD_INAPPROPRIATE_FALLBACK;
  530. case SSL_AD_NO_APPLICATION_PROTOCOL:
  531. return TLS1_AD_NO_APPLICATION_PROTOCOL;
  532. case SSL_AD_CERTIFICATE_REQUIRED:
  533. return SSL_AD_HANDSHAKE_FAILURE;
  534. case TLS13_AD_MISSING_EXTENSION:
  535. return SSL_AD_HANDSHAKE_FAILURE;
  536. default:
  537. return -1;
  538. }
  539. }