xref: /aosp_15_r20/external/boringssl/src/crypto/x509/x509_ext.c (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1 /* Copyright (C) 1995-1998 Eric Young ([email protected])
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young ([email protected]).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to.  The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson ([email protected]).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  *    must display the following acknowledgement:
32  *    "This product includes cryptographic software written by
33  *     Eric Young ([email protected])"
34  *    The word 'cryptographic' can be left out if the rouines from the library
35  *    being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  *    the apps directory (application code) you must include an acknowledgement:
38  *    "This product includes software written by Tim Hudson ([email protected])"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed.  i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.] */
56 
57 #include <openssl/asn1.h>
58 #include <openssl/evp.h>
59 #include <openssl/obj.h>
60 #include <openssl/stack.h>
61 #include <openssl/x509.h>
62 
63 #include "internal.h"
64 
X509_CRL_get_ext_count(const X509_CRL * x)65 int X509_CRL_get_ext_count(const X509_CRL *x) {
66   return (X509v3_get_ext_count(x->crl->extensions));
67 }
68 
X509_CRL_get_ext_by_NID(const X509_CRL * x,int nid,int lastpos)69 int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid, int lastpos) {
70   return (X509v3_get_ext_by_NID(x->crl->extensions, nid, lastpos));
71 }
72 
X509_CRL_get_ext_by_OBJ(const X509_CRL * x,const ASN1_OBJECT * obj,int lastpos)73 int X509_CRL_get_ext_by_OBJ(const X509_CRL *x, const ASN1_OBJECT *obj,
74                             int lastpos) {
75   return (X509v3_get_ext_by_OBJ(x->crl->extensions, obj, lastpos));
76 }
77 
X509_CRL_get_ext_by_critical(const X509_CRL * x,int crit,int lastpos)78 int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit, int lastpos) {
79   return (X509v3_get_ext_by_critical(x->crl->extensions, crit, lastpos));
80 }
81 
X509_CRL_get_ext(const X509_CRL * x,int loc)82 X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc) {
83   return (X509v3_get_ext(x->crl->extensions, loc));
84 }
85 
X509_CRL_delete_ext(X509_CRL * x,int loc)86 X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc) {
87   return (X509v3_delete_ext(x->crl->extensions, loc));
88 }
89 
X509_CRL_get_ext_d2i(const X509_CRL * crl,int nid,int * out_critical,int * out_idx)90 void *X509_CRL_get_ext_d2i(const X509_CRL *crl, int nid, int *out_critical,
91                            int *out_idx) {
92   return X509V3_get_d2i(crl->crl->extensions, nid, out_critical, out_idx);
93 }
94 
X509_CRL_add1_ext_i2d(X509_CRL * x,int nid,void * value,int crit,unsigned long flags)95 int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit,
96                           unsigned long flags) {
97   return X509V3_add1_i2d(&x->crl->extensions, nid, value, crit, flags);
98 }
99 
X509_CRL_add_ext(X509_CRL * x,const X509_EXTENSION * ex,int loc)100 int X509_CRL_add_ext(X509_CRL *x, const X509_EXTENSION *ex, int loc) {
101   return (X509v3_add_ext(&(x->crl->extensions), ex, loc) != NULL);
102 }
103 
X509_get_ext_count(const X509 * x)104 int X509_get_ext_count(const X509 *x) {
105   return (X509v3_get_ext_count(x->cert_info->extensions));
106 }
107 
X509_get_ext_by_NID(const X509 * x,int nid,int lastpos)108 int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos) {
109   return (X509v3_get_ext_by_NID(x->cert_info->extensions, nid, lastpos));
110 }
111 
X509_get_ext_by_OBJ(const X509 * x,const ASN1_OBJECT * obj,int lastpos)112 int X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj, int lastpos) {
113   return (X509v3_get_ext_by_OBJ(x->cert_info->extensions, obj, lastpos));
114 }
115 
X509_get_ext_by_critical(const X509 * x,int crit,int lastpos)116 int X509_get_ext_by_critical(const X509 *x, int crit, int lastpos) {
117   return (X509v3_get_ext_by_critical(x->cert_info->extensions, crit, lastpos));
118 }
119 
X509_get_ext(const X509 * x,int loc)120 X509_EXTENSION *X509_get_ext(const X509 *x, int loc) {
121   return (X509v3_get_ext(x->cert_info->extensions, loc));
122 }
123 
X509_delete_ext(X509 * x,int loc)124 X509_EXTENSION *X509_delete_ext(X509 *x, int loc) {
125   return (X509v3_delete_ext(x->cert_info->extensions, loc));
126 }
127 
X509_add_ext(X509 * x,const X509_EXTENSION * ex,int loc)128 int X509_add_ext(X509 *x, const X509_EXTENSION *ex, int loc) {
129   return (X509v3_add_ext(&(x->cert_info->extensions), ex, loc) != NULL);
130 }
131 
X509_get_ext_d2i(const X509 * x509,int nid,int * out_critical,int * out_idx)132 void *X509_get_ext_d2i(const X509 *x509, int nid, int *out_critical,
133                        int *out_idx) {
134   return X509V3_get_d2i(x509->cert_info->extensions, nid, out_critical,
135                         out_idx);
136 }
137 
X509_add1_ext_i2d(X509 * x,int nid,void * value,int crit,unsigned long flags)138 int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit,
139                       unsigned long flags) {
140   return X509V3_add1_i2d(&x->cert_info->extensions, nid, value, crit, flags);
141 }
142 
X509_REVOKED_get_ext_count(const X509_REVOKED * x)143 int X509_REVOKED_get_ext_count(const X509_REVOKED *x) {
144   return (X509v3_get_ext_count(x->extensions));
145 }
146 
X509_REVOKED_get_ext_by_NID(const X509_REVOKED * x,int nid,int lastpos)147 int X509_REVOKED_get_ext_by_NID(const X509_REVOKED *x, int nid, int lastpos) {
148   return (X509v3_get_ext_by_NID(x->extensions, nid, lastpos));
149 }
150 
X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED * x,const ASN1_OBJECT * obj,int lastpos)151 int X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED *x, const ASN1_OBJECT *obj,
152                                 int lastpos) {
153   return (X509v3_get_ext_by_OBJ(x->extensions, obj, lastpos));
154 }
155 
X509_REVOKED_get_ext_by_critical(const X509_REVOKED * x,int crit,int lastpos)156 int X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x, int crit,
157                                      int lastpos) {
158   return (X509v3_get_ext_by_critical(x->extensions, crit, lastpos));
159 }
160 
X509_REVOKED_get_ext(const X509_REVOKED * x,int loc)161 X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc) {
162   return (X509v3_get_ext(x->extensions, loc));
163 }
164 
X509_REVOKED_delete_ext(X509_REVOKED * x,int loc)165 X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc) {
166   return (X509v3_delete_ext(x->extensions, loc));
167 }
168 
X509_REVOKED_add_ext(X509_REVOKED * x,const X509_EXTENSION * ex,int loc)169 int X509_REVOKED_add_ext(X509_REVOKED *x, const X509_EXTENSION *ex, int loc) {
170   return (X509v3_add_ext(&(x->extensions), ex, loc) != NULL);
171 }
172 
X509_REVOKED_get_ext_d2i(const X509_REVOKED * revoked,int nid,int * out_critical,int * out_idx)173 void *X509_REVOKED_get_ext_d2i(const X509_REVOKED *revoked, int nid,
174                                int *out_critical, int *out_idx) {
175   return X509V3_get_d2i(revoked->extensions, nid, out_critical, out_idx);
176 }
177 
X509_REVOKED_add1_ext_i2d(X509_REVOKED * x,int nid,void * value,int crit,unsigned long flags)178 int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit,
179                               unsigned long flags) {
180   return X509V3_add1_i2d(&x->extensions, nid, value, crit, flags);
181 }
182