/src/openssl/crypto/x509/x_crl.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1995-2021 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 | | } ASN1_SEQUENCE_END(X509_REVOKED) |
27 | | |
28 | | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r); |
29 | | static int def_crl_lookup(X509_CRL *crl, |
30 | | X509_REVOKED **ret, const ASN1_INTEGER *serial, |
31 | | const X509_NAME *issuer); |
32 | | |
33 | | static X509_CRL_METHOD int_crl_meth = { |
34 | | 0, |
35 | | 0, 0, |
36 | | def_crl_lookup, |
37 | | def_crl_verify |
38 | | }; |
39 | | |
40 | | static const X509_CRL_METHOD *default_crl_method = &int_crl_meth; |
41 | | |
42 | | /* |
43 | | * The X509_CRL_INFO structure needs a bit of customisation. Since we cache |
44 | | * the original encoding the signature won't be affected by reordering of the |
45 | | * revoked field. |
46 | | */ |
47 | | static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
48 | | 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 *gens, *gtmp; |
87 | 0 | STACK_OF(X509_REVOKED) *revoked; |
88 | |
|
89 | 0 | revoked = X509_CRL_get_REVOKED(crl); |
90 | |
|
91 | 0 | gens = NULL; |
92 | 0 | for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) { |
93 | 0 | X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i); |
94 | 0 | STACK_OF(X509_EXTENSION) *exts; |
95 | 0 | ASN1_ENUMERATED *reason; |
96 | 0 | X509_EXTENSION *ext; |
97 | |
|
98 | 0 | gtmp = X509_REVOKED_get_ext_d2i(rev, |
99 | 0 | NID_certificate_issuer, &j, NULL); |
100 | 0 | if (gtmp == NULL && j != -1) { |
101 | 0 | crl->flags |= EXFLAG_INVALID; |
102 | 0 | return 1; |
103 | 0 | } |
104 | | |
105 | 0 | if (gtmp != NULL) { |
106 | 0 | if (crl->issuers == NULL) { |
107 | 0 | crl->issuers = sk_GENERAL_NAMES_new_null(); |
108 | 0 | if (crl->issuers == NULL) { |
109 | 0 | GENERAL_NAMES_free(gtmp); |
110 | 0 | return 0; |
111 | 0 | } |
112 | 0 | } |
113 | 0 | if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp)) { |
114 | 0 | GENERAL_NAMES_free(gtmp); |
115 | 0 | return 0; |
116 | 0 | } |
117 | 0 | gens = gtmp; |
118 | 0 | } |
119 | 0 | rev->issuer = gens; |
120 | |
|
121 | 0 | reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, &j, NULL); |
122 | 0 | if (reason == NULL && j != -1) { |
123 | 0 | crl->flags |= EXFLAG_INVALID; |
124 | 0 | return 1; |
125 | 0 | } |
126 | | |
127 | 0 | if (reason != NULL) { |
128 | 0 | rev->reason = ASN1_ENUMERATED_get(reason); |
129 | 0 | ASN1_ENUMERATED_free(reason); |
130 | 0 | } else |
131 | 0 | rev->reason = CRL_REASON_NONE; |
132 | | |
133 | | /* Check for critical CRL entry extensions */ |
134 | |
|
135 | 0 | exts = rev->extensions; |
136 | |
|
137 | 0 | for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) { |
138 | 0 | ext = sk_X509_EXTENSION_value(exts, j); |
139 | 0 | if (X509_EXTENSION_get_critical(ext)) { |
140 | 0 | if (OBJ_obj2nid(X509_EXTENSION_get_object(ext)) |
141 | 0 | == NID_certificate_issuer) |
142 | 0 | continue; |
143 | 0 | crl->flags |= EXFLAG_CRITICAL; |
144 | 0 | break; |
145 | 0 | } |
146 | 0 | } |
147 | |
|
148 | 0 | } |
149 | | |
150 | 0 | return 1; |
151 | |
|
152 | 0 | } |
153 | | |
154 | | /* |
155 | | * The X509_CRL structure needs a bit of customisation. Cache some extensions |
156 | | * and hash of the whole CRL or set EXFLAG_NO_FINGERPRINT if this fails. |
157 | | */ |
158 | | static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
159 | | void *exarg) |
160 | 0 | { |
161 | 0 | X509_CRL *crl = (X509_CRL *)*pval; |
162 | 0 | STACK_OF(X509_EXTENSION) *exts; |
163 | 0 | X509_EXTENSION *ext; |
164 | 0 | int idx, i; |
165 | |
|
166 | 0 | switch (operation) { |
167 | 0 | case ASN1_OP_D2I_PRE: |
168 | 0 | if (crl->meth->crl_free) { |
169 | 0 | if (!crl->meth->crl_free(crl)) |
170 | 0 | return 0; |
171 | 0 | } |
172 | 0 | AUTHORITY_KEYID_free(crl->akid); |
173 | 0 | ISSUING_DIST_POINT_free(crl->idp); |
174 | 0 | ASN1_INTEGER_free(crl->crl_number); |
175 | 0 | ASN1_INTEGER_free(crl->base_crl_number); |
176 | 0 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); |
177 | | /* fall through */ |
178 | |
|
179 | 0 | case ASN1_OP_NEW_POST: |
180 | 0 | crl->idp = NULL; |
181 | 0 | crl->akid = NULL; |
182 | 0 | crl->flags = 0; |
183 | 0 | crl->idp_flags = 0; |
184 | 0 | crl->idp_reasons = CRLDP_ALL_REASONS; |
185 | 0 | crl->meth = default_crl_method; |
186 | 0 | crl->meth_data = NULL; |
187 | 0 | crl->issuers = NULL; |
188 | 0 | crl->crl_number = NULL; |
189 | 0 | crl->base_crl_number = NULL; |
190 | 0 | break; |
191 | | |
192 | 0 | case ASN1_OP_D2I_POST: |
193 | 0 | if (!X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL)) |
194 | 0 | crl->flags |= EXFLAG_NO_FINGERPRINT; |
195 | 0 | crl->idp = X509_CRL_get_ext_d2i(crl, |
196 | 0 | NID_issuing_distribution_point, &i, |
197 | 0 | NULL); |
198 | 0 | if (crl->idp != NULL) { |
199 | 0 | if (!setup_idp(crl, crl->idp)) |
200 | 0 | crl->flags |= EXFLAG_INVALID; |
201 | 0 | } |
202 | 0 | else if (i != -1) { |
203 | 0 | crl->flags |= EXFLAG_INVALID; |
204 | 0 | } |
205 | |
|
206 | 0 | crl->akid = X509_CRL_get_ext_d2i(crl, |
207 | 0 | NID_authority_key_identifier, &i, |
208 | 0 | NULL); |
209 | 0 | if (crl->akid == NULL && i != -1) |
210 | 0 | crl->flags |= EXFLAG_INVALID; |
211 | |
|
212 | 0 | crl->crl_number = X509_CRL_get_ext_d2i(crl, |
213 | 0 | NID_crl_number, &i, NULL); |
214 | 0 | if (crl->crl_number == NULL && i != -1) |
215 | 0 | crl->flags |= EXFLAG_INVALID; |
216 | |
|
217 | 0 | crl->base_crl_number = X509_CRL_get_ext_d2i(crl, |
218 | 0 | NID_delta_crl, &i, |
219 | 0 | NULL); |
220 | 0 | if (crl->base_crl_number == NULL && i != -1) |
221 | 0 | crl->flags |= EXFLAG_INVALID; |
222 | | /* Delta CRLs must have CRL number */ |
223 | 0 | if (crl->base_crl_number && !crl->crl_number) |
224 | 0 | 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 | |
|
233 | 0 | exts = crl->crl.extensions; |
234 | |
|
235 | 0 | for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) { |
236 | 0 | int nid; |
237 | 0 | ext = sk_X509_EXTENSION_value(exts, idx); |
238 | 0 | nid = OBJ_obj2nid(X509_EXTENSION_get_object(ext)); |
239 | 0 | if (nid == NID_freshest_crl) |
240 | 0 | crl->flags |= EXFLAG_FRESHEST; |
241 | 0 | if (X509_EXTENSION_get_critical(ext)) { |
242 | | /* We handle IDP and deltas */ |
243 | 0 | if ((nid == NID_issuing_distribution_point) |
244 | 0 | || (nid == NID_authority_key_identifier) |
245 | 0 | || (nid == NID_delta_crl)) |
246 | 0 | continue; |
247 | 0 | crl->flags |= EXFLAG_CRITICAL; |
248 | 0 | break; |
249 | 0 | } |
250 | 0 | } |
251 | |
|
252 | 0 | if (!crl_set_issuers(crl)) |
253 | 0 | return 0; |
254 | | |
255 | 0 | if (crl->meth->crl_init) { |
256 | 0 | if (crl->meth->crl_init(crl) == 0) |
257 | 0 | return 0; |
258 | 0 | } |
259 | | |
260 | 0 | crl->flags |= EXFLAG_SET; |
261 | 0 | break; |
262 | | |
263 | 0 | case ASN1_OP_FREE_POST: |
264 | 0 | if (crl->meth != NULL && crl->meth->crl_free != NULL) { |
265 | 0 | if (!crl->meth->crl_free(crl)) |
266 | 0 | return 0; |
267 | 0 | } |
268 | 0 | AUTHORITY_KEYID_free(crl->akid); |
269 | 0 | ISSUING_DIST_POINT_free(crl->idp); |
270 | 0 | ASN1_INTEGER_free(crl->crl_number); |
271 | 0 | ASN1_INTEGER_free(crl->base_crl_number); |
272 | 0 | sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); |
273 | 0 | OPENSSL_free(crl->propq); |
274 | 0 | break; |
275 | 0 | case ASN1_OP_DUP_POST: |
276 | 0 | { |
277 | 0 | X509_CRL *old = exarg; |
278 | |
|
279 | 0 | if (!ossl_x509_crl_set0_libctx(crl, old->libctx, old->propq)) |
280 | 0 | return 0; |
281 | 0 | } |
282 | 0 | break; |
283 | 0 | } |
284 | 0 | return 1; |
285 | 0 | } |
286 | | |
287 | | /* Convert IDP into a more convenient form */ |
288 | | |
289 | | static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) |
290 | 0 | { |
291 | 0 | int idp_only = 0; |
292 | | |
293 | | /* Set various flags according to IDP */ |
294 | 0 | crl->idp_flags |= IDP_PRESENT; |
295 | 0 | if (idp->onlyuser > 0) { |
296 | 0 | idp_only++; |
297 | 0 | crl->idp_flags |= IDP_ONLYUSER; |
298 | 0 | } |
299 | 0 | if (idp->onlyCA > 0) { |
300 | 0 | idp_only++; |
301 | 0 | crl->idp_flags |= IDP_ONLYCA; |
302 | 0 | } |
303 | 0 | if (idp->onlyattr > 0) { |
304 | 0 | idp_only++; |
305 | 0 | crl->idp_flags |= IDP_ONLYATTR; |
306 | 0 | } |
307 | |
|
308 | 0 | if (idp_only > 1) |
309 | 0 | crl->idp_flags |= IDP_INVALID; |
310 | |
|
311 | 0 | if (idp->indirectCRL > 0) |
312 | 0 | crl->idp_flags |= IDP_INDIRECT; |
313 | |
|
314 | 0 | if (idp->onlysomereasons) { |
315 | 0 | crl->idp_flags |= IDP_REASONS; |
316 | 0 | if (idp->onlysomereasons->length > 0) |
317 | 0 | crl->idp_reasons = idp->onlysomereasons->data[0]; |
318 | 0 | if (idp->onlysomereasons->length > 1) |
319 | 0 | crl->idp_reasons |= (idp->onlysomereasons->data[1] << 8); |
320 | 0 | crl->idp_reasons &= CRLDP_ALL_REASONS; |
321 | 0 | } |
322 | |
|
323 | 0 | return DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); |
324 | 0 | } |
325 | | |
326 | | ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = { |
327 | | ASN1_EMBED(X509_CRL, crl, X509_CRL_INFO), |
328 | | ASN1_EMBED(X509_CRL, sig_alg, X509_ALGOR), |
329 | | ASN1_EMBED(X509_CRL, signature, ASN1_BIT_STRING) |
330 | | } ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL) |
331 | | |
332 | | IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED) |
333 | | |
334 | | IMPLEMENT_ASN1_DUP_FUNCTION(X509_REVOKED) |
335 | | |
336 | | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO) |
337 | | |
338 | | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL) |
339 | | |
340 | | IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) |
341 | | |
342 | | static int X509_REVOKED_cmp(const X509_REVOKED *const *a, |
343 | | const X509_REVOKED *const *b) |
344 | 0 | { |
345 | 0 | return (ASN1_STRING_cmp((ASN1_STRING *)&(*a)->serialNumber, |
346 | 0 | (ASN1_STRING *)&(*b)->serialNumber)); |
347 | 0 | } |
348 | | |
349 | | X509_CRL *X509_CRL_new_ex(OSSL_LIB_CTX *libctx, const char *propq) |
350 | 0 | { |
351 | 0 | X509_CRL *crl = NULL; |
352 | |
|
353 | 0 | crl = (X509_CRL *)ASN1_item_new((X509_CRL_it())); |
354 | 0 | if (!ossl_x509_crl_set0_libctx(crl, libctx, propq)) { |
355 | 0 | X509_CRL_free(crl); |
356 | 0 | crl = NULL; |
357 | 0 | } |
358 | 0 | return crl; |
359 | 0 | } |
360 | | |
361 | | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) |
362 | 0 | { |
363 | 0 | X509_CRL_INFO *inf; |
364 | |
|
365 | 0 | inf = &crl->crl; |
366 | 0 | if (inf->revoked == NULL) |
367 | 0 | inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); |
368 | 0 | if (inf->revoked == NULL || !sk_X509_REVOKED_push(inf->revoked, rev)) { |
369 | 0 | ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB); |
370 | 0 | return 0; |
371 | 0 | } |
372 | 0 | inf->enc.modified = 1; |
373 | 0 | return 1; |
374 | 0 | } |
375 | | |
376 | | int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r) |
377 | 0 | { |
378 | 0 | if (crl->meth->crl_verify) |
379 | 0 | return crl->meth->crl_verify(crl, r); |
380 | 0 | return 0; |
381 | 0 | } |
382 | | |
383 | | int X509_CRL_get0_by_serial(X509_CRL *crl, |
384 | | X509_REVOKED **ret, const ASN1_INTEGER *serial) |
385 | 0 | { |
386 | 0 | if (crl->meth->crl_lookup) |
387 | 0 | return crl->meth->crl_lookup(crl, ret, serial, NULL); |
388 | 0 | return 0; |
389 | 0 | } |
390 | | |
391 | | int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x) |
392 | 0 | { |
393 | 0 | if (crl->meth->crl_lookup) |
394 | 0 | return crl->meth->crl_lookup(crl, ret, |
395 | 0 | X509_get0_serialNumber(x), |
396 | 0 | X509_get_issuer_name(x)); |
397 | 0 | return 0; |
398 | 0 | } |
399 | | |
400 | | static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r) |
401 | 0 | { |
402 | 0 | return ASN1_item_verify_ex(ASN1_ITEM_rptr(X509_CRL_INFO), |
403 | 0 | &crl->sig_alg, &crl->signature, &crl->crl, NULL, |
404 | 0 | r, crl->libctx, crl->propq); |
405 | 0 | } |
406 | | |
407 | | static int crl_revoked_issuer_match(X509_CRL *crl, const X509_NAME *nm, |
408 | | X509_REVOKED *rev) |
409 | 0 | { |
410 | 0 | int i; |
411 | |
|
412 | 0 | if (!rev->issuer) { |
413 | 0 | if (!nm) |
414 | 0 | return 1; |
415 | 0 | if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl))) |
416 | 0 | return 1; |
417 | 0 | return 0; |
418 | 0 | } |
419 | | |
420 | 0 | if (!nm) |
421 | 0 | nm = X509_CRL_get_issuer(crl); |
422 | |
|
423 | 0 | for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) { |
424 | 0 | GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i); |
425 | 0 | if (gen->type != GEN_DIRNAME) |
426 | 0 | continue; |
427 | 0 | if (!X509_NAME_cmp(nm, gen->d.directoryName)) |
428 | 0 | return 1; |
429 | 0 | } |
430 | 0 | return 0; |
431 | |
|
432 | 0 | } |
433 | | |
434 | | static int def_crl_lookup(X509_CRL *crl, |
435 | | X509_REVOKED **ret, const ASN1_INTEGER *serial, |
436 | | const X509_NAME *issuer) |
437 | 0 | { |
438 | 0 | X509_REVOKED rtmp, *rev; |
439 | 0 | int idx, num; |
440 | |
|
441 | 0 | if (crl->crl.revoked == NULL) |
442 | 0 | return 0; |
443 | | |
444 | | /* |
445 | | * Sort revoked into serial number order if not already sorted. Do this |
446 | | * under a lock to avoid race condition. |
447 | | */ |
448 | 0 | if (!sk_X509_REVOKED_is_sorted(crl->crl.revoked)) { |
449 | 0 | if (!CRYPTO_THREAD_write_lock(crl->lock)) |
450 | 0 | return 0; |
451 | 0 | sk_X509_REVOKED_sort(crl->crl.revoked); |
452 | 0 | CRYPTO_THREAD_unlock(crl->lock); |
453 | 0 | } |
454 | 0 | rtmp.serialNumber = *serial; |
455 | 0 | idx = sk_X509_REVOKED_find(crl->crl.revoked, &rtmp); |
456 | 0 | if (idx < 0) |
457 | 0 | return 0; |
458 | | /* Need to look for matching name */ |
459 | 0 | for (num = sk_X509_REVOKED_num(crl->crl.revoked); idx < num; idx++) { |
460 | 0 | rev = sk_X509_REVOKED_value(crl->crl.revoked, idx); |
461 | 0 | if (ASN1_INTEGER_cmp(&rev->serialNumber, serial)) |
462 | 0 | return 0; |
463 | 0 | if (crl_revoked_issuer_match(crl, issuer, rev)) { |
464 | 0 | if (ret) |
465 | 0 | *ret = rev; |
466 | 0 | if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) |
467 | 0 | return 2; |
468 | 0 | return 1; |
469 | 0 | } |
470 | 0 | } |
471 | 0 | return 0; |
472 | 0 | } |
473 | | |
474 | | void X509_CRL_set_default_method(const X509_CRL_METHOD *meth) |
475 | 0 | { |
476 | 0 | if (meth == NULL) |
477 | 0 | default_crl_method = &int_crl_meth; |
478 | 0 | else |
479 | 0 | default_crl_method = meth; |
480 | 0 | } |
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, |
486 | | const ASN1_INTEGER *ser, |
487 | | const X509_NAME *issuer), |
488 | | int (*crl_verify) (X509_CRL *crl, |
489 | | EVP_PKEY *pk)) |
490 | 0 | { |
491 | 0 | X509_CRL_METHOD *m = OPENSSL_malloc(sizeof(*m)); |
492 | |
|
493 | 0 | if (m == NULL) |
494 | 0 | return NULL; |
495 | 0 | m->crl_init = crl_init; |
496 | 0 | m->crl_free = crl_free; |
497 | 0 | m->crl_lookup = crl_lookup; |
498 | 0 | m->crl_verify = crl_verify; |
499 | 0 | m->flags = X509_CRL_METHOD_DYNAMIC; |
500 | 0 | return m; |
501 | 0 | } |
502 | | |
503 | | void X509_CRL_METHOD_free(X509_CRL_METHOD *m) |
504 | 0 | { |
505 | 0 | if (m == NULL || !(m->flags & X509_CRL_METHOD_DYNAMIC)) |
506 | 0 | return; |
507 | 0 | OPENSSL_free(m); |
508 | 0 | } |
509 | | |
510 | | void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) |
511 | 0 | { |
512 | 0 | crl->meth_data = dat; |
513 | 0 | } |
514 | | |
515 | | void *X509_CRL_get_meth_data(X509_CRL *crl) |
516 | 0 | { |
517 | 0 | return crl->meth_data; |
518 | 0 | } |
519 | | |
520 | | int ossl_x509_crl_set0_libctx(X509_CRL *x, OSSL_LIB_CTX *libctx, |
521 | | const char *propq) |
522 | 0 | { |
523 | 0 | if (x != NULL) { |
524 | 0 | x->libctx = libctx; |
525 | 0 | OPENSSL_free(x->propq); |
526 | 0 | x->propq = NULL; |
527 | 0 | if (propq != NULL) { |
528 | 0 | x->propq = OPENSSL_strdup(propq); |
529 | 0 | if (x->propq == NULL) |
530 | 0 | return 0; |
531 | 0 | } |
532 | 0 | } |
533 | 0 | return 1; |
534 | 0 | } |