Skip to content

Commit

Permalink
MAL-359 Add RPK support to tokio-boring
Browse files Browse the repository at this point in the history
Assertions were added to the methods that can't be used in RPK mode. Without those we would hit assertions in BoringSSL code which causes SIGTERM on FFI boundary.
  • Loading branch information
inikulin committed Apr 28, 2021
1 parent 54375d1 commit 7f2cdcd
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 28 deletions.
45 changes: 38 additions & 7 deletions boring/src/ssl/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg==
-----END DH PARAMETERS-----
";

enum ContextType {
WithMethod(SslMethod),
Rpk,
}

#[allow(clippy::inconsistent_digit_grouping)]
fn ctx(method: SslMethod) -> Result<SslContextBuilder, ErrorStack> {
let mut ctx = SslContextBuilder::new(method)?;
fn ctx(ty: ContextType) -> Result<SslContextBuilder, ErrorStack> {
let mut ctx = match ty {
ContextType::WithMethod(method) => SslContextBuilder::new(method),
ContextType::Rpk => SslContextBuilder::new_rpk(),
}?;

let mut opts = SslOptions::ALL
| SslOptions::NO_COMPRESSION
Expand Down Expand Up @@ -64,7 +72,7 @@ impl SslConnector {
///
/// The default configuration is subject to change, and is currently derived from Python.
pub fn builder(method: SslMethod) -> Result<SslConnectorBuilder, ErrorStack> {
let mut ctx = ctx(method)?;
let mut ctx = ctx(ContextType::WithMethod(method))?;
ctx.set_default_verify_paths()?;
ctx.set_cipher_list(
"DEFAULT:!aNULL:!eNULL:!MD5:!3DES:!DES:!RC4:!IDEA:!SEED:!aDSS:!SRP:!PSK",
Expand All @@ -74,6 +82,16 @@ impl SslConnector {
Ok(SslConnectorBuilder(ctx))
}

/// Creates a new builder for TLS connections with raw public key.
pub fn rpk_builder() -> Result<SslConnectorBuilder, ErrorStack> {
let mut ctx = ctx(ContextType::Rpk)?;
ctx.set_cipher_list(
"DEFAULT:!aNULL:!eNULL:!MD5:!3DES:!DES:!RC4:!IDEA:!SEED:!aDSS:!SRP:!PSK",
)?;

Ok(SslConnectorBuilder(ctx))
}

/// Initiates a client-side TLS session on a stream.
///
/// The domain is used for SNI and hostname verification.
Expand Down Expand Up @@ -179,7 +197,7 @@ impl ConnectConfiguration {
self.ssl.set_hostname(domain)?;
}

if self.verify_hostname {
if !self.ssl.ssl_context().is_rpk() && self.verify_hostname {
setup_verify_hostname(&mut self.ssl, domain)?;
}

Expand Down Expand Up @@ -209,6 +227,19 @@ impl DerefMut for ConnectConfiguration {
pub struct SslAcceptor(SslContext);

impl SslAcceptor {
pub fn rpk() -> Result<SslAcceptorBuilder, ErrorStack> {
let mut ctx = ctx(ContextType::Rpk)?;
ctx.set_options(SslOptions::NO_TLSV1 | SslOptions::NO_TLSV1_1);
let dh = Dh::params_from_pem(FFDHE_2048.as_bytes())?;
ctx.set_tmp_dh(&dh)?;
ctx.set_cipher_list(
"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:\
ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:\
DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"
)?;
Ok(SslAcceptorBuilder(ctx))
}

/// Creates a new builder configured to connect to non-legacy clients. This should generally be
/// considered a reasonable default choice.
///
Expand All @@ -217,7 +248,7 @@ impl SslAcceptor {
///
/// [docs]: https://wiki.mozilla.org/Security/Server_Side_TLS
pub fn mozilla_intermediate_v5(method: SslMethod) -> Result<SslAcceptorBuilder, ErrorStack> {
let mut ctx = ctx(method)?;
let mut ctx = ctx(ContextType::WithMethod(method))?;
ctx.set_options(SslOptions::NO_TLSV1 | SslOptions::NO_TLSV1_1);
let dh = Dh::params_from_pem(FFDHE_2048.as_bytes())?;
ctx.set_tmp_dh(&dh)?;
Expand All @@ -238,7 +269,7 @@ impl SslAcceptor {
/// [docs]: https://wiki.mozilla.org/Security/Server_Side_TLS
// FIXME remove in next major version
pub fn mozilla_intermediate(method: SslMethod) -> Result<SslAcceptorBuilder, ErrorStack> {
let mut ctx = ctx(method)?;
let mut ctx = ctx(ContextType::WithMethod(method))?;
ctx.set_options(SslOptions::CIPHER_SERVER_PREFERENCE);
ctx.set_options(SslOptions::NO_TLSV1_3);
let dh = Dh::params_from_pem(FFDHE_2048.as_bytes())?;
Expand All @@ -264,7 +295,7 @@ impl SslAcceptor {
/// [docs]: https://wiki.mozilla.org/Security/Server_Side_TLS
// FIXME remove in next major version
pub fn mozilla_modern(method: SslMethod) -> Result<SslAcceptorBuilder, ErrorStack> {
let mut ctx = ctx(method)?;
let mut ctx = ctx(ContextType::WithMethod(method))?;
ctx.set_options(
SslOptions::CIPHER_SERVER_PREFERENCE | SslOptions::NO_TLSV1 | SslOptions::NO_TLSV1_1,
);
Expand Down

0 comments on commit 7f2cdcd

Please sign in to comment.