@@ -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" ) . cloned( ) . unwrap_or_else( || json!( { } ) ) ,
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}
0 commit comments