diff options
Diffstat (limited to 'src/lib/libssl/src/crypto/x509/x509_lu.c')
-rw-r--r-- | src/lib/libssl/src/crypto/x509/x509_lu.c | 139 |
1 files changed, 52 insertions, 87 deletions
diff --git a/src/lib/libssl/src/crypto/x509/x509_lu.c b/src/lib/libssl/src/crypto/x509/x509_lu.c index 2c7e10a46e..18bfecb11e 100644 --- a/src/lib/libssl/src/crypto/x509/x509_lu.c +++ b/src/lib/libssl/src/crypto/x509/x509_lu.c | |||
@@ -58,14 +58,13 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "lhash.h" | 61 | #include <openssl/lhash.h> |
62 | #include "x509.h" | 62 | #include <openssl/x509.h> |
63 | 63 | ||
64 | static STACK *x509_store_meth=NULL; | 64 | static STACK *x509_store_meth=NULL; |
65 | static STACK *x509_store_ctx_meth=NULL; | 65 | static STACK *x509_store_ctx_meth=NULL; |
66 | 66 | ||
67 | X509_LOOKUP *X509_LOOKUP_new(method) | 67 | X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method) |
68 | X509_LOOKUP_METHOD *method; | ||
69 | { | 68 | { |
70 | X509_LOOKUP *ret; | 69 | X509_LOOKUP *ret; |
71 | 70 | ||
@@ -85,8 +84,7 @@ X509_LOOKUP_METHOD *method; | |||
85 | return(ret); | 84 | return(ret); |
86 | } | 85 | } |
87 | 86 | ||
88 | void X509_LOOKUP_free(ctx) | 87 | void X509_LOOKUP_free(X509_LOOKUP *ctx) |
89 | X509_LOOKUP *ctx; | ||
90 | { | 88 | { |
91 | if (ctx == NULL) return; | 89 | if (ctx == NULL) return; |
92 | if ( (ctx->method != NULL) && | 90 | if ( (ctx->method != NULL) && |
@@ -95,8 +93,7 @@ X509_LOOKUP *ctx; | |||
95 | Free(ctx); | 93 | Free(ctx); |
96 | } | 94 | } |
97 | 95 | ||
98 | int X509_LOOKUP_init(ctx) | 96 | int X509_LOOKUP_init(X509_LOOKUP *ctx) |
99 | X509_LOOKUP *ctx; | ||
100 | { | 97 | { |
101 | if (ctx->method == NULL) return(0); | 98 | if (ctx->method == NULL) return(0); |
102 | if (ctx->method->init != NULL) | 99 | if (ctx->method->init != NULL) |
@@ -105,22 +102,17 @@ X509_LOOKUP *ctx; | |||
105 | return(1); | 102 | return(1); |
106 | } | 103 | } |
107 | 104 | ||
108 | int X509_LOOKUP_shutdown(ctx) | 105 | int X509_LOOKUP_shutdown(X509_LOOKUP *ctx) |
109 | X509_LOOKUP *ctx; | ||
110 | { | 106 | { |
111 | if (ctx->method == NULL) return(0); | 107 | if (ctx->method == NULL) return(0); |
112 | if (ctx->method->init != NULL) | 108 | if (ctx->method->shutdown != NULL) |
113 | return(ctx->method->shutdown(ctx)); | 109 | return(ctx->method->shutdown(ctx)); |
114 | else | 110 | else |
115 | return(1); | 111 | return(1); |
116 | } | 112 | } |
117 | 113 | ||
118 | int X509_LOOKUP_ctrl(ctx,cmd,argc,argl,ret) | 114 | int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, |
119 | X509_LOOKUP *ctx; | 115 | char **ret) |
120 | int cmd; | ||
121 | char *argc; | ||
122 | long argl; | ||
123 | char **ret; | ||
124 | { | 116 | { |
125 | if (ctx->method == NULL) return(-1); | 117 | if (ctx->method == NULL) return(-1); |
126 | if (ctx->method->ctrl != NULL) | 118 | if (ctx->method->ctrl != NULL) |
@@ -129,11 +121,8 @@ char **ret; | |||
129 | return(1); | 121 | return(1); |
130 | } | 122 | } |
131 | 123 | ||
132 | int X509_LOOKUP_by_subject(ctx,type,name,ret) | 124 | int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name, |
133 | X509_LOOKUP *ctx; | 125 | X509_OBJECT *ret) |
134 | int type; | ||
135 | X509_NAME *name; | ||
136 | X509_OBJECT *ret; | ||
137 | { | 126 | { |
138 | if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL)) | 127 | if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL)) |
139 | return(X509_LU_FAIL); | 128 | return(X509_LU_FAIL); |
@@ -141,12 +130,8 @@ X509_OBJECT *ret; | |||
141 | return(ctx->method->get_by_subject(ctx,type,name,ret)); | 130 | return(ctx->method->get_by_subject(ctx,type,name,ret)); |
142 | } | 131 | } |
143 | 132 | ||
144 | int X509_LOOKUP_by_issuer_serial(ctx,type,name,serial,ret) | 133 | int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name, |
145 | X509_LOOKUP *ctx; | 134 | ASN1_INTEGER *serial, X509_OBJECT *ret) |
146 | int type; | ||
147 | X509_NAME *name; | ||
148 | ASN1_INTEGER *serial; | ||
149 | X509_OBJECT *ret; | ||
150 | { | 135 | { |
151 | if ((ctx->method == NULL) || | 136 | if ((ctx->method == NULL) || |
152 | (ctx->method->get_by_issuer_serial == NULL)) | 137 | (ctx->method->get_by_issuer_serial == NULL)) |
@@ -154,32 +139,23 @@ X509_OBJECT *ret; | |||
154 | return(ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret)); | 139 | return(ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret)); |
155 | } | 140 | } |
156 | 141 | ||
157 | int X509_LOOKUP_by_fingerprint(ctx,type,bytes,len,ret) | 142 | int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, |
158 | X509_LOOKUP *ctx; | 143 | unsigned char *bytes, int len, X509_OBJECT *ret) |
159 | int type; | ||
160 | unsigned char *bytes; | ||
161 | int len; | ||
162 | X509_OBJECT *ret; | ||
163 | { | 144 | { |
164 | if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL)) | 145 | if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL)) |
165 | return(X509_LU_FAIL); | 146 | return(X509_LU_FAIL); |
166 | return(ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret)); | 147 | return(ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret)); |
167 | } | 148 | } |
168 | 149 | ||
169 | int X509_LOOKUP_by_alias(ctx,type,str,len,ret) | 150 | int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len, |
170 | X509_LOOKUP *ctx; | 151 | X509_OBJECT *ret) |
171 | int type; | ||
172 | char *str; | ||
173 | int len; | ||
174 | X509_OBJECT *ret; | ||
175 | { | 152 | { |
176 | if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL)) | 153 | if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL)) |
177 | return(X509_LU_FAIL); | 154 | return(X509_LU_FAIL); |
178 | return(ctx->method->get_by_alias(ctx,str,len,ret)); | 155 | return(ctx->method->get_by_alias(ctx,type,str,len,ret)); |
179 | } | 156 | } |
180 | 157 | ||
181 | static unsigned long x509_object_hash(a) | 158 | static unsigned long x509_object_hash(X509_OBJECT *a) |
182 | X509_OBJECT *a; | ||
183 | { | 159 | { |
184 | unsigned long h; | 160 | unsigned long h; |
185 | 161 | ||
@@ -197,8 +173,7 @@ X509_OBJECT *a; | |||
197 | return(h); | 173 | return(h); |
198 | } | 174 | } |
199 | 175 | ||
200 | static int x509_object_cmp(a,b) | 176 | static int x509_object_cmp(X509_OBJECT *a, X509_OBJECT *b) |
201 | X509_OBJECT *a,*b; | ||
202 | { | 177 | { |
203 | int ret; | 178 | int ret; |
204 | 179 | ||
@@ -218,7 +193,7 @@ X509_OBJECT *a,*b; | |||
218 | return(ret); | 193 | return(ret); |
219 | } | 194 | } |
220 | 195 | ||
221 | X509_STORE *X509_STORE_new() | 196 | X509_STORE *X509_STORE_new(void) |
222 | { | 197 | { |
223 | X509_STORE *ret; | 198 | X509_STORE *ret; |
224 | 199 | ||
@@ -226,16 +201,16 @@ X509_STORE *X509_STORE_new() | |||
226 | return(NULL); | 201 | return(NULL); |
227 | ret->certs=lh_new(x509_object_hash,x509_object_cmp); | 202 | ret->certs=lh_new(x509_object_hash,x509_object_cmp); |
228 | ret->cache=1; | 203 | ret->cache=1; |
229 | ret->get_cert_methods=sk_new_null(); | 204 | ret->get_cert_methods=sk_X509_LOOKUP_new_null(); |
230 | ret->verify=NULL; | 205 | ret->verify=NULL; |
231 | ret->verify_cb=NULL; | 206 | ret->verify_cb=NULL; |
232 | memset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA)); | 207 | memset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA)); |
233 | ret->references=1; | 208 | ret->references=1; |
209 | ret->depth=0; | ||
234 | return(ret); | 210 | return(ret); |
235 | } | 211 | } |
236 | 212 | ||
237 | static void cleanup(a) | 213 | static void cleanup(X509_OBJECT *a) |
238 | X509_OBJECT *a; | ||
239 | { | 214 | { |
240 | if (a->type == X509_LU_X509) | 215 | if (a->type == X509_LU_X509) |
241 | { | 216 | { |
@@ -251,21 +226,23 @@ X509_OBJECT *a; | |||
251 | Free(a); | 226 | Free(a); |
252 | } | 227 | } |
253 | 228 | ||
254 | void X509_STORE_free(vfy) | 229 | void X509_STORE_free(X509_STORE *vfy) |
255 | X509_STORE *vfy; | ||
256 | { | 230 | { |
257 | int i; | 231 | int i; |
258 | STACK *sk; | 232 | STACK_OF(X509_LOOKUP) *sk; |
259 | X509_LOOKUP *lu; | 233 | X509_LOOKUP *lu; |
260 | 234 | ||
235 | if(vfy == NULL) | ||
236 | return; | ||
237 | |||
261 | sk=vfy->get_cert_methods; | 238 | sk=vfy->get_cert_methods; |
262 | for (i=0; i<sk_num(sk); i++) | 239 | for (i=0; i<sk_X509_LOOKUP_num(sk); i++) |
263 | { | 240 | { |
264 | lu=(X509_LOOKUP *)sk_value(sk,i); | 241 | lu=sk_X509_LOOKUP_value(sk,i); |
265 | X509_LOOKUP_shutdown(lu); | 242 | X509_LOOKUP_shutdown(lu); |
266 | X509_LOOKUP_free(lu); | 243 | X509_LOOKUP_free(lu); |
267 | } | 244 | } |
268 | sk_free(sk); | 245 | sk_X509_LOOKUP_free(sk); |
269 | 246 | ||
270 | CRYPTO_free_ex_data(x509_store_meth,(char *)vfy,&vfy->ex_data); | 247 | CRYPTO_free_ex_data(x509_store_meth,(char *)vfy,&vfy->ex_data); |
271 | lh_doall(vfy->certs,cleanup); | 248 | lh_doall(vfy->certs,cleanup); |
@@ -273,18 +250,16 @@ X509_STORE *vfy; | |||
273 | Free(vfy); | 250 | Free(vfy); |
274 | } | 251 | } |
275 | 252 | ||
276 | X509_LOOKUP *X509_STORE_add_lookup(v,m) | 253 | X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m) |
277 | X509_STORE *v; | ||
278 | X509_LOOKUP_METHOD *m; | ||
279 | { | 254 | { |
280 | int i; | 255 | int i; |
281 | STACK *sk; | 256 | STACK_OF(X509_LOOKUP) *sk; |
282 | X509_LOOKUP *lu; | 257 | X509_LOOKUP *lu; |
283 | 258 | ||
284 | sk=v->get_cert_methods; | 259 | sk=v->get_cert_methods; |
285 | for (i=0; i<sk_num(sk); i++) | 260 | for (i=0; i<sk_X509_LOOKUP_num(sk); i++) |
286 | { | 261 | { |
287 | lu=(X509_LOOKUP *)sk_value(sk,i); | 262 | lu=sk_X509_LOOKUP_value(sk,i); |
288 | if (m == lu->method) | 263 | if (m == lu->method) |
289 | { | 264 | { |
290 | return(lu); | 265 | return(lu); |
@@ -297,7 +272,7 @@ X509_LOOKUP_METHOD *m; | |||
297 | else | 272 | else |
298 | { | 273 | { |
299 | lu->store_ctx=v; | 274 | lu->store_ctx=v; |
300 | if (sk_push(v->get_cert_methods,(char *)lu)) | 275 | if (sk_X509_LOOKUP_push(v->get_cert_methods,lu)) |
301 | return(lu); | 276 | return(lu); |
302 | else | 277 | else |
303 | { | 278 | { |
@@ -307,24 +282,21 @@ X509_LOOKUP_METHOD *m; | |||
307 | } | 282 | } |
308 | } | 283 | } |
309 | 284 | ||
310 | int X509_STORE_get_by_subject(vs,type,name,ret) | 285 | int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name, |
311 | X509_STORE_CTX *vs; | 286 | X509_OBJECT *ret) |
312 | int type; | ||
313 | X509_NAME *name; | ||
314 | X509_OBJECT *ret; | ||
315 | { | 287 | { |
316 | X509_STORE *ctx=vs->ctx; | 288 | X509_STORE *ctx=vs->ctx; |
317 | X509_LOOKUP *lu; | 289 | X509_LOOKUP *lu; |
318 | X509_OBJECT stmp,*tmp; | 290 | X509_OBJECT stmp,*tmp; |
319 | int i,j; | 291 | int i,j; |
320 | 292 | ||
321 | tmp=X509_OBJECT_retrive_by_subject(ctx->certs,type,name); | 293 | tmp=X509_OBJECT_retrieve_by_subject(ctx->certs,type,name); |
322 | 294 | ||
323 | if (tmp == NULL) | 295 | if (tmp == NULL) |
324 | { | 296 | { |
325 | for (i=vs->current_method; i<sk_num(ctx->get_cert_methods); i++) | 297 | for (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++) |
326 | { | 298 | { |
327 | lu=(X509_LOOKUP *)sk_value(ctx->get_cert_methods,i); | 299 | lu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i); |
328 | j=X509_LOOKUP_by_subject(lu,type,name,&stmp); | 300 | j=X509_LOOKUP_by_subject(lu,type,name,&stmp); |
329 | if (j < 0) | 301 | if (j < 0) |
330 | { | 302 | { |
@@ -353,8 +325,7 @@ X509_OBJECT *ret; | |||
353 | return(1); | 325 | return(1); |
354 | } | 326 | } |
355 | 327 | ||
356 | void X509_OBJECT_up_ref_count(a) | 328 | void X509_OBJECT_up_ref_count(X509_OBJECT *a) |
357 | X509_OBJECT *a; | ||
358 | { | 329 | { |
359 | switch (a->type) | 330 | switch (a->type) |
360 | { | 331 | { |
@@ -367,8 +338,7 @@ X509_OBJECT *a; | |||
367 | } | 338 | } |
368 | } | 339 | } |
369 | 340 | ||
370 | void X509_OBJECT_free_contents(a) | 341 | void X509_OBJECT_free_contents(X509_OBJECT *a) |
371 | X509_OBJECT *a; | ||
372 | { | 342 | { |
373 | switch (a->type) | 343 | switch (a->type) |
374 | { | 344 | { |
@@ -381,10 +351,8 @@ X509_OBJECT *a; | |||
381 | } | 351 | } |
382 | } | 352 | } |
383 | 353 | ||
384 | X509_OBJECT *X509_OBJECT_retrive_by_subject(h,type,name) | 354 | X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h, int type, |
385 | LHASH *h; | 355 | X509_NAME *name) |
386 | int type; | ||
387 | X509_NAME *name; | ||
388 | { | 356 | { |
389 | X509_OBJECT stmp,*tmp; | 357 | X509_OBJECT stmp,*tmp; |
390 | X509 x509_s; | 358 | X509 x509_s; |
@@ -413,11 +381,8 @@ X509_NAME *name; | |||
413 | return(tmp); | 381 | return(tmp); |
414 | } | 382 | } |
415 | 383 | ||
416 | void X509_STORE_CTX_init(ctx,store,x509,chain) | 384 | void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509, |
417 | X509_STORE_CTX *ctx; | 385 | STACK_OF(X509) *chain) |
418 | X509_STORE *store; | ||
419 | X509 *x509; | ||
420 | STACK *chain; | ||
421 | { | 386 | { |
422 | ctx->ctx=store; | 387 | ctx->ctx=store; |
423 | ctx->current_method=0; | 388 | ctx->current_method=0; |
@@ -426,21 +391,21 @@ STACK *chain; | |||
426 | ctx->last_untrusted=0; | 391 | ctx->last_untrusted=0; |
427 | ctx->valid=0; | 392 | ctx->valid=0; |
428 | ctx->chain=NULL; | 393 | ctx->chain=NULL; |
429 | ctx->depth=10; | 394 | ctx->depth=9; |
430 | ctx->error=0; | 395 | ctx->error=0; |
431 | ctx->current_cert=NULL; | 396 | ctx->current_cert=NULL; |
432 | memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA)); | 397 | memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA)); |
433 | } | 398 | } |
434 | 399 | ||
435 | void X509_STORE_CTX_cleanup(ctx) | 400 | void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx) |
436 | X509_STORE_CTX *ctx; | ||
437 | { | 401 | { |
438 | if (ctx->chain != NULL) | 402 | if (ctx->chain != NULL) |
439 | { | 403 | { |
440 | sk_pop_free(ctx->chain,X509_free); | 404 | sk_X509_pop_free(ctx->chain,X509_free); |
441 | ctx->chain=NULL; | 405 | ctx->chain=NULL; |
442 | } | 406 | } |
443 | CRYPTO_free_ex_data(x509_store_ctx_meth,(char *)ctx,&(ctx->ex_data)); | 407 | CRYPTO_free_ex_data(x509_store_ctx_meth,(char *)ctx,&(ctx->ex_data)); |
444 | memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA)); | 408 | memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA)); |
445 | } | 409 | } |
446 | 410 | ||
411 | IMPLEMENT_STACK_OF(X509_LOOKUP) | ||