Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/x509/x509cset.c

raw
1 // Written by Dr Stephen N Henson ([email protected]) for the OpenSSL project 2001.
2 // Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
4
5 #include <openssl/asn1.h>
6 #include <openssl/evp.h>
7 #include <openssl/obj.h>
8 #include <openssl/x509.h>
9
10 #include "../asn1/internal.h"
11 #include "../internal.h"
12 #include "internal.h"
13
14 int X509_CRL_set_version(X509_CRL *x, long version) {
15 if (x == NULL) {
16 return 0;
17 }
18
19 if (version < X509_CRL_VERSION_1 || version > X509_CRL_VERSION_2) {
20 OPENSSL_PUT_ERROR(X509, X509_R_INVALID_VERSION);
21 return 0;
22 }
23
24 // v1(0) is default and is represented by omitting the version.
25 if (version == X509_CRL_VERSION_1) {
26 ASN1_INTEGER_free(x->crl->version);
27 x->crl->version = NULL;
28 return 1;
29 }
30
31 if (x->crl->version == NULL) {
32 x->crl->version = ASN1_INTEGER_new();
33 if (x->crl->version == NULL) {
34 return 0;
35 }
36 }
37 return ASN1_INTEGER_set_int64(x->crl->version, version);
38 }
39
40 int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name) {
41 if ((x == NULL) || (x->crl == NULL)) {
42 return 0;
43 }
44 return (X509_NAME_set(&x->crl->issuer, name));
45 }
46
47 int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm) {
48 ASN1_TIME *in;
49
50 if (x == NULL) {
51 return 0;
52 }
53 in = x->crl->lastUpdate;
54 if (in != tm) {
55 in = ASN1_STRING_dup(tm);
56 if (in != NULL) {
57 ASN1_TIME_free(x->crl->lastUpdate);
58 x->crl->lastUpdate = in;
59 }
60 }
61 return in != NULL;
62 }
63
64 int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm) {
65 ASN1_TIME *in;
66
67 if (x == NULL) {
68 return 0;
69 }
70 in = x->crl->nextUpdate;
71 if (in != tm) {
72 in = ASN1_STRING_dup(tm);
73 if (in != NULL) {
74 ASN1_TIME_free(x->crl->nextUpdate);
75 x->crl->nextUpdate = in;
76 }
77 }
78 return in != NULL;
79 }
80
81 int X509_CRL_sort(X509_CRL *c) {
82 // Sort the data so it will be written in serial number order.
83 sk_X509_REVOKED_sort(c->crl->revoked);
84 asn1_encoding_clear(&c->crl->enc);
85 return 1;
86 }
87
88 int X509_CRL_up_ref(X509_CRL *crl) {
89 if (crl == NULL) {
90 return 0;
91 }
92 CRYPTO_refcount_inc(&crl->references);
93 return 1;
94 }
95
96 long X509_CRL_get_version(const X509_CRL *crl) {
97 return ASN1_INTEGER_get(crl->crl->version);
98 }
99
100 const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl) {
101 return crl->crl->lastUpdate;
102 }
103
104 const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl) {
105 return crl->crl->nextUpdate;
106 }
107
108 ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl) {
109 return crl->crl->lastUpdate;
110 }
111
112 ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl) {
113 return crl->crl->nextUpdate;
114 }
115
116 X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl) { return crl->crl->issuer; }
117
118 STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl) {
119 return crl->crl->revoked;
120 }
121
122 const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl) {
123 return crl->crl->extensions;
124 }
125
126 void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
127 const X509_ALGOR **palg) {
128 if (psig != NULL) {
129 *psig = crl->signature;
130 }
131 if (palg != NULL) {
132 *palg = crl->sig_alg;
133 }
134 }
135
136 int X509_CRL_get_signature_nid(const X509_CRL *crl) {
137 return OBJ_obj2nid(crl->sig_alg->algorithm);
138 }
139
140 const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *revoked) {
141 return revoked->revocationDate;
142 }
143
144 int X509_REVOKED_set_revocationDate(X509_REVOKED *revoked,
145 const ASN1_TIME *tm) {
146 ASN1_TIME *in;
147
148 if (revoked == NULL) {
149 return 0;
150 }
151 in = revoked->revocationDate;
152 if (in != tm) {
153 in = ASN1_STRING_dup(tm);
154 if (in != NULL) {
155 ASN1_TIME_free(revoked->revocationDate);
156 revoked->revocationDate = in;
157 }
158 }
159 return in != NULL;
160 }
161
162 const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(
163 const X509_REVOKED *revoked) {
164 return revoked->serialNumber;
165 }
166
167 int X509_REVOKED_set_serialNumber(X509_REVOKED *revoked,
168 const ASN1_INTEGER *serial) {
169 ASN1_INTEGER *in;
170
171 if (serial->type != V_ASN1_INTEGER && serial->type != V_ASN1_NEG_INTEGER) {
172 OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
173 return 0;
174 }
175
176 if (revoked == NULL) {
177 return 0;
178 }
179 in = revoked->serialNumber;
180 if (in != serial) {
181 in = ASN1_INTEGER_dup(serial);
182 if (in != NULL) {
183 ASN1_INTEGER_free(revoked->serialNumber);
184 revoked->serialNumber = in;
185 }
186 }
187 return in != NULL;
188 }
189
190 const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(
191 const X509_REVOKED *r) {
192 return r->extensions;
193 }
194
195 int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp) {
196 asn1_encoding_clear(&crl->crl->enc);
197 return i2d_X509_CRL_INFO(crl->crl, outp);
198 }
199
200 int i2d_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp) {
201 return i2d_X509_CRL_INFO(crl->crl, outp);
202 }
203
204 int X509_CRL_set1_signature_algo(X509_CRL *crl, const X509_ALGOR *algo) {
205 X509_ALGOR *copy1 = X509_ALGOR_dup(algo);
206 X509_ALGOR *copy2 = X509_ALGOR_dup(algo);
207 if (copy1 == NULL || copy2 == NULL) {
208 X509_ALGOR_free(copy1);
209 X509_ALGOR_free(copy2);
210 return 0;
211 }
212
213 X509_ALGOR_free(crl->sig_alg);
214 crl->sig_alg = copy1;
215 X509_ALGOR_free(crl->crl->sig_alg);
216 crl->crl->sig_alg = copy2;
217 return 1;
218 }
219
220 int X509_CRL_set1_signature_value(X509_CRL *crl, const uint8_t *sig,
221 size_t sig_len) {
222 if (!ASN1_STRING_set(crl->signature, sig, sig_len)) {
223 return 0;
224 }
225 crl->signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
226 crl->signature->flags |= ASN1_STRING_FLAG_BITS_LEFT;
227 return 1;
228 }