openssl_sys/
tls1.rs

1use libc::*;
2use std::mem;
3use std::ptr;
4
5use super::*;
6
7pub const TLS1_VERSION: c_int = 0x301;
8pub const TLS1_1_VERSION: c_int = 0x302;
9pub const TLS1_2_VERSION: c_int = 0x303;
10#[cfg(any(ossl111, libressl))]
11pub const TLS1_3_VERSION: c_int = 0x304;
12
13pub const DTLS1_VERSION: c_int = 0xFEFF;
14pub const DTLS1_2_VERSION: c_int = 0xFEFD;
15
16pub const TLS1_AD_DECODE_ERROR: c_int = 50;
17pub const TLS1_AD_UNRECOGNIZED_NAME: c_int = 112;
18
19pub const TLSEXT_NAMETYPE_host_name: c_int = 0;
20pub const TLSEXT_STATUSTYPE_ocsp: c_int = 1;
21
22pub unsafe fn SSL_set_tlsext_host_name(s: *mut SSL, name: *mut c_char) -> c_long {
23    SSL_ctrl(
24        s,
25        SSL_CTRL_SET_TLSEXT_HOSTNAME,
26        TLSEXT_NAMETYPE_host_name as c_long,
27        name as *mut c_void,
28    )
29}
30
31pub unsafe fn SSL_set_tlsext_status_type(s: *mut SSL, type_: c_int) -> c_long {
32    SSL_ctrl(
33        s,
34        SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE,
35        type_ as c_long,
36        ptr::null_mut(),
37    )
38}
39
40pub unsafe fn SSL_get_tlsext_status_ocsp_resp(ssl: *mut SSL, resp: *mut *mut c_uchar) -> c_long {
41    SSL_ctrl(
42        ssl,
43        SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP,
44        0,
45        resp as *mut c_void,
46    )
47}
48
49pub unsafe fn SSL_set_tlsext_status_ocsp_resp(
50    ssl: *mut SSL,
51    resp: *mut c_uchar,
52    len: c_long,
53) -> c_long {
54    SSL_ctrl(
55        ssl,
56        SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP,
57        len,
58        resp as *mut c_void,
59    )
60}
61
62#[deprecated(note = "use SSL_CTX_set_tlsext_servername_callback__fixed_rust instead")]
63#[allow(deprecated)]
64pub unsafe fn SSL_CTX_set_tlsext_servername_callback(
65    ctx: *mut SSL_CTX,
66    // FIXME should have the right signature
67    cb: Option<extern "C" fn()>,
68) -> c_long {
69    SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_TLSEXT_SERVERNAME_CB, cb)
70}
71
72pub unsafe fn SSL_CTX_set_tlsext_servername_callback__fixed_rust(
73    ctx: *mut SSL_CTX,
74    cb: Option<unsafe extern "C" fn(*mut SSL, *mut c_int, *mut c_void) -> c_int>,
75) -> c_long {
76    SSL_CTX_callback_ctrl__fixed_rust(
77        ctx,
78        SSL_CTRL_SET_TLSEXT_SERVERNAME_CB,
79        mem::transmute::<
80            std::option::Option<
81                unsafe extern "C" fn(*mut SSL, *mut c_int, *mut libc::c_void) -> i32,
82            >,
83            std::option::Option<unsafe extern "C" fn()>,
84        >(cb),
85    )
86}
87
88pub const SSL_TLSEXT_ERR_OK: c_int = 0;
89pub const SSL_TLSEXT_ERR_ALERT_WARNING: c_int = 1;
90pub const SSL_TLSEXT_ERR_ALERT_FATAL: c_int = 2;
91pub const SSL_TLSEXT_ERR_NOACK: c_int = 3;
92
93pub unsafe fn SSL_CTX_set_tlsext_servername_arg(ctx: *mut SSL_CTX, arg: *mut c_void) -> c_long {
94    SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG, 0, arg)
95}
96
97pub unsafe fn SSL_CTX_set_tlsext_status_cb(
98    ctx: *mut SSL_CTX,
99    cb: Option<unsafe extern "C" fn(*mut SSL, *mut c_void) -> c_int>,
100) -> c_long {
101    SSL_CTX_callback_ctrl__fixed_rust(
102        ctx,
103        SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB,
104        mem::transmute::<
105            std::option::Option<unsafe extern "C" fn(*mut SSL, *mut c_void) -> i32>,
106            std::option::Option<unsafe extern "C" fn()>,
107        >(cb),
108    )
109}
110
111#[cfg(not(osslconf = "OPENSSL_NO_SRTP"))]
112pub unsafe fn SSL_CTX_set_tlsext_status_arg(ctx: *mut SSL_CTX, arg: *mut c_void) -> c_long {
113    SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG, 0, arg)
114}