Skip to content

Commit 5fafc05

Browse files
Add KEYLIME_DIR support for verifier TLS certificates in push model agent
The push model agent previously had hardcoded CLI argument defaults for verifier TLS certificates that ignored the KEYLIME_DIR environment variable. This change adds proper KEYLIME_DIR support by introducing new config options that follow the same pattern used for registrar TLS certificates. Changes: - Add verifier_tls_ca_cert, verifier_tls_client_cert, and verifier_tls_client_key config fields - Make push model agent CLI args optional and use config values as defaults - Update keylime-agent.conf with documentation for new options - Path resolution now respects KEYLIME_DIR for verifier certificates Backward compatibility: - CLI arguments continue to work and override config values - Without KEYLIME_DIR, paths resolve to /var/lib/keylime/cv_ca/* (same as before) - With KEYLIME_DIR, paths resolve to $KEYLIME_DIR/cv_ca/* (new capability) Assisted-by: Claude 4.5 Sonnet Signed-off-by: Sergio Correia <[email protected]>
1 parent 8496841 commit 5fafc05

File tree

5 files changed

+126
-23
lines changed

5 files changed

+126
-23
lines changed

keylime-agent.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,16 @@ enable_authentication = false
390390
# Verifier URL (Push Model specific).
391391
# Verifier URL containing schema, host and port
392392
verifier_url = "https://localhost:8881"
393+
394+
# Verifier client TLS certificates (Push Model specific)
395+
# These certificates are used by the push model agent to authenticate with the verifier.
396+
# If set as "default", the paths below are used relative to keylime_dir.
397+
# If a relative path is set, it will be considered relative from the keylime_dir.
398+
# If an absolute path is set, it is used without change.
399+
#
400+
# To override verifier_tls_ca_cert, set KEYLIME_AGENT_VERIFIER_TLS_CA_CERT environment variable.
401+
# To override verifier_tls_client_cert, set KEYLIME_AGENT_VERIFIER_TLS_CLIENT_CERT environment variable.
402+
# To override verifier_tls_client_key, set KEYLIME_AGENT_VERIFIER_TLS_CLIENT_KEY environment variable.
403+
verifier_tls_ca_cert = "default" # default: cv_ca/cacert.crt
404+
verifier_tls_client_cert = "default" # default: cv_ca/client-cert.crt
405+
verifier_tls_client_key = "default" # default: cv_ca/client-private.pem

keylime-push-model-agent/src/main.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,17 @@ struct Args {
4444
#[arg(long, default_value = url_selector::DEFAULT_API_VERSION)]
4545
api_version: Option<String>,
4646
/// CA certificate file
47-
#[arg(long, default_value = "/var/lib/keylime/cv_ca/cacert.crt")]
48-
ca_certificate: String,
47+
/// If not provided, uses verifier_tls_ca_cert from config (default: $KEYLIME_DIR/cv_ca/cacert.crt)
48+
#[arg(long)]
49+
ca_certificate: Option<String>,
4950
/// Client certificate file
50-
#[arg(
51-
short,
52-
long,
53-
default_value = "/var/lib/keylime/cv_ca/client-cert.crt"
54-
)]
55-
certificate: String,
51+
/// If not provided, uses verifier_tls_client_cert from config (default: $KEYLIME_DIR/cv_ca/client-cert.crt)
52+
#[arg(short, long)]
53+
certificate: Option<String>,
5654
/// Client private key file
57-
#[arg(
58-
short,
59-
long,
60-
default_value = "/var/lib/keylime/cv_ca/client-private.pem"
61-
)]
62-
key: String,
55+
/// If not provided, uses verifier_tls_client_key from config (default: $KEYLIME_DIR/cv_ca/client-private.pem)
56+
#[arg(short, long)]
57+
key: Option<String>,
6358
/// json file
6459
#[arg(short, long, default_missing_value = "")]
6560
json_file: Option<String>,
@@ -237,16 +232,25 @@ async fn run(
237232
debug!("Negotiations request URL: {negotiations_request_url}");
238233
let neg_config = attestation::NegotiationConfig {
239234
avoid_tpm,
240-
ca_certificate: &args.ca_certificate,
241-
client_certificate: &args.certificate,
235+
ca_certificate: args
236+
.ca_certificate
237+
.as_deref()
238+
.unwrap_or(config.verifier_tls_ca_cert()),
239+
client_certificate: args
240+
.certificate
241+
.as_deref()
242+
.unwrap_or(config.verifier_tls_client_cert()),
242243
enable_authentication: config.enable_authentication(),
243244
agent_id: &agent_identifier,
244245
ima_log_path: Some(config.ima_ml_path.as_str()),
245246
initial_delay_ms: config
246247
.exponential_backoff_initial_delay
247248
.unwrap_or(1000),
248249
insecure: args.insecure,
249-
key: &args.key,
250+
key: args
251+
.key
252+
.as_deref()
253+
.unwrap_or(config.verifier_tls_client_key()),
250254
max_delay_ms: config.exponential_backoff_max_delay,
251255
max_retries: config.exponential_backoff_max_retries.unwrap_or(5),
252256
timeout: args.timeout,
@@ -634,9 +638,9 @@ mod tests {
634638
registrar_url: "".to_string(),
635639
verifier_url: Some("".to_string()),
636640
timeout: 0,
637-
ca_certificate: "".to_string(),
638-
certificate: "".to_string(),
639-
key: "".to_string(),
641+
ca_certificate: Some("".to_string()),
642+
certificate: Some("".to_string()),
643+
key: Some("".to_string()),
640644
insecure: None,
641645
agent_identifier: None,
642646
json_file: None,
@@ -669,9 +673,9 @@ mod tests {
669673
registrar_url: "".to_string(),
670674
verifier_url: Some("".to_string()),
671675
timeout: 0,
672-
ca_certificate: "".to_string(),
673-
certificate: "".to_string(),
674-
key: "".to_string(),
676+
ca_certificate: Some("".to_string()),
677+
certificate: Some("".to_string()),
678+
key: Some("".to_string()),
675679
insecure: None,
676680
agent_identifier: None,
677681
json_file: None,

keylime/src/config/base.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ pub static DEFAULT_PUSH_EK_HANDLE: &str = "";
119119
pub static DEFAULT_VERIFIER_URL: &str = "https://localhost:8881";
120120
pub static DEFAULT_REGISTRAR_URL: &str = "http://localhost:8888";
121121

122+
// Verifier client TLS certificate defaults (Push Model)
123+
// These are relative to KEYLIME_DIR, just like DEFAULT_TRUSTED_CLIENT_CA
124+
pub static DEFAULT_VERIFIER_TLS_CA_CERT: &str = "cv_ca/cacert.crt";
125+
pub static DEFAULT_VERIFIER_TLS_CLIENT_CERT: &str = "cv_ca/client-cert.crt";
126+
pub static DEFAULT_VERIFIER_TLS_CLIENT_KEY: &str = "cv_ca/client-private.pem";
127+
122128
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
123129
pub struct AgentConfig {
124130
pub agent_data_path: String,
@@ -188,6 +194,9 @@ pub struct AgentConfig {
188194
pub registrar_api_versions: String,
189195
pub uefi_logs_evidence_version: String,
190196
pub verifier_url: String,
197+
pub verifier_tls_ca_cert: String,
198+
pub verifier_tls_client_cert: String,
199+
pub verifier_tls_client_key: String,
191200

192201
// TLS security options
193202
/// Accept invalid TLS certificates (INSECURE - for testing only)
@@ -362,6 +371,9 @@ impl Default for AgentConfig {
362371
uefi_logs_evidence_version: DEFAULT_UEFI_LOGS_EVIDENCE_VERSION
363372
.to_string(),
364373
verifier_url: DEFAULT_VERIFIER_URL.to_string(),
374+
verifier_tls_ca_cert: "default".to_string(),
375+
verifier_tls_client_cert: "default".to_string(),
376+
verifier_tls_client_key: "default".to_string(),
365377

366378
// TLS security defaults - SECURE by default
367379
tls_accept_invalid_certs: false,
@@ -498,6 +510,30 @@ pub(crate) fn config_translate_keywords(
498510
true,
499511
);
500512

513+
let verifier_tls_ca_cert = config_get_file_path(
514+
"verifier_tls_ca_cert",
515+
&config.verifier_tls_ca_cert,
516+
keylime_dir,
517+
DEFAULT_VERIFIER_TLS_CA_CERT,
518+
false,
519+
);
520+
521+
let verifier_tls_client_cert = config_get_file_path(
522+
"verifier_tls_client_cert",
523+
&config.verifier_tls_client_cert,
524+
keylime_dir,
525+
DEFAULT_VERIFIER_TLS_CLIENT_CERT,
526+
false,
527+
);
528+
529+
let verifier_tls_client_key = config_get_file_path(
530+
"verifier_tls_client_key",
531+
&config.verifier_tls_client_key,
532+
keylime_dir,
533+
DEFAULT_VERIFIER_TLS_CLIENT_KEY,
534+
false,
535+
);
536+
501537
let ek_handle = match config.ek_handle.as_ref() {
502538
"generate" => "".to_string(),
503539
"" => "".to_string(),
@@ -668,6 +704,9 @@ pub(crate) fn config_translate_keywords(
668704
payload_key,
669705
trusted_client_ca,
670706
uuid,
707+
verifier_tls_ca_cert,
708+
verifier_tls_client_cert,
709+
verifier_tls_client_key,
671710
..config.clone()
672711
})
673712
}

keylime/src/config/env.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ mod test {
166166
),
167167
("KEYLIME_AGENT_UUID", "override_uuid"),
168168
("KEYLIME_AGENT_VERSION", "override_version"),
169+
(
170+
"KEYLIME_AGENT_VERIFIER_TLS_CA_CERT",
171+
"override_verifier_tls_ca_cert",
172+
),
173+
(
174+
"KEYLIME_AGENT_VERIFIER_TLS_CLIENT_CERT",
175+
"override_verifier_tls_client_cert",
176+
),
177+
(
178+
"KEYLIME_AGENT_VERIFIER_TLS_CLIENT_KEY",
179+
"override_verifier_tls_client_key",
180+
),
169181
]);
170182

171183
// Get the configuration using a temporary directory as `keylime_dir`

keylime/src/config/push_model.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ pub struct PushModelConfig {
6363
uefi_logs_evidence_version: String,
6464
uuid: String,
6565
verifier_url: String,
66+
verifier_tls_ca_cert: String,
67+
verifier_tls_client_cert: String,
68+
verifier_tls_client_key: String,
6669
}
6770

6871
#[cfg(feature = "testing")]
@@ -190,4 +193,36 @@ mod tests {
190193
DEFAULT_ENABLE_AUTHENTICATION
191194
);
192195
}
196+
197+
#[test]
198+
fn test_verifier_tls_cert_paths_default() {
199+
let tmpdir = tempfile::tempdir().expect("failed to create tmpdir");
200+
let config = get_testing_config(tmpdir.path(), None);
201+
202+
// Verify default paths are resolved correctly relative to keylime_dir
203+
assert_eq!(
204+
config.verifier_tls_ca_cert(),
205+
tmpdir
206+
.path()
207+
.join(DEFAULT_VERIFIER_TLS_CA_CERT)
208+
.display()
209+
.to_string()
210+
);
211+
assert_eq!(
212+
config.verifier_tls_client_cert(),
213+
tmpdir
214+
.path()
215+
.join(DEFAULT_VERIFIER_TLS_CLIENT_CERT)
216+
.display()
217+
.to_string()
218+
);
219+
assert_eq!(
220+
config.verifier_tls_client_key(),
221+
tmpdir
222+
.path()
223+
.join(DEFAULT_VERIFIER_TLS_CLIENT_KEY)
224+
.display()
225+
.to_string()
226+
);
227+
}
193228
}

0 commit comments

Comments
 (0)