Loading openssl-sys/build.rs +9 −12 Original line number Diff line number Diff line Loading @@ -29,9 +29,8 @@ const DEFINES: &'static [&'static str] = &[ ]; enum Version { Openssl110, Openssl102, Openssl101, Openssl11x, Openssl10x, Libressl, } Loading Loading @@ -89,10 +88,8 @@ fn main() { let libs = match libs_env.as_ref().and_then(|s| s.to_str()) { Some(ref v) => v.split(":").collect(), None => match version { Version::Openssl101 | Version::Openssl102 if target.contains("windows") => { vec!["ssleay32", "libeay32"] } Version::Openssl110 if target.contains("windows") => vec!["libssl", "libcrypto"], Version::Openssl10x if target.contains("windows") => vec!["ssleay32", "libeay32"], Version::Openssl11x if target.contains("windows") => vec!["libssl", "libcrypto"], _ => vec!["ssl", "crypto"], }, }; Loading Loading @@ -446,25 +443,25 @@ See rust-openssl README for more information: println!("cargo:rustc-cfg=ossl111"); println!("cargo:rustc-cfg=ossl110"); println!("cargo:version=111"); Version::Openssl110 Version::Openssl11x } else if openssl_version >= 0x1_01_00_06_0 { println!("cargo:rustc-cfg=ossl110"); println!("cargo:rustc-cfg=ossl110f"); println!("cargo:version=110"); println!("cargo:patch=f"); Version::Openssl110 Version::Openssl11x } else if openssl_version >= 0x1_01_00_00_0 { println!("cargo:rustc-cfg=ossl110"); println!("cargo:version=110"); Version::Openssl110 Version::Openssl11x } else if openssl_version >= 0x1_00_02_00_0 { println!("cargo:rustc-cfg=ossl102"); println!("cargo:version=102"); Version::Openssl102 Version::Openssl10x } else if openssl_version >= 0x1_00_01_00_0 { println!("cargo:rustc-cfg=ossl101"); println!("cargo:version=101"); Version::Openssl101 Version::Openssl10x } else { version_error() } Loading openssl/src/ssl/test.rs +81 −60 Original line number Diff line number Diff line Loading @@ -17,16 +17,16 @@ use tempdir::TempDir; use dh::Dh; use hash::MessageDigest; use ocsp::{OcspResponse, OcspResponseStatus}; use pkey::PKey; use ssl; use ssl::{Error, HandshakeError, ShutdownResult, Ssl, SslAcceptor, SslConnector, SslContext, SslFiletype, SslMethod, SslSessionCacheMode, SslStream, MidHandshakeSslStream, SslVerifyMode, StatusType}; #[cfg(any(ossl110, ossl111))] use ssl::SslVersion; use x509::{X509, X509Name, X509StoreContext, X509VerifyResult}; use ssl::{Error, HandshakeError, MidHandshakeSslStream, ShutdownResult, Ssl, SslAcceptor, SslConnector, SslContext, SslFiletype, SslMethod, SslSessionCacheMode, SslStream, SslVerifyMode, StatusType}; #[cfg(any(ossl102, ossl110))] use x509::verify::X509CheckFlags; use pkey::PKey; use x509::{X509, X509Name, X509StoreContext, X509VerifyResult}; use std::net::UdpSocket; Loading Loading @@ -1391,6 +1391,11 @@ fn _check_kinds() { is_sync::<SslStream<TcpStream>>(); } #[test] #[cfg(ossl111)] fn stateless() { use super::SslOptions; #[derive(Debug)] struct MemoryStream { incoming: io::Cursor<Vec<u8>>, Loading @@ -1398,16 +1403,20 @@ struct MemoryStream { } impl MemoryStream { pub fn new() -> Self { Self { pub fn new() -> Self { Self { incoming: io::Cursor::new(Vec::new()), outgoing: Vec::new(), }} } } pub fn extend_incoming(&mut self, data: &[u8]) { self.incoming.get_mut().extend_from_slice(data); } pub fn take_outgoing(&mut self) -> Outgoing { Outgoing(&mut self.outgoing) } pub fn take_outgoing(&mut self) -> Outgoing { Outgoing(&mut self.outgoing) } } impl Read for MemoryStream { Loading @@ -1418,7 +1427,10 @@ impl Read for MemoryStream { self.incoming.get_mut().clear(); } if n == 0 { return Err(io::Error::new(io::ErrorKind::WouldBlock, "no data available")); return Err(io::Error::new( io::ErrorKind::WouldBlock, "no data available", )); } Ok(n) } Loading @@ -1429,7 +1441,9 @@ impl Write for MemoryStream { self.outgoing.write(buf) } fn flush(&mut self) -> io::Result<()> { Ok(()) } fn flush(&mut self) -> io::Result<()> { Ok(()) } } pub struct Outgoing<'a>(&'a mut Vec<u8>); Loading @@ -1442,23 +1456,24 @@ impl<'a> Drop for Outgoing<'a> { impl<'a> ::std::ops::Deref for Outgoing<'a> { type Target = [u8]; fn deref(&self) -> &[u8] { &self.0 } fn deref(&self) -> &[u8] { &self.0 } } impl<'a> AsRef<[u8]> for Outgoing<'a> { fn as_ref(&self) -> &[u8] { &self.0 } fn as_ref(&self) -> &[u8] { &self.0 } } fn send(from: &mut MemoryStream, to: &mut MemoryStream) { to.extend_incoming(&from.take_outgoing()); } #[test] #[cfg(ossl111)] fn stateless() { use super::SslOptions; fn hs<S: ::std::fmt::Debug>(stream: Result<SslStream<S>, HandshakeError<S>>) -> Result<SslStream<S>, MidHandshakeSslStream<S>> { fn hs<S: ::std::fmt::Debug>( stream: Result<SslStream<S>, HandshakeError<S>>, ) -> Result<SslStream<S>, MidHandshakeSslStream<S>> { match stream { Ok(stream) => Ok(stream), Err(HandshakeError::WouldBlock(stream)) => Err(stream), Loading @@ -1475,14 +1490,20 @@ fn stateless() { let client_stream = Ssl::new(&client_ctx.build()).unwrap(); let mut server_ctx = SslContext::builder(SslMethod::tls()).unwrap(); server_ctx.set_certificate_file(&Path::new("test/cert.pem"), SslFiletype::PEM) server_ctx .set_certificate_file(&Path::new("test/cert.pem"), SslFiletype::PEM) .unwrap(); server_ctx.set_private_key_file(&Path::new("test/key.pem"), SslFiletype::PEM) server_ctx .set_private_key_file(&Path::new("test/key.pem"), SslFiletype::PEM) .unwrap(); const COOKIE: &[u8] = b"chocolate chip"; server_ctx.set_stateless_cookie_generate_cb(|_tls, buf| { buf[0..COOKIE.len()].copy_from_slice(COOKIE); Ok(COOKIE.len()) }); server_ctx.set_stateless_cookie_generate_cb(|_tls, buf| { buf[0..COOKIE.len()].copy_from_slice(COOKIE); Ok(COOKIE.len()) }); server_ctx.set_stateless_cookie_verify_cb(|_tls, buf| buf == COOKIE); let mut server_stream = ssl::SslStreamBuilder::new(Ssl::new(&server_ctx.build()).unwrap(), MemoryStream::new()); let mut server_stream = ssl::SslStreamBuilder::new(Ssl::new(&server_ctx.build()).unwrap(), MemoryStream::new()); // // Handshake Loading Loading
openssl-sys/build.rs +9 −12 Original line number Diff line number Diff line Loading @@ -29,9 +29,8 @@ const DEFINES: &'static [&'static str] = &[ ]; enum Version { Openssl110, Openssl102, Openssl101, Openssl11x, Openssl10x, Libressl, } Loading Loading @@ -89,10 +88,8 @@ fn main() { let libs = match libs_env.as_ref().and_then(|s| s.to_str()) { Some(ref v) => v.split(":").collect(), None => match version { Version::Openssl101 | Version::Openssl102 if target.contains("windows") => { vec!["ssleay32", "libeay32"] } Version::Openssl110 if target.contains("windows") => vec!["libssl", "libcrypto"], Version::Openssl10x if target.contains("windows") => vec!["ssleay32", "libeay32"], Version::Openssl11x if target.contains("windows") => vec!["libssl", "libcrypto"], _ => vec!["ssl", "crypto"], }, }; Loading Loading @@ -446,25 +443,25 @@ See rust-openssl README for more information: println!("cargo:rustc-cfg=ossl111"); println!("cargo:rustc-cfg=ossl110"); println!("cargo:version=111"); Version::Openssl110 Version::Openssl11x } else if openssl_version >= 0x1_01_00_06_0 { println!("cargo:rustc-cfg=ossl110"); println!("cargo:rustc-cfg=ossl110f"); println!("cargo:version=110"); println!("cargo:patch=f"); Version::Openssl110 Version::Openssl11x } else if openssl_version >= 0x1_01_00_00_0 { println!("cargo:rustc-cfg=ossl110"); println!("cargo:version=110"); Version::Openssl110 Version::Openssl11x } else if openssl_version >= 0x1_00_02_00_0 { println!("cargo:rustc-cfg=ossl102"); println!("cargo:version=102"); Version::Openssl102 Version::Openssl10x } else if openssl_version >= 0x1_00_01_00_0 { println!("cargo:rustc-cfg=ossl101"); println!("cargo:version=101"); Version::Openssl101 Version::Openssl10x } else { version_error() } Loading
openssl/src/ssl/test.rs +81 −60 Original line number Diff line number Diff line Loading @@ -17,16 +17,16 @@ use tempdir::TempDir; use dh::Dh; use hash::MessageDigest; use ocsp::{OcspResponse, OcspResponseStatus}; use pkey::PKey; use ssl; use ssl::{Error, HandshakeError, ShutdownResult, Ssl, SslAcceptor, SslConnector, SslContext, SslFiletype, SslMethod, SslSessionCacheMode, SslStream, MidHandshakeSslStream, SslVerifyMode, StatusType}; #[cfg(any(ossl110, ossl111))] use ssl::SslVersion; use x509::{X509, X509Name, X509StoreContext, X509VerifyResult}; use ssl::{Error, HandshakeError, MidHandshakeSslStream, ShutdownResult, Ssl, SslAcceptor, SslConnector, SslContext, SslFiletype, SslMethod, SslSessionCacheMode, SslStream, SslVerifyMode, StatusType}; #[cfg(any(ossl102, ossl110))] use x509::verify::X509CheckFlags; use pkey::PKey; use x509::{X509, X509Name, X509StoreContext, X509VerifyResult}; use std::net::UdpSocket; Loading Loading @@ -1391,6 +1391,11 @@ fn _check_kinds() { is_sync::<SslStream<TcpStream>>(); } #[test] #[cfg(ossl111)] fn stateless() { use super::SslOptions; #[derive(Debug)] struct MemoryStream { incoming: io::Cursor<Vec<u8>>, Loading @@ -1398,16 +1403,20 @@ struct MemoryStream { } impl MemoryStream { pub fn new() -> Self { Self { pub fn new() -> Self { Self { incoming: io::Cursor::new(Vec::new()), outgoing: Vec::new(), }} } } pub fn extend_incoming(&mut self, data: &[u8]) { self.incoming.get_mut().extend_from_slice(data); } pub fn take_outgoing(&mut self) -> Outgoing { Outgoing(&mut self.outgoing) } pub fn take_outgoing(&mut self) -> Outgoing { Outgoing(&mut self.outgoing) } } impl Read for MemoryStream { Loading @@ -1418,7 +1427,10 @@ impl Read for MemoryStream { self.incoming.get_mut().clear(); } if n == 0 { return Err(io::Error::new(io::ErrorKind::WouldBlock, "no data available")); return Err(io::Error::new( io::ErrorKind::WouldBlock, "no data available", )); } Ok(n) } Loading @@ -1429,7 +1441,9 @@ impl Write for MemoryStream { self.outgoing.write(buf) } fn flush(&mut self) -> io::Result<()> { Ok(()) } fn flush(&mut self) -> io::Result<()> { Ok(()) } } pub struct Outgoing<'a>(&'a mut Vec<u8>); Loading @@ -1442,23 +1456,24 @@ impl<'a> Drop for Outgoing<'a> { impl<'a> ::std::ops::Deref for Outgoing<'a> { type Target = [u8]; fn deref(&self) -> &[u8] { &self.0 } fn deref(&self) -> &[u8] { &self.0 } } impl<'a> AsRef<[u8]> for Outgoing<'a> { fn as_ref(&self) -> &[u8] { &self.0 } fn as_ref(&self) -> &[u8] { &self.0 } } fn send(from: &mut MemoryStream, to: &mut MemoryStream) { to.extend_incoming(&from.take_outgoing()); } #[test] #[cfg(ossl111)] fn stateless() { use super::SslOptions; fn hs<S: ::std::fmt::Debug>(stream: Result<SslStream<S>, HandshakeError<S>>) -> Result<SslStream<S>, MidHandshakeSslStream<S>> { fn hs<S: ::std::fmt::Debug>( stream: Result<SslStream<S>, HandshakeError<S>>, ) -> Result<SslStream<S>, MidHandshakeSslStream<S>> { match stream { Ok(stream) => Ok(stream), Err(HandshakeError::WouldBlock(stream)) => Err(stream), Loading @@ -1475,14 +1490,20 @@ fn stateless() { let client_stream = Ssl::new(&client_ctx.build()).unwrap(); let mut server_ctx = SslContext::builder(SslMethod::tls()).unwrap(); server_ctx.set_certificate_file(&Path::new("test/cert.pem"), SslFiletype::PEM) server_ctx .set_certificate_file(&Path::new("test/cert.pem"), SslFiletype::PEM) .unwrap(); server_ctx.set_private_key_file(&Path::new("test/key.pem"), SslFiletype::PEM) server_ctx .set_private_key_file(&Path::new("test/key.pem"), SslFiletype::PEM) .unwrap(); const COOKIE: &[u8] = b"chocolate chip"; server_ctx.set_stateless_cookie_generate_cb(|_tls, buf| { buf[0..COOKIE.len()].copy_from_slice(COOKIE); Ok(COOKIE.len()) }); server_ctx.set_stateless_cookie_generate_cb(|_tls, buf| { buf[0..COOKIE.len()].copy_from_slice(COOKIE); Ok(COOKIE.len()) }); server_ctx.set_stateless_cookie_verify_cb(|_tls, buf| buf == COOKIE); let mut server_stream = ssl::SslStreamBuilder::new(Ssl::new(&server_ctx.build()).unwrap(), MemoryStream::new()); let mut server_stream = ssl::SslStreamBuilder::new(Ssl::new(&server_ctx.build()).unwrap(), MemoryStream::new()); // // Handshake Loading