From 9436027866412bbb73f56a0b8427f431bbfcc4b3 Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Fri, 18 Dec 2015 23:18:03 +0200 Subject: [PATCH 1/7] Fix Cargo.toml to actually depend on gdi32-sys and user32-sys --- openssl-sys/Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index eee9312c..91465667 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -40,15 +40,15 @@ libressl-pnacl-sys = "2.1.0" libressl-pnacl-sys = "2.1.0" # Only here to make sure we link to these in a static build on Windows -[target.i686-pc-windows-gnu] +[target.i686-pc-windows-gnu.dependencies] user32-sys = "0.1" gdi32-sys = "0.1" -[target.x86_64-pc-windows-gnu] +[target.x86_64-pc-windows-gnu.dependencies] user32-sys = "0.1" gdi32-sys = "0.1" -[target.i686-pc-windows-msvc] +[target.i686-pc-windows-msvc.dependencies] user32-sys = "0.1" gdi32-sys = "0.1" -[target.x86_64-pc-windows-msvc] +[target.x86_64-pc-windows-msvc.dependencies] user32-sys = "0.1" gdi32-sys = "0.1" From e85b49d3755375b3e535cbd4b07d4fbf953948cb Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 18 Dec 2015 21:19:16 -0800 Subject: [PATCH 2/7] Work around the worst of clone bogusness SslStream::{clone,try_clone} are inherently broken since the Ssl object shared by both streams is only going to be talking to one stream. Stuff like hyper depends on try_clone, so we'll leave it here for now but minimize the brokenness to "no worse than what it used to be like". They'll be removed in 0.8. cc #325 --- openssl/src/ssl/bio.rs | 38 +++++++++--------------------------- openssl/src/ssl/mod.rs | 34 +++++++++++++++++++------------- openssl/src/ssl/tests/mod.rs | 8 ++++++++ 3 files changed, 37 insertions(+), 43 deletions(-) diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs index ef63d146..99d9af0a 100644 --- a/openssl/src/ssl/bio.rs +++ b/openssl/src/ssl/bio.rs @@ -6,35 +6,20 @@ use std::io::prelude::*; use std::mem; use std::slice; use std::ptr; +use std::sync::Arc; use ssl::error::SslError; // "rust" const NAME: [c_char; 5] = [114, 117, 115, 116, 0]; -// we use this after removing the stream from the BIO so that we don't have to -// worry about freeing the heap allocated BIO_METHOD after freeing the BIO. -static DESTROY_METHOD: BIO_METHOD = BIO_METHOD { - type_: BIO_TYPE_NONE, - name: &NAME[0], - bwrite: None, - bread: None, - bputs: None, - bgets: None, - ctrl: None, - create: None, - destroy: Some(destroy), - callback_ctrl: None, -}; - pub struct StreamState { pub stream: S, pub error: Option, } -pub fn new(stream: S) -> Result<(*mut BIO, Box), SslError> { - - let method = Box::new(BIO_METHOD { +pub fn new(stream: S) -> Result<(*mut BIO, Arc), SslError> { + let method = Arc::new(BIO_METHOD { type_: BIO_TYPE_NONE, name: &NAME[0], bwrite: Some(bwrite::), @@ -43,7 +28,7 @@ pub fn new(stream: S) -> Result<(*mut BIO, Box), Ss bgets: None, ctrl: Some(ctrl::), create: Some(create), - destroy: None, // covered in the replacement BIO_METHOD + destroy: Some(destroy::), callback_ctrl: None, }); @@ -66,14 +51,6 @@ pub unsafe fn take_error(bio: *mut BIO) -> Option { state.error.take() } -pub unsafe fn take_stream(bio: *mut BIO) -> S { - let state: Box> = Box::from_raw((*bio).ptr as *mut _); - (*bio).ptr = ptr::null_mut(); - (*bio).method = &DESTROY_METHOD as *const _ as *mut _; - (*bio).init = 0; - state.stream -} - pub unsafe fn get_ref<'a, S: 'a>(bio: *mut BIO) -> &'a S { let state: &'a StreamState = mem::transmute((*bio).ptr); &state.stream @@ -159,11 +136,14 @@ unsafe extern "C" fn create(bio: *mut BIO) -> c_int { 1 } -unsafe extern "C" fn destroy(bio: *mut BIO) -> c_int { +unsafe extern "C" fn destroy(bio: *mut BIO) -> c_int { if bio.is_null() { return 0; } - assert!((*bio).ptr.is_null()); + assert!(!(*bio).ptr.is_null()); + Box::>::from_raw((*bio).ptr as *mut _); + (*bio).ptr = ptr::null_mut(); + (*bio).init = 0; 1 } diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index d529347f..b4385290 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -10,7 +10,7 @@ use std::str; use std::net; use std::path::Path; use std::ptr; -use std::sync::{Once, ONCE_INIT, Mutex}; +use std::sync::{Once, ONCE_INIT, Mutex, Arc}; use std::cmp; use std::any::Any; #[cfg(any(feature = "npn", feature = "alpn"))] @@ -778,6 +778,7 @@ impl Drop for Ssl { } impl Clone for Ssl { + /// # Deprecated fn clone(&self) -> Ssl { unsafe { rust_SSL_clone(self.ssl) }; Ssl { ssl: self.ssl } @@ -1003,23 +1004,22 @@ make_LibSslError! { /// A stream wrapper which handles SSL encryption for an underlying stream. pub struct SslStream { ssl: Ssl, - _method: Box, // :( + _method: Arc, // NOTE: this *must* be after the Ssl field so things drop right _p: PhantomData, } unsafe impl Send for SslStream {} impl Clone for SslStream { + /// # Deprecated + /// + /// This method does not behave as expected and will be removed in a future + /// release. fn clone(&self) -> SslStream { - let stream = self.get_ref().clone(); - Self::new_base(self.ssl.clone(), stream) - } -} - -impl Drop for SslStream { - fn drop(&mut self) { - unsafe { - let _ = bio::take_stream::(self.ssl.get_raw_rbio()); + SslStream { + ssl: self.ssl.clone(), + _method: self._method.clone(), + _p: PhantomData, } } } @@ -1232,10 +1232,16 @@ impl SslStream { } impl SslStream<::std::net::TcpStream> { - /// Like `TcpStream::try_clone`. + /// # Deprecated + /// + /// This method does not behave as expected and will be removed in a future + /// release. pub fn try_clone(&self) -> io::Result> { - let stream = try!(self.get_ref().try_clone()); - Ok(Self::new_base(self.ssl.clone(), stream)) + Ok(SslStream { + ssl: self.ssl.clone(), + _method: self._method.clone(), + _p: PhantomData + }) } } diff --git a/openssl/src/ssl/tests/mod.rs b/openssl/src/ssl/tests/mod.rs index 7ed8fc3b..af3c005e 100644 --- a/openssl/src/ssl/tests/mod.rs +++ b/openssl/src/ssl/tests/mod.rs @@ -949,3 +949,11 @@ fn test_read_nonblocking() { assert!(bytes_read >= 5); assert_eq!(&input_buffer[..5], b"HTTP/"); } + +#[test] +fn broken_try_clone_doesnt_crash() { + let context = SslContext::new(SslMethod::Sslv23).unwrap(); + let inner = TcpStream::connect("example.com:443").unwrap(); + let stream1 = SslStream::connect(&context, inner).unwrap(); + let _stream2 = stream1.try_clone().unwrap(); +} From 2a66e858bad76d7650980eaa39863490cba3e30e Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 18 Dec 2015 22:14:32 -0800 Subject: [PATCH 3/7] Add a script to build docs with all features enabled --- build_docs.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 build_docs.sh diff --git a/build_docs.sh b/build_docs.sh new file mode 100755 index 00000000..3cfe1b79 --- /dev/null +++ b/build_docs.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +export CARGO_TARGET_DIR=target + +for toml in $(find . -maxdepth 2 -name "Cargo.toml"); do + cargo update --manifest-path $toml || true + features=$(cargo read-manifest --manifest-path $toml | jq -r '.features|keys|join(" ")') + cargo doc --verbose --no-deps --manifest-path $toml --features "$features" +done From 4f0a7e24d16dcdc7587293c35b227b9bd7963e2e Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 18 Dec 2015 22:20:57 -0800 Subject: [PATCH 4/7] Drop verbose flag --- build_docs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_docs.sh b/build_docs.sh index 3cfe1b79..c41fd675 100755 --- a/build_docs.sh +++ b/build_docs.sh @@ -6,5 +6,5 @@ export CARGO_TARGET_DIR=target for toml in $(find . -maxdepth 2 -name "Cargo.toml"); do cargo update --manifest-path $toml || true features=$(cargo read-manifest --manifest-path $toml | jq -r '.features|keys|join(" ")') - cargo doc --verbose --no-deps --manifest-path $toml --features "$features" + cargo doc --no-deps --manifest-path $toml --features "$features" done From a31acdbb93988638afb1d3c211e5ef6a3219a30c Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 18 Dec 2015 22:21:23 -0800 Subject: [PATCH 5/7] Fix deprecation location --- openssl/src/ssl/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index b4385290..ec37bf0f 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -1010,11 +1010,11 @@ pub struct SslStream { unsafe impl Send for SslStream {} +/// # Deprecated +/// +/// This method does not behave as expected and will be removed in a future +/// release. impl Clone for SslStream { - /// # Deprecated - /// - /// This method does not behave as expected and will be removed in a future - /// release. fn clone(&self) -> SslStream { SslStream { ssl: self.ssl.clone(), From 11129aa5214b7ed70027368d52715c7d4e2247c2 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 18 Dec 2015 22:34:30 -0800 Subject: [PATCH 6/7] Rustfmt --- openssl/src/ssl/bio.rs | 2 +- openssl/src/ssl/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs index 99d9af0a..a361ae81 100644 --- a/openssl/src/ssl/bio.rs +++ b/openssl/src/ssl/bio.rs @@ -101,7 +101,7 @@ unsafe extern "C" fn bread(bio: *mut BIO, buf: *mut c_char, len: c_int) fn retriable_error(err: &io::Error) -> bool { match err.kind() { io::ErrorKind::WouldBlock | io::ErrorKind::NotConnected => true, - _ => false + _ => false, } } diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index ec37bf0f..955f10fd 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -1240,7 +1240,7 @@ impl SslStream<::std::net::TcpStream> { Ok(SslStream { ssl: self.ssl.clone(), _method: self._method.clone(), - _p: PhantomData + _p: PhantomData, }) } } From 926c8167beff5422f0a7526a03fdce1052499153 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 18 Dec 2015 22:41:46 -0800 Subject: [PATCH 7/7] Release v0.7.4 --- openssl-sys-extras/Cargo.toml | 6 +++--- openssl-sys-extras/src/lib.rs | 2 +- openssl-sys/Cargo.toml | 4 ++-- openssl-sys/src/lib.rs | 2 +- openssl/Cargo.toml | 8 ++++---- openssl/src/lib.rs | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openssl-sys-extras/Cargo.toml b/openssl-sys-extras/Cargo.toml index cf037fe1..01a49e78 100644 --- a/openssl-sys-extras/Cargo.toml +++ b/openssl-sys-extras/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "openssl-sys-extras" -version = "0.7.3" +version = "0.7.4" authors = ["Steven Fackler "] license = "MIT" description = "Extra FFI bindings to OpenSSL that require a C shim" repository = "https://github.com/sfackler/rust-openssl" -documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.3/openssl_sys_extras" +documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.4/openssl_sys_extras" build = "build.rs" [features] @@ -13,7 +13,7 @@ ecdh_auto = [] [dependencies] libc = "0.2" -openssl-sys = { version = "0.7.3", path = "../openssl-sys" } +openssl-sys = { version = "0.7.4", path = "../openssl-sys" } [build-dependencies] gcc = "0.3" diff --git a/openssl-sys-extras/src/lib.rs b/openssl-sys-extras/src/lib.rs index 4fab0740..6097155a 100644 --- a/openssl-sys-extras/src/lib.rs +++ b/openssl-sys-extras/src/lib.rs @@ -1,5 +1,5 @@ #![allow(non_upper_case_globals, non_snake_case)] -#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.3")] +#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.4")] extern crate openssl_sys; extern crate libc; diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index 91465667..735c4d51 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "openssl-sys" -version = "0.7.3" +version = "0.7.4" authors = ["Alex Crichton ", "Steven Fackler "] license = "MIT" description = "FFI bindings to OpenSSL" repository = "https://github.com/sfackler/rust-openssl" -documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.3/openssl_sys" +documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.4/openssl_sys" links = "openssl" build = "build.rs" diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs index 91cbb13c..f780b6d9 100644 --- a/openssl-sys/src/lib.rs +++ b/openssl-sys/src/lib.rs @@ -1,6 +1,6 @@ #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] #![allow(dead_code)] -#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.3")] +#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.4")] extern crate libc; diff --git a/openssl/Cargo.toml b/openssl/Cargo.toml index 30121fe2..9c56623e 100644 --- a/openssl/Cargo.toml +++ b/openssl/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "openssl" -version = "0.7.3" +version = "0.7.4" authors = ["Steven Fackler "] license = "Apache-2.0" description = "OpenSSL bindings" repository = "https://github.com/sfackler/rust-openssl" -documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.3/openssl" +documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.4/openssl" readme = "../README.md" keywords = ["crypto", "tls", "ssl", "dtls"] build = "build.rs" @@ -29,8 +29,8 @@ pkcs5_pbkdf2_hmac = ["openssl-sys/pkcs5_pbkdf2_hmac"] bitflags = ">= 0.2, < 0.4" lazy_static = "0.1" libc = "0.2" -openssl-sys = { version = "0.7.3", path = "../openssl-sys" } -openssl-sys-extras = { version = "0.7.3", path = "../openssl-sys-extras" } +openssl-sys = { version = "0.7.4", path = "../openssl-sys" } +openssl-sys-extras = { version = "0.7.4", path = "../openssl-sys-extras" } [build-dependencies] gcc = "0.3" diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index 942589e7..88b67d97 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.3")] +#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.4")] #[macro_use] extern crate bitflags;