@@ -98,6 +98,9 @@ pub const DEFAULT_EXP_BACKOFF_INITIAL_DELAY: u32 = 10000; // 10 seconds
9898pub const DEFAULT_EXP_BACKOFF_MAX_RETRIES : u32 = 5 ;
9999pub const DEFAULT_EXP_BACKOFF_MAX_DELAY : u32 = 300000 ; // 300 seconds
100100
101+ // Default attestation interval for push model (in seconds)
102+ pub const DEFAULT_ATTESTATION_INTERVAL_SECONDS : u64 = 60 ;
103+
101104// TODO These should be temporary
102105pub const DEFAULT_CERTIFICATION_KEYS_SERVER_IDENTIFIER : & str = "ak" ;
103106pub static DEFAULT_PUSH_API_VERSIONS : & [ & str ] = & [ "3.0" ] ;
@@ -163,6 +166,7 @@ pub struct AgentConfig {
163166 pub payload_key_password : String ,
164167
165168 // Push attestation options
169+ pub attestation_interval_seconds : u64 ,
166170 pub certification_keys_server_identifier : String ,
167171 pub ima_ml_count_file : String ,
168172 pub registrar_api_versions : String ,
@@ -320,6 +324,8 @@ impl Default for AgentConfig {
320324 trusted_client_ca : "default" . to_string ( ) ,
321325 uuid : DEFAULT_UUID . to_string ( ) ,
322326 version : CONFIG_VERSION . to_string ( ) ,
327+ attestation_interval_seconds :
328+ DEFAULT_ATTESTATION_INTERVAL_SECONDS ,
323329 certification_keys_server_identifier :
324330 DEFAULT_CERTIFICATION_KEYS_SERVER_IDENTIFIER . to_string ( ) ,
325331 ima_ml_count_file : DEFAULT_IMA_ML_COUNT_FILE . to_string ( ) ,
@@ -1172,4 +1178,83 @@ mod tests {
11721178 config_get_file_path ( "test" , "" , workdir, "default" , false ) ;
11731179 assert_eq ! ( "/workdir/default" , translated) ;
11741180 }
1181+
1182+ #[ test]
1183+ fn test_attestation_interval_seconds_default ( ) {
1184+ let config = AgentConfig :: default ( ) ;
1185+ assert_eq ! (
1186+ config. attestation_interval_seconds,
1187+ DEFAULT_ATTESTATION_INTERVAL_SECONDS
1188+ ) ;
1189+ assert_eq ! ( config. attestation_interval_seconds, 60 ) ;
1190+ }
1191+
1192+ #[ test]
1193+ fn test_attestation_interval_seconds_custom ( ) {
1194+ let tempdir = tempfile:: tempdir ( )
1195+ . expect ( "failed to create temporary directory" ) ;
1196+
1197+ let config = AgentConfig {
1198+ keylime_dir : tempdir. path ( ) . display ( ) . to_string ( ) ,
1199+ attestation_interval_seconds : 5 ,
1200+ ..AgentConfig :: default ( )
1201+ } ;
1202+
1203+ assert_eq ! ( config. attestation_interval_seconds, 5 ) ;
1204+
1205+ // Verify that config_translate_keywords preserves the custom value
1206+ let result = config_translate_keywords ( & config) ;
1207+ assert ! ( result. is_ok( ) ) ;
1208+ let translated = result. unwrap ( ) ; //#[allow_ci]
1209+ assert_eq ! ( translated. attestation_interval_seconds, 5 ) ;
1210+ }
1211+
1212+ #[ test]
1213+ fn test_attestation_interval_seconds_constant_value ( ) {
1214+ // Ensure the constant has the expected value
1215+ assert_eq ! ( DEFAULT_ATTESTATION_INTERVAL_SECONDS , 60 ) ;
1216+ }
1217+
1218+ #[ test]
1219+ fn test_attestation_interval_from_toml ( ) {
1220+ use std:: fs;
1221+ use std:: io:: Write ;
1222+
1223+ let tempdir = tempfile:: tempdir ( )
1224+ . expect ( "failed to create temporary directory" ) ;
1225+
1226+ // Create a temporary config file with custom attestation_interval_seconds
1227+ let config_path = tempdir. path ( ) . join ( "agent.toml" ) ;
1228+ let mut file = fs:: File :: create ( & config_path)
1229+ . expect ( "failed to create config file" ) ;
1230+
1231+ writeln ! ( file, "[agent]" ) . expect ( "failed to write to config file" ) ;
1232+ writeln ! ( file, "attestation_interval_seconds = 10" )
1233+ . expect ( "failed to write to config file" ) ;
1234+
1235+ // Load the configuration
1236+ use config:: { Config , File , FileFormat } ;
1237+ let default_config = AgentConfig {
1238+ keylime_dir : tempdir. path ( ) . display ( ) . to_string ( ) ,
1239+ ..AgentConfig :: default ( )
1240+ } ;
1241+
1242+ let settings = Config :: builder ( )
1243+ . add_source ( default_config)
1244+ . add_source ( File :: from ( config_path) . format ( FileFormat :: Toml ) )
1245+ . build ( )
1246+ . expect ( "failed to build config" ) ;
1247+
1248+ #[ derive( serde:: Deserialize ) ]
1249+ struct Wrapper {
1250+ agent : AgentConfig ,
1251+ }
1252+
1253+ let wrapper: Wrapper = settings
1254+ . try_deserialize ( )
1255+ . expect ( "failed to deserialize config" ) ;
1256+
1257+ // Verify the value was loaded correctly from TOML (overriding default of 60)
1258+ assert_eq ! ( wrapper. agent. attestation_interval_seconds, 10 ) ;
1259+ }
11751260}
0 commit comments