]>
Commit | Line | Data |
---|---|---|
b1322259 | 1 | /* |
e39e295e | 2 | * Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved. |
354c3ace | 3 | * |
3c120f91 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
b1322259 RS |
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 | |
354c3ace BL |
8 | */ |
9 | ||
e4468e6d P |
10 | /* We need to use some engine deprecated APIs */ |
11 | #define OPENSSL_SUPPRESS_DEPRECATED | |
12 | ||
706457b7 | 13 | #include "eng_local.h" |
354c3ace | 14 | |
b6d1e52d | 15 | /* Basic get/set stuff */ |
354c3ace | 16 | |
0f113f3e MC |
17 | int ENGINE_set_load_privkey_function(ENGINE *e, |
18 | ENGINE_LOAD_KEY_PTR loadpriv_f) | |
19 | { | |
20 | e->load_privkey = loadpriv_f; | |
21 | return 1; | |
22 | } | |
354c3ace | 23 | |
b6d1e52d | 24 | int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f) |
0f113f3e MC |
25 | { |
26 | e->load_pubkey = loadpub_f; | |
27 | return 1; | |
28 | } | |
354c3ace | 29 | |
05935c47 | 30 | int ENGINE_set_load_ssl_client_cert_function(ENGINE *e, |
0f113f3e MC |
31 | ENGINE_SSL_CLIENT_CERT_PTR |
32 | loadssl_f) | |
33 | { | |
34 | e->load_ssl_client_cert = loadssl_f; | |
35 | return 1; | |
36 | } | |
05935c47 | 37 | |
b6d1e52d | 38 | ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e) |
0f113f3e MC |
39 | { |
40 | return e->load_privkey; | |
41 | } | |
354c3ace | 42 | |
b6d1e52d | 43 | ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e) |
0f113f3e MC |
44 | { |
45 | return e->load_pubkey; | |
46 | } | |
354c3ace | 47 | |
0f113f3e MC |
48 | ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE |
49 | *e) | |
50 | { | |
51 | return e->load_ssl_client_cert; | |
52 | } | |
05935c47 | 53 | |
b6d1e52d | 54 | /* API functions to load public/private keys */ |
354c3ace | 55 | |
b6d1e52d | 56 | EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, |
0f113f3e MC |
57 | UI_METHOD *ui_method, void *callback_data) |
58 | { | |
59 | EVP_PKEY *pkey; | |
0e360199 | 60 | |
0f113f3e | 61 | if (e == NULL) { |
9311d0c4 | 62 | ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER); |
0f113f3e MC |
63 | return 0; |
64 | } | |
40e068d5 | 65 | CRYPTO_THREAD_write_lock(global_engine_lock); |
0f113f3e | 66 | if (e->funct_ref == 0) { |
40e068d5 | 67 | CRYPTO_THREAD_unlock(global_engine_lock); |
9311d0c4 | 68 | ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED); |
0f113f3e MC |
69 | return 0; |
70 | } | |
40e068d5 | 71 | CRYPTO_THREAD_unlock(global_engine_lock); |
0f113f3e | 72 | if (!e->load_privkey) { |
9311d0c4 | 73 | ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION); |
0f113f3e MC |
74 | return 0; |
75 | } | |
76 | pkey = e->load_privkey(e, key_id, ui_method, callback_data); | |
12a765a5 | 77 | if (pkey == NULL) { |
9311d0c4 | 78 | ERR_raise(ERR_LIB_ENGINE, ENGINE_R_FAILED_LOADING_PRIVATE_KEY); |
0f113f3e MC |
79 | return 0; |
80 | } | |
81 | return pkey; | |
82 | } | |
0e360199 | 83 | |
b6d1e52d | 84 | EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, |
0f113f3e MC |
85 | UI_METHOD *ui_method, void *callback_data) |
86 | { | |
87 | EVP_PKEY *pkey; | |
0e360199 | 88 | |
0f113f3e | 89 | if (e == NULL) { |
9311d0c4 | 90 | ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER); |
0f113f3e MC |
91 | return 0; |
92 | } | |
40e068d5 | 93 | CRYPTO_THREAD_write_lock(global_engine_lock); |
0f113f3e | 94 | if (e->funct_ref == 0) { |
40e068d5 | 95 | CRYPTO_THREAD_unlock(global_engine_lock); |
9311d0c4 | 96 | ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED); |
0f113f3e MC |
97 | return 0; |
98 | } | |
40e068d5 | 99 | CRYPTO_THREAD_unlock(global_engine_lock); |
0f113f3e | 100 | if (!e->load_pubkey) { |
9311d0c4 | 101 | ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION); |
0f113f3e MC |
102 | return 0; |
103 | } | |
104 | pkey = e->load_pubkey(e, key_id, ui_method, callback_data); | |
12a765a5 | 105 | if (pkey == NULL) { |
9311d0c4 | 106 | ERR_raise(ERR_LIB_ENGINE, ENGINE_R_FAILED_LOADING_PUBLIC_KEY); |
0f113f3e MC |
107 | return 0; |
108 | } | |
109 | return pkey; | |
110 | } | |
05935c47 DSH |
111 | |
112 | int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, | |
0f113f3e MC |
113 | STACK_OF(X509_NAME) *ca_dn, X509 **pcert, |
114 | EVP_PKEY **ppkey, STACK_OF(X509) **pother, | |
115 | UI_METHOD *ui_method, void *callback_data) | |
116 | { | |
05935c47 | 117 | |
0f113f3e | 118 | if (e == NULL) { |
9311d0c4 | 119 | ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER); |
0f113f3e MC |
120 | return 0; |
121 | } | |
40e068d5 | 122 | CRYPTO_THREAD_write_lock(global_engine_lock); |
0f113f3e | 123 | if (e->funct_ref == 0) { |
40e068d5 | 124 | CRYPTO_THREAD_unlock(global_engine_lock); |
9311d0c4 | 125 | ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED); |
0f113f3e MC |
126 | return 0; |
127 | } | |
40e068d5 | 128 | CRYPTO_THREAD_unlock(global_engine_lock); |
0f113f3e | 129 | if (!e->load_ssl_client_cert) { |
9311d0c4 | 130 | ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION); |
0f113f3e MC |
131 | return 0; |
132 | } | |
133 | return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother, | |
134 | ui_method, callback_data); | |
135 | } |