/src/openssl/crypto/x509/x509cset.c
Line | Count | Source (jump to first uncovered line) |
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 | 0 | { |
21 | 0 | if (x == NULL) |
22 | 0 | return 0; |
23 | 0 | if (x->crl.version == NULL) { |
24 | 0 | if ((x->crl.version = ASN1_INTEGER_new()) == NULL) |
25 | 0 | return 0; |
26 | 0 | } |
27 | 0 | return ASN1_INTEGER_set(x->crl.version, version); |
28 | 0 | } |
29 | | |
30 | | int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name) |
31 | 0 | { |
32 | 0 | if (x == NULL) |
33 | 0 | return 0; |
34 | 0 | return X509_NAME_set(&x->crl.issuer, name); |
35 | 0 | } |
36 | | |
37 | | int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm) |
38 | 0 | { |
39 | 0 | if (x == NULL) |
40 | 0 | return 0; |
41 | 0 | return x509_set1_time(&x->crl.lastUpdate, tm); |
42 | 0 | } |
43 | | |
44 | | int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm) |
45 | 0 | { |
46 | 0 | if (x == NULL) |
47 | 0 | return 0; |
48 | 0 | return x509_set1_time(&x->crl.nextUpdate, tm); |
49 | 0 | } |
50 | | |
51 | | int X509_CRL_sort(X509_CRL *c) |
52 | 0 | { |
53 | 0 | int i; |
54 | 0 | X509_REVOKED *r; |
55 | | /* |
56 | | * sort the data so it will be written in serial number order |
57 | | */ |
58 | 0 | sk_X509_REVOKED_sort(c->crl.revoked); |
59 | 0 | for (i = 0; i < sk_X509_REVOKED_num(c->crl.revoked); i++) { |
60 | 0 | r = sk_X509_REVOKED_value(c->crl.revoked, i); |
61 | 0 | r->sequence = i; |
62 | 0 | } |
63 | 0 | c->crl.enc.modified = 1; |
64 | 0 | return 1; |
65 | 0 | } |
66 | | |
67 | | int X509_CRL_up_ref(X509_CRL *crl) |
68 | 0 | { |
69 | 0 | int i; |
70 | |
|
71 | 0 | if (CRYPTO_UP_REF(&crl->references, &i, crl->lock) <= 0) |
72 | 0 | return 0; |
73 | | |
74 | 0 | REF_PRINT_COUNT("X509_CRL", crl); |
75 | 0 | REF_ASSERT_ISNT(i < 2); |
76 | 0 | return ((i > 1) ? 1 : 0); |
77 | 0 | } |
78 | | |
79 | | long X509_CRL_get_version(const X509_CRL *crl) |
80 | 0 | { |
81 | 0 | return ASN1_INTEGER_get(crl->crl.version); |
82 | 0 | } |
83 | | |
84 | | const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl) |
85 | 0 | { |
86 | 0 | return crl->crl.lastUpdate; |
87 | 0 | } |
88 | | |
89 | | const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl) |
90 | 0 | { |
91 | 0 | return crl->crl.nextUpdate; |
92 | 0 | } |
93 | | |
94 | | #ifndef OPENSSL_NO_DEPRECATED_1_1_0 |
95 | | ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl) |
96 | 0 | { |
97 | 0 | return crl->crl.lastUpdate; |
98 | 0 | } |
99 | | |
100 | | ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl) |
101 | 0 | { |
102 | 0 | return crl->crl.nextUpdate; |
103 | 0 | } |
104 | | #endif |
105 | | |
106 | | X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl) |
107 | 0 | { |
108 | 0 | return crl->crl.issuer; |
109 | 0 | } |
110 | | |
111 | | const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl) |
112 | 0 | { |
113 | 0 | return crl->crl.extensions; |
114 | 0 | } |
115 | | |
116 | | STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl) |
117 | 0 | { |
118 | 0 | return crl->crl.revoked; |
119 | 0 | } |
120 | | |
121 | | void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, |
122 | | const X509_ALGOR **palg) |
123 | 0 | { |
124 | 0 | if (psig != NULL) |
125 | 0 | *psig = &crl->signature; |
126 | 0 | if (palg != NULL) |
127 | 0 | *palg = &crl->sig_alg; |
128 | 0 | } |
129 | | |
130 | | int X509_CRL_get_signature_nid(const X509_CRL *crl) |
131 | 0 | { |
132 | 0 | return OBJ_obj2nid(crl->sig_alg.algorithm); |
133 | 0 | } |
134 | | |
135 | | const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x) |
136 | 0 | { |
137 | 0 | return x->revocationDate; |
138 | 0 | } |
139 | | |
140 | | int X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm) |
141 | 0 | { |
142 | 0 | ASN1_TIME *in; |
143 | |
|
144 | 0 | if (x == NULL) |
145 | 0 | return 0; |
146 | 0 | in = x->revocationDate; |
147 | 0 | if (in != tm) { |
148 | 0 | in = ASN1_STRING_dup(tm); |
149 | 0 | if (in != NULL) { |
150 | 0 | ASN1_TIME_free(x->revocationDate); |
151 | 0 | x->revocationDate = in; |
152 | 0 | } |
153 | 0 | } |
154 | 0 | return (in != NULL); |
155 | 0 | } |
156 | | |
157 | | const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x) |
158 | 0 | { |
159 | 0 | return &x->serialNumber; |
160 | 0 | } |
161 | | |
162 | | int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial) |
163 | 0 | { |
164 | 0 | ASN1_INTEGER *in; |
165 | |
|
166 | 0 | if (x == NULL) |
167 | 0 | return 0; |
168 | 0 | in = &x->serialNumber; |
169 | 0 | if (in != serial) |
170 | 0 | return ASN1_STRING_copy(in, serial); |
171 | 0 | return 1; |
172 | 0 | } |
173 | | |
174 | | const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(const X509_REVOKED *r) |
175 | 0 | { |
176 | 0 | return r->extensions; |
177 | 0 | } |
178 | | |
179 | | int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **pp) |
180 | 0 | { |
181 | 0 | crl->crl.enc.modified = 1; |
182 | 0 | return i2d_X509_CRL_INFO(&crl->crl, pp); |
183 | 0 | } |