aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2018-01-06 22:20:20 -0800
committerSteven Fackler <[email protected]>2018-01-06 22:20:20 -0800
commitaf7aa52364aa093a1436491646d659827634b188 (patch)
treecbb1db8d86d862b2b9a51d701376faf2036346c4 /openssl/src
parentMerge pull request #822 from sfackler/doc-fixes (diff)
downloadrust-openssl-af7aa52364aa093a1436491646d659827634b188.tar.xz
rust-openssl-af7aa52364aa093a1436491646d659827634b188.zip
Adjust the SNI callback
Brings it more in line with how the raw callback is structured.
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/ssl/callbacks.rs19
-rw-r--r--openssl/src/ssl/mod.rs30
2 files changed, 30 insertions, 19 deletions
diff --git a/openssl/src/ssl/callbacks.rs b/openssl/src/ssl/callbacks.rs
index 17f8c1f6..7d884b4e 100644
--- a/openssl/src/ssl/callbacks.rs
+++ b/openssl/src/ssl/callbacks.rs
@@ -11,7 +11,7 @@ use dh::Dh;
#[cfg(any(all(feature = "v101", ossl101), all(feature = "v102", ossl102)))]
use ec::EcKey;
use pkey::Params;
-use ssl::{get_callback_idx, get_ssl_callback_idx, SniError, SslRef};
+use ssl::{get_callback_idx, get_ssl_callback_idx, SniError, SslAlert, SslRef};
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
use ssl::AlpnError;
use x509::X509StoreContextRef;
@@ -89,25 +89,20 @@ where
pub extern "C" fn raw_sni<F>(ssl: *mut ffi::SSL, al: *mut c_int, _arg: *mut c_void) -> c_int
where
- F: Fn(&mut SslRef) -> Result<(), SniError> + 'static + Sync + Send,
+ F: Fn(&mut SslRef, &mut SslAlert) -> Result<(), SniError> + 'static + Sync + Send,
{
unsafe {
let ssl_ctx = ffi::SSL_get_SSL_CTX(ssl);
let callback = ffi::SSL_CTX_get_ex_data(ssl_ctx, get_callback_idx::<F>());
let callback: &F = &*(callback as *mut F);
let ssl = SslRef::from_ptr_mut(ssl);
+ let mut alert = SslAlert(*al);
- match callback(ssl) {
+ let r = callback(ssl, &mut alert);
+ *al = alert.0;
+ match r {
Ok(()) => ffi::SSL_TLSEXT_ERR_OK,
- Err(SniError::Fatal(e)) => {
- *al = e;
- ffi::SSL_TLSEXT_ERR_ALERT_FATAL
- }
- Err(SniError::Warning(e)) => {
- *al = e;
- ffi::SSL_TLSEXT_ERR_ALERT_WARNING
- }
- Err(SniError::NoAck) => ffi::SSL_TLSEXT_ERR_NOACK,
+ Err(e) => e.0,
}
}
}
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 0384ca1e..2474c2ab 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -428,18 +428,34 @@ fn get_new_ssl_idx<T>() -> c_int {
}
}
-// FIXME look into this
-/// An error returned from an SNI callback.
-pub enum SniError {
- Fatal(c_int),
- Warning(c_int),
- NoAck,
+/// An error returned from the SNI callback.
+#[derive(Debug, Copy, Clone)]
+pub struct SniError(c_int);
+
+impl SniError {
+ /// Abort the handshake with a fatal alert.
+ pub const ALERT_FATAL: SniError = SniError(ffi::SSL_TLSEXT_ERR_ALERT_FATAL);
+
+ /// Send a warning alert to the client and continue the handshake.
+ pub const ALERT_WARNING: SniError = SniError(ffi::SSL_TLSEXT_ERR_ALERT_WARNING);
+
+ pub const NOACK: SniError = SniError(ffi::SSL_TLSEXT_ERR_NOACK);
+}
+
+/// An SSL/TLS alert.
+#[derive(Debug, Copy, Clone)]
+pub struct SslAlert(c_int);
+
+impl SslAlert {
+ /// Alert 112 - `unrecognized_name`.
+ pub const UNRECOGNIZED_NAME: SslAlert = SslAlert(ffi::SSL_AD_UNRECOGNIZED_NAME);
}
/// An error returned from an ALPN selection callback.
///
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
+#[derive(Debug, Copy, Clone)]
pub struct AlpnError(c_int);
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
@@ -564,7 +580,7 @@ impl SslContextBuilder {
/// [`SSL_CTX_set_tlsext_servername_callback`]: https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_tlsext_servername_callback.html
pub fn set_servername_callback<F>(&mut self, callback: F)
where
- F: Fn(&mut SslRef) -> Result<(), SniError> + 'static + Sync + Send,
+ F: Fn(&mut SslRef, &mut SslAlert) -> Result<(), SniError> + 'static + Sync + Send,
{
unsafe {
let callback = Box::new(callback);