mirror of
https://github.com/eycorsican/leaf.git
synced 2026-12-06 08:02:36 +00:00
fix(config): refuse a client key on tls and quic outbounds
Both outbounds accepted certificateKey and rawCertificateKey and never used them: neither presents a client certificate. Someone who set one believed the server could tell this client apart, and it could not. Setting either is now a configuration error naming the outbound. The dead branches that chose between identical no-client-auth builders are gone.
This commit is contained in:
1 parent
857d3393f5
commit
3e2c66d539
4 files changed
+48
-22
No files matched your search
@@ -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`
|
||||
|
||||
@@ -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<String>,
|
||||
raw_certificate_key: &Option<Vec<String>>,
|
||||
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<internal::Config> {
|
||||
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<internal::Config> {
|
||||
"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<internal::Config> {
|
||||
} => {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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<Arc<ClientConfig>> {
|
||||
@@ -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()
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user