s3_enc.c 17.4 KB
Newer Older
R
Rich Salz 已提交
1 2
/*
 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3
 * Copyright 2005 Nokia. All rights reserved.
4
 *
R
Rich Salz 已提交
5 6 7 8
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
9
 */
R
Rich Salz 已提交
10

11 12
#include <stdio.h>
#include "ssl_locl.h"
13
#include <openssl/evp.h>
14
#include <openssl/md5.h>
M
Matt Caswell 已提交
15
#include "internal/cryptlib.h"
16

B
Bodo Möller 已提交
17
static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
18
{
19 20
    EVP_MD_CTX *m5;
    EVP_MD_CTX *s1;
21 22 23
    unsigned char buf[16], smd[SHA_DIGEST_LENGTH];
    unsigned char c = 'A';
    unsigned int i, j, k;
24
    int ret = 0;
25

26
#ifdef CHARSET_EBCDIC
27
    c = os_toascii[c];          /* 'A' in ASCII */
28
#endif
29
    k = 0;
30 31
    m5 = EVP_MD_CTX_new();
    s1 = EVP_MD_CTX_new();
32 33 34 35 36
    if (m5 == NULL || s1 == NULL) {
        SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
37 38
    for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
        k++;
39
        if (k > sizeof(buf)) {
40 41
            /* bug: 'buf' is too small for this ciphersuite */
            SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_INTERNAL_ERROR);
42
            goto err;
43 44 45 46 47
        }

        for (j = 0; j < k; j++)
            buf[j] = c;
        c++;
48 49 50 51 52 53 54 55 56 57 58 59
        if (!EVP_DigestInit_ex(s1, EVP_sha1(), NULL)
            || !EVP_DigestUpdate(s1, buf, k)
            || !EVP_DigestUpdate(s1, s->session->master_key,
                                 s->session->master_key_length)
            || !EVP_DigestUpdate(s1, s->s3->server_random, SSL3_RANDOM_SIZE)
            || !EVP_DigestUpdate(s1, s->s3->client_random, SSL3_RANDOM_SIZE)
            || !EVP_DigestFinal_ex(s1, smd, NULL)
            || !EVP_DigestInit_ex(m5, EVP_md5(), NULL)
            || !EVP_DigestUpdate(m5, s->session->master_key,
                                 s->session->master_key_length)
            || !EVP_DigestUpdate(m5, smd, SHA_DIGEST_LENGTH))
            goto err;
60
        if ((int)(i + MD5_DIGEST_LENGTH) > num) {
61 62
            if (!EVP_DigestFinal_ex(m5, smd, NULL))
                goto err;
63
            memcpy(km, smd, (num - i));
64 65 66 67
        } else {
            if (!EVP_DigestFinal_ex(m5, km, NULL))
                goto err;
        }
68 69 70

        km += MD5_DIGEST_LENGTH;
    }
R
Rich Salz 已提交
71
    OPENSSL_cleanse(smd, sizeof(smd));
72 73
    ret = 1;
 err:
74 75
    EVP_MD_CTX_free(m5);
    EVP_MD_CTX_free(s1);
76
    return ret;
77
}
78

U
Ulf Möller 已提交
79
int ssl3_change_cipher_state(SSL *s, int which)
80 81 82 83
{
    unsigned char *p, *mac_secret;
    unsigned char exp_key[EVP_MAX_KEY_LENGTH];
    unsigned char exp_iv[EVP_MAX_IV_LENGTH];
84
    unsigned char *ms, *key, *iv;
85 86
    EVP_CIPHER_CTX *dd;
    const EVP_CIPHER *c;
87
#ifndef OPENSSL_NO_COMP
88
    COMP_METHOD *comp;
89
#endif
90
    const EVP_MD *m;
91 92
    int mdi;
    size_t n, i, j, k, cl;
93 94 95 96 97
    int reuse_dd = 0;

    c = s->s3->tmp.new_sym_enc;
    m = s->s3->tmp.new_hash;
    /* m == NULL will lead to a crash later */
98
    if (!ossl_assert(m != NULL)) {
99 100 101
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_CHANGE_CIPHER_STATE,
                 ERR_R_INTERNAL_ERROR);
        goto err;
102
    }
103
#ifndef OPENSSL_NO_COMP
104 105 106 107
    if (s->s3->tmp.new_compression == NULL)
        comp = NULL;
    else
        comp = s->s3->tmp.new_compression->method;
