s3_enc.c 16 KB

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