2 * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
10 /* We need to use some engine deprecated APIs */
11 #define OPENSSL_SUPPRESS_DEPRECATED
13 #include "eng_local.h"
15 /* Basic get/set stuff */
17 int ENGINE_set_load_privkey_function(ENGINE *e,
18 ENGINE_LOAD_KEY_PTR loadpriv_f)
20 e->load_privkey = loadpriv_f;
24 int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
26 e->load_pubkey = loadpub_f;
30 int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
31 ENGINE_SSL_CLIENT_CERT_PTR
34 e->load_ssl_client_cert = loadssl_f;
38 ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)
40 return e->load_privkey;
43 ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)
45 return e->load_pubkey;
48 ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE
51 return e->load_ssl_client_cert;
54 /* API functions to load public/private keys */
56 EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
57 UI_METHOD *ui_method, void *callback_data)
62 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
63 ERR_R_PASSED_NULL_PARAMETER);
66 CRYPTO_THREAD_write_lock(global_engine_lock);
67 if (e->funct_ref == 0) {
68 CRYPTO_THREAD_unlock(global_engine_lock);
69 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, ENGINE_R_NOT_INITIALISED);
72 CRYPTO_THREAD_unlock(global_engine_lock);
73 if (!e->load_privkey) {
74 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
75 ENGINE_R_NO_LOAD_FUNCTION);
78 pkey = e->load_privkey(e, key_id, ui_method, callback_data);
80 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
81 ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
87 EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
88 UI_METHOD *ui_method, void *callback_data)
93 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
94 ERR_R_PASSED_NULL_PARAMETER);
97 CRYPTO_THREAD_write_lock(global_engine_lock);
98 if (e->funct_ref == 0) {
99 CRYPTO_THREAD_unlock(global_engine_lock);
100 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, ENGINE_R_NOT_INITIALISED);
103 CRYPTO_THREAD_unlock(global_engine_lock);
104 if (!e->load_pubkey) {
105 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, ENGINE_R_NO_LOAD_FUNCTION);
108 pkey = e->load_pubkey(e, key_id, ui_method, callback_data);
110 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
111 ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
117 int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s,
118 STACK_OF(X509_NAME) *ca_dn, X509 **pcert,
119 EVP_PKEY **ppkey, STACK_OF(X509) **pother,
120 UI_METHOD *ui_method, void *callback_data)
124 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
125 ERR_R_PASSED_NULL_PARAMETER);
128 CRYPTO_THREAD_write_lock(global_engine_lock);
129 if (e->funct_ref == 0) {
130 CRYPTO_THREAD_unlock(global_engine_lock);
131 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
132 ENGINE_R_NOT_INITIALISED);
135 CRYPTO_THREAD_unlock(global_engine_lock);
136 if (!e->load_ssl_client_cert) {
137 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
138 ENGINE_R_NO_LOAD_FUNCTION);
141 return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother,
142 ui_method, callback_data);