108
#endif
109

110
    if (which & SSL3_CC_READ) {
111
        if (s->enc_read_ctx != NULL) {
112
            reuse_dd = 1;
113 114 115
        } else if ((s->enc_read_ctx = EVP_CIPHER_CTX_new()) == NULL) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_CHANGE_CIPHER_STATE,
                     ERR_R_MALLOC_FAILURE);
116
            goto err;
117
        } else {
118
            /*
F
FdaSilvaYY 已提交
119
             * make sure it's initialised in case we exit later with an error
120
             */
121
            EVP_CIPHER_CTX_reset(s->enc_read_ctx);
122
        }
123 124
        dd = s->enc_read_ctx;

125
        if (ssl_replace_hash(&s->read_hash, m) == NULL) {
126 127 128
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_CHANGE_CIPHER_STATE,
                     ERR_R_INTERNAL_ERROR);
            goto err;
M
Matt Caswell 已提交
129
        }
130
#ifndef OPENSSL_NO_COMP
131
        /* COMPRESS */
R
Rich Salz 已提交
132 133
        COMP_CTX_free(s->expand);
        s->expand = NULL;
134 135 136
        if (comp != NULL) {
            s->expand = COMP_CTX_new(comp);
            if (s->expand == NULL) {
137 138 139 140
                SSLfatal(s, SSL_AD_INTERNAL_ERROR,
                         SSL_F_SSL3_CHANGE_CIPHER_STATE,
                        SSL_R_COMPRESSION_LIBRARY_ERROR);
                goto err;
141 142
            }
        }
143
#endif
144
        RECORD_LAYER_reset_read_sequence(&s->rlayer);
145 146
        mac_secret = &(s->s3->read_mac_secret[0]);
    } else {
147
        if (s->enc_write_ctx != NULL) {
148
            reuse_dd = 1;
149 150 151
        } else if ((s->enc_write_ctx = EVP_CIPHER_CTX_new()) == NULL) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_CHANGE_CIPHER_STATE,
                     ERR_R_MALLOC_FAILURE);
152
            goto err;
153
        } else {
154
            /*
F
FdaSilvaYY 已提交
155
             * make sure it's initialised in case we exit later with an error
156
             */
157
            EVP_CIPHER_CTX_reset(s->enc_write_ctx);
158
        }
159
        dd = s->enc_write_ctx;
160
        if (ssl_replace_hash(&s->write_hash, m) == NULL) {
161 162 163
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_CHANGE_CIPHER_STATE,
                     ERR_R_MALLOC_FAILURE);
            goto err;
M
Matt Caswell 已提交
164
        }
165
#ifndef OPENSSL_NO_COMP
166
        /* COMPRESS */
R
Rich Salz 已提交
167 168
        COMP_CTX_free(s->compress);
        s->compress = NULL;
169 170 171
        if (comp != NULL) {
            s->compress = COMP_CTX_new(comp);
            if (s->compress == NULL) {
172 173 174 175
                SSLfatal(s, SSL_AD_INTERNAL_ERROR,
                         SSL_F_SSL3_CHANGE_CIPHER_STATE,
                         SSL_R_COMPRESSION_LIBRARY_ERROR);
                goto err;
176 177
            }
        }
178
#endif
179
        RECORD_LAYER_reset_write_sequence(&s->rlayer);
180 181 182 183
        mac_secret = &(s->s3->write_mac_secret[0]);
    }

    if (reuse_dd)
184
        EVP_CIPHER_CTX_reset(dd);
185 186

    p = s->s3->tmp.key_block;
187
    mdi = EVP_MD_size(m);
188 189 190 191 192
    if (mdi < 0) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_CHANGE_CIPHER_STATE,
                 ERR_R_INTERNAL_ERROR);
        goto err;
    }
193
    i = mdi;
194
    cl = EVP_CIPHER_key_length(c);
195
    j = cl;
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    k = EVP_CIPHER_iv_length(c);
    if ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
        (which == SSL3_CHANGE_CIPHER_SERVER_READ)) {
        ms = &(p[0]);
        n = i + i;
        key = &(p[n]);
        n += j + j;
        iv = &(p[n]);
        n += k + k;
    } else {
        n = i;
        ms = &(p[n]);
        n += i + j;
        key = &(p[n]);
        n += j + k;
        iv = &(p[n]);
        n += k;
    }

    if (n > s->s3->tmp.key_block_length) {
216 217 218
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_CHANGE_CIPHER_STATE,
                 ERR_R_INTERNAL_ERROR);
        goto err;
