summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/x_crl.c
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2015-03-08 16:48:49 +0000
committercvs2svn <admin@example.com>2015-03-08 16:48:49 +0000
commitdecf84ba5550c1656a7fdb51b5b81969590c3f03 (patch)
tree44872802e872bdfd60730fa9cf01d9d5751251c1 /src/lib/libcrypto/asn1/x_crl.c
parent7a8f138352aa4eb7b65ac4b1a5fe7630fbee1427 (diff)
downloadopenbsd-libressl-v2.1.5.tar.gz
openbsd-libressl-v2.1.5.tar.bz2
openbsd-libressl-v2.1.5.zip
This commit was manufactured by cvs2git to create branch 'OPENBSD_5_7'.libressl-v2.1.5
Diffstat (limited to 'src/lib/libcrypto/asn1/x_crl.c')
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c686
1 files changed, 0 insertions, 686 deletions
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
deleted file mode 100644
index 7b76d2ec47..0000000000
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ /dev/null
@@ -1,686 +0,0 @@
1/* $OpenBSD: x_crl.c,v 1.24 2015/02/11 04:00:39 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
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
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
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.
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
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:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
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
51 * SUCH DAMAGE.
52 *
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
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60
61#include <openssl/opensslconf.h>
62
63#include <openssl/asn1t.h>
64#include <openssl/err.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68#include "asn1_locl.h"
69
70static int X509_REVOKED_cmp(const X509_REVOKED * const *a,
71 const X509_REVOKED * const *b);
72static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp);
73
74static const ASN1_TEMPLATE X509_REVOKED_seq_tt[] = {
75 {
76 .offset = offsetof(X509_REVOKED, serialNumber),
77 .field_name = "serialNumber",
78 .item = &ASN1_INTEGER_it,
79 },
80 {
81 .offset = offsetof(X509_REVOKED, revocationDate),
82 .field_name = "revocationDate",
83 .item = &ASN1_TIME_it,
84 },
85 {
86 .flags = ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
87 .offset = offsetof(X509_REVOKED, extensions),
88 .field_name = "extensions",
89 .item = &X509_EXTENSION_it,
90 },
91};
92
93const ASN1_ITEM X509_REVOKED_it = {
94 .itype = ASN1_ITYPE_SEQUENCE,
95 .utype = V_ASN1_SEQUENCE,
96 .templates = X509_REVOKED_seq_tt,
97 .tcount = sizeof(X509_REVOKED_seq_tt) / sizeof(ASN1_TEMPLATE),
98 .size = sizeof(X509_REVOKED),
99 .sname = "X509_REVOKED",
100};
101
102static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r);
103static int def_crl_lookup(X509_CRL *crl, X509_REVOKED **ret,
104 ASN1_INTEGER *serial, X509_NAME *issuer);
105
106static X509_CRL_METHOD int_crl_meth = {
107 .crl_lookup = def_crl_lookup,
108 .crl_verify = def_crl_verify
109};
110
111static const X509_CRL_METHOD *default_crl_method = &int_crl_meth;
112
113/* The X509_CRL_INFO structure needs a bit of customisation.
114 * Since we cache the original encoding the signature wont be affected by
115 * reordering of the revoked field.
116 */
117static int
118crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
119{
120 X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
121
122 if (!a || !a->revoked)
123 return 1;
124 switch (operation) {
125 /* Just set cmp function here. We don't sort because that
126 * would affect the output of X509_CRL_print().
127 */
128 case ASN1_OP_D2I_POST:
129 (void)sk_X509_REVOKED_set_cmp_func(a->revoked, X509_REVOKED_cmp);
130 break;
131 }
132 return 1;
133}
134
135
136static const ASN1_AUX X509_CRL_INFO_aux = {
137 .flags = ASN1_AFLG_ENCODING,
138 .asn1_cb = crl_inf_cb,
139 .enc_offset = offsetof(X509_CRL_INFO, enc),
140};
141static const ASN1_TEMPLATE X509_CRL_INFO_seq_tt[] = {
142 {
143 .flags = ASN1_TFLG_OPTIONAL,
144 .offset = offsetof(X509_CRL_INFO, version),
145 .field_name = "version",
146 .item = &ASN1_INTEGER_it,
147 },
148 {
149 .offset = offsetof(X509_CRL_INFO, sig_alg),
150 .field_name = "sig_alg",
151 .item = &X509_ALGOR_it,
152 },
153 {
154 .offset = offsetof(X509_CRL_INFO, issuer),
155 .field_name = "issuer",
156 .item = &X509_NAME_it,
157 },
158 {
159 .offset = offsetof(X509_CRL_INFO, lastUpdate),
160 .field_name = "lastUpdate",
161 .item = &ASN1_TIME_it,
162 },
163 {
164 .flags = ASN1_TFLG_OPTIONAL,
165 .offset = offsetof(X509_CRL_INFO, nextUpdate),
166 .field_name = "nextUpdate",
167 .item = &ASN1_TIME_it,
168 },
169 {
170 .flags = ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
171 .offset = offsetof(X509_CRL_INFO, revoked),
172 .field_name = "revoked",
173 .item = &X509_REVOKED_it,
174 },
175 {
176 .flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
177 .offset = offsetof(X509_CRL_INFO, extensions),
178 .field_name = "extensions",
179 .item = &X509_EXTENSION_it,
180 },
181};
182
183const ASN1_ITEM X509_CRL_INFO_it = {
184 .itype = ASN1_ITYPE_SEQUENCE,
185 .utype = V_ASN1_SEQUENCE,
186 .templates = X509_CRL_INFO_seq_tt,
187 .tcount = sizeof(X509_CRL_INFO_seq_tt) / sizeof(ASN1_TEMPLATE),
188 .funcs = &X509_CRL_INFO_aux,
189 .size = sizeof(X509_CRL_INFO),
190 .sname = "X509_CRL_INFO",
191};
192
193/* Set CRL entry issuer according to CRL certificate issuer extension.
194 * Check for unhandled critical CRL entry extensions.
195 */
196
197static int
198crl_set_issuers(X509_CRL *crl)
199{
200 int i, j;
201 GENERAL_NAMES *gens, *gtmp;
202 STACK_OF(X509_REVOKED) *revoked;
203
204 revoked = X509_CRL_get_REVOKED(crl);
205
206 gens = NULL;
207 for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) {
208 X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i);
209 STACK_OF(X509_EXTENSION) *exts;
210 ASN1_ENUMERATED *reason;
211 X509_EXTENSION *ext;
212 gtmp = X509_REVOKED_get_ext_d2i(rev, NID_certificate_issuer,
213 &j, NULL);
214 if (!gtmp && (j != -1)) {
215 crl->flags |= EXFLAG_INVALID;
216 return 1;
217 }
218
219 if (gtmp) {
220 gens = gtmp;
221 if (!crl->issuers) {
222 crl->issuers = sk_GENERAL_NAMES_new_null();
223 if (!crl->issuers)
224 return 0;
225 }
226 if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp))
227 return 0;
228 }
229 rev->issuer = gens;
230
231 reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason,
232 &j, NULL);
233 if (!reason && (j != -1)) {
234 crl->flags |= EXFLAG_INVALID;
235 return 1;
236 }
237
238 if (reason) {
239 rev->reason = ASN1_ENUMERATED_get(reason);
240 ASN1_ENUMERATED_free(reason);
241 } else
242 rev->reason = CRL_REASON_NONE;
243
244 /* Check for critical CRL entry extensions */
245
246 exts = rev->extensions;
247
248 for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) {
249 ext = sk_X509_EXTENSION_value(exts, j);
250 if (ext->critical > 0) {
251 if (OBJ_obj2nid(ext->object) ==
252 NID_certificate_issuer)
253 continue;
254 crl->flags |= EXFLAG_CRITICAL;
255 break;
256 }
257 }
258 }
259
260 return 1;
261}
262
263/* The X509_CRL structure needs a bit of customisation. Cache some extensions
264 * and hash of the whole CRL.
265 */
266static int
267crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
268{
269 X509_CRL *crl = (X509_CRL *)*pval;
270 STACK_OF(X509_EXTENSION) *exts;
271 X509_EXTENSION *ext;
272 int idx;
273
274 switch (operation) {
275 case ASN1_OP_NEW_POST:
276 crl->idp = NULL;
277 crl->akid = NULL;
278 crl->flags = 0;
279 crl->idp_flags = 0;
280 crl->idp_reasons = CRLDP_ALL_REASONS;
281 crl->meth = default_crl_method;
282 crl->meth_data = NULL;
283 crl->issuers = NULL;
284 crl->crl_number = NULL;
285 crl->base_crl_number = NULL;
286 break;
287
288 case ASN1_OP_D2I_POST:
289#ifndef OPENSSL_NO_SHA
290 X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL);
291#endif
292 crl->idp = X509_CRL_get_ext_d2i(crl,
293 NID_issuing_distribution_point, NULL, NULL);
294 if (crl->idp)
295 setup_idp(crl, crl->idp);
296
297 crl->akid = X509_CRL_get_ext_d2i(crl,
298 NID_authority_key_identifier, NULL, NULL);
299
300 crl->crl_number = X509_CRL_get_ext_d2i(crl,
301 NID_crl_number, NULL, NULL);
302
303 crl->base_crl_number = X509_CRL_get_ext_d2i(crl,
304 NID_delta_crl, NULL, NULL);
305 /* Delta CRLs must have CRL number */
306 if (crl->base_crl_number && !crl->crl_number)
307 crl->flags |= EXFLAG_INVALID;
308
309 /* See if we have any unhandled critical CRL extensions and
310 * indicate this in a flag. We only currently handle IDP,
311 * AKID and deltas, so anything else critical sets the flag.
312 *
313 * This code accesses the X509_CRL structure directly:
314 * applications shouldn't do this.
315 */
316
317 exts = crl->crl->extensions;
318
319 for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) {
320 int nid;
321 ext = sk_X509_EXTENSION_value(exts, idx);
322 nid = OBJ_obj2nid(ext->object);
323 if (nid == NID_freshest_crl)
324 crl->flags |= EXFLAG_FRESHEST;
325 if (ext->critical > 0) {
326 /* We handle IDP, AKID and deltas */
327 if (nid == NID_issuing_distribution_point ||
328 nid == NID_authority_key_identifier ||
329 nid == NID_delta_crl)
330 break;
331 crl->flags |= EXFLAG_CRITICAL;
332 break;
333 }
334 }
335
336 if (!crl_set_issuers(crl))
337 return 0;
338
339 if (crl->meth->crl_init) {
340 if (crl->meth->crl_init(crl) == 0)
341 return 0;
342 }
343 break;
344
345 case ASN1_OP_FREE_POST:
346 if (crl->meth->crl_free) {
347 if (!crl->meth->crl_free(crl))
348 return 0;
349 }
350 if (crl->akid)
351 AUTHORITY_KEYID_free(crl->akid);
352 if (crl->idp)
353 ISSUING_DIST_POINT_free(crl->idp);
354 ASN1_INTEGER_free(crl->crl_number);
355 ASN1_INTEGER_free(crl->base_crl_number);
356 sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free);
357 break;
358 }
359 return 1;
360}
361
362/* Convert IDP into a more convenient form */
363
364static void
365setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
366{
367 int idp_only = 0;
368
369 /* Set various flags according to IDP */
370 crl->idp_flags |= IDP_PRESENT;
371 if (idp->onlyuser > 0) {
372 idp_only++;
373 crl->idp_flags |= IDP_ONLYUSER;
374 }
375 if (idp->onlyCA > 0) {
376 idp_only++;
377 crl->idp_flags |= IDP_ONLYCA;
378 }
379 if (idp->onlyattr > 0) {
380 idp_only++;
381 crl->idp_flags |= IDP_ONLYATTR;
382 }
383
384 if (idp_only > 1)
385 crl->idp_flags |= IDP_INVALID;
386
387 if (idp->indirectCRL > 0)
388 crl->idp_flags |= IDP_INDIRECT;
389
390 if (idp->onlysomereasons) {
391 crl->idp_flags |= IDP_REASONS;
392 if (idp->onlysomereasons->length > 0)
393 crl->idp_reasons = idp->onlysomereasons->data[0];
394 if (idp->onlysomereasons->length > 1)
395 crl->idp_reasons |=
396 (idp->onlysomereasons->data[1] << 8);
397 crl->idp_reasons &= CRLDP_ALL_REASONS;
398 }
399
400 DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl));
401}
402
403static const ASN1_AUX X509_CRL_aux = {
404 .app_data = NULL,
405 .flags = ASN1_AFLG_REFCOUNT,
406 .ref_offset = offsetof(X509_CRL, references),
407 .ref_lock = CRYPTO_LOCK_X509_CRL,
408 .asn1_cb = crl_cb,
409};
410static const ASN1_TEMPLATE X509_CRL_seq_tt[] = {
411 {
412 .offset = offsetof(X509_CRL, crl),
413 .field_name = "crl",
414 .item = &X509_CRL_INFO_it,
415 },
416 {
417 .offset = offsetof(X509_CRL, sig_alg),
418 .field_name = "sig_alg",
419 .item = &X509_ALGOR_it,
420 },
421 {
422 .offset = offsetof(X509_CRL, signature),
423 .field_name = "signature",
424 .item = &ASN1_BIT_STRING_it,
425 },
426};
427
428const ASN1_ITEM X509_CRL_it = {
429 .itype = ASN1_ITYPE_SEQUENCE,
430 .utype = V_ASN1_SEQUENCE,
431 .templates = X509_CRL_seq_tt,
432 .tcount = sizeof(X509_CRL_seq_tt) / sizeof(ASN1_TEMPLATE),
433 .funcs = &X509_CRL_aux,
434 .size = sizeof(X509_CRL),
435 .sname = "X509_CRL",
436};
437
438
439X509_REVOKED *
440d2i_X509_REVOKED(X509_REVOKED **a, const unsigned char **in, long len)
441{
442 return (X509_REVOKED *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
443 &X509_REVOKED_it);
444}
445
446int
447i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **out)
448{
449 return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_REVOKED_it);
450}
451
452X509_REVOKED *
453X509_REVOKED_new(void)
454{
455 return (X509_REVOKED *)ASN1_item_new(&X509_REVOKED_it);
456}
457
458void
459X509_REVOKED_free(X509_REVOKED *a)
460{
461 ASN1_item_free((ASN1_VALUE *)a, &X509_REVOKED_it);
462}
463
464X509_CRL_INFO *
465d2i_X509_CRL_INFO(X509_CRL_INFO **a, const unsigned char **in, long len)
466{
467 return (X509_CRL_INFO *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
468 &X509_CRL_INFO_it);
469}
470
471int
472i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **out)
473{
474 return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_CRL_INFO_it);
475}
476
477X509_CRL_INFO *
478X509_CRL_INFO_new(void)
479{
480 return (X509_CRL_INFO *)ASN1_item_new(&X509_CRL_INFO_it);
481}
482
483void
484X509_CRL_INFO_free(X509_CRL_INFO *a)
485{
486 ASN1_item_free((ASN1_VALUE *)a, &X509_CRL_INFO_it);
487}
488
489X509_CRL *
490d2i_X509_CRL(X509_CRL **a, const unsigned char **in, long len)
491{
492 return (X509_CRL *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
493 &X509_CRL_it);
494}
495
496int
497i2d_X509_CRL(X509_CRL *a, unsigned char **out)
498{
499 return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_CRL_it);
500}
501
502X509_CRL *
503X509_CRL_new(void)
504{
505 return (X509_CRL *)ASN1_item_new(&X509_CRL_it);
506}
507
508void
509X509_CRL_free(X509_CRL *a)
510{
511 ASN1_item_free((ASN1_VALUE *)a, &X509_CRL_it);
512}
513
514X509_CRL *
515X509_CRL_dup(X509_CRL *x)
516{
517 return ASN1_item_dup(&X509_CRL_it, x);
518}
519
520static int
521X509_REVOKED_cmp(const X509_REVOKED * const *a, const X509_REVOKED * const *b)
522{
523 return(ASN1_STRING_cmp(
524 (ASN1_STRING *)(*a)->serialNumber,
525 (ASN1_STRING *)(*b)->serialNumber));
526}
527
528int
529X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
530{
531 X509_CRL_INFO *inf;
532
533 inf = crl->crl;
534 if (!inf->revoked)
535 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
536 if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) {
537 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE);
538 return 0;
539 }
540 inf->enc.modified = 1;
541 return 1;
542}
543
544int
545X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r)
546{
547 if (crl->meth->crl_verify)
548 return crl->meth->crl_verify(crl, r);
549 return 0;
550}
551
552int
553X509_CRL_get0_by_serial(X509_CRL *crl, X509_REVOKED **ret,
554 ASN1_INTEGER *serial)
555{
556 if (crl->meth->crl_lookup)
557 return crl->meth->crl_lookup(crl, ret, serial, NULL);
558 return 0;
559}
560
561int
562X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x)
563{
564 if (crl->meth->crl_lookup)
565 return crl->meth->crl_lookup(crl, ret,
566 X509_get_serialNumber(x), X509_get_issuer_name(x));
567 return 0;
568}
569
570static int
571def_crl_verify(X509_CRL *crl, EVP_PKEY *r)
572{
573 return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CRL_INFO),
574 crl->sig_alg, crl->signature, crl->crl, r));
575}
576
577static int
578crl_revoked_issuer_match(X509_CRL *crl, X509_NAME *nm, X509_REVOKED *rev)
579{
580 int i;
581
582 if (!rev->issuer) {
583 if (!nm)
584 return 1;
585 if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl)))
586 return 1;
587 return 0;
588 }
589
590 if (!nm)
591 nm = X509_CRL_get_issuer(crl);
592
593 for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) {
594 GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i);
595 if (gen->type != GEN_DIRNAME)
596 continue;
597 if (!X509_NAME_cmp(nm, gen->d.directoryName))
598 return 1;
599 }
600 return 0;
601
602}
603
604static int
605def_crl_lookup(X509_CRL *crl, X509_REVOKED **ret, ASN1_INTEGER *serial,
606 X509_NAME *issuer)
607{
608 X509_REVOKED rtmp, *rev;
609 int idx;
610
611 rtmp.serialNumber = serial;
612 /* Sort revoked into serial number order if not already sorted.
613 * Do this under a lock to avoid race condition.
614 */
615 if (!sk_X509_REVOKED_is_sorted(crl->crl->revoked)) {
616 CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL);
617 sk_X509_REVOKED_sort(crl->crl->revoked);
618 CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL);
619 }
620 idx = sk_X509_REVOKED_find(crl->crl->revoked, &rtmp);
621 if (idx < 0)
622 return 0;
623 /* Need to look for matching name */
624 for (; idx < sk_X509_REVOKED_num(crl->crl->revoked); idx++) {
625 rev = sk_X509_REVOKED_value(crl->crl->revoked, idx);
626 if (ASN1_INTEGER_cmp(rev->serialNumber, serial))
627 return 0;
628 if (crl_revoked_issuer_match(crl, issuer, rev)) {
629 if (ret)
630 *ret = rev;
631 if (rev->reason == CRL_REASON_REMOVE_FROM_CRL)
632 return 2;
633 return 1;
634 }
635 }
636 return 0;
637}
638
639void
640X509_CRL_set_default_method(const X509_CRL_METHOD *meth)
641{
642 if (meth == NULL)
643 default_crl_method = &int_crl_meth;
644 else
645 default_crl_method = meth;
646}
647
648X509_CRL_METHOD *
649X509_CRL_METHOD_new(int (*crl_init)(X509_CRL *crl),
650 int (*crl_free)(X509_CRL *crl),
651 int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret,
652 ASN1_INTEGER *ser, X509_NAME *issuer),
653 int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk))
654{
655 X509_CRL_METHOD *m;
656
657 m = malloc(sizeof(X509_CRL_METHOD));
658 if (!m)
659 return NULL;
660 m->crl_init = crl_init;
661 m->crl_free = crl_free;
662 m->crl_lookup = crl_lookup;
663 m->crl_verify = crl_verify;
664 m->flags = X509_CRL_METHOD_DYNAMIC;
665 return m;
666}
667
668void
669X509_CRL_METHOD_free(X509_CRL_METHOD *m)
670{
671 if (!(m->flags & X509_CRL_METHOD_DYNAMIC))
672 return;
673 free(m);
674}
675
676void
677X509_CRL_set_meth_data(X509_CRL *crl, void *dat)
678{
679 crl->meth_data = dat;
680}
681
682void *
683X509_CRL_get_meth_data(X509_CRL *crl)
684{
685 return crl->meth_data;
686}