1 /*
2  * Copyright (C) 2014 Free Software Foundation, Inc.
3  *
4  * Author: Nikos Mavrogiannopoulos
5  *
6  * This file is part of GnuTLS.
7  *
8  * The GnuTLS is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program.  If not, see <https://www.gnu.org/licenses/>
20  *
21  */
22 
23 /* Prototypes for direct handling of extension data */
24 
25 #ifndef GNUTLS_X509_EXT_H
26 #define GNUTLS_X509_EXT_H
27 
28 #include <gnutls/gnutls.h>
29 #include <gnutls/x509.h>
30 
31 /* *INDENT-OFF* */
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 /* *INDENT-ON* */
36 
37 typedef struct gnutls_subject_alt_names_st *gnutls_subject_alt_names_t;
38 
39 int gnutls_subject_alt_names_init(gnutls_subject_alt_names_t *);
40 void gnutls_subject_alt_names_deinit(gnutls_subject_alt_names_t sans);
41 int gnutls_subject_alt_names_get(gnutls_subject_alt_names_t sans, unsigned int seq,
42 				 unsigned int *san_type, gnutls_datum_t * san,
43 				 gnutls_datum_t * othername_oid);
44 int gnutls_subject_alt_names_set(gnutls_subject_alt_names_t sans,
45 				 unsigned int san_type,
46 				 const gnutls_datum_t * san,
47 				 const char* othername_oid);
48 
49 
50 int gnutls_x509_ext_import_subject_alt_names(const gnutls_datum_t * ext,
51 					 gnutls_subject_alt_names_t,
52 					 unsigned int flags);
53 int gnutls_x509_ext_export_subject_alt_names(gnutls_subject_alt_names_t,
54 					  gnutls_datum_t * ext);
55 
56 /* They are exactly the same */
57 #define gnutls_x509_ext_import_issuer_alt_name gnutls_x509_ext_import_subject_alt_name
58 #define gnutls_x509_ext_export_issuer_alt_name gnutls_x509_ext_export_subject_alt_name
59 
60 typedef struct gnutls_x509_crl_dist_points_st *gnutls_x509_crl_dist_points_t;
61 
62 int gnutls_x509_crl_dist_points_init(gnutls_x509_crl_dist_points_t *);
63 void gnutls_x509_crl_dist_points_deinit(gnutls_x509_crl_dist_points_t);
64 int gnutls_x509_crl_dist_points_get(gnutls_x509_crl_dist_points_t, unsigned int seq,
65 				  unsigned int *type,
66 				  gnutls_datum_t *dist, unsigned int *reason_flags);
67 int gnutls_x509_crl_dist_points_set(gnutls_x509_crl_dist_points_t,
68 				 gnutls_x509_subject_alt_name_t type,
69 				 const gnutls_datum_t *dist, unsigned int reason_flags);
70 
71 int gnutls_x509_ext_import_crl_dist_points(const gnutls_datum_t * ext,
72 					gnutls_x509_crl_dist_points_t dp,
73 					unsigned int flags);
74 int gnutls_x509_ext_export_crl_dist_points(gnutls_x509_crl_dist_points_t dp,
75 					gnutls_datum_t * ext);
76 
77 int gnutls_x509_ext_import_name_constraints(const gnutls_datum_t * ext,
78 					 gnutls_x509_name_constraints_t nc,
79 					 unsigned int flags);
80 int gnutls_x509_ext_export_name_constraints(gnutls_x509_name_constraints_t nc,
81 					 gnutls_datum_t * ext);
82 
83 typedef struct gnutls_x509_aia_st *gnutls_x509_aia_t;
84 
85 int gnutls_x509_aia_init(gnutls_x509_aia_t *);
86 void gnutls_x509_aia_deinit(gnutls_x509_aia_t);
87 int gnutls_x509_aia_get(gnutls_x509_aia_t aia, unsigned int seq,
88 			gnutls_datum_t *oid,
89 			unsigned *san_type,
90 			gnutls_datum_t *san);
91 int gnutls_x509_aia_set(gnutls_x509_aia_t aia,
92 			const char *oid,
93 			unsigned san_type,
94 			const gnutls_datum_t * san);
95 
96 int gnutls_x509_ext_import_aia(const gnutls_datum_t * ext,
97 				gnutls_x509_aia_t,
98 				unsigned int flags);
99 int gnutls_x509_ext_export_aia(gnutls_x509_aia_t aia,
100 					      gnutls_datum_t * ext);
101 
102 int gnutls_x509_ext_import_subject_key_id(const gnutls_datum_t * ext,
103 				       gnutls_datum_t * id);
104 int gnutls_x509_ext_export_subject_key_id(const gnutls_datum_t * id,
105 				       gnutls_datum_t * ext);
106 
107 typedef struct gnutls_x509_aki_st *gnutls_x509_aki_t;
108 
109 int gnutls_x509_ext_export_authority_key_id(gnutls_x509_aki_t,
110 					 gnutls_datum_t * ext);
111 int gnutls_x509_ext_import_authority_key_id(const gnutls_datum_t * ext,
112 					 gnutls_x509_aki_t,
113 					 unsigned int flags);
114 
115 int gnutls_x509_othername_to_virtual(const char *oid,
116 				     const gnutls_datum_t *othername,
117 				     unsigned int *virt_type,
118 				     gnutls_datum_t *virt);
119 
120 int gnutls_x509_aki_init(gnutls_x509_aki_t *);
121 int gnutls_x509_aki_get_id(gnutls_x509_aki_t, gnutls_datum_t *id);
122 int gnutls_x509_aki_get_cert_issuer(gnutls_x509_aki_t aki, unsigned int seq,
123 				 unsigned int *san_type, gnutls_datum_t * san,
124 				 gnutls_datum_t *othername_oid,
125 				 gnutls_datum_t *serial);
126 int gnutls_x509_aki_set_id(gnutls_x509_aki_t aki, const gnutls_datum_t *id);
127 int gnutls_x509_aki_set_cert_issuer(gnutls_x509_aki_t aki,
128 				 unsigned int san_type,
129 				 const gnutls_datum_t * san,
130 				 const char *othername_oid,
131 				 const gnutls_datum_t * serial);
132 void gnutls_x509_aki_deinit(gnutls_x509_aki_t);
133 
134 int gnutls_x509_ext_import_private_key_usage_period(const gnutls_datum_t * ext,
135 						 time_t * activation,
136 						 time_t * expiration);
137 int gnutls_x509_ext_export_private_key_usage_period(time_t activation,
138 						 time_t expiration,
139 						 gnutls_datum_t * ext);
140 
141 int gnutls_x509_ext_import_basic_constraints(const gnutls_datum_t * ext,
142 					  unsigned int *ca, int *pathlen);
143 int gnutls_x509_ext_export_basic_constraints(unsigned int ca, int pathlen,
144 					  gnutls_datum_t * ext);
145 
146 typedef struct gnutls_x509_key_purposes_st *gnutls_x509_key_purposes_t;
147 
148 int gnutls_x509_key_purpose_init(gnutls_x509_key_purposes_t *p);
149 void gnutls_x509_key_purpose_deinit(gnutls_x509_key_purposes_t p);
150 int gnutls_x509_key_purpose_set(gnutls_x509_key_purposes_t p, const char *oid);
151 int gnutls_x509_key_purpose_get(gnutls_x509_key_purposes_t p, unsigned idx, gnutls_datum_t *oid);
152 
153 int gnutls_x509_ext_import_key_purposes(const gnutls_datum_t * ext,
154 				     gnutls_x509_key_purposes_t,
155 				     unsigned int flags);
156 int gnutls_x509_ext_export_key_purposes(gnutls_x509_key_purposes_t,
157 				     gnutls_datum_t * ext);
158 
159 
160 int gnutls_x509_ext_import_key_usage(const gnutls_datum_t * ext,
161 				  unsigned int *key_usage);
162 int gnutls_x509_ext_export_key_usage(unsigned int key_usage,
163 				  gnutls_datum_t * ext);
164 
165 int gnutls_x509_ext_import_inhibit_anypolicy(const gnutls_datum_t * ext,
166 				  unsigned int *skipcerts);
167 int gnutls_x509_ext_export_inhibit_anypolicy(unsigned int skipcerts,
168 				  gnutls_datum_t * ext);
169 
170 int gnutls_x509_ext_import_proxy(const gnutls_datum_t * ext, int *pathlen,
171 			      char **policyLanguage, char **policy,
172 			      size_t * sizeof_policy);
173 int gnutls_x509_ext_export_proxy(int pathLenConstraint, const char *policyLanguage,
174 			      const char *policy, size_t sizeof_policy,
175 			      gnutls_datum_t * ext);
176 
177 typedef struct gnutls_x509_policies_st *gnutls_x509_policies_t;
178 
179 int gnutls_x509_policies_init(gnutls_x509_policies_t *);
180 void gnutls_x509_policies_deinit(gnutls_x509_policies_t);
181 
182 int gnutls_x509_policies_get(gnutls_x509_policies_t policies, unsigned int seq,
183 				 struct gnutls_x509_policy_st *policy);
184 int gnutls_x509_policies_set(gnutls_x509_policies_t policies,
185 				 const struct gnutls_x509_policy_st *policy);
186 
187 int gnutls_x509_ext_import_policies(const gnutls_datum_t * ext, gnutls_x509_policies_t
188 				 policies,
189 				 unsigned int flags);
190 int gnutls_x509_ext_export_policies(gnutls_x509_policies_t policies,
191 				 gnutls_datum_t * ext);
192 
193 int gnutls_x509_ext_import_tlsfeatures(const gnutls_datum_t * ext,
194 									   gnutls_x509_tlsfeatures_t,
195 									   unsigned int flags);
196 
197 int gnutls_x509_ext_export_tlsfeatures(gnutls_x509_tlsfeatures_t f,
198 					  gnutls_datum_t * ext);
199 
200 int gnutls_x509_tlsfeatures_add(gnutls_x509_tlsfeatures_t f, unsigned int feature);
201 
202 /* *INDENT-OFF* */
203 #ifdef __cplusplus
204 }
205 #endif
206 /* *INDENT-ON* */
207 #endif				/* GNUTLS_X509_H */
208