From 03871d368e1fdffd74ffad57197d55c4d59bd77b Mon Sep 17 00:00:00 2001 From: Valerii Hiora Date: Fri, 12 Sep 2014 20:37:23 +0300 Subject: [PATCH 1/2] Enabling TLS1.2 support Unfortunately OS X comes with 0.9.8 bundled. There is a way to install a recent version through homebrew, however it is extremely hard to make it link agains brewed version without tricking link version --- src/ssl/ffi.rs | 11 +++++++++++ src/ssl/mod.rs | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ssl/ffi.rs b/src/ssl/ffi.rs index 2e21a24b..d284353a 100755 --- a/src/ssl/ffi.rs +++ b/src/ssl/ffi.rs @@ -103,8 +103,17 @@ pub static X509_FILETYPE_PEM: c_int = 1; pub static X509_FILETYPE_ASN1: c_int = 2; pub static X509_FILETYPE_DEFAULT: c_int = 3; +#[cfg(target_os = "macos")] +#[link(name="ssl.1.0.0")] +#[link(name="crypto.1.0.0")] +extern {} + + +#[cfg(not(target_os = "macos"))] #[link(name="ssl")] #[link(name="crypto")] +extern {} + extern "C" { pub fn CRYPTO_num_locks() -> c_int; pub fn CRYPTO_set_locking_callback(func: extern "C" fn(mode: c_int, @@ -120,6 +129,8 @@ extern "C" { pub fn SSLv2_method() -> *const SSL_METHOD; pub fn SSLv3_method() -> *const SSL_METHOD; pub fn TLSv1_method() -> *const SSL_METHOD; + pub fn TLSv1_1_method() -> *const SSL_METHOD; + pub fn TLSv1_2_method() -> *const SSL_METHOD; pub fn SSLv23_method() -> *const SSL_METHOD; pub fn SSL_CTX_new(method: *const SSL_METHOD) -> *mut SSL_CTX; diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs index 785b8dfc..f0961ce9 100644 --- a/src/ssl/mod.rs +++ b/src/ssl/mod.rs @@ -48,6 +48,7 @@ fn init() { /// Determines the SSL method supported #[deriving(Show, Hash, PartialEq, Eq)] +#[allow(non_camel_case_types)] pub enum SslMethod { #[cfg(sslv2)] /// Only support the SSLv2 protocol @@ -58,6 +59,8 @@ pub enum SslMethod { Tlsv1, /// Support the SSLv2, SSLv3 and TLSv1 protocols Sslv23, + Tlsv1_1, + Tlsv1_2, } impl SslMethod { @@ -67,7 +70,9 @@ impl SslMethod { Sslv2 => ffi::SSLv2_method(), Sslv3 => ffi::SSLv3_method(), Tlsv1 => ffi::TLSv1_method(), - Sslv23 => ffi::SSLv23_method() + Sslv23 => ffi::SSLv23_method(), + Tlsv1_1 => ffi::TLSv1_1_method(), + Tlsv1_2 => ffi::TLSv1_2_method() } } } From 4c1edcf4c8aa00ec3bb8ff0c0e8627a91a36792f Mon Sep 17 00:00:00 2001 From: Valerii Hiora Date: Tue, 23 Sep 2014 18:13:48 +0300 Subject: [PATCH 2/2] TLS 1_1, 1_2, Ssl 2 is enabled by features --- .travis.yml | 5 +++++ Cargo.toml | 5 +++++ src/ssl/ffi.rs | 9 ++++++--- src/ssl/mod.rs | 8 ++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 66926322..432f9506 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,16 @@ language: rust env: global: - secure: qLvBJoJOJcPPZ+e31175O6sMUGBHgHe/kBuI0FCPeifYmpFyeRAkEvGddEkf8t3rojV+wE14CNYzzGsT/W/+JY7xW0C1FQKW3r+8SZ1Cave/8ahee0aCQVXGf0XY8c52uG6MrLGiUlNZbOsyFSdFUc/Io+kYZas4DxrinRSOIEA= +os: + - osx + - linux before_script: - openssl s_server -accept 15418 -www -cert test/cert.pem -key test/key.pem >/dev/null & script: - cargo build - cargo test - rustdoc src/lib.rs + - cargo build --features "sslv2" + - cargo build --features "tlsv1_1 tlsv1_2" after_script: - curl http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN | sh diff --git a/Cargo.toml b/Cargo.toml index 4e7246ff..4c61dd7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,8 @@ authors = ["Steven Fackler c_int; - #[cfg(sslv2)] + #[cfg(feature = "sslv2")] pub fn SSLv2_method() -> *const SSL_METHOD; pub fn SSLv3_method() -> *const SSL_METHOD; pub fn TLSv1_method() -> *const SSL_METHOD; + #[cfg(feature = "tlsv1_1")] pub fn TLSv1_1_method() -> *const SSL_METHOD; + #[cfg(feature = "tlsv1_2")] pub fn TLSv1_2_method() -> *const SSL_METHOD; pub fn SSLv23_method() -> *const SSL_METHOD; diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs index f0961ce9..fc775a32 100644 --- a/src/ssl/mod.rs +++ b/src/ssl/mod.rs @@ -50,7 +50,7 @@ fn init() { #[deriving(Show, Hash, PartialEq, Eq)] #[allow(non_camel_case_types)] pub enum SslMethod { - #[cfg(sslv2)] + #[cfg(feature = "sslv2")] /// Only support the SSLv2 protocol Sslv2, /// Only support the SSLv3 protocol @@ -59,19 +59,23 @@ pub enum SslMethod { Tlsv1, /// Support the SSLv2, SSLv3 and TLSv1 protocols Sslv23, + #[cfg(feature = "tlsv1_1")] Tlsv1_1, + #[cfg(feature = "tlsv1_2")] Tlsv1_2, } impl SslMethod { unsafe fn to_raw(&self) -> *const ffi::SSL_METHOD { match *self { - #[cfg(sslv2)] + #[cfg(feature = "sslv2")] Sslv2 => ffi::SSLv2_method(), Sslv3 => ffi::SSLv3_method(), Tlsv1 => ffi::TLSv1_method(), Sslv23 => ffi::SSLv23_method(), + #[cfg(feature = "tlsv1_1")] Tlsv1_1 => ffi::TLSv1_1_method(), + #[cfg(feature = "tlsv1_2")] Tlsv1_2 => ffi::TLSv1_2_method() } }