Coverage Report

Created: 2026-02-22 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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 <openssl/asn1t.h>
12
#include <openssl/x509.h>
13
#include "crypto/x509.h"
14
#include <openssl/x509v3.h>
15
#include "x509_local.h"
16
17
static int X509_REVOKED_cmp(const X509_REVOKED *const *a,
18
    const X509_REVOKED *const *b);
19
static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp);
20
21
ASN1_SEQUENCE(X509_REVOKED) = {
22
    ASN1_EMBED(X509_REVOKED, serialNumber, ASN1_INTEGER),
23
    ASN1_SIMPLE(X509_REVOKED, revocationDate, ASN1_TIME),
24
    ASN1_SEQUENCE_OF_OPT(X509_REVOKED, extensions, X509_EXTENSION)
25
0
} ASN1_SEQUENCE_END(X509_REVOKED)
26
0
27
0
static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r);
28
0
static int def_crl_lookup(X509_CRL *crl,
29
0
    X509_REVOKED **ret, const ASN1_INTEGER *serial,
30
0
    const X509_NAME *issuer);
31
0
32
0
static X509_CRL_METHOD int_crl_meth = {
33
0
    0,
34
0
    0, 0,
35
0
    def_crl_lookup,
36
0
    def_crl_verify
37
0
};
38
0
39
0
static const X509_CRL_METHOD *default_crl_method = &int_crl_meth;
40
0
41
0
/*
42
0
 * The X509_CRL_INFO structure needs a bit of customisation. Since we cache
43
0
 * the original encoding the signature won't be affected by reordering of the
44
0
 * revoked field.
45
0
 */
46
0
static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
47
0
    void *exarg)
48
0
{
49
0
    X509_CRL_INFO *a = (X509_CRL_INFO *)*pval;
50
51
0
    if (!a || !a->revoked)
52
0
        return 1;
53
0
    switch (operation) {
54
        /*
55
         * Just set cmp function here. We don't sort because that would
56
         * affect the output of X509_CRL_print().
57
         */
58
0
    case ASN1_OP_D2I_POST:
59
0
        (void)sk_X509_REVOKED_set_cmp_func(a->revoked, X509_REVOKED_cmp);
60
0
        break;
61
0
    }
62
0
    return 1;
63
0
}
64
65
ASN1_SEQUENCE_enc(X509_CRL_INFO, enc, crl_inf_cb) = {
66
    ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER),
67
    ASN1_EMBED(X509_CRL_INFO, sig_alg, X509_ALGOR),
68
    ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME),
69
    ASN1_SIMPLE(X509_CRL_INFO, lastUpdate, ASN1_TIME),
70
    ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME),
71
    ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED),
72
    ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0)
73
} ASN1_SEQUENCE_END_enc(X509_CRL_INFO, X509_CRL_INFO)
74
75
/*
76
 * Set CRL entry issuer according to CRL certificate issuer extension. Check
77
 * for unhandled critical CRL entry extensions.
78
 */
