Coverage Report

Created: 2026-10-16 07:07

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