@@ -1804,9 +1804,9 @@ fn load_payload_file(path: &str) -> Result<String, CommandError> {
18041804/// let policy = resolve_tpm_policy_enhanced(None, Some("/path/to/mb_with_tpm_policy.json"));
18051805/// // Returns extracted TPM policy from measured boot policy
18061806///
1807- /// // With default fallback
1807+ /// // With default fallback (empty policy with no PCRs)
18081808/// let policy = resolve_tpm_policy_enhanced(None, None);
1809- /// assert_eq!(policy, "{}" );
1809+ /// assert_eq!(policy, r#"{"mask":"0x0"}"# );
18101810/// ```
18111811fn resolve_tpm_policy_enhanced (
18121812 explicit_policy : Option < & str > ,
@@ -1838,9 +1838,9 @@ fn resolve_tpm_policy_enhanced(
18381838 }
18391839 }
18401840
1841- // Priority 3: Default empty policy
1842- debug ! ( "Using default empty TPM policy" ) ;
1843- Ok ( "{}" . to_string ( ) )
1841+ // Priority 3: Default empty policy with zeroed mask (no PCRs)
1842+ debug ! ( "Using default empty TPM policy with zeroed mask " ) ;
1843+ Ok ( r#"{"mask":"0x0"}"# . to_string ( ) )
18441844}
18451845
18461846/// Extract TPM policy from a measured boot policy file
@@ -2291,43 +2291,45 @@ fn build_push_model_request(
22912291) -> Result < Value , CommandError > {
22922292 debug ! ( "Building push model enrollment request for agent {agent_id}" ) ;
22932293
2294- let mut request = json ! ( {
2295- "agent_id" : agent_id,
2294+ // Load and encode runtime policy (required field, use empty string if not provided)
2295+ let runtime_policy_b64 = if let Some ( policy_path) = runtime_policy {
2296+ let policy_content = load_policy_file ( policy_path) ?;
2297+ STANDARD . encode ( policy_content. as_bytes ( ) )
2298+ } else {
2299+ String :: new ( ) // Empty string if no policy provided
2300+ } ;
2301+
2302+ // Load and encode measured boot policy (use empty string if not provided)
2303+ let mb_policy_b64 = if let Some ( policy_path) = mb_policy {
2304+ let policy_content = load_policy_file ( policy_path) ?;
2305+ STANDARD . encode ( policy_content. as_bytes ( ) )
2306+ } else {
2307+ String :: new ( ) // Empty string if no policy provided
2308+ } ;
2309+
2310+ let request = json ! ( {
2311+ "v" : agent_data. get( "v" ) ,
22962312 "cloudagent_ip" : cloudagent_ip,
22972313 "cloudagent_port" : cloudagent_port,
22982314 "tpm_policy" : tpm_policy,
2299- "accept_attestations" : true ,
23002315 "ak_tpm" : agent_data. get( "aik_tpm" ) ,
23012316 "mtls_cert" : agent_data. get( "mtls_cert" ) ,
2302- "accept_tpm_hash_algs" : [ "sha256" , "sha1" ] ,
2303- "accept_tpm_encryption_algs" : [ "rsa" , "ecc" ] ,
2304- "accept_tpm_signing_algs" : [ "rsa" , "ecdsa" ] ,
2305- "ima_sign_verification_keys" : agent_data. get( "ima_sign_verification_keys" ) . and_then( |v| v. as_str( ) ) . unwrap_or( "" ) ,
2317+ "runtime_policy_name" : null,
2318+ "runtime_policy" : runtime_policy_b64,
2319+ "runtime_policy_sig" : "" ,
2320+ "runtime_policy_key" : "" ,
2321+ "mb_refstate" : "null" ,
2322+ "mb_policy_name" : null,
2323+ "mb_policy" : mb_policy_b64,
2324+ "ima_sign_verification_keys" : agent_data. get( "ima_sign_verification_keys" ) . and_then( |v| v. as_str( ) ) . unwrap_or( "[]" ) ,
2325+ "metadata" : agent_data. get( "metadata" ) . and_then( |v| v. as_str( ) ) . unwrap_or( "{}" ) ,
23062326 "revocation_key" : agent_data. get( "revocation_key" ) . and_then( |v| v. as_str( ) ) . unwrap_or( "" ) ,
2307- "supported_version" : agent_data. get( "supported_version" ) . and_then( |v| v. as_str( ) ) . unwrap_or( "3.0" ) ,
2308- "mb_policy_name" : agent_data. get( "mb_policy_name" ) . and_then( |v| v. as_str( ) ) . unwrap_or( "" ) ,
2309- "mb_policy" : agent_data. get( "mb_policy" ) . and_then( |v| v. as_str( ) ) . unwrap_or( "" )
2327+ "accept_tpm_hash_algs" : [ "sha512" , "sha384" , "sha256" , "sha1" ] ,
2328+ "accept_tpm_encryption_algs" : [ "ecc" , "rsa" ] ,
2329+ "accept_tpm_signing_algs" : [ "ecschnorr" , "rsassa" ] ,
2330+ "supported_version" : agent_data. get( "supported_version" ) . and_then( |v| v. as_str( ) ) . unwrap_or( "2.0" )
23102331 } ) ;
23112332
2312- // Add policies if provided (base64-encoded as expected by verifier)
2313- if let Some ( policy_path) = runtime_policy {
2314- let policy_content = load_policy_file ( policy_path) ?;
2315- let policy_b64 = STANDARD . encode ( policy_content. as_bytes ( ) ) ;
2316- request[ "runtime_policy" ] = json ! ( policy_b64) ;
2317- }
2318-
2319- if let Some ( policy_path) = mb_policy {
2320- let policy_content = load_policy_file ( policy_path) ?;
2321- let policy_b64 = STANDARD . encode ( policy_content. as_bytes ( ) ) ;
2322- request[ "mb_policy" ] = json ! ( policy_b64) ;
2323- }
2324-
2325- // Add metadata from agent data or default
2326- request[ "metadata" ] = agent_data
2327- . get ( "metadata" )
2328- . cloned ( )
2329- . unwrap_or_else ( || json ! ( { } ) ) ;
2330-
23312333 debug ! ( "Push model request built successfully" ) ;
23322334 Ok ( request)
23332335}
@@ -2885,9 +2887,9 @@ mod tests {
28852887
28862888 #[ test]
28872889 fn test_resolve_tpm_policy_default_fallback ( ) {
2888- // Should fallback to default when no policies provided
2890+ // Should fallback to default when no policies provided (empty policy with no PCRs)
28892891 let result = resolve_tpm_policy_enhanced ( None , None ) . unwrap ( ) ;
2890- assert_eq ! ( result, "{}" ) ;
2892+ assert_eq ! ( result, r#"{"mask":"0x0"}"# ) ;
28912893 }
28922894
28932895 #[ test]
@@ -3024,14 +3026,14 @@ mod tests {
30243026
30253027 #[ test]
30263028 fn test_resolve_tpm_policy_enhanced_extraction_error_fallback ( ) {
3027- // When extraction fails, should fallback to default
3029+ // When extraction fails, should fallback to default (empty policy with no PCRs)
30283030 let result = resolve_tpm_policy_enhanced (
30293031 None ,
30303032 Some ( "/nonexistent/file.json" ) ,
30313033 )
30323034 . unwrap ( ) ;
30333035
3034- assert_eq ! ( result, "{}" ) ;
3036+ assert_eq ! ( result, r#"{"mask":"0x0"}"# ) ;
30353037 }
30363038
30373039 #[ test]
0 commit comments