Skip to content

Commit dd0e070

Browse files
committed
keylimectl: Disable hostname checking in clients
This is necessary because keylime certificates don't properly set the Subject Alternative Name (SAN). Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent 8e0eb72 commit dd0e070

File tree

3 files changed

+10
-32
lines changed

3 files changed

+10
-32
lines changed

keylimectl/src/client/base.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ impl BaseClient {
131131
/// - Client certificate and key (if specified)
132132
/// - Server certificate verification (can be disabled for testing)
133133
/// - Connection timeout from config
134+
/// - Hostname verification disabled (required for Keylime certificates)
134135
/// - HTTP/2 and connection pooling
135136
///
136137
/// # Security Notes
137138
///
138139
/// - Client certificates enable mutual TLS authentication
140+
/// - Hostname verification is disabled for Keylime certificate compatibility
139141
/// - Server certificate verification should only be disabled for testing
140142
/// - Invalid certificates will cause connection failures
141143
///
@@ -153,7 +155,8 @@ impl BaseClient {
153155
config.tls.verify_server_cert, config.tls.client_cert, config.tls.client_key, config.tls.trusted_ca);
154156

155157
let mut builder = reqwest::Client::builder()
156-
.timeout(Duration::from_secs(config.client.timeout));
158+
.timeout(Duration::from_secs(config.client.timeout))
159+
.danger_accept_invalid_hostnames(true); // Required for Keylime certificates
157160

158161
// Configure TLS
159162
if !config.tls.verify_server_cert {

keylimectl/src/client/registrar.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ use log::{debug, info, warn};
6262
use reqwest::{Method, StatusCode};
6363
use serde_json::Value;
6464

65-
/// Unknown API version constant for when version detection fails
66-
pub const UNKNOWN_API_VERSION: &str = "unknown";
67-
6865
/// Supported API versions in order from oldest to newest (fallback tries newest first)
6966
pub const SUPPORTED_API_VERSIONS: &[&str] =
7067
&["2.0", "2.1", "2.2", "2.3", "3.0"];
@@ -375,12 +372,11 @@ impl RegistrarClient {
375372
}
376373
}
377374

378-
// If all versions failed, set to unknown and continue with default
375+
// If all versions failed, continue with default version
379376
warn!(
380377
"Could not detect registrar API version, using default: {}",
381378
self.api_version
382379
);
383-
self.api_version = UNKNOWN_API_VERSION.to_string();
384380
Ok(())
385381
}
386382

@@ -1081,10 +1077,6 @@ mod tests {
10811077
}
10821078
}
10831079

1084-
#[test]
1085-
fn test_unknown_api_version_constant() {
1086-
assert_eq!(UNKNOWN_API_VERSION, "unknown");
1087-
}
10881080

10891081
#[test]
10901082
fn test_response_structure_deserialization() {
@@ -1174,8 +1166,8 @@ mod tests {
11741166
client.api_version = "2.0".to_string();
11751167
assert_eq!(client.api_version, "2.0");
11761168

1177-
client.api_version = UNKNOWN_API_VERSION.to_string();
1178-
assert_eq!(client.api_version, "unknown");
1169+
client.api_version = "3.0".to_string();
1170+
assert_eq!(client.api_version, "3.0");
11791171
}
11801172

11811173
#[test]
@@ -1225,12 +1217,8 @@ mod tests {
12251217
#[allow(clippy::const_is_empty)]
12261218
fn test_version_constants_consistency() {
12271219
// Ensure our constants are consistent with expected patterns
1228-
assert!(!UNKNOWN_API_VERSION.is_empty()); // Known constant value
12291220
assert!(!SUPPORTED_API_VERSIONS.is_empty()); // Known constant value
12301221

1231-
// UNKNOWN_API_VERSION should not be in SUPPORTED_API_VERSIONS
1232-
assert!(!SUPPORTED_API_VERSIONS.contains(&UNKNOWN_API_VERSION));
1233-
12341222
// All supported versions should be valid version strings
12351223
for version in SUPPORTED_API_VERSIONS {
12361224
assert!(!version.is_empty());
@@ -1334,7 +1322,6 @@ mod tests {
13341322
SUPPORTED_API_VERSIONS,
13351323
verifier::SUPPORTED_API_VERSIONS
13361324
);
1337-
assert_eq!(UNKNOWN_API_VERSION, verifier::UNKNOWN_API_VERSION);
13381325
}
13391326

13401327
#[test]

keylimectl/src/client/verifier.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ use log::{debug, info, warn};
6161
use reqwest::{Method, StatusCode};
6262
use serde_json::Value;
6363

64-
/// Unknown API version constant for when version detection fails
65-
pub const UNKNOWN_API_VERSION: &str = "unknown";
66-
6764
/// Supported API versions in order from oldest to newest (fallback tries newest first)
6865
pub const SUPPORTED_API_VERSIONS: &[&str] =
6966
&["2.0", "2.1", "2.2", "2.3", "3.0"];
@@ -367,12 +364,11 @@ impl VerifierClient {
367364
}
368365
}
369366

370-
// If all versions failed, set to unknown and continue with default
367+
// If all versions failed, continue with default version
371368
warn!(
372369
"Could not detect verifier API version, using default: {}",
373370
self.api_version
374371
);
375-
self.api_version = UNKNOWN_API_VERSION.to_string();
376372
Ok(())
377373
}
378374

@@ -1528,10 +1524,6 @@ mod tests {
15281524
}
15291525
}
15301526

1531-
#[test]
1532-
fn test_unknown_api_version_constant() {
1533-
assert_eq!(UNKNOWN_API_VERSION, "unknown");
1534-
}
15351527

15361528
#[test]
15371529
fn test_response_structure_deserialization() {
@@ -1621,8 +1613,8 @@ mod tests {
16211613
client.api_version = "2.0".to_string();
16221614
assert_eq!(client.api_version, "2.0");
16231615

1624-
client.api_version = UNKNOWN_API_VERSION.to_string();
1625-
assert_eq!(client.api_version, "unknown");
1616+
client.api_version = "3.0".to_string();
1617+
assert_eq!(client.api_version, "3.0");
16261618
}
16271619

16281620
#[test]
@@ -1672,12 +1664,8 @@ mod tests {
16721664
#[allow(clippy::const_is_empty)]
16731665
fn test_version_constants_consistency() {
16741666
// Ensure our constants are consistent with expected patterns
1675-
assert!(!UNKNOWN_API_VERSION.is_empty()); // Known constant value
16761667
assert!(!SUPPORTED_API_VERSIONS.is_empty()); // Known constant value
16771668

1678-
// UNKNOWN_API_VERSION should not be in SUPPORTED_API_VERSIONS
1679-
assert!(!SUPPORTED_API_VERSIONS.contains(&UNKNOWN_API_VERSION));
1680-
16811669
// All supported versions should be valid version strings
16821670
for version in SUPPORTED_API_VERSIONS {
16831671
assert!(!version.is_empty());

0 commit comments

Comments
 (0)