From 8c255d6dc41900c48bd17d134973d93d8ea48c9b Mon Sep 17 00:00:00 2001 From: Bruno Bigras Date: Wed, 10 Dec 2014 10:07:11 -0500 Subject: [PATCH 01/16] Add rustlib 64-bit path in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 427f6e47..58a2285b 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ For some reason, the OpenSSL distribution for Windows is structured differently, 2. Run the installer, making note of where it's installing OpenSSL. The option to copy the libraries to the Windows system directory or `[OpenSSL folder]/bin` is your choice. The latter is probably preferable, and the default. 3. Navigate to `[OpenSSL folder]/lib/MinGW/`, and copy `libeay32.a` and `ssleay32.a` (If 64-bit, then they will have `64` instead of `32`.) to your Rust install's libs folder. The default should be: * 32-bit: `C:\Program Files (x86)\Rust\bin\rustlib\i686-pc-mingw32\lib` - * 64-bit: TODO + * 64-bit: `C:\Program Files (x86)\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib` 4. Rename `libeay32.a` and `ssleay32.a` to `libcrypto.a` and `libssl.a`, respectively. 5. Run `cargo build`. From c9220900753052a946abf6ac6de172d4a5e98b43 Mon Sep 17 00:00:00 2001 From: Valerii Hiora Date: Thu, 11 Dec 2014 13:44:37 +0200 Subject: [PATCH 02/16] Update to nightly: explicit Copy trait --- openssl-sys/src/lib.rs | 4 ++++ src/bn/mod.rs | 1 + src/crypto/hash.rs | 1 + src/crypto/pkey.rs | 4 +++- src/crypto/symm.rs | 2 ++ src/ssl/mod.rs | 2 ++ src/x509/mod.rs | 7 +++++-- 7 files changed, 18 insertions(+), 3 deletions(-) diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs index 1faf749e..8550ce33 100644 --- a/openssl-sys/src/lib.rs +++ b/openssl-sys/src/lib.rs @@ -39,6 +39,7 @@ pub type X509_NAME_ENTRY = c_void; pub type X509_REQ = c_void; pub type X509_STORE_CTX = c_void; +#[allow(missing_copy_implementations)] #[repr(C)] pub struct EVP_MD_CTX { digest: *mut EVP_MD, @@ -49,6 +50,7 @@ pub struct EVP_MD_CTX { update: *mut c_void } +#[allow(missing_copy_implementations)] #[repr(C)] pub struct HMAC_CTX { md: *mut EVP_MD, @@ -59,6 +61,7 @@ pub struct HMAC_CTX { key: [c_uchar, ..128] } +#[allow(missing_copy_implementations)] #[repr(C)] pub struct X509V3_CTX { flags: c_int, @@ -72,6 +75,7 @@ pub struct X509V3_CTX { // Maybe more here } +#[allow(missing_copy_implementations)] #[repr(C)] pub struct BIGNUM { pub d: *mut c_void, diff --git a/src/bn/mod.rs b/src/bn/mod.rs index 2536f8a5..069c6b22 100644 --- a/src/bn/mod.rs +++ b/src/bn/mod.rs @@ -7,6 +7,7 @@ use ssl::error::SslError; pub struct BigNum(*mut ffi::BIGNUM); +#[deriving(Copy)] #[repr(C)] pub enum RNGProperty { MsbMaybeZero = -1, diff --git a/src/crypto/hash.rs b/src/crypto/hash.rs index b5d0eab5..37573368 100644 --- a/src/crypto/hash.rs +++ b/src/crypto/hash.rs @@ -4,6 +4,7 @@ use std::io; use ffi; +#[deriving(Copy)] pub enum HashType { MD5, SHA1, diff --git a/src/crypto/pkey.rs b/src/crypto/pkey.rs index 146d2aa3..bab7addc 100644 --- a/src/crypto/pkey.rs +++ b/src/crypto/pkey.rs @@ -6,7 +6,7 @@ use crypto::hash::HashType; use ffi; use ssl::error::{SslError, StreamError}; - +#[deriving(Copy)] enum Parts { Neither, Public, @@ -14,6 +14,7 @@ enum Parts { } /// Represents a role an asymmetric key might be appropriate for. +#[deriving(Copy)] pub enum Role { Encrypt, Decrypt, @@ -22,6 +23,7 @@ pub enum Role { } /// Type of encryption padding to use. +#[deriving(Copy)] pub enum EncryptionPadding { OAEP, PKCS1v15 diff --git a/src/crypto/symm.rs b/src/crypto/symm.rs index 998d351c..61365f2e 100644 --- a/src/crypto/symm.rs +++ b/src/crypto/symm.rs @@ -2,12 +2,14 @@ use libc::{c_int}; use ffi; +#[deriving(Copy)] pub enum Mode { Encrypt, Decrypt, } #[allow(non_camel_case_types)] +#[deriving(Copy)] pub enum Type { AES_128_ECB, AES_128_CBC, diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs index 6112bc8d..5aa60666 100644 --- a/src/ssl/mod.rs +++ b/src/ssl/mod.rs @@ -33,6 +33,7 @@ fn init() { /// Determines the SSL method supported #[deriving(Show, Hash, PartialEq, Eq)] #[allow(non_camel_case_types)] +#[deriving(Copy)] pub enum SslMethod { #[cfg(feature = "sslv2")] /// Only support the SSLv2 protocol, requires `feature="sslv2"` @@ -68,6 +69,7 @@ impl SslMethod { } /// Determines the type of certificate verification used +#[deriving(Copy)] #[repr(i32)] pub enum SslVerifyMode { /// Verify that the server's certificate is trusted diff --git a/src/x509/mod.rs b/src/x509/mod.rs index a06fe4e1..47294c3d 100644 --- a/src/x509/mod.rs +++ b/src/x509/mod.rs @@ -15,6 +15,7 @@ use ssl::error::{SslError, StreamError}; #[cfg(test)] mod tests; +#[deriving(Copy)] #[repr(i32)] pub enum X509FileType { PEM = ffi::X509_FILETYPE_PEM, @@ -22,6 +23,7 @@ pub enum X509FileType { Default = ffi::X509_FILETYPE_DEFAULT } +#[allow(missing_copy_implementations)] pub struct X509StoreContext { ctx: *mut ffi::X509_STORE_CTX } @@ -54,7 +56,7 @@ trait AsStr<'a> { fn as_str(&self) -> &'a str; } -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub enum KeyUsage { DigitalSignature, NonRepudiation, @@ -84,7 +86,7 @@ impl AsStr<'static> for KeyUsage { } -#[deriving(Clone)] +#[deriving(Clone, Copy)] pub enum ExtKeyUsage { ServerAuth, ClientAuth, @@ -430,6 +432,7 @@ pub struct X509Name<'x> { macro_rules! make_validation_error( ($ok_val:ident, $($name:ident = $val:ident,)+) => ( + #[deriving(Copy)] pub enum X509ValidationError { $($name,)+ X509UnknownError(c_int) From c1e225563d1e8a339a07df9d30649bfd25bfe4ca Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 11 Dec 2014 09:04:27 -0800 Subject: [PATCH 03/16] Clean up Copy impls a bit --- openssl-sys/src/lib.rs | 12 ++++++++---- src/x509/mod.rs | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs index 8550ce33..2a99d710 100644 --- a/openssl-sys/src/lib.rs +++ b/openssl-sys/src/lib.rs @@ -39,7 +39,6 @@ pub type X509_NAME_ENTRY = c_void; pub type X509_REQ = c_void; pub type X509_STORE_CTX = c_void; -#[allow(missing_copy_implementations)] #[repr(C)] pub struct EVP_MD_CTX { digest: *mut EVP_MD, @@ -50,7 +49,8 @@ pub struct EVP_MD_CTX { update: *mut c_void } -#[allow(missing_copy_implementations)] +impl Copy for EVP_MD_CTX {} + #[repr(C)] pub struct HMAC_CTX { md: *mut EVP_MD, @@ -61,7 +61,8 @@ pub struct HMAC_CTX { key: [c_uchar, ..128] } -#[allow(missing_copy_implementations)] +impl Copy for HMAC_CTX {} + #[repr(C)] pub struct X509V3_CTX { flags: c_int, @@ -75,7 +76,8 @@ pub struct X509V3_CTX { // Maybe more here } -#[allow(missing_copy_implementations)] +impl Copy for X509V3_CTX {} + #[repr(C)] pub struct BIGNUM { pub d: *mut c_void, @@ -85,6 +87,8 @@ pub struct BIGNUM { pub flags: c_int, } +impl Copy for BIGNUM {} + pub type CRYPTO_EX_new = extern "C" fn(parent: *mut c_void, ptr: *mut c_void, ad: *const CRYPTO_EX_DATA, idx: c_int, argl: c_long, argp: *const c_void) -> c_int; diff --git a/src/x509/mod.rs b/src/x509/mod.rs index 47294c3d..8baafe41 100644 --- a/src/x509/mod.rs +++ b/src/x509/mod.rs @@ -362,7 +362,7 @@ impl<'ctx> X509<'ctx> { } /// Reads certificate from PEM, takes ownership of handle - pub fn from_pem(reader: &mut Reader) -> Result, SslError> { + pub fn from_pem(reader: &mut R) -> Result, SslError> where R: Reader { let mut mem_bio = try!(MemBio::new()); let buf = try!(reader.read_to_end().map_err(StreamError)); try!(mem_bio.write(buf.as_slice()).map_err(StreamError)); @@ -404,7 +404,7 @@ impl<'ctx> X509<'ctx> { } /// Writes certificate as PEM - pub fn write_pem(&self, writer: &mut Writer) -> Result<(), SslError> { + pub fn write_pem(&self, writer: &mut W) -> Result<(), SslError> where W: Writer{ let mut mem_bio = try!(MemBio::new()); unsafe { try_ssl!(ffi::PEM_write_bio_X509(mem_bio.get_handle(), From 4d49abd102942c6374c83767949ef812a7806ea7 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Fri, 12 Dec 2014 08:05:42 +1000 Subject: [PATCH 04/16] Use static linking on android, which simplifies deployment since loading application specific shared libraries on android requires Java code or other hacks. --- openssl-sys/src/build.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/openssl-sys/src/build.rs b/openssl-sys/src/build.rs index 53c047b2..ca71f791 100644 --- a/openssl-sys/src/build.rs +++ b/openssl-sys/src/build.rs @@ -9,9 +9,14 @@ fn main() { if pkg_config::find_library("openssl").is_err() { - let mut flags = " -l crypto -l ssl".to_string(); - let target = os::getenv("TARGET").unwrap(); + let is_android = target.find_str("android").is_some(); + + let mut flags = if is_android { + " -l crypto:static -l ssl:static" + } else { + " -l crypto -l ssl" + }.to_string(); let win_pos = target.find_str("windows") .or(target.find_str("win32")) @@ -23,7 +28,7 @@ fn main() { flags.push_str(" -l gdi32 -l wsock32"); } - if target.find_str("android").is_some() { + if is_android { let path = os::getenv("OPENSSL_PATH").expect("Android does not provide openssl libraries, please \ build them yourselves (instructions in the README) \ and provide their location through $OPENSSL_PATH."); From 6119d916cb57422d6f51b921f40239dbdf53b4fc Mon Sep 17 00:00:00 2001 From: Valerii Hiora Date: Mon, 15 Dec 2014 14:01:17 +0200 Subject: [PATCH 06/16] Track master: proc removal, tuple indexing --- src/ssl/mod.rs | 2 +- src/ssl/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs index 5aa60666..8930a3c5 100644 --- a/src/ssl/mod.rs +++ b/src/ssl/mod.rs @@ -541,7 +541,7 @@ impl Writer for SslStream { let mut start = 0; while start < buf.len() { let ret = self.in_retry_wrapper(|ssl| { - ssl.write(buf.split_at(start).val1()) + ssl.write(buf.split_at(start).1) }); match ret { Ok(len) => start += len as uint, diff --git a/src/ssl/tests.rs b/src/ssl/tests.rs index e4414f84..127b87d1 100644 --- a/src/ssl/tests.rs +++ b/src/ssl/tests.rs @@ -198,7 +198,7 @@ fn test_clone() { let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut stream = SslStream::new(&SslContext::new(Sslv23).unwrap(), stream).unwrap(); let mut stream2 = stream.clone(); - spawn(proc() { + spawn(move || { stream2.write("GET /\r\n\r\n".as_bytes()).unwrap(); stream2.flush().unwrap(); }); From 1dc66d948676b434690f866cb226fe4178dcd42d Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 15 Dec 2014 09:26:34 -0800 Subject: [PATCH 07/16] Release v0.2.4 --- Cargo.toml | 4 ++-- openssl-sys/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 321873e9..3b3571e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl" -version = "0.2.3" +version = "0.2.4" authors = ["Steven Fackler "] license = "Apache-2.0" description = "OpenSSL bindings" @@ -17,4 +17,4 @@ aes_xts = ["openssl-sys/aes_xts"] [dependencies.openssl-sys] path = "openssl-sys" -version = "0.2.3" +version = "0.2.4" diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index 60ebc8c3..095088a6 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl-sys" -version = "0.2.3" +version = "0.2.4" authors = ["Alex Crichton ", "Steven Fackler "] license = "MIT" From 01a5d7cc56244e72ea760d47844da1f399978b05 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Dec 2014 08:14:50 -0800 Subject: [PATCH 08/16] Update to rust master --- src/bn/mod.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/bn/mod.rs b/src/bn/mod.rs index 069c6b22..b409cb73 100644 --- a/src/bn/mod.rs +++ b/src/bn/mod.rs @@ -407,45 +407,45 @@ pub mod unchecked { use ffi; use super::{BigNum}; - impl Add for BigNum { - fn add(&self, oth: &BigNum) -> BigNum { + impl<'a> Add<&'a BigNum, BigNum> for &'a BigNum { + fn add(self, oth: &'a BigNum) -> BigNum { self.checked_add(oth).unwrap() } } - impl Sub for BigNum { - fn sub(&self, oth: &BigNum) -> BigNum { + impl<'a> Sub<&'a BigNum, BigNum> for &'a BigNum { + fn sub(self, oth: &'a BigNum) -> BigNum { self.checked_sub(oth).unwrap() } } - impl Mul for BigNum { - fn mul(&self, oth: &BigNum) -> BigNum { + impl<'a> Mul<&'a BigNum, BigNum> for &'a BigNum { + fn mul(self, oth: &'a BigNum) -> BigNum { self.checked_mul(oth).unwrap() } } - impl Div for BigNum { - fn div(&self, oth: &BigNum) -> BigNum { + impl<'a> Div<&'a BigNum, BigNum> for &'a BigNum { + fn div(self, oth: &'a BigNum) -> BigNum { self.checked_div(oth).unwrap() } } - impl Rem for BigNum { - fn rem(&self, oth: &BigNum) -> BigNum { + impl<'a> Rem<&'a BigNum, BigNum> for &'a BigNum { + fn rem(self, oth: &'a BigNum) -> BigNum { self.checked_mod(oth).unwrap() } } - impl Shl for BigNum { - fn shl(&self, n: &i32) -> BigNum { - self.checked_shl(n).unwrap() + impl<'a> Shl for &'a BigNum { + fn shl(self, n: i32) -> BigNum { + self.checked_shl(&n).unwrap() } } - impl Shr for BigNum { - fn shr(&self, n: &i32) -> BigNum { - self.checked_shr(n).unwrap() + impl<'a> Shr for &'a BigNum { + fn shr(self, n: i32) -> BigNum { + self.checked_shr(&n).unwrap() } } From ada2398b758c9c46fd4beb7ef2e2f675e6d5c1e4 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 16 Dec 2014 08:58:07 -0800 Subject: [PATCH 09/16] Release v0.2.5 --- Cargo.toml | 4 ++-- openssl-sys/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b3571e5..d6f2d140 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl" -version = "0.2.4" +version = "0.2.5" authors = ["Steven Fackler "] license = "Apache-2.0" description = "OpenSSL bindings" @@ -17,4 +17,4 @@ aes_xts = ["openssl-sys/aes_xts"] [dependencies.openssl-sys] path = "openssl-sys" -version = "0.2.4" +version = "0.2.5" diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index 095088a6..ca081425 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl-sys" -version = "0.2.4" +version = "0.2.5" authors = ["Alex Crichton ", "Steven Fackler "] license = "MIT" From a637f2b0bfaa077e1e56edc83d76677bccff09c6 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Fri, 19 Dec 2014 10:45:19 -0500 Subject: [PATCH 10/16] Updated for language changes to macros. --- src/bn/mod.rs | 6 +++--- src/crypto/hmac.rs | 2 +- src/x509/mod.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bn/mod.rs b/src/bn/mod.rs index b409cb73..721fcea5 100644 --- a/src/bn/mod.rs +++ b/src/bn/mod.rs @@ -26,7 +26,7 @@ macro_rules! with_ctx( r } }); -) +); macro_rules! with_bn( ($name:ident, $action:block) => ({ @@ -42,7 +42,7 @@ macro_rules! with_bn( Err(err) => Err(err), } }); -) +); macro_rules! with_bn_in_ctx( ($name:ident, $ctx_name:ident, $action:block) => ({ @@ -66,7 +66,7 @@ macro_rules! with_bn_in_ctx( Err(err) => Err(err), } }); -) +); impl BigNum { pub fn new() -> Result { diff --git a/src/crypto/hmac.rs b/src/crypto/hmac.rs index 8096a948..aab0c014 100644 --- a/src/crypto/hmac.rs +++ b/src/crypto/hmac.rs @@ -55,7 +55,7 @@ impl HMAC { let mut res = Vec::from_elem(self.len, 0u8); let mut outlen = 0; ffi::HMAC_Final(&mut self.ctx, res.as_mut_ptr(), &mut outlen); - assert!(self.len == outlen as uint) + assert!(self.len == outlen as uint); res } } diff --git a/src/x509/mod.rs b/src/x509/mod.rs index 8baafe41..c82eab11 100644 --- a/src/x509/mod.rs +++ b/src/x509/mod.rs @@ -449,7 +449,7 @@ macro_rules! make_validation_error( } } ) -) +); make_validation_error!(X509_V_OK, X509UnableToGetIssuerCert = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT, @@ -505,7 +505,7 @@ make_validation_error!(X509_V_OK, X509UnsupportedNameSyntax = X509_V_ERR_UNSUPPORTED_NAME_SYNTAX, X509CrlPathValidationError= X509_V_ERR_CRL_PATH_VALIDATION_ERROR, X509ApplicationVerification = X509_V_ERR_APPLICATION_VERIFICATION, -) +); #[test] From 1392970360b5f71734fdc4069b36f6c267a51745 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 19 Dec 2014 08:22:08 -0800 Subject: [PATCH 11/16] Release v0.2.6 --- Cargo.toml | 4 ++-- openssl-sys/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d6f2d140..257c1744 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl" -version = "0.2.5" +version = "0.2.6" authors = ["Steven Fackler "] license = "Apache-2.0" description = "OpenSSL bindings" @@ -17,4 +17,4 @@ aes_xts = ["openssl-sys/aes_xts"] [dependencies.openssl-sys] path = "openssl-sys" -version = "0.2.5" +version = "0.2.6" diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index ca081425..c77e3ccf 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl-sys" -version = "0.2.5" +version = "0.2.6" authors = ["Alex Crichton ", "Steven Fackler "] license = "MIT" From 217dad59dfbed952aa3eb0b18045dfbc1fe61b67 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 19 Dec 2014 19:56:31 -0800 Subject: [PATCH 12/16] Print unexpected error codes This is breaking occaisionally but I can't repro it locally :( --- src/ssl/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs index 8930a3c5..b0db32ea 100644 --- a/src/ssl/mod.rs +++ b/src/ssl/mod.rs @@ -384,7 +384,7 @@ impl Ssl { } -#[deriving(FromPrimitive)] +#[deriving(FromPrimitive, Show)] #[repr(i32)] enum LibSslError { ErrorNone = ffi::SSL_ERROR_NONE, @@ -489,7 +489,7 @@ impl SslStream { LibSslError::ErrorWantWrite => { try_ssl_stream!(self.flush()) } LibSslError::ErrorZeroReturn => return Err(SslSessionClosed), LibSslError::ErrorSsl => return Err(SslError::get()), - _ => unreachable!() + err => panic!("unexpected error {}", err), } } } From e2fa62e2ae7bce4bee4744aa8ea440d8777e6890 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Sun, 21 Dec 2014 08:52:12 -0500 Subject: [PATCH 13/16] Replaced now removed NativeMutex with StaticMutex, and fixed Neg implementation for BigNum. --- openssl-sys/src/lib.rs | 14 ++++++++------ src/bn/mod.rs | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs index 2a99d710..104f71b5 100644 --- a/openssl-sys/src/lib.rs +++ b/openssl-sys/src/lib.rs @@ -2,7 +2,6 @@ #![allow(dead_code)] extern crate libc; -extern crate rustrt; #[cfg(feature = "libressl-pnacl-sys")] extern crate "libressl-pnacl-sys" as _for_linkage; @@ -10,7 +9,7 @@ extern crate "libressl-pnacl-sys" as _for_linkage; use libc::{c_void, c_int, c_char, c_ulong, c_long, c_uint, c_uchar, size_t}; use std::mem; use std::ptr; -use rustrt::mutex::NativeMutex; +use std::sync::{StaticMutex, StaticMutexGuard, MUTEX_INIT}; use std::sync::{Once, ONCE_INIT}; pub type ASN1_INTEGER = c_void; @@ -192,7 +191,8 @@ pub const X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE: c_int = 45; pub const X509_V_ERR_UNSUPPORTED_NAME_SYNTAX: c_int = 53; pub const X509_V_OK: c_int = 0; -static mut MUTEXES: *mut Vec = 0 as *mut Vec; +static mut MUTEXES: *mut Vec = 0 as *mut Vec; +static mut GUARDS: *mut Vec> = 0 as *mut Vec>; extern fn locking_function(mode: c_int, n: c_int, _file: *const c_char, _line: c_int) { @@ -200,9 +200,9 @@ extern fn locking_function(mode: c_int, n: c_int, _file: *const c_char, let mutex = &(*MUTEXES)[n as uint]; if mode & CRYPTO_LOCK != 0 { - mutex.lock_noguard(); + (*GUARDS)[n as uint] = Some(mutex.lock()); } else { - mutex.unlock_noguard(); + &(*GUARDS)[n as uint].take(); } } } @@ -216,8 +216,10 @@ pub fn init() { SSL_load_error_strings(); let num_locks = CRYPTO_num_locks(); - let mutexes = box Vec::from_fn(num_locks as uint, |_| NativeMutex::new()); + let mutexes = box Vec::from_fn(num_locks as uint, |_| MUTEX_INIT); MUTEXES = mem::transmute(mutexes); + let guards: Box>> = box Vec::from_fn(num_locks as uint, |_| None); + GUARDS = mem::transmute(guards); CRYPTO_set_locking_callback(locking_function); }) diff --git a/src/bn/mod.rs b/src/bn/mod.rs index 721fcea5..bcf6c104 100644 --- a/src/bn/mod.rs +++ b/src/bn/mod.rs @@ -463,7 +463,7 @@ pub mod unchecked { } impl Neg for BigNum { - fn neg(&self) -> BigNum { + fn neg(self) -> BigNum { let mut n = self.clone(); n.negate(); n From 12d31ade9dca8006b23e36d7631e9113f6234fc0 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 21 Dec 2014 13:36:35 -0500 Subject: [PATCH 14/16] Release v0.2.7 --- Cargo.toml | 4 ++-- openssl-sys/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 257c1744..ada356f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl" -version = "0.2.6" +version = "0.2.7" authors = ["Steven Fackler "] license = "Apache-2.0" description = "OpenSSL bindings" @@ -17,4 +17,4 @@ aes_xts = ["openssl-sys/aes_xts"] [dependencies.openssl-sys] path = "openssl-sys" -version = "0.2.6" +version = "0.2.7" diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index c77e3ccf..d15f53bd 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl-sys" -version = "0.2.6" +version = "0.2.7" authors = ["Alex Crichton ", "Steven Fackler "] license = "MIT" From 7774e672a2c190dcf7a594882620b1fb607a3c13 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 23 Dec 2014 08:14:42 -0800 Subject: [PATCH 15/16] Update to rust master --- src/crypto/hash.rs | 2 +- src/ssl/mod.rs | 11 ++++++++--- src/ssl/tests.rs | 21 +++++++++++---------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/crypto/hash.rs b/src/crypto/hash.rs index 37573368..2a181526 100644 --- a/src/crypto/hash.rs +++ b/src/crypto/hash.rs @@ -135,7 +135,7 @@ mod tests { } fn compare(calced_raw: Vec, hashtest: &HashTest) { - let calced = calced_raw.as_slice().to_hex().into_string(); + let calced = calced_raw.as_slice().to_hex().to_string(); if calced != hashtest.expected_output { println!("Test failed - {} != {}", calced, hashtest.expected_output); diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs index b0db32ea..43673596 100644 --- a/src/ssl/mod.rs +++ b/src/ssl/mod.rs @@ -93,8 +93,9 @@ fn get_verify_data_idx() -> c_int { unsafe { INIT.doit(|| { + let f: ffi::CRYPTO_EX_free = free_data_box::; let idx = ffi::SSL_CTX_get_ex_new_index(0, ptr::null(), None, - None, Some(free_data_box::)); + None, Some(f)); assert!(idx >= 0); VERIFY_DATA_IDX = idx; }); @@ -199,7 +200,9 @@ impl SslContext { unsafe { ffi::SSL_CTX_set_ex_data(self.ctx, VERIFY_IDX, mem::transmute(verify)); - ffi::SSL_CTX_set_verify(self.ctx, mode as c_int, Some(raw_verify)); + let f: extern fn(c_int, *mut ffi::X509_STORE_CTX) -> c_int = + raw_verify; + ffi::SSL_CTX_set_verify(self.ctx, mode as c_int, Some(f)); } } @@ -216,7 +219,9 @@ impl SslContext { mem::transmute(Some(verify))); ffi::SSL_CTX_set_ex_data(self.ctx, get_verify_data_idx::(), mem::transmute(data)); - ffi::SSL_CTX_set_verify(self.ctx, mode as c_int, Some(raw_verify_with_data::)); + let f: extern fn(c_int, *mut ffi::X509_STORE_CTX) -> c_int = + raw_verify_with_data::; + ffi::SSL_CTX_set_verify(self.ctx, mode as c_int, Some(f)); } } diff --git a/src/ssl/tests.rs b/src/ssl/tests.rs index 127b87d1..6723fa58 100644 --- a/src/ssl/tests.rs +++ b/src/ssl/tests.rs @@ -1,10 +1,11 @@ use serialize::hex::FromHex; -use std::io::{Writer}; use std::io::net::tcp::TcpStream; +use std::io::{Writer}; +use std::thread::Thread; use crypto::hash::HashType::{SHA256}; use ssl::SslMethod::Sslv23; -use ssl::{SslContext, SslStream}; +use ssl::{SslContext, SslStream, VerifyCallback}; use ssl::SslVerifyMode::SslVerifyPeer; use x509::{X509StoreContext}; @@ -52,7 +53,7 @@ fn test_verify_untrusted_callback_override_ok() { } let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut ctx = SslContext::new(Sslv23).unwrap(); - ctx.set_verify(SslVerifyPeer, Some(callback)); + ctx.set_verify(SslVerifyPeer, Some(callback as VerifyCallback)); match SslStream::new(&ctx, stream) { Ok(_) => (), Err(err) => panic!("Expected success, got {}", err) @@ -66,7 +67,7 @@ fn test_verify_untrusted_callback_override_bad() { } let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut ctx = SslContext::new(Sslv23).unwrap(); - ctx.set_verify(SslVerifyPeer, Some(callback)); + ctx.set_verify(SslVerifyPeer, Some(callback as VerifyCallback)); assert!(SslStream::new(&ctx, stream).is_err()); } @@ -77,7 +78,7 @@ fn test_verify_trusted_callback_override_ok() { } let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut ctx = SslContext::new(Sslv23).unwrap(); - ctx.set_verify(SslVerifyPeer, Some(callback)); + ctx.set_verify(SslVerifyPeer, Some(callback as VerifyCallback)); match ctx.set_CA_file(&Path::new("test/cert.pem")) { None => {} Some(err) => panic!("Unexpected error {}", err) @@ -95,7 +96,7 @@ fn test_verify_trusted_callback_override_bad() { } let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut ctx = SslContext::new(Sslv23).unwrap(); - ctx.set_verify(SslVerifyPeer, Some(callback)); + ctx.set_verify(SslVerifyPeer, Some(callback as VerifyCallback)); match ctx.set_CA_file(&Path::new("test/cert.pem")) { None => {} Some(err) => panic!("Unexpected error {}", err) @@ -111,7 +112,7 @@ fn test_verify_callback_load_certs() { } let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut ctx = SslContext::new(Sslv23).unwrap(); - ctx.set_verify(SslVerifyPeer, Some(callback)); + ctx.set_verify(SslVerifyPeer, Some(callback as VerifyCallback)); assert!(SslStream::new(&ctx, stream).is_ok()); } @@ -123,7 +124,7 @@ fn test_verify_trusted_get_error_ok() { } let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut ctx = SslContext::new(Sslv23).unwrap(); - ctx.set_verify(SslVerifyPeer, Some(callback)); + ctx.set_verify(SslVerifyPeer, Some(callback as VerifyCallback)); match ctx.set_CA_file(&Path::new("test/cert.pem")) { None => {} Some(err) => panic!("Unexpected error {}", err) @@ -139,7 +140,7 @@ fn test_verify_trusted_get_error_err() { } let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut ctx = SslContext::new(Sslv23).unwrap(); - ctx.set_verify(SslVerifyPeer, Some(callback)); + ctx.set_verify(SslVerifyPeer, Some(callback as VerifyCallback)); assert!(SslStream::new(&ctx, stream).is_err()); } @@ -198,7 +199,7 @@ fn test_clone() { let stream = TcpStream::connect("127.0.0.1:15418").unwrap(); let mut stream = SslStream::new(&SslContext::new(Sslv23).unwrap(), stream).unwrap(); let mut stream2 = stream.clone(); - spawn(move || { + let _t = Thread::spawn(move || { stream2.write("GET /\r\n\r\n".as_bytes()).unwrap(); stream2.flush().unwrap(); }); From 49a72ae9217c1d24e97445b9862da8eec7d86819 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 23 Dec 2014 11:58:05 -0500 Subject: [PATCH 16/16] Release v0.2.8 --- Cargo.toml | 4 ++-- openssl-sys/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ada356f7..c56b593d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl" -version = "0.2.7" +version = "0.2.8" authors = ["Steven Fackler "] license = "Apache-2.0" description = "OpenSSL bindings" @@ -17,4 +17,4 @@ aes_xts = ["openssl-sys/aes_xts"] [dependencies.openssl-sys] path = "openssl-sys" -version = "0.2.7" +version = "0.2.8" diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index d15f53bd..b9695f49 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openssl-sys" -version = "0.2.7" +version = "0.2.8" authors = ["Alex Crichton ", "Steven Fackler "] license = "MIT"