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