219 220 221 222
    }

    memcpy(mac_secret, ms, i);

223 224 225 226 227
    if (!EVP_CipherInit_ex(dd, c, NULL, key, iv, (which & SSL3_CC_WRITE))) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_CHANGE_CIPHER_STATE,
                 ERR_R_INTERNAL_ERROR);
        goto err;
    }
228

R
Rich Salz 已提交
229 230
    OPENSSL_cleanse(exp_key, sizeof(exp_key));
    OPENSSL_cleanse(exp_iv, sizeof(exp_iv));
231
    return 1;
232
 err:
R
Rich Salz 已提交
233 234
    OPENSSL_cleanse(exp_key, sizeof(exp_key));
    OPENSSL_cleanse(exp_iv, sizeof(exp_iv));
K
KaoruToda 已提交
235
    return 0;
236
}
237

U
Ulf Möller 已提交
238
int ssl3_setup_key_block(SSL *s)
239 240 241 242 243 244 245 246 247
{
    unsigned char *p;
    const EVP_CIPHER *c;
    const EVP_MD *hash;
    int num;
    int ret = 0;
    SSL_COMP *comp;

    if (s->s3->tmp.key_block_length != 0)
248
        return 1;
249 250

    if (!ssl_cipher_get_evp(s->session, &c, &hash, NULL, NULL, &comp, 0)) {
251 252
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_SETUP_KEY_BLOCK,
                 SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
K
KaoruToda 已提交
253
        return 0;
254 255 256 257
    }

    s->s3->tmp.new_sym_enc = c;
    s->s3->tmp.new_hash = hash;
258
#ifdef OPENSSL_NO_COMP
259
    s->s3->tmp.new_compression = NULL;
260
#else
261
    s->s3->tmp.new_compression = comp;
262
#endif
263

264 265 266 267 268 269
    num = EVP_MD_size(hash);
    if (num < 0)
        return 0;

    num = EVP_CIPHER_key_length(c) + num + EVP_CIPHER_iv_length(c);
    num *= 2;
270

271
    ssl3_cleanup_key_block(s);
272

273 274 275 276 277
    if ((p = OPENSSL_malloc(num)) == NULL) {
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_SETUP_KEY_BLOCK,
                 ERR_R_MALLOC_FAILURE);
        return 0;
    }
278

279 280
    s->s3->tmp.key_block_length = num;
    s->s3->tmp.key_block = p;
281

282
    ret = ssl3_generate_key_block(s, p, num);
283

284 285 286 287 288 289
    if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)) {
        /*
         * enable vulnerability countermeasure for CBC ciphers with known-IV
         * problem (http://www.openssl.org/~bodo/tls-cbc.txt)
         */
        s->s3->need_empty_fragments = 1;
290

291 292 293
        if (s->session->cipher != NULL) {
            if (s->session->cipher->algorithm_enc == SSL_eNULL)
                s->s3->need_empty_fragments = 0;
294

295
#ifndef OPENSSL_NO_RC4
296 297
            if (s->session->cipher->algorithm_enc == SSL_RC4)
                s->s3->need_empty_fragments = 0;
298
#endif
299 300
        }
    }
301

302 303
    return ret;
}
304

U
Ulf Möller 已提交
305
void ssl3_cleanup_key_block(SSL *s)
306
{
R
Rich Salz 已提交
307 308
    OPENSSL_clear_free(s->s3->tmp.key_block, s->s3->tmp.key_block_length);
    s->s3->tmp.key_block = NULL;
309 310
    s->s3->tmp.key_block_length = 0;
}
311

312
int ssl3_init_finished_mac(SSL *s)
313
{
314 315 316
    BIO *buf = BIO_new(BIO_s_mem());

    if (buf == NULL) {
317 318
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_INIT_FINISHED_MAC,
                 ERR_R_MALLOC_FAILURE);
319 320
        return 0;
    }
321
    ssl3_free_digest_list(s);
322
    s->s3->handshake_buffer = buf;
323
    (void)BIO_set_close(s->s3->handshake_buffer, BIO_CLOSE);
324
    return 1;
325 326
}

D
Dr. Stephen Henson 已提交
327 328 329 330 331
/*
 * Free digest list. Also frees handshake buffer since they are always freed
 * together.
 */

