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