|
28 | 28 | #include "policy_config.h" |
29 | 29 | #include "text_util.h" |
30 | 30 |
|
31 | | -static BSL_HostEIDPattern_t mock_bpa_util_get_eid_pattern_from_text(const char *text) |
32 | | -{ |
33 | | - BSL_HostEIDPattern_t pat; |
34 | | - BSL_HostEIDPattern_Init(&pat); |
35 | | - ASSERT_PROPERTY(0 == BSL_HostEIDPattern_DecodeFromText(&pat, text)); |
36 | | - return pat; |
37 | | -} |
38 | | - |
39 | 31 | int mock_bpa_rfc9173_bcb_cek(unsigned char *buf, int len) |
40 | 32 | { |
41 | 33 | if (len == 12) // IV |
@@ -66,12 +58,9 @@ int mock_bpa_register_policy_from_json(const char *pp_cfg_file_path, BSLP_Policy |
66 | 58 | BSL_PolicyLocation_e policy_loc_enum; |
67 | 59 | BSL_PolicyAction_e policy_action_enum; |
68 | 60 |
|
69 | | - const char *src_str; |
70 | | - const char *dest_str; |
71 | | - const char *sec_src_str; |
72 | | - BSL_HostEIDPattern_t src_eid; |
73 | | - BSL_HostEIDPattern_t dest_eid; |
74 | | - BSL_HostEIDPattern_t sec_src_eid; |
| 61 | + const char *src_str; |
| 62 | + const char *dest_str; |
| 63 | + const char *sec_src_str; |
75 | 64 |
|
76 | 65 | const char *rule_id_str; |
77 | 66 |
|
@@ -170,35 +159,32 @@ int mock_bpa_register_policy_from_json(const char *pp_cfg_file_path, BSLP_Policy |
170 | 159 | { |
171 | 160 | src_str = json_string_value(src); |
172 | 161 | BSL_LOG_DEBUG(" src : %s", src_str); |
173 | | - src_eid = mock_bpa_util_get_eid_pattern_from_text(src_str); |
174 | 162 | } |
175 | 163 | else |
176 | 164 | { |
177 | | - src_eid = mock_bpa_util_get_eid_pattern_from_text("*:**"); |
| 165 | + src_str = "*:**"; |
178 | 166 | } |
179 | 167 |
|
180 | 168 | json_t *dest = json_object_get(filter, "dest"); |
181 | 169 | if (dest) |
182 | 170 | { |
183 | 171 | dest_str = json_string_value(dest); |
184 | 172 | BSL_LOG_DEBUG(" dest : %s", dest_str); |
185 | | - dest_eid = mock_bpa_util_get_eid_pattern_from_text(dest_str); |
186 | 173 | } |
187 | 174 | else |
188 | 175 | { |
189 | | - dest_eid = mock_bpa_util_get_eid_pattern_from_text("*:**"); |
| 176 | + dest_str = "*:**"; |
190 | 177 | } |
191 | 178 |
|
192 | 179 | json_t *sec_src = json_object_get(filter, "sec_src"); |
193 | 180 | if (sec_src) |
194 | 181 | { |
195 | 182 | sec_src_str = json_string_value(sec_src); |
196 | 183 | BSL_LOG_DEBUG(" sec_src : %s", sec_src_str); |
197 | | - sec_src_eid = mock_bpa_util_get_eid_pattern_from_text(sec_src_str); |
198 | 184 | } |
199 | 185 | else |
200 | 186 | { |
201 | | - sec_src_eid = mock_bpa_util_get_eid_pattern_from_text("*:**"); |
| 187 | + sec_src_str = "*:**"; |
202 | 188 | } |
203 | 189 |
|
204 | 190 | // check tgt (target block type) |
@@ -522,32 +508,34 @@ int mock_bpa_register_policy_from_json(const char *pp_cfg_file_path, BSLP_Policy |
522 | 508 | } |
523 | 509 | } |
524 | 510 |
|
525 | | - BSLP_PolicyPredicate_t *predicate = &policy->predicates[policy->predicate_count++]; |
526 | | - BSLP_PolicyPredicate_Init(predicate, policy_loc_enum, src_eid, sec_src_eid, dest_eid); |
| 511 | + BSLP_PolicyPredicate_t predicate; |
| 512 | + BSLP_PolicyPredicate_InitFrom(&predicate, policy_loc_enum, src_str, sec_src_str, dest_str); |
527 | 513 |
|
528 | | - BSLP_PolicyRule_t *rule = &policy->rules[policy->rule_count++]; |
529 | | - BSLP_PolicyRule_Init(rule, rule_id_str, predicate, sec_ctx_id, sec_role, sec_block_type, target_block_type, |
530 | | - policy_action_enum); |
| 514 | + BSLP_PolicyRule_t rule; |
| 515 | + BSLP_PolicyRule_InitFrom(&rule, rule_id_str, sec_ctx_id, sec_role, sec_block_type, target_block_type, |
| 516 | + policy_action_enum); |
531 | 517 |
|
532 | 518 | // TODO validate params_got |
533 | 519 | (void)params_got; |
534 | 520 |
|
535 | 521 | if (sec_ctx_id == 2) // BCB |
536 | 522 | { |
537 | | - BSLP_PolicyRule_CopyParam(rule, params->param_aes_variant); |
| 523 | + BSLP_PolicyRule_CopyParam(&rule, params->param_aes_variant); |
538 | 524 | if (sec_role == BSL_SECROLE_SOURCE) |
539 | 525 | { |
540 | | - BSLP_PolicyRule_CopyParam(rule, params->param_aad_scope_flag); |
| 526 | + BSLP_PolicyRule_CopyParam(&rule, params->param_aad_scope_flag); |
541 | 527 | BSL_Crypto_SetRngGenerator(mock_bpa_rfc9173_bcb_cek); |
542 | 528 | } |
543 | 529 | } |
544 | 530 | else |
545 | 531 | { |
546 | | - BSLP_PolicyRule_CopyParam(rule, params->param_sha_variant); |
547 | | - BSLP_PolicyRule_CopyParam(rule, params->param_integ_scope_flag); |
| 532 | + BSLP_PolicyRule_CopyParam(&rule, params->param_sha_variant); |
| 533 | + BSLP_PolicyRule_CopyParam(&rule, params->param_integ_scope_flag); |
548 | 534 | } |
549 | | - BSLP_PolicyRule_CopyParam(rule, params->param_test_key); |
550 | | - BSLP_PolicyRule_CopyParam(rule, params->param_use_wrapped_key); |
| 535 | + BSLP_PolicyRule_CopyParam(&rule, params->param_test_key); |
| 536 | + BSLP_PolicyRule_CopyParam(&rule, params->param_use_wrapped_key); |
| 537 | + |
| 538 | + BSLP_PolicyProvider_AddRule(policy, &rule, &predicate); |
551 | 539 | } |
552 | 540 |
|
553 | 541 | json_decref(root); |
@@ -688,44 +676,46 @@ static void mock_bpa_register_policy(const bsl_mock_policy_configuration_t polic |
688 | 676 | break; |
689 | 677 | } |
690 | 678 |
|
691 | | - BSL_HostEIDPattern_t eid_src_pat; |
| 679 | + const char *eid_src_pat_str; |
692 | 680 | if (policy_ignore) |
693 | 681 | { |
694 | 682 | BSL_LOG_INFO("Creating src eid pattern to match none - bundle should be ignored!"); |
695 | | - eid_src_pat = mock_bpa_util_get_eid_pattern_from_text(""); |
| 683 | + eid_src_pat_str = ""; |
696 | 684 | } |
697 | 685 | else |
698 | 686 | { |
699 | | - eid_src_pat = mock_bpa_util_get_eid_pattern_from_text("*:**"); |
| 687 | + eid_src_pat_str = "*:**"; |
700 | 688 | } |
701 | 689 |
|
702 | 690 | // Create a rule to verify security block at APP/CLA Ingress |
703 | 691 | char policybits_str[100]; |
704 | 692 | snprintf(policybits_str, 100, "Policy: %x", policy_bits); |
705 | | - BSLP_PolicyPredicate_t *predicate_all_in = &policy->predicates[policy->predicate_count++]; |
706 | | - BSLP_PolicyPredicate_Init(predicate_all_in, policy_loc_enum, eid_src_pat, |
707 | | - mock_bpa_util_get_eid_pattern_from_text("*:**"), |
708 | | - mock_bpa_util_get_eid_pattern_from_text("*:**")); |
709 | | - BSLP_PolicyRule_t *rule_all_in = &policy->rules[policy->rule_count++]; |
710 | | - BSLP_PolicyRule_Init(rule_all_in, policybits_str, predicate_all_in, sec_context, sec_role_enum, sec_block_emum, |
711 | | - bundle_block_enum, policy_action_enum); |
| 693 | + |
| 694 | + BSLP_PolicyPredicate_t predicate_all_in; |
| 695 | + BSLP_PolicyPredicate_InitFrom(&predicate_all_in, policy_loc_enum, eid_src_pat_str, "*:**", "*:**"); |
| 696 | + |
| 697 | + BSLP_PolicyRule_t rule_all_in; |
| 698 | + BSLP_PolicyRule_InitFrom(&rule_all_in, policybits_str, sec_context, sec_role_enum, sec_block_emum, |
| 699 | + bundle_block_enum, policy_action_enum); |
712 | 700 |
|
713 | 701 | if (sec_block_emum == BSL_SECBLOCKTYPE_BCB) |
714 | 702 | { |
715 | | - BSLP_PolicyRule_CopyParam(rule_all_in, params->param_aes_variant); |
| 703 | + BSLP_PolicyRule_CopyParam(&rule_all_in, params->param_aes_variant); |
716 | 704 | if (sec_role_enum == BSL_SECROLE_SOURCE) |
717 | 705 | { |
718 | | - BSLP_PolicyRule_CopyParam(rule_all_in, params->param_aad_scope_flag); |
| 706 | + BSLP_PolicyRule_CopyParam(&rule_all_in, params->param_aad_scope_flag); |
719 | 707 | BSL_Crypto_SetRngGenerator(mock_bpa_rfc9173_bcb_cek); |
720 | 708 | } |
721 | 709 | } |
722 | 710 | else |
723 | 711 | { |
724 | | - BSLP_PolicyRule_CopyParam(rule_all_in, params->param_sha_variant); |
725 | | - BSLP_PolicyRule_CopyParam(rule_all_in, params->param_integ_scope_flag); |
| 712 | + BSLP_PolicyRule_CopyParam(&rule_all_in, params->param_sha_variant); |
| 713 | + BSLP_PolicyRule_CopyParam(&rule_all_in, params->param_integ_scope_flag); |
726 | 714 | } |
727 | | - BSLP_PolicyRule_CopyParam(rule_all_in, params->param_use_wrapped_key); |
728 | | - BSLP_PolicyRule_CopyParam(rule_all_in, params->param_test_key); |
| 715 | + BSLP_PolicyRule_CopyParam(&rule_all_in, params->param_use_wrapped_key); |
| 716 | + BSLP_PolicyRule_CopyParam(&rule_all_in, params->param_test_key); |
| 717 | + |
| 718 | + BSLP_PolicyProvider_AddRule(policy, &rule_all_in, &predicate_all_in); |
729 | 719 | } |
730 | 720 |
|
731 | 721 | int mock_bpa_handle_policy_config(const char *policies, BSLP_PolicyProvider_t *policy, mock_bpa_policy_registry_t *reg) |
|
0 commit comments