tongsuo_sys/handwritten/
ssl.rs

1use super::super::*;
2use libc::*;
3
4pub enum SSL_METHOD {}
5pub enum SSL_CIPHER {}
6cfg_if! {
7    if #[cfg(any(ossl110, libressl280))] {
8        pub enum SSL_SESSION {}
9    } else if #[cfg(libressl251)] {
10        #[repr(C)]
11        pub struct SSL_SESSION {
12            ssl_version: c_int,
13            pub master_key_length: c_int,
14            pub master_key: [c_uchar; 48],
15            session_id_length: c_uint,
16            session_id: [c_uchar; SSL_MAX_SSL_SESSION_ID_LENGTH as usize],
17            sid_ctx_length: c_uint,
18            sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize],
19            peer: *mut X509,
20            verify_result: c_long,
21            timeout: c_long,
22            time: time_t,
23            pub references: c_int,
24            cipher: *const SSL_CIPHER,
25            cipher_id: c_long,
26            ciphers: *mut stack_st_SSL_CIPHER,
27            tlsext_hostname: *mut c_char,
28            tlsext_tick: *mut c_uchar,
29            tlsext_ticklen: size_t,
30            tlsext_tick_lifetime_int: c_long,
31            internal: *mut c_void,
32        }
33    } else if #[cfg(libressl)] {
34        #[repr(C)]
35        pub struct SSL_SESSION {
36            ssl_version: c_int,
37            pub master_key_length: c_int,
38            pub master_key: [c_uchar; 48],
39            session_id_length: c_uint,
40            session_id: [c_uchar; SSL_MAX_SSL_SESSION_ID_LENGTH as usize],
41            sid_ctx_length: c_uint,
42            sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize],
43            not_resumable: c_int,
44            sess_cert: *mut c_void,
45            peer: *mut X509,
46            verify_result: c_long,
47            timeout: c_long,
48            time: time_t,
49            pub references: c_int,
50            cipher: *const c_void,
51            cipher_id: c_ulong,
52            ciphers: *mut c_void,
53            ex_data: CRYPTO_EX_DATA,
54            prev: *mut c_void,
55            next: *mut c_void,
56            tlsext_hostname: *mut c_char,
57            tlsext_ecpointformatlist_length: size_t,
58            tlsext_ecpointformatlist: *mut u8,
59            tlsext_ellipticcurvelist_length: size_t,
60            tlsext_ellipticcurvelist: *mut u16,
61            tlsext_tick: *mut c_uchar,
62            tlsext_ticklen: size_t,
63            tlsext_tick_lifetime_hint: c_long,
64        }
65    } else {
66        #[repr(C)]
67        pub struct SSL_SESSION {
68            ssl_version: c_int,
69            key_arg_length: c_uint,
70            key_arg: [c_uchar; SSL_MAX_KEY_ARG_LENGTH as usize],
71            pub master_key_length: c_int,
72            pub master_key: [c_uchar; 48],
73            session_id_length: c_uint,
74            session_id: [c_uchar; SSL_MAX_SSL_SESSION_ID_LENGTH as usize],
75            sid_ctx_length: c_uint,
76            sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize],
77            #[cfg(not(osslconf = "OPENSSL_NO_KRB5"))]
78            krb5_client_princ_len: c_uint,
79            #[cfg(not(osslconf = "OPENSSL_NO_KRB5"))]
80            krb5_client_princ: [c_uchar; SSL_MAX_KRB5_PRINCIPAL_LENGTH as usize],
81            #[cfg(not(osslconf = "OPENSSL_NO_PSK"))]
82            psk_identity_hint: *mut c_char,
83            #[cfg(not(osslconf = "OPENSSL_NO_PSK"))]
84            psk_identity: *mut c_char,
85            not_resumable: c_int,
86            sess_cert: *mut c_void,
87            peer: *mut X509,
88            verify_result: c_long,
89            pub references: c_int,
90            timeout: c_long,
91            time: c_long,
92            compress_meth: c_uint,
93            cipher: *const c_void,
94            cipher_id: c_ulong,
95            ciphers: *mut c_void,
96            ex_data: CRYPTO_EX_DATA,
97            prev: *mut c_void,
98            next: *mut c_void,
99            #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))]
100            tlsext_hostname: *mut c_char,
101            #[cfg(all(
102                not(osslconf = "OPENSSL_NO_TLSEXT"),
103                not(osslconf = "OPENSSL_NO_EC")
104            ))]
105            tlsext_ecpointformatlist_length: size_t,
106            #[cfg(all(
107                not(osslconf = "OPENSSL_NO_TLSEXT"),
108                not(osslconf = "OPENSSL_NO_EC")
109            ))]
110            tlsext_ecpointformatlist: *mut c_uchar,
111            #[cfg(all(
112                not(osslconf = "OPENSSL_NO_TLSEXT"),
113                not(osslconf = "OPENSSL_NO_EC")
114            ))]
115            tlsext_ellipticcurvelist_length: size_t,
116            #[cfg(all(
117                not(osslconf = "OPENSSL_NO_TLSEXT"),
118                not(osslconf = "OPENSSL_NO_EC")
119            ))]
120            tlsext_ellipticcurvelist: *mut c_uchar,
121            #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))]
122            tlsext_tick: *mut c_uchar,
123            #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))]
124            tlsext_ticklen: size_t,
125            #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))]
126            tlsext_tick_lifetime_hint: c_long,
127            #[cfg(not(osslconf = "OPENSSL_NO_SRP"))]
128            srp_username: *mut c_char,
129        }
130    }
131}
132
133stack!(stack_st_SSL_CIPHER);
134
135#[repr(C)]
136pub struct SRTP_PROTECTION_PROFILE {
137    pub name: *const c_char,
138    pub id: c_ulong,
139}
140
141stack!(stack_st_SRTP_PROTECTION_PROFILE);
142
143pub type tls_session_ticket_ext_cb_fn =
144    Option<unsafe extern "C" fn(*mut SSL, *const c_uchar, c_int, *mut c_void) -> c_int>;
145pub type tls_session_secret_cb_fn = Option<
146    unsafe extern "C" fn(
147        *mut SSL,
148        *mut c_void,
149        *mut c_int,
150        *mut stack_st_SSL_CIPHER,
151        *mut *mut SSL_CIPHER,
152        *mut c_void,
153    ) -> c_int,
154>;
155
156#[cfg(ossl111)]
157pub type SSL_custom_ext_add_cb_ex = Option<
158    unsafe extern "C" fn(
159        ssl: *mut SSL,
160        ext_type: c_uint,
161        context: c_uint,
162        out: *mut *const c_uchar,
163        outlen: *mut size_t,
164        x: *mut X509,
165        chainidx: size_t,
166        al: *mut c_int,
167        add_arg: *mut c_void,
168    ) -> c_int,
169>;
170
171#[cfg(ossl111)]
172pub type SSL_custom_ext_free_cb_ex = Option<
173    unsafe extern "C" fn(
174        ssl: *mut SSL,
175        ext_type: c_uint,
176        context: c_uint,
177        out: *const c_uchar,
178        add_arg: *mut c_void,
179    ),
180>;
181
182#[cfg(ossl111)]
183pub type SSL_custom_ext_parse_cb_ex = Option<
184    unsafe extern "C" fn(
185        ssl: *mut SSL,
186        ext_type: c_uint,
187        context: c_uint,
188        input: *const c_uchar,
189        inlen: size_t,
190        x: *mut X509,
191        chainidx: size_t,
192        al: *mut c_int,
193        parse_arg: *mut c_void,
194    ) -> c_int,
195>;
196
197cfg_if! {
198    if #[cfg(ossl300)] {
199        extern "C" {
200            pub fn SSL_CTX_get_options(ctx: *const SSL_CTX) -> u64;
201            pub fn SSL_CTX_set_options(ctx: *mut SSL_CTX, op: u64) -> u64;
202            pub fn SSL_CTX_clear_options(ctx: *mut SSL_CTX, op: u64) -> u64;
203        }
204    } else if #[cfg(ossl110)] {
205        extern "C" {
206            pub fn SSL_CTX_get_options(ctx: *const SSL_CTX) -> c_ulong;
207            pub fn SSL_CTX_set_options(ctx: *mut SSL_CTX, op: c_ulong) -> c_ulong;
208            pub fn SSL_CTX_clear_options(ctx: *mut SSL_CTX, op: c_ulong) -> c_ulong;
209        }
210    }
211}
212
213pub type GEN_SESSION_CB =
214    Option<unsafe extern "C" fn(*const SSL, *mut c_uchar, *mut c_uint) -> c_int>;
215
216extern "C" {
217    pub fn SSL_CTX_sess_set_new_cb(
218        ctx: *mut SSL_CTX,
219        new_session_cb: Option<unsafe extern "C" fn(*mut SSL, *mut SSL_SESSION) -> c_int>,
220    );
221    pub fn SSL_CTX_sess_set_remove_cb(
222        ctx: *mut SSL_CTX,
223        remove_session_cb: Option<unsafe extern "C" fn(*mut SSL_CTX, *mut SSL_SESSION)>,
224    );
225}
226cfg_if! {
227    // const change in passed function pointer signature
228    if #[cfg(any(ossl110, libressl280))] {
229        extern "C" {
230            pub fn SSL_CTX_sess_set_get_cb(
231                ctx: *mut SSL_CTX,
232                get_session_cb: Option<
233                    unsafe extern "C" fn(*mut SSL, *const c_uchar, c_int, *mut c_int) -> *mut SSL_SESSION,
234                >,
235            );
236        }
237    } else {
238        extern "C" {
239            pub fn SSL_CTX_sess_set_get_cb(
240                ctx: *mut SSL_CTX,
241                get_session_cb: Option<
242                    unsafe extern "C" fn(*mut SSL, *mut c_uchar, c_int, *mut c_int) -> *mut SSL_SESSION,
243                >,
244            );
245        }
246    }
247}
248extern "C" {
249    // FIXME change to unsafe extern "C" fn
250    pub fn SSL_CTX_set_cookie_generate_cb(
251        s: *mut SSL_CTX,
252        cb: Option<
253            extern "C" fn(ssl: *mut SSL, cookie: *mut c_uchar, cookie_len: *mut c_uint) -> c_int,
254        >,
255    );
256}
257
258cfg_if! {
259    // const change in passed function pointer signature
260    if #[cfg(any(ossl110, libressl280))] {
261        extern "C" {
262            pub fn SSL_CTX_set_cookie_verify_cb(
263                s: *mut SSL_CTX,
264                cb: Option<
265                    extern "C" fn(ssl: *mut SSL, cookie: *const c_uchar, cookie_len: c_uint) -> c_int,
266                >,
267            );
268        }
269    } else {
270        extern "C" {
271            pub fn SSL_CTX_set_cookie_verify_cb(
272                s: *mut SSL_CTX,
273                cb: Option<extern "C" fn(ssl: *mut SSL, cookie: *mut c_uchar, cookie_len: c_uint) -> c_int>,
274            );
275        }
276    }
277}
278
279extern "C" {
280    #[cfg(ossl111)]
281    pub fn SSL_CTX_set_stateless_cookie_generate_cb(
282        s: *mut SSL_CTX,
283        cb: Option<
284            unsafe extern "C" fn(
285                ssl: *mut SSL,
286                cookie: *mut c_uchar,
287                cookie_len: *mut size_t,
288            ) -> c_int,
289        >,
290    );
291    #[cfg(ossl111)]
292    pub fn SSL_CTX_set_stateless_cookie_verify_cb(
293        s: *mut SSL_CTX,
294        cb: Option<
295            unsafe extern "C" fn(
296                ssl: *mut SSL,
297                cookie: *const c_uchar,
298                cookie_len: size_t,
299            ) -> c_int,
300        >,
301    );
302
303    pub fn SSL_CTX_set_next_protos_advertised_cb(
304        ssl: *mut SSL_CTX,
305        cb: extern "C" fn(
306            ssl: *mut SSL,
307            out: *mut *const c_uchar,
308            outlen: *mut c_uint,
309            arg: *mut c_void,
310        ) -> c_int,
311        arg: *mut c_void,
312    );
313    pub fn SSL_CTX_set_next_proto_select_cb(
314        ssl: *mut SSL_CTX,
315        cb: extern "C" fn(
316            ssl: *mut SSL,
317            out: *mut *mut c_uchar,
318            outlen: *mut c_uchar,
319            inbuf: *const c_uchar,
320            inlen: c_uint,
321            arg: *mut c_void,
322        ) -> c_int,
323        arg: *mut c_void,
324    );
325    pub fn SSL_get0_next_proto_negotiated(
326        s: *const SSL,
327        data: *mut *const c_uchar,
328        len: *mut c_uint,
329    );
330
331    pub fn SSL_select_next_proto(
332        out: *mut *mut c_uchar,
333        outlen: *mut c_uchar,
334        inbuf: *const c_uchar,
335        inlen: c_uint,
336        client: *const c_uchar,
337        client_len: c_uint,
338    ) -> c_int;
339}
340
341extern "C" {
342    #[cfg(any(ossl102, libressl261))]
343    pub fn SSL_CTX_set_alpn_protos(s: *mut SSL_CTX, data: *const c_uchar, len: c_uint) -> c_int;
344    #[cfg(any(ossl102, libressl261))]
345    pub fn SSL_set_alpn_protos(s: *mut SSL, data: *const c_uchar, len: c_uint) -> c_int;
346    #[cfg(any(ossl102, libressl261))]
347    #[link_name = "SSL_CTX_set_alpn_select_cb"]
348    pub fn SSL_CTX_set_alpn_select_cb__fixed_rust(
349        ssl: *mut SSL_CTX,
350        cb: Option<
351            unsafe extern "C" fn(
352                ssl: *mut SSL,
353                out: *mut *const c_uchar,
354                outlen: *mut c_uchar,
355                inbuf: *const c_uchar,
356                inlen: c_uint,
357                arg: *mut c_void,
358            ) -> c_int,
359        >,
360        arg: *mut c_void,
361    );
362    #[cfg(any(ossl102, libressl261))]
363    pub fn SSL_get0_alpn_selected(s: *const SSL, data: *mut *const c_uchar, len: *mut c_uint);
364}
365
366#[cfg(not(osslconf = "OPENSSL_NO_PSK"))]
367extern "C" {
368    pub fn SSL_CTX_set_psk_client_callback(
369        ssl: *mut SSL_CTX,
370        psk_client_cb: Option<
371            extern "C" fn(
372                *mut SSL,
373                *const c_char,
374                *mut c_char,
375                c_uint,
376                *mut c_uchar,
377                c_uint,
378            ) -> c_uint,
379        >,
380    );
381    pub fn SSL_CTX_set_psk_server_callback(
382        ssl: *mut SSL_CTX,
383        psk_server_cb: Option<
384            extern "C" fn(*mut SSL, *const c_char, *mut c_uchar, c_uint) -> c_uint,
385        >,
386    );
387    pub fn SSL_get_psk_identity_hint(ssl: *const SSL) -> *const c_char;
388    pub fn SSL_get_psk_identity(ssl: *const SSL) -> *const c_char;
389}
390
391extern "C" {
392    #[cfg(ossl111)]
393    pub fn SSL_CTX_add_custom_ext(
394        ctx: *mut SSL_CTX,
395        ext_type: c_uint,
396        context: c_uint,
397        add_cb: SSL_custom_ext_add_cb_ex,
398        free_cb: SSL_custom_ext_free_cb_ex,
399        add_arg: *mut c_void,
400        parse_cb: SSL_custom_ext_parse_cb_ex,
401        parse_arg: *mut c_void,
402    ) -> c_int;
403
404    #[cfg(ossl102)]
405    pub fn SSL_extension_supported(ext_type: c_uint) -> c_int;
406}
407
408#[cfg(ossl111)]
409pub type SSL_CTX_keylog_cb_func =
410    Option<unsafe extern "C" fn(ssl: *const SSL, line: *const c_char)>;
411
412extern "C" {
413    #[cfg(ossl111)]
414    pub fn SSL_CTX_set_keylog_callback(ctx: *mut SSL_CTX, cb: SSL_CTX_keylog_cb_func);
415
416    #[cfg(any(ossl111, libressl340))]
417    pub fn SSL_CTX_set_max_early_data(ctx: *mut SSL_CTX, max_early_data: u32) -> c_int;
418    #[cfg(any(ossl111, libressl340))]
419    pub fn SSL_CTX_get_max_early_data(ctx: *const SSL_CTX) -> u32;
420    #[cfg(any(ossl111, libressl340))]
421    pub fn SSL_set_max_early_data(ctx: *mut SSL, max_early_data: u32) -> c_int;
422    #[cfg(any(ossl111, libressl340))]
423    pub fn SSL_get_max_early_data(ctx: *const SSL) -> u32;
424
425    pub fn SSL_get_finished(s: *const SSL, buf: *mut c_void, count: size_t) -> size_t;
426    pub fn SSL_get_peer_finished(s: *const SSL, buf: *mut c_void, count: size_t) -> size_t;
427
428    pub fn SSL_CTX_get_verify_mode(ctx: *const SSL_CTX) -> c_int;
429    pub fn SSL_get_verify_mode(s: *const SSL) -> c_int;
430}
431
432const_ptr_api! {
433    extern "C" {
434        #[cfg(ossl110)]
435        pub fn SSL_is_init_finished(s: #[const_ptr_if(ossl111)] SSL) -> c_int;
436    }
437}
438
439cfg_if! {
440    if #[cfg(libressl261)] {
441        extern "C" {
442            pub fn SSL_CTX_set_min_proto_version(ctx: *mut SSL_CTX, version: u16) -> c_int;
443            pub fn SSL_CTX_set_max_proto_version(ctx: *mut SSL_CTX, version: u16) -> c_int;
444            pub fn SSL_set_min_proto_version(s: *mut SSL, version: u16) -> c_int;
445            pub fn SSL_set_max_proto_version(s: *mut SSL, version: u16) -> c_int;
446        }
447    }
448}
449
450cfg_if! {
451    if #[cfg(libressl270)] {
452        extern "C" {
453            pub fn SSL_CTX_get_min_proto_version(ctx: *mut SSL_CTX) -> c_int;
454            pub fn SSL_CTX_get_max_proto_version(ctx: *mut SSL_CTX) -> c_int;
455            pub fn SSL_get_min_proto_version(s: *mut SSL) -> c_int;
456            pub fn SSL_get_max_proto_version(s: *mut SSL) -> c_int;
457        }
458    }
459}
460
461extern "C" {
462    pub fn SSL_CTX_set_cipher_list(ssl: *mut SSL_CTX, s: *const c_char) -> c_int;
463    pub fn SSL_CTX_new(method: *const SSL_METHOD) -> *mut SSL_CTX;
464    pub fn SSL_CTX_free(ctx: *mut SSL_CTX);
465    #[cfg(any(ossl110, libressl273))]
466    pub fn SSL_CTX_up_ref(x: *mut SSL_CTX) -> c_int;
467    pub fn SSL_CTX_get_cert_store(ctx: *const SSL_CTX) -> *mut X509_STORE;
468    pub fn SSL_CTX_set_cert_store(ctx: *mut SSL_CTX, store: *mut X509_STORE);
469
470    pub fn SSL_get_current_cipher(ssl: *const SSL) -> *const SSL_CIPHER;
471    pub fn SSL_CIPHER_get_bits(cipher: *const SSL_CIPHER, alg_bits: *mut c_int) -> c_int;
472}
473const_ptr_api! {
474    extern "C" {
475        pub fn SSL_CIPHER_get_version(cipher: *const SSL_CIPHER) -> #[const_ptr_if(any(ossl110, libressl280))] c_char;
476    }
477}
478extern "C" {
479    #[cfg(ossl111)]
480    pub fn SSL_CIPHER_get_handshake_digest(cipher: *const SSL_CIPHER) -> *const EVP_MD;
481    pub fn SSL_CIPHER_get_name(cipher: *const SSL_CIPHER) -> *const c_char;
482    #[cfg(ossl111)]
483    pub fn SSL_CIPHER_standard_name(cipher: *const SSL_CIPHER) -> *const c_char;
484    #[cfg(ossl111)]
485    pub fn OPENSSL_cipher_name(rfc_name: *const c_char) -> *const c_char;
486
487    pub fn SSL_pending(ssl: *const SSL) -> c_int;
488    pub fn SSL_set_bio(ssl: *mut SSL, rbio: *mut BIO, wbio: *mut BIO);
489    pub fn SSL_get_rbio(ssl: *const SSL) -> *mut BIO;
490    pub fn SSL_get_wbio(ssl: *const SSL) -> *mut BIO;
491    #[cfg(any(ossl111, libressl340))]
492    pub fn SSL_CTX_set_ciphersuites(ctx: *mut SSL_CTX, str: *const c_char) -> c_int;
493    #[cfg(any(ossl111, libressl340))]
494    pub fn SSL_set_ciphersuites(ssl: *mut SSL, str: *const c_char) -> c_int;
495    pub fn SSL_set_cipher_list(ssl: *mut SSL, s: *const c_char) -> c_int;
496    pub fn SSL_set_ssl_method(s: *mut SSL, method: *const SSL_METHOD) -> c_int;
497    pub fn SSL_set_verify(
498        ssl: *mut SSL,
499        mode: c_int,
500        // FIXME should be unsafe
501        verify_callback: Option<extern "C" fn(c_int, *mut X509_STORE_CTX) -> c_int>,
502    );
503    pub fn SSL_CTX_use_PrivateKey(ctx: *mut SSL_CTX, key: *mut EVP_PKEY) -> c_int;
504    pub fn SSL_CTX_use_certificate(ctx: *mut SSL_CTX, cert: *mut X509) -> c_int;
505
506    pub fn SSL_CTX_use_PrivateKey_file(
507        ctx: *mut SSL_CTX,
508        key_file: *const c_char,
509        file_type: c_int,
510    ) -> c_int;
511    pub fn SSL_CTX_use_certificate_file(
512        ctx: *mut SSL_CTX,
513        cert_file: *const c_char,
514        file_type: c_int,
515    ) -> c_int;
516    pub fn SSL_CTX_use_certificate_chain_file(
517        ctx: *mut SSL_CTX,
518        cert_chain_file: *const c_char,
519    ) -> c_int;
520    pub fn SSL_use_PrivateKey_file(ssl: *mut SSL, file: *const c_char, type_: c_int) -> c_int;
521    pub fn SSL_use_PrivateKey(ssl: *mut SSL, pkey: *mut EVP_PKEY) -> c_int;
522    pub fn SSL_use_certificate(ssl: *mut SSL, x: *mut X509) -> c_int;
523    #[cfg(any(ossl110, libressl332))]
524    pub fn SSL_use_certificate_chain_file(ssl: *mut SSL, file: *const c_char) -> c_int;
525    pub fn SSL_set_client_CA_list(s: *mut SSL, name_list: *mut stack_st_X509_NAME);
526    pub fn SSL_add_client_CA(ssl: *mut SSL, x: *mut X509) -> c_int;
527    pub fn SSL_load_client_CA_file(file: *const c_char) -> *mut stack_st_X509_NAME;
528
529    #[cfg(not(ossl110))]
530    pub fn SSL_load_error_strings();
531    pub fn SSL_state_string(ssl: *const SSL) -> *const c_char;
532    pub fn SSL_state_string_long(ssl: *const SSL) -> *const c_char;
533
534    pub fn SSL_SESSION_get_time(s: *const SSL_SESSION) -> c_long;
535    pub fn SSL_SESSION_get_timeout(s: *const SSL_SESSION) -> c_long;
536    #[cfg(any(ossl110, libressl270))]
537    pub fn SSL_SESSION_get_protocol_version(s: *const SSL_SESSION) -> c_int;
538
539    #[cfg(any(ossl111, libressl340))]
540    pub fn SSL_SESSION_set_max_early_data(ctx: *mut SSL_SESSION, max_early_data: u32) -> c_int;
541    #[cfg(any(ossl111, libressl340))]
542    pub fn SSL_SESSION_get_max_early_data(ctx: *const SSL_SESSION) -> u32;
543
544    pub fn SSL_SESSION_get_id(s: *const SSL_SESSION, len: *mut c_uint) -> *const c_uchar;
545    #[cfg(any(ossl110, libressl273))]
546    pub fn SSL_SESSION_up_ref(ses: *mut SSL_SESSION) -> c_int;
547    pub fn SSL_SESSION_free(s: *mut SSL_SESSION);
548}
549cfg_if! {
550    if #[cfg(tongsuo)] {
551        extern "C" {
552            pub fn SSL_CTX_use_enc_PrivateKey(ctx: *mut SSL_CTX, pkey: *mut EVP_PKEY) -> c_int;
553            pub fn SSL_CTX_use_sign_PrivateKey(ctx: *mut SSL_CTX, pkey: *mut EVP_PKEY) -> c_int;
554            pub fn SSL_CTX_use_enc_PrivateKey_file(ctx: *mut SSL_CTX, file: *const c_char, type_: c_int) -> c_int;
555            pub fn SSL_CTX_use_sign_PrivateKey_file(ctx: *mut SSL_CTX, file: *const c_char, type_: c_int) -> c_int;
556            pub fn SSL_CTX_enable_ntls(ctx: *mut SSL_CTX);
557            pub fn SSL_CTX_disable_ntls(ctx: *mut SSL_CTX);
558            pub fn SSL_CTX_enable_force_ntls(ctx: *mut SSL_CTX);
559            pub fn SSL_CTX_disable_force_ntls(ctx: *mut SSL_CTX);
560            pub fn SSL_enable_ntls(s: *mut SSL);
561            pub fn SSL_disable_ntls(s: *mut SSL);
562            pub fn SSL_enable_force_ntls(s: *mut SSL);
563            pub fn SSL_disable_force_ntls(s: *mut SSL);
564            pub fn SSL_CTX_enable_sm_tls13_strict(ctx: *mut SSL_CTX);
565            pub fn SSL_CTX_disable_sm_tls13_strict(ctx: *mut SSL_CTX);
566            pub fn SSL_enable_sm_tls13_strict(s: *mut SSL);
567            pub fn SSL_disable_sm_tls13_strict(s: *mut SSL);
568            pub fn SSL_CTX_use_enc_certificate(ctx: *mut SSL_CTX, x: *mut X509) -> c_int;
569            pub fn SSL_CTX_use_sign_certificate(ctx: *mut SSL_CTX, x: *mut X509) -> c_int;
570            pub fn SSL_CTX_use_enc_certificate_file(ctx: *mut SSL_CTX, file: *const c_char, type_: c_int) -> c_int;
571            pub fn SSL_CTX_use_sign_certificate_file(ctx: *mut SSL_CTX, file: *const c_char, type_: c_int) -> c_int;
572            pub fn SSL_is_ntls(s: *const SSL) -> c_int;
573            pub fn NTLS_method() -> *const SSL_METHOD;
574            pub fn NTLS_server_method() -> *const SSL_METHOD;
575            pub fn NTLS_client_method() -> *const SSL_METHOD;
576            pub fn SSL_set_ciphers(s: *mut SSL, cipher_list: *mut stack_st_SSL_CIPHER) -> c_int;
577            pub fn SSL_set_ciphers_by_id(s: *mut SSL, cipher_list_by_id: *mut stack_st_SSL_CIPHER) -> c_int;
578            pub fn SSL_CTX_set_ciphers(ctx: *mut SSL_CTX, cipher_list: *mut stack_st_SSL_CIPHER) -> c_int;
579            pub fn SSL_CTX_get_ciphers_by_id(ctx: *const SSL_CTX) -> *mut stack_st_SSL_CIPHER;
580            pub fn SSL_CTX_set_ciphers_by_id(ctx: *mut SSL_CTX, cipher_list_by_id: *mut stack_st_SSL_CIPHER) -> c_int;
581            pub fn SSL_use_sign_certificate(ssl: *mut SSL, x: *mut X509) -> c_int;
582            pub fn SSL_use_sign_certificate_file(ssl: *mut SSL, file: *const c_char, type_: c_int) -> c_int;
583            pub fn SSL_use_enc_certificate(ssl: *mut SSL, x: *mut X509) -> c_int;
584            pub fn SSL_use_enc_certificate_file(ssl: *mut SSL, file: *const c_char, type_: c_int) -> c_int;
585            pub fn SSL_use_enc_PrivateKey(ssl: *mut SSL, pkey: *mut EVP_PKEY) -> c_int;
586            pub fn SSL_use_enc_PrivateKey_file(ssl: *mut SSL, file: *const c_char, type_: c_int) -> c_int;
587            pub fn SSL_use_sign_PrivateKey(ssl: *mut SSL, pkey: *mut EVP_PKEY) -> c_int;
588            pub fn SSL_use_sign_PrivateKey_file(ssl: *mut SSL, file: *const c_char, type_: c_int) -> c_int;
589        }
590    }
591}
592const_ptr_api! {
593    extern "C" {
594        pub fn i2d_SSL_SESSION(s: #[const_ptr_if(ossl300)] SSL_SESSION, pp: *mut *mut c_uchar) -> c_int;
595    }
596}
597extern "C" {
598    pub fn SSL_set_session(ssl: *mut SSL, session: *mut SSL_SESSION) -> c_int;
599    pub fn SSL_CTX_add_session(ctx: *mut SSL_CTX, session: *mut SSL_SESSION) -> c_int;
600    pub fn SSL_CTX_remove_session(ctx: *mut SSL_CTX, session: *mut SSL_SESSION) -> c_int;
601    pub fn d2i_SSL_SESSION(
602        a: *mut *mut SSL_SESSION,
603        pp: *mut *const c_uchar,
604        len: c_long,
605    ) -> *mut SSL_SESSION;
606
607    #[cfg(not(ossl300))]
608    pub fn SSL_get_peer_certificate(ssl: *const SSL) -> *mut X509;
609    #[cfg(ossl300)]
610    pub fn SSL_get1_peer_certificate(ssl: *const SSL) -> *mut X509;
611
612    pub fn SSL_get_peer_cert_chain(ssl: *const SSL) -> *mut stack_st_X509;
613
614    pub fn SSL_CTX_set_verify(
615        ctx: *mut SSL_CTX,
616        mode: c_int,
617        verify_callback: Option<extern "C" fn(c_int, *mut X509_STORE_CTX) -> c_int>,
618    );
619    pub fn SSL_CTX_set_verify_depth(ctx: *mut SSL_CTX, depth: c_int);
620
621    #[cfg(any(ossl111, libressl340))]
622    pub fn SSL_CTX_set_post_handshake_auth(ctx: *mut SSL_CTX, val: c_int);
623
624    pub fn SSL_CTX_check_private_key(ctx: *const SSL_CTX) -> c_int;
625
626    pub fn SSL_CTX_set_session_id_context(
627        ssl: *mut SSL_CTX,
628        sid_ctx: *const c_uchar,
629        sid_ctx_len: c_uint,
630    ) -> c_int;
631
632    pub fn SSL_new(ctx: *mut SSL_CTX) -> *mut SSL;
633
634    #[cfg(any(ossl102, libressl261))]
635    pub fn SSL_CTX_get0_param(ctx: *mut SSL_CTX) -> *mut X509_VERIFY_PARAM;
636
637    #[cfg(any(ossl102, libressl261))]
638    pub fn SSL_get0_param(ssl: *mut SSL) -> *mut X509_VERIFY_PARAM;
639}
640
641#[cfg(ossl111)]
642pub type SSL_client_hello_cb_fn =
643    Option<unsafe extern "C" fn(s: *mut SSL, al: *mut c_int, arg: *mut c_void) -> c_int>;
644extern "C" {
645    #[cfg(ossl111)]
646    pub fn SSL_CTX_set_client_hello_cb(
647        c: *mut SSL_CTX,
648        cb: SSL_client_hello_cb_fn,
649        arg: *mut c_void,
650    );
651    #[cfg(ossl111)]
652    pub fn SSL_client_hello_isv2(s: *mut SSL) -> c_int;
653    #[cfg(ossl111)]
654    pub fn SSL_client_hello_get0_legacy_version(s: *mut SSL) -> c_uint;
655    #[cfg(ossl111)]
656    pub fn SSL_client_hello_get0_random(s: *mut SSL, out: *mut *const c_uchar) -> size_t;
657    #[cfg(ossl111)]
658    pub fn SSL_client_hello_get0_session_id(s: *mut SSL, out: *mut *const c_uchar) -> size_t;
659    #[cfg(ossl111)]
660    pub fn SSL_client_hello_get0_ciphers(s: *mut SSL, out: *mut *const c_uchar) -> size_t;
661    #[cfg(ossl111)]
662    pub fn SSL_client_hello_get0_compression_methods(
663        s: *mut SSL,
664        out: *mut *const c_uchar,
665    ) -> size_t;
666    #[cfg(ossl111)]
667    pub fn SSL_client_hello_get1_extensions_present(
668        s: *mut SSL,
669        out: *mut *mut c_int,
670        outlen: *mut size_t,
671    ) -> c_int;
672    #[cfg(ossl111)]
673    pub fn SSL_client_hello_get0_ext(
674        s: *mut SSL,
675        type_: c_uint,
676        out: *mut *const c_uchar,
677        outlen: *mut size_t,
678    ) -> c_int;
679
680    pub fn SSL_free(ssl: *mut SSL);
681    pub fn SSL_accept(ssl: *mut SSL) -> c_int;
682    #[cfg(ossl111)]
683    pub fn SSL_stateless(s: *mut SSL) -> c_int;
684    pub fn SSL_connect(ssl: *mut SSL) -> c_int;
685    pub fn SSL_read(ssl: *mut SSL, buf: *mut c_void, num: c_int) -> c_int;
686    #[cfg(any(ossl111, libressl350))]
687    pub fn SSL_read_ex(ssl: *mut SSL, buf: *mut c_void, num: usize, readbytes: *mut usize)
688        -> c_int;
689    pub fn SSL_peek(ssl: *mut SSL, buf: *mut c_void, num: c_int) -> c_int;
690    #[cfg(any(ossl111, libressl350))]
691    pub fn SSL_peek_ex(ssl: *mut SSL, buf: *mut c_void, num: usize, readbytes: *mut usize)
692        -> c_int;
693    #[cfg(any(ossl111, libressl340))]
694    pub fn SSL_read_early_data(
695        s: *mut SSL,
696        buf: *mut c_void,
697        num: size_t,
698        readbytes: *mut size_t,
699    ) -> c_int;
700    #[cfg(ossl111)]
701    pub fn SSL_bytes_to_cipher_list(
702        s: *mut SSL,
703        bytes: *const c_uchar,
704        len: size_t,
705        isv2format: c_int,
706        sk: *mut *mut stack_st_SSL_CIPHER,
707        scsvs: *mut *mut stack_st_SSL_CIPHER,
708    ) -> c_int;
709}
710
711extern "C" {
712    pub fn SSL_write(ssl: *mut SSL, buf: *const c_void, num: c_int) -> c_int;
713    #[cfg(any(ossl111, libressl350))]
714    pub fn SSL_write_ex(
715        ssl: *mut SSL,
716        buf: *const c_void,
717        num: size_t,
718        written: *mut size_t,
719    ) -> c_int;
720    #[cfg(any(ossl111, libressl340))]
721    pub fn SSL_write_early_data(
722        s: *mut SSL,
723        buf: *const c_void,
724        num: size_t,
725        written: *mut size_t,
726    ) -> c_int;
727    pub fn SSL_ctrl(ssl: *mut SSL, cmd: c_int, larg: c_long, parg: *mut c_void) -> c_long;
728    pub fn SSL_CTX_ctrl(ctx: *mut SSL_CTX, cmd: c_int, larg: c_long, parg: *mut c_void) -> c_long;
729    #[link_name = "SSL_CTX_callback_ctrl"]
730    pub fn SSL_CTX_callback_ctrl__fixed_rust(
731        ctx: *mut SSL_CTX,
732        cmd: c_int,
733        fp: Option<unsafe extern "C" fn()>,
734    ) -> c_long;
735}
736
737cfg_if! {
738    if #[cfg(any(ossl110, libressl291))] {
739        extern "C" {
740            pub fn TLS_method() -> *const SSL_METHOD;
741
742            pub fn DTLS_method() -> *const SSL_METHOD;
743
744            pub fn TLS_server_method() -> *const SSL_METHOD;
745
746            pub fn TLS_client_method() -> *const SSL_METHOD;
747        }
748    } else {
749        extern "C" {
750            #[cfg(not(osslconf = "OPENSSL_NO_SSL3_METHOD"))]
751            pub fn SSLv3_method() -> *const SSL_METHOD;
752
753            pub fn SSLv23_method() -> *const SSL_METHOD;
754
755            pub fn SSLv23_client_method() -> *const SSL_METHOD;
756
757            pub fn SSLv23_server_method() -> *const SSL_METHOD;
758
759            pub fn TLSv1_method() -> *const SSL_METHOD;
760
761            pub fn TLSv1_1_method() -> *const SSL_METHOD;
762
763            pub fn TLSv1_2_method() -> *const SSL_METHOD;
764
765            pub fn DTLSv1_method() -> *const SSL_METHOD;
766
767            #[cfg(ossl102)]
768            pub fn DTLSv1_2_method() -> *const SSL_METHOD;
769        }
770    }
771}
772
773extern "C" {
774    pub fn SSL_get_error(ssl: *const SSL, ret: c_int) -> c_int;
775    pub fn SSL_get_version(ssl: *const SSL) -> *const c_char;
776
777    pub fn SSL_do_handshake(ssl: *mut SSL) -> c_int;
778    pub fn SSL_shutdown(ssl: *mut SSL) -> c_int;
779
780    pub fn SSL_CTX_set_client_CA_list(ctx: *mut SSL_CTX, list: *mut stack_st_X509_NAME);
781
782    pub fn SSL_CTX_add_client_CA(ctx: *mut SSL_CTX, cacert: *mut X509) -> c_int;
783
784    pub fn SSL_CTX_set_default_verify_paths(ctx: *mut SSL_CTX) -> c_int;
785    pub fn SSL_CTX_load_verify_locations(
786        ctx: *mut SSL_CTX,
787        CAfile: *const c_char,
788        CApath: *const c_char,
789    ) -> c_int;
790}
791
792const_ptr_api! {
793    extern "C" {
794        pub fn SSL_get_ssl_method(ssl: #[const_ptr_if(ossl111b)] SSL) -> *const SSL_METHOD;
795    }
796}
797
798extern "C" {
799    pub fn SSL_set_connect_state(s: *mut SSL);
800    pub fn SSL_set_accept_state(s: *mut SSL);
801
802    #[cfg(not(ossl110))]
803    pub fn SSL_library_init() -> c_int;
804
805    pub fn SSL_CIPHER_description(
806        cipher: *const SSL_CIPHER,
807        buf: *mut c_char,
808        size: c_int,
809    ) -> *mut c_char;
810
811    pub fn SSL_get_certificate(ssl: *const SSL) -> *mut X509;
812}
813const_ptr_api! {
814    extern "C" {
815        pub fn SSL_get_privatekey(ssl: #[const_ptr_if(any(ossl102, libressl280))] SSL) -> *mut EVP_PKEY;
816    }
817}
818
819extern "C" {
820    #[cfg(any(ossl102, libressl270))]
821    pub fn SSL_CTX_get0_certificate(ctx: *const SSL_CTX) -> *mut X509;
822    #[cfg(any(ossl102, libressl340))]
823    pub fn SSL_CTX_get0_privatekey(ctx: *const SSL_CTX) -> *mut EVP_PKEY;
824
825    pub fn SSL_set_shutdown(ss: *mut SSL, mode: c_int);
826    pub fn SSL_get_shutdown(ssl: *const SSL) -> c_int;
827    pub fn SSL_version(ssl: *const SSL) -> c_int;
828    pub fn SSL_get_session(s: *const SSL) -> *mut SSL_SESSION;
829    pub fn SSL_get_SSL_CTX(ssl: *const SSL) -> *mut SSL_CTX;
830    pub fn SSL_set_SSL_CTX(ssl: *mut SSL, ctx: *mut SSL_CTX) -> *mut SSL_CTX;
831
832    pub fn SSL_get_verify_result(ssl: *const SSL) -> c_long;
833    #[cfg(ossl110)]
834    pub fn SSL_get0_verified_chain(ssl: *const SSL) -> *mut stack_st_X509;
835
836    #[cfg(any(ossl110, libressl270))]
837    pub fn SSL_get_client_random(ssl: *const SSL, out: *mut c_uchar, len: size_t) -> size_t;
838    #[cfg(any(ossl110, libressl270))]
839    pub fn SSL_get_server_random(ssl: *const SSL, out: *mut c_uchar, len: size_t) -> size_t;
840    #[cfg(any(ossl110, libressl273))]
841    pub fn SSL_SESSION_get_master_key(
842        session: *const SSL_SESSION,
843        out: *mut c_uchar,
844        outlen: size_t,
845    ) -> size_t;
846}
847
848extern "C" {
849    #[cfg(not(ossl110))]
850    pub fn SSL_get_ex_new_index(
851        argl: c_long,
852        argp: *mut c_void,
853        new_func: Option<CRYPTO_EX_new>,
854        dup_func: Option<CRYPTO_EX_dup>,
855        free_func: Option<CRYPTO_EX_free>,
856    ) -> c_int;
857
858    pub fn SSL_set_ex_data(ssl: *mut SSL, idx: c_int, data: *mut c_void) -> c_int;
859    pub fn SSL_get_ex_data(ssl: *const SSL, idx: c_int) -> *mut c_void;
860
861    #[cfg(not(ossl110))]
862    pub fn SSL_CTX_get_ex_new_index(
863        argl: c_long,
864        argp: *mut c_void,
865        new_func: Option<CRYPTO_EX_new>,
866        dup_func: Option<CRYPTO_EX_dup>,
867        free_func: Option<CRYPTO_EX_free>,
868    ) -> c_int;
869
870    pub fn SSL_CTX_set_ex_data(ctx: *mut SSL_CTX, idx: c_int, data: *mut c_void) -> c_int;
871    pub fn SSL_CTX_get_ex_data(ctx: *const SSL_CTX, idx: c_int) -> *mut c_void;
872
873    pub fn SSL_get_ex_data_X509_STORE_CTX_idx() -> c_int;
874}
875
876extern "C" {
877    #[link_name = "SSL_CTX_set_tmp_dh_callback"]
878    pub fn SSL_CTX_set_tmp_dh_callback__fixed_rust(
879        ctx: *mut SSL_CTX,
880        dh: Option<
881            unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut DH,
882        >,
883    );
884    #[link_name = "SSL_set_tmp_dh_callback"]
885    pub fn SSL_set_tmp_dh_callback__fixed_rust(
886        ctx: *mut SSL,
887        dh: Option<
888            unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut DH,
889        >,
890    );
891    #[cfg(not(ossl110))]
892    #[link_name = "SSL_CTX_set_tmp_ecdh_callback"]
893    pub fn SSL_CTX_set_tmp_ecdh_callback__fixed_rust(
894        ctx: *mut SSL_CTX,
895        ecdh: Option<
896            unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut EC_KEY,
897        >,
898    );
899    #[cfg(not(ossl110))]
900    #[link_name = "SSL_set_tmp_ecdh_callback"]
901    pub fn SSL_set_tmp_ecdh_callback__fixed_rust(
902        ssl: *mut SSL,
903        ecdh: Option<
904            unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut EC_KEY,
905        >,
906    );
907}
908
909cfg_if! {
910    if #[cfg(libressl)] {
911        extern "C" {
912            pub fn SSL_get_current_compression(ssl: *mut SSL) -> *const libc::c_void;
913        }
914    } else if #[cfg(not(osslconf = "OPENSSL_NO_COMP"))] {
915        const_ptr_api! {
916            extern "C" {
917                pub fn SSL_get_current_compression(ssl: #[const_ptr_if(ossl111b)] SSL) -> *const COMP_METHOD;
918            }
919        }
920    }
921}
922cfg_if! {
923    if #[cfg(libressl)] {
924        extern "C" {
925            pub fn SSL_COMP_get_name(comp: *const libc::c_void) -> *const c_char;
926        }
927    } else if #[cfg(not(osslconf = "OPENSSL_NO_COMP"))] {
928        extern "C" {
929            pub fn SSL_COMP_get_name(comp: *const COMP_METHOD) -> *const c_char;
930        }
931    }
932}
933
934#[cfg(not(osslconf = "OPENSSL_NO_COMP"))]
935extern "C" {
936    #[cfg(ossl110)]
937    pub fn COMP_get_type(meth: *const COMP_METHOD) -> i32;
938}
939
940extern "C" {
941    #[cfg(any(ossl110, libressl270))]
942    pub fn SSL_CIPHER_get_cipher_nid(c: *const SSL_CIPHER) -> c_int;
943    #[cfg(any(ossl110, libressl270))]
944    pub fn SSL_CIPHER_get_digest_nid(c: *const SSL_CIPHER) -> c_int;
945}
946
947const_ptr_api! {
948    extern "C" {
949        #[cfg(ossl110)]
950        pub fn SSL_session_reused(ssl: #[const_ptr_if(ossl111c)] SSL) -> c_int;
951    }
952}
953
954const_ptr_api! {
955    extern "C" {
956        #[cfg(any(ossl102, libressl273))]
957        pub fn SSL_is_server(s: #[const_ptr_if(any(ossl110f, libressl273))] SSL) -> c_int;
958    }
959}
960
961extern "C" {
962    #[cfg(ossl110)]
963    pub fn OPENSSL_init_ssl(opts: u64, settings: *const OPENSSL_INIT_SETTINGS) -> c_int;
964}
965
966extern "C" {
967    #[cfg(ossl111)]
968    pub fn SSL_CTX_set_num_tickets(ctx: *mut SSL_CTX, num_tickets: size_t) -> c_int;
969
970    #[cfg(ossl111)]
971    pub fn SSL_set_num_tickets(s: *mut SSL, num_tickets: size_t) -> c_int;
972
973    #[cfg(ossl111b)]
974    pub fn SSL_CTX_get_num_tickets(ctx: *const SSL_CTX) -> size_t;
975    #[cfg(all(ossl111, not(ossl111b)))]
976    pub fn SSL_CTX_get_num_tickets(ctx: *mut SSL_CTX) -> size_t;
977
978    #[cfg(ossl111b)]
979    pub fn SSL_get_num_tickets(s: *const SSL) -> size_t;
980    #[cfg(all(ossl111, not(ossl111b)))]
981    pub fn SSL_get_num_tickets(s: *mut SSL) -> size_t;
982}
983
984extern "C" {
985    #[cfg(any(ossl110, libressl360))]
986    pub fn SSL_CTX_set_security_level(ctx: *mut SSL_CTX, level: c_int);
987
988    #[cfg(any(ossl110, libressl360))]
989    pub fn SSL_set_security_level(s: *mut SSL, level: c_int);
990
991    #[cfg(any(ossl110, libressl360))]
992    pub fn SSL_CTX_get_security_level(ctx: *const SSL_CTX) -> c_int;
993
994    #[cfg(any(ossl110, libressl360))]
995    pub fn SSL_get_security_level(s: *const SSL) -> c_int;
996}