xref: /aosp_15_r20/external/cronet/third_party/boringssl/src/crypto/x509/x509_lu.c (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 /* Copyright (C) 1995-1998 Eric Young ([email protected])
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young ([email protected]).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to.  The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson ([email protected]).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  *    must display the following acknowledgement:
32  *    "This product includes cryptographic software written by
33  *     Eric Young ([email protected])"
34  *    The word 'cryptographic' can be left out if the rouines from the library
35  *    being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  *    the apps directory (application code) you must include an acknowledgement:
38  *    "This product includes software written by Tim Hudson ([email protected])"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed.  i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.] */
56 
57 #include <string.h>
58 
59 #include <openssl/err.h>
60 #include <openssl/mem.h>
61 #include <openssl/thread.h>
62 #include <openssl/x509.h>
63 
64 #include "../internal.h"
65 #include "internal.h"
66 
67 
68 static int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
69                                       X509_NAME *name);
70 static X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h,
71                                                     int type, X509_NAME *name);
72 static X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h,
73                                                X509_OBJECT *x);
74 static int X509_OBJECT_up_ref_count(X509_OBJECT *a);
75 
76 static X509_LOOKUP *X509_LOOKUP_new(const X509_LOOKUP_METHOD *method,
77                                     X509_STORE *store);
78 static int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
79                                   X509_OBJECT *ret);
80 
X509_LOOKUP_new(const X509_LOOKUP_METHOD * method,X509_STORE * store)81 static X509_LOOKUP *X509_LOOKUP_new(const X509_LOOKUP_METHOD *method,
82                                     X509_STORE *store) {
83   X509_LOOKUP *ret = OPENSSL_zalloc(sizeof(X509_LOOKUP));
84   if (ret == NULL) {
85     return NULL;
86   }
87 
88   ret->method = method;
89   ret->store_ctx = store;
90   if (method->new_item != NULL && !method->new_item(ret)) {
91     OPENSSL_free(ret);
92     return NULL;
93   }
94   return ret;
95 }
96 
X509_LOOKUP_free(X509_LOOKUP * ctx)97 void X509_LOOKUP_free(X509_LOOKUP *ctx) {
98   if (ctx == NULL) {
99     return;
100   }
101   if (ctx->method != NULL && ctx->method->free != NULL) {
102     (*ctx->method->free)(ctx);
103   }
104   OPENSSL_free(ctx);
105 }
106 
X509_LOOKUP_ctrl(X509_LOOKUP * ctx,int cmd,const char * argc,long argl,char ** ret)107 int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
108                      char **ret) {
109   if (ctx->method == NULL) {
110     return -1;
111   }
112   if (ctx->method->ctrl != NULL) {
113     return ctx->method->ctrl(ctx, cmd, argc, argl, ret);
114   } else {
115     return 1;
116   }
117 }
118 
X509_LOOKUP_by_subject(X509_LOOKUP * ctx,int type,X509_NAME * name,X509_OBJECT * ret)119 static int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
120                                   X509_OBJECT *ret) {
121   if (ctx->method == NULL || ctx->method->get_by_subject == NULL) {
122     return 0;
123   }
124   // Note |get_by_subject| leaves |ret| in an inconsistent state. It has
125   // pointers to an |X509| or |X509_CRL|, but has not bumped the refcount yet.
126   // For now, the caller is expected to fix this, but ideally we'd fix the
127   // |X509_LOOKUP| convention itself.
128   return ctx->method->get_by_subject(ctx, type, name, ret) > 0;
129 }
130 
x509_object_cmp(const X509_OBJECT * a,const X509_OBJECT * b)131 static int x509_object_cmp(const X509_OBJECT *a, const X509_OBJECT *b) {
132   int ret = a->type - b->type;
133   if (ret) {
134     return ret;
135   }
136   switch (a->type) {
137     case X509_LU_X509:
138       return X509_subject_name_cmp(a->data.x509, b->data.x509);
139     case X509_LU_CRL:
140       return X509_CRL_cmp(a->data.crl, b->data.crl);
141     default:
142       // abort();
143       return 0;
144   }
145 }
146 
x509_object_cmp_sk(const X509_OBJECT * const * a,const X509_OBJECT * const * b)147 static int x509_object_cmp_sk(const X509_OBJECT *const *a,
148                               const X509_OBJECT *const *b) {
149   return x509_object_cmp(*a, *b);
150 }
151 
X509_STORE_new(void)152 X509_STORE *X509_STORE_new(void) {
153   X509_STORE *ret = OPENSSL_zalloc(sizeof(X509_STORE));
154   if (ret == NULL) {
155     return NULL;
156   }
157 
158   ret->references = 1;
159   CRYPTO_MUTEX_init(&ret->objs_lock);
160   ret->objs = sk_X509_OBJECT_new(x509_object_cmp_sk);
161   ret->get_cert_methods = sk_X509_LOOKUP_new_null();
162   ret->param = X509_VERIFY_PARAM_new();
163   if (ret->objs == NULL ||
164       ret->get_cert_methods == NULL ||
165       ret->param == NULL) {
166     X509_STORE_free(ret);
167     return NULL;
168   }
169 
170   return ret;
171 }
172 
X509_STORE_up_ref(X509_STORE * store)173 int X509_STORE_up_ref(X509_STORE *store) {
174   CRYPTO_refcount_inc(&store->references);
175   return 1;
176 }
177 
X509_STORE_free(X509_STORE * vfy)178 void X509_STORE_free(X509_STORE *vfy) {
179   if (vfy == NULL) {
180     return;
181   }
182 
183   if (!CRYPTO_refcount_dec_and_test_zero(&vfy->references)) {
184     return;
185   }
186 
187   CRYPTO_MUTEX_cleanup(&vfy->objs_lock);
188   sk_X509_LOOKUP_pop_free(vfy->get_cert_methods, X509_LOOKUP_free);
189   sk_X509_OBJECT_pop_free(vfy->objs, X509_OBJECT_free);
190   X509_VERIFY_PARAM_free(vfy->param);
191   OPENSSL_free(vfy);
192 }
193 
X509_STORE_add_lookup(X509_STORE * v,const X509_LOOKUP_METHOD * m)194 X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, const X509_LOOKUP_METHOD *m) {
195   STACK_OF(X509_LOOKUP) *sk = v->get_cert_methods;
196   for (size_t i = 0; i < sk_X509_LOOKUP_num(sk); i++) {
197     X509_LOOKUP *lu = sk_X509_LOOKUP_value(sk, i);
198     if (m == lu->method) {
199       return lu;
200     }
201   }
202 
203   X509_LOOKUP *lu = X509_LOOKUP_new(m, v);
204   if (lu == NULL || !sk_X509_LOOKUP_push(v->get_cert_methods, lu)) {
205     X509_LOOKUP_free(lu);
206     return NULL;
207   }
208 
209   return lu;
210 }
211 
X509_STORE_CTX_get_by_subject(X509_STORE_CTX * vs,int type,X509_NAME * name,X509_OBJECT * ret)212 int X509_STORE_CTX_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,
213                                   X509_OBJECT *ret) {
214   X509_STORE *ctx = vs->ctx;
215   X509_OBJECT stmp;
216   CRYPTO_MUTEX_lock_write(&ctx->objs_lock);
217   X509_OBJECT *tmp = X509_OBJECT_retrieve_by_subject(ctx->objs, type, name);
218   CRYPTO_MUTEX_unlock_write(&ctx->objs_lock);
219 
220   if (tmp == NULL || type == X509_LU_CRL) {
221     for (size_t i = 0; i < sk_X509_LOOKUP_num(ctx->get_cert_methods); i++) {
222       X509_LOOKUP *lu = sk_X509_LOOKUP_value(ctx->get_cert_methods, i);
223       if (X509_LOOKUP_by_subject(lu, type, name, &stmp)) {
224         tmp = &stmp;
225         break;
226       }
227     }
228     if (tmp == NULL) {
229       return 0;
230     }
231   }
232 
233   // TODO(crbug.com/boringssl/685): This should call
234   // |X509_OBJECT_free_contents|.
235   ret->type = tmp->type;
236   ret->data = tmp->data;
237   X509_OBJECT_up_ref_count(ret);
238   return 1;
239 }
240 
x509_store_add(X509_STORE * ctx,void * x,int is_crl)241 static int x509_store_add(X509_STORE *ctx, void *x, int is_crl) {
242   if (x == NULL) {
243     return 0;
244   }
245 
246   X509_OBJECT *const obj = X509_OBJECT_new();
247   if (obj == NULL) {
248     return 0;
249   }
250 
251   if (is_crl) {
252     obj->type = X509_LU_CRL;
253     obj->data.crl = (X509_CRL *)x;
254   } else {
255     obj->type = X509_LU_X509;
256     obj->data.x509 = (X509 *)x;
257   }
258   X509_OBJECT_up_ref_count(obj);
259 
260   CRYPTO_MUTEX_lock_write(&ctx->objs_lock);
261 
262   int ret = 1;
263   int added = 0;
264   // Duplicates are silently ignored
265   if (!X509_OBJECT_retrieve_match(ctx->objs, obj)) {
266     ret = added = (sk_X509_OBJECT_push(ctx->objs, obj) != 0);
267   }
268 
269   CRYPTO_MUTEX_unlock_write(&ctx->objs_lock);
270 
271   if (!added) {
272     X509_OBJECT_free(obj);
273   }
274 
275   return ret;
276 }
277 
X509_STORE_add_cert(X509_STORE * ctx,X509 * x)278 int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) {
279   return x509_store_add(ctx, x, /*is_crl=*/0);
280 }
281 
X509_STORE_add_crl(X509_STORE * ctx,X509_CRL * x)282 int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) {
283   return x509_store_add(ctx, x, /*is_crl=*/1);
284 }
285 
X509_OBJECT_new(void)286 X509_OBJECT *X509_OBJECT_new(void) {
287   return OPENSSL_zalloc(sizeof(X509_OBJECT));
288 }
289 
X509_OBJECT_free(X509_OBJECT * obj)290 void X509_OBJECT_free(X509_OBJECT *obj) {
291   if (obj == NULL) {
292     return;
293   }
294   X509_OBJECT_free_contents(obj);
295   OPENSSL_free(obj);
296 }
297 
X509_OBJECT_up_ref_count(X509_OBJECT * a)298 static int X509_OBJECT_up_ref_count(X509_OBJECT *a) {
299   switch (a->type) {
300     case X509_LU_X509:
301       X509_up_ref(a->data.x509);
302       break;
303     case X509_LU_CRL:
304       X509_CRL_up_ref(a->data.crl);
305       break;
306   }
307   return 1;
308 }
309 
X509_OBJECT_free_contents(X509_OBJECT * a)310 void X509_OBJECT_free_contents(X509_OBJECT *a) {
311   switch (a->type) {
312     case X509_LU_X509:
313       X509_free(a->data.x509);
314       break;
315     case X509_LU_CRL:
316       X509_CRL_free(a->data.crl);
317       break;
318   }
319 
320   OPENSSL_memset(a, 0, sizeof(X509_OBJECT));
321 }
322 
X509_OBJECT_get_type(const X509_OBJECT * a)323 int X509_OBJECT_get_type(const X509_OBJECT *a) { return a->type; }
324 
X509_OBJECT_get0_X509(const X509_OBJECT * a)325 X509 *X509_OBJECT_get0_X509(const X509_OBJECT *a) {
326   if (a == NULL || a->type != X509_LU_X509) {
327     return NULL;
328   }
329   return a->data.x509;
330 }
331 
x509_object_idx_cnt(STACK_OF (X509_OBJECT)* h,int type,X509_NAME * name,int * pnmatch)332 static int x509_object_idx_cnt(STACK_OF(X509_OBJECT) *h, int type,
333                                X509_NAME *name, int *pnmatch) {
334   X509_OBJECT stmp;
335   X509 x509_s;
336   X509_CINF cinf_s;
337   X509_CRL crl_s;
338   X509_CRL_INFO crl_info_s;
339 
340   stmp.type = type;
341   switch (type) {
342     case X509_LU_X509:
343       stmp.data.x509 = &x509_s;
344       x509_s.cert_info = &cinf_s;
345       cinf_s.subject = name;
346       break;
347     case X509_LU_CRL:
348       stmp.data.crl = &crl_s;
349       crl_s.crl = &crl_info_s;
350       crl_info_s.issuer = name;
351       break;
352     default:
353       // abort();
354       return -1;
355   }
356 
357   size_t idx;
358   sk_X509_OBJECT_sort(h);
359   if (!sk_X509_OBJECT_find(h, &idx, &stmp)) {
360     return -1;
361   }
362 
363   if (pnmatch != NULL) {
364     *pnmatch = 1;
365     for (size_t tidx = idx + 1; tidx < sk_X509_OBJECT_num(h); tidx++) {
366       const X509_OBJECT *tobj = sk_X509_OBJECT_value(h, tidx);
367       if (x509_object_cmp(tobj, &stmp)) {
368         break;
369       }
370       (*pnmatch)++;
371     }
372   }
373 
374   return (int)idx;
375 }
376 
X509_OBJECT_idx_by_subject(STACK_OF (X509_OBJECT)* h,int type,X509_NAME * name)377 static int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
378                                       X509_NAME *name) {
379   return x509_object_idx_cnt(h, type, name, NULL);
380 }
381 
X509_OBJECT_retrieve_by_subject(STACK_OF (X509_OBJECT)* h,int type,X509_NAME * name)382 static X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h,
383                                                     int type, X509_NAME *name) {
384   int idx;
385   idx = X509_OBJECT_idx_by_subject(h, type, name);
386   if (idx == -1) {
387     return NULL;
388   }
389   return sk_X509_OBJECT_value(h, idx);
390 }
391 
x509_object_dup(const X509_OBJECT * obj)392 static X509_OBJECT *x509_object_dup(const X509_OBJECT *obj) {
393   X509_OBJECT *ret = X509_OBJECT_new();
394   if (ret == NULL) {
395     return NULL;
396   }
397   ret->type = obj->type;
398   ret->data = obj->data;
399   X509_OBJECT_up_ref_count(ret);
400   return ret;
401 }
402 
STACK_OF(X509_OBJECT)403 STACK_OF(X509_OBJECT) *X509_STORE_get1_objects(X509_STORE *store) {
404   CRYPTO_MUTEX_lock_read(&store->objs_lock);
405   STACK_OF(X509_OBJECT) *ret =
406       sk_X509_OBJECT_deep_copy(store->objs, x509_object_dup, X509_OBJECT_free);
407   CRYPTO_MUTEX_unlock_read(&store->objs_lock);
408   return ret;
409 }
410 
STACK_OF(X509_OBJECT)411 STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *store) {
412   return store->objs;
413 }
414 
STACK_OF(X509)415 STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) {
416   int cnt;
417   STACK_OF(X509) *sk = sk_X509_new_null();
418   if (sk == NULL) {
419     return NULL;
420   }
421   CRYPTO_MUTEX_lock_write(&ctx->ctx->objs_lock);
422   int idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
423   if (idx < 0) {
424     // Nothing found in cache: do lookup to possibly add new objects to
425     // cache
426     X509_OBJECT xobj;
427     CRYPTO_MUTEX_unlock_write(&ctx->ctx->objs_lock);
428     if (!X509_STORE_CTX_get_by_subject(ctx, X509_LU_X509, nm, &xobj)) {
429       sk_X509_free(sk);
430       return NULL;
431     }
432     X509_OBJECT_free_contents(&xobj);
433     CRYPTO_MUTEX_lock_write(&ctx->ctx->objs_lock);
434     idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
435     if (idx < 0) {
436       CRYPTO_MUTEX_unlock_write(&ctx->ctx->objs_lock);
437       sk_X509_free(sk);
438       return NULL;
439     }
440   }
441   for (int i = 0; i < cnt; i++, idx++) {
442     X509_OBJECT *obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
443     X509 *x = obj->data.x509;
444     if (!sk_X509_push(sk, x)) {
445       CRYPTO_MUTEX_unlock_write(&ctx->ctx->objs_lock);
446       sk_X509_pop_free(sk, X509_free);
447       return NULL;
448     }
449     X509_up_ref(x);
450   }
451   CRYPTO_MUTEX_unlock_write(&ctx->ctx->objs_lock);
452   return sk;
453 }
454 
STACK_OF(X509_CRL)455 STACK_OF(X509_CRL) *X509_STORE_CTX_get1_crls(X509_STORE_CTX *ctx,
456                                              X509_NAME *nm) {
457   int cnt;
458   X509_OBJECT xobj;
459   STACK_OF(X509_CRL) *sk = sk_X509_CRL_new_null();
460   if (sk == NULL) {
461     return NULL;
462   }
463 
464   // Always do lookup to possibly add new CRLs to cache.
465   if (!X509_STORE_CTX_get_by_subject(ctx, X509_LU_CRL, nm, &xobj)) {
466     sk_X509_CRL_free(sk);
467     return NULL;
468   }
469   X509_OBJECT_free_contents(&xobj);
470   CRYPTO_MUTEX_lock_write(&ctx->ctx->objs_lock);
471   int idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_CRL, nm, &cnt);
472   if (idx < 0) {
473     CRYPTO_MUTEX_unlock_write(&ctx->ctx->objs_lock);
474     sk_X509_CRL_free(sk);
475     return NULL;
476   }
477 
478   for (int i = 0; i < cnt; i++, idx++) {
479     X509_OBJECT *obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
480     X509_CRL *x = obj->data.crl;
481     X509_CRL_up_ref(x);
482     if (!sk_X509_CRL_push(sk, x)) {
483       CRYPTO_MUTEX_unlock_write(&ctx->ctx->objs_lock);
484       X509_CRL_free(x);
485       sk_X509_CRL_pop_free(sk, X509_CRL_free);
486       return NULL;
487     }
488   }
489   CRYPTO_MUTEX_unlock_write(&ctx->ctx->objs_lock);
490   return sk;
491 }
492 
X509_OBJECT_retrieve_match(STACK_OF (X509_OBJECT)* h,X509_OBJECT * x)493 static X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h,
494                                                X509_OBJECT *x) {
495   sk_X509_OBJECT_sort(h);
496   size_t idx;
497   if (!sk_X509_OBJECT_find(h, &idx, x)) {
498     return NULL;
499   }
500   if ((x->type != X509_LU_X509) && (x->type != X509_LU_CRL)) {
501     return sk_X509_OBJECT_value(h, idx);
502   }
503   for (size_t i = idx; i < sk_X509_OBJECT_num(h); i++) {
504     X509_OBJECT *obj = sk_X509_OBJECT_value(h, i);
505     if (x509_object_cmp(obj, x)) {
506       return NULL;
507     }
508     if (x->type == X509_LU_X509) {
509       if (!X509_cmp(obj->data.x509, x->data.x509)) {
510         return obj;
511       }
512     } else if (x->type == X509_LU_CRL) {
513       if (!X509_CRL_match(obj->data.crl, x->data.crl)) {
514         return obj;
515       }
516     } else {
517       return obj;
518     }
519   }
520   return NULL;
521 }
522 
X509_STORE_CTX_get1_issuer(X509 ** out_issuer,X509_STORE_CTX * ctx,X509 * x)523 int X509_STORE_CTX_get1_issuer(X509 **out_issuer, X509_STORE_CTX *ctx,
524                                X509 *x) {
525   X509_NAME *xn;
526   X509_OBJECT obj, *pobj;
527   int idx, ret;
528   size_t i;
529   xn = X509_get_issuer_name(x);
530   if (!X509_STORE_CTX_get_by_subject(ctx, X509_LU_X509, xn, &obj)) {
531     return 0;
532   }
533   // If certificate matches all OK
534   if (x509_check_issued_with_callback(ctx, x, obj.data.x509)) {
535     *out_issuer = obj.data.x509;
536     return 1;
537   }
538   X509_OBJECT_free_contents(&obj);
539 
540   // Else find index of first cert accepted by
541   // |x509_check_issued_with_callback|.
542   ret = 0;
543   CRYPTO_MUTEX_lock_write(&ctx->ctx->objs_lock);
544   idx = X509_OBJECT_idx_by_subject(ctx->ctx->objs, X509_LU_X509, xn);
545   if (idx != -1) {  // should be true as we've had at least one
546                     // match
547     // Look through all matching certs for suitable issuer
548     for (i = idx; i < sk_X509_OBJECT_num(ctx->ctx->objs); i++) {
549       pobj = sk_X509_OBJECT_value(ctx->ctx->objs, i);
550       // See if we've run past the matches
551       if (pobj->type != X509_LU_X509) {
552         break;
553       }
554       if (X509_NAME_cmp(xn, X509_get_subject_name(pobj->data.x509))) {
555         break;
556       }
557       if (x509_check_issued_with_callback(ctx, x, pobj->data.x509)) {
558         *out_issuer = pobj->data.x509;
559         X509_OBJECT_up_ref_count(pobj);
560         ret = 1;
561         break;
562       }
563     }
564   }
565   CRYPTO_MUTEX_unlock_write(&ctx->ctx->objs_lock);
566   return ret;
567 }
568 
X509_STORE_set_flags(X509_STORE * ctx,unsigned long flags)569 int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags) {
570   return X509_VERIFY_PARAM_set_flags(ctx->param, flags);
571 }
572 
X509_STORE_set_depth(X509_STORE * ctx,int depth)573 int X509_STORE_set_depth(X509_STORE *ctx, int depth) {
574   X509_VERIFY_PARAM_set_depth(ctx->param, depth);
575   return 1;
576 }
577 
X509_STORE_set_purpose(X509_STORE * ctx,int purpose)578 int X509_STORE_set_purpose(X509_STORE *ctx, int purpose) {
579   return X509_VERIFY_PARAM_set_purpose(ctx->param, purpose);
580 }
581 
X509_STORE_set_trust(X509_STORE * ctx,int trust)582 int X509_STORE_set_trust(X509_STORE *ctx, int trust) {
583   return X509_VERIFY_PARAM_set_trust(ctx->param, trust);
584 }
585 
X509_STORE_set1_param(X509_STORE * ctx,const X509_VERIFY_PARAM * param)586 int X509_STORE_set1_param(X509_STORE *ctx, const X509_VERIFY_PARAM *param) {
587   return X509_VERIFY_PARAM_set1(ctx->param, param);
588 }
589 
X509_STORE_get0_param(X509_STORE * ctx)590 X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *ctx) { return ctx->param; }
591 
X509_STORE_set_verify_cb(X509_STORE * ctx,X509_STORE_CTX_verify_cb verify_cb)592 void X509_STORE_set_verify_cb(X509_STORE *ctx,
593                               X509_STORE_CTX_verify_cb verify_cb) {
594   ctx->verify_cb = verify_cb;
595 }
596 
X509_STORE_set_get_crl(X509_STORE * ctx,X509_STORE_CTX_get_crl_fn get_crl)597 void X509_STORE_set_get_crl(X509_STORE *ctx,
598                             X509_STORE_CTX_get_crl_fn get_crl) {
599   ctx->get_crl = get_crl;
600 }
601 
X509_STORE_set_check_crl(X509_STORE * ctx,X509_STORE_CTX_check_crl_fn check_crl)602 void X509_STORE_set_check_crl(X509_STORE *ctx,
603                               X509_STORE_CTX_check_crl_fn check_crl) {
604   ctx->check_crl = check_crl;
605 }
606 
X509_STORE_CTX_get0_store(const X509_STORE_CTX * ctx)607 X509_STORE *X509_STORE_CTX_get0_store(const X509_STORE_CTX *ctx) {
608   return ctx->ctx;
609 }
610