79
80
static int crl_set_issuers(X509_CRL *crl)
81
0
{
82
0
    int i, j;
83
0
    GENERAL_NAMES *most_recent_issuer, *gtmp;
84
0
    STACK_OF(X509_REVOKED) *revoked;
85
86
    /*
87
     * The CRL's nextUpdate field is optional, but we will still verify
88
     * lastUpdate and treat missing or invalid values as a failure.
89
     */
90
0
    if (crl->crl.lastUpdate == NULL) {
91
0
        crl->flags |= EXFLAG_INVALID;
92
0
        ERR_raise_data(ERR_LIB_ASN1, ASN1_R_ILLEGAL_TIME_VALUE,
93
0
            "lastUpdate in CRL is not well-formed");
94
0
        return 0;
95
0
    }
96
97
0
    revoked = X509_CRL_get_REVOKED(crl);
98
99
    /*
100
     * If this extension is not present on the first entry in an indirect CRL,
101
     * the certificate issuer defaults to the CRL issuer. Subsequent entries in
102
     * an indirect CRL, if this extension is not present, the certificate issuer
103
     * for the entry is the same as that for the preceding entry.
104
     * https://datatracker.ietf.org/doc/html/rfc5280#section-5.3.3
105
     */
106
0
    most_recent_issuer = NULL;
107
108
0
    for (i = 0; i < sk_X509_REVOKED_num(revoked); i++) {
109
0
        X509_REVOKED *rev = sk_X509_REVOKED_value(revoked, i);
110
0
        STACK_OF(X509_EXTENSION) *exts;
111
0
        ASN1_ENUMERATED *reason;
112
0
        X509_EXTENSION *ext;
113
0
        const ASN1_TIME *rev_date;
114
0
        ASN1_GENERALIZEDTIME *inv_date;
115
0
        int nid;
116
117
        /*
118
         * The revocation date is a mandatory attribute. If we get NULL here, it
119
         * means the validation has failed and an error has been pushed onto the
120
         * error stack.
121
         */
122
0
        if ((rev_date = X509_REVOKED_get0_revocationDate(rev)) == NULL) {
123
0
            crl->flags |= EXFLAG_INVALID;
124
0
            ERR_raise_data(ERR_LIB_ASN1, ASN1_R_ILLEGAL_TIME_VALUE,
125
0
                "revocationDate in CRL is not well-formed");
126
0
            return 0;
127
0
        }
128
129
0
        gtmp = X509_REVOKED_get_ext_d2i(rev, NID_certificate_issuer, &j, NULL);
130
0
        if (gtmp == NULL && j != -1) {
131
0
            crl->flags |= EXFLAG_INVALID;
132
0
            return 1;
133
0
        }
134
135
0
        if (gtmp != NULL) {
136
            /*
137
             * Validation to ensure Certificate Issuer extensions in CRL
138
             * entries only appear when the Indirect CRL flag is TRUE in the
139
             * Issuing Distribution Point (IDP) extension, as required by
140
             * https://datatracker.ietf.org/doc/html/rfc5280#section-5.3.3
141
             */
142
0
            if (crl->idp == NULL || !crl->idp->indirectCRL) {
143
0
                crl->flags |= EXFLAG_INVALID;
144
0
                ERR_raise_data(ERR_LIB_ASN1, ASN1_R_INVALID_VALUE,
145
0
                    "CRL Certificate Issuer extension requires Indirect CRL flag to be set");
146
0
                GENERAL_NAMES_free(gtmp);
147
0
                return 0;
148
0
            }
149
150
0
            if (crl->issuers == NULL) {
151
0
                crl->issuers = sk_GENERAL_NAMES_new_null();
152
0
                if (crl->issuers == NULL) {
153
0
                    GENERAL_NAMES_free(gtmp);
154
0
                    return 0;
155
0
                }
156
0
            }
157
0
            if (!sk_GENERAL_NAMES_push(crl->issuers, gtmp)) {
158
0
                GENERAL_NAMES_free(gtmp);
159
0
                return 0;
160
0
            }
161
0
            most_recent_issuer = gtmp;
162
0
        }
163
0
        rev->issuer = most_recent_issuer;
164
165
0
        reason = X509_REVOKED_get_ext_d2i(rev, NID_crl_reason, &j, NULL);
166
0
        if (reason == NULL && j != -1) {
167
0
            crl->flags |= EXFLAG_INVALID;
168
0
            return 1;
169
0
        }
170
171
0
        if (reason != NULL) {
172
0
            rev->reason = ASN1_ENUMERATED_get(reason);
173
0
            ASN1_ENUMERATED_free(reason);
174
0
        } else
175
0
            rev->reason = CRL_REASON_NONE;
176
177
        /* Check for critical CRL entry extensions and validate time. */
178
0
        exts = rev->extensions;
179
180
0
        for (j = 0; j < sk_X509_EXTENSION_num(exts); j++) {
181
0
            ext = sk_X509_EXTENSION_value(exts, j);
182
0
            nid = OBJ_obj2nid(X509_EXTENSION_get_object(ext));
183
184
            /*
185
             * If we obtain the extension but the time is NULL, it means that
186
             * the validation has failed and the reason will be pushed onto the
187
             * error stack.
188
             */
189
0
            if (nid == NID_invalidity_date) {
190
0
                if ((inv_date = X509V3_EXT_d2i(ext)) == NULL) {
191
0
                    crl->flags |= EXFLAG_INVALID;
192
0
                    ERR_raise_data(ERR_LIB_ASN1, ASN1_R_ILLEGAL_TIME_VALUE,
193
0
                        "invalidityDate in CRL is not well-formed");
194
0
                    return 0;
195
0
                }
196
0
                ASN1_GENERALIZEDTIME_free(inv_date);
197
0
            }
198
0
            if (X509_EXTENSION_get_critical(ext)) {
199
0
                if (nid == NID_certificate_issuer)
200
0
                    continue;
201
0
                crl->flags |= EXFLAG_CRITICAL;
202
0
            }
203
0
        }
204
0
    }
205
206
0
    return 1;
207
0
}
208
209
/*
210
 * The X509_CRL structure needs a bit of customisation. Cache some extensions
211
 * and hash of the whole CRL or set EXFLAG_NO_FINGERPRINT if this fails.
212
 */
213
static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
214
    void *exarg)
