2 * Copyright 2001-2023 The OpenSSL Project Authors. All Rights Reserved.
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
11 #include "internal/cryptlib.h"
12 #include "internal/refcount.h"
13 #include <openssl/asn1.h>
14 #include <openssl/objects.h>
15 #include <openssl/evp.h>
16 #include <openssl/x509.h>
17 #include "crypto/x509.h"
19 int X509_CRL_set_version(X509_CRL *x, long version)
23 if (x->crl.version == NULL) {
24 if ((x->crl.version = ASN1_INTEGER_new()) == NULL)
27 if (!ASN1_INTEGER_set(x->crl.version, version))
29 x->crl.enc.modified = 1;
33 int X509_CRL_set_issuer_name(X509_CRL *x, const X509_NAME *name)
37 if (!X509_NAME_set(&x->crl.issuer, name))
39 x->crl.enc.modified = 1;
43 int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm)
45 if (x == NULL || tm == NULL)
47 return ossl_x509_set1_time(&x->crl.enc.modified, &x->crl.lastUpdate, tm);
50 int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm)
54 return ossl_x509_set1_time(&x->crl.enc.modified, &x->crl.nextUpdate, tm);
57 int X509_CRL_sort(X509_CRL *c)
63 * sort the data so it will be written in serial number order
65 sk_X509_REVOKED_sort(c->crl.revoked);
66 for (i = 0; i < sk_X509_REVOKED_num(c->crl.revoked); i++) {
67 r = sk_X509_REVOKED_value(c->crl.revoked, i);
70 c->crl.enc.modified = 1;
74 int X509_CRL_up_ref(X509_CRL *crl)
78 if (CRYPTO_UP_REF(&crl->references, &i) <= 0)
81 REF_PRINT_COUNT("X509_CRL", crl);
82 REF_ASSERT_ISNT(i < 2);
86 long X509_CRL_get_version(const X509_CRL *crl)
88 return ASN1_INTEGER_get(crl->crl.version);
91 const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl)
93 return crl->crl.lastUpdate;
96 const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl)
98 return crl->crl.nextUpdate;
101 #ifndef OPENSSL_NO_DEPRECATED_1_1_0
102 ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl)
104 return crl->crl.lastUpdate;
107 ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl)
109 return crl->crl.nextUpdate;
113 X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl)
115 return crl->crl.issuer;
118 const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl)
120 return crl->crl.extensions;
123 STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl)
125 return crl->crl.revoked;
128 void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
129 const X509_ALGOR **palg)
132 *psig = &crl->signature;
134 *palg = &crl->sig_alg;
137 int X509_CRL_get_signature_nid(const X509_CRL *crl)
139 return OBJ_obj2nid(crl->sig_alg.algorithm);
142 const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x)
144 return x->revocationDate;
147 int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm)
149 if (x == NULL || tm == NULL)
151 return ossl_x509_set1_time(NULL, &x->revocationDate, tm);
154 const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x)
156 return &x->serialNumber;
159 int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial)
165 in = &x->serialNumber;
167 return ASN1_STRING_copy(in, serial);
171 const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(const
174 return r->extensions;
177 int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **pp)
179 crl->crl.enc.modified = 1;
180 return i2d_X509_CRL_INFO(&crl->crl, pp);