Coverage Report

Created: 2023-06-08 06:40

/src/openssl111/crypto/engine/eng_pkey.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the OpenSSL license (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include "eng_local.h"
11
12
/* Basic get/set stuff */
13
14
int ENGINE_set_load_privkey_function(ENGINE *e,
15
                                     ENGINE_LOAD_KEY_PTR loadpriv_f)
16
0
{
17
0
    e->load_privkey = loadpriv_f;
18
0
    return 1;
19
0
}
20
21
int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
22
0
{
23
0
    e->load_pubkey = loadpub_f;
24
0
    return 1;
25
0
}
26
27
int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
28
                                             ENGINE_SSL_CLIENT_CERT_PTR
29
                                             loadssl_f)
30
0
{
31
0
    e->load_ssl_client_cert = loadssl_f;
32
0
    return 1;
33
0
}
34
35
ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)
36
0
{
37
0
    return e->load_privkey;
38
0
}
39
40
ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)
41
0
{
42
0
    return e->load_pubkey;
43
0
}
44
45
ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE
46
                                                               *e)
47
0
{
48
0
    return e->load_ssl_client_cert;
49
0
}
50
51
/* API functions to load public/private keys */
52
53
EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
54
                                  UI_METHOD *ui_method, void *callback_data)
55
0
{
56
0
    EVP_PKEY *pkey;
57
58
0
    if (e == NULL) {
59
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
60
0
                  ERR_R_PASSED_NULL_PARAMETER);
61
0
        return 0;
62
0
    }
63
0
    CRYPTO_THREAD_write_lock(global_engine_lock);
64
0
    if (e->funct_ref == 0) {
65
0
        CRYPTO_THREAD_unlock(global_engine_lock);
66
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, ENGINE_R_NOT_INITIALISED);
67
0
        return 0;
68
0
    }
69
0
    CRYPTO_THREAD_unlock(global_engine_lock);
70
0
    if (!e->load_privkey) {
71
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
72
0
                  ENGINE_R_NO_LOAD_FUNCTION);
73
0
        return 0;
74
0
    }
75
0
    pkey = e->load_privkey(e, key_id, ui_method, callback_data);
76
0
    if (!pkey) {
77
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
78
0
                  ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
79
0
        return 0;
80
0
    }
81
0
    return pkey;
82
0
}
83
84
EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
85
                                 UI_METHOD *ui_method, void *callback_data)
86
0
{
87
0
    EVP_PKEY *pkey;
88
89
0
    if (e == NULL) {
90
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
91
0
                  ERR_R_PASSED_NULL_PARAMETER);
92
0
        return 0;
93
0
    }
94
0
    CRYPTO_THREAD_write_lock(global_engine_lock);
95
0
    if (e->funct_ref == 0) {
96
0
        CRYPTO_THREAD_unlock(global_engine_lock);
97
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, ENGINE_R_NOT_INITIALISED);
98
0
        return 0;
99
0
    }
100
0
    CRYPTO_THREAD_unlock(global_engine_lock);
101
0
    if (!e->load_pubkey) {
102
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, ENGINE_R_NO_LOAD_FUNCTION);
103
0
        return 0;
104
0
    }
105
0
    pkey = e->load_pubkey(e, key_id, ui_method, callback_data);
106
0
    if (!pkey) {
107
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
108
0
                  ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
109
0
        return 0;
110
0
    }
111
0
    return pkey;
112
0
}
113
114
int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s,
115
                                STACK_OF(X509_NAME) *ca_dn, X509 **pcert,
116
                                EVP_PKEY **ppkey, STACK_OF(X509) **pother,
117
                                UI_METHOD *ui_method, void *callback_data)
118
0
{
119
120
0
    if (e == NULL) {
121
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
122
0
                  ERR_R_PASSED_NULL_PARAMETER);
123
0
        return 0;
124
0
    }
125
0
    CRYPTO_THREAD_write_lock(global_engine_lock);
126
0
    if (e->funct_ref == 0) {
127
0
        CRYPTO_THREAD_unlock(global_engine_lock);
128
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
129
0
                  ENGINE_R_NOT_INITIALISED);
130
0
        return 0;
131
0
    }
132
0
    CRYPTO_THREAD_unlock(global_engine_lock);
133
0
    if (!e->load_ssl_client_cert) {
134
0
        ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
135
0
                  ENGINE_R_NO_LOAD_FUNCTION);
136
0
        return 0;
137
0
    }
138
0
    return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother,
139
0
                                   ui_method, callback_data);
140
0
}