summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/engine/eng_pkey.c
diff options
context:
space:
mode:
authorjsing <>2014-06-22 12:05:09 +0000
committerjsing <>2014-06-22 12:05:09 +0000
commit76145303a8345eadeb8eb36e46f50b090c9770b6 (patch)
treea2f8076f8125ce2b23509d2fe9b69914e7456a6a /src/lib/libcrypto/engine/eng_pkey.c
parent4e9e58a49cbe8568e8bc87832cb5905e49c0f4ba (diff)
downloadopenbsd-76145303a8345eadeb8eb36e46f50b090c9770b6.tar.gz
openbsd-76145303a8345eadeb8eb36e46f50b090c9770b6.tar.bz2
openbsd-76145303a8345eadeb8eb36e46f50b090c9770b6.zip
KNF.
Diffstat (limited to 'src/lib/libcrypto/engine/eng_pkey.c')
-rw-r--r--src/lib/libcrypto/engine/eng_pkey.c157
1 files changed, 77 insertions, 80 deletions
diff --git a/src/lib/libcrypto/engine/eng_pkey.c b/src/lib/libcrypto/engine/eng_pkey.c
index 410a9c3373..dc832450a6 100644
--- a/src/lib/libcrypto/engine/eng_pkey.c
+++ b/src/lib/libcrypto/engine/eng_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_pkey.c,v 1.4 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: eng_pkey.c,v 1.5 2014/06/22 12:05:09 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -57,140 +57,137 @@
57 57
58/* Basic get/set stuff */ 58/* Basic get/set stuff */
59 59
60int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f) 60int
61 { 61ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f)
62{
62 e->load_privkey = loadpriv_f; 63 e->load_privkey = loadpriv_f;
63 return 1; 64 return 1;
64 } 65}
65 66
66int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f) 67int
67 { 68ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f)
69{
68 e->load_pubkey = loadpub_f; 70 e->load_pubkey = loadpub_f;
69 return 1; 71 return 1;
70 } 72}
71 73
72int ENGINE_set_load_ssl_client_cert_function(ENGINE *e, 74int
73 ENGINE_SSL_CLIENT_CERT_PTR loadssl_f) 75ENGINE_set_load_ssl_client_cert_function(ENGINE *e,
74 { 76 ENGINE_SSL_CLIENT_CERT_PTR loadssl_f)
77{
75 e->load_ssl_client_cert = loadssl_f; 78 e->load_ssl_client_cert = loadssl_f;
76 return 1; 79 return 1;
77 } 80}
78 81
79ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e) 82ENGINE_LOAD_KEY_PTR
80 { 83ENGINE_get_load_privkey_function(const ENGINE *e)
84{
81 return e->load_privkey; 85 return e->load_privkey;
82 } 86}
83 87
84ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e) 88ENGINE_LOAD_KEY_PTR
85 { 89ENGINE_get_load_pubkey_function(const ENGINE *e)
90{
86 return e->load_pubkey; 91 return e->load_pubkey;
87 } 92}
88 93
89ENGINE_SSL_CLIENT_CERT_PTR ENGINE_get_ssl_client_cert_function(const ENGINE *e) 94ENGINE_SSL_CLIENT_CERT_PTR
90 { 95ENGINE_get_ssl_client_cert_function(const ENGINE *e)
96{
91 return e->load_ssl_client_cert; 97 return e->load_ssl_client_cert;
92 } 98}
93 99
94/* API functions to load public/private keys */ 100/* API functions to load public/private keys */
95 101
96EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, 102EVP_PKEY *
97 UI_METHOD *ui_method, void *callback_data) 103ENGINE_load_private_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method,
98 { 104 void *callback_data)
105{
99 EVP_PKEY *pkey; 106 EVP_PKEY *pkey;
100 107
101 if(e == NULL) 108 if (e == NULL) {
102 {
103 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 109 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
104 ERR_R_PASSED_NULL_PARAMETER); 110 ERR_R_PASSED_NULL_PARAMETER);
105 return 0; 111 return 0;
106 } 112 }
107 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 113 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
108 if(e->funct_ref == 0) 114 if (e->funct_ref == 0) {
109 {
110 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 115 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
111 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 116 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
112 ENGINE_R_NOT_INITIALISED); 117 ENGINE_R_NOT_INITIALISED);
113 return 0; 118 return 0;
114 } 119 }
115 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 120 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
116 if (!e->load_privkey) 121 if (!e->load_privkey) {
117 {
118 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 122 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
119 ENGINE_R_NO_LOAD_FUNCTION); 123 ENGINE_R_NO_LOAD_FUNCTION);
120 return 0; 124 return 0;
121 } 125 }
122 pkey = e->load_privkey(e, key_id, ui_method, callback_data); 126 pkey = e->load_privkey(e, key_id, ui_method, callback_data);
123 if (!pkey) 127 if (!pkey) {
124 {
125 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 128 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,
126 ENGINE_R_FAILED_LOADING_PRIVATE_KEY); 129 ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
127 return 0; 130 return 0;
128 }
129 return pkey;
130 } 131 }
132 return pkey;
133}
131 134
132EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, 135EVP_PKEY *
133 UI_METHOD *ui_method, void *callback_data) 136ENGINE_load_public_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method,
134 { 137 void *callback_data)
138{
135 EVP_PKEY *pkey; 139 EVP_PKEY *pkey;
136 140
137 if(e == NULL) 141 if (e == NULL) {
138 {
139 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 142 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
140 ERR_R_PASSED_NULL_PARAMETER); 143 ERR_R_PASSED_NULL_PARAMETER);
141 return 0; 144 return 0;
142 } 145 }
143 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 146 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
144 if(e->funct_ref == 0) 147 if (e->funct_ref == 0) {
145 {
146 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 148 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
147 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 149 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
148 ENGINE_R_NOT_INITIALISED); 150 ENGINE_R_NOT_INITIALISED);
149 return 0; 151 return 0;
150 } 152 }
151 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 153 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
152 if (!e->load_pubkey) 154 if (!e->load_pubkey) {
153 {
154 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 155 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
155 ENGINE_R_NO_LOAD_FUNCTION); 156 ENGINE_R_NO_LOAD_FUNCTION);
156 return 0; 157 return 0;
157 } 158 }
158 pkey = e->load_pubkey(e, key_id, ui_method, callback_data); 159 pkey = e->load_pubkey(e, key_id, ui_method, callback_data);
159 if (!pkey) 160 if (!pkey) {
160 {
161 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 161 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,
162 ENGINE_R_FAILED_LOADING_PUBLIC_KEY); 162 ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
163 return 0; 163 return 0;
164 }
165 return pkey;
166 } 164 }
165 return pkey;
166}
167 167
168int ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, 168int
169 STACK_OF(X509_NAME) *ca_dn, X509 **pcert, EVP_PKEY **ppkey, 169ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, STACK_OF(X509_NAME) *ca_dn,
170 STACK_OF(X509) **pother, UI_METHOD *ui_method, void *callback_data) 170 X509 **pcert, EVP_PKEY **ppkey, STACK_OF(X509) **pother,
171 { 171 UI_METHOD *ui_method, void *callback_data)
172 172{
173 if(e == NULL) 173 if (e == NULL) {
174 {
175 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT, 174 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
176 ERR_R_PASSED_NULL_PARAMETER); 175 ERR_R_PASSED_NULL_PARAMETER);
177 return 0; 176 return 0;
178 } 177 }
179 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 178 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
180 if(e->funct_ref == 0) 179 if (e->funct_ref == 0) {
181 {
182 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 180 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
183 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT, 181 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
184 ENGINE_R_NOT_INITIALISED); 182 ENGINE_R_NOT_INITIALISED);
185 return 0; 183 return 0;
186 } 184 }
187 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 185 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
188 if (!e->load_ssl_client_cert) 186 if (!e->load_ssl_client_cert) {
189 {
190 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT, 187 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT,
191 ENGINE_R_NO_LOAD_FUNCTION); 188 ENGINE_R_NO_LOAD_FUNCTION);
192 return 0; 189 return 0;
193 }
194 return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother,
195 ui_method, callback_data);
196 } 190 }
191 return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother,
192 ui_method, callback_data);
193}