215
0
{
216
0
    X509_CRL *crl = (X509_CRL *)*pval;
217
0
    STACK_OF(X509_EXTENSION) *exts;
218
0
    X509_EXTENSION *ext;
219
0
    int idx, i;
220
221
0
    switch (operation) {
222
0
    case ASN1_OP_D2I_PRE:
223
0
        if (crl->meth->crl_free) {
224
0
            if (!crl->meth->crl_free(crl))
225
0
                return 0;
226
0
        }
227
0
        AUTHORITY_KEYID_free(crl->akid);
228
0
        ISSUING_DIST_POINT_free(crl->idp);
229
0
        ASN1_INTEGER_free(crl->crl_number);
230
0
        ASN1_INTEGER_free(crl->base_crl_number);
231
0
        sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free);
232
        /* fall through */
233
234
0
    case ASN1_OP_NEW_POST:
235
0
        crl->idp = NULL;
236
0
        crl->akid = NULL;
237
0
        crl->flags = 0;
238
0
        crl->idp_flags = 0;
239
0
        crl->idp_reasons = CRLDP_ALL_REASONS;
240
0
        crl->meth = default_crl_method;
241
0
        crl->meth_data = NULL;
242
0
        crl->issuers = NULL;
243
0
        crl->crl_number = NULL;
244
0
        crl->base_crl_number = NULL;
245
0
        break;
246
247
0
    case ASN1_OP_D2I_POST:
248
0
        if (!X509_CRL_digest(crl, EVP_sha1(), crl->sha1_hash, NULL))
249
0
            crl->flags |= EXFLAG_NO_FINGERPRINT;
250
0
        crl->idp = X509_CRL_get_ext_d2i(crl,
251
0
            NID_issuing_distribution_point, &i,
252
0
            NULL);
253
0
        if (crl->idp != NULL) {
254
0
            if (!setup_idp(crl, crl->idp))
255
0
                crl->flags |= EXFLAG_INVALID;
256
0
        } else if (i != -1) {
257
0
            crl->flags |= EXFLAG_INVALID;
258
0
        }
259
260
0
        crl->akid = X509_CRL_get_ext_d2i(crl,
261
0
            NID_authority_key_identifier, &i,
262
0
            NULL);
263
0
        if (crl->akid == NULL && i != -1)
264
0
            crl->flags |= EXFLAG_INVALID;
265
266
0
        crl->crl_number = X509_CRL_get_ext_d2i(crl, NID_crl_number, &i, NULL);
267
0
        if (crl->crl_number == NULL && i != -1) {
268
0
            ERR_raise_data(ERR_LIB_ASN1, ASN1_R_ILLEGAL_OBJECT,
269
0
                "CRL: malformed CRL number extension");
270
0
            return 0;
271
0
        }
272
0
        crl->base_crl_number = X509_CRL_get_ext_d2i(crl, NID_delta_crl, &i, NULL);
273
0
        if (crl->base_crl_number == NULL && i != -1) {
274
0
            ERR_raise_data(ERR_LIB_ASN1, ASN1_R_ILLEGAL_OBJECT,
275
0
                "CRL: malformed Delta CRL Indicator");
276
0
            return 0;
277
0
        }
278
        /* Delta CRLs must have CRL number */
279
0
        if (crl->base_crl_number && !crl->crl_number)
280
0
            crl->flags |= EXFLAG_INVALID;
281
        /*
282
         * See if we have any unhandled critical CRL extensions and indicate
283
         * this in a flag. We only currently handle IDP so anything else
284
         * critical sets the flag. This code accesses the X509_CRL structure
285
         * directly: applications shouldn't do this.
286
         */
287
288
0
        exts = crl->crl.extensions;
289
290
0
        for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) {
291
0
            int nid;
292
0
            ext = sk_X509_EXTENSION_value(exts, idx);
293
0
            nid = OBJ_obj2nid(X509_EXTENSION_get_object(ext));
294
0
            if (nid == NID_freshest_crl)
295
0
                crl->flags |= EXFLAG_FRESHEST;
296
0
            if (X509_EXTENSION_get_critical(ext)) {
297
                /* We handle IDP and deltas */
298
0
                if ((nid == NID_issuing_distribution_point)
299
0
                    || (nid == NID_authority_key_identifier)
300
0
                    || (nid == NID_delta_crl))
301
0
                    continue;
302
0
                crl->flags |= EXFLAG_CRITICAL;
303
0
                break;
304
0
            }
305
0
        }
306
307
0
        if (!crl_set_issuers(crl))
308
0
            return 0;
309
310
0
        if (crl->meth->crl_init) {
311
0
            if (crl->meth->crl_init(crl) == 0)
312
0
                return 0;
313
0
        }
314
315
0
        crl->flags |= EXFLAG_SET;
316
0
        break;
317
318
0
    case ASN1_OP_FREE_POST:
319
0
        if (crl->meth != NULL && crl->meth->crl_free != NULL) {
320
0
            if (!crl->meth->crl_free(crl))
321
0
                return 0;
322
0
        }
