1From ef81d97a30ce0277be9eba813131f07f9328e3a6 Mon Sep 17 00:00:00 2001 2From: Viktoriia Kovalova <vkovalova@google.com> 3Date: Wed, 13 Nov 2024 15:42:48 +0000 4Subject: [PATCH] Enable set_alpn_select_callback for BoringSSL 5 6--- 7 src/ssl/callbacks.rs | 4 ++-- 8 src/ssl/mod.rs | 21 ++++++++++++++------- 9 2 files changed, 16 insertions(+), 9 deletions(-) 10 11diff --git a/src/ssl/callbacks.rs b/src/ssl/callbacks.rs 12index ccf53085..f7e51a5d 100644 13--- a/src/ssl/callbacks.rs 14+++ b/src/ssl/callbacks.rs 15@@ -19,7 +19,7 @@ use crate::dh::Dh; 16 use crate::ec::EcKey; 17 use crate::error::ErrorStack; 18 use crate::pkey::Params; 19-#[cfg(any(ossl102, libressl261))] 20+#[cfg(any(ossl102, libressl261, boringssl))] 21 use crate::ssl::AlpnError; 22 use crate::ssl::{ 23 try_get_session_ctx_index, SniError, Ssl, SslAlert, SslContext, SslContextRef, SslRef, 24@@ -178,7 +178,7 @@ where 25 } 26 } 27 28-#[cfg(any(ossl102, libressl261))] 29+#[cfg(any(ossl102, libressl261, boringssl))] 30 pub extern "C" fn raw_alpn_select<F>( 31 ssl: *mut ffi::SSL, 32 out: *mut *const c_uchar, 33diff --git a/src/ssl/mod.rs b/src/ssl/mod.rs 34index d9b2a724..f5a696ab 100644 35--- a/src/ssl/mod.rs 36+++ b/src/ssl/mod.rs 37@@ -602,17 +602,17 @@ impl SslAlert { 38 39 /// An error returned from an ALPN selection callback. 40 /// 41-/// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer. 42-#[cfg(any(ossl102, libressl261))] 43+/// Requires BoringSSL or OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer. 44+#[cfg(any(ossl102, libressl261, boringssl))] 45 #[derive(Debug, Copy, Clone, PartialEq, Eq)] 46 pub struct AlpnError(c_int); 47 48-#[cfg(any(ossl102, libressl261))] 49+#[cfg(any(ossl102, libressl261, boringssl))] 50 impl AlpnError { 51 /// Terminate the handshake with a fatal alert. 52 /// 53- /// Requires OpenSSL 1.1.0 or newer. 54- #[cfg(ossl110)] 55+ /// Requires BoringSSL or OpenSSL 1.1.0 or newer. 56+ #[cfg(any(ossl110, boringssl))] 57 pub const ALERT_FATAL: AlpnError = AlpnError(ffi::SSL_TLSEXT_ERR_ALERT_FATAL); 58 59 /// Do not select a protocol, but continue the handshake. 60@@ -1267,23 +1267,30 @@ impl SslContextBuilder { 61 /// of those protocols on success. The [`select_next_proto`] function implements the standard 62 /// protocol selection algorithm. 63 /// 64- /// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer. 65+ /// Requires BoringSSL or OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer. 66 /// 67 /// [`SslContextBuilder::set_alpn_protos`]: struct.SslContextBuilder.html#method.set_alpn_protos 68 /// [`select_next_proto`]: fn.select_next_proto.html 69 #[corresponds(SSL_CTX_set_alpn_select_cb)] 70- #[cfg(any(ossl102, libressl261))] 71+ #[cfg(any(ossl102, libressl261, boringssl))] 72 pub fn set_alpn_select_callback<F>(&mut self, callback: F) 73 where 74 F: for<'a> Fn(&mut SslRef, &'a [u8]) -> Result<&'a [u8], AlpnError> + 'static + Sync + Send, 75 { 76 unsafe { 77 self.set_ex_data(SslContext::cached_ex_index::<F>(), callback); 78+ #[cfg(not(boringssl))] 79 ffi::SSL_CTX_set_alpn_select_cb__fixed_rust( 80 self.as_ptr(), 81 Some(callbacks::raw_alpn_select::<F>), 82 ptr::null_mut(), 83 ); 84+ #[cfg(boringssl)] 85+ ffi::SSL_CTX_set_alpn_select_cb( 86+ self.as_ptr(), 87+ Some(callbacks::raw_alpn_select::<F>), 88+ ptr::null_mut(), 89+ ); 90 } 91 } 92 93-- 942.47.0.277.g8800431eea-goog 95 96