2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2005 Nokia. All rights reserved.
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
13 #include <openssl/comp.h>
14 #include <openssl/evp.h>
15 #include <openssl/kdf.h>
16 #include <openssl/rand.h>
18 /* seed1 through seed5 are concatenated */
19 static int tls1_PRF(SSL *s,
20 const void *seed1, size_t seed1_len,
21 const void *seed2, size_t seed2_len,
22 const void *seed3, size_t seed3_len,
23 const void *seed4, size_t seed4_len,
24 const void *seed5, size_t seed5_len,
25 const unsigned char *sec, size_t slen,
26 unsigned char *out, size_t olen, int fatal)
28 const EVP_MD *md = ssl_prf_md(s);
29 EVP_PKEY_CTX *pctx = NULL;
33 /* Should never happen */
35 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_PRF,
36 ERR_R_INTERNAL_ERROR);
38 SSLerr(SSL_F_TLS1_PRF, ERR_R_INTERNAL_ERROR);
41 pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL);
42 if (pctx == NULL || EVP_PKEY_derive_init(pctx) <= 0
43 || EVP_PKEY_CTX_set_tls1_prf_md(pctx, md) <= 0
44 || EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, sec, (int)slen) <= 0
45 || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed1, (int)seed1_len) <= 0
46 || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed2, (int)seed2_len) <= 0
47 || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed3, (int)seed3_len) <= 0
48 || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed4, (int)seed4_len) <= 0
49 || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed5, (int)seed5_len) <= 0
50 || EVP_PKEY_derive(pctx, out, &olen) <= 0) {
52 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_PRF,
53 ERR_R_INTERNAL_ERROR);
55 SSLerr(SSL_F_TLS1_PRF, ERR_R_INTERNAL_ERROR);
62 EVP_PKEY_CTX_free(pctx);
66 static int tls1_generate_key_block(SSL *s, unsigned char *km, size_t num)
70 /* Calls SSLfatal() as required */
72 TLS_MD_KEY_EXPANSION_CONST,
73 TLS_MD_KEY_EXPANSION_CONST_SIZE, s->s3->server_random,
74 SSL3_RANDOM_SIZE, s->s3->client_random, SSL3_RANDOM_SIZE,
75 NULL, 0, NULL, 0, s->session->master_key,
76 s->session->master_key_length, km, num, 1);
81 int tls1_change_cipher_state(SSL *s, int which)
83 unsigned char *p, *mac_secret;
84 unsigned char tmp1[EVP_MAX_KEY_LENGTH];
85 unsigned char tmp2[EVP_MAX_KEY_LENGTH];
86 unsigned char iv1[EVP_MAX_IV_LENGTH * 2];
87 unsigned char iv2[EVP_MAX_IV_LENGTH * 2];
88 unsigned char *ms, *key, *iv;
91 #ifndef OPENSSL_NO_COMP
96 size_t *mac_secret_size;
99 size_t n, i, j, k, cl;
102 c = s->s3->tmp.new_sym_enc;
103 m = s->s3->tmp.new_hash;
104 mac_type = s->s3->tmp.new_mac_pkey_type;
105 #ifndef OPENSSL_NO_COMP
106 comp = s->s3->tmp.new_compression;
109 if (which & SSL3_CC_READ) {
111 s->s3->flags |= TLS1_FLAGS_ENCRYPT_THEN_MAC_READ;
113 s->s3->flags &= ~TLS1_FLAGS_ENCRYPT_THEN_MAC_READ;
115 if (s->s3->tmp.new_cipher->algorithm2 & TLS1_STREAM_MAC)
116 s->mac_flags |= SSL_MAC_FLAG_READ_MAC_STREAM;
118 s->mac_flags &= ~SSL_MAC_FLAG_READ_MAC_STREAM;
120 if (s->enc_read_ctx != NULL) {
122 } else if ((s->enc_read_ctx = EVP_CIPHER_CTX_new()) == NULL) {
123 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE,
124 ERR_R_MALLOC_FAILURE);
128 * make sure it's initialised in case we exit later with an error
130 EVP_CIPHER_CTX_reset(s->enc_read_ctx);
132 dd = s->enc_read_ctx;
133 mac_ctx = ssl_replace_hash(&s->read_hash, NULL);
136 #ifndef OPENSSL_NO_COMP
137 COMP_CTX_free(s->expand);
140 s->expand = COMP_CTX_new(comp->method);
141 if (s->expand == NULL) {
142 SSLfatal(s, SSL_AD_INTERNAL_ERROR,
143 SSL_F_TLS1_CHANGE_CIPHER_STATE,
144 SSL_R_COMPRESSION_LIBRARY_ERROR);
150 * this is done by dtls1_reset_seq_numbers for DTLS
153 RECORD_LAYER_reset_read_sequence(&s->rlayer);
154 mac_secret = &(s->s3->read_mac_secret[0]);
155 mac_secret_size = &(s->s3->read_mac_secret_size);
157 s->statem.enc_write_state = ENC_WRITE_STATE_INVALID;
159 s->s3->flags |= TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE;
161 s->s3->flags &= ~TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE;
163 if (s->s3->tmp.new_cipher->algorithm2 & TLS1_STREAM_MAC)
164 s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM;
166 s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM;
167 if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s)) {
169 } else if ((s->enc_write_ctx = EVP_CIPHER_CTX_new()) == NULL) {
170 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE,
171 ERR_R_MALLOC_FAILURE);
174 dd = s->enc_write_ctx;
175 if (SSL_IS_DTLS(s)) {
176 mac_ctx = EVP_MD_CTX_new();
177 if (mac_ctx == NULL) {
178 SSLfatal(s, SSL_AD_INTERNAL_ERROR,
179 SSL_F_TLS1_CHANGE_CIPHER_STATE,
180 ERR_R_MALLOC_FAILURE);
183 s->write_hash = mac_ctx;
185 mac_ctx = ssl_replace_hash(&s->write_hash, NULL);
186 if (mac_ctx == NULL) {
187 SSLfatal(s, SSL_AD_INTERNAL_ERROR,
188 SSL_F_TLS1_CHANGE_CIPHER_STATE,
189 ERR_R_MALLOC_FAILURE);
193 #ifndef OPENSSL_NO_COMP
194 COMP_CTX_free(s->compress);
197 s->compress = COMP_CTX_new(comp->method);
198 if (s->compress == NULL) {
199 SSLfatal(s, SSL_AD_INTERNAL_ERROR,
200 SSL_F_TLS1_CHANGE_CIPHER_STATE,
201 SSL_R_COMPRESSION_LIBRARY_ERROR);
207 * this is done by dtls1_reset_seq_numbers for DTLS
210 RECORD_LAYER_reset_write_sequence(&s->rlayer);
211 mac_secret = &(s->s3->write_mac_secret[0]);
212 mac_secret_size = &(s->s3->write_mac_secret_size);
216 EVP_CIPHER_CTX_reset(dd);
218 p = s->s3->tmp.key_block;
219 i = *mac_secret_size = s->s3->tmp.new_mac_secret_size;
221 /* TODO(size_t): convert me */
222 cl = EVP_CIPHER_key_length(c);
224 /* Was j=(exp)?5:EVP_CIPHER_key_length(c); */
225 /* If GCM/CCM mode only part of IV comes from PRF */
226 if (EVP_CIPHER_mode(c) == EVP_CIPH_GCM_MODE)
227 k = EVP_GCM_TLS_FIXED_IV_LEN;
228 else if (EVP_CIPHER_mode(c) == EVP_CIPH_CCM_MODE)
229 k = EVP_CCM_TLS_FIXED_IV_LEN;
231 k = EVP_CIPHER_iv_length(c);
232 if ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
233 (which == SSL3_CHANGE_CIPHER_SERVER_READ)) {
250 if (n > s->s3->tmp.key_block_length) {
251 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE,
252 ERR_R_INTERNAL_ERROR);
256 memcpy(mac_secret, ms, i);
258 if (!(EVP_CIPHER_flags(c) & EVP_CIPH_FLAG_AEAD_CIPHER)) {
259 /* TODO(size_t): Convert this function */
260 mac_key = EVP_PKEY_new_mac_key(mac_type, NULL, mac_secret,
261 (int)*mac_secret_size);
263 || EVP_DigestSignInit(mac_ctx, NULL, m, NULL, mac_key) <= 0) {
264 EVP_PKEY_free(mac_key);
265 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE,
266 ERR_R_INTERNAL_ERROR);
269 EVP_PKEY_free(mac_key);
272 printf("which = %04X\nmac key=", which);
275 for (z = 0; z < i; z++)
276 printf("%02X%c", ms[z], ((z + 1) % 16) ? ' ' : '\n');
280 if (EVP_CIPHER_mode(c) == EVP_CIPH_GCM_MODE) {
281 if (!EVP_CipherInit_ex(dd, c, NULL, key, NULL, (which & SSL3_CC_WRITE))
282 || !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_GCM_SET_IV_FIXED, (int)k,
284 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE,
285 ERR_R_INTERNAL_ERROR);
288 } else if (EVP_CIPHER_mode(c) == EVP_CIPH_CCM_MODE) {
291 new_cipher->algorithm_enc & (SSL_AES128CCM8 | SSL_AES256CCM8))
292 taglen = EVP_CCM8_TLS_TAG_LEN;
294 taglen = EVP_CCM_TLS_TAG_LEN;
295 if (!EVP_CipherInit_ex(dd, c, NULL, NULL, NULL, (which & SSL3_CC_WRITE))
296 || !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_AEAD_SET_IVLEN, 12, NULL)
297 || !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_AEAD_SET_TAG, taglen, NULL)
298 || !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_CCM_SET_IV_FIXED, (int)k, iv)
299 || !EVP_CipherInit_ex(dd, NULL, NULL, key, NULL, -1)) {
300 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE,
301 ERR_R_INTERNAL_ERROR);
305 if (!EVP_CipherInit_ex(dd, c, NULL, key, iv, (which & SSL3_CC_WRITE))) {
306 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE,
307 ERR_R_INTERNAL_ERROR);
311 /* Needed for "composite" AEADs, such as RC4-HMAC-MD5 */
312 if ((EVP_CIPHER_flags(c) & EVP_CIPH_FLAG_AEAD_CIPHER) && *mac_secret_size
313 && !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_AEAD_SET_MAC_KEY,
314 (int)*mac_secret_size, mac_secret)) {
315 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE,
316 ERR_R_INTERNAL_ERROR);
319 s->statem.enc_write_state = ENC_WRITE_STATE_VALID;
322 printf("which = %04X\nkey=", which);
325 for (z = 0; z < EVP_CIPHER_key_length(c); z++)
326 printf("%02X%c", key[z], ((z + 1) % 16) ? ' ' : '\n');
331 for (z = 0; z < k; z++)
332 printf("%02X%c", iv[z], ((z + 1) % 16) ? ' ' : '\n');
337 OPENSSL_cleanse(tmp1, sizeof(tmp1));
338 OPENSSL_cleanse(tmp2, sizeof(tmp1));
339 OPENSSL_cleanse(iv1, sizeof(iv1));
340 OPENSSL_cleanse(iv2, sizeof(iv2));
343 OPENSSL_cleanse(tmp1, sizeof(tmp1));
344 OPENSSL_cleanse(tmp2, sizeof(tmp1));
345 OPENSSL_cleanse(iv1, sizeof(iv1));
346 OPENSSL_cleanse(iv2, sizeof(iv2));
350 int tls1_setup_key_block(SSL *s)
356 int mac_type = NID_undef;
357 size_t num, mac_secret_size = 0;
360 if (s->s3->tmp.key_block_length != 0)
363 if (!ssl_cipher_get_evp(s->session, &c, &hash, &mac_type, &mac_secret_size,
364 &comp, s->ext.use_etm)) {
365 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_SETUP_KEY_BLOCK,
366 SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
370 s->s3->tmp.new_sym_enc = c;
371 s->s3->tmp.new_hash = hash;
372 s->s3->tmp.new_mac_pkey_type = mac_type;
373 s->s3->tmp.new_mac_secret_size = mac_secret_size;
374 num = EVP_CIPHER_key_length(c) + mac_secret_size + EVP_CIPHER_iv_length(c);
377 ssl3_cleanup_key_block(s);
379 if ((p = OPENSSL_malloc(num)) == NULL) {
380 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_SETUP_KEY_BLOCK,
381 ERR_R_MALLOC_FAILURE);
385 s->s3->tmp.key_block_length = num;
386 s->s3->tmp.key_block = p;
389 printf("client random\n");
392 for (z = 0; z < SSL3_RANDOM_SIZE; z++)
393 printf("%02X%c", s->s3->client_random[z],
394 ((z + 1) % 16) ? ' ' : '\n');
396 printf("server random\n");
399 for (z = 0; z < SSL3_RANDOM_SIZE; z++)
400 printf("%02X%c", s->s3->server_random[z],
401 ((z + 1) % 16) ? ' ' : '\n');
403 printf("master key\n");
406 for (z = 0; z < s->session->master_key_length; z++)
407 printf("%02X%c", s->session->master_key[z],
408 ((z + 1) % 16) ? ' ' : '\n');
411 if (!tls1_generate_key_block(s, p, num)) {
412 /* SSLfatal() already called */
416 printf("\nkey block\n");
419 for (z = 0; z < num; z++)
420 printf("%02X%c", p[z], ((z + 1) % 16) ? ' ' : '\n');
424 if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)
425 && s->method->version <= TLS1_VERSION) {
427 * enable vulnerability countermeasure for CBC ciphers with known-IV
428 * problem (http://www.openssl.org/~bodo/tls-cbc.txt)
430 s->s3->need_empty_fragments = 1;
432 if (s->session->cipher != NULL) {
433 if (s->session->cipher->algorithm_enc == SSL_eNULL)
434 s->s3->need_empty_fragments = 0;
436 #ifndef OPENSSL_NO_RC4
437 if (s->session->cipher->algorithm_enc == SSL_RC4)
438 s->s3->need_empty_fragments = 0;
448 size_t tls1_final_finish_mac(SSL *s, const char *str, size_t slen,
452 unsigned char hash[EVP_MAX_MD_SIZE];
454 if (!ssl3_digest_cached_records(s, 0)) {
455 /* SSLfatal() already called */
459 if (!ssl_handshake_hash(s, hash, sizeof(hash), &hashlen)) {
460 /* SSLfatal() already called */
464 if (!tls1_PRF(s, str, slen, hash, hashlen, NULL, 0, NULL, 0, NULL, 0,
465 s->session->master_key, s->session->master_key_length,
466 out, TLS1_FINISH_MAC_LENGTH, 1)) {
467 /* SSLfatal() already called */
470 OPENSSL_cleanse(hash, hashlen);
471 return TLS1_FINISH_MAC_LENGTH;
474 int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
475 size_t len, size_t *secret_size)
477 if (s->session->flags & SSL_SESS_FLAG_EXTMS) {
478 unsigned char hash[EVP_MAX_MD_SIZE * 2];
481 * Digest cached records keeping record buffer (if present): this wont
482 * affect client auth because we're freezing the buffer at the same
483 * point (after client key exchange and before certificate verify)
485 if (!ssl3_digest_cached_records(s, 1)
486 || !ssl_handshake_hash(s, hash, sizeof(hash), &hashlen)) {
487 /* SSLfatal() already called */
491 fprintf(stderr, "Handshake hashes:\n");
492 BIO_dump_fp(stderr, (char *)hash, hashlen);
495 TLS_MD_EXTENDED_MASTER_SECRET_CONST,
496 TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE,
500 NULL, 0, p, len, out,
501 SSL3_MASTER_SECRET_SIZE, 1)) {
502 /* SSLfatal() already called */
505 OPENSSL_cleanse(hash, hashlen);
508 TLS_MD_MASTER_SECRET_CONST,
509 TLS_MD_MASTER_SECRET_CONST_SIZE,
510 s->s3->client_random, SSL3_RANDOM_SIZE,
512 s->s3->server_random, SSL3_RANDOM_SIZE,
513 NULL, 0, p, len, out,
514 SSL3_MASTER_SECRET_SIZE, 1)) {
515 /* SSLfatal() already called */
520 fprintf(stderr, "Premaster Secret:\n");
521 BIO_dump_fp(stderr, (char *)p, len);
522 fprintf(stderr, "Client Random:\n");
523 BIO_dump_fp(stderr, (char *)s->s3->client_random, SSL3_RANDOM_SIZE);
524 fprintf(stderr, "Server Random:\n");
525 BIO_dump_fp(stderr, (char *)s->s3->server_random, SSL3_RANDOM_SIZE);
526 fprintf(stderr, "Master Secret:\n");
527 BIO_dump_fp(stderr, (char *)s->session->master_key,
528 SSL3_MASTER_SECRET_SIZE);
531 *secret_size = SSL3_MASTER_SECRET_SIZE;
535 int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
536 const char *label, size_t llen,
537 const unsigned char *context,
538 size_t contextlen, int use_context)
540 unsigned char *val = NULL;
541 size_t vallen = 0, currentvalpos;
545 * construct PRF arguments we construct the PRF argument ourself rather
546 * than passing separate values into the TLS PRF to ensure that the
547 * concatenation of values does not create a prohibited label.
549 vallen = llen + SSL3_RANDOM_SIZE * 2;
551 vallen += 2 + contextlen;
554 val = OPENSSL_malloc(vallen);
558 memcpy(val + currentvalpos, (unsigned char *)label, llen);
559 currentvalpos += llen;
560 memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE);
561 currentvalpos += SSL3_RANDOM_SIZE;
562 memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE);
563 currentvalpos += SSL3_RANDOM_SIZE;
566 val[currentvalpos] = (contextlen >> 8) & 0xff;
568 val[currentvalpos] = contextlen & 0xff;
570 if ((contextlen > 0) || (context != NULL)) {
571 memcpy(val + currentvalpos, context, contextlen);
576 * disallow prohibited labels note that SSL3_RANDOM_SIZE > max(prohibited
577 * label len) = 15, so size of val > max(prohibited label len) = 15 and
578 * the comparisons won't have buffer overflow
580 if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,
581 TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)
583 if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,
584 TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)
586 if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,
587 TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)
589 if (memcmp(val, TLS_MD_EXTENDED_MASTER_SECRET_CONST,
590 TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE) == 0)
592 if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,
593 TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)
602 s->session->master_key, s->session->master_key_length,
607 SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
611 SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);
614 OPENSSL_clear_free(val, vallen);
618 int tls1_alert_code(int code)
621 case SSL_AD_CLOSE_NOTIFY:
622 return SSL3_AD_CLOSE_NOTIFY;
623 case SSL_AD_UNEXPECTED_MESSAGE:
624 return SSL3_AD_UNEXPECTED_MESSAGE;
625 case SSL_AD_BAD_RECORD_MAC:
626 return SSL3_AD_BAD_RECORD_MAC;
627 case SSL_AD_DECRYPTION_FAILED:
628 return TLS1_AD_DECRYPTION_FAILED;
629 case SSL_AD_RECORD_OVERFLOW:
630 return TLS1_AD_RECORD_OVERFLOW;
631 case SSL_AD_DECOMPRESSION_FAILURE:
632 return SSL3_AD_DECOMPRESSION_FAILURE;
633 case SSL_AD_HANDSHAKE_FAILURE:
634 return SSL3_AD_HANDSHAKE_FAILURE;
635 case SSL_AD_NO_CERTIFICATE:
637 case SSL_AD_BAD_CERTIFICATE:
638 return SSL3_AD_BAD_CERTIFICATE;
639 case SSL_AD_UNSUPPORTED_CERTIFICATE:
640 return SSL3_AD_UNSUPPORTED_CERTIFICATE;
641 case SSL_AD_CERTIFICATE_REVOKED:
642 return SSL3_AD_CERTIFICATE_REVOKED;
643 case SSL_AD_CERTIFICATE_EXPIRED:
644 return SSL3_AD_CERTIFICATE_EXPIRED;
645 case SSL_AD_CERTIFICATE_UNKNOWN:
646 return SSL3_AD_CERTIFICATE_UNKNOWN;
647 case SSL_AD_ILLEGAL_PARAMETER:
648 return SSL3_AD_ILLEGAL_PARAMETER;
649 case SSL_AD_UNKNOWN_CA:
650 return TLS1_AD_UNKNOWN_CA;
651 case SSL_AD_ACCESS_DENIED:
652 return TLS1_AD_ACCESS_DENIED;
653 case SSL_AD_DECODE_ERROR:
654 return TLS1_AD_DECODE_ERROR;
655 case SSL_AD_DECRYPT_ERROR:
656 return TLS1_AD_DECRYPT_ERROR;
657 case SSL_AD_EXPORT_RESTRICTION:
658 return TLS1_AD_EXPORT_RESTRICTION;
659 case SSL_AD_PROTOCOL_VERSION:
660 return TLS1_AD_PROTOCOL_VERSION;
661 case SSL_AD_INSUFFICIENT_SECURITY:
662 return TLS1_AD_INSUFFICIENT_SECURITY;
663 case SSL_AD_INTERNAL_ERROR:
664 return TLS1_AD_INTERNAL_ERROR;
665 case SSL_AD_USER_CANCELLED:
666 return TLS1_AD_USER_CANCELLED;
667 case SSL_AD_NO_RENEGOTIATION:
668 return TLS1_AD_NO_RENEGOTIATION;
669 case SSL_AD_UNSUPPORTED_EXTENSION:
670 return TLS1_AD_UNSUPPORTED_EXTENSION;
671 case SSL_AD_CERTIFICATE_UNOBTAINABLE:
672 return TLS1_AD_CERTIFICATE_UNOBTAINABLE;
673 case SSL_AD_UNRECOGNIZED_NAME:
674 return TLS1_AD_UNRECOGNIZED_NAME;
675 case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
676 return TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE;
677 case SSL_AD_BAD_CERTIFICATE_HASH_VALUE:
678 return TLS1_AD_BAD_CERTIFICATE_HASH_VALUE;
679 case SSL_AD_UNKNOWN_PSK_IDENTITY:
680 return TLS1_AD_UNKNOWN_PSK_IDENTITY;
681 case SSL_AD_INAPPROPRIATE_FALLBACK:
682 return TLS1_AD_INAPPROPRIATE_FALLBACK;
683 case SSL_AD_NO_APPLICATION_PROTOCOL:
684 return TLS1_AD_NO_APPLICATION_PROTOCOL;
685 case SSL_AD_CERTIFICATE_REQUIRED:
686 return SSL_AD_HANDSHAKE_FAILURE;