]>
Commit | Line | Data |
---|---|---|
b1322259 | 1 | /* |
4333b89f | 2 | * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. |
d02b48c6 | 3 | * |
3e4b43b9 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
b1322259 RS |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
d02b48c6 RE |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
b39fc560 | 11 | #include "internal/cryptlib.h" |
9d6b1ce6 | 12 | #include <openssl/asn1t.h> |
ec577822 | 13 | #include <openssl/x509.h> |
25f2138b | 14 | #include "crypto/x509.h" |
edc54021 | 15 | #include <openssl/x509v3.h> |
706457b7 | 16 | #include "x509_local.h" |
d02b48c6 | 17 | |
0f113f3e MC |
18 | static int X509_REVOKED_cmp(const X509_REVOKED *const *a, |
19 | const X509_REVOKED *const *b); | |
7e06a675 | 20 | static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp); |
d02b48c6 | 21 | |
9d6b1ce6 | 22 | ASN1_SEQUENCE(X509_REVOKED) = { |
1287dabd | 23 | ASN1_EMBED(X509_REVOKED, serialNumber, ASN1_INTEGER), |
24 | ASN1_SIMPLE(X509_REVOKED, revocationDate, ASN1_TIME), | |
25 | ASN1_SEQUENCE_OF_OPT(X509_REVOKED, extensions, X509_EXTENSION) | |
d339187b | 26 | } ASN1_SEQUENCE_END(X509_REVOKED) |
9d6b1ce6 | 27 | |
f4c630ab DSH |
28 | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r); |
29 | static int def_crl_lookup(X509_CRL *crl, | |
8cc86b81 DDO |
30 | X509_REVOKED **ret, const ASN1_INTEGER *serial, |
31 | const X509_NAME *issuer); | |
f4c630ab | 32 | |
0f113f3e MC |
33 | static X509_CRL_METHOD int_crl_meth = { |
34 | 0, | |
35 | 0, 0, | |
36 | def_crl_lookup, | |
37 | def_crl_verify | |
38 | }; | |
f4c630ab DSH |
39 | |
40 | static const X509_CRL_METHOD *default_crl_method = &int_crl_meth; | |
41 | ||
0f113f3e MC |
42 | /* |
43 | * The X509_CRL_INFO structure needs a bit of customisation. Since we cache | |
60250017 | 44 | * the original encoding the signature won't be affected by reordering of the |
0f113f3e | 45 | * revoked field. |
9d6b1ce6 | 46 | */ |
24484759 | 47 | static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
0f113f3e | 48 | void *exarg) |
9d6b1ce6 | 49 | { |
0f113f3e MC |
50 | X509_CRL_INFO *a = (X509_CRL_INFO *)*pval; |
51 | ||
52 | if (!a || !a->revoked) | |
53 | return 1; | |
54 | switch (operation) { | |
55 | /* | |
56 | * Just set cmp function here. We don't sort because that would | |
57 | * affect the output of X509_CRL_print(). | |
58 | */ | |
59 | case ASN1_OP_D2I_POST: | |
60 | (void)sk_X509_REVOKED_set_cmp_func(a->revoked, X509_REVOKED_cmp); | |
61 | break; | |
62 | } | |
63 | return 1; | |
9d6b1ce6 DSH |
64 | } |
65 | ||
66 | ||
2f605e8d | 67 | ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = { |
0f113f3e | 68 | ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER), |
6e63c142 | 69 | ASN1_EMBED(X509_CRL_INFO, sig_alg, X509_ALGOR), |
0f113f3e MC |
70 | ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME), |
71 | ASN1_SIMPLE(X509_CRL_INFO, lastUpdate, ASN1_TIME), | |
72 | ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME), | |
73 | ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED), | |
74 | ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0) | |
2f605e8d | 75 | } ASN1_SEQUENCE_END_enc(X509_CRL_INFO, X509_CRL_INFO) |
9d6b1ce6 | 76 | |
0f113f3e MC |
77 | /* |
78 | * Set CRL entry issuer according to CRL certificate issuer extension. Check | |
79 | * for unhandled critical CRL entry extensions. | |
d0fff69d DSH |
80 | */ |
81 | ||
82 | static int crl_set_issuers(X509_CRL *crl) | |
0f113f3e MC |
83 | { |
84 | ||
85 | int i, j; | |
86 | GENERAL_NAMES *gens, *gtmp; | |
87 | STACK_OF(X509_REVOKED) *revoked; | |
88 | ||
89 | revoked = X509_CRL_get_REVOKED(crl); | |
90 | ||
91 | gens = NULL; | |
92 | for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) { | |
93 | X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); | |
94 | STACK_OF(X509_EXTENSION) *exts; | |
95 | ASN1_ENUMERATED *reason; | |
96 | X509_EXTENSION *ext; | |
cb0c36d1 | 97 | |
0f113f3e MC |
98 | gtmp = X509_REVOKED_get_ext_d2i(rev, |
99 | NID_certificate_issuer, &j, NULL); | |
cb0c36d1 | 100 | if (gtmp == NULL && j != -1) { |
0f113f3e MC |
101 | crl->flags |= EXFLAG_INVALID; |
102 | return 1; | |
103 | } | |
104 | ||
cb0c36d1 | 105 | if (gtmp != NULL) { |
e9007e09 | 106 | if (crl->issuers == NULL) { |
0f113f3e | 107 | crl->issuers = sk_GENERAL_NAMES_new_null(); |
e9007e09 BE |
108 | if (crl->issuers == NULL) { |
109 | GENERAL_NAMES_free(gtmp); | |
0f113f3e | 110 | return 0; |
e9007e09 | 111 | } |
0f113f3e | 112 | } |
e9007e09 BE |
113 | if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp)) { |
114 | GENERAL_NAMES_free(gtmp); | |
0f113f3e | 115 | return 0; |
e9007e09 | 116 | } |
cb0c36d1 | 117 | gens = gtmp; |
0f113f3e MC |
118 | } |
119 | rev->issuer = gens; | |
120 | ||
121 | reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, &j, NULL); | |
cb0c36d1 | 122 | if (reason == NULL && j != -1) { |
0f113f3e MC |
123 | crl->flags |= EXFLAG_INVALID; |
124 | return 1; | |
125 | } | |
126 | ||
cb0c36d1 | 127 | if (reason != NULL) { |
0f113f3e MC |
128 | rev->reason = ASN1_ENUMERATED_get(reason); |
129 | ASN1_ENUMERATED_free(reason); | |
130 | } else | |
131 | rev->reason = CRL_REASON_NONE; | |
132 | ||
133 | /* Check for critical CRL entry extensions */ | |
134 | ||
135 | exts = rev->extensions; | |
136 | ||
137 | for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) { | |
138 | ext = sk_X509_EXTENSION_value(exts, j); | |
4903abd5 | 139 | if (X509_EXTENSION_get_critical(ext)) { |
cb0c36d1 BE |
140 | if (OBJ_obj2nid(X509_EXTENSION_get_object(ext)) |
141 | == NID_certificate_issuer) | |
0f113f3e MC |
142 | continue; |
143 | crl->flags |= EXFLAG_CRITICAL; | |
144 | break; | |
145 | } | |
146 | } | |
147 | ||
148 | } | |
149 | ||
150 | return 1; | |
151 | ||
152 | } | |
153 | ||
154 | /* | |
155 | * The X509_CRL structure needs a bit of customisation. Cache some extensions | |
f2a04587 | 156 | * and hash of the whole CRL or set EXFLAG_NO_FINGERPRINT if this fails. |
edc54021 DSH |
157 | */ |
158 | static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | |
0f113f3e MC |
159 | void *exarg) |
160 | { | |
161 | X509_CRL *crl = (X509_CRL *)*pval; | |
162 | STACK_OF(X509_EXTENSION) *exts; | |
163 | X509_EXTENSION *ext; | |
7e06a675 | 164 | int idx, i; |
0f113f3e MC |
165 | |
166 | switch (operation) { | |
a7276279 BE |
167 | case ASN1_OP_D2I_PRE: |
168 | if (crl->meth->crl_free) { | |
169 | if (!crl->meth->crl_free(crl)) | |
170 | return 0; | |
171 | } | |
172 | AUTHORITY_KEYID_free(crl->akid); | |
173 | ISSUING_DIST_POINT_free(crl->idp); | |
174 | ASN1_INTEGER_free(crl->crl_number); | |
175 | ASN1_INTEGER_free(crl->base_crl_number); | |
176 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); | |
177 | /* fall thru */ | |
178 | ||
0f113f3e MC |
179 | case ASN1_OP_NEW_POST: |
180 | crl->idp = NULL; | |
181 | crl->akid = NULL; | |
182 | crl->flags = 0; | |
183 | crl->idp_flags = 0; | |
184 | crl->idp_reasons = CRLDP_ALL_REASONS; | |
185 | crl->meth = default_crl_method; | |
186 | crl->meth_data = NULL; | |
187 | crl->issuers = NULL; | |
188 | crl->crl_number = NULL; | |
189 | crl->base_crl_number = NULL; | |
190 | break; | |
191 | ||
192 | case ASN1_OP_D2I_POST: | |
7e06a675 | 193 | if (!X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL)) |
f2a04587 | 194 | crl->flags |= EXFLAG_NO_FINGERPRINT; |
0f113f3e | 195 | crl->idp = X509_CRL_get_ext_d2i(crl, |
7e06a675 | 196 | NID_issuing_distribution_point, &i, |
0f113f3e | 197 | NULL); |
7e06a675 BE |
198 | if (crl->idp != NULL) { |
199 | if (!setup_idp(crl, crl->idp)) | |
200 | crl->flags |= EXFLAG_INVALID; | |
201 | } | |
202 | else if (i != -1) { | |
203 | crl->flags |= EXFLAG_INVALID; | |
204 | } | |
0f113f3e MC |
205 | |
206 | crl->akid = X509_CRL_get_ext_d2i(crl, | |
7e06a675 | 207 | NID_authority_key_identifier, &i, |
0f113f3e | 208 | NULL); |
7e06a675 BE |
209 | if (crl->akid == NULL && i != -1) |
210 | crl->flags |= EXFLAG_INVALID; | |
0f113f3e MC |
211 | |
212 | crl->crl_number = X509_CRL_get_ext_d2i(crl, | |
7e06a675 BE |
213 | NID_crl_number, &i, NULL); |
214 | if (crl->crl_number == NULL && i != -1) | |
215 | crl->flags |= EXFLAG_INVALID; | |
0f113f3e MC |
216 | |
217 | crl->base_crl_number = X509_CRL_get_ext_d2i(crl, | |
7e06a675 | 218 | NID_delta_crl, &i, |
0f113f3e | 219 | NULL); |
7e06a675 BE |
220 | if (crl->base_crl_number == NULL && i != -1) |
221 | crl->flags |= EXFLAG_INVALID; | |
0f113f3e MC |
222 | /* Delta CRLs must have CRL number */ |
223 | if (crl->base_crl_number && !crl->crl_number) | |
224 | crl->flags |= EXFLAG_INVALID; | |
225 | ||
226 | /* | |
227 | * See if we have any unhandled critical CRL extensions and indicate | |
228 | * this in a flag. We only currently handle IDP so anything else | |
229 | * critical sets the flag. This code accesses the X509_CRL structure | |
230 | * directly: applications shouldn't do this. | |
231 | */ | |
232 | ||
7aef39a7 | 233 | exts = crl->crl.extensions; |
0f113f3e MC |
234 | |
235 | for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) { | |
236 | int nid; | |
237 | ext = sk_X509_EXTENSION_value(exts, idx); | |
4903abd5 | 238 | nid = OBJ_obj2nid(X509_EXTENSION_get_object(ext)); |
0f113f3e MC |
239 | if (nid == NID_freshest_crl) |
240 | crl->flags |= EXFLAG_FRESHEST; | |
4903abd5 | 241 | if (X509_EXTENSION_get_critical(ext)) { |
0f113f3e MC |
242 | /* We handle IDP and deltas */ |
243 | if ((nid == NID_issuing_distribution_point) | |
244 | || (nid == NID_authority_key_identifier) | |
245 | || (nid == NID_delta_crl)) | |
2b406990 | 246 | continue; |
0f113f3e MC |
247 | crl->flags |= EXFLAG_CRITICAL; |
248 | break; | |
249 | } | |
250 | } | |
251 | ||
252 | if (!crl_set_issuers(crl)) | |
253 | return 0; | |
254 | ||
255 | if (crl->meth->crl_init) { | |
256 | if (crl->meth->crl_init(crl) == 0) | |
257 | return 0; | |
258 | } | |
6195848b RL |
259 | |
260 | crl->flags |= EXFLAG_SET; | |
0f113f3e MC |
261 | break; |
262 | ||
263 | case ASN1_OP_FREE_POST: | |
557825ac | 264 | if (crl->meth != NULL && crl->meth->crl_free != NULL) { |
0f113f3e MC |
265 | if (!crl->meth->crl_free(crl)) |
266 | return 0; | |
267 | } | |
25aaa98a RS |
268 | AUTHORITY_KEYID_free(crl->akid); |
269 | ISSUING_DIST_POINT_free(crl->idp); | |
0f113f3e MC |
270 | ASN1_INTEGER_free(crl->crl_number); |
271 | ASN1_INTEGER_free(crl->base_crl_number); | |
272 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); | |
c22139a7 SL |
273 | OPENSSL_free(crl->propq); |
274 | break; | |
275 | case ASN1_OP_DUP_POST: | |
276 | { | |
277 | X509_CRL *old = exarg; | |
278 | ||
4669015d | 279 | if (!ossl_x509_crl_set0_libctx(crl, old->libctx, old->propq)) |
c22139a7 SL |
280 | return 0; |
281 | } | |
0f113f3e MC |
282 | break; |
283 | } | |
284 | return 1; | |
285 | } | |
edc54021 | 286 | |
4d50a2b4 DSH |
287 | /* Convert IDP into a more convenient form */ |
288 | ||
7e06a675 | 289 | static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) |
0f113f3e MC |
290 | { |
291 | int idp_only = 0; | |
7e06a675 | 292 | |
0f113f3e MC |
293 | /* Set various flags according to IDP */ |
294 | crl->idp_flags |= IDP_PRESENT; | |
295 | if (idp->onlyuser > 0) { | |
296 | idp_only++; | |
297 | crl->idp_flags |= IDP_ONLYUSER; | |
298 | } | |
299 | if (idp->onlyCA > 0) { | |
300 | idp_only++; | |
301 | crl->idp_flags |= IDP_ONLYCA; | |
302 | } | |
303 | if (idp->onlyattr > 0) { | |
304 | idp_only++; | |
305 | crl->idp_flags |= IDP_ONLYATTR; | |
306 | } | |
307 | ||
308 | if (idp_only > 1) | |
309 | crl->idp_flags |= IDP_INVALID; | |
310 | ||
311 | if (idp->indirectCRL > 0) | |
312 | crl->idp_flags |= IDP_INDIRECT; | |
313 | ||
314 | if (idp->onlysomereasons) { | |
315 | crl->idp_flags |= IDP_REASONS; | |
316 | if (idp->onlysomereasons->length > 0) | |
317 | crl->idp_reasons = idp->onlysomereasons->data[0]; | |
318 | if (idp->onlysomereasons->length > 1) | |
319 | crl->idp_reasons |= (idp->onlysomereasons->data[1] << 8); | |
320 | crl->idp_reasons &= CRLDP_ALL_REASONS; | |
321 | } | |
322 | ||
7e06a675 | 323 | return DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); |
0f113f3e | 324 | } |
4d50a2b4 | 325 | |
c001ce33 | 326 | ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = { |
7aef39a7 | 327 | ASN1_EMBED(X509_CRL, crl, X509_CRL_INFO), |
6e63c142 | 328 | ASN1_EMBED(X509_CRL, sig_alg, X509_ALGOR), |
34a42e14 | 329 | ASN1_EMBED(X509_CRL, signature, ASN1_BIT_STRING) |
d339187b | 330 | } ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL) |
9d6b1ce6 DSH |
331 | |
332 | IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED) | |
0f113f3e | 333 | |
2e8cb108 | 334 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_REVOKED) |
0f113f3e | 335 | |
9d6b1ce6 | 336 | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO) |
739a5eee | 337 | |
9d6b1ce6 | 338 | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL) |
739a5eee | 339 | |
1241126a | 340 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) |
d02b48c6 | 341 | |
0f113f3e MC |
342 | static int X509_REVOKED_cmp(const X509_REVOKED *const *a, |
343 | const X509_REVOKED *const *b) | |
344 | { | |
34a42e14 DSH |
345 | return (ASN1_STRING_cmp((ASN1_STRING *)&(*a)->serialNumber, |
346 | (ASN1_STRING *)&(*b)->serialNumber)); | |
0f113f3e | 347 | } |
d02b48c6 | 348 | |
e6c2f964 SL |
349 | X509_CRL *X509_CRL_new_ex(OSSL_LIB_CTX *libctx, const char *propq) |
350 | { | |
351 | X509_CRL *crl = NULL; | |
352 | ||
353 | crl = (X509_CRL *)ASN1_item_new((X509_CRL_it())); | |
354 | if (!ossl_x509_crl_set0_libctx(crl, libctx, propq)) { | |
355 | X509_CRL_free(crl); | |
356 | crl = NULL; | |
357 | } | |
358 | return crl; | |
359 | } | |
360 | ||
9d6b1ce6 DSH |
361 | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) |
362 | { | |
0f113f3e | 363 | X509_CRL_INFO *inf; |
7fcdbd83 | 364 | |
7aef39a7 | 365 | inf = &crl->crl; |
90945fa3 | 366 | if (inf->revoked == NULL) |
0f113f3e | 367 | inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); |
90945fa3 | 368 | if (inf->revoked == NULL || !sk_X509_REVOKED_push(inf->revoked, rev)) { |
e077455e | 369 | ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
0f113f3e MC |
370 | return 0; |
371 | } | |
372 | inf->enc.modified = 1; | |
373 | return 1; | |
9d6b1ce6 DSH |
374 | } |
375 | ||
010fa0b3 | 376 | int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) |
0f113f3e MC |
377 | { |
378 | if (crl->meth->crl_verify) | |
379 | return crl->meth->crl_verify(crl, r); | |
380 | return 0; | |
381 | } | |
f4c630ab DSH |
382 | |
383 | int X509_CRL_get0_by_serial(X509_CRL *crl, | |
8cc86b81 | 384 | X509_REVOKED **ret, const ASN1_INTEGER *serial) |
0f113f3e MC |
385 | { |
386 | if (crl->meth->crl_lookup) | |
387 | return crl->meth->crl_lookup(crl, ret, serial, NULL); | |
388 | return 0; | |
389 | } | |
d0fff69d DSH |
390 | |
391 | int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) | |
0f113f3e MC |
392 | { |
393 | if (crl->meth->crl_lookup) | |
394 | return crl->meth->crl_lookup(crl, ret, | |
1337a3a9 | 395 | X509_get0_serialNumber(x), |
0f113f3e MC |
396 | X509_get_issuer_name(x)); |
397 | return 0; | |
398 | } | |
f4c630ab DSH |
399 | |
400 | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) | |
0f113f3e | 401 | { |
5c107243 SL |
402 | return ASN1_item_verify_ex(ASN1_ITEM_rptr(X509_CRL_INFO), |
403 | &crl->sig_alg, &crl->signature, &crl->crl, NULL, | |
404 | r, crl->libctx, crl->propq); | |
0f113f3e | 405 | } |
010fa0b3 | 406 | |
8cc86b81 | 407 | static int crl_revoked_issuer_match(X509_CRL *crl, const X509_NAME *nm, |
0f113f3e MC |
408 | X509_REVOKED *rev) |
409 | { | |
410 | int i; | |
411 | ||
412 | if (!rev->issuer) { | |
413 | if (!nm) | |
414 | return 1; | |
415 | if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) | |
416 | return 1; | |
417 | return 0; | |
418 | } | |
419 | ||
420 | if (!nm) | |
421 | nm = X509_CRL_get_issuer(crl); | |
422 | ||
423 | for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) { | |
424 | GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); | |
425 | if (gen->type != GEN_DIRNAME) | |
426 | continue; | |
427 | if (!X509_NAME_cmp(nm, gen->d.directoryName)) | |
428 | return 1; | |
429 | } | |
430 | return 0; | |
431 | ||
432 | } | |
d0fff69d | 433 | |
f4c630ab | 434 | static int def_crl_lookup(X509_CRL *crl, |
8cc86b81 DDO |
435 | X509_REVOKED **ret, const ASN1_INTEGER *serial, |
436 | const X509_NAME *issuer) | |
0f113f3e MC |
437 | { |
438 | X509_REVOKED rtmp, *rev; | |
5b37fef0 AP |
439 | int idx, num; |
440 | ||
441 | if (crl->crl.revoked == NULL) | |
442 | return 0; | |
443 | ||
0f113f3e MC |
444 | /* |
445 | * Sort revoked into serial number order if not already sorted. Do this | |
446 | * under a lock to avoid race condition. | |
447 | */ | |
7aef39a7 | 448 | if (!sk_X509_REVOKED_is_sorted(crl->crl.revoked)) { |
cd3f8c1b RS |
449 | if (!CRYPTO_THREAD_write_lock(crl->lock)) |
450 | return 0; | |
7aef39a7 | 451 | sk_X509_REVOKED_sort(crl->crl.revoked); |
c001ce33 | 452 | CRYPTO_THREAD_unlock(crl->lock); |
0f113f3e | 453 | } |
5b37fef0 | 454 | rtmp.serialNumber = *serial; |
7aef39a7 | 455 | idx = sk_X509_REVOKED_find(crl->crl.revoked, &rtmp); |
0f113f3e MC |
456 | if (idx < 0) |
457 | return 0; | |
458 | /* Need to look for matching name */ | |
5b37fef0 | 459 | for (num = sk_X509_REVOKED_num(crl->crl.revoked); idx < num; idx++) { |
7aef39a7 | 460 | rev = sk_X509_REVOKED_value(crl->crl.revoked, idx); |
34a42e14 | 461 | if (ASN1_INTEGER_cmp(&rev->serialNumber, serial)) |
0f113f3e MC |
462 | return 0; |
463 | if (crl_revoked_issuer_match(crl, issuer, rev)) { | |
464 | if (ret) | |
465 | *ret = rev; | |
466 | if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) | |
467 | return 2; | |
468 | return 1; | |
469 | } | |
470 | } | |
471 | return 0; | |
472 | } | |
010fa0b3 | 473 | |
f4c630ab | 474 | void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) |
0f113f3e MC |
475 | { |
476 | if (meth == NULL) | |
477 | default_crl_method = &int_crl_meth; | |
478 | else | |
479 | default_crl_method = meth; | |
480 | } | |
481 | ||
482 | X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init) (X509_CRL *crl), | |
483 | int (*crl_free) (X509_CRL *crl), | |
484 | int (*crl_lookup) (X509_CRL *crl, | |
485 | X509_REVOKED **ret, | |
8cc86b81 DDO |
486 | const ASN1_INTEGER *ser, |
487 | const X509_NAME *issuer), | |
0f113f3e MC |
488 | int (*crl_verify) (X509_CRL *crl, |
489 | EVP_PKEY *pk)) | |
490 | { | |
7fcdbd83 F |
491 | X509_CRL_METHOD *m = OPENSSL_malloc(sizeof(*m)); |
492 | ||
e077455e | 493 | if (m == NULL) |
0f113f3e MC |
494 | return NULL; |
495 | m->crl_init = crl_init; | |
496 | m->crl_free = crl_free; | |
497 | m->crl_lookup = crl_lookup; | |
498 | m->crl_verify = crl_verify; | |
499 | m->flags = X509_CRL_METHOD_DYNAMIC; | |
500 | return m; | |
501 | } | |
f4c630ab DSH |
502 | |
503 | void X509_CRL_METHOD_free(X509_CRL_METHOD *m) | |
0f113f3e | 504 | { |
7cb1ecec | 505 | if (m == NULL || !(m->flags & X509_CRL_METHOD_DYNAMIC)) |
0f113f3e MC |
506 | return; |
507 | OPENSSL_free(m); | |
508 | } | |
f4c630ab DSH |
509 | |
510 | void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) | |
0f113f3e MC |
511 | { |
512 | crl->meth_data = dat; | |
513 | } | |
f4c630ab DSH |
514 | |
515 | void *X509_CRL_get_meth_data(X509_CRL *crl) | |
0f113f3e MC |
516 | { |
517 | return crl->meth_data; | |
518 | } | |
34b80d06 | 519 | |
4669015d SL |
520 | int ossl_x509_crl_set0_libctx(X509_CRL *x, OSSL_LIB_CTX *libctx, |
521 | const char *propq) | |
34b80d06 RL |
522 | { |
523 | if (x != NULL) { | |
524 | x->libctx = libctx; | |
c22139a7 SL |
525 | OPENSSL_free(x->propq); |
526 | x->propq = NULL; | |
527 | if (propq != NULL) { | |
528 | x->propq = OPENSSL_strdup(propq); | |
529 | if (x->propq == NULL) | |
530 | return 0; | |
531 | } | |
34b80d06 RL |
532 | } |
533 | return 1; | |
534 | } |