VirtualBox

source: vbox/trunk/src/libs/openssl-3.1.7/crypto/engine/eng_pkey.c@ 105945

最後變更 在這個檔案從105945是 105945,由 vboxsync 提交於 7 月 前

openssl-3.1.7: Applied and adjusted our OpenSSL changes to 3.1.7. bugref:10757

檔案大小: 4.1 KB
 
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 "internal/deprecated.h"
14#include "eng_local.h"
15
16/* Basic get/set stuff */
17
18int ENGINE_set_load_privkey_function(ENGINE *e,
19 ENGINE_LOAD_KEY_PTR loadpriv_f)
20{
21 e->load_privkey = loadpriv_f;
22 return 1;
23}
24
25int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
26{
27 e->load_pubkey = loadpub_f;
28 return 1;
29}
30
31int ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
32 ENGINE_SSL_CLIENT_CERT_PTR
33 loadssl_f)
34{
35 e->load_ssl_client_cert = loadssl_f;
36 return 1;
37}
38
39ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e)
40{
41 return e->load_privkey;
42}
43
44ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e)
45{
46 return e->load_pubkey;
47}
48
49ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE
50 *e)
51{
52 return e->load_ssl_client_cert;
53}
54
55/* API functions to load public/private keys */
56
57EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
58 UI_METHOD *ui_method, void *callback_data)
59{
60 EVP_PKEY *pkey;
61
62 if (e == NULL) {
63 ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER);
64 return NULL;
65 }
66 if (!CRYPTO_THREAD_write_lock(global_engine_lock))
67 return NULL;
68 if (e->funct_ref == 0) {
69 CRYPTO_THREAD_unlock(global_engine_lock);
70 ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED);
71 return NULL;
72 }
73 CRYPTO_THREAD_unlock(global_engine_lock);
74 if (!e->load_privkey) {
75 ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION);
76 return NULL;
77 }
78 pkey = e->load_privkey(e, key_id, ui_method, callback_data);
79 if (pkey == NULL) {
80 ERR_raise(ERR_LIB_ENGINE, ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
81 return NULL;
82 }
83 return pkey;
84}
85
86EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
87 UI_METHOD *ui_method, void *callback_data)
88{
89 EVP_PKEY *pkey;
90
91 if (e == NULL) {
92 ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER);
93 return NULL;
94 }
95 if (!CRYPTO_THREAD_write_lock(global_engine_lock))
96 return NULL;
97 if (e->funct_ref == 0) {
98 CRYPTO_THREAD_unlock(global_engine_lock);
99 ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED);
100 return NULL;
101 }
102 CRYPTO_THREAD_unlock(global_engine_lock);
103 if (!e->load_pubkey) {
104 ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION);
105 return NULL;
106 }
107 pkey = e->load_pubkey(e, key_id, ui_method, callback_data);
108 if (pkey == NULL) {
109 ERR_raise(ERR_LIB_ENGINE, ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
110 return NULL;
111 }
112 return pkey;
113}
114
115int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s,
116 STACK_OF(X509_NAME) *ca_dn, X509 **pcert,
117 EVP_PKEY **ppkey, STACK_OF(X509) **pother,
118 UI_METHOD *ui_method, void *callback_data)
119{
120
121 if (e == NULL) {
122 ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER);
123 return 0;
124 }
125 if (!CRYPTO_THREAD_write_lock(global_engine_lock))
126 return 0;
127 if (e->funct_ref == 0) {
128 CRYPTO_THREAD_unlock(global_engine_lock);
129 ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NOT_INITIALISED);
130 return 0;
131 }
132 CRYPTO_THREAD_unlock(global_engine_lock);
133 if (!e->load_ssl_client_cert) {
134 ERR_raise(ERR_LIB_ENGINE, ENGINE_R_NO_LOAD_FUNCTION);
135 return 0;
136 }
137 return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother,
138 ui_method, callback_data);
139}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette