diff options
| author | Steven Fackler <[email protected]> | 2018-05-20 12:52:49 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2018-05-20 12:52:49 -0700 |
| commit | 4c1fdf1d81e20ee2130e883bb9065af0d1d4de2a (patch) | |
| tree | 8d3f01193654f99bb132514577c8447a8fdb15a1 /openssl/src | |
| parent | Merge pull request #923 from sfackler/libressl-hostname (diff) | |
| download | rust-openssl-4c1fdf1d81e20ee2130e883bb9065af0d1d4de2a.tar.xz rust-openssl-4c1fdf1d81e20ee2130e883bb9065af0d1d4de2a.zip | |
Support ALPN on libressl
Closes #690
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/ssl/callbacks.rs | 9 | ||||
| -rw-r--r-- | openssl/src/ssl/mod.rs | 19 | ||||
| -rw-r--r-- | openssl/src/ssl/test.rs | 10 |
3 files changed, 21 insertions, 17 deletions
diff --git a/openssl/src/ssl/callbacks.rs b/openssl/src/ssl/callbacks.rs index 6ec9aef9..b23c60e7 100644 --- a/openssl/src/ssl/callbacks.rs +++ b/openssl/src/ssl/callbacks.rs @@ -1,9 +1,12 @@ use ffi; use foreign_types::ForeignType; use foreign_types::ForeignTypeRef; +#[cfg(not(osslconf = "OPENSSL_NO_PSK"))] +use libc::c_char; #[cfg(ossl111)] use libc::size_t; -use libc::{c_char, c_int, c_uchar, c_uint, c_void}; +use libc::{c_int, c_uchar, c_uint, c_void}; +#[cfg(not(osslconf = "OPENSSL_NO_PSK"))] use std::ffi::CStr; use std::mem; use std::ptr; @@ -17,7 +20,7 @@ use dh::Dh; use ec::EcKey; use error::ErrorStack; use pkey::Params; -#[cfg(ossl102)] +#[cfg(any(ossl102, libressl261))] use ssl::AlpnError; #[cfg(ossl111)] use ssl::ExtensionContext; @@ -130,7 +133,7 @@ where } } -#[cfg(any(ossl102, ossl110))] +#[cfg(any(ossl102, libressl261))] pub extern "C" fn raw_alpn_select<F>( ssl: *mut ffi::SSL, out: *mut *const c_uchar, diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index ce9c4b1d..08475888 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -85,6 +85,7 @@ use error::ErrorStack; use ex_data::Index; #[cfg(ossl111)] use hash::MessageDigest; +#[cfg(ossl110)] use nid::Nid; use pkey::{HasPrivate, PKeyRef, Params, Private}; use ssl::bio::BioMethod; @@ -506,12 +507,12 @@ impl SslAlert { /// An error returned from an ALPN selection callback. /// -/// Requires OpenSSL 1.0.2 or newer. -#[cfg(any(ossl102, ossl110))] +/// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer. +#[cfg(any(ossl102, libressl261))] #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct AlpnError(c_int); -#[cfg(any(ossl102, ossl110))] +#[cfg(any(ossl102, libressl261))] impl AlpnError { /// Terminate the handshake with a fatal alert. /// @@ -1109,10 +1110,10 @@ impl SslContextBuilder { /// /// This corresponds to [`SSL_CTX_set_alpn_protos`]. /// - /// Requires OpenSSL 1.0.2 or newer. + /// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer. /// /// [`SSL_CTX_set_alpn_protos`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_CTX_set_alpn_protos.html - #[cfg(any(ossl102, ossl110))] + #[cfg(any(ossl102, libressl261))] pub fn set_alpn_protos(&mut self, protocols: &[u8]) -> Result<(), ErrorStack> { unsafe { assert!(protocols.len() <= c_uint::max_value() as usize); @@ -1140,12 +1141,12 @@ impl SslContextBuilder { /// /// This corresponds to [`SSL_CTX_set_alpn_select_cb`]. /// - /// Requires OpenSSL 1.0.2 or newer. + /// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer. /// /// [`SslContextBuilder::set_alpn_protos`]: struct.SslContextBuilder.html#method.set_alpn_protos /// [`select_next_proto`]: fn.select_next_proto.html /// [`SSL_CTX_set_alpn_select_cb`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_CTX_set_alpn_protos.html - #[cfg(any(ossl102, ossl110))] + #[cfg(any(ossl102, libressl261))] pub fn set_alpn_select_callback<F>(&mut self, callback: F) where F: for<'a> Fn(&mut SslRef, &'a [u8]) -> Result<&'a [u8], AlpnError> + 'static + Sync + Send, @@ -2283,12 +2284,12 @@ impl SslRef { /// The protocol's name is returned is an opaque sequence of bytes. It is up to the client /// to interpret it. /// - /// Requires OpenSSL 1.0.2 or newer. + /// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer. /// /// This corresponds to [`SSL_get0_alpn_selected`]. /// /// [`SSL_get0_alpn_selected`]: https://www.openssl.org/docs/manmaster/man3/SSL_get0_next_proto_negotiated.html - #[cfg(any(ossl102, ossl110))] + #[cfg(any(ossl102, libressl261))] pub fn selected_alpn_protocol(&self) -> Option<&[u8]> { unsafe { let mut data: *const c_uchar = ptr::null(); diff --git a/openssl/src/ssl/test.rs b/openssl/src/ssl/test.rs index f2dc4a65..0d418d2c 100644 --- a/openssl/src/ssl/test.rs +++ b/openssl/src/ssl/test.rs @@ -481,7 +481,7 @@ fn test_state() { /// Tests that connecting with the client using ALPN, but the server not does not /// break the existing connection behavior. #[test] -#[cfg(any(ossl102, ossl110))] +#[cfg(any(ossl102, libressl261))] fn test_connect_with_unilateral_alpn() { let (_s, stream) = Server::new(); let mut ctx = SslContext::builder(SslMethod::tls()).unwrap(); @@ -503,7 +503,7 @@ fn test_connect_with_unilateral_alpn() { /// Tests that when both the client as well as the server use ALPN and their /// lists of supported protocols have an overlap, the correct protocol is chosen. #[test] -#[cfg(any(ossl102, ossl110))] +#[cfg(any(ossl102, libressl261))] fn test_connect_with_alpn_successful_multiple_matching() { let (_s, stream) = Server::new_alpn(); let mut ctx = SslContext::builder(SslMethod::tls()).unwrap(); @@ -526,7 +526,7 @@ fn test_connect_with_alpn_successful_multiple_matching() { /// lists of supported protocols have an overlap -- with only ONE protocol /// being valid for both. #[test] -#[cfg(any(ossl102, ossl110))] +#[cfg(any(ossl102, libressl261))] fn test_connect_with_alpn_successful_single_match() { let (_s, stream) = Server::new_alpn(); let mut ctx = SslContext::builder(SslMethod::tls()).unwrap(); @@ -548,7 +548,7 @@ fn test_connect_with_alpn_successful_single_match() { /// Tests that when the `SslStream` is created as a server stream, the protocols /// are correctly advertised to the client. #[test] -#[cfg(any(ossl102, ossl110))] +#[cfg(any(ossl102, libressl261))] fn test_alpn_server_advertise_multiple() { let listener = TcpListener::bind("127.0.0.1:0").unwrap(); let localhost = listener.local_addr().unwrap(); @@ -624,7 +624,7 @@ fn test_alpn_server_select_none_fatal() { } #[test] -#[cfg(any(ossl102, ossl110))] +#[cfg(any(ossl102, libressl261))] fn test_alpn_server_select_none() { let listener = TcpListener::bind("127.0.0.1:0").unwrap(); let localhost = listener.local_addr().unwrap(); |