summaryrefslogtreecommitdiff
path: root/src/lib/libssl/src/crypto/x509/x509_lu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/src/crypto/x509/x509_lu.c')
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_lu.c139
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
64static STACK *x509_store_meth=NULL; 64static STACK *x509_store_meth=NULL;
65static STACK *x509_store_ctx_meth=NULL; 65static STACK *x509_store_ctx_meth=NULL;
66 66
67X509_LOOKUP *X509_LOOKUP_new(method) 67X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method)
68X509_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
88void X509_LOOKUP_free(ctx) 87void X509_LOOKUP_free(X509_LOOKUP *ctx)
89X509_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
98int X509_LOOKUP_init(ctx) 96int X509_LOOKUP_init(X509_LOOKUP *ctx)
99X509_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
108int X509_LOOKUP_shutdown(ctx) 105int X509_LOOKUP_shutdown(X509_LOOKUP *ctx)
109X509_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
118int X509_LOOKUP_ctrl(ctx,cmd,argc,argl,ret) 114int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
119X509_LOOKUP *ctx; 115 char **ret)
120int cmd;
121char *argc;
122long argl;
123char **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
132int X509_LOOKUP_by_subject(ctx,type,name,ret) 124int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
133X509_LOOKUP *ctx; 125 X509_OBJECT *ret)
134int type;
135X509_NAME *name;
136X509_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
144int X509_LOOKUP_by_issuer_serial(ctx,type,name,serial,ret) 133int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
145X509_LOOKUP *ctx; 134 ASN1_INTEGER *serial, X509_OBJECT *ret)
146int type;
147X509_NAME *name;
148ASN1_INTEGER *serial;
149X509_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
157int X509_LOOKUP_by_fingerprint(ctx,type,bytes,len,ret) 142int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
158X509_LOOKUP *ctx; 143 unsigned char *bytes, int len, X509_OBJECT *ret)
159int type;
160unsigned char *bytes;
161int len;
162X509_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
169int X509_LOOKUP_by_alias(ctx,type,str,len,ret) 150int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len,
170X509_LOOKUP *ctx; 151 X509_OBJECT *ret)
171int type;
172char *str;
173int len;
174X509_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
181static unsigned long x509_object_hash(a) 158static unsigned long x509_object_hash(X509_OBJECT *a)
182X509_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
200static int x509_object_cmp(a,b) 176static int x509_object_cmp(X509_OBJECT *a, X509_OBJECT *b)
201X509_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
221X509_STORE *X509_STORE_new() 196X509_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
237static void cleanup(a) 213static void cleanup(X509_OBJECT *a)
238X509_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
254void X509_STORE_free(vfy) 229void X509_STORE_free(X509_STORE *vfy)
255X509_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
276X509_LOOKUP *X509_STORE_add_lookup(v,m) 253X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m)
277X509_STORE *v;
278X509_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
310int X509_STORE_get_by_subject(vs,type,name,ret) 285int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,
311X509_STORE_CTX *vs; 286 X509_OBJECT *ret)
312int type;
313X509_NAME *name;
314X509_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
356void X509_OBJECT_up_ref_count(a) 328void X509_OBJECT_up_ref_count(X509_OBJECT *a)
357X509_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
370void X509_OBJECT_free_contents(a) 341void X509_OBJECT_free_contents(X509_OBJECT *a)
371X509_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
384X509_OBJECT *X509_OBJECT_retrive_by_subject(h,type,name) 354X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h, int type,
385LHASH *h; 355 X509_NAME *name)
386int type;
387X509_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
416void X509_STORE_CTX_init(ctx,store,x509,chain) 384void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
417X509_STORE_CTX *ctx; 385 STACK_OF(X509) *chain)
418X509_STORE *store;
419X509 *x509;
420STACK *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
435void X509_STORE_CTX_cleanup(ctx) 400void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
436X509_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
411IMPLEMENT_STACK_OF(X509_LOOKUP)