332 333
void ssl3_free_digest_list(SSL *s)
{
D
Dr. Stephen Henson 已提交
334 335
    BIO_free(s->s3->handshake_buffer);
    s->s3->handshake_buffer = NULL;
336
    EVP_MD_CTX_free(s->s3->handshake_dgst);
337 338
    s->s3->handshake_dgst = NULL;
}
339

M
Matt Caswell 已提交
340
int ssl3_finish_mac(SSL *s, const unsigned char *buf, size_t len)
341
{
342 343
    int ret;

M
Matt Caswell 已提交
344
    if (s->s3->handshake_dgst == NULL) {
345
        /* Note: this writes to a memory BIO so a failure is a fatal error */
346 347 348
        if (len > INT_MAX) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_FINISH_MAC,
                     SSL_R_OVERFLOW_ERROR);
M
Matt Caswell 已提交
349
            return 0;
350
        }
M
Matt Caswell 已提交
351
        ret = BIO_write(s->s3->handshake_buffer, (void *)buf, (int)len);
352 353 354 355 356
        if (ret <= 0 || ret != (int)len) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_FINISH_MAC,
                     ERR_R_INTERNAL_ERROR);
            return 0;
        }
M
Matt Caswell 已提交
357
    } else {
358 359 360 361 362 363
        ret = EVP_DigestUpdate(s->s3->handshake_dgst, buf, len);
        if (!ret) {
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_FINISH_MAC,
                     ERR_R_INTERNAL_ERROR);
            return 0;
        }
M
Matt Caswell 已提交
364
    }
365
    return 1;
366
}
367

368
int ssl3_digest_cached_records(SSL *s, int keep)
369 370 371 372 373 374
{
    const EVP_MD *md;
    long hdatalen;
    void *hdata;

    if (s->s3->handshake_dgst == NULL) {
375 376
        hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);
        if (hdatalen <= 0) {
377 378
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_DIGEST_CACHED_RECORDS,
                     SSL_R_BAD_HANDSHAKE_LENGTH);
379 380
            return 0;
        }
381

382
        s->s3->handshake_dgst = EVP_MD_CTX_new();
383
        if (s->s3->handshake_dgst == NULL) {
384 385
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_DIGEST_CACHED_RECORDS,
                     ERR_R_MALLOC_FAILURE);
386 387 388 389
            return 0;
        }

        md = ssl_handshake_md(s);
E
Emilia Kasper 已提交
390 391
        if (md == NULL || !EVP_DigestInit_ex(s->s3->handshake_dgst, md, NULL)
            || !EVP_DigestUpdate(s->s3->handshake_dgst, hdata, hdatalen)) {
392 393
            SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_DIGEST_CACHED_RECORDS,
                     ERR_R_INTERNAL_ERROR);
394
            return 0;
395 396
        }
    }
397
    if (keep == 0) {
398 399 400 401 402 403
        BIO_free(s->s3->handshake_buffer);
        s->s3->handshake_buffer = NULL;
    }

    return 1;
}
404

405 406
size_t ssl3_final_finish_mac(SSL *s, const char *sender, size_t len,
                             unsigned char *p)
407
{
408
    int ret;
409
    EVP_MD_CTX *ctx = NULL;
410

411 412
    if (!ssl3_digest_cached_records(s, 0))
        return 0;
413

414
    if (EVP_MD_CTX_type(s->s3->handshake_dgst) != NID_md5_sha1) {
D
Dr. Stephen Henson 已提交
415
        SSLerr(SSL_F_SSL3_FINAL_FINISH_MAC, SSL_R_NO_REQUIRED_DIGEST);
416 417
        return 0;
    }
418

419
    ctx = EVP_MD_CTX_new();
420 421 422 423
    if (ctx == NULL) {
        SSLerr(SSL_F_SSL3_FINAL_FINISH_MAC, ERR_R_MALLOC_FAILURE);
        return 0;
    }
424 425 426 427
    if (!EVP_MD_CTX_copy_ex(ctx, s->s3->handshake_dgst)) {
        SSLerr(SSL_F_SSL3_FINAL_FINISH_MAC, ERR_R_INTERNAL_ERROR);
        return 0;
    }
428

429
    ret = EVP_MD_CTX_size(ctx);
430
    if (ret < 0) {
431
        EVP_MD_CTX_reset(ctx);
432
        return 0;
433
    }
434

435
    if ((sender != NULL && EVP_DigestUpdate(ctx, sender, len) <= 0)
E
Emilia Kasper 已提交
436
        || EVP_MD_CTX_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET,
437
                           (int)s->session->master_key_length,
E
Emilia Kasper 已提交
438 439
                           s->session->master_key) <= 0
        || EVP_DigestFinal_ex(ctx, p, NULL) <= 0) {
D
Dr. Stephen Henson 已提交
440
        SSLerr(SSL_F_SSL3_FINAL_FINISH_MAC, ERR_R_INTERNAL_ERROR);
441 442
        ret = 0;
    }
