Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tls): for incoming connection alpn negotiation should be done using set_alpn_select_callback #18843

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/vector-core/src/tls/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl TlsSettings {
Some(_) => {
let mut acceptor = SslAcceptor::mozilla_intermediate(SslMethod::tls())
.context(CreateAcceptorSnafu)?;
self.apply_context(&mut acceptor)?;
self.apply_context_base(&mut acceptor, true)?;
Ok(acceptor.build())
}
}
Expand Down
23 changes: 19 additions & 4 deletions lib/vector-core/src/tls/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use openssl::{
pkcs12::{ParsedPkcs12_2, Pkcs12},
pkey::{PKey, Private},
ssl::{ConnectConfiguration, SslContextBuilder, SslVerifyMode},
ssl::{select_next_proto, AlpnError, ConnectConfiguration, SslContextBuilder, SslVerifyMode},
stack::Stack,
x509::{store::X509StoreBuilder, X509},
};
Expand Down Expand Up @@ -268,6 +268,14 @@
}

pub(super) fn apply_context(&self, context: &mut SslContextBuilder) -> Result<()> {
self.apply_context_base(context, false)
}

pub(super) fn apply_context_base(
&self,
context: &mut SslContextBuilder,
for_server: bool,
) -> Result<()> {
context.set_verify(if self.verify_certificate {
SslVerifyMode::PEER | SslVerifyMode::FAIL_IF_NO_PEER_CERT
} else {
Expand Down Expand Up @@ -310,9 +318,16 @@
}

if let Some(alpn) = &self.alpn_protocols {
context
.set_alpn_protos(alpn.as_slice())
.context(SetAlpnProtocolsSnafu)?;
if !for_server {

Check failure on line 321 in lib/vector-core/src/tls/settings.rs

View workflow job for this annotation

GitHub Actions / Checks

unnecessary boolean `not` operation
context
.set_alpn_protos(alpn.as_slice())
.context(SetAlpnProtocolsSnafu)?;
} else {
let server_proto = alpn.clone();
context.set_alpn_select_callback(move |_, client_proto| {

Check failure on line 327 in lib/vector-core/src/tls/settings.rs

View workflow job for this annotation

GitHub Actions / Checks

consider adding a `;` to the last statement for consistent formatting
select_next_proto(server_proto.as_slice(), client_proto).ok_or(AlpnError::NOACK)
})
}
}

Ok(())
Expand Down
Loading