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