323
0
        AUTHORITY_KEYID_free(crl->akid);
324
0
        ISSUING_DIST_POINT_free(crl->idp);
325
0
        ASN1_INTEGER_free(crl->crl_number);
326
0
        ASN1_INTEGER_free(crl->base_crl_number);
327
0
        sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free);
328
0
        OPENSSL_free(crl->propq);
329
0
        break;
330
0
    case ASN1_OP_DUP_POST: {
331
0
        X509_CRL *old = exarg;
332
333
0
        if (!ossl_x509_crl_set0_libctx(crl, old->libctx, old->propq))
334
0
            return 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
0
}
496
497
static int def_crl_lookup(X509_CRL *crl,
498
    X509_REVOKED **ret, const ASN1_INTEGER *serial,
499
    const X509_NAME *issuer)
500
0
{
501
0
    X509_REVOKED rtmp, *rev;
502
0
    int idx, num;
503
504
0
    if (crl->crl.revoked == NULL)
505
0
        return 0;
506
507
    /*
508
     * Sort revoked into serial number order if not already sorted. Do this
509
     * under a lock to avoid race condition.
510
     */
511
0
    if (!sk_X509_REVOKED_is_sorted(crl->crl.revoked)) {
512
0
        if (!CRYPTO_THREAD_write_lock(crl->lock))
513
0
            return 0;
514
0
        sk_X509_REVOKED_sort(crl->crl.revoked);
515
0
        CRYPTO_THREAD_unlock(crl->lock);
516
0
    }
517
0
    rtmp.serialNumber = *serial;
518
0
    idx = sk_X509_REVOKED_find(crl->crl.revoked, &rtmp);
519
0
    if (idx < 0)
520
0
        return 0;
521
    /* Need to look for matching name */
522
0
    for (num = sk_X509_REVOKED_num(crl->crl.revoked); idx < num; idx++) {
523
0
        rev = sk_X509_REVOKED_value(crl->crl.revoked, idx);
524
0
        if (ASN1_INTEGER_cmp(&rev->serialNumber, serial))
525
0
            return 0;
526
0
        if (crl_revoked_issuer_match(crl, issuer, rev)) {
527
0
            if (ret)
528
0
                *ret = rev;
529
0
            if (rev->reason == CRL_REASON_REMOVE_FROM_CRL)
530
0
                return 2;
531
0
            return 1;
532
0
        }
533
0
    }
534
0
    return 0;
535
0
}
536
537
void X509_CRL_set_default_method(const X509_CRL_METHOD *meth)
538
0
{
539
0
    if (meth == NULL)
540
0
        default_crl_method = &int_crl_meth;
541
0
    else
542
0
        default_crl_method = meth;
543
0
}
544
545
X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init)(X509_CRL *crl),
546
    int (*crl_free)(X509_CRL *crl),
547
    int (*crl_lookup)(X509_CRL *crl,
548
        X509_REVOKED **ret,
549
        const ASN1_INTEGER *ser,
550
        const X509_NAME *issuer),
551
    int (*crl_verify)(X509_CRL *crl,
552
        EVP_PKEY *pk))
553
0
{
554
0
    X509_CRL_METHOD *m = OPENSSL_malloc(sizeof(*m));
555
556
0
    if (m == NULL)
557
0
        return NULL;
558
0
    m->crl_init = crl_init;
559
0
    m->crl_free = crl_free;
560
0
    m->crl_lookup = crl_lookup;
561
0
    m->crl_verify = crl_verify;
562
0
    m->flags = X509_CRL_METHOD_DYNAMIC;
563
0
    return m;
564
0
}
565
566
void X509_CRL_METHOD_free(X509_CRL_METHOD *m)
567
0
{
568
0
    if (m == NULL || !(m->flags & X509_CRL_METHOD_DYNAMIC))
569
0
        return;
570
0
    OPENSSL_free(m);
571
0
}
572
573
void X509_CRL_set_meth_data(X509_CRL *crl, void *dat)
574
0
{
575
0
    crl->meth_data = dat;
576
0
}
577
578
void *X509_CRL_get_meth_data(X509_CRL *crl)
579
0
{
580
0
    return crl->meth_data;
581
0
}
582
583
int ossl_x509_crl_set0_libctx(X509_CRL *x, OSSL_LIB_CTX *libctx,
584
    const char *propq)
585
0
{
586
0
    if (x != NULL) {
587
0
        x->libctx = libctx;
588
0
        OPENSSL_free(x->propq);
589
0
        x->propq = NULL;
590
0
        if (propq != NULL) {
591
0
            x->propq = OPENSSL_strdup(propq);
592
0
            if (x->propq == NULL)
593
0
                return 0;
594
0
        }
595
0
    }
596
0
    return 1;
597
0
}