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