diff options
Diffstat (limited to 'src/lib/libcrypto/x509/x509_lu.c')
-rw-r--r-- | src/lib/libcrypto/x509/x509_lu.c | 355 |
1 files changed, 203 insertions, 152 deletions
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c index a89cd70313..aec1121ffb 100644 --- a/src/lib/libcrypto/x509/x509_lu.c +++ b/src/lib/libcrypto/x509/x509_lu.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -62,18 +62,20 @@ | |||
62 | #include <openssl/x509.h> | 62 | #include <openssl/x509.h> |
63 | #include <openssl/x509v3.h> | 63 | #include <openssl/x509v3.h> |
64 | 64 | ||
65 | X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method) | 65 | X509_LOOKUP * |
66 | X509_LOOKUP_new(X509_LOOKUP_METHOD *method) | ||
66 | { | 67 | { |
67 | X509_LOOKUP *ret; | 68 | X509_LOOKUP *ret; |
68 | 69 | ||
69 | ret=(X509_LOOKUP *)malloc(sizeof(X509_LOOKUP)); | 70 | ret = (X509_LOOKUP *)malloc(sizeof(X509_LOOKUP)); |
70 | if (ret == NULL) return NULL; | 71 | if (ret == NULL) |
72 | return NULL; | ||
71 | 73 | ||
72 | ret->init=0; | 74 | ret->init = 0; |
73 | ret->skip=0; | 75 | ret->skip = 0; |
74 | ret->method=method; | 76 | ret->method = method; |
75 | ret->method_data=NULL; | 77 | ret->method_data = NULL; |
76 | ret->store_ctx=NULL; | 78 | ret->store_ctx = NULL; |
77 | if ((method->new_item != NULL) && !method->new_item(ret)) { | 79 | if ((method->new_item != NULL) && !method->new_item(ret)) { |
78 | free(ret); | 80 | free(ret); |
79 | return NULL; | 81 | return NULL; |
@@ -81,91 +83,104 @@ X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method) | |||
81 | return ret; | 83 | return ret; |
82 | } | 84 | } |
83 | 85 | ||
84 | void X509_LOOKUP_free(X509_LOOKUP *ctx) | 86 | void |
87 | X509_LOOKUP_free(X509_LOOKUP *ctx) | ||
85 | { | 88 | { |
86 | if (ctx == NULL) return; | 89 | if (ctx == NULL) |
87 | if ( (ctx->method != NULL) && | 90 | return; |
88 | (ctx->method->free != NULL)) | 91 | if ((ctx->method != NULL) && (ctx->method->free != NULL)) |
89 | (*ctx->method->free)(ctx); | 92 | (*ctx->method->free)(ctx); |
90 | free(ctx); | 93 | free(ctx); |
91 | } | 94 | } |
92 | 95 | ||
93 | int X509_LOOKUP_init(X509_LOOKUP *ctx) | 96 | int |
97 | X509_LOOKUP_init(X509_LOOKUP *ctx) | ||
94 | { | 98 | { |
95 | if (ctx->method == NULL) return 0; | 99 | if (ctx->method == NULL) |
100 | return 0; | ||
96 | if (ctx->method->init != NULL) | 101 | if (ctx->method->init != NULL) |
97 | return ctx->method->init(ctx); | 102 | return ctx->method->init(ctx); |
98 | else | 103 | else |
99 | return 1; | 104 | return 1; |
100 | } | 105 | } |
101 | 106 | ||
102 | int X509_LOOKUP_shutdown(X509_LOOKUP *ctx) | 107 | int |
108 | X509_LOOKUP_shutdown(X509_LOOKUP *ctx) | ||
103 | { | 109 | { |
104 | if (ctx->method == NULL) return 0; | 110 | if (ctx->method == NULL) |
111 | return 0; | ||
105 | if (ctx->method->shutdown != NULL) | 112 | if (ctx->method->shutdown != NULL) |
106 | return ctx->method->shutdown(ctx); | 113 | return ctx->method->shutdown(ctx); |
107 | else | 114 | else |
108 | return 1; | 115 | return 1; |
109 | } | 116 | } |
110 | 117 | ||
111 | int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, | 118 | int |
112 | char **ret) | 119 | X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, |
120 | char **ret) | ||
113 | { | 121 | { |
114 | if (ctx->method == NULL) return -1; | 122 | if (ctx->method == NULL) |
123 | return -1; | ||
115 | if (ctx->method->ctrl != NULL) | 124 | if (ctx->method->ctrl != NULL) |
116 | return ctx->method->ctrl(ctx,cmd,argc,argl,ret); | 125 | return ctx->method->ctrl(ctx, cmd, argc, argl, ret); |
117 | else | 126 | else |
118 | return 1; | 127 | return 1; |
119 | } | 128 | } |
120 | 129 | ||
121 | int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name, | 130 | int |
122 | X509_OBJECT *ret) | 131 | X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name, |
123 | { | 132 | X509_OBJECT *ret) |
133 | { | ||
124 | if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL)) | 134 | if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL)) |
125 | return X509_LU_FAIL; | 135 | return X509_LU_FAIL; |
126 | if (ctx->skip) return 0; | 136 | if (ctx->skip) |
127 | return ctx->method->get_by_subject(ctx,type,name,ret); | 137 | return 0; |
138 | return ctx->method->get_by_subject(ctx, type, name, ret); | ||
128 | } | 139 | } |
129 | 140 | ||
130 | int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name, | 141 | int |
131 | ASN1_INTEGER *serial, X509_OBJECT *ret) | 142 | X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name, |
143 | ASN1_INTEGER *serial, X509_OBJECT *ret) | ||
132 | { | 144 | { |
133 | if ((ctx->method == NULL) || | 145 | if ((ctx->method == NULL) || |
134 | (ctx->method->get_by_issuer_serial == NULL)) | 146 | (ctx->method->get_by_issuer_serial == NULL)) |
135 | return X509_LU_FAIL; | 147 | return X509_LU_FAIL; |
136 | return ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret); | 148 | return ctx->method->get_by_issuer_serial(ctx, type, name, serial, ret); |
137 | } | 149 | } |
138 | 150 | ||
139 | int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, | 151 | int |
140 | unsigned char *bytes, int len, X509_OBJECT *ret) | 152 | X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, unsigned char *bytes, |
153 | int len, X509_OBJECT *ret) | ||
141 | { | 154 | { |
142 | if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL)) | 155 | if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL)) |
143 | return X509_LU_FAIL; | 156 | return X509_LU_FAIL; |
144 | return ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret); | 157 | return ctx->method->get_by_fingerprint(ctx, type, bytes, len, ret); |
145 | } | 158 | } |
146 | 159 | ||
147 | int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len, | 160 | int |
148 | X509_OBJECT *ret) | 161 | X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len, |
162 | X509_OBJECT *ret) | ||
149 | { | 163 | { |
150 | if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL)) | 164 | if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL)) |
151 | return X509_LU_FAIL; | 165 | return X509_LU_FAIL; |
152 | return ctx->method->get_by_alias(ctx,type,str,len,ret); | 166 | return ctx->method->get_by_alias(ctx, type, str, len, ret); |
153 | } | 167 | } |
154 | 168 | ||
155 | 169 | static int | |
156 | static int x509_object_cmp(const X509_OBJECT * const *a, const X509_OBJECT * const *b) | 170 | x509_object_cmp(const X509_OBJECT * const *a, const X509_OBJECT * const *b) |
157 | { | 171 | { |
158 | int ret; | 172 | int ret; |
159 | 173 | ||
160 | ret=((*a)->type - (*b)->type); | 174 | ret = ((*a)->type - (*b)->type); |
161 | if (ret) return ret; | 175 | if (ret) |
162 | switch ((*a)->type) { | 176 | return ret; |
163 | case X509_LU_X509: | 177 | switch ((*a)->type) { |
164 | ret=X509_subject_name_cmp((*a)->data.x509,(*b)->data.x509); | 178 | case X509_LU_X509: |
165 | break; | 179 | ret = X509_subject_name_cmp((*a)->data.x509, (*b)->data.x509); |
166 | case X509_LU_CRL: | 180 | break; |
167 | ret=X509_CRL_cmp((*a)->data.crl,(*b)->data.crl); | 181 | case X509_LU_CRL: |
168 | break; | 182 | ret = X509_CRL_cmp((*a)->data.crl, (*b)->data.crl); |
183 | break; | ||
169 | default: | 184 | default: |
170 | /* abort(); */ | 185 | /* abort(); */ |
171 | return 0; | 186 | return 0; |
@@ -173,23 +188,24 @@ static int x509_object_cmp(const X509_OBJECT * const *a, const X509_OBJECT * con | |||
173 | return ret; | 188 | return ret; |
174 | } | 189 | } |
175 | 190 | ||
176 | X509_STORE *X509_STORE_new(void) | 191 | X509_STORE * |
192 | X509_STORE_new(void) | ||
177 | { | 193 | { |
178 | X509_STORE *ret; | 194 | X509_STORE *ret; |
179 | 195 | ||
180 | if ((ret=(X509_STORE *)malloc(sizeof(X509_STORE))) == NULL) | 196 | if ((ret = (X509_STORE *)malloc(sizeof(X509_STORE))) == NULL) |
181 | return NULL; | 197 | return NULL; |
182 | ret->objs = sk_X509_OBJECT_new(x509_object_cmp); | 198 | ret->objs = sk_X509_OBJECT_new(x509_object_cmp); |
183 | ret->cache=1; | 199 | ret->cache = 1; |
184 | ret->get_cert_methods=sk_X509_LOOKUP_new_null(); | 200 | ret->get_cert_methods = sk_X509_LOOKUP_new_null(); |
185 | ret->verify=0; | 201 | ret->verify = 0; |
186 | ret->verify_cb=0; | 202 | ret->verify_cb = 0; |
187 | 203 | ||
188 | if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) { | 204 | if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) { |
189 | sk_X509_OBJECT_free(ret->objs); | 205 | sk_X509_OBJECT_free(ret->objs); |
190 | free(ret); | 206 | free(ret); |
191 | return NULL; | 207 | return NULL; |
192 | } | 208 | } |
193 | 209 | ||
194 | ret->get_issuer = 0; | 210 | ret->get_issuer = 0; |
195 | ret->check_issued = 0; | 211 | ret->check_issued = 0; |
@@ -201,17 +217,19 @@ X509_STORE *X509_STORE_new(void) | |||
201 | ret->lookup_crls = 0; | 217 | ret->lookup_crls = 0; |
202 | ret->cleanup = 0; | 218 | ret->cleanup = 0; |
203 | 219 | ||
204 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data)) { | 220 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, |
221 | ret, &ret->ex_data)) { | ||
205 | sk_X509_OBJECT_free(ret->objs); | 222 | sk_X509_OBJECT_free(ret->objs); |
206 | free(ret); | 223 | free(ret); |
207 | return NULL; | 224 | return NULL; |
208 | } | 225 | } |
209 | 226 | ||
210 | ret->references=1; | 227 | ret->references = 1; |
211 | return ret; | 228 | return ret; |
212 | } | 229 | } |
213 | 230 | ||
214 | static void cleanup(X509_OBJECT *a) | 231 | static void |
232 | cleanup(X509_OBJECT *a) | ||
215 | { | 233 | { |
216 | if (a->type == X509_LU_X509) { | 234 | if (a->type == X509_LU_X509) { |
217 | X509_free(a->data.x509); | 235 | X509_free(a->data.x509); |
@@ -224,18 +242,19 @@ static void cleanup(X509_OBJECT *a) | |||
224 | free(a); | 242 | free(a); |
225 | } | 243 | } |
226 | 244 | ||
227 | void X509_STORE_free(X509_STORE *vfy) | 245 | void |
246 | X509_STORE_free(X509_STORE *vfy) | ||
228 | { | 247 | { |
229 | int i; | 248 | int i; |
230 | STACK_OF(X509_LOOKUP) *sk; | 249 | STACK_OF(X509_LOOKUP) *sk; |
231 | X509_LOOKUP *lu; | 250 | X509_LOOKUP *lu; |
232 | 251 | ||
233 | if (vfy == NULL) | 252 | if (vfy == NULL) |
234 | return; | 253 | return; |
235 | 254 | ||
236 | sk=vfy->get_cert_methods; | 255 | sk = vfy->get_cert_methods; |
237 | for (i=0; i<sk_X509_LOOKUP_num(sk); i++) { | 256 | for (i = 0; i < sk_X509_LOOKUP_num(sk); i++) { |
238 | lu=sk_X509_LOOKUP_value(sk,i); | 257 | lu = sk_X509_LOOKUP_value(sk, i); |
239 | X509_LOOKUP_shutdown(lu); | 258 | X509_LOOKUP_shutdown(lu); |
240 | X509_LOOKUP_free(lu); | 259 | X509_LOOKUP_free(lu); |
241 | } | 260 | } |
@@ -248,26 +267,27 @@ void X509_STORE_free(X509_STORE *vfy) | |||
248 | free(vfy); | 267 | free(vfy); |
249 | } | 268 | } |
250 | 269 | ||
251 | X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m) | 270 | X509_LOOKUP * |
271 | X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m) | ||
252 | { | 272 | { |
253 | int i; | 273 | int i; |
254 | STACK_OF(X509_LOOKUP) *sk; | 274 | STACK_OF(X509_LOOKUP) *sk; |
255 | X509_LOOKUP *lu; | 275 | X509_LOOKUP *lu; |
256 | 276 | ||
257 | sk=v->get_cert_methods; | 277 | sk = v->get_cert_methods; |
258 | for (i=0; i<sk_X509_LOOKUP_num(sk); i++) { | 278 | for (i = 0; i < sk_X509_LOOKUP_num(sk); i++) { |
259 | lu=sk_X509_LOOKUP_value(sk,i); | 279 | lu = sk_X509_LOOKUP_value(sk, i); |
260 | if (m == lu->method) { | 280 | if (m == lu->method) { |
261 | return lu; | 281 | return lu; |
262 | } | 282 | } |
263 | } | 283 | } |
264 | /* a new one */ | 284 | /* a new one */ |
265 | lu=X509_LOOKUP_new(m); | 285 | lu = X509_LOOKUP_new(m); |
266 | if (lu == NULL) | 286 | if (lu == NULL) |
267 | return NULL; | 287 | return NULL; |
268 | else { | 288 | else { |
269 | lu->store_ctx=v; | 289 | lu->store_ctx = v; |
270 | if (sk_X509_LOOKUP_push(v->get_cert_methods,lu)) | 290 | if (sk_X509_LOOKUP_push(v->get_cert_methods, lu)) |
271 | return lu; | 291 | return lu; |
272 | else { | 292 | else { |
273 | X509_LOOKUP_free(lu); | 293 | X509_LOOKUP_free(lu); |
@@ -276,31 +296,33 @@ X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m) | |||
276 | } | 296 | } |
277 | } | 297 | } |
278 | 298 | ||
279 | int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name, | 299 | int |
280 | X509_OBJECT *ret) | 300 | X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name, |
301 | X509_OBJECT *ret) | ||
281 | { | 302 | { |
282 | X509_STORE *ctx=vs->ctx; | 303 | X509_STORE *ctx = vs->ctx; |
283 | X509_LOOKUP *lu; | 304 | X509_LOOKUP *lu; |
284 | X509_OBJECT stmp,*tmp; | 305 | X509_OBJECT stmp, *tmp; |
285 | int i,j; | 306 | int i, j; |
286 | 307 | ||
287 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 308 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
288 | tmp=X509_OBJECT_retrieve_by_subject(ctx->objs,type,name); | 309 | tmp = X509_OBJECT_retrieve_by_subject(ctx->objs, type, name); |
289 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 310 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
290 | 311 | ||
291 | if (tmp == NULL || type == X509_LU_CRL) { | 312 | if (tmp == NULL || type == X509_LU_CRL) { |
292 | for (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++) { | 313 | for (i = vs->current_method; |
293 | lu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i); | 314 | i < sk_X509_LOOKUP_num(ctx->get_cert_methods); i++) { |
294 | j=X509_LOOKUP_by_subject(lu,type,name,&stmp); | 315 | lu = sk_X509_LOOKUP_value(ctx->get_cert_methods, i); |
316 | j = X509_LOOKUP_by_subject(lu, type, name, &stmp); | ||
295 | if (j < 0) { | 317 | if (j < 0) { |
296 | vs->current_method=j; | 318 | vs->current_method = j; |
297 | return j; | 319 | return j; |
298 | } else if (j) { | 320 | } else if (j) { |
299 | tmp= &stmp; | 321 | tmp = &stmp; |
300 | break; | 322 | break; |
301 | } | 323 | } |
302 | } | 324 | } |
303 | vs->current_method=0; | 325 | vs->current_method = 0; |
304 | if (tmp == NULL) | 326 | if (tmp == NULL) |
305 | return 0; | 327 | return 0; |
306 | } | 328 | } |
@@ -308,27 +330,29 @@ int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name, | |||
308 | /* if (ret->data.ptr != NULL) | 330 | /* if (ret->data.ptr != NULL) |
309 | X509_OBJECT_free_contents(ret); */ | 331 | X509_OBJECT_free_contents(ret); */ |
310 | 332 | ||
311 | ret->type=tmp->type; | 333 | ret->type = tmp->type; |
312 | ret->data.ptr=tmp->data.ptr; | 334 | ret->data.ptr = tmp->data.ptr; |
313 | 335 | ||
314 | X509_OBJECT_up_ref_count(ret); | 336 | X509_OBJECT_up_ref_count(ret); |
315 | 337 | ||
316 | return 1; | 338 | return 1; |
317 | } | 339 | } |
318 | 340 | ||
319 | int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) | 341 | int |
342 | X509_STORE_add_cert(X509_STORE *ctx, X509 *x) | ||
320 | { | 343 | { |
321 | X509_OBJECT *obj; | 344 | X509_OBJECT *obj; |
322 | int ret=1; | 345 | int ret = 1; |
323 | 346 | ||
324 | if (x == NULL) return 0; | 347 | if (x == NULL) |
325 | obj=(X509_OBJECT *)malloc(sizeof(X509_OBJECT)); | 348 | return 0; |
349 | obj = (X509_OBJECT *)malloc(sizeof(X509_OBJECT)); | ||
326 | if (obj == NULL) { | 350 | if (obj == NULL) { |
327 | X509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE); | 351 | X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE); |
328 | return 0; | 352 | return 0; |
329 | } | 353 | } |
330 | obj->type=X509_LU_X509; | 354 | obj->type = X509_LU_X509; |
331 | obj->data.x509=x; | 355 | obj->data.x509 = x; |
332 | 356 | ||
333 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 357 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
334 | 358 | ||
@@ -337,29 +361,32 @@ int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) | |||
337 | if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { | 361 | if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { |
338 | X509_OBJECT_free_contents(obj); | 362 | X509_OBJECT_free_contents(obj); |
339 | free(obj); | 363 | free(obj); |
340 | X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE); | 364 | X509err(X509_F_X509_STORE_ADD_CERT, |
341 | ret=0; | 365 | X509_R_CERT_ALREADY_IN_HASH_TABLE); |
342 | } | 366 | ret = 0; |
343 | else sk_X509_OBJECT_push(ctx->objs, obj); | 367 | } else |
368 | sk_X509_OBJECT_push(ctx->objs, obj); | ||
344 | 369 | ||
345 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 370 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
346 | 371 | ||
347 | return ret; | 372 | return ret; |
348 | } | 373 | } |
349 | 374 | ||
350 | int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) | 375 | int |
376 | X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) | ||
351 | { | 377 | { |
352 | X509_OBJECT *obj; | 378 | X509_OBJECT *obj; |
353 | int ret=1; | 379 | int ret = 1; |
354 | 380 | ||
355 | if (x == NULL) return 0; | 381 | if (x == NULL) |
356 | obj=(X509_OBJECT *)malloc(sizeof(X509_OBJECT)); | 382 | return 0; |
383 | obj = (X509_OBJECT *)malloc(sizeof(X509_OBJECT)); | ||
357 | if (obj == NULL) { | 384 | if (obj == NULL) { |
358 | X509err(X509_F_X509_STORE_ADD_CRL,ERR_R_MALLOC_FAILURE); | 385 | X509err(X509_F_X509_STORE_ADD_CRL, ERR_R_MALLOC_FAILURE); |
359 | return 0; | 386 | return 0; |
360 | } | 387 | } |
361 | obj->type=X509_LU_CRL; | 388 | obj->type = X509_LU_CRL; |
362 | obj->data.crl=x; | 389 | obj->data.crl = x; |
363 | 390 | ||
364 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 391 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
365 | 392 | ||
@@ -368,8 +395,9 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) | |||
368 | if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { | 395 | if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { |
369 | X509_OBJECT_free_contents(obj); | 396 | X509_OBJECT_free_contents(obj); |
370 | free(obj); | 397 | free(obj); |
371 | X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE); | 398 | X509err(X509_F_X509_STORE_ADD_CRL, |
372 | ret=0; | 399 | X509_R_CERT_ALREADY_IN_HASH_TABLE); |
400 | ret = 0; | ||
373 | } else | 401 | } else |
374 | sk_X509_OBJECT_push(ctx->objs, obj); | 402 | sk_X509_OBJECT_push(ctx->objs, obj); |
375 | 403 | ||
@@ -378,19 +406,21 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) | |||
378 | return ret; | 406 | return ret; |
379 | } | 407 | } |
380 | 408 | ||
381 | void X509_OBJECT_up_ref_count(X509_OBJECT *a) | 409 | void |
410 | X509_OBJECT_up_ref_count(X509_OBJECT *a) | ||
382 | { | 411 | { |
383 | switch (a->type) { | 412 | switch (a->type) { |
384 | case X509_LU_X509: | 413 | case X509_LU_X509: |
385 | CRYPTO_add(&a->data.x509->references,1,CRYPTO_LOCK_X509); | 414 | CRYPTO_add(&a->data.x509->references, 1, CRYPTO_LOCK_X509); |
386 | break; | 415 | break; |
387 | case X509_LU_CRL: | 416 | case X509_LU_CRL: |
388 | CRYPTO_add(&a->data.crl->references,1,CRYPTO_LOCK_X509_CRL); | 417 | CRYPTO_add(&a->data.crl->references, 1, CRYPTO_LOCK_X509_CRL); |
389 | break; | 418 | break; |
390 | } | 419 | } |
391 | } | 420 | } |
392 | 421 | ||
393 | void X509_OBJECT_free_contents(X509_OBJECT *a) | 422 | void |
423 | X509_OBJECT_free_contents(X509_OBJECT *a) | ||
394 | { | 424 | { |
395 | switch (a->type) { | 425 | switch (a->type) { |
396 | case X509_LU_X509: | 426 | case X509_LU_X509: |
@@ -402,8 +432,9 @@ void X509_OBJECT_free_contents(X509_OBJECT *a) | |||
402 | } | 432 | } |
403 | } | 433 | } |
404 | 434 | ||
405 | static int x509_object_idx_cnt(STACK_OF(X509_OBJECT) *h, int type, | 435 | static int |
406 | X509_NAME *name, int *pnmatch) | 436 | x509_object_idx_cnt(STACK_OF(X509_OBJECT) *h, int type, X509_NAME *name, |
437 | int *pnmatch) | ||
407 | { | 438 | { |
408 | X509_OBJECT stmp; | 439 | X509_OBJECT stmp; |
409 | X509 x509_s; | 440 | X509 x509_s; |
@@ -412,24 +443,24 @@ static int x509_object_idx_cnt(STACK_OF(X509_OBJECT) *h, int type, | |||
412 | X509_CRL_INFO crl_info_s; | 443 | X509_CRL_INFO crl_info_s; |
413 | int idx; | 444 | int idx; |
414 | 445 | ||
415 | stmp.type=type; | 446 | stmp.type = type; |
416 | switch (type) { | 447 | switch (type) { |
417 | case X509_LU_X509: | 448 | case X509_LU_X509: |
418 | stmp.data.x509= &x509_s; | 449 | stmp.data.x509 = &x509_s; |
419 | x509_s.cert_info= &cinf_s; | 450 | x509_s.cert_info = &cinf_s; |
420 | cinf_s.subject=name; | 451 | cinf_s.subject = name; |
421 | break; | 452 | break; |
422 | case X509_LU_CRL: | 453 | case X509_LU_CRL: |
423 | stmp.data.crl= &crl_s; | 454 | stmp.data.crl = &crl_s; |
424 | crl_s.crl= &crl_info_s; | 455 | crl_s.crl = &crl_info_s; |
425 | crl_info_s.issuer=name; | 456 | crl_info_s.issuer = name; |
426 | break; | 457 | break; |
427 | default: | 458 | default: |
428 | /* abort(); */ | 459 | /* abort(); */ |
429 | return -1; | 460 | return -1; |
430 | } | 461 | } |
431 | 462 | ||
432 | idx = sk_X509_OBJECT_find(h,&stmp); | 463 | idx = sk_X509_OBJECT_find(h, &stmp); |
433 | if (idx >= 0 && pnmatch) { | 464 | if (idx >= 0 && pnmatch) { |
434 | int tidx; | 465 | int tidx; |
435 | const X509_OBJECT *tobj, *pstmp; | 466 | const X509_OBJECT *tobj, *pstmp; |
@@ -445,28 +476,32 @@ static int x509_object_idx_cnt(STACK_OF(X509_OBJECT) *h, int type, | |||
445 | return idx; | 476 | return idx; |
446 | } | 477 | } |
447 | 478 | ||
448 | 479 | int | |
449 | int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type, | 480 | X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type, X509_NAME *name) |
450 | X509_NAME *name) | ||
451 | { | 481 | { |
452 | return x509_object_idx_cnt(h, type, name, NULL); | 482 | return x509_object_idx_cnt(h, type, name, NULL); |
453 | } | 483 | } |
454 | 484 | ||
455 | X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, int type, | 485 | X509_OBJECT * |
456 | X509_NAME *name) | 486 | X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, int type, |
487 | X509_NAME *name) | ||
457 | { | 488 | { |
458 | int idx; | 489 | int idx; |
490 | |||
459 | idx = X509_OBJECT_idx_by_subject(h, type, name); | 491 | idx = X509_OBJECT_idx_by_subject(h, type, name); |
460 | if (idx==-1) return NULL; | 492 | if (idx == -1) |
493 | return NULL; | ||
461 | return sk_X509_OBJECT_value(h, idx); | 494 | return sk_X509_OBJECT_value(h, idx); |
462 | } | 495 | } |
463 | 496 | ||
464 | STACK_OF(X509)* X509_STORE_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) | 497 | STACK_OF(X509) * |
498 | X509_STORE_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) | ||
465 | { | 499 | { |
466 | int i, idx, cnt; | 500 | int i, idx, cnt; |
467 | STACK_OF(X509) *sk; | 501 | STACK_OF(X509) *sk; |
468 | X509 *x; | 502 | X509 *x; |
469 | X509_OBJECT *obj; | 503 | X509_OBJECT *obj; |
504 | |||
470 | sk = sk_X509_new_null(); | 505 | sk = sk_X509_new_null(); |
471 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 506 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
472 | idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt); | 507 | idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt); |
@@ -482,7 +517,8 @@ STACK_OF(X509)* X509_STORE_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) | |||
482 | } | 517 | } |
483 | X509_OBJECT_free_contents(&xobj); | 518 | X509_OBJECT_free_contents(&xobj); |
484 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 519 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
485 | idx = x509_object_idx_cnt(ctx->ctx->objs,X509_LU_X509,nm, &cnt); | 520 | idx = x509_object_idx_cnt(ctx->ctx->objs, |
521 | X509_LU_X509, nm, &cnt); | ||
486 | if (idx < 0) { | 522 | if (idx < 0) { |
487 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 523 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
488 | sk_X509_free(sk); | 524 | sk_X509_free(sk); |
@@ -505,12 +541,14 @@ STACK_OF(X509)* X509_STORE_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) | |||
505 | 541 | ||
506 | } | 542 | } |
507 | 543 | ||
508 | STACK_OF(X509_CRL)* X509_STORE_get1_crls(X509_STORE_CTX *ctx, X509_NAME *nm) | 544 | STACK_OF(X509_CRL) * |
545 | X509_STORE_get1_crls(X509_STORE_CTX *ctx, X509_NAME *nm) | ||
509 | { | 546 | { |
510 | int i, idx, cnt; | 547 | int i, idx, cnt; |
511 | STACK_OF(X509_CRL) *sk; | 548 | STACK_OF(X509_CRL) *sk; |
512 | X509_CRL *x; | 549 | X509_CRL *x; |
513 | X509_OBJECT *obj, xobj; | 550 | X509_OBJECT *obj, xobj; |
551 | |||
514 | sk = sk_X509_CRL_new_null(); | 552 | sk = sk_X509_CRL_new_null(); |
515 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 553 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
516 | /* Check cache first */ | 554 | /* Check cache first */ |
@@ -525,7 +563,7 @@ STACK_OF(X509_CRL)* X509_STORE_get1_crls(X509_STORE_CTX *ctx, X509_NAME *nm) | |||
525 | } | 563 | } |
526 | X509_OBJECT_free_contents(&xobj); | 564 | X509_OBJECT_free_contents(&xobj); |
527 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | 565 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); |
528 | idx = x509_object_idx_cnt(ctx->ctx->objs,X509_LU_CRL, nm, &cnt); | 566 | idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_CRL, nm, &cnt); |
529 | if (idx < 0) { | 567 | if (idx < 0) { |
530 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | 568 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); |
531 | sk_X509_CRL_free(sk); | 569 | sk_X509_CRL_free(sk); |
@@ -547,17 +585,21 @@ STACK_OF(X509_CRL)* X509_STORE_get1_crls(X509_STORE_CTX *ctx, X509_NAME *nm) | |||
547 | return sk; | 585 | return sk; |
548 | } | 586 | } |
549 | 587 | ||
550 | X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x) | 588 | X509_OBJECT * |
589 | X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x) | ||
551 | { | 590 | { |
552 | int idx, i; | 591 | int idx, i; |
553 | X509_OBJECT *obj; | 592 | X509_OBJECT *obj; |
593 | |||
554 | idx = sk_X509_OBJECT_find(h, x); | 594 | idx = sk_X509_OBJECT_find(h, x); |
555 | if (idx == -1) return NULL; | 595 | if (idx == -1) |
596 | return NULL; | ||
556 | if ((x->type != X509_LU_X509) && (x->type != X509_LU_CRL)) | 597 | if ((x->type != X509_LU_X509) && (x->type != X509_LU_CRL)) |
557 | return sk_X509_OBJECT_value(h, idx); | 598 | return sk_X509_OBJECT_value(h, idx); |
558 | for (i = idx; i < sk_X509_OBJECT_num(h); i++) { | 599 | for (i = idx; i < sk_X509_OBJECT_num(h); i++) { |
559 | obj = sk_X509_OBJECT_value(h, i); | 600 | obj = sk_X509_OBJECT_value(h, i); |
560 | if (x509_object_cmp((const X509_OBJECT **)&obj, (const X509_OBJECT **)&x)) | 601 | if (x509_object_cmp((const X509_OBJECT **)&obj, |
602 | (const X509_OBJECT **)&x)) | ||
561 | return NULL; | 603 | return NULL; |
562 | if (x->type == X509_LU_X509) { | 604 | if (x->type == X509_LU_X509) { |
563 | if (!X509_cmp(obj->data.x509, x->data.x509)) | 605 | if (!X509_cmp(obj->data.x509, x->data.x509)) |
@@ -583,17 +625,19 @@ X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x | |||
583 | * 0 certificate not found. | 625 | * 0 certificate not found. |
584 | * -1 some other error. | 626 | * -1 some other error. |
585 | */ | 627 | */ |
586 | int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x) | 628 | int |
629 | X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x) | ||
587 | { | 630 | { |
588 | X509_NAME *xn; | 631 | X509_NAME *xn; |
589 | X509_OBJECT obj, *pobj; | 632 | X509_OBJECT obj, *pobj; |
590 | int i, ok, idx, ret; | 633 | int i, ok, idx, ret; |
591 | xn=X509_get_issuer_name(x); | 634 | xn = X509_get_issuer_name(x); |
592 | ok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj); | 635 | ok = X509_STORE_get_by_subject(ctx, X509_LU_X509, xn, &obj); |
593 | if (ok != X509_LU_X509) { | 636 | if (ok != X509_LU_X509) { |
594 | if (ok == X509_LU_RETRY) { | 637 | if (ok == X509_LU_RETRY) { |
595 | X509_OBJECT_free_contents(&obj); | 638 | X509_OBJECT_free_contents(&obj); |
596 | X509err(X509_F_X509_STORE_CTX_GET1_ISSUER,X509_R_SHOULD_RETRY); | 639 | X509err(X509_F_X509_STORE_CTX_GET1_ISSUER, |
640 | X509_R_SHOULD_RETRY); | ||
597 | return -1; | 641 | return -1; |
598 | } else if (ok != X509_LU_FAIL) { | 642 | } else if (ok != X509_LU_FAIL) { |
599 | X509_OBJECT_free_contents(&obj); | 643 | X509_OBJECT_free_contents(&obj); |
@@ -620,7 +664,8 @@ int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x) | |||
620 | /* See if we've run past the matches */ | 664 | /* See if we've run past the matches */ |
621 | if (pobj->type != X509_LU_X509) | 665 | if (pobj->type != X509_LU_X509) |
622 | break; | 666 | break; |
623 | if (X509_NAME_cmp(xn, X509_get_subject_name(pobj->data.x509))) | 667 | if (X509_NAME_cmp(xn, |
668 | X509_get_subject_name(pobj->data.x509))) | ||
624 | break; | 669 | break; |
625 | if (ctx->check_issued(ctx, x, pobj->data.x509)) { | 670 | if (ctx->check_issued(ctx, x, pobj->data.x509)) { |
626 | *issuer = pobj->data.x509; | 671 | *issuer = pobj->data.x509; |
@@ -634,34 +679,40 @@ int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x) | |||
634 | return ret; | 679 | return ret; |
635 | } | 680 | } |
636 | 681 | ||
637 | int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags) | 682 | int |
683 | X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags) | ||
638 | { | 684 | { |
639 | return X509_VERIFY_PARAM_set_flags(ctx->param, flags); | 685 | return X509_VERIFY_PARAM_set_flags(ctx->param, flags); |
640 | } | 686 | } |
641 | 687 | ||
642 | int X509_STORE_set_depth(X509_STORE *ctx, int depth) | 688 | int |
689 | X509_STORE_set_depth(X509_STORE *ctx, int depth) | ||
643 | { | 690 | { |
644 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); | 691 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); |
645 | return 1; | 692 | return 1; |
646 | } | 693 | } |
647 | 694 | ||
648 | int X509_STORE_set_purpose(X509_STORE *ctx, int purpose) | 695 | int |
696 | X509_STORE_set_purpose(X509_STORE *ctx, int purpose) | ||
649 | { | 697 | { |
650 | return X509_VERIFY_PARAM_set_purpose(ctx->param, purpose); | 698 | return X509_VERIFY_PARAM_set_purpose(ctx->param, purpose); |
651 | } | 699 | } |
652 | 700 | ||
653 | int X509_STORE_set_trust(X509_STORE *ctx, int trust) | 701 | int |
702 | X509_STORE_set_trust(X509_STORE *ctx, int trust) | ||
654 | { | 703 | { |
655 | return X509_VERIFY_PARAM_set_trust(ctx->param, trust); | 704 | return X509_VERIFY_PARAM_set_trust(ctx->param, trust); |
656 | } | 705 | } |
657 | 706 | ||
658 | int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *param) | 707 | int |
708 | X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *param) | ||
659 | { | 709 | { |
660 | return X509_VERIFY_PARAM_set1(ctx->param, param); | 710 | return X509_VERIFY_PARAM_set1(ctx->param, param); |
661 | } | 711 | } |
662 | 712 | ||
663 | void X509_STORE_set_verify_cb(X509_STORE *ctx, | 713 | void |
664 | int (*verify_cb)(int, X509_STORE_CTX *)) | 714 | X509_STORE_set_verify_cb(X509_STORE *ctx, |
715 | int (*verify_cb)(int, X509_STORE_CTX *)) | ||
665 | { | 716 | { |
666 | ctx->verify_cb = verify_cb; | 717 | ctx->verify_cb = verify_cb; |
667 | } | 718 | } |