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

feat(tls): Add support for rustls ignore_client_order #2042

Merged
merged 7 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 0 deletions tonic/src/transport/server/service/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl TlsAcceptor {
identity: Identity,
client_ca_root: Option<Certificate>,
client_auth_optional: bool,
ignore_client_order: bool,
) -> Result<Self, crate::BoxError> {
let builder = ServerConfig::builder();

Expand All @@ -42,6 +43,7 @@ impl TlsAcceptor {

let (cert, key) = convert_identity_to_pki_types(&identity)?;
let mut config = builder.with_single_cert(cert, key)?;
config.ignore_client_order = ignore_client_order;

config.alpn_protocols.push(ALPN_H2.into());
Ok(Self {
Expand Down
15 changes: 15 additions & 0 deletions tonic/src/transport/server/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct ServerTlsConfig {
identity: Option<Identity>,
client_ca_root: Option<Certificate>,
client_auth_optional: bool,
ignore_client_order: bool,
}

impl fmt::Debug for ServerTlsConfig {
Expand All @@ -24,6 +25,7 @@ impl ServerTlsConfig {
identity: None,
client_ca_root: None,
client_auth_optional: false,
ignore_client_order: false,
}
}

Expand Down Expand Up @@ -56,11 +58,24 @@ impl ServerTlsConfig {
}
}

/// Sets whether the server's cipher preferences are followed instead of the client's.
/// It prevents attacks such as POODLE
tottoto marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Default
/// By default, this option is set to `false`.
pub fn ignore_client_order(self, ignore_client_order: bool) -> Self {
ServerTlsConfig {
ignore_client_order,
..self
}
}

pub(crate) fn tls_acceptor(&self) -> Result<TlsAcceptor, crate::BoxError> {
TlsAcceptor::new(
self.identity.clone().unwrap(),
self.client_ca_root.clone(),
self.client_auth_optional,
self.ignore_client_order,
)
}
}