Coverage Report

Created: 2026-03-09 06:55

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, NID_issuing_distribution_point, &i, NULL);
251
0
        if (crl->idp == NULL && i != -1) {
252
0
            ERR_raise_data(ERR_LIB_ASN1, ASN1_R_ILLEGAL_OBJECT,
253
0
                "CRL: malformed CRL issuing distribution point");
254
0
            return 0;
255
0
        }
256
0
        if (crl->idp != NULL) {
257
0
            if (!setup_idp(crl, crl->idp))
258
0
                crl->flags |= EXFLAG_INVALID;
259
0
        } else if (i != -1) {
260
0
            crl->flags |= EXFLAG_INVALID;
261
0
        }
262
263
0
        crl->akid = X509_CRL_get_ext_d2i(crl,
264
0
            NID_authority_key_identifier, &i,
265
0
            NULL);
266
0
        if (crl->akid == NULL && i != -1)
267
0
            crl->flags |= EXFLAG_INVALID;
268
269
0
        crl->crl_number = X509_CRL_get_ext_d2i(crl, NID_crl_number, &i, NULL);
270
0
        if (crl->crl_number == NULL && i != -1) {
271
0
            ERR_raise_data(ERR_LIB_ASN1, ASN1_R_ILLEGAL_OBJECT,
272
0
                "CRL: malformed CRL number extension");
273
0
            return 0;
274
0
        }
275
0
        crl->base_crl_number = X509_CRL_get_ext_d2i(crl, NID_delta_crl, &i, NULL);
276
0
        if (crl->base_crl_number == NULL && i != -1) {
277
0
            ERR_raise_data(ERR_LIB_ASN1, ASN1_R_ILLEGAL_OBJECT,
278
0
                "CRL: malformed Delta CRL Indicator");
279
0
            return 0;
280
0
        }
281
        /* Delta CRLs must have CRL number */
282
0
        if (crl->base_crl_number && !crl->crl_number)
283
0
            crl->flags |= EXFLAG_INVALID;
284
        /*
285
         * See if we have any unhandled critical CRL extensions and indicate
286
         * this in a flag. We only currently handle IDP so anything else
287
         * critical sets the flag. This code accesses the X509_CRL structure
288
         * directly: applications shouldn't do this.
289
         */
290
291
0
        exts = crl->crl.extensions;
292
293
0
        for (idx = 0; idx < sk_X509_EXTENSION_num(exts); idx++) {
294
0
            int nid;
295
0
            ext = sk_X509_EXTENSION_value(exts, idx);
296
0
            nid = OBJ_obj2nid(X509_EXTENSION_get_object(ext));
297
0
            if (nid == NID_freshest_crl)
298
0
                crl->flags |= EXFLAG_FRESHEST;
299
0
            if (X509_EXTENSION_get_critical(ext)) {
300
                /* We handle IDP and deltas */
301
0
                if ((nid == NID_issuing_distribution_point)
302
0
                    || (nid == NID_authority_key_identifier)
303
0
                    || (nid == NID_delta_crl))
304
0
                    continue;
305
0
                crl->flags |= EXFLAG_CRITICAL;
306
0
                break;
307
0
            }
308
0
        }
309
310
0
        if (!crl_set_issuers(crl))
311
0
            return 0;
312
313
0
        if (crl->meth->crl_init) {
314
0
            if (crl->meth->crl_init(crl) == 0)
315
0
                return 0;
316
0
        }
317
318
0
        crl->flags |= EXFLAG_SET;
319
0
        break;
320
321
0
    case ASN1_OP_FREE_POST:
322
0
        if (crl->meth != NULL && crl->meth->crl_free != NULL) {
323
0
            if (!crl->meth->crl_free(crl))
324
0
                return 0;
325
0
        }
326
0
        AUTHORITY_KEYID_free(crl->akid);
327
0
        ISSUING_DIST_POINT_free(crl->idp);
328
0
        ASN1_INTEGER_free(crl->crl_number);
329
0
        ASN1_INTEGER_free(crl->base_crl_number);
330
0
        sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free);
331
0
        OPENSSL_free(crl->propq);
332
0
        break;
333
0
    case ASN1_OP_DUP_POST: {
334
0
        X509_CRL *old = exarg;
335
336
0
        if (!ossl_x509_crl_set0_libctx(crl, old->libctx, old->propq))
337
0
            return 0;
338
0
    } break;
339
0
    }
340
0
    return 1;
