]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/x509/x509cset.c
Add support for reference counting using C11 atomics
[thirdparty/openssl.git] / crypto / x509 / x509cset.c
CommitLineData
0f113f3e 1/*
b1322259 2 * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
35bf3541 3 *
b1322259
RS
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
35bf3541
DSH
8 */
9
10#include <stdio.h>
b39fc560 11#include "internal/cryptlib.h"
35bf3541
DSH
12#include <openssl/asn1.h>
13#include <openssl/objects.h>
14#include <openssl/evp.h>
15#include <openssl/x509.h>
e3e57192 16#include "internal/x509_int.h"
35bf3541
DSH
17
18int X509_CRL_set_version(X509_CRL *x, long version)
0f113f3e
MC
19{
20 if (x == NULL)
21 return (0);
7aef39a7
DSH
22 if (x->crl.version == NULL) {
23 if ((x->crl.version = ASN1_INTEGER_new()) == NULL)
0f113f3e
MC
24 return (0);
25 }
7aef39a7 26 return (ASN1_INTEGER_set(x->crl.version, version));
0f113f3e 27}
35bf3541
DSH
28
29int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name)
0f113f3e 30{
7aef39a7 31 if (x == NULL)
0f113f3e 32 return (0);
7aef39a7 33 return (X509_NAME_set(&x->crl.issuer, name));
0f113f3e 34}
35bf3541 35
568ce3a5 36int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm)
0f113f3e 37{
0f113f3e 38 if (x == NULL)
3a60d6fa
DSH
39 return 0;
40 return x509_set1_time(&x->crl.lastUpdate, tm);
0f113f3e 41}
35bf3541 42
568ce3a5 43int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm)
0f113f3e 44{
0f113f3e 45 if (x == NULL)
3a60d6fa
DSH
46 return 0;
47 return x509_set1_time(&x->crl.nextUpdate, tm);
0f113f3e 48}
35bf3541
DSH
49
50int X509_CRL_sort(X509_CRL *c)
0f113f3e
MC
51{
52 int i;
53 X509_REVOKED *r;
54 /*
55 * sort the data so it will be written in serial number order
56 */
7aef39a7
DSH
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);
0f113f3e
MC
60 r->sequence = i;
61 }
7aef39a7 62 c->crl.enc.modified = 1;
0f113f3e
MC
63 return 1;
64}
35bf3541 65
c5ebfcab 66int X509_CRL_up_ref(X509_CRL *crl)
65cbf983 67{
c001ce33 68 int i;
c5ebfcab 69
2f545ae4 70 if (CRYPTO_UP_REF(&crl->references, &i, crl->lock) <= 0)
c5ebfcab
F
71 return 0;
72
73 REF_PRINT_COUNT("X509_CRL", crl);
74 REF_ASSERT_ISNT(i < 2);
75 return ((i > 1) ? 1 : 0);
65cbf983
DSH
76}
77
67302ade 78long X509_CRL_get_version(const X509_CRL *crl)
e3e57192 79{
7aef39a7 80 return ASN1_INTEGER_get(crl->crl.version);
e3e57192
DSH
81}
82
568ce3a5 83const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl)
e3e57192 84{
7aef39a7 85 return crl->crl.lastUpdate;
e3e57192
DSH
86}
87
568ce3a5 88const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl)
e3e57192 89{
7aef39a7 90 return crl->crl.nextUpdate;
e3e57192
DSH
91}
92
568ce3a5
DSH
93#if OPENSSL_API_COMPAT < 0x10100000L
94ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl)
95{
96 return crl->crl.lastUpdate;
97}
98
99ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl)
100{
101 return crl->crl.nextUpdate;
102}
103#endif
104
67302ade 105X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl)
e3e57192 106{
7aef39a7 107 return crl->crl.issuer;
e3e57192
DSH
108}
109
5e6089f0 110const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl)
835911b8
DSH
111{
112 return crl->crl.extensions;
113}
114
e3e57192
DSH
115STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl)
116{
7aef39a7 117 return crl->crl.revoked;
e3e57192
DSH
118}
119
5e6089f0
MC
120void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
121 const X509_ALGOR **palg)
e3e57192 122{
75ef61d7 123 if (psig != NULL)
34a42e14 124 *psig = &crl->signature;
75ef61d7 125 if (palg != NULL)
6e63c142 126 *palg = &crl->sig_alg;
e3e57192
DSH
127}
128
a9732d04
DSH
129int X509_CRL_get_signature_nid(const X509_CRL *crl)
130{
131 return OBJ_obj2nid(crl->sig_alg.algorithm);
132}
133
604f6eff 134const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x)
dc29030a
DSH
135{
136 return x->revocationDate;
137}
138
35bf3541 139int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm)
0f113f3e
MC
140{
141 ASN1_TIME *in;
35bf3541 142
0f113f3e
MC
143 if (x == NULL)
144 return (0);
145 in = x->revocationDate;
146 if (in != tm) {
f422a514 147 in = ASN1_STRING_dup(tm);
0f113f3e 148 if (in != NULL) {
f422a514 149 ASN1_TIME_free(x->revocationDate);
0f113f3e
MC
150 x->revocationDate = in;
151 }
152 }
153 return (in != NULL);
154}
35bf3541 155
604f6eff 156const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x)
dc29030a 157{
34a42e14 158 return &x->serialNumber;
dc29030a
DSH
159}
160
35bf3541 161int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial)
0f113f3e
MC
162{
163 ASN1_INTEGER *in;
35bf3541 164
0f113f3e
MC
165 if (x == NULL)
166 return (0);
34a42e14
DSH
167 in = &x->serialNumber;
168 if (in != serial)
169 return ASN1_STRING_copy(in, serial);
170 return 1;
0f113f3e 171}
a9732d04 172
604f6eff 173const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(const X509_REVOKED *r)
835911b8
DSH
174{
175 return r->extensions;
176}
177
a9732d04
DSH
178int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **pp)
179{
180 crl->crl.enc.modified = 1;
181 return i2d_X509_CRL_INFO(&crl->crl, pp);
182}