@@ -53,15 +53,12 @@ pub struct FillerFromHardware<'a> {
53
53
54
54
impl < ' a > FillerFromHardware < ' a > {
55
55
pub fn new ( tpm_context_info : & ' a mut ContextInfo ) -> Self {
56
- // TODO: Change config obtaining here to avoid repetitions
56
+ // TODO: Change this to avoid loading the configuration multiple times
57
57
// TODO: Modify here to avoid panic on failure
58
- let global_config = AgentConfig :: new ( ) ;
59
- let ml_path = match global_config {
60
- Ok ( config) => config. measuredboot_ml_path . clone ( ) ,
61
- Err ( _) => "" . to_string ( ) ,
62
- } ;
63
- let uefi_log_handler =
64
- uefi_log_handler:: UefiLogHandler :: new ( & ml_path) ;
58
+ let config =
59
+ AgentConfig :: new ( ) . expect ( "failed to load configuration" ) ;
60
+ let ml_path = config. measuredboot_ml_path ( ) ;
61
+ let uefi_log_handler = uefi_log_handler:: UefiLogHandler :: new ( ml_path) ;
65
62
match uefi_log_handler {
66
63
Ok ( handler) => FillerFromHardware {
67
64
tpm_context_info,
@@ -81,8 +78,10 @@ impl<'a> FillerFromHardware<'a> {
81
78
fn get_attestation_request_final (
82
79
& mut self ,
83
80
) -> structures:: AttestationRequest {
84
- // TODO: Change config obtaining here to avoid repetitions
85
- let config = keylime:: config:: PushModelConfig :: default ( ) ;
81
+ // TODO: Change this to avoid loading the configuration multiple times
82
+ // TODO Modify this to not panic on failure
83
+ let config =
84
+ AgentConfig :: new ( ) . expect ( "failed to load configuration" ) ;
86
85
let tpmc_ref = self . tpm_context_info . get_mutable_tpm_context ( ) ;
87
86
let tpm_banks_sha1 =
88
87
tpmc_ref. pcr_banks ( HashAlgorithm :: Sha1 ) . unwrap_or_else ( |_| {
@@ -95,6 +94,7 @@ impl<'a> FillerFromHardware<'a> {
95
94
error ! ( "Failed to get PCR banks for SHA256" ) ;
96
95
vec ! [ ]
97
96
} ) ;
97
+ // TODO: Change this to avoid loading the configuration multiple times
98
98
// TODO Modify this to not panic on failure
99
99
let default =
100
100
AgentConfig :: new ( ) . expect ( "failed to load default config" ) ;
@@ -139,21 +139,23 @@ impl<'a> FillerFromHardware<'a> {
139
139
structures:: EvidenceSupported :: EvidenceLog {
140
140
evidence_type: "uefi_log" . to_string( ) ,
141
141
capabilities: structures:: LogCapabilities {
142
- evidence_version: Some ( config. get_uefi_logs_evidence_version ( ) ) ,
142
+ evidence_version: Some ( config. uefi_logs_evidence_version ( ) . to_string ( ) ) ,
143
143
entry_count: uefi_count,
144
- supports_partial_access: config. get_uefi_logs_supports_partial_access( ) ,
145
- appendable: config. get_uefi_logs_appendable( ) ,
146
- formats: config. get_uefi_logs_formats( ) ,
144
+ supports_partial_access: config. uefi_logs_supports_partial_access( ) ,
145
+ appendable: config. uefi_logs_appendable( ) ,
146
+ // TODO: make this to not panic on failure
147
+ formats: config. uefi_logs_formats( ) . expect( "failed to get uefi_logs_formats" ) . iter( ) . map( |e| e. to_string( ) ) . collect( ) ,
147
148
} ,
148
149
} ,
149
150
structures:: EvidenceSupported :: EvidenceLog {
150
151
evidence_type: "ima_log" . to_string( ) ,
151
152
capabilities: structures:: LogCapabilities {
152
153
evidence_version: None ,
153
154
entry_count: ima_log_count,
154
- supports_partial_access: config. get_ima_logs_supports_partial_access( ) ,
155
- appendable: config. get_ima_logs_appendable( ) ,
156
- formats: config. get_ima_logs_formats( ) ,
155
+ supports_partial_access: config. ima_logs_supports_partial_access( ) ,
156
+ appendable: config. ima_logs_appendable( ) ,
157
+ // TODO: make this to not panic on failure
158
+ formats: config. ima_logs_formats( ) . expect( "failed to get ima_log_formats" ) . iter( ) . map( |e| e. to_string( ) ) . collect( ) ,
157
159
} ,
158
160
} ,
159
161
] ,
@@ -393,7 +395,7 @@ mod tests {
393
395
use super :: * ;
394
396
395
397
#[ cfg( feature = "testing" ) ]
396
- use keylime:: tpm:: testing;
398
+ use keylime:: { config :: get_testing_config , context_info , tpm:: testing} ;
397
399
398
400
#[ test]
399
401
fn get_attestation_request_test ( ) {
@@ -658,14 +660,14 @@ mod tests {
658
660
#[ tokio:: test]
659
661
#[ cfg( feature = "testing" ) ]
660
662
async fn test_attestation_request_final ( ) {
661
- use keylime:: context_info;
662
663
let _mutex = testing:: lock_tests ( ) . await ;
663
- let config = keylime:: config:: PushModelConfig :: default ( ) ;
664
+ let tmpdir = tempfile:: tempdir ( ) . expect ( "failed to create tmpdir" ) ;
665
+ let config = get_testing_config ( tmpdir. path ( ) ) ;
664
666
let mut context_info = context_info:: ContextInfo :: new_from_str (
665
667
context_info:: AlgorithmConfigurationString {
666
- tpm_encryption_alg : config. get_tpm_encryption_alg ( ) ,
667
- tpm_hash_alg : config. get_tpm_hash_alg ( ) ,
668
- tpm_signing_alg : config. get_tpm_signing_alg ( ) ,
668
+ tpm_encryption_alg : config. tpm_encryption_alg ( ) . to_string ( ) ,
669
+ tpm_hash_alg : config. tpm_hash_alg ( ) . to_string ( ) ,
670
+ tpm_signing_alg : config. tpm_signing_alg ( ) . to_string ( ) ,
669
671
agent_data_path : "" . to_string ( ) ,
670
672
} ,
671
673
)
@@ -683,12 +685,13 @@ mod tests {
683
685
async fn test_session_request ( ) {
684
686
use keylime:: context_info;
685
687
let _mutex = testing:: lock_tests ( ) . await ;
686
- let config = keylime:: config:: PushModelConfig :: default ( ) ;
688
+ let tmpdir = tempfile:: tempdir ( ) . expect ( "failed to create tmpdir" ) ;
689
+ let config = get_testing_config ( tmpdir. path ( ) ) ;
687
690
let mut context_info = context_info:: ContextInfo :: new_from_str (
688
691
context_info:: AlgorithmConfigurationString {
689
- tpm_encryption_alg : config. get_tpm_encryption_alg ( ) ,
690
- tpm_hash_alg : config. get_tpm_hash_alg ( ) ,
691
- tpm_signing_alg : config. get_tpm_signing_alg ( ) ,
692
+ tpm_encryption_alg : config. tpm_encryption_alg ( ) . to_string ( ) ,
693
+ tpm_hash_alg : config. tpm_hash_alg ( ) . to_string ( ) ,
694
+ tpm_signing_alg : config. tpm_signing_alg ( ) . to_string ( ) ,
692
695
agent_data_path : "" . to_string ( ) ,
693
696
} ,
694
697
)
@@ -706,12 +709,13 @@ mod tests {
706
709
async fn test_evidence_handling_request ( ) {
707
710
use keylime:: context_info;
708
711
let _mutex = testing:: lock_tests ( ) . await ;
709
- let config = keylime:: config:: PushModelConfig :: default ( ) ;
712
+ let tmpdir = tempfile:: tempdir ( ) . expect ( "failed to create tmpdir" ) ;
713
+ let config = get_testing_config ( tmpdir. path ( ) ) ;
710
714
let mut context_info = context_info:: ContextInfo :: new_from_str (
711
715
context_info:: AlgorithmConfigurationString {
712
- tpm_encryption_alg : config. get_tpm_encryption_alg ( ) ,
713
- tpm_hash_alg : config. get_tpm_hash_alg ( ) ,
714
- tpm_signing_alg : config. get_tpm_signing_alg ( ) ,
716
+ tpm_encryption_alg : config. tpm_encryption_alg ( ) . to_string ( ) ,
717
+ tpm_hash_alg : config. tpm_hash_alg ( ) . to_string ( ) ,
718
+ tpm_signing_alg : config. tpm_signing_alg ( ) . to_string ( ) ,
715
719
agent_data_path : "" . to_string ( ) ,
716
720
} ,
717
721
)
0 commit comments