2
0

t1_enc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /*
  2. * Copyright 1995-2024 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 "record/record_local.h"
  13. #include "internal/ktls.h"
  14. #include "internal/cryptlib.h"
  15. #include "internal/ssl_unwrap.h"
  16. #include <openssl/comp.h>
  17. #include <openssl/evp.h>
  18. #include <openssl/kdf.h>
  19. #include <openssl/rand.h>
  20. #include <openssl/obj_mac.h>
  21. #include <openssl/core_names.h>
  22. #include <openssl/trace.h>
  23. /* seed1 through seed5 are concatenated */
  24. static int tls1_PRF(SSL_CONNECTION *s,
  25. const void *seed1, size_t seed1_len,
  26. const void *seed2, size_t seed2_len,
  27. const void *seed3, size_t seed3_len,
  28. const void *seed4, size_t seed4_len,
  29. const void *seed5, size_t seed5_len,
  30. const unsigned char *sec, size_t slen,
  31. unsigned char *out, size_t olen, int fatal)
  32. {
  33. const EVP_MD *md = ssl_prf_md(s);
  34. EVP_KDF *kdf;
  35. EVP_KDF_CTX *kctx = NULL;
  36. OSSL_PARAM params[8], *p = params;
  37. const char *mdname;
  38. if (md == NULL) {
  39. /* Should never happen */
  40. if (fatal)
  41. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  42. else
  43. ERR_raise(ERR_LIB_SSL, ERR_R_INTERNAL_ERROR);
  44. return 0;
  45. }
  46. kdf = EVP_KDF_fetch(SSL_CONNECTION_GET_CTX(s)->libctx,
  47. OSSL_KDF_NAME_TLS1_PRF,
  48. SSL_CONNECTION_GET_CTX(s)->propq);
  49. if (kdf == NULL)
  50. goto err;
  51. kctx = EVP_KDF_CTX_new(kdf);
  52. EVP_KDF_free(kdf);
  53. if (kctx == NULL)
  54. goto err;
  55. mdname = EVP_MD_get0_name(md);
  56. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
  57. (char *)mdname, 0);
  58. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
  59. (unsigned char *)sec,
  60. (size_t)slen);
  61. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
  62. (void *)seed1, (size_t)seed1_len);
  63. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
  64. (void *)seed2, (size_t)seed2_len);
  65. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
  66. (void *)seed3, (size_t)seed3_len);
  67. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
  68. (void *)seed4, (size_t)seed4_len);
  69. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
  70. (void *)seed5, (size_t)seed5_len);
  71. *p = OSSL_PARAM_construct_end();
  72. if (EVP_KDF_derive(kctx, out, olen, params)) {
  73. EVP_KDF_CTX_free(kctx);
  74. return 1;
  75. }
  76. err:
  77. if (fatal)
  78. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  79. else
  80. ERR_raise(ERR_LIB_SSL, ERR_R_INTERNAL_ERROR);
  81. EVP_KDF_CTX_free(kctx);
  82. return 0;
  83. }
  84. static int tls1_generate_key_block(SSL_CONNECTION *s, unsigned char *km,
  85. size_t num)
  86. {
  87. int ret;
  88. /* Calls SSLfatal() as required */
  89. ret = tls1_PRF(s,
  90. TLS_MD_KEY_EXPANSION_CONST,
  91. TLS_MD_KEY_EXPANSION_CONST_SIZE, s->s3.server_random,
  92. SSL3_RANDOM_SIZE, s->s3.client_random, SSL3_RANDOM_SIZE,
  93. NULL, 0, NULL, 0, s->session->master_key,
  94. s->session->master_key_length, km, num, 1);
  95. return ret;
  96. }
  97. static int tls_iv_length_within_key_block(const EVP_CIPHER *c)
  98. {
  99. /* If GCM/CCM mode only part of IV comes from PRF */
  100. if (EVP_CIPHER_get_mode(c) == EVP_CIPH_GCM_MODE)
  101. return EVP_GCM_TLS_FIXED_IV_LEN;
  102. else if (EVP_CIPHER_get_mode(c) == EVP_CIPH_CCM_MODE)
  103. return EVP_CCM_TLS_FIXED_IV_LEN;
  104. else
  105. return EVP_CIPHER_get_iv_length(c);
  106. }
  107. int tls1_change_cipher_state(SSL_CONNECTION *s, int which)
  108. {
  109. unsigned char *p, *mac_secret;
  110. unsigned char *key, *iv;
  111. const EVP_CIPHER *c;
  112. const SSL_COMP *comp = NULL;
  113. const EVP_MD *m;
  114. int mac_type;
  115. size_t mac_secret_size;
  116. size_t n, i, j, k, cl;
  117. int iivlen;
  118. /*
  119. * Taglen is only relevant for CCM ciphersuites. Other ciphersuites
  120. * ignore this value so we can default it to 0.
  121. */
  122. size_t taglen = 0;
  123. int direction;
  124. c = s->s3.tmp.new_sym_enc;
  125. m = s->s3.tmp.new_hash;
  126. mac_type = s->s3.tmp.new_mac_pkey_type;
  127. #ifndef OPENSSL_NO_COMP
  128. comp = s->s3.tmp.new_compression;
  129. #endif
  130. p = s->s3.tmp.key_block;
  131. i = mac_secret_size = s->s3.tmp.new_mac_secret_size;
  132. cl = EVP_CIPHER_get_key_length(c);
  133. j = cl;
  134. iivlen = tls_iv_length_within_key_block(c);
  135. if (iivlen < 0) {
  136. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  137. goto err;
  138. }
  139. k = iivlen;
  140. if ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
  141. (which == SSL3_CHANGE_CIPHER_SERVER_READ)) {
  142. mac_secret = &(p[0]);
  143. n = i + i;
  144. key = &(p[n]);
  145. n += j + j;
  146. iv = &(p[n]);
  147. n += k + k;
  148. } else {
  149. n = i;
  150. mac_secret = &(p[n]);
  151. n += i + j;
  152. key = &(p[n]);
  153. n += j + k;
  154. iv = &(p[n]);
  155. n += k;
  156. }
  157. if (n > s->s3.tmp.key_block_length) {
  158. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  159. goto err;
  160. }
  161. switch (EVP_CIPHER_get_mode(c)) {
  162. case EVP_CIPH_GCM_MODE:
  163. taglen = EVP_GCM_TLS_TAG_LEN;
  164. break;
  165. case EVP_CIPH_CCM_MODE:
  166. if ((s->s3.tmp.new_cipher->algorithm_enc
  167. & (SSL_AES128CCM8 | SSL_AES256CCM8)) != 0)
  168. taglen = EVP_CCM8_TLS_TAG_LEN;
  169. else
  170. taglen = EVP_CCM_TLS_TAG_LEN;
  171. break;
  172. default:
  173. if (EVP_CIPHER_is_a(c, "CHACHA20-POLY1305")) {
  174. taglen = EVP_CHACHAPOLY_TLS_TAG_LEN;
  175. } else {
  176. /* MAC secret size corresponds to the MAC output size */
  177. taglen = s->s3.tmp.new_mac_secret_size;
  178. }
  179. break;
  180. }
  181. if (which & SSL3_CC_READ) {
  182. if (s->ext.use_etm)
  183. s->s3.flags |= TLS1_FLAGS_ENCRYPT_THEN_MAC_READ;
  184. else
  185. s->s3.flags &= ~TLS1_FLAGS_ENCRYPT_THEN_MAC_READ;
  186. if (s->s3.tmp.new_cipher->algorithm2 & TLS1_STREAM_MAC)
  187. s->mac_flags |= SSL_MAC_FLAG_READ_MAC_STREAM;
  188. else
  189. s->mac_flags &= ~SSL_MAC_FLAG_READ_MAC_STREAM;
  190. if (s->s3.tmp.new_cipher->algorithm2 & TLS1_TLSTREE)
  191. s->mac_flags |= SSL_MAC_FLAG_READ_MAC_TLSTREE;
  192. else
  193. s->mac_flags &= ~SSL_MAC_FLAG_READ_MAC_TLSTREE;
  194. direction = OSSL_RECORD_DIRECTION_READ;
  195. } else {
  196. if (s->ext.use_etm)
  197. s->s3.flags |= TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE;
  198. else
  199. s->s3.flags &= ~TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE;
  200. if (s->s3.tmp.new_cipher->algorithm2 & TLS1_STREAM_MAC)
  201. s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM;
  202. else
  203. s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM;
  204. if (s->s3.tmp.new_cipher->algorithm2 & TLS1_TLSTREE)
  205. s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_TLSTREE;
  206. else
  207. s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_TLSTREE;
  208. direction = OSSL_RECORD_DIRECTION_WRITE;
  209. }
  210. if (SSL_CONNECTION_IS_DTLS(s))
  211. dtls1_increment_epoch(s, which);
  212. if (!ssl_set_new_record_layer(s, s->version, direction,
  213. OSSL_RECORD_PROTECTION_LEVEL_APPLICATION,
  214. NULL, 0, key, cl, iv, (size_t)k, mac_secret,
  215. mac_secret_size, c, taglen, mac_type,
  216. m, comp, NULL)) {
  217. /* SSLfatal already called */
  218. goto err;
  219. }
  220. OSSL_TRACE_BEGIN(TLS) {
  221. BIO_printf(trc_out, "which = %04X, key:\n", which);
  222. BIO_dump_indent(trc_out, key, EVP_CIPHER_get_key_length(c), 4);
  223. BIO_printf(trc_out, "iv:\n");
  224. BIO_dump_indent(trc_out, iv, k, 4);
  225. } OSSL_TRACE_END(TLS);
  226. return 1;
  227. err:
  228. return 0;
  229. }
  230. int tls1_setup_key_block(SSL_CONNECTION *s)
  231. {
  232. unsigned char *p;
  233. const EVP_CIPHER *c;
  234. const EVP_MD *hash;
  235. SSL_COMP *comp;
  236. int mac_type = NID_undef;
  237. size_t num, mac_secret_size = 0;
  238. int ret = 0;
  239. int ivlen;
  240. if (s->s3.tmp.key_block_length != 0)
  241. return 1;
  242. if (!ssl_cipher_get_evp(SSL_CONNECTION_GET_CTX(s), s->session, &c, &hash,
  243. &mac_type, &mac_secret_size, &comp,
  244. s->ext.use_etm)) {
  245. /* Error is already recorded */
  246. SSLfatal_alert(s, SSL_AD_INTERNAL_ERROR);
  247. return 0;
  248. }
  249. ssl_evp_cipher_free(s->s3.tmp.new_sym_enc);
  250. s->s3.tmp.new_sym_enc = c;
  251. ssl_evp_md_free(s->s3.tmp.new_hash);
  252. s->s3.tmp.new_hash = hash;
  253. s->s3.tmp.new_mac_pkey_type = mac_type;
  254. s->s3.tmp.new_mac_secret_size = mac_secret_size;
  255. ivlen = tls_iv_length_within_key_block(c);
  256. if (ivlen < 0) {
  257. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  258. return 0;
  259. }
  260. num = mac_secret_size + EVP_CIPHER_get_key_length(c) + ivlen;
  261. num *= 2;
  262. ssl3_cleanup_key_block(s);
  263. if ((p = OPENSSL_malloc(num)) == NULL) {
  264. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_CRYPTO_LIB);
  265. goto err;
  266. }
  267. s->s3.tmp.key_block_length = num;
  268. s->s3.tmp.key_block = p;
  269. OSSL_TRACE_BEGIN(TLS) {
  270. BIO_printf(trc_out, "key block length: %zu\n", num);
  271. BIO_printf(trc_out, "client random\n");
  272. BIO_dump_indent(trc_out, s->s3.client_random, SSL3_RANDOM_SIZE, 4);
  273. BIO_printf(trc_out, "server random\n");
  274. BIO_dump_indent(trc_out, s->s3.server_random, SSL3_RANDOM_SIZE, 4);
  275. BIO_printf(trc_out, "master key\n");
  276. BIO_dump_indent(trc_out,
  277. s->session->master_key,
  278. s->session->master_key_length, 4);
  279. } OSSL_TRACE_END(TLS);
  280. if (!tls1_generate_key_block(s, p, num)) {
  281. /* SSLfatal() already called */
  282. goto err;
  283. }
  284. OSSL_TRACE_BEGIN(TLS) {
  285. BIO_printf(trc_out, "key block\n");
  286. BIO_dump_indent(trc_out, p, num, 4);
  287. } OSSL_TRACE_END(TLS);
  288. ret = 1;
  289. err:
  290. return ret;
  291. }
  292. size_t tls1_final_finish_mac(SSL_CONNECTION *s, const char *str,
  293. size_t slen, unsigned char *out)
  294. {
  295. size_t hashlen;
  296. unsigned char hash[EVP_MAX_MD_SIZE];
  297. size_t finished_size = TLS1_FINISH_MAC_LENGTH;
  298. if (s->s3.tmp.new_cipher->algorithm_mkey & SSL_kGOST18)
  299. finished_size = 32;
  300. if (!ssl3_digest_cached_records(s, 0)) {
  301. /* SSLfatal() already called */
  302. return 0;
  303. }
  304. if (!ssl_handshake_hash(s, hash, sizeof(hash), &hashlen)) {
  305. /* SSLfatal() already called */
  306. return 0;
  307. }
  308. if (!tls1_PRF(s, str, slen, hash, hashlen, NULL, 0, NULL, 0, NULL, 0,
  309. s->session->master_key, s->session->master_key_length,
  310. out, finished_size, 1)) {
  311. /* SSLfatal() already called */
  312. return 0;
  313. }
  314. OPENSSL_cleanse(hash, hashlen);
  315. return finished_size;
  316. }
  317. int tls1_generate_master_secret(SSL_CONNECTION *s, unsigned char *out,
  318. unsigned char *p, size_t len,
  319. size_t *secret_size)
  320. {
  321. if (s->session->flags & SSL_SESS_FLAG_EXTMS) {
  322. unsigned char hash[EVP_MAX_MD_SIZE * 2];
  323. size_t hashlen;
  324. /*
  325. * Digest cached records keeping record buffer (if present): this won't
  326. * affect client auth because we're freezing the buffer at the same
  327. * point (after client key exchange and before certificate verify)
  328. */
  329. if (!ssl3_digest_cached_records(s, 1)
  330. || !ssl_handshake_hash(s, hash, sizeof(hash), &hashlen)) {
  331. /* SSLfatal() already called */
  332. return 0;
  333. }
  334. OSSL_TRACE_BEGIN(TLS) {
  335. BIO_printf(trc_out, "Handshake hashes:\n");
  336. BIO_dump(trc_out, (char *)hash, hashlen);
  337. } OSSL_TRACE_END(TLS);
  338. if (!tls1_PRF(s,
  339. TLS_MD_EXTENDED_MASTER_SECRET_CONST,
  340. TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE,
  341. hash, hashlen,
  342. NULL, 0,
  343. NULL, 0,
  344. NULL, 0, p, len, out,
  345. SSL3_MASTER_SECRET_SIZE, 1)) {
  346. /* SSLfatal() already called */
  347. return 0;
  348. }
  349. OPENSSL_cleanse(hash, hashlen);
  350. } else {
  351. if (!tls1_PRF(s,
  352. TLS_MD_MASTER_SECRET_CONST,
  353. TLS_MD_MASTER_SECRET_CONST_SIZE,
  354. s->s3.client_random, SSL3_RANDOM_SIZE,
  355. NULL, 0,
  356. s->s3.server_random, SSL3_RANDOM_SIZE,
  357. NULL, 0, p, len, out,
  358. SSL3_MASTER_SECRET_SIZE, 1)) {
  359. /* SSLfatal() already called */
  360. return 0;
  361. }
  362. }
  363. OSSL_TRACE_BEGIN(TLS) {
  364. BIO_printf(trc_out, "Premaster Secret:\n");
  365. BIO_dump_indent(trc_out, p, len, 4);
  366. BIO_printf(trc_out, "Client Random:\n");
  367. BIO_dump_indent(trc_out, s->s3.client_random, SSL3_RANDOM_SIZE, 4);
  368. BIO_printf(trc_out, "Server Random:\n");
  369. BIO_dump_indent(trc_out, s->s3.server_random, SSL3_RANDOM_SIZE, 4);
  370. BIO_printf(trc_out, "Master Secret:\n");
  371. BIO_dump_indent(trc_out,
  372. s->session->master_key,
  373. SSL3_MASTER_SECRET_SIZE, 4);
  374. } OSSL_TRACE_END(TLS);
  375. *secret_size = SSL3_MASTER_SECRET_SIZE;
  376. return 1;
  377. }
  378. int tls1_export_keying_material(SSL_CONNECTION *s, unsigned char *out,
  379. size_t olen, const char *label, size_t llen,
  380. const unsigned char *context,
  381. size_t contextlen, int use_context)
  382. {
  383. unsigned char *val = NULL;
  384. size_t vallen = 0, currentvalpos;
  385. int rv = 0;
  386. /*
  387. * RFC 5705 embeds context length as uint16; reject longer context
  388. * before proceeding.
  389. */
  390. if (contextlen > 0xffff) {
  391. ERR_raise(ERR_LIB_SSL, ERR_R_PASSED_INVALID_ARGUMENT);
  392. return 0;
  393. }
  394. /*
  395. * construct PRF arguments we construct the PRF argument ourself rather
  396. * than passing separate values into the TLS PRF to ensure that the
  397. * concatenation of values does not create a prohibited label.
  398. */
  399. vallen = llen + SSL3_RANDOM_SIZE * 2;
  400. if (use_context) {
  401. vallen += 2 + contextlen;
  402. }
  403. val = OPENSSL_malloc(vallen);
  404. if (val == NULL)
  405. goto ret;
  406. currentvalpos = 0;
  407. memcpy(val + currentvalpos, (unsigned char *)label, llen);
  408. currentvalpos += llen;
  409. memcpy(val + currentvalpos, s->s3.client_random, SSL3_RANDOM_SIZE);
  410. currentvalpos += SSL3_RANDOM_SIZE;
  411. memcpy(val + currentvalpos, s->s3.server_random, SSL3_RANDOM_SIZE);
  412. currentvalpos += SSL3_RANDOM_SIZE;
  413. if (use_context) {
  414. val[currentvalpos] = (contextlen >> 8) & 0xff;
  415. currentvalpos++;
  416. val[currentvalpos] = contextlen & 0xff;
  417. currentvalpos++;
  418. if ((contextlen > 0) || (context != NULL)) {
  419. memcpy(val + currentvalpos, context, contextlen);
  420. }
  421. }
  422. /*
  423. * disallow prohibited labels note that SSL3_RANDOM_SIZE > max(prohibited
  424. * label len) = 15, so size of val > max(prohibited label len) = 15 and
  425. * the comparisons won't have buffer overflow
  426. */
  427. if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,
  428. TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)
  429. goto err1;
  430. if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,
  431. TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)
  432. goto err1;
  433. if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,
  434. TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)
  435. goto err1;
  436. if (memcmp(val, TLS_MD_EXTENDED_MASTER_SECRET_CONST,
  437. TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE) == 0)
  438. goto err1;
  439. if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,
  440. TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)
  441. goto err1;
  442. rv = tls1_PRF(s,
  443. val, vallen,
  444. NULL, 0,
  445. NULL, 0,
  446. NULL, 0,
  447. NULL, 0,
  448. s->session->master_key, s->session->master_key_length,
  449. out, olen, 0);
  450. goto ret;
  451. err1:
  452. ERR_raise(ERR_LIB_SSL, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
  453. ret:
  454. OPENSSL_clear_free(val, vallen);
  455. return rv;
  456. }
  457. int tls1_alert_code(int code)
  458. {
  459. switch (code) {
  460. case SSL_AD_CLOSE_NOTIFY:
  461. return SSL3_AD_CLOSE_NOTIFY;
  462. case SSL_AD_UNEXPECTED_MESSAGE:
  463. return SSL3_AD_UNEXPECTED_MESSAGE;
  464. case SSL_AD_BAD_RECORD_MAC:
  465. return SSL3_AD_BAD_RECORD_MAC;
  466. case SSL_AD_DECRYPTION_FAILED:
  467. return TLS1_AD_DECRYPTION_FAILED;
  468. case SSL_AD_RECORD_OVERFLOW:
  469. return TLS1_AD_RECORD_OVERFLOW;
  470. case SSL_AD_DECOMPRESSION_FAILURE:
  471. return SSL3_AD_DECOMPRESSION_FAILURE;
  472. case SSL_AD_HANDSHAKE_FAILURE:
  473. return SSL3_AD_HANDSHAKE_FAILURE;
  474. case SSL_AD_NO_CERTIFICATE:
  475. return -1;
  476. case SSL_AD_BAD_CERTIFICATE:
  477. return SSL3_AD_BAD_CERTIFICATE;
  478. case SSL_AD_UNSUPPORTED_CERTIFICATE:
  479. return SSL3_AD_UNSUPPORTED_CERTIFICATE;
  480. case SSL_AD_CERTIFICATE_REVOKED:
  481. return SSL3_AD_CERTIFICATE_REVOKED;
  482. case SSL_AD_CERTIFICATE_EXPIRED:
  483. return SSL3_AD_CERTIFICATE_EXPIRED;
  484. case SSL_AD_CERTIFICATE_UNKNOWN:
  485. return SSL3_AD_CERTIFICATE_UNKNOWN;
  486. case SSL_AD_ILLEGAL_PARAMETER:
  487. return SSL3_AD_ILLEGAL_PARAMETER;
  488. case SSL_AD_UNKNOWN_CA:
  489. return TLS1_AD_UNKNOWN_CA;
  490. case SSL_AD_ACCESS_DENIED:
  491. return TLS1_AD_ACCESS_DENIED;
  492. case SSL_AD_DECODE_ERROR:
  493. return TLS1_AD_DECODE_ERROR;
  494. case SSL_AD_DECRYPT_ERROR:
  495. return TLS1_AD_DECRYPT_ERROR;
  496. case SSL_AD_EXPORT_RESTRICTION:
  497. return TLS1_AD_EXPORT_RESTRICTION;
  498. case SSL_AD_PROTOCOL_VERSION:
  499. return TLS1_AD_PROTOCOL_VERSION;
  500. case SSL_AD_INSUFFICIENT_SECURITY:
  501. return TLS1_AD_INSUFFICIENT_SECURITY;
  502. case SSL_AD_INTERNAL_ERROR:
  503. return TLS1_AD_INTERNAL_ERROR;
  504. case SSL_AD_USER_CANCELLED:
  505. return TLS1_AD_USER_CANCELLED;
  506. case SSL_AD_NO_RENEGOTIATION:
  507. return TLS1_AD_NO_RENEGOTIATION;
  508. case SSL_AD_UNSUPPORTED_EXTENSION:
  509. return TLS1_AD_UNSUPPORTED_EXTENSION;
  510. case SSL_AD_CERTIFICATE_UNOBTAINABLE:
  511. return TLS1_AD_CERTIFICATE_UNOBTAINABLE;
  512. case SSL_AD_UNRECOGNIZED_NAME:
  513. return TLS1_AD_UNRECOGNIZED_NAME;
  514. case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
  515. return TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE;
  516. case SSL_AD_BAD_CERTIFICATE_HASH_VALUE:
  517. return TLS1_AD_BAD_CERTIFICATE_HASH_VALUE;
  518. case SSL_AD_UNKNOWN_PSK_IDENTITY:
  519. return TLS1_AD_UNKNOWN_PSK_IDENTITY;
  520. case SSL_AD_INAPPROPRIATE_FALLBACK:
  521. return TLS1_AD_INAPPROPRIATE_FALLBACK;
  522. case SSL_AD_NO_APPLICATION_PROTOCOL:
  523. return TLS1_AD_NO_APPLICATION_PROTOCOL;
  524. case SSL_AD_CERTIFICATE_REQUIRED:
  525. return SSL_AD_HANDSHAKE_FAILURE;
  526. case TLS13_AD_MISSING_EXTENSION:
  527. return SSL_AD_HANDSHAKE_FAILURE;
  528. default:
  529. return -1;
  530. }
  531. }