443

444
    EVP_MD_CTX_free(ctx);
445

446
    return ret;
447
}
448

U
Ulf Möller 已提交
449
int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
450
                                size_t len, size_t *secret_size)
451 452
{
    static const unsigned char *salt[3] = {
453
#ifndef CHARSET_EBCDIC
454 455 456
        (const unsigned char *)"A",
        (const unsigned char *)"BB",
        (const unsigned char *)"CCC",
457
#else
458 459 460
        (const unsigned char *)"\x41",
        (const unsigned char *)"\x42\x42",
        (const unsigned char *)"\x43\x43\x43",
461
#endif
462 463
    };
    unsigned char buf[EVP_MAX_MD_SIZE];
464
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
465
    int i, ret = 1;
466
    unsigned int n;
467
    size_t ret_secret_size = 0;
468

469
    if (ctx == NULL) {
470 471
        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_MASTER_SECRET,
                 ERR_R_MALLOC_FAILURE);
472 473
        return 0;
    }
474
    for (i = 0; i < 3; i++) {
475
        if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
E
Emilia Kasper 已提交
476 477 478 479 480 481 482
            || EVP_DigestUpdate(ctx, salt[i],
                                strlen((const char *)salt[i])) <= 0
            || EVP_DigestUpdate(ctx, p, len) <= 0
            || EVP_DigestUpdate(ctx, &(s->s3->client_random[0]),
                                SSL3_RANDOM_SIZE) <= 0
            || EVP_DigestUpdate(ctx, &(s->s3->server_random[0]),
                                SSL3_RANDOM_SIZE) <= 0
483
               /* TODO(size_t) : convert me */
E
Emilia Kasper 已提交
484 485 486 487 488
            || EVP_DigestFinal_ex(ctx, buf, &n) <= 0
            || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0
            || EVP_DigestUpdate(ctx, p, len) <= 0
            || EVP_DigestUpdate(ctx, buf, n) <= 0
            || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {
489 490
            SSLfatal(s, SSL_AD_INTERNAL_ERROR,
                     SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);
491 492 493
            ret = 0;
            break;
        }
494
        out += n;
495
        ret_secret_size += n;
496
    }
497
    EVP_MD_CTX_free(ctx);
498

R
Rich Salz 已提交
499
    OPENSSL_cleanse(buf, sizeof(buf));
500 501 502
    if (ret)
        *secret_size = ret_secret_size;
    return ret;
503
}
504

