1 | /* |
2 | * Copyright 2001-2017 The OpenSSL Project Authors. All Rights Reserved. |
3 | * |
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 |
8 | */ |
9 | |
10 | #include <stdio.h> |
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" |
18 | |
19 | int X509_CRL_set_version(X509_CRL *x, long version) |
20 | { |
21 | if (x == NULL) |
22 | return 0; |
23 | if (x->crl.version == NULL) { |
24 | if ((x->crl.version = ASN1_INTEGER_new()) == NULL) |
25 | return 0; |
26 | } |
27 | return ASN1_INTEGER_set(x->crl.version, version); |
28 | } |
29 | |
30 | int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name) |
31 | { |
32 | if (x == NULL) |
33 | return 0; |
34 | return X509_NAME_set(&x->crl.issuer, name); |
35 | } |
36 | |
37 | int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm) |
38 | { |
39 | if (x == NULL) |
40 | return 0; |
41 | return x509_set1_time(&x->crl.lastUpdate, tm); |
42 | } |
43 | |
44 | int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm) |
45 | { |
46 | if (x == NULL) |
47 | return 0; |
48 | return x509_set1_time(&x->crl.nextUpdate, tm); |
49 | } |
50 | |
51 | int X509_CRL_sort(X509_CRL *c) |
52 | { |
53 | int i; |
54 | X509_REVOKED *r; |
55 | /* |
56 | * sort the data so it will be written in serial number order |
57 | */ |
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); |
61 | r->sequence = i; |
62 | } |
63 | c->crl.enc.modified = 1; |
64 | return 1; |
65 | } |
66 | |
67 | int X509_CRL_up_ref(X509_CRL *crl) |
68 | { |
69 | int i; |
70 | |
71 | if (CRYPTO_UP_REF(&crl->references, &i, crl->lock) <= 0) |
72 | return 0; |
73 | |
74 | REF_PRINT_COUNT("X509_CRL" , crl); |
75 | REF_ASSERT_ISNT(i < 2); |
76 | return ((i > 1) ? 1 : 0); |
77 | } |
78 | |
79 | long X509_CRL_get_version(const X509_CRL *crl) |
80 | { |
81 | return ASN1_INTEGER_get(crl->crl.version); |
82 | } |
83 | |
84 | const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl) |
85 | { |
86 | return crl->crl.lastUpdate; |
87 | } |
88 | |
89 | const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl) |
90 | { |
91 | return crl->crl.nextUpdate; |
92 | } |
93 | |
94 | #ifndef OPENSSL_NO_DEPRECATED_1_1_0 |
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 | |
106 | X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl) |
107 | { |
108 | return crl->crl.issuer; |
109 | } |
110 | |
111 | const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl) |
112 | { |
113 | return crl->crl.extensions; |
114 | } |
115 | |
116 | STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl) |
117 | { |
118 | return crl->crl.revoked; |
119 | } |
120 | |
121 | void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, |
122 | const X509_ALGOR **palg) |
123 | { |
124 | if (psig != NULL) |
125 | *psig = &crl->signature; |
126 | if (palg != NULL) |
127 | *palg = &crl->sig_alg; |
128 | } |
129 | |
130 | int X509_CRL_get_signature_nid(const X509_CRL *crl) |
131 | { |
132 | return OBJ_obj2nid(crl->sig_alg.algorithm); |
133 | } |
134 | |
135 | const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x) |
136 | { |
137 | return x->revocationDate; |
138 | } |
139 | |
140 | int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm) |
141 | { |
142 | ASN1_TIME *in; |
143 | |
144 | if (x == NULL) |
145 | return 0; |
146 | in = x->revocationDate; |
147 | if (in != tm) { |
148 | in = ASN1_STRING_dup(tm); |
149 | if (in != NULL) { |
150 | ASN1_TIME_free(x->revocationDate); |
151 | x->revocationDate = in; |
152 | } |
153 | } |
154 | return (in != NULL); |
155 | } |
156 | |
157 | const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x) |
158 | { |
159 | return &x->serialNumber; |
160 | } |
161 | |
162 | int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial) |
163 | { |
164 | ASN1_INTEGER *in; |
165 | |
166 | if (x == NULL) |
167 | return 0; |
168 | in = &x->serialNumber; |
169 | if (in != serial) |
170 | return ASN1_STRING_copy(in, serial); |
171 | return 1; |
172 | } |
173 | |
174 | const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(const X509_REVOKED *r) |
175 | { |
176 | return r->extensions; |
177 | } |
178 | |
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 | } |
184 | |