341
0
}
342
343
/* Convert IDP into a more convenient form */
344
345
static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp)
346
0
{
347
0
    int idp_only = 0;
348
0
    int ret = 0;
349
350
    /* Set various flags according to IDP */
351
0
    crl->idp_flags |= IDP_PRESENT;
352
0
    if (idp->onlyuser > 0) {
353
0
        idp_only++;
354
0
        crl->idp_flags |= IDP_ONLYUSER;
355
0
    }
356
0
    if (idp->onlyCA > 0) {
357
0
        idp_only++;
358
0
        crl->idp_flags |= IDP_ONLYCA;
359
0
    }
360
0
    if (idp->onlyattr > 0) {
361
0
        idp_only++;
362
0
        crl->idp_flags |= IDP_ONLYATTR;
363
0
    }
364
365
0
    if (idp_only > 1)
366
0
        crl->idp_flags |= IDP_INVALID;
367
368
0
    if (idp->indirectCRL > 0)
369
0
        crl->idp_flags |= IDP_INDIRECT;
370
371
0
    if (idp->onlysomereasons) {
372
0
        crl->idp_flags |= IDP_REASONS;
373
0
        if (idp->onlysomereasons->length > 0)
374
0
            crl->idp_reasons = idp->onlysomereasons->data[0];
375
0
        if (idp->onlysomereasons->length > 1)
376
0
            crl->idp_reasons |= (idp->onlysomereasons->data[1] << 8);
377
0
        crl->idp_reasons &= CRLDP_ALL_REASONS;
378
0
    }
379
380
0
    ret = DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl));
381
382
    /*
383
     * RFC5280 specifies that if onlyContainsUserCerts, onlyContainsCACerts,
384
     * indirectCRL, and OnlyContainsAttributeCerts are all FALSE, there must
385
     * be either a distributionPoint field or an onlySomeReasons field present.
386
     */
387
0
    if (crl->idp_flags == IDP_PRESENT && idp->distpoint == NULL)
388
0
        crl->idp_flags |= IDP_INVALID;
389
390
0
    return ret;
391
0
}
392
393
ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = {
394
    ASN1_EMBED(X509_CRL, crl, X509_CRL_INFO),
395
    ASN1_EMBED(X509_CRL, sig_alg, X509_ALGOR),
396
    ASN1_EMBED(X509_CRL, signature, ASN1_BIT_STRING)
397
} ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL)
398
399
IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED)
400
401
IMPLEMENT_ASN1_DUP_FUNCTION(X509_REVOKED)
402
403
IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO)
404
405
IMPLEMENT_ASN1_FUNCTIONS(X509_CRL)
406
407
IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL)
408
409
static int X509_REVOKED_cmp(const X509_REVOKED *const *a,
410
    const X509_REVOKED *const *b)
411
0
{
412
0
    return (ASN1_STRING_cmp((ASN1_STRING *)&(*a)->serialNumber,
413
0
        (ASN1_STRING *)&(*b)->serialNumber));
414
0
}
415
416
X509_CRL *X509_CRL_new_ex(OSSL_LIB_CTX *libctx, const char *propq)
417
0
{
418
0
    X509_CRL *crl = NULL;
419
420
0
    crl = (X509_CRL *)ASN1_item_new((X509_CRL_it()));
421
0
    if (!ossl_x509_crl_set0_libctx(crl, libctx, propq)) {
422
0
        X509_CRL_free(crl);
423
0
        crl = NULL;
424
0
    }
425
0
    return crl;
426
0
}
427
428
int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
429
0
{
430
0
    X509_CRL_INFO *inf;
431
432
0
    inf = &crl->crl;
433
0
    if (inf->revoked == NULL)
434
0
        inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
435
0
    if (inf->revoked == NULL || !sk_X509_REVOKED_push(inf->revoked, rev)) {
436
0
        ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB);
437
0
        return 0;
438
0
    }
439
0
    inf->enc.modified = 1;
440
0
    return 1;
441
0
}
442
443
int X509_CRL_verify(X509_CRL *crl, EVP_PKEY *r)
444
0
{
445
0
    if (crl->meth->crl_verify)
446
0
        return crl->meth->crl_verify(crl, r);
447
0
    return 0;
448
0
}
449
450
int X509_CRL_get0_by_serial(X509_CRL *crl,
451
    X509_REVOKED **ret, const ASN1_INTEGER *serial)
452
0
{
453
0
    if (crl->meth->crl_lookup)
454
0
        return crl->meth->crl_lookup(crl, ret, serial, NULL);
455
0
    return 0;
456
0
}
457
458
int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, const X509 *x)
459
0
{
460
0
    if (crl->meth->crl_lookup)
461
0
        return crl->meth->crl_lookup(crl, ret,
462
0
            X509_get0_serialNumber(x),
463
0
            X509_get_issuer_name(x));
464
0
    return 0;
465
0
}
466
467
static int def_crl_verify(X509_CRL *crl, EVP_PKEY *r)
468
0
{
469
0
    return ASN1_item_verify_ex(ASN1_ITEM_rptr(X509_CRL_INFO),
470
0
        &crl->sig_alg, &crl->signature, &crl->crl, NULL,
471
0
        r, crl->libctx, crl->propq);
472
0
}
473
474
static int crl_revoked_issuer_match(X509_CRL *crl, const X509_NAME *nm,
475
    X509_REVOKED *rev)
