/src/openssl31/crypto/engine/eng_pkey.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright 2001-2024 The OpenSSL Project Authors. All Rights Reserved.  | 
3  |  |  *  | 
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  | 
8  |  |  */  | 
9  |  |  | 
10  |  | /* We need to use some engine deprecated APIs */  | 
11  |  | #define OPENSSL_SUPPRESS_DEPRECATED  | 
12  |  |  | 
13  |  | #include "eng_local.h"  | 
14  |  |  | 
15  |  | /* Basic get/set stuff */  | 
16  |  |  | 
17  |  | int ENGINE_set_load_privkey_function(ENGINE *e,  | 
18  |  |                                      ENGINE_LOAD_KEY_PTR loadpriv_f)  | 
19  | 0  | { | 
20  | 0  |     e->load_privkey = loadpriv_f;  | 
21  | 0  |     return 1;  | 
22  | 0  | }  | 
23  |  |  | 
24  |  | int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)  | 
25  | 0  | { | 
26  | 0  |     e->load_pubkey = loadpub_f;  | 
27  | 0  |     return 1;  | 
28  | 0  | }  | 
29  |  |  | 
30  |  | int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,  | 
31  |  |                                              ENGINE_SSL_CLIENT_CERT_PTR  | 
32  |  |                                              loadssl_f)  | 
33  | 0  | { | 
34  | 0  |     e->load_ssl_client_cert = loadssl_f;  | 
35  | 0  |     return 1;  | 
36  | 0  | }  | 
37  |  |  | 
38  |  | ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)  | 
39  | 0  | { | 
40  | 0  |     return e->load_privkey;  | 
41  | 0  | }  | 
42  |  |  | 
43  |  | ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)  | 
44  | 0  | { | 
45  | 0  |     return e->load_pubkey;  | 
46  | 0  | }  | 
47  |  |  | 
48  |  | ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE  | 
49  |  |                                                                *e)  | 
50  | 0  | { | 
51  | 0  |     return e->load_ssl_client_cert;  | 
52  | 0  | }  | 
53  |  |  | 
54  |  | /* API functions to load public/private keys */  | 
55  |  |  | 
56  |  | EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,  | 
57  |  |                                   UI_METHOD *ui_method, void *callback_data)  | 
58  | 0  | { | 
59  | 0  |     EVP_PKEY *pkey;  | 
60  |  | 
  | 
61  | 0  |     if (e == NULL) { | 
62  | 0  |         ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER);  | 
63  | 0  |         return NULL;  | 
64  | 0  |     }  | 
65  | 0  |     if (!CRYPTO_THREAD_write_lock(global_engine_lock))  | 
66  | 0  |         return NULL;  | 
67  | 0  |     if (e->funct_ref == 0) { | 
68  | 0  |         CRYPTO_THREAD_unlock(global_engine_lock);  | 
69  | 0  |         ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED);  | 
70  | 0  |         return NULL;  | 
71  | 0  |     }  | 
72  | 0  |     CRYPTO_THREAD_unlock(global_engine_lock);  | 
73  | 0  |     if (!e->load_privkey) { | 
74  | 0  |         ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION);  | 
75  | 0  |         return NULL;  | 
76  | 0  |     }  | 
77  | 0  |     pkey = e->load_privkey(e, key_id, ui_method, callback_data);  | 
78  | 0  |     if (pkey == NULL) { | 
79  | 0  |         ERR_raise(ERR_LIB_ENGINE, ENGINE_R_FAILED_LOADING_PRIVATE_KEY);  | 
80  | 0  |         return NULL;  | 
81  | 0  |     }  | 
82  | 0  |     return pkey;  | 
83  | 0  | }  | 
84  |  |  | 
85  |  | EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,  | 
86  |  |                                  UI_METHOD *ui_method, void *callback_data)  | 
87  | 0  | { | 
88  | 0  |     EVP_PKEY *pkey;  | 
89  |  | 
  | 
90  | 0  |     if (e == NULL) { | 
91  | 0  |         ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER);  | 
92  | 0  |         return NULL;  | 
93  | 0  |     }  | 
94  | 0  |     if (!CRYPTO_THREAD_write_lock(global_engine_lock))  | 
95  | 0  |         return NULL;  | 
96  | 0  |     if (e->funct_ref == 0) { | 
97  | 0  |         CRYPTO_THREAD_unlock(global_engine_lock);  | 
98  | 0  |         ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED);  | 
99  | 0  |         return NULL;  | 
100  | 0  |     }  | 
101  | 0  |     CRYPTO_THREAD_unlock(global_engine_lock);  | 
102  | 0  |     if (!e->load_pubkey) { | 
103  | 0  |         ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION);  | 
104  | 0  |         return NULL;  | 
105  | 0  |     }  | 
106  | 0  |     pkey = e->load_pubkey(e, key_id, ui_method, callback_data);  | 
107  | 0  |     if (pkey == NULL) { | 
108  | 0  |         ERR_raise(ERR_LIB_ENGINE, ENGINE_R_FAILED_LOADING_PUBLIC_KEY);  | 
109  | 0  |         return NULL;  | 
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  |         ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER);  | 
122  | 0  |         return 0;  | 
123  | 0  |     }  | 
124  | 0  |     if (!CRYPTO_THREAD_write_lock(global_engine_lock))  | 
125  | 0  |         return 0;  | 
126  | 0  |     if (e->funct_ref == 0) { | 
127  | 0  |         CRYPTO_THREAD_unlock(global_engine_lock);  | 
128  | 0  |         ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED);  | 
129  | 0  |         return 0;  | 
130  | 0  |     }  | 
131  | 0  |     CRYPTO_THREAD_unlock(global_engine_lock);  | 
132  | 0  |     if (!e->load_ssl_client_cert) { | 
133  | 0  |         ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION);  | 
134  | 0  |         return 0;  | 
135  | 0  |     }  | 
136  | 0  |     return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother,  | 
137  | 0  |                                    ui_method, callback_data);  | 
138  | 0  | }  |