Merge branch 'release-v0.7.9' into release

This commit is contained in:
Steven Fackler 2016-04-06 21:34:26 -07:00
commit a25f115360
11 changed files with 63 additions and 52 deletions

View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/sfackler/rust-openssl.svg?branch=master)](https://travis-ci.org/sfackler/rust-openssl) [![Build Status](https://travis-ci.org/sfackler/rust-openssl.svg?branch=master)](https://travis-ci.org/sfackler/rust-openssl)
[Documentation](https://sfackler.github.io/rust-openssl/doc/v0.7.8/openssl). [Documentation](https://sfackler.github.io/rust-openssl/doc/v0.7.9/openssl).
## Building ## Building

View File

@ -1,11 +1,11 @@
[package] [package]
name = "openssl-sys-extras" name = "openssl-sys-extras"
version = "0.7.8" version = "0.7.9"
authors = ["Steven Fackler <sfackler@gmail.com>"] authors = ["Steven Fackler <sfackler@gmail.com>"]
license = "MIT" license = "MIT"
description = "Extra FFI bindings to OpenSSL that require a C shim" description = "Extra FFI bindings to OpenSSL that require a C shim"
repository = "https://github.com/sfackler/rust-openssl" repository = "https://github.com/sfackler/rust-openssl"
documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.8/openssl_sys_extras" documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.9/openssl_sys_extras"
build = "build.rs" build = "build.rs"
[features] [features]
@ -13,7 +13,7 @@ ecdh_auto = []
[dependencies] [dependencies]
libc = "0.2" libc = "0.2"
openssl-sys = { version = "0.7.8", path = "../openssl-sys" } openssl-sys = { version = "0.7.9", path = "../openssl-sys" }
[build-dependencies] [build-dependencies]
gcc = "0.3" gcc = "0.3"

View File

@ -1,5 +1,5 @@
#![allow(non_upper_case_globals, non_snake_case)] #![allow(non_upper_case_globals, non_snake_case)]
#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.8")] #![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.9")]
extern crate openssl_sys; extern crate openssl_sys;
extern crate libc; extern crate libc;

View File

@ -1,12 +1,12 @@
[package] [package]
name = "openssl-sys" name = "openssl-sys"
version = "0.7.8" version = "0.7.9"
authors = ["Alex Crichton <alex@alexcrichton.com>", authors = ["Alex Crichton <alex@alexcrichton.com>",
"Steven Fackler <sfackler@gmail.com>"] "Steven Fackler <sfackler@gmail.com>"]
license = "MIT" license = "MIT"
description = "FFI bindings to OpenSSL" description = "FFI bindings to OpenSSL"
repository = "https://github.com/sfackler/rust-openssl" repository = "https://github.com/sfackler/rust-openssl"
documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.8/openssl_sys" documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.9/openssl_sys"
links = "openssl" links = "openssl"
build = "build.rs" build = "build.rs"

View File

@ -1,6 +1,6 @@
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
#![allow(dead_code)] #![allow(dead_code)]
#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.8")] #![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.9")]
extern crate libc; extern crate libc;
@ -548,6 +548,7 @@ extern "C" {
pub fn EVP_PKEY_new() -> *mut EVP_PKEY; pub fn EVP_PKEY_new() -> *mut EVP_PKEY;
pub fn EVP_PKEY_free(k: *mut EVP_PKEY); pub fn EVP_PKEY_free(k: *mut EVP_PKEY);
pub fn EVP_PKEY_assign(pkey: *mut EVP_PKEY, typ: c_int, key: *const c_void) -> c_int; pub fn EVP_PKEY_assign(pkey: *mut EVP_PKEY, typ: c_int, key: *const c_void) -> c_int;
pub fn EVP_PKEY_copy_parameters(to: *mut EVP_PKEY, from: *const EVP_PKEY) -> c_int;
pub fn EVP_PKEY_get1_RSA(k: *mut EVP_PKEY) -> *mut RSA; pub fn EVP_PKEY_get1_RSA(k: *mut EVP_PKEY) -> *mut RSA;
pub fn EVP_PKEY_set1_RSA(k: *mut EVP_PKEY, r: *mut RSA) -> c_int; pub fn EVP_PKEY_set1_RSA(k: *mut EVP_PKEY, r: *mut RSA) -> c_int;
pub fn EVP_PKEY_cmp(a: *const EVP_PKEY, b: *const EVP_PKEY) -> c_int; pub fn EVP_PKEY_cmp(a: *const EVP_PKEY, b: *const EVP_PKEY) -> c_int;

View File

@ -1,11 +1,11 @@
[package] [package]
name = "openssl" name = "openssl"
version = "0.7.8" version = "0.7.9"
authors = ["Steven Fackler <sfackler@gmail.com>"] authors = ["Steven Fackler <sfackler@gmail.com>"]
license = "Apache-2.0" license = "Apache-2.0"
description = "OpenSSL bindings" description = "OpenSSL bindings"
repository = "https://github.com/sfackler/rust-openssl" repository = "https://github.com/sfackler/rust-openssl"
documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.8/openssl" documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.9/openssl"
readme = "../README.md" readme = "../README.md"
keywords = ["crypto", "tls", "ssl", "dtls"] keywords = ["crypto", "tls", "ssl", "dtls"]
build = "build.rs" build = "build.rs"
@ -32,8 +32,8 @@ nightly = []
bitflags = "0.4" bitflags = "0.4"
lazy_static = "0.1" lazy_static = "0.1"
libc = "0.2" libc = "0.2"
openssl-sys = { version = "0.7.8", path = "../openssl-sys" } openssl-sys = { version = "0.7.9", path = "../openssl-sys" }
openssl-sys-extras = { version = "0.7.8", path = "../openssl-sys-extras" } openssl-sys-extras = { version = "0.7.9", path = "../openssl-sys-extras" }
[build-dependencies] [build-dependencies]
gcc = "0.3" gcc = "0.3"

View File

@ -8,10 +8,6 @@ void rust_SSL_CTX_clone(SSL_CTX *ctx) {
CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
} }
void rust_EVP_PKEY_clone(EVP_PKEY *pkey) {
CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
}
void rust_X509_clone(X509 *x509) { void rust_X509_clone(X509 *x509) {
CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
} }

View File

@ -53,10 +53,6 @@ fn openssl_hash_nid(hash: HashType) -> c_int {
} }
} }
extern "C" {
fn rust_EVP_PKEY_clone(pkey: *mut ffi::EVP_PKEY);
}
pub struct PKey { pub struct PKey {
evp: *mut ffi::EVP_PKEY, evp: *mut ffi::EVP_PKEY,
parts: Parts, parts: Parts,
@ -614,10 +610,10 @@ impl Drop for PKey {
impl Clone for PKey { impl Clone for PKey {
fn clone(&self) -> Self { fn clone(&self) -> Self {
unsafe { unsafe {
rust_EVP_PKEY_clone(self.evp); let new_evp = ffi::EVP_PKEY_new();
assert!(ffi::EVP_PKEY_copy_parameters(new_evp, self.evp) == 0);
PKey::from_handle(new_evp, self.parts)
} }
PKey::from_handle(self.evp, self.parts)
} }
} }
@ -866,4 +862,16 @@ mod tests {
pkey.load_pub(&[]); pkey.load_pub(&[]);
pkey.verify(&[], &[]); pkey.verify(&[], &[]);
} }
#[test]
fn test_pkey_clone_creates_copy() {
let mut pkey = super::PKey::new();
pkey.gen(512);
let old_pkey_n = pkey.get_rsa().n().unwrap();
let mut pkey2 = pkey.clone();
pkey2.gen(512);
assert!(old_pkey_n == pkey.get_rsa().n().unwrap());
}
} }

