s3_enc.c 18 KB

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