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