View File

@ -1,4 +1,4 @@
#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.8")] #![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/v0.7.9")]
#![cfg_attr(feature = "nightly", feature(const_fn, recover, panic_propagate))] #![cfg_attr(feature = "nightly", feature(const_fn, recover, panic_propagate))]
#[macro_use] #[macro_use]

View File

@ -1,5 +1,5 @@
use libc::{c_char, c_int, c_long, c_void, strlen}; use libc::{c_char, c_int, c_long, c_void, strlen};
use ffi::{BIO, BIO_METHOD, BIO_CTRL_FLUSH, BIO_TYPE_NONE, BIO_new}; use ffi::{self, BIO, BIO_CTRL_FLUSH, BIO_TYPE_NONE, BIO_new};
use ffi_extras::{BIO_clear_retry_flags, BIO_set_retry_read, BIO_set_retry_write}; use ffi_extras::{BIO_clear_retry_flags, BIO_set_retry_read, BIO_set_retry_write};
use std::any::Any; use std::any::Any;
use std::io; use std::io;
@ -17,19 +17,30 @@ pub struct StreamState<S> {
pub panic: Option<Box<Any + Send>>, pub panic: Option<Box<Any + Send>>,
} }
pub fn new<S: Read + Write>(stream: S) -> Result<(*mut BIO, Arc<BIO_METHOD>), SslError> { /// Safe wrapper for BIO_METHOD
let method = Arc::new(BIO_METHOD { pub struct BioMethod(ffi::BIO_METHOD);
type_: BIO_TYPE_NONE,
name: b"rust\0".as_ptr() as *const _, impl BioMethod {
bwrite: Some(bwrite::<S>), pub fn new<S: Read + Write>() -> BioMethod {
bread: Some(bread::<S>), BioMethod(ffi::BIO_METHOD {
bputs: Some(bputs::<S>), type_: BIO_TYPE_NONE,
bgets: None, name: b"rust\0".as_ptr() as *const _,
ctrl: Some(ctrl::<S>), bwrite: Some(bwrite::<S>),
create: Some(create), bread: Some(bread::<S>),
destroy: Some(destroy::<S>), bputs: Some(bputs::<S>),
callback_ctrl: None, bgets: None,
}); ctrl: Some(ctrl::<S>),
create: Some(create),
destroy: Some(destroy::<S>),
callback_ctrl: None,
})
}
}
unsafe impl Send for BioMethod {}
pub fn new<S: Read + Write>(stream: S) -> Result<(*mut BIO, Arc<BioMethod>), SslError> {
let method = Arc::new(BioMethod::new::<S>());
let state = Box::new(StreamState { let state = Box::new(StreamState {
stream: stream, stream: stream,
@ -38,7 +49,7 @@ pub fn new<S: Read + Write>(stream: S) -> Result<(*mut BIO, Arc<BIO_METHOD>), Ss
}); });
unsafe { unsafe {
let bio = try_ssl_null!(BIO_new(&*method)); let bio = try_ssl_null!(BIO_new(&method.0));
(*bio).ptr = Box::into_raw(state) as *mut _; (*bio).ptr = Box::into_raw(state) as *mut _;
(*bio).init = 1; (*bio).init = 1;
@ -72,7 +83,7 @@ unsafe fn state<'a, S: 'a>(bio: *mut BIO) -> &'a mut StreamState<S> {
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
fn recover<F, T>(f: F) -> Result<T, Box<Any + Send>> where F: FnOnce() -> T { fn recover<F, T>(f: F) -> Result<T, Box<Any + Send>> where F: FnOnce() -> T {
::std::panic::recover(::std::panic::AssertRecoverSafe::new(f)) ::std::panic::recover(::std::panic::AssertRecoverSafe(f))
} }
#[cfg(not(feature = "nightly"))] #[cfg(not(feature = "nightly"))]
@ -86,9 +97,7 @@ unsafe extern "C" fn bwrite<S: Write>(bio: *mut BIO, buf: *const c_char, len: c_
let state = state::<S>(bio); let state = state::<S>(bio);
let buf = slice::from_raw_parts(buf as *const _, len as usize); let buf = slice::from_raw_parts(buf as *const _, len as usize);
let result = recover(|| state.stream.write(buf)); match recover(|| state.stream.write(buf)) {
match result {
Ok(Ok(len)) => len as c_int, Ok(Ok(len)) => len as c_int,
Ok(Err(err)) => { Ok(Err(err)) => {
if retriable_error(&err) { if retriable_error(&err) {
@ -110,9 +119,7 @@ unsafe extern "C" fn bread<S: Read>(bio: *mut BIO, buf: *mut c_char, len: c_int)
let state = state::<S>(bio); let state = state::<S>(bio);
let buf = slice::from_raw_parts_mut(buf as *mut _, len as usize); let buf = slice::from_raw_parts_mut(buf as *mut _, len as usize);
let result = recover(|| state.stream.read(buf)); match recover(|| state.stream.read(buf)) {
match result {
Ok(Ok(len)) => len as c_int, Ok(Ok(len)) => len as c_int,
Ok(Err(err)) => { Ok(Err(err)) => {
if retriable_error(&err) { if retriable_error(&err) {
@ -146,9 +153,8 @@ unsafe extern "C" fn ctrl<S: Write>(bio: *mut BIO,
-> c_long { -> c_long {
if cmd == BIO_CTRL_FLUSH { if cmd == BIO_CTRL_FLUSH {
let state = state::<S>(bio); let state = state::<S>(bio);
let result = recover(|| state.stream.flush());
match result { match recover(|| state.stream.flush()) {
Ok(Ok(())) => 1, Ok(Ok(())) => 1,
Ok(Err(err)) => { Ok(Err(err)) => {
state.error = Some(err); state.error = Some(err);

View File

@ -35,6 +35,8 @@ mod bio;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use self::bio::BioMethod;
#[doc(inline)] #[doc(inline)]
pub use ssl::error::Error; pub use ssl::error::Error;
@ -827,7 +829,7 @@ impl <'a> SslCipher<'a> {
let desc_ptr = ffi::SSL_CIPHER_description(self.cipher, buf.as_mut_ptr(), 128); let desc_ptr = ffi::SSL_CIPHER_description(self.cipher, buf.as_mut_ptr(), 128);
if !desc_ptr.is_null() { if !desc_ptr.is_null() {
String::from_utf8(CStr::from_ptr(desc_ptr).to_bytes().to_vec()).ok() String::from_utf8(CStr::from_ptr(desc_ptr as *const _).to_bytes().to_vec()).ok()
} else { } else {
None None
} }
@ -1117,12 +1119,10 @@ make_LibSslError! {
/// A stream wrapper which handles SSL encryption for an underlying stream. /// A stream wrapper which handles SSL encryption for an underlying stream.
pub struct SslStream<S> { pub struct SslStream<S> {
ssl: Ssl, ssl: Ssl,
_method: Arc<ffi::BIO_METHOD>, // NOTE: this *must* be after the Ssl field so things drop right _method: Arc<BioMethod>, // NOTE: this *must* be after the Ssl field so things drop right
_p: PhantomData<S>, _p: PhantomData<S>,
} }
unsafe impl<S: Send> Send for SslStream<S> {}
/// # Deprecated /// # Deprecated
/// ///
/// This method does not behave as expected and will be removed in a future /// This method does not behave as expected and will be removed in a future