You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
main: Move IAK/IDevID related code to dedicated module
Move the IAK/IDevID initialization code to the dedicated module
'device_id'.
The module implements the builder pattern to set the parameters set
through configuration.
The goal is to simplify the code in main.
Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
let idevid = if config.agent.idevid_handle.trim().is_empty(){
398
-
/// If handle is not set in config, recreate IDevID according to template
399
-
info!("Recreating IDevID.");
400
-
let regen_idev = ctx.create_idevid(asym_alg, name_alg)?;
401
-
ctx.flush_context(regen_idev.handle.into())?;
402
-
// Flush after creating to make room for AK and EK and IAK
403
-
regen_idev
404
-
}else{
405
-
info!("Collecting persisted IDevID.");
406
-
ctx.idevid_from_handle(
407
-
config.agent.idevid_handle.as_str(),
408
-
config.agent.idevid_password.as_str(),
409
-
)?
410
-
};
411
-
/// Check that recreated/collected IDevID key matches the one in the certificate
412
-
if crypto::check_x509_key(
413
-
&idevid_cert.clone().ok_or(Error::Other(
414
-
"IAK/IDevID enabled but IDevID cert could not be used"
415
-
.to_string(),
416
-
))?,
417
-
idevid.clone().public,
418
-
)? {
419
-
info!("IDevID matches certificate.");
420
-
}else{
421
-
error!("IDevID template does not match certificate. Check template in configuration.");
422
-
returnErr(Error::Configuration(config::KeylimeConfigError::Generic("IDevID template does not match certificate. Check template in configuration.".to_string())));
423
-
}
424
-
425
-
/// IAK recreation/collection
426
-
let iak = if config.agent.iak_handle.trim().is_empty(){
427
-
/// If handle is not set in config, recreate IAK according to template
428
-
info!("Recreating IAK.");
429
-
ctx.create_iak(asym_alg, name_alg)?
430
-
}else{
431
-
/// If a handle has been set, try to collect from the handle
432
-
/// If there is an IAK password, add the password to the handle
433
-
info!("Collecting persisted IAK.");
434
-
ctx.iak_from_handle(
435
-
config.agent.iak_handle.as_str(),
436
-
config.agent.iak_password.as_str(),
437
-
)?
438
-
};
439
-
/// Check that recreated/collected IAK key matches the one in the certificate
440
-
if crypto::check_x509_key(
441
-
&iak_cert.clone().ok_or(Error::Other(
442
-
"IAK/IDevID enabled but IAK cert could not be used"
443
-
.to_string(),
444
-
))?,
445
-
iak.clone().public,
446
-
)? {
447
-
info!("IAK matches certificate.");
448
-
}else{
449
-
error!("IAK template does not match certificate. Check template in configuration.");
450
-
returnErr(Error::Configuration(config::KeylimeConfigError::Generic("IAK template does not match certificate. Check template in configuration.".to_string())));
451
-
}
452
-
453
-
(Some(iak),Some(idevid))
454
-
}else{
455
-
(None,None)
456
-
};
457
-
458
330
// Gather EK values and certs
459
331
let ek_result = match config.agent.ek_handle.as_ref(){
0 commit comments