2 * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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 <openssl/asn1.h>
13 #include <openssl/objects.h>
14 #include <openssl/evp.h>
15 #include <openssl/x509.h>
16 #include "internal/x509_int.h"
18 int X509_CRL_set_version(X509_CRL *x, long version)
22 if (x->crl.version == NULL) {
23 if ((x->crl.version = ASN1_INTEGER_new()) == NULL)
26 return (ASN1_INTEGER_set(x->crl.version, version));
29 int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name)
33 return (X509_NAME_set(&x->crl.issuer, name));
36 int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm)
40 return x509_set1_time(&x->crl.lastUpdate, tm);
43 int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm)
47 return x509_set1_time(&x->crl.nextUpdate, tm);
50 int X509_CRL_sort(X509_CRL *c)
55 * sort the data so it will be written in serial number order
57 sk_X509_REVOKED_sort(c->crl.revoked);
58 for (i = 0; i < sk_X509_REVOKED_num(c->crl.revoked); i++) {
59 r = sk_X509_REVOKED_value(c->crl.revoked, i);
62 c->crl.enc.modified = 1;
66 int X509_CRL_up_ref(X509_CRL *crl)
70 if (CRYPTO_atomic_add(&crl->references, 1, &i, crl->lock) <= 0)
73 REF_PRINT_COUNT("X509_CRL", crl);
74 REF_ASSERT_ISNT(i < 2);
75 return ((i > 1) ? 1 : 0);
78 long X509_CRL_get_version(const X509_CRL *crl)
80 return ASN1_INTEGER_get(crl->crl.version);
83 ASN1_TIME *X509_CRL_get_lastUpdate(const X509_CRL *crl)
85 return crl->crl.lastUpdate;
88 ASN1_TIME *X509_CRL_get_nextUpdate(const X509_CRL *crl)
90 return crl->crl.nextUpdate;
93 X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl)
95 return crl->crl.issuer;
98 const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl)
100 return crl->crl.extensions;
103 STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl)
105 return crl->crl.revoked;
108 void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
109 const X509_ALGOR **palg)
112 *psig = &crl->signature;
114 *palg = &crl->sig_alg;
117 int X509_CRL_get_signature_nid(const X509_CRL *crl)
119 return OBJ_obj2nid(crl->sig_alg.algorithm);
122 const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x)
124 return x->revocationDate;
127 int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm)
133 in = x->revocationDate;
135 in = ASN1_STRING_dup(tm);
137 ASN1_TIME_free(x->revocationDate);
138 x->revocationDate = in;
144 const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x)
146 return &x->serialNumber;
149 int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial)
155 in = &x->serialNumber;
157 return ASN1_STRING_copy(in, serial);
161 const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(const X509_REVOKED *r)
163 return r->extensions;
166 int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **pp)
168 crl->crl.enc.modified = 1;
169 return i2d_X509_CRL_INFO(&crl->crl, pp);