U
Ulf Möller 已提交
505
int ssl3_alert_code(int code)
506 507 508
{
    switch (code) {
    case SSL_AD_CLOSE_NOTIFY:
K
KaoruToda 已提交
509
        return SSL3_AD_CLOSE_NOTIFY;
510
    case SSL_AD_UNEXPECTED_MESSAGE:
K
KaoruToda 已提交
511
        return SSL3_AD_UNEXPECTED_MESSAGE;
512
    case SSL_AD_BAD_RECORD_MAC:
K
KaoruToda 已提交
513
        return SSL3_AD_BAD_RECORD_MAC;
514
    case SSL_AD_DECRYPTION_FAILED:
K
KaoruToda 已提交
515
        return SSL3_AD_BAD_RECORD_MAC;
516
    case SSL_AD_RECORD_OVERFLOW:
K
KaoruToda 已提交
517
        return SSL3_AD_BAD_RECORD_MAC;
518
    case SSL_AD_DECOMPRESSION_FAILURE:
K
KaoruToda 已提交
519
        return SSL3_AD_DECOMPRESSION_FAILURE;
520
    case SSL_AD_HANDSHAKE_FAILURE:
K
KaoruToda 已提交
521
        return SSL3_AD_HANDSHAKE_FAILURE;
522
    case SSL_AD_NO_CERTIFICATE:
K
KaoruToda 已提交
523
        return SSL3_AD_NO_CERTIFICATE;
524
    case SSL_AD_BAD_CERTIFICATE:
K
KaoruToda 已提交
525
        return SSL3_AD_BAD_CERTIFICATE;
526
    case SSL_AD_UNSUPPORTED_CERTIFICATE:
K
KaoruToda 已提交
527
        return SSL3_AD_UNSUPPORTED_CERTIFICATE;
528
    case SSL_AD_CERTIFICATE_REVOKED:
K
KaoruToda 已提交
529
        return SSL3_AD_CERTIFICATE_REVOKED;
530
    case SSL_AD_CERTIFICATE_EXPIRED:
K
KaoruToda 已提交
531
        return SSL3_AD_CERTIFICATE_EXPIRED;
532
    case SSL_AD_CERTIFICATE_UNKNOWN:
K
KaoruToda 已提交
533
        return SSL3_AD_CERTIFICATE_UNKNOWN;
534
    case SSL_AD_ILLEGAL_PARAMETER:
K
KaoruToda 已提交
535
        return SSL3_AD_ILLEGAL_PARAMETER;
536
    case SSL_AD_UNKNOWN_CA:
K
KaoruToda 已提交
537
        return SSL3_AD_BAD_CERTIFICATE;
538
    case SSL_AD_ACCESS_DENIED:
K
KaoruToda 已提交
539
        return SSL3_AD_HANDSHAKE_FAILURE;
540
    case SSL_AD_DECODE_ERROR:
K
KaoruToda 已提交
541
        return SSL3_AD_HANDSHAKE_FAILURE;
542
    case SSL_AD_DECRYPT_ERROR:
K
KaoruToda 已提交
543
        return SSL3_AD_HANDSHAKE_FAILURE;
544
    case SSL_AD_EXPORT_RESTRICTION:
K
KaoruToda 已提交
545
        return SSL3_AD_HANDSHAKE_FAILURE;
546
    case SSL_AD_PROTOCOL_VERSION:
K
KaoruToda 已提交
547
        return SSL3_AD_HANDSHAKE_FAILURE;
548
    case SSL_AD_INSUFFICIENT_SECURITY:
K
KaoruToda 已提交
549
        return SSL3_AD_HANDSHAKE_FAILURE;
550
    case SSL_AD_INTERNAL_ERROR:
K
KaoruToda 已提交
551
        return SSL3_AD_HANDSHAKE_FAILURE;
552
    case SSL_AD_USER_CANCELLED:
K
KaoruToda 已提交
553
        return SSL3_AD_HANDSHAKE_FAILURE;
554
    case SSL_AD_NO_RENEGOTIATION:
K
KaoruToda 已提交
555
        return -1;            /* Don't send it :-) */
556
    case SSL_AD_UNSUPPORTED_EXTENSION:
K
KaoruToda 已提交
557
        return SSL3_AD_HANDSHAKE_FAILURE;
558
    case SSL_AD_CERTIFICATE_UNOBTAINABLE:
K
KaoruToda 已提交
559
        return SSL3_AD_HANDSHAKE_FAILURE;
560
    case SSL_AD_UNRECOGNIZED_NAME:
K
KaoruToda 已提交
561
        return SSL3_AD_HANDSHAKE_FAILURE;
562
    case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
K
KaoruToda 已提交
563
        return SSL3_AD_HANDSHAKE_FAILURE;
564
    case SSL_AD_BAD_CERTIFICATE_HASH_VALUE:
K
KaoruToda 已提交
565
        return SSL3_AD_HANDSHAKE_FAILURE;
566
    case SSL_AD_UNKNOWN_PSK_IDENTITY:
K
KaoruToda 已提交
567
        return TLS1_AD_UNKNOWN_PSK_IDENTITY;
568
    case SSL_AD_INAPPROPRIATE_FALLBACK:
K
KaoruToda 已提交
569
        return TLS1_AD_INAPPROPRIATE_FALLBACK;
570
    case SSL_AD_NO_APPLICATION_PROTOCOL:
K
KaoruToda 已提交
571
        return TLS1_AD_NO_APPLICATION_PROTOCOL;
572 573
    case SSL_AD_CERTIFICATE_REQUIRED:
        return SSL_AD_HANDSHAKE_FAILURE;
574
    default:
K
KaoruToda 已提交
575
        return -1;
576 577
    }
}