s3_enc.c 18 KB

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