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;
18pub const TLS1_AD_NO_APPLICATION_PROTOCOL: c_int = 120;
19
20pub const TLSEXT_NAMETYPE_host_name: c_int = 0;
21pub const TLSEXT_STATUSTYPE_ocsp: c_int = 1;
22
23pub const TLSEXT_TYPE_server_name: c_int = 0;
24pub const TLSEXT_TYPE_application_layer_protocol_negotiation: c_int = 16;
25
26pub unsafe fn SSL_set_tlsext_host_name(s: *mut SSL, name: *mut c_char) -> c_long {
27 SSL_ctrl(
28 s,
29 SSL_CTRL_SET_TLSEXT_HOSTNAME,
30 TLSEXT_NAMETYPE_host_name as c_long,
31 name as *mut c_void,
32 )
33}
34
35pub unsafe fn SSL_set_tlsext_status_type(s: *mut SSL, type_: c_int) -> c_long {
36 SSL_ctrl(
37 s,
38 SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE,
39 type_ as c_long,
40 ptr::null_mut(),
41 )
42}
43
44pub unsafe fn SSL_get_tlsext_status_type(s: *mut SSL) -> c_long {
45 SSL_ctrl(s, SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE, 0, ptr::null_mut())
46}
47
48pub unsafe fn SSL_get_tlsext_status_ocsp_resp(ssl: *mut SSL, resp: *mut *mut c_uchar) -> c_long {
49 SSL_ctrl(
50 ssl,
51 SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP,
52 0,
53 resp as *mut c_void,
54 )
55}
56
57pub unsafe fn SSL_set_tlsext_status_ocsp_resp(
58 ssl: *mut SSL,
59 resp: *mut c_uchar,
60 len: c_long,
61) -> c_long {
62 SSL_ctrl(
63 ssl,
64 SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP,
65 len,
66 resp as *mut c_void,
67 )
68}
69
70pub unsafe fn SSL_CTX_set_tlsext_servername_callback(
71 ctx: *mut SSL_CTX,
72 cb: Option<unsafe extern "C" fn(*mut SSL, *mut c_int, *mut c_void) -> c_int>,
73) -> c_long {
74 SSL_CTX_callback_ctrl(
75 ctx,
76 SSL_CTRL_SET_TLSEXT_SERVERNAME_CB,
77 mem::transmute::<
78 Option<unsafe extern "C" fn(*mut SSL, *mut c_int, *mut c_void) -> c_int>,
79 Option<unsafe extern "C" fn()>,
80 >(cb),
81 )
82}
83
84pub const SSL_TLSEXT_ERR_OK: c_int = 0;
85pub const SSL_TLSEXT_ERR_ALERT_WARNING: c_int = 1;
86pub const SSL_TLSEXT_ERR_ALERT_FATAL: c_int = 2;
87pub const SSL_TLSEXT_ERR_NOACK: c_int = 3;
88
89pub unsafe fn SSL_CTX_set_tlsext_servername_arg(ctx: *mut SSL_CTX, arg: *mut c_void) -> c_long {
90 SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG, 0, arg)
91}
92
93pub unsafe fn SSL_CTX_set_tlsext_status_cb(
94 ctx: *mut SSL_CTX,
95 cb: Option<unsafe extern "C" fn(*mut SSL, *mut c_void) -> c_int>,
96) -> c_long {
97 SSL_CTX_callback_ctrl(
98 ctx,
99 SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB,
100 mem::transmute::<
101 Option<unsafe extern "C" fn(*mut SSL, *mut c_void) -> c_int>,
102 Option<unsafe extern "C" fn()>,
103 >(cb),
104 )
105}
106
107#[cfg(not(osslconf = "OPENSSL_NO_SRTP"))]
108pub unsafe fn SSL_CTX_set_tlsext_status_arg(ctx: *mut SSL_CTX, arg: *mut c_void) -> c_long {
109 SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG, 0, arg)
110}
111
112pub unsafe fn SSL_CTX_set_tlsext_status_type(ctx: *mut SSL_CTX, type_: c_int) -> c_long {
113 SSL_CTX_ctrl(
114 ctx,
115 SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE,
116 type_ as c_long,
117 ptr::null_mut(),
118 )
119}
120
121pub unsafe fn SSL_CTX_get_tlsext_status_type(ctx: *mut SSL_CTX) -> c_long {
122 SSL_CTX_ctrl(ctx, SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE, 0, ptr::null_mut())
123}
124
125pub const SSL_TICKET_KEY_NAME_LEN: c_int = 16;
126
127pub unsafe fn SSL_CTX_set_tlsext_ticket_key_cb(
128 ctx: *mut SSL_CTX,
129 cb: Option<
130 unsafe extern "C" fn(
131 arg1: *mut SSL,
132 arg2: *mut c_uchar,
133 arg3: *mut c_uchar,
134 arg4: *mut EVP_CIPHER_CTX,
135 arg5: *mut HMAC_CTX,
136 arg6: c_int,
137 ) -> c_int,
138 >,
139) -> c_long {
140 SSL_CTX_callback_ctrl(
141 ctx,
142 SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,
143 mem::transmute::<
144 Option<
145 unsafe extern "C" fn(
146 *mut SSL,
147 *mut c_uchar,
148 *mut c_uchar,
149 *mut EVP_CIPHER_CTX,
150 *mut HMAC_CTX,
151 c_int,
152 ) -> c_int,
153 >,
154 Option<unsafe extern "C" fn()>,
155 >(cb),
156 )
157}