Skip to content

Commit 223b9ee

Browse files
committed
config: Make IAK and IDevID certificates optional
When IAK/IDevID are enabled, but the paths to the certificates are explicitly configured as the empty string, continue normally and register without IAK and IDevID certificates. This is to make it possible to use IAK and IDevID without the certificates, in case the user does the public key matching check separately. Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent 123dc7d commit 223b9ee

File tree

4 files changed

+259
-80
lines changed

4 files changed

+259
-80
lines changed

keylime-agent/src/config.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -501,34 +501,39 @@ fn config_translate_keywords(
501501
&config.agent.agent_data_path,
502502
keylime_dir,
503503
DEFAULT_AGENT_DATA_PATH,
504+
false,
504505
);
505506

506507
let mut ima_ml_path = config_get_file_path(
507508
"ima_ml_path",
508509
&config.agent.ima_ml_path,
509510
root_path,
510511
DEFAULT_IMA_ML_PATH,
512+
false,
511513
);
512514

513515
let mut measuredboot_ml_path = config_get_file_path(
514516
"measuredboot_ml_path",
515517
&config.agent.measuredboot_ml_path,
516518
root_path,
517519
DEFAULT_MEASUREDBOOT_ML_PATH,
520+
false,
518521
);
519522

520523
let mut server_key = config_get_file_path(
521524
"server_key",
522525
&config.agent.server_key,
523526
keylime_dir,
524527
DEFAULT_SERVER_KEY,
528+
false,
525529
);
526530

527531
let mut server_cert = config_get_file_path(
528532
"server_cert",
529533
&config.agent.server_cert,
530534
keylime_dir,
531535
DEFAULT_SERVER_CERT,
536+
false,
532537
);
533538

534539
let trusted_client_ca: String =
@@ -540,6 +545,7 @@ fn config_translate_keywords(
540545
t,
541546
keylime_dir,
542547
DEFAULT_TRUSTED_CLIENT_CA,
548+
false,
543549
)
544550
})
545551
.collect::<Vec<_>>()
@@ -550,13 +556,15 @@ fn config_translate_keywords(
550556
&config.agent.iak_cert,
551557
keylime_dir,
552558
DEFAULT_IAK_CERT,
559+
true,
553560
);
554561

555562
let mut idevid_cert = config_get_file_path(
556563
"idevid_cert",
557564
&config.agent.idevid_cert,
558565
keylime_dir,
559566
DEFAULT_IDEVID_CERT,
567+
true,
560568
);
561569

