diff --git a/docs/configuration.md b/docs/configuration.md index a2eb6d5..0b02531 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -489,7 +489,7 @@ The TLS transport. | `alpn` | ALPN protocols to offer, e.g. `["http/1.1"]` | none offered | | `certificate` | Trust these CA certificates (path or inline PEM) *instead of* the bundled public roots | bundled public roots | | `rawCertificate` | The same as a list of PEM lines | | -| `certificateKey`, `rawCertificateKey` | Accepted and unused: there is no client certificate | | +| `certificateKey`, `rawCertificateKey` | Refused: there is no client certificate, and a key would only look like one | | | `insecure` | Skip certificate verification | `false` | | `ech` | Use Encrypted Client Hello, with the config list looked up in DNS (`HTTPS` record) | `false` | | `echConfigList` | A fixed ECH config list (base64), used when the lookup fails or is disabled | none | @@ -532,7 +532,7 @@ A QUIC transport to a server. | `address`, `port` | The server | required | | `serverName` | Name to verify the certificate against | `address` | | `certificate`, `rawCertificate` | CA to trust instead of the public roots | public roots | -| `certificateKey`, `rawCertificateKey` | Accepted and unused | | +| `certificateKey`, `rawCertificateKey` | Refused, as for `tls` | | | `alpn` | ALPN protocols | none | ### `amux` diff --git a/leaf/src/config/common.rs b/leaf/src/config/common.rs index 3fca256..f9b1d34 100644 --- a/leaf/src/config/common.rs +++ b/leaf/src/config/common.rs @@ -565,6 +565,23 @@ fn validate_non_empty_str(value: &str, field_name: &str, protocol: &str) -> Resu Ok(()) } +/// Outbound TLS has no client certificate, so a key configured for one would +/// do nothing while the deployer believed the server could tell this client +/// from any other. +fn refuse_client_key( + certificate_key: &Option, + raw_certificate_key: &Option>, + tag: &str, +) -> Result<()> { + if certificate_key.is_some() || raw_certificate_key.is_some() { + return Err(anyhow::anyhow!( + "invalid [{}] outbound settings: client certificates are not supported, remove certificateKey", + tag + )); + } + Ok(()) +} + pub fn to_internal(mut config: Config) -> Result { let mut log = internal::Log::new(); if let Some(ext_log) = &config.log { @@ -1179,6 +1196,11 @@ pub fn to_internal(mut config: Config) -> Result { "tls outbound", )?; } + refuse_client_key( + &ext_settings.certificate_key, + &ext_settings.raw_certificate_key, + &outbound.tag, + )?; let mut settings = internal::TlsOutboundSettings::new(); if let Some(ext_server_name) = &ext_settings.server_name { settings.server_name = ext_server_name.clone(); @@ -1345,6 +1367,11 @@ pub fn to_internal(mut config: Config) -> Result { } => { outbound.protocol = "quic".to_string(); if let Some(ext_settings) = ext_settings { + refuse_client_key( + &ext_settings.certificate_key, + &ext_settings.raw_certificate_key, + &outbound.tag, + )?; let mut settings = internal::QuicOutboundSettings::new(); if let Some(ext_address) = &ext_settings.address { settings.address = ext_address.clone(); @@ -1749,4 +1776,18 @@ mod tests { .unwrap(); assert_eq!(settings.security, "aes-128-gcm"); } + + #[cfg(feature = "config-json")] + #[test] + fn an_outbound_client_key_is_refused() { + let tls = |extra: &str| { + crate::config::json::from_string(&format!( + r#"{{"outbounds": [{{"tag": "t", "protocol": "tls", "settings": {{"serverName": "example.com"{}}}}}]}}"#, + extra + )) + }; + assert!(tls("").is_ok()); + assert!(tls(r#", "certificateKey": "/etc/leaf/client.key""#).is_err()); + assert!(tls(r#", "rawCertificateKey": ["-----BEGIN PRIVATE KEY-----"]"#).is_err()); + } } diff --git a/leaf/src/proxy/quic/outbound/stream.rs b/leaf/src/proxy/quic/outbound/stream.rs index 6bf8858..ec5ccf2 100644 --- a/leaf/src/proxy/quic/outbound/stream.rs +++ b/leaf/src/proxy/quic/outbound/stream.rs @@ -77,16 +77,9 @@ impl Manager { .unwrap() .with_root_certificates(roots); - let mut client_crypto = if let Some(_certificate) = certificate { - if let Some(_certificate_key) = certificate_key { - // FIXME support client auth - builder.with_no_client_auth() - } else { - builder.with_no_client_auth() - } - } else { - builder.with_no_client_auth() - }; + // There is no client certificate: the config refuses a key for one. + let _ = certificate_key; + let mut client_crypto = builder.with_no_client_auth(); for alpn in alpns { client_crypto.alpn_protocols.push(alpn.as_bytes().to_vec()); } diff --git a/leaf/src/proxy/tls/outbound/stream.rs b/leaf/src/proxy/tls/outbound/stream.rs index 4092363..e50fa94 100644 --- a/leaf/src/proxy/tls/outbound/stream.rs +++ b/leaf/src/proxy/tls/outbound/stream.rs @@ -122,7 +122,7 @@ impl Handler { fn build_rustls_config( alpns: &[String], certificate: Option<&String>, - certificate_key: Option<&String>, + _certificate_key: Option<&String>, insecure: bool, ech_config_list: Option<&str>, ) -> Result> { @@ -185,15 +185,7 @@ impl Handler { let builder = builder .dangerous() .with_custom_certificate_verifier(Arc::new(dangerous::NotVerified)); - if certificate.is_some() { - if certificate_key.is_some() { - builder.with_no_client_auth() - } else { - builder.with_no_client_auth() - } - } else { - builder.with_no_client_auth() - } + builder.with_no_client_auth() } else { builder.with_root_certificates(roots).with_no_client_auth() };