2
0

s3_enc.c 19 KB

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