562570
let ek_handle = match config.agent.ek_handle.as_ref() {
@@ -630,6 +638,7 @@ fn config_translate_keywords(
630638
&config.agent.revocation_cert,
631639
keylime_dir,
632640
&format!("secure/unzipped/{DEFAULT_REVOCATION_CERT}"),
641+
false,
633642
);
634643

635644
Ok(KeylimeConfig {
@@ -657,18 +666,23 @@ fn config_translate_keywords(
657666
/// Expand a file path from the configuration file.
658667
///
659668
/// If the string is set as "default", return the provided default path relative from the provided work_dir.
660-
/// If the string is empty, use again the default value
669+
/// If the string is empty, use the default value unless the 'leave_empty' is 'true'
661670
/// If the string is a relative path, return the path relative from the provided work_dir
662671
/// If the string is an absolute path, return the path without change.
663672
fn config_get_file_path(
664673
option: &str,
665674
path: &str,
666675
work_dir: &Path,
667676
default: &str,
677+
leave_empty: bool,
668678
) -> String {
669679
match path {
670680
"default" => work_dir.join(default).display().to_string(),
671681
"" => {
682+
if leave_empty {
683+
return "".to_string();
684+
}
685+
672686
warn!("Empty string provided in configuration option {option}, using default {default}");
673687
work_dir.join(default).display().to_string()
674688
}
@@ -1107,7 +1121,7 @@ mod tests {
11071121

11081122
let translated: Vec<String> = list
11091123
.iter()
1110-
.map(|e| config_get_file_path("test", e, workdir, default))
1124+
.map(|e| config_get_file_path("test", e, workdir, default, false))
11111125
.collect();
11121126

11131127
assert_eq!(
@@ -1122,5 +1136,13 @@ mod tests {
11221136
],
11231137
translated
11241138
);
1139+
1140+
let translated =
1141+
config_get_file_path("test", "", workdir, "default", true);
1142+
assert_eq!("", translated);
1143+
1144+
let translated =
1145+
config_get_file_path("test", "", workdir, "default", false);
1146+
assert_eq!("/workdir/default", translated);
11251147
}
11261148
}

keylime-agent/src/main.rs

+28-20
Original file line numberDiff line numberDiff line change
@@ -436,22 +436,30 @@ async fn main() -> Result<()> {
436436

437437
// If using IAK/IDevID is enabled, obtain IAK/IDevID and respective certificates
438438
let mut device_id = if config.agent.enable_iak_idevid {
439-
Some(
440-
DeviceIDBuilder::new()
441-
.iak_handle(&config.agent.iak_handle)
442-
.iak_cert_path(&config.agent.iak_cert)
443-
.iak_password(&config.agent.iak_password)
444-
.iak_template(&config.agent.iak_idevid_template)
445-
.iak_asym_alg(&config.agent.iak_idevid_asymmetric_alg)
446-
.iak_hash_alg(&config.agent.iak_idevid_name_alg)
447-
.idevid_handle(&config.agent.idevid_handle)
448-
.idevid_cert_path(&config.agent.idevid_cert)
449-
.idevid_password(&config.agent.idevid_password)
450-
.idevid_template(&config.agent.iak_idevid_template)
451-
.idevid_asym_alg(&config.agent.iak_idevid_asymmetric_alg)
452-
.idevid_hash_alg(&config.agent.iak_idevid_name_alg)
453-
.build(&mut ctx)?,
454-
)
439+
let mut builder = DeviceIDBuilder::new()
440+
.iak_handle(&config.agent.iak_handle)
441+
.iak_password(&config.agent.iak_password)
442+
.iak_default_template(config::DEFAULT_IAK_IDEVID_TEMPLATE)
443+
.iak_template(&config.agent.iak_idevid_template)
444+
.iak_asym_alg(&config.agent.iak_idevid_asymmetric_alg)
445+
.iak_hash_alg(&config.agent.iak_idevid_name_alg)
446+
.idevid_handle(&config.agent.idevid_handle)
447+
.idevid_cert_path(&config.agent.idevid_cert)
448+
.idevid_password(&config.agent.idevid_password)
449+
.idevid_default_template(config::DEFAULT_IAK_IDEVID_TEMPLATE)
450+
.idevid_template(&config.agent.iak_idevid_template)
451+
.idevid_asym_alg(&config.agent.iak_idevid_asymmetric_alg)
452+
.idevid_hash_alg(&config.agent.iak_idevid_name_alg);
453+
454+
if !&config.agent.iak_cert.is_empty() {
455+
builder = builder.iak_cert_path(&config.agent.iak_cert);
456+
}
457+
458+
if !&config.agent.idevid_cert.is_empty() {
459+
builder = builder.idevid_cert_path(&config.agent.idevid_cert);
460+
}
461+
462+
Some(builder.build(&mut ctx)?)
455463
} else {
456464
None
457465
};
@@ -617,15 +625,15 @@ async fn main() -> Result<()> {
617625
ek_result.ek_cert,
618626
&PublicBuffer::try_from(ak.public)?.marshall()?,
619627
Some(
620-
&PublicBuffer::try_from(dev_id.iak.public.clone())?
628+
&PublicBuffer::try_from(dev_id.iak_pubkey.clone())?
621629
.marshall()?,
622630
),
623631
Some(
624-
&PublicBuffer::try_from(dev_id.idevid.public.clone())?
632+
&PublicBuffer::try_from(dev_id.idevid_pubkey.clone())?
625633
.marshall()?,
626634
),
627-
Some(dev_id.idevid_cert.clone()),
628-
Some(dev_id.iak_cert.clone()),
635+
dev_id.idevid_cert.clone(),
636+
dev_id.iak_cert.clone(),
629637
Some(attest.marshall()?),
630638
Some(signature.marshall()?),
631639
mtls_cert,

0 commit comments

Comments
 (0)