476
0
{
477
0
    int i;
478
479
0
    if (!rev->issuer) {
480
0
        if (!nm)
481
0
            return 1;
482
0
        if (!X509_NAME_cmp(nm, X509_CRL_get_issuer(crl)))
483
0
            return 1;
484
0
        return 0;
485
0
    }
486
487
0
    if (!nm)
488
0
        nm = X509_CRL_get_issuer(crl);
489
490
0
    for (i = 0; i < sk_GENERAL_NAME_num(rev->issuer); i++) {
491
0
        GENERAL_NAME *gen = sk_GENERAL_NAME_value(rev->issuer, i);
492
0
        if (gen->type != GEN_DIRNAME)
493
0
            continue;
494
0
        if (!X509_NAME_cmp(nm, gen->d.directoryName))
495
0
            return 1;
496
0
    }
497
0
    return 0;
498
0
}
499
500
static int def_crl_lookup(X509_CRL *crl,
501
    X509_REVOKED **ret, const ASN1_INTEGER *serial,
502
    const X509_NAME *issuer)
503
0
{
504
0
    X509_REVOKED rtmp, *rev;
505
0
    int idx, num;
506
507
0
    if (crl->crl.revoked == NULL)
508
0
        return 0;
509
510
    /*
511
     * Sort revoked into serial number order if not already sorted. Do this
512
     * under a lock to avoid race condition.
513
     */
514
0
    if (!sk_X509_REVOKED_is_sorted(crl->crl.revoked)) {
515
0
        if (!CRYPTO_THREAD_write_lock(crl->lock))
516
0
            return 0;
517
0
        sk_X509_REVOKED_sort(crl->crl.revoked);
518
0
        CRYPTO_THREAD_unlock(crl->lock);
519
0
    }
520
0
    rtmp.serialNumber = *serial;
521
0
    idx = sk_X509_REVOKED_find(crl->crl.revoked, &rtmp);
522
0
    if (idx < 0)
523
0
        return 0;
524
    /* Need to look for matching name */
525
0
    for (num = sk_X509_REVOKED_num(crl->crl.revoked); idx < num; idx++) {
526
0
        rev = sk_X509_REVOKED_value(crl->crl.revoked, idx);
527
0
        if (ASN1_INTEGER_cmp(&rev->serialNumber, serial))
528
0
            return 0;
529
0
        if (crl_revoked_issuer_match(crl, issuer, rev)) {
530
0
            if (ret)
531
0
                *ret = rev;
532
0
            if (rev->reason == CRL_REASON_REMOVE_FROM_CRL)
533
0
                return 2;
534
0
            return 1;
535
0
        }
536
0
    }
537
0
    return 0;
538
0
}
539
540
void X509_CRL_set_default_method(const X509_CRL_METHOD *meth)
541
0
{
542
0
    if (meth == NULL)
543
0
        default_crl_method = &int_crl_meth;
544
0
    else
545
0
        default_crl_method = meth;
546
0
}
547
548
X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init)(X509_CRL *crl),
549
    int (*crl_free)(X509_CRL *crl),
550
    int (*crl_lookup)(X509_CRL *crl,
551
        X509_REVOKED **ret,
552
        const ASN1_INTEGER *ser,
553
        const X509_NAME *issuer),
554
    int (*crl_verify)(X509_CRL *crl,
555
        EVP_PKEY *pk))
556
0
{
557
0
    X509_CRL_METHOD *m = OPENSSL_malloc(sizeof(*m));
558
559
0
    if (m == NULL)
560
0
        return NULL;
561
0
    m->crl_init = crl_init;
562
0
    m->crl_free = crl_free;
563
0
    m->crl_lookup = crl_lookup;
564
0
    m->crl_verify = crl_verify;
565
0
    m->flags = X509_CRL_METHOD_DYNAMIC;
566
0
    return m;
567
0
}
568
569
void X509_CRL_METHOD_free(X509_CRL_METHOD *m)
570
0
{
571
0
    if (m == NULL || !(m->flags & X509_CRL_METHOD_DYNAMIC))
572
0
        return;
573
0
    OPENSSL_free(m);
574
0
}
575
576
void X509_CRL_set_meth_data(X509_CRL *crl, void *dat)
577
0
{
578
0
    crl->meth_data = dat;
579
0
}
580
581
void *X509_CRL_get_meth_data(X509_CRL *crl)
582
0
{
583
0
    return crl->meth_data;
584
0
}
585
586
int ossl_x509_crl_set0_libctx(X509_CRL *x, OSSL_LIB_CTX *libctx,
587
    const char *propq)
588
0
{
589
0
    if (x != NULL) {
590
0
        x->libctx = libctx;
591
0
        OPENSSL_free(x->propq);
592
0
        x->propq = NULL;
593
0
        if (propq != NULL) {
594
0
            x->propq = OPENSSL_strdup(propq);
595
0
            if (x->propq == NULL)
596
0
                return 0;
597
0
        }
598
0
    }
599
0
    return 1;
600
0
}