Skip to content

Commit e14a9d6

Browse files
authored
Merge pull request #159 from cipherstash/rustls-platform-verifier
fix(deps): Add rustls-platform-verifier for certs
2 parents 78e79f8 + 00cbfe6 commit e14a9d6

File tree

4 files changed

+150
-19
lines changed

4 files changed

+150
-19
lines changed

Cargo.lock

Lines changed: 137 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cipherstash-proxy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ rust_decimal = { version = "1.36.0", default-features = false, features = [
3737
] }
3838
rustls = { version = "0.23.20", default-features = false, features = ["std"] }
3939
rustls-pemfile = "2.2.0"
40+
rustls-platform-verifier = "0.5.0"
4041
rustls-pki-types = "1.10.0"
4142
serde = "1.0"
4243
serde_json = "1.0"
@@ -54,7 +55,6 @@ tokio-util = { version = "0.7.13", features = ["rt"] }
5455
tracing = { workspace = true }
5556
tracing-subscriber = { workspace = true }
5657
uuid = { version = "1.11.0", features = ["serde", "v4"] }
57-
webpki-roots = "0.26.7"
5858
x509-parser = "0.17.0"
5959

6060

packages/cipherstash-proxy/src/config/tandem.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,15 @@ impl DatabaseConfig {
539539
pub fn connection_timeout(&self) -> Duration {
540540
Duration::from_millis(self.connection_timeout)
541541
}
542+
543+
pub fn server_name(&self) -> Result<ServerName, Error> {
544+
let name = ServerName::try_from(self.host.as_str()).map_err(|_| {
545+
ConfigError::InvalidServerName {
546+
name: self.host.to_owned(),
547+
}
548+
})?;
549+
Ok(name)
550+
}
542551
}
543552

544553
impl Display for DatabaseConfig {

packages/cipherstash-proxy/src/tls/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{DatabaseConfig, TandemConfig};
33
use rustls::client::danger::ServerCertVerifier;
44
use rustls::ClientConfig;
55
use rustls_pki_types::{pem::PemObject, CertificateDer, PrivateKeyDer, ServerName};
6+
use rustls_platform_verifier::ConfigVerifierExt;
67
use std::sync::Arc;
78
use tokio::net::TcpStream;
89
use tokio_rustls::{TlsAcceptor, TlsConnector, TlsStream};
@@ -17,7 +18,7 @@ pub async fn client(
1718
) -> Result<TlsStream<TcpStream>, Error> {
1819
let tls_config = configure_client(&config.database);
1920
let connector = TlsConnector::from(Arc::new(tls_config));
20-
let domain = config.server.server_name()?.to_owned();
21+
let domain = config.database.server_name()?.to_owned();
2122
let tls_stream = connector.connect(domain, stream).await?;
2223

2324
Ok(tls_stream.into())
@@ -70,12 +71,7 @@ pub fn configure_server(config: &TlsConfig) -> Result<rustls::ServerConfig, Erro
7071
/// The client will use the system root certificates
7172
///
7273
pub fn configure_client(config: &DatabaseConfig) -> ClientConfig {
73-
let mut root_cert_store = rustls::RootCertStore::empty();
74-
root_cert_store.extend(webpki_roots::TLS_SERVER_ROOTS.iter().cloned());
75-
76-
let mut tls_config = rustls::ClientConfig::builder()
77-
.with_root_certificates(root_cert_store)
78-
.with_no_client_auth();
74+
let mut tls_config = ClientConfig::with_platform_verifier();
7975

8076
if !config.with_tls_verification {
8177
let mut dangerous = tls_config.dangerous();

0 commit comments

Comments
 (0)