/src/openssl/crypto/x509/x_crl.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
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 |
8 | | */ |
9 | | |
10 | | #include <stdio.h> |
11 | | #include "internal/cryptlib.h" |
12 | | #include <openssl/asn1t.h> |
13 | | #include <openssl/x509.h> |
14 | | #include "crypto/x509.h" |
15 | | #include <openssl/x509v3.h> |
16 | | #include "x509_local.h" |
17 | | |
18 | | static int X509_REVOKED_cmp(const X509_REVOKED *const *a, |
19 | | const X509_REVOKED *const *b); |
20 | | static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp); |
21 | | |
22 | | ASN1_SEQUENCE(X509_REVOKED) = { |
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) |
26 | 0 | } ASN1_SEQUENCE_END(X509_REVOKED) |
27 | 0 |
|
28 | 0 | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r); |
29 | 0 | static int def_crl_lookup(X509_CRL *crl, |
30 | 0 | X509_REVOKED **ret, const ASN1_INTEGER *serial, |
31 | 0 | const X509_NAME *issuer); |
32 | 0 |
|
33 | 0 | static X509_CRL_METHOD int_crl_meth = { |
34 | 0 | 0, |
35 | 0 | 0, 0, |
36 | 0 | def_crl_lookup, |
37 | 0 | def_crl_verify |
38 | 0 | }; |
39 | 0 |
|
40 | 0 | static const X509_CRL_METHOD *default_crl_method = &int_crl_meth; |
41 | 0 |
|
42 | 0 | /* |
43 | 0 | * The X509_CRL_INFO structure needs a bit of customisation. Since we cache |
44 | 0 | * the original encoding the signature won't be affected by reordering of the |
45 | 0 | * revoked field. |
46 | 0 | */ |
47 | 0 | static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
48 | 0 | void *exarg) |
49 | 0 | { |
50 | 0 | X509_CRL_INFO *a = (X509_CRL_INFO *)*pval; |
51 | |
|
52 | 0 | if (!a || !a->revoked) |
53 | 0 | return 1; |
54 | 0 | 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 | 0 | case ASN1_OP_D2I_POST: |
60 | 0 | (void)sk_X509_REVOKED_set_cmp_func(a->revoked, X509_REVOKED_cmp); |
61 | 0 | break; |
62 | 0 | } |
63 | 0 | return 1; |
64 | 0 | } |
65 | | |
66 | | |
67 | | ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = { |
68 | | ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER), |
69 | | ASN1_EMBED(X509_CRL_INFO, sig_alg, X509_ALGOR), |
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) |
75 | | } ASN1_SEQUENCE_END_enc(X509_CRL_INFO, X509_CRL_INFO) |
76 | | |
77 | | /* |
78 | | * Set CRL entry issuer according to CRL certificate issuer extension. Check |
79 | | * for unhandled critical CRL entry extensions. |
80 | | */ |
81 | | |
82 | | static int crl_set_issuers(X509_CRL *crl) |
83 | 0 | { |
84 | |
|
85 | 0 | int i, j; |
86 | 0 | GENERAL_NAMES *most_recent_issuer, *gtmp; |
87 | 0 | STACK_OF(X509_REVOKED) *revoked; |
88 | | |
89 | | /* |
90 | | * The CRL's nextUpdate field is optional, but we will still verify |
91 | | * lastUpdate and treat missing or invalid values as a failure. |
92 | | */ |
93 | 0 | if (crl->crl.lastUpdate == NULL) { |
94 | 0 | crl->flags |= EXFLAG_INVALID; |
95 | 0 | return 0; |
96 | 0 | } |
97 | | |
98 | 0 | revoked = X509_CRL_get_REVOKED(crl); |
99 | | |
100 | | /* |
101 | | * If this extension is not present on the first entry in an indirect CRL, |
102 | | * the certificate issuer defaults to the CRL issuer. Subsequent entries in |
103 | | * an indirect CRL, if this extension is not present, the certificate issuer |
104 | | * for the entry is the same as that for the preceding entry. |
105 | | * https://datatracker.ietf.org/doc/html/rfc5280#section-5.3.3 |
106 | | */ |
107 | 0 | most_recent_issuer = NULL; |
108 | |
|
109 | 0 | for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) { |
110 | 0 | X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); |
111 | 0 | STACK_OF(X509_EXTENSION) *exts; |
112 | 0 | ASN1_ENUMERATED *reason; |
113 | 0 | X509_EXTENSION *ext; |
114 | 0 | const ASN1_TIME *rev_date; |
115 | 0 | ASN1_GENERALIZEDTIME *inv_date; |
116 | 0 | int nid; |
117 | | |
118 | | /* |
119 | | * The revocation date is a mandatory attribute. If we get NULL here, it |
120 | | * means the validation has failed and an error has been pushed onto the |
121 | | * error stack. |
122 | | */ |
123 | 0 | if ((rev_date = X509_REVOKED_get0_revocationDate(rev)) == NULL) { |
124 | 0 | crl->flags |= EXFLAG_INVALID; |
125 | 0 | return 0; |
126 | 0 | } |
127 | | |
128 | 0 | gtmp = X509_REVOKED_get_ext_d2i(rev, NID_certificate_issuer, &j, NULL); |
129 | 0 | if (gtmp == NULL && j != -1) { |
130 | 0 | crl->flags |= EXFLAG_INVALID; |
131 | 0 | return 1; |
132 | 0 | } |
133 | | |
134 | 0 | if (gtmp != NULL) { |
135 | | /* |
136 | | * Validation to ensure Certificate Issuer extensions in CRL |
137 | | * entries only appear when the Indirect CRL flag is TRUE in the |
138 | | * Issuing Distribution Point (IDP) extension, as required by |
139 | | * https://datatracker.ietf.org/doc/html/rfc5280#section-5.3.3 |
140 | | */ |
141 | 0 | if (crl->idp == NULL || !crl->idp->indirectCRL) { |
142 | 0 | crl->flags |= EXFLAG_INVALID; |
143 | 0 | GENERAL_NAMES_free(gtmp); |
144 | 0 | return 0; |
145 | 0 | } |
146 | | |
147 | 0 | if (crl->issuers == NULL) { |
148 | 0 | crl->issuers = sk_GENERAL_NAMES_new_null(); |
149 | 0 | if (crl->issuers == NULL) { |
150 | 0 | GENERAL_NAMES_free(gtmp); |
151 | 0 | return 0; |
152 | 0 | } |
153 | 0 | } |
154 | 0 | if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp)) { |
155 | 0 | GENERAL_NAMES_free(gtmp); |
156 | 0 | return 0; |
157 | 0 | } |
158 | 0 | most_recent_issuer = gtmp; |
159 | 0 | } |
160 | 0 | rev->issuer = most_recent_issuer; |
161 | |
|
162 | 0 | reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, &j, NULL); |
163 | 0 | if (reason == NULL && j != -1) { |
164 | 0 | crl->flags |= EXFLAG_INVALID; |
165 | 0 | return 1; |
166 | 0 | } |
167 | | |
168 | 0 | if (reason != NULL) { |
169 | 0 | rev->reason = ASN1_ENUMERATED_get(reason); |
170 | 0 | ASN1_ENUMERATED_free(reason); |
171 | 0 | } else |
172 | 0 | rev->reason = CRL_REASON_NONE; |
173 | | |
174 | | /* Check for critical CRL entry extensions and validate time. */ |
175 | |
|
176 | 0 | exts = rev->extensions; |
177 | |
|
178 | 0 | for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) { |
179 | 0 | ext = sk_X509_EXTENSION_value(exts, j); |
180 | 0 | nid = OBJ_obj2nid(X509_EXTENSION_get_object(ext)); |
181 | | |
182 | | /* |
183 | | * If we obtain the extension but the time is NULL, it means that |
184 | | * the validation has failed and the reason will be pushed onto the |
185 | | * error stack. |
186 | | */ |
187 | 0 | if (nid == NID_invalidity_date) { |
188 | 0 | if ((inv_date = X509V3_EXT_d2i(ext)) == NULL) { |
189 | 0 | crl->flags |= EXFLAG_INVALID; |
190 | 0 | return 0; |
191 | 0 | } |
192 | 0 | ASN1_GENERALIZEDTIME_free(inv_date); |
193 | 0 | } |
194 | 0 | if (X509_EXTENSION_get_critical(ext)) { |
195 | 0 | if (nid == NID_certificate_issuer) |
196 | 0 | continue; |
197 | 0 | crl->flags |= EXFLAG_CRITICAL; |
198 | 0 | } |
199 | 0 | } |
200 | |
|
201 | 0 | } |
202 | | |
203 | 0 | return 1; |
204 | |
|
205 | 0 | } |
206 | | |
207 | | /* |
208 | | * The X509_CRL structure needs a bit of customisation. Cache some extensions |
209 | | * and hash of the whole CRL or set EXFLAG_NO_FINGERPRINT if this fails. |
210 | | */ |
211 | | static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
212 | | void *exarg) |
213 | 0 | { |
214 | 0 | X509_CRL *crl = (X509_CRL *)*pval; |
215 | 0 | STACK_OF(X509_EXTENSION) *exts; |
216 | 0 | X509_EXTENSION *ext; |
217 | 0 | int idx, i; |
218 | |
|
219 | 0 | switch (operation) { |
220 | 0 | case ASN1_OP_D2I_PRE: |
221 | 0 | if (crl->meth->crl_free) { |
222 | 0 | if (!crl->meth->crl_free(crl)) |
223 | 0 | return 0; |
224 | 0 | } |
225 | 0 | AUTHORITY_KEYID_free(crl->akid); |
226 | 0 | ISSUING_DIST_POINT_free(crl->idp); |
227 | 0 | ASN1_INTEGER_free(crl->crl_number); |
228 | 0 | ASN1_INTEGER_free(crl->base_crl_number); |
229 | 0 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); |
230 | | /* fall through */ |
231 | |
|
232 | 0 | case ASN1_OP_NEW_POST: |
233 | 0 | crl->idp = NULL; |
234 | 0 | crl->akid = NULL; |
235 | 0 | crl->flags = 0; |
236 | 0 | crl->idp_flags = 0; |
237 | 0 | crl->idp_reasons = CRLDP_ALL_REASONS; |
238 | 0 | crl->meth = default_crl_method; |
239 | 0 | crl->meth_data = NULL; |
240 | 0 | crl->issuers = NULL; |
241 | 0 | crl->crl_number = NULL; |
242 | 0 | crl->base_crl_number = NULL; |
243 | 0 | break; |
244 | | |
245 | 0 | case ASN1_OP_D2I_POST: |
246 | 0 | if (!X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL)) |
247 | 0 | crl->flags |= EXFLAG_NO_FINGERPRINT; |
248 | 0 | crl->idp = X509_CRL_get_ext_d2i(crl, |
249 | 0 | NID_issuing_distribution_point, &i, |
250 | 0 | NULL); |
251 | 0 | if (crl->idp != NULL) { |
252 | 0 | if (!setup_idp(crl, crl->idp)) |
253 | 0 | crl->flags |= EXFLAG_INVALID; |
254 | 0 | } |
255 | 0 | else if (i != -1) { |
256 | 0 | crl->flags |= EXFLAG_INVALID; |
257 | 0 | } |
258 | |
|
259 | 0 | crl->akid = X509_CRL_get_ext_d2i(crl, |
260 | 0 | NID_authority_key_identifier, &i, |
261 | 0 | NULL); |
262 | 0 | if (crl->akid == NULL && i != -1) |
263 | 0 | crl->flags |= EXFLAG_INVALID; |
264 | |
|
265 | 0 | crl->crl_number = X509_CRL_get_ext_d2i(crl, |
266 | 0 | NID_crl_number, &i, NULL); |
267 | 0 | if (crl->crl_number == NULL && i != -1) |
268 | 0 | crl->flags |= EXFLAG_INVALID; |
269 | |
|
270 | 0 | crl->base_crl_number = X509_CRL_get_ext_d2i(crl, |
271 | 0 | NID_delta_crl, &i, |
272 | 0 | NULL); |
273 | 0 | if (crl->base_crl_number == NULL && i != -1) |
274 | 0 | crl->flags |= EXFLAG_INVALID; |
275 | | /* Delta CRLs must have CRL number */ |
276 | 0 | if (crl->base_crl_number && !crl->crl_number) |
277 | 0 | crl->flags |= EXFLAG_INVALID; |
278 | | |
279 | | /* |
280 | | * See if we have any unhandled critical CRL extensions and indicate |
281 | | * this in a flag. We only currently handle IDP so anything else |
282 | | * critical sets the flag. This code accesses the X509_CRL structure |
283 | | * directly: applications shouldn't do this. |
284 | | */ |
285 | |
|
286 | 0 | exts = crl->crl.extensions; |
287 | |
|
288 | 0 | for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) { |
289 | 0 | int nid; |
290 | 0 | ext = sk_X509_EXTENSION_value(exts, idx); |
291 | 0 | nid = OBJ_obj2nid(X509_EXTENSION_get_object(ext)); |
292 | 0 | if (nid == NID_freshest_crl) |
293 | 0 | crl->flags |= EXFLAG_FRESHEST; |
294 | 0 | if (X509_EXTENSION_get_critical(ext)) { |
295 | | /* We handle IDP and deltas */ |
296 | 0 | if ((nid == NID_issuing_distribution_point) |
297 | 0 | || (nid == NID_authority_key_identifier) |
298 | 0 | || (nid == NID_delta_crl)) |
299 | 0 | continue; |
300 | 0 | crl->flags |= EXFLAG_CRITICAL; |
301 | 0 | break; |
302 | 0 | } |
303 | 0 | } |
304 | |
|
305 | 0 | if (!crl_set_issuers(crl)) |
306 | 0 | return 0; |
307 | | |
308 | 0 | if (crl->meth->crl_init) { |
309 | 0 | if (crl->meth->crl_init(crl) == 0) |
310 | 0 | return 0; |
311 | 0 | } |
312 | | |
313 | 0 | crl->flags |= EXFLAG_SET; |
314 | 0 | break; |
315 | | |
316 | 0 | case ASN1_OP_FREE_POST: |
317 | 0 | if (crl->meth != NULL && crl->meth->crl_free != NULL) { |
318 | 0 | if (!crl->meth->crl_free(crl)) |
319 | 0 | return 0; |
320 | 0 | } |
321 | 0 | AUTHORITY_KEYID_free(crl->akid); |
322 | 0 | ISSUING_DIST_POINT_free(crl->idp); |
323 | 0 | ASN1_INTEGER_free(crl->crl_number); |
324 | 0 | ASN1_INTEGER_free(crl->base_crl_number); |
325 | 0 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); |
326 | 0 | OPENSSL_free(crl->propq); |
327 | 0 | break; |
328 | 0 | case ASN1_OP_DUP_POST: |
329 | 0 | { |
330 | 0 | X509_CRL *old = exarg; |
331 | |
|
332 | 0 | if (!ossl_x509_crl_set0_libctx(crl, old->libctx, old->propq)) |
333 | 0 | return 0; |
334 | 0 | } |
335 | 0 | break; |
336 | 0 | } |
337 | 0 | return 1; |
338 | 0 | } |
339 | | |
340 | | /* Convert IDP into a more convenient form */ |
341 | | |
342 | | static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) |
343 | 0 | { |
344 | 0 | int idp_only = 0; |
345 | 0 | int ret = 0; |
346 | | |
347 | | /* Set various flags according to IDP */ |
348 | 0 | crl->idp_flags |= IDP_PRESENT; |
349 | 0 | if (idp->onlyuser > 0) { |
350 | 0 | idp_only++; |
351 | 0 | crl->idp_flags |= IDP_ONLYUSER; |
352 | 0 | } |
353 | 0 | if (idp->onlyCA > 0) { |
354 | 0 | idp_only++; |
355 | 0 | crl->idp_flags |= IDP_ONLYCA; |
356 | 0 | } |
357 | 0 | if (idp->onlyattr > 0) { |
358 | 0 | idp_only++; |
359 | 0 | crl->idp_flags |= IDP_ONLYATTR; |
360 | 0 | } |
361 | |
|
362 | 0 | if (idp_only > 1) |
363 | 0 | crl->idp_flags |= IDP_INVALID; |
364 | |
|
365 | 0 | if (idp->indirectCRL > 0) |
366 | 0 | crl->idp_flags |= IDP_INDIRECT; |
367 | |
|
368 | 0 | if (idp->onlysomereasons) { |
369 | 0 | crl->idp_flags |= IDP_REASONS; |
370 | 0 | if (idp->onlysomereasons->length > 0) |
371 | 0 | crl->idp_reasons = idp->onlysomereasons->data[0]; |
372 | 0 | if (idp->onlysomereasons->length > 1) |
373 | 0 | crl->idp_reasons |= (idp->onlysomereasons->data[1] << 8); |
374 | 0 | crl->idp_reasons &= CRLDP_ALL_REASONS; |
375 | 0 | } |
376 | |
|
377 | 0 | ret = DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); |
378 | | |
379 | | /* |
380 | | * RFC5280 specifies that if onlyContainsUserCerts, onlyContainsCACerts, |
381 | | * indirectCRL, and OnlyContainsAttributeCerts are all FALSE, there must |
382 | | * be either a distributionPoint field or an onlySomeReasons field present. |
383 | | */ |
384 | 0 | if (crl->idp_flags == IDP_PRESENT && idp->distpoint == NULL) |
385 | 0 | crl->idp_flags |= IDP_INVALID; |
386 | |
|
387 | 0 | return ret; |
388 | 0 | } |
389 | | |
390 | | ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = { |
391 | | ASN1_EMBED(X509_CRL, crl, X509_CRL_INFO), |
392 | | ASN1_EMBED(X509_CRL, sig_alg, X509_ALGOR), |
393 | | ASN1_EMBED(X509_CRL, signature, ASN1_BIT_STRING) |
394 | | } ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL) |
395 | | |
396 | | IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED) |
397 | | |
398 | | IMPLEMENT_ASN1_DUP_FUNCTION(X509_REVOKED) |
399 | | |
400 | | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO) |
401 | | |
402 | | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL) |
403 | | |
404 | | IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) |
405 | | |
406 | | static int X509_REVOKED_cmp(const X509_REVOKED *const *a, |
407 | | const X509_REVOKED *const *b) |
408 | 0 | { |
409 | 0 | return (ASN1_STRING_cmp((ASN1_STRING *)&(*a)->serialNumber, |
410 | 0 | (ASN1_STRING *)&(*b)->serialNumber)); |
411 | 0 | } |
412 | | |
413 | | X509_CRL *X509_CRL_new_ex(OSSL_LIB_CTX *libctx, const char *propq) |
414 | 0 | { |
415 | 0 | X509_CRL *crl = NULL; |
416 | |
|
417 | 0 | crl = (X509_CRL *)ASN1_item_new((X509_CRL_it())); |
418 | 0 | if (!ossl_x509_crl_set0_libctx(crl, libctx, propq)) { |
419 | 0 | X509_CRL_free(crl); |
420 | 0 | crl = NULL; |
421 | 0 | } |
422 | 0 | return crl; |
423 | 0 | } |
424 | | |
425 | | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) |
426 | 0 | { |
427 | 0 | X509_CRL_INFO *inf; |
428 | |
|
429 | 0 | inf = &crl->crl; |
430 | 0 | if (inf->revoked == NULL) |
431 | 0 | inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); |
432 | 0 | if (inf->revoked == NULL || !sk_X509_REVOKED_push(inf->revoked, rev)) { |
433 | 0 | ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
434 | 0 | return 0; |
435 | 0 | } |
436 | 0 | inf->enc.modified = 1; |
437 | 0 | return 1; |
438 | 0 | } |
439 | | |
440 | | int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) |
441 | 0 | { |
442 | 0 | if (crl->meth->crl_verify) |
443 | 0 | return crl->meth->crl_verify(crl, r); |
444 | 0 | return 0; |
445 | 0 | } |
446 | | |
447 | | int X509_CRL_get0_by_serial(X509_CRL *crl, |
448 | | X509_REVOKED **ret, const ASN1_INTEGER *serial) |
449 | 0 | { |
450 | 0 | if (crl->meth->crl_lookup) |
451 | 0 | return crl->meth->crl_lookup(crl, ret, serial, NULL); |
452 | 0 | return 0; |
453 | 0 | } |
454 | | |
455 | | int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) |
456 | 0 | { |
457 | 0 | if (crl->meth->crl_lookup) |
458 | 0 | return crl->meth->crl_lookup(crl, ret, |
459 | 0 | X509_get0_serialNumber(x), |
460 | 0 | X509_get_issuer_name(x)); |
461 | 0 | return 0; |
462 | 0 | } |
463 | | |
464 | | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) |
465 | 0 | { |
466 | 0 | return ASN1_item_verify_ex(ASN1_ITEM_rptr(X509_CRL_INFO), |
467 | 0 | &crl->sig_alg, &crl->signature, &crl->crl, NULL, |
468 | 0 | r, crl->libctx, crl->propq); |
469 | 0 | } |
470 | | |
471 | | static int crl_revoked_issuer_match(X509_CRL *crl, const X509_NAME *nm, |
472 | | X509_REVOKED *rev) |
473 | 0 | { |
474 | 0 | int i; |
475 | |
|
476 | 0 | if (!rev->issuer) { |
477 | 0 | if (!nm) |
478 | 0 | return 1; |
479 | 0 | if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) |
480 | 0 | return 1; |
481 | 0 | return 0; |
482 | 0 | } |
483 | | |
484 | 0 | if (!nm) |
485 | 0 | nm = X509_CRL_get_issuer(crl); |
486 | |
|
487 | 0 | for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) { |
488 | 0 | GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); |
489 | 0 | if (gen->type != GEN_DIRNAME) |
490 | 0 | continue; |
491 | 0 | if (!X509_NAME_cmp(nm, gen->d.directoryName)) |
492 | 0 | return 1; |
493 | 0 | } |
494 | 0 | return 0; |
495 | |
|
496 | 0 | } |
497 | | |
498 | | static int def_crl_lookup(X509_CRL *crl, |
499 | | X509_REVOKED **ret, const ASN1_INTEGER *serial, |
500 | | const X509_NAME *issuer) |
501 | 0 | { |
502 | 0 | X509_REVOKED rtmp, *rev; |
503 | 0 | int idx, num; |
504 | |
|
505 | 0 | if (crl->crl.revoked == NULL) |
506 | 0 | return 0; |
507 | | |
508 | | /* |
509 | | * Sort revoked into serial number order if not already sorted. Do this |
510 | | * under a lock to avoid race condition. |
511 | | */ |
512 | 0 | if (!sk_X509_REVOKED_is_sorted(crl->crl.revoked)) { |
513 | 0 | if (!CRYPTO_THREAD_write_lock(crl->lock)) |
514 | 0 | return 0; |
515 | 0 | sk_X509_REVOKED_sort(crl->crl.revoked); |
516 | 0 | CRYPTO_THREAD_unlock(crl->lock); |
517 | 0 | } |
518 | 0 | rtmp.serialNumber = *serial; |
519 | 0 | idx = sk_X509_REVOKED_find(crl->crl.revoked, &rtmp); |
520 | 0 | if (idx < 0) |
521 | 0 | return 0; |
522 | | /* Need to look for matching name */ |
523 | 0 | for (num = sk_X509_REVOKED_num(crl->crl.revoked); idx < num; idx++) { |
524 | 0 | rev = sk_X509_REVOKED_value(crl->crl.revoked, idx); |
525 | 0 | if (ASN1_INTEGER_cmp(&rev->serialNumber, serial)) |
526 | 0 | return 0; |
527 | 0 | if (crl_revoked_issuer_match(crl, issuer, rev)) { |
528 | 0 | if (ret) |
529 | 0 | *ret = rev; |
530 | 0 | if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) |
531 | 0 | return 2; |
532 | 0 | return 1; |
533 | 0 | } |
534 | 0 | } |
535 | 0 | return 0; |
536 | 0 | } |
537 | | |
538 | | void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) |
539 | 0 | { |
540 | 0 | if (meth == NULL) |
541 | 0 | default_crl_method = &int_crl_meth; |
542 | 0 | else |
543 | 0 | default_crl_method = meth; |
544 | 0 | } |
545 | | |
546 | | X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init) (X509_CRL *crl), |
547 | | int (*crl_free) (X509_CRL *crl), |
548 | | int (*crl_lookup) (X509_CRL *crl, |
549 | | X509_REVOKED **ret, |
550 | | const ASN1_INTEGER *ser, |
551 | | const X509_NAME *issuer), |
552 | | int (*crl_verify) (X509_CRL *crl, |
553 | | EVP_PKEY *pk)) |
554 | 0 | { |
555 | 0 | X509_CRL_METHOD *m = OPENSSL_malloc(sizeof(*m)); |
556 | |
|
557 | 0 | if (m == NULL) |
558 | 0 | return NULL; |
559 | 0 | m->crl_init = crl_init; |
560 | 0 | m->crl_free = crl_free; |
561 | 0 | m->crl_lookup = crl_lookup; |
562 | 0 | m->crl_verify = crl_verify; |
563 | 0 | m->flags = X509_CRL_METHOD_DYNAMIC; |
564 | 0 | return m; |
565 | 0 | } |
566 | | |
567 | | void X509_CRL_METHOD_free(X509_CRL_METHOD *m) |
568 | 0 | { |
569 | 0 | if (m == NULL || !(m->flags & X509_CRL_METHOD_DYNAMIC)) |
570 | 0 | return; |
571 | 0 | OPENSSL_free(m); |
572 | 0 | } |
573 | | |
574 | | void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) |
575 | 0 | { |
576 | 0 | crl->meth_data = dat; |
577 | 0 | } |
578 | | |
579 | | void *X509_CRL_get_meth_data(X509_CRL *crl) |
580 | 0 | { |
581 | 0 | return crl->meth_data; |
582 | 0 | } |
583 | | |
584 | | int ossl_x509_crl_set0_libctx(X509_CRL *x, OSSL_LIB_CTX *libctx, |
585 | | const char *propq) |
586 | 0 | { |
587 | 0 | if (x != NULL) { |
588 | 0 | x->libctx = libctx; |
589 | 0 | OPENSSL_free(x->propq); |
590 | 0 | x->propq = NULL; |
591 | 0 | if (propq != NULL) { |
592 | 0 | x->propq = OPENSSL_strdup(propq); |
593 | 0 | if (x->propq == NULL) |
594 | 0 | return 0; |
595 | 0 | } |
596 | 0 | } |
597 | 0 | return 1; |
598 | 0 | } |