1 use libc::*;
2 
3 use *;
4 
5 pub const X509_FILETYPE_PEM: c_int = 1;
6 pub const X509_FILETYPE_ASN1: c_int = 2;
7 pub const X509_FILETYPE_DEFAULT: c_int = 3;
8 
9 #[repr(C)]
10 pub struct X509_VAL {
11     pub notBefore: *mut ASN1_TIME,
12     pub notAfter: *mut ASN1_TIME,
13 }
14 
15 pub enum X509_NAME_ENTRY {}
16 
17 stack!(stack_st_X509_NAME);
18 
19 pub enum X509_EXTENSION {}
20 
21 stack!(stack_st_X509_EXTENSION);
22 
23 stack!(stack_st_X509_ATTRIBUTE);
24 
25 cfg_if! {
26     if #[cfg(ossl110)] {
27         pub enum X509_REQ_INFO {}
28     } else {
29         #[repr(C)]
30         pub struct X509_REQ_INFO {
31             pub enc: ASN1_ENCODING,
32             pub version: *mut ::ASN1_INTEGER,
33             pub subject: *mut ::X509_NAME,
34             pubkey: *mut c_void,
35             pub attributes: *mut stack_st_X509_ATTRIBUTE,
36         }
37     }
38 }
39 
40 cfg_if! {
41     if #[cfg(ossl110)] {
42         pub enum X509_REQ {}
43     } else {
44         #[repr(C)]
45         pub struct X509_REQ {
46             pub req_info: *mut X509_REQ_INFO,
47             sig_alg: *mut c_void,
48             signature: *mut c_void,
49             references: c_int,
50         }
51     }
52 }
53 
54 cfg_if! {
55     if #[cfg(ossl110)] {
56         pub enum X509_CINF {}
57     } else {
58         #[repr(C)]
59         pub struct X509_CINF {
60             version: *mut c_void,
61             serialNumber: *mut c_void,
62             signature: *mut c_void,
63             issuer: *mut c_void,
64             pub validity: *mut X509_VAL,
65             subject: *mut c_void,
66             key: *mut c_void,
67             issuerUID: *mut c_void,
68             subjectUID: *mut c_void,
69             pub extensions: *mut stack_st_X509_EXTENSION,
70             enc: ASN1_ENCODING,
71         }
72     }
73 }
74 
75 stack!(stack_st_X509);
76 
77 cfg_if! {
78     if #[cfg(not(ossl110))] {
79         pub const X509_LU_FAIL: c_int = 0;
80         pub const X509_LU_X509: c_int = 1;
81         pub const X509_LU_CRL: c_int = 2;
82     }
83 }
84 
85 cfg_if! {
86     if #[cfg(any(ossl110, libressl270))] {
87         pub enum X509_OBJECT {}
88     } else {
89         #[repr(C)]
90         pub struct X509_OBJECT {
91             pub type_: c_int,
92             pub data: X509_OBJECT_data,
93         }
94         #[repr(C)]
95         pub union X509_OBJECT_data {
96             pub ptr: *mut c_char,
97             pub x509: *mut X509,
98             pub crl: *mut X509_CRL,
99             pub pkey: *mut EVP_PKEY,
100         }
101     }
102 }
103 
104 stack!(stack_st_X509_OBJECT);
105 
106 pub enum X509_LOOKUP {}
107 
108 stack!(stack_st_X509_LOOKUP);
109 
110 extern "C" {
X509_verify_cert_error_string(n: c_long) -> *const c_char111     pub fn X509_verify_cert_error_string(n: c_long) -> *const c_char;
112 
X509_sign(x: *mut X509, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int113     pub fn X509_sign(x: *mut X509, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int;
114 
X509_digest( x: *const X509, digest: *const EVP_MD, buf: *mut c_uchar, len: *mut c_uint, ) -> c_int115     pub fn X509_digest(
116         x: *const X509,
117         digest: *const EVP_MD,
118         buf: *mut c_uchar,
119         len: *mut c_uint,
120     ) -> c_int;
121 
X509_REQ_sign(x: *mut X509_REQ, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int122     pub fn X509_REQ_sign(x: *mut X509_REQ, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int;
123 
i2d_X509_bio(b: *mut BIO, x: *mut X509) -> c_int124     pub fn i2d_X509_bio(b: *mut BIO, x: *mut X509) -> c_int;
i2d_X509_REQ_bio(b: *mut BIO, x: *mut X509_REQ) -> c_int125     pub fn i2d_X509_REQ_bio(b: *mut BIO, x: *mut X509_REQ) -> c_int;
i2d_PrivateKey_bio(b: *mut BIO, x: *mut EVP_PKEY) -> c_int126     pub fn i2d_PrivateKey_bio(b: *mut BIO, x: *mut EVP_PKEY) -> c_int;
i2d_PUBKEY_bio(b: *mut BIO, x: *mut EVP_PKEY) -> c_int127     pub fn i2d_PUBKEY_bio(b: *mut BIO, x: *mut EVP_PKEY) -> c_int;
128 
i2d_PUBKEY(k: *mut EVP_PKEY, buf: *mut *mut u8) -> c_int129     pub fn i2d_PUBKEY(k: *mut EVP_PKEY, buf: *mut *mut u8) -> c_int;
d2i_PUBKEY(k: *mut *mut EVP_PKEY, buf: *mut *const u8, len: c_long) -> *mut EVP_PKEY130     pub fn d2i_PUBKEY(k: *mut *mut EVP_PKEY, buf: *mut *const u8, len: c_long) -> *mut EVP_PKEY;
d2i_RSA_PUBKEY(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA131     pub fn d2i_RSA_PUBKEY(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA;
i2d_RSA_PUBKEY(k: *mut RSA, buf: *mut *mut u8) -> c_int132     pub fn i2d_RSA_PUBKEY(k: *mut RSA, buf: *mut *mut u8) -> c_int;
d2i_DSA_PUBKEY(k: *mut *mut DSA, pp: *mut *const c_uchar, length: c_long) -> *mut DSA133     pub fn d2i_DSA_PUBKEY(k: *mut *mut DSA, pp: *mut *const c_uchar, length: c_long) -> *mut DSA;
i2d_DSA_PUBKEY(a: *mut DSA, pp: *mut *mut c_uchar) -> c_int134     pub fn i2d_DSA_PUBKEY(a: *mut DSA, pp: *mut *mut c_uchar) -> c_int;
d2i_EC_PUBKEY( a: *mut *mut EC_KEY, pp: *mut *const c_uchar, length: c_long, ) -> *mut EC_KEY135     pub fn d2i_EC_PUBKEY(
136         a: *mut *mut EC_KEY,
137         pp: *mut *const c_uchar,
138         length: c_long,
139     ) -> *mut EC_KEY;
i2d_EC_PUBKEY(a: *mut EC_KEY, pp: *mut *mut c_uchar) -> c_int140     pub fn i2d_EC_PUBKEY(a: *mut EC_KEY, pp: *mut *mut c_uchar) -> c_int;
i2d_PrivateKey(k: *mut EVP_PKEY, buf: *mut *mut u8) -> c_int141     pub fn i2d_PrivateKey(k: *mut EVP_PKEY, buf: *mut *mut u8) -> c_int;
142 
d2i_ECPrivateKey( k: *mut *mut EC_KEY, pp: *mut *const c_uchar, length: c_long, ) -> *mut EC_KEY143     pub fn d2i_ECPrivateKey(
144         k: *mut *mut EC_KEY,
145         pp: *mut *const c_uchar,
146         length: c_long,
147     ) -> *mut EC_KEY;
i2d_ECPrivateKey(ec_key: *mut EC_KEY, pp: *mut *mut c_uchar) -> c_int148     pub fn i2d_ECPrivateKey(ec_key: *mut EC_KEY, pp: *mut *mut c_uchar) -> c_int;
149 }
150 
151 cfg_if! {
152     if #[cfg(ossl110)] {
153         extern "C" {
154             pub fn X509_ALGOR_get0(
155                 paobj: *mut *const ASN1_OBJECT,
156                 pptype: *mut c_int,
157                 ppval: *mut *const c_void,
158                 alg: *const X509_ALGOR,
159             );
160         }
161     } else if #[cfg(ossl102)] {
162         extern "C" {
163             pub fn X509_ALGOR_get0(
164                 paobj: *mut *mut ASN1_OBJECT,
165                 pptype: *mut c_int,
166                 ppval: *mut *mut c_void,
167                 alg: *mut X509_ALGOR,
168             );
169         }
170     }
171 }
172 
173 extern "C" {
X509_gmtime_adj(time: *mut ASN1_TIME, adj: c_long) -> *mut ASN1_TIME174     pub fn X509_gmtime_adj(time: *mut ASN1_TIME, adj: c_long) -> *mut ASN1_TIME;
175 
X509_to_X509_REQ(x: *mut X509, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> *mut X509_REQ176     pub fn X509_to_X509_REQ(x: *mut X509, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> *mut X509_REQ;
177 
X509_ALGOR_free(x: *mut X509_ALGOR)178     pub fn X509_ALGOR_free(x: *mut X509_ALGOR);
179 
X509_REQ_new() -> *mut X509_REQ180     pub fn X509_REQ_new() -> *mut X509_REQ;
X509_REQ_free(x: *mut X509_REQ)181     pub fn X509_REQ_free(x: *mut X509_REQ);
d2i_X509_REQ( a: *mut *mut X509_REQ, pp: *mut *const c_uchar, length: c_long, ) -> *mut X509_REQ182     pub fn d2i_X509_REQ(
183         a: *mut *mut X509_REQ,
184         pp: *mut *const c_uchar,
185         length: c_long,
186     ) -> *mut X509_REQ;
i2d_X509_REQ(x: *mut X509_REQ, buf: *mut *mut u8) -> c_int187     pub fn i2d_X509_REQ(x: *mut X509_REQ, buf: *mut *mut u8) -> c_int;
188 }
189 
190 cfg_if! {
191     if #[cfg(any(ossl110, libressl273))] {
192         extern "C" {
193             pub fn X509_get0_signature(
194                 psig: *mut *const ASN1_BIT_STRING,
195                 palg: *mut *const X509_ALGOR,
196                 x: *const X509,
197             );
198         }
199     } else if #[cfg(ossl102)] {
200         extern "C" {
201             pub fn X509_get0_signature(
202                 psig: *mut *mut ASN1_BIT_STRING,
203                 palg: *mut *mut X509_ALGOR,
204                 x: *const X509,
205             );
206         }
207     }
208 }
209 extern "C" {
210     #[cfg(ossl102)]
X509_get_signature_nid(x: *const X509) -> c_int211     pub fn X509_get_signature_nid(x: *const X509) -> c_int;
212 
X509_EXTENSION_free(ext: *mut X509_EXTENSION)213     pub fn X509_EXTENSION_free(ext: *mut X509_EXTENSION);
214 
X509_NAME_ENTRY_free(x: *mut X509_NAME_ENTRY)215     pub fn X509_NAME_ENTRY_free(x: *mut X509_NAME_ENTRY);
216 
X509_NAME_new() -> *mut X509_NAME217     pub fn X509_NAME_new() -> *mut X509_NAME;
X509_NAME_free(x: *mut X509_NAME)218     pub fn X509_NAME_free(x: *mut X509_NAME);
219 
X509_new() -> *mut X509220     pub fn X509_new() -> *mut X509;
X509_free(x: *mut X509)221     pub fn X509_free(x: *mut X509);
i2d_X509(x: *mut X509, buf: *mut *mut u8) -> c_int222     pub fn i2d_X509(x: *mut X509, buf: *mut *mut u8) -> c_int;
d2i_X509(a: *mut *mut X509, pp: *mut *const c_uchar, length: c_long) -> *mut X509223     pub fn d2i_X509(a: *mut *mut X509, pp: *mut *const c_uchar, length: c_long) -> *mut X509;
224 
X509_get_pubkey(x: *mut X509) -> *mut EVP_PKEY225     pub fn X509_get_pubkey(x: *mut X509) -> *mut EVP_PKEY;
226 
X509_set_version(x: *mut X509, version: c_long) -> c_int227     pub fn X509_set_version(x: *mut X509, version: c_long) -> c_int;
X509_set_serialNumber(x: *mut X509, sn: *mut ASN1_INTEGER) -> c_int228     pub fn X509_set_serialNumber(x: *mut X509, sn: *mut ASN1_INTEGER) -> c_int;
X509_get_serialNumber(x: *mut X509) -> *mut ASN1_INTEGER229     pub fn X509_get_serialNumber(x: *mut X509) -> *mut ASN1_INTEGER;
X509_set_issuer_name(x: *mut X509, name: *mut X509_NAME) -> c_int230     pub fn X509_set_issuer_name(x: *mut X509, name: *mut X509_NAME) -> c_int;
231 }
232 cfg_if! {
233     if #[cfg(any(ossl110, libressl280))] {
234         extern "C" {
235             pub fn X509_get_issuer_name(x: *const ::X509) -> *mut ::X509_NAME;
236         }
237     } else {
238         extern "C" {
239             pub fn X509_get_issuer_name(x: *mut ::X509) -> *mut ::X509_NAME;
240         }
241     }
242 }
243 extern "C" {
X509_set_subject_name(x: *mut X509, name: *mut X509_NAME) -> c_int244     pub fn X509_set_subject_name(x: *mut X509, name: *mut X509_NAME) -> c_int;
245 }
246 cfg_if! {
247     if #[cfg(any(ossl110, libressl280))] {
248         extern "C" {
249             pub fn X509_get_subject_name(x: *const ::X509) -> *mut ::X509_NAME;
250         }
251     } else {
252         extern "C" {
253             pub fn X509_get_subject_name(x: *mut ::X509) -> *mut ::X509_NAME;
254         }
255     }
256 }
257 cfg_if! {
258     if #[cfg(ossl110)] {
259         extern "C" {
260             pub fn X509_set1_notBefore(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int;
261             pub fn X509_set1_notAfter(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int;
262         }
263     } else {
264         extern "C" {
265             pub fn X509_set_notBefore(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int;
266             pub fn X509_set_notAfter(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int;
267         }
268     }
269 }
270 extern "C" {
271     #[cfg(ossl110)]
X509_REQ_get_version(req: *const X509_REQ) -> c_long272     pub fn X509_REQ_get_version(req: *const X509_REQ) -> c_long;
X509_REQ_set_version(req: *mut X509_REQ, version: c_long) -> c_int273     pub fn X509_REQ_set_version(req: *mut X509_REQ, version: c_long) -> c_int;
274     #[cfg(ossl110)]
X509_REQ_get_subject_name(req: *const X509_REQ) -> *mut X509_NAME275     pub fn X509_REQ_get_subject_name(req: *const X509_REQ) -> *mut X509_NAME;
X509_REQ_set_subject_name(req: *mut X509_REQ, name: *mut X509_NAME) -> c_int276     pub fn X509_REQ_set_subject_name(req: *mut X509_REQ, name: *mut X509_NAME) -> c_int;
X509_REQ_set_pubkey(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int277     pub fn X509_REQ_set_pubkey(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int;
X509_REQ_get_pubkey(req: *mut X509_REQ) -> *mut EVP_PKEY278     pub fn X509_REQ_get_pubkey(req: *mut X509_REQ) -> *mut EVP_PKEY;
X509_REQ_get_extensions(req: *mut X509_REQ) -> *mut stack_st_X509_EXTENSION279     pub fn X509_REQ_get_extensions(req: *mut X509_REQ) -> *mut stack_st_X509_EXTENSION;
X509_REQ_add_extensions(req: *mut X509_REQ, exts: *mut stack_st_X509_EXTENSION) -> c_int280     pub fn X509_REQ_add_extensions(req: *mut X509_REQ, exts: *mut stack_st_X509_EXTENSION)
281         -> c_int;
X509_set_pubkey(x: *mut X509, pkey: *mut EVP_PKEY) -> c_int282     pub fn X509_set_pubkey(x: *mut X509, pkey: *mut EVP_PKEY) -> c_int;
X509_REQ_verify(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int283     pub fn X509_REQ_verify(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int;
284     #[cfg(any(ossl110, libressl273))]
X509_getm_notBefore(x: *const X509) -> *mut ASN1_TIME285     pub fn X509_getm_notBefore(x: *const X509) -> *mut ASN1_TIME;
286     #[cfg(any(ossl110, libressl273))]
X509_getm_notAfter(x: *const X509) -> *mut ASN1_TIME287     pub fn X509_getm_notAfter(x: *const X509) -> *mut ASN1_TIME;
288     #[cfg(any(ossl110, libressl273))]
X509_up_ref(x: *mut X509) -> c_int289     pub fn X509_up_ref(x: *mut X509) -> c_int;
290 
291     #[cfg(ossl110)]
X509_get0_extensions(req: *const ::X509) -> *const stack_st_X509_EXTENSION292     pub fn X509_get0_extensions(req: *const ::X509) -> *const stack_st_X509_EXTENSION;
293 }
294 
295 cfg_if! {
296     if #[cfg(any(ossl110, libressl280))] {
297         extern "C" {
298             pub fn X509_NAME_entry_count(n: *const X509_NAME) -> c_int;
299         }
300     } else {
301         extern "C" {
302             pub fn X509_NAME_entry_count(n: *mut X509_NAME) -> c_int;
303         }
304     }
305 }
306 
307 cfg_if! {
308     if #[cfg(libressl280)] {
309         extern "C" {
310             pub fn X509_NAME_get_index_by_NID(n: *const X509_NAME, nid: c_int, last_pos: c_int) -> c_int;
311         }
312     } else {
313         extern "C" {
314             pub fn X509_NAME_get_index_by_NID(n: *mut X509_NAME, nid: c_int, last_pos: c_int) -> c_int;
315         }
316     }
317 }
318 cfg_if! {
319     if #[cfg(any(ossl110, libressl280))] {
320         extern "C" {
321             pub fn X509_NAME_get_entry(n: *const X509_NAME, loc: c_int) -> *mut X509_NAME_ENTRY;
322             pub fn X509_NAME_add_entry_by_NID(
323                 x: *mut X509_NAME,
324                 field: c_int,
325                 ty: c_int,
326                 bytes: *const c_uchar,
327                 len: c_int,
328                 loc: c_int,
329                 set: c_int,
330             ) -> c_int;
331             pub fn X509_NAME_ENTRY_get_object(ne: *const X509_NAME_ENTRY) -> *mut ASN1_OBJECT;
332             pub fn X509_NAME_ENTRY_get_data(ne: *const X509_NAME_ENTRY) -> *mut ASN1_STRING;
333         }
334     } else {
335         extern "C" {
336             pub fn X509_NAME_get_entry(n: *mut X509_NAME, loc: c_int) -> *mut X509_NAME_ENTRY;
337             pub fn X509_NAME_add_entry_by_NID(
338                 x: *mut X509_NAME,
339                 field: c_int,
340                 ty: c_int,
341                 bytes: *mut c_uchar,
342                 len: c_int,
343                 loc: c_int,
344                 set: c_int,
345             ) -> c_int;
346             pub fn X509_NAME_ENTRY_get_object(ne: *mut X509_NAME_ENTRY) -> *mut ASN1_OBJECT;
347             pub fn X509_NAME_ENTRY_get_data(ne: *mut X509_NAME_ENTRY) -> *mut ASN1_STRING;
348         }
349     }
350 }
351 extern "C" {
X509_NAME_add_entry_by_txt( x: *mut X509_NAME, field: *const c_char, ty: c_int, bytes: *const c_uchar, len: c_int, loc: c_int, set: c_int, ) -> c_int352     pub fn X509_NAME_add_entry_by_txt(
353         x: *mut X509_NAME,
354         field: *const c_char,
355         ty: c_int,
356         bytes: *const c_uchar,
357         len: c_int,
358         loc: c_int,
359         set: c_int,
360     ) -> c_int;
361 
X509_add_ext(x: *mut X509, ext: *mut X509_EXTENSION, loc: c_int) -> c_int362     pub fn X509_add_ext(x: *mut X509, ext: *mut X509_EXTENSION, loc: c_int) -> c_int;
363 }
364 cfg_if! {
365     if #[cfg(any(ossl110, libressl280))] {
366         extern "C" {
367             pub fn X509_get_ext_d2i(
368                 x: *const ::X509,
369                 nid: c_int,
370                 crit: *mut c_int,
371                 idx: *mut c_int,
372             ) -> *mut c_void;
373         }
374     } else {
375         extern "C" {
376             pub fn X509_get_ext_d2i(
377                 x: *mut ::X509,
378                 nid: c_int,
379                 crit: *mut c_int,
380                 idx: *mut c_int,
381             ) -> *mut c_void;
382         }
383     }
384 }
385 
386 extern "C" {
X509_verify_cert(ctx: *mut X509_STORE_CTX) -> c_int387     pub fn X509_verify_cert(ctx: *mut X509_STORE_CTX) -> c_int;
388 }
389 
390 #[cfg(any(ossl110, libressl270))]
391 extern "C" {
X509_STORE_get0_objects(ctx: *mut X509_STORE) -> *mut stack_st_X509_OBJECT392     pub fn X509_STORE_get0_objects(ctx: *mut X509_STORE) -> *mut stack_st_X509_OBJECT;
X509_OBJECT_get0_X509(x: *const X509_OBJECT) -> *mut X509393     pub fn X509_OBJECT_get0_X509(x: *const X509_OBJECT) -> *mut X509;
394 }
395 
396 cfg_if! {
397     if #[cfg(ossl110)] {
398         extern "C" {
399             pub fn X509_OBJECT_free(a: *mut X509_OBJECT);
400         }
401     } else {
402         extern "C" {
403             pub fn X509_OBJECT_free_contents(a: *mut X509_OBJECT);
404         }
405     }
406 }
407