Coverage Report

Created: 2018-08-29 13:53

/src/openssl/crypto/engine/eng_fat.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
3
 * Copyright (c) 2002, Oracle and/or its affiliates. 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
11
#include "eng_int.h"
12
#include <openssl/conf.h>
13
14
int ENGINE_set_default(ENGINE *e, unsigned int flags)
15
0
{
16
0
    if ((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e))
17
0
        return 0;
18
0
    if ((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e))
19
0
        return 0;
20
0
#ifndef OPENSSL_NO_RSA
21
0
    if ((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e))
22
0
        return 0;
23
0
#endif
24
0
#ifndef OPENSSL_NO_DSA
25
0
    if ((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e))
26
0
        return 0;
27
0
#endif
28
0
#ifndef OPENSSL_NO_DH
29
0
    if ((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e))
30
0
        return 0;
31
0
#endif
32
0
#ifndef OPENSSL_NO_EC
33
0
    if ((flags & ENGINE_METHOD_EC) && !ENGINE_set_default_EC(e))
34
0
        return 0;
35
0
#endif
36
0
    if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
37
0
        return 0;
38
0
    if ((flags & ENGINE_METHOD_PKEY_METHS)
39
0
        && !ENGINE_set_default_pkey_meths(e))
40
0
        return 0;
41
0
    if ((flags & ENGINE_METHOD_PKEY_ASN1_METHS)
42
0
        && !ENGINE_set_default_pkey_asn1_meths(e))
43
0
        return 0;
44
0
    return 1;
45
0
}
46
47
/* Set default algorithms using a string */
48
49
static int int_def_cb(const char *alg, int len, void *arg)
50
{
51
    unsigned int *pflags = arg;
52
    if (alg == NULL)
53
        return 0;
54
    if (strncmp(alg, "ALL", len) == 0)
55
        *pflags |= ENGINE_METHOD_ALL;
56
    else if (strncmp(alg, "RSA", len) == 0)
57
        *pflags |= ENGINE_METHOD_RSA;
58
    else if (strncmp(alg, "DSA", len) == 0)
59
        *pflags |= ENGINE_METHOD_DSA;
60
    else if (strncmp(alg, "DH", len) == 0)
61
        *pflags |= ENGINE_METHOD_DH;
62
    else if (strncmp(alg, "EC", len) == 0)
63
        *pflags |= ENGINE_METHOD_EC;
64
    else if (strncmp(alg, "RAND", len) == 0)
65
        *pflags |= ENGINE_METHOD_RAND;
66
    else if (strncmp(alg, "CIPHERS", len) == 0)
67
        *pflags |= ENGINE_METHOD_CIPHERS;
68
    else if (strncmp(alg, "DIGESTS", len) == 0)
69
        *pflags |= ENGINE_METHOD_DIGESTS;
70
    else if (strncmp(alg, "PKEY", len) == 0)
71
        *pflags |= ENGINE_METHOD_PKEY_METHS | ENGINE_METHOD_PKEY_ASN1_METHS;
72
    else if (strncmp(alg, "PKEY_CRYPTO", len) == 0)
73
        *pflags |= ENGINE_METHOD_PKEY_METHS;
74
    else if (strncmp(alg, "PKEY_ASN1", len) == 0)
75
        *pflags |= ENGINE_METHOD_PKEY_ASN1_METHS;
76
    else
77
        return 0;
78
    return 1;
79
}
80
81
int ENGINE_set_default_string(ENGINE *e, const char *def_list)
82
0
{
83
0
    unsigned int flags = 0;
84
0
    if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) {
85
0
        ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING,
86
0
                  ENGINE_R_INVALID_STRING);
87
0
        ERR_add_error_data(2, "str=", def_list);
88
0
        return 0;
89
0
    }
90
0
    return ENGINE_set_default(e, flags);
91
0
}
92
93
int ENGINE_register_complete(ENGINE *e)
94
0
{
95
0
    ENGINE_register_ciphers(e);
96
0
    ENGINE_register_digests(e);
97
0
#ifndef OPENSSL_NO_RSA
98
0
    ENGINE_register_RSA(e);
99
0
#endif
100
0
#ifndef OPENSSL_NO_DSA
101
0
    ENGINE_register_DSA(e);
102
0
#endif
103
0
#ifndef OPENSSL_NO_DH
104
0
    ENGINE_register_DH(e);
105
0
#endif
106
0
#ifndef OPENSSL_NO_EC
107
0
    ENGINE_register_EC(e);
108
0
#endif
109
0
    ENGINE_register_RAND(e);
110
0
    ENGINE_register_pkey_meths(e);
111
0
    ENGINE_register_pkey_asn1_meths(e);
112
0
    return 1;
113
0
}
114
115
int ENGINE_register_all_complete(void)
116
0
{
117
0
    ENGINE *e;
118
0
119
0
    for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
120
0
        if (!(e->flags & ENGINE_FLAGS_NO_REGISTER_ALL))
121
0
            ENGINE_register_complete(e);
122
0
    return 1;
123
0
}