Skip to content

Commit a44ca94

Browse files
authored
Merge pull request #477 from stakpak/fix/warden-tls-interception-platform-verifier
fix: use platform TLS verifier in MCP proxy/client for warden CA trust
2 parents 418a9ee + 98d4a77 commit a44ca94

5 files changed

Lines changed: 40 additions & 2 deletions

File tree

Cargo.lock

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

libs/mcp/client/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ rmcp = { workspace = true }
1717
futures = { workspace = true }
1818
uuid = { workspace = true }
1919
reqwest = { workspace = true }
20+
rustls = { workspace = true }
21+
rustls-platform-verifier = { workspace = true }
2022

2123
[lints.clippy]
2224
unwrap_used = "deny"

libs/mcp/client/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,22 @@ pub async fn connect_https(
3434
.pool_max_idle_per_host(10)
3535
.tcp_keepalive(std::time::Duration::from_secs(60));
3636

37-
// Configure mTLS if certificate chain is provided
37+
// Configure TLS: use mTLS cert chain if provided, otherwise use
38+
// platform-verified TLS so the OS CA store is trusted.
3839
if let Some(cert_chain) = certificate_chain {
3940
let tls_config = cert_chain.create_client_config()?;
4041
client_builder = client_builder.use_preconfigured_tls(tls_config);
42+
} else {
43+
let arc_crypto_provider = std::sync::Arc::new(rustls::crypto::ring::default_provider());
44+
if let Ok(tls_config) = rustls::ClientConfig::builder_with_provider(arc_crypto_provider)
45+
.with_safe_default_protocol_versions()
46+
.map(|builder| {
47+
rustls_platform_verifier::BuilderVerifierExt::with_platform_verifier(builder)
48+
.with_no_client_auth()
49+
})
50+
{
51+
client_builder = client_builder.use_preconfigured_tls(tls_config);
52+
}
4153
}
4254

4355
let http_client = client_builder.build()?;

libs/mcp/proxy/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ rmcp = { workspace = true }
1717
tracing = { workspace = true }
1818
toml = { workspace = true }
1919
reqwest = { workspace = true }
20+
rustls = { workspace = true }
21+
rustls-platform-verifier = { workspace = true }
2022
axum = { workspace = true }
2123
axum-server = { workspace = true }

libs/mcp/proxy/src/server/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ impl ProxyServer {
374374
.pool_max_idle_per_host(10)
375375
.tcp_keepalive(std::time::Duration::from_secs(60));
376376

377-
// Configure mTLS if certificate chain is provided
377+
// Configure TLS: use mTLS cert chain if provided, otherwise use
378+
// platform-verified TLS so the OS CA store is trusted (needed for
379+
// warden container where a custom CA is installed).
378380
if let Some(cert_chain) = certificate_chain.as_ref() {
379381
match cert_chain.create_client_config() {
380382
Ok(tls_config) => {
@@ -385,6 +387,22 @@ impl ProxyServer {
385387
return;
386388
}
387389
}
390+
} else {
391+
// No mTLS cert chain — use platform verifier to trust system CA store
392+
let arc_crypto_provider =
393+
std::sync::Arc::new(rustls::crypto::ring::default_provider());
394+
if let Ok(tls_config) = rustls::ClientConfig::builder_with_provider(
395+
arc_crypto_provider,
396+
)
397+
.with_safe_default_protocol_versions()
398+
.map(|builder| {
399+
rustls_platform_verifier::BuilderVerifierExt::with_platform_verifier(
400+
builder,
401+
)
402+
.with_no_client_auth()
403+
}) {
404+
client_builder = client_builder.use_preconfigured_tls(tls_config);
405+
}
388406
}
389407

390408
if let Some(headers_map) = headers {

0 commit comments

Comments
 (0)