Skip to content

Commit d3d7c12

Browse files
authored
Merge pull request #2327 from ViktoriiaKovalova/add-select-alpn-cb
Enable set_alpn_select_callback for BoringSSL
2 parents 96607c6 + cf40611 commit d3d7c12

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

openssl/src/ssl/callbacks.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::dh::Dh;
1919
use crate::ec::EcKey;
2020
use crate::error::ErrorStack;
2121
use crate::pkey::Params;
22-
#[cfg(any(ossl102, libressl261))]
22+
#[cfg(any(ossl102, libressl261, boringssl))]
2323
use crate::ssl::AlpnError;
2424
use crate::ssl::{
2525
try_get_session_ctx_index, SniError, Ssl, SslAlert, SslContext, SslContextRef, SslRef,
@@ -178,7 +178,7 @@ where
178178
}
179179
}
180180

181-
#[cfg(any(ossl102, libressl261))]
181+
#[cfg(any(ossl102, libressl261, boringssl))]
182182
pub extern "C" fn raw_alpn_select<F>(
183183
ssl: *mut ffi::SSL,
184184
out: *mut *const c_uchar,

openssl/src/ssl/mod.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -602,17 +602,17 @@ impl SslAlert {
602602

603603
/// An error returned from an ALPN selection callback.
604604
///
605-
/// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
606-
#[cfg(any(ossl102, libressl261))]
605+
/// Requires BoringSSL or OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
606+
#[cfg(any(ossl102, libressl261, boringssl))]
607607
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
608608
pub struct AlpnError(c_int);
609609

610-
#[cfg(any(ossl102, libressl261))]
610+
#[cfg(any(ossl102, libressl261, boringssl))]
611611
impl AlpnError {
612612
/// Terminate the handshake with a fatal alert.
613613
///
614-
/// Requires OpenSSL 1.1.0 or newer.
615-
#[cfg(ossl110)]
614+
/// Requires BoringSSL or OpenSSL 1.1.0 or newer.
615+
#[cfg(any(ossl110, boringssl))]
616616
pub const ALERT_FATAL: AlpnError = AlpnError(ffi::SSL_TLSEXT_ERR_ALERT_FATAL);
617617

618618
/// Do not select a protocol, but continue the handshake.
@@ -1267,23 +1267,30 @@ impl SslContextBuilder {
12671267
/// of those protocols on success. The [`select_next_proto`] function implements the standard
12681268
/// protocol selection algorithm.
12691269
///
1270-
/// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
1270+
/// Requires BoringSSL or OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
12711271
///
12721272
/// [`SslContextBuilder::set_alpn_protos`]: struct.SslContextBuilder.html#method.set_alpn_protos
12731273
/// [`select_next_proto`]: fn.select_next_proto.html
12741274
#[corresponds(SSL_CTX_set_alpn_select_cb)]
1275-
#[cfg(any(ossl102, libressl261))]
1275+
#[cfg(any(ossl102, libressl261, boringssl))]
12761276
pub fn set_alpn_select_callback<F>(&mut self, callback: F)
12771277
where
12781278
F: for<'a> Fn(&mut SslRef, &'a [u8]) -> Result<&'a [u8], AlpnError> + 'static + Sync + Send,
12791279
{
12801280
unsafe {
12811281
self.set_ex_data(SslContext::cached_ex_index::<F>(), callback);
1282+
#[cfg(not(boringssl))]
12821283
ffi::SSL_CTX_set_alpn_select_cb__fixed_rust(
12831284
self.as_ptr(),
12841285
Some(callbacks::raw_alpn_select::<F>),
12851286
ptr::null_mut(),
12861287
);
1288+
#[cfg(boringssl)]
1289+
ffi::SSL_CTX_set_alpn_select_cb(
1290+
self.as_ptr(),
1291+
Some(callbacks::raw_alpn_select::<F>),
1292+
ptr::null_mut(),
1293+
);
12871294
}
12881295
}
12891296

openssl/src/ssl/test/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ fn test_connect_with_srtp_ssl() {
502502
/// Tests that when the `SslStream` is created as a server stream, the protocols
503503
/// are correctly advertised to the client.
504504
#[test]
505-
#[cfg(any(ossl102, libressl261))]
505+
#[cfg(any(ossl102, libressl261, boringssl))]
506506
fn test_alpn_server_advertise_multiple() {
507507
let mut server = Server::builder();
508508
server.ctx().set_alpn_select_callback(|_, client| {
@@ -517,7 +517,7 @@ fn test_alpn_server_advertise_multiple() {
517517
}
518518

519519
#[test]
520-
#[cfg(ossl110)]
520+
#[cfg(any(ossl110, boringssl))]
521521
fn test_alpn_server_select_none_fatal() {
522522
let mut server = Server::builder();
523523
server.ctx().set_alpn_select_callback(|_, client| {
@@ -533,7 +533,7 @@ fn test_alpn_server_select_none_fatal() {
533533
}
534534

535535
#[test]
536-
#[cfg(any(ossl102, libressl261))]
536+
#[cfg(any(ossl102, libressl261, boringssl))]
537537
fn test_alpn_server_select_none() {
538538
static CALLED_BACK: AtomicBool = AtomicBool::new(false);
539539

0 commit comments

Comments
 (0)