From 286a5f7d0262cf139c19910b0f9ad9870986ee6b Mon Sep 17 00:00:00 2001 From: William Fei Date: Wed, 8 Jul 2026 14:32:43 -0400 Subject: [PATCH 1/4] remove ResponseSet --- src/BPSecLib_Private.h | 44 ++---------- src/BPSecLib_Public.h | 8 +-- src/CMakeLists.txt | 2 - src/backend/PolicyProvider.c | 5 +- src/backend/PublicInterfaceImpl.c | 8 +-- src/backend/SecurityContext.c | 7 +- src/backend/SecurityResultSet.c | 70 ------------------- src/backend/SecurityResultSet.h | 60 ----------------- src/mock_bpa/agent.c | 6 +- src/policy_provider/SamplePolicyProvider.c | 3 +- src/policy_provider/SamplePolicyProvider.h | 3 +- test/DefaultScUtils.c | 5 -- test/DefaultScUtils.h | 3 +- test/test_BackendPolicyProvider.c | 8 +-- test/test_BackendSecurityContext.c | 78 ++++++---------------- test/test_DynamicMemCbs.c | 9 +-- test/test_PublicInterfaceImpl.c | 33 +++------ 17 files changed, 51 insertions(+), 301 deletions(-) delete mode 100644 src/backend/SecurityResultSet.c delete mode 100644 src/backend/SecurityResultSet.h diff --git a/src/BPSecLib_Private.h b/src/BPSecLib_Private.h index ad8be410..838e5a23 100644 --- a/src/BPSecLib_Private.h +++ b/src/BPSecLib_Private.h @@ -1152,40 +1152,6 @@ const BSL_SecurityAction_t *BSL_SecurityActionSet_GetActionAtIndex(const BSL_Sec */ size_t BSL_SecurityActionSet_CountErrors(const BSL_SecurityActionSet_t *self); -/// @brief Returns size of this struct type -size_t BSL_SecurityResponseSet_Sizeof(void); - -/** Initialize with the given count of operations and failures - * - */ -void BSL_SecurityResponseSet_Init(BSL_SecurityResponseSet_t *self); - -/** Zeroize itself and release any owned resources - * - * @param[in,out] self This response set. - */ -void BSL_SecurityResponseSet_Deinit(BSL_SecurityResponseSet_t *self); - -/** Return true if internal consistency checks pass. - * - * @param[in] self This response set. - */ -bool BSL_SecurityResponseSet_IsConsistent(const BSL_SecurityResponseSet_t *self); - -/** Return number of responses (operations acted upon) - * - * @param[in] self This response set. - */ -size_t BSL_SecurityResponseSet_CountResponses(const BSL_SecurityResponseSet_t *self); - -/** Append a result code to the security response set - * @param[in,out] self the response set to append result to - * @param[in] result the result code to append - * @param[in] policy_action the on-failure policy action associated with the response - */ -void BSL_SecurityResponseSet_AppendResult(BSL_SecurityResponseSet_t *self, int64_t result, - BSL_PolicyAction_e policy_action); - /** Queries the policy provider for any security operations to take on the bundle. * * @note The caller is obligated to allocate space for the policy_action_set output. @@ -1212,12 +1178,11 @@ int BSL_PolicyRegistry_InspectActions(const BSL_LibCtx_t *bsl, BSL_SecurityActio * @param[in] policy_actions A policy action set, which may contain error codes and other info. @preallocated * Caller-allocated, zeroed space for action set * @param[in,out] bundle Bundle seeking security operations - * @param[in] response_output results from security context * @param[in] location Where in the BPA lifecycle this query arises from * @return 0 if success */ int BSL_PolicyRegistry_FinalizeActions(const BSL_LibCtx_t *bsl, const BSL_SecurityActionSet_t *policy_actions, - BSL_BundleRef_t *bundle, const BSL_SecurityResponseSet_t *response_output); + BSL_BundleRef_t *bundle); /// @brief Callback interface to query policy provider to populate the action set typedef int (*BSL_PolicyInspect_f)(void *user_data, BSL_SecurityActionSet_t *output_action_set, @@ -1226,7 +1191,7 @@ typedef int (*BSL_PolicyInspect_f)(void *user_data, BSL_SecurityActionSet_t *out /// @brief Callback interface to finalize policy provider over the action set. Finalize should ignore actions from /// different policy providers typedef int (*BSL_PolicyFinalize_f)(void *user_data, const BSL_SecurityActionSet_t *output_action_set, - BSL_BundleRef_t *bundle, const BSL_SecurityResponseSet_t *response_output); + BSL_BundleRef_t *bundle); /// @brief Callback interface for policy provider to shut down and release any resources typedef void (*BSL_PolicyDeinit_f)(void *user_data); @@ -1243,13 +1208,12 @@ struct BSL_PolicyDesc_s /** Call the underlying security context to perform the given action set * * @param[in] lib This BSL context - * @param[out] output_response Pointer to allocated, zeroed memory into which the response is populated * @param[in,out] bundle Pointer to bundle, which may be modified. * @param[in] action_set Action containing all params and operations. * @return 0 on success, negative on failure. */ -int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet_t *output_response, - BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *action_set); +int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, + const BSL_SecurityActionSet_t *action_set); /** Call the underlying security context to validate the given action set * diff --git a/src/BPSecLib_Public.h b/src/BPSecLib_Public.h index 3e4080e7..dd169432 100644 --- a/src/BPSecLib_Public.h +++ b/src/BPSecLib_Public.h @@ -59,10 +59,6 @@ typedef struct BSL_LibCtx_s BSL_LibCtx_t; */ size_t BSL_LibCtx_Sizeof(void); -// Forward declaration of this struct. -// This contains information for BSL and the host BPA to process the Bundle. -typedef struct BSL_SecurityResponseSet_s BSL_SecurityResponseSet_t; - // Forward declaration of this struct. // This contains actions for BSL to process the Bundle. typedef struct BSL_SecurityActionSet_s BSL_SecurityActionSet_t; @@ -555,13 +551,11 @@ int BSL_API_QuerySecurity(BSL_LibCtx_t *bsl, BSL_SecurityActionSet_t *output_act /** @brief Performs the given security operations on a Bundle, modifying or even dropping it entirely. * * @param[in] bsl Pointer to BSL context structure. - * @param[out] response_output Pointer to host-allocated output structure. * @param[in,out] bundle Reference to host-owned Bundle, which may be modified or dropped by the BSL. * @param[in] policy_actions Pointer to policy actions, which was populated using the `QuerySecurity` function. */ BSL_REQUIRE_CHECK -int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *response_output, BSL_BundleRef_t *bundle, - const BSL_SecurityActionSet_t *policy_actions); +int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *policy_actions); #ifdef __cplusplus } // extern C diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9c756602..83f285a6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -145,7 +145,6 @@ set(BSL_DYNAMIC_H ${CMAKE_CURRENT_SOURCE_DIR}/backend/CBOR.h ${CMAKE_CURRENT_SOURCE_DIR}/backend/IdValPair.h ${CMAKE_CURRENT_SOURCE_DIR}/backend/PublicInterfaceImpl.h - ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityResultSet.h ${CMAKE_CURRENT_SOURCE_DIR}/backend/UtilDefs_SeqReadWrite.h ) @@ -162,7 +161,6 @@ set(BSL_DYNAMIC_C ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityAction.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityActionSet.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityContext.c - ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityResultSet.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/UtilDefs_SeqReadWrite.c ) diff --git a/src/backend/PolicyProvider.c b/src/backend/PolicyProvider.c index a104164d..1e535e7f 100644 --- a/src/backend/PolicyProvider.c +++ b/src/backend/PolicyProvider.c @@ -62,12 +62,11 @@ int BSL_PolicyRegistry_InspectActions(const BSL_LibCtx_t *bsl, BSL_SecurityActio } int BSL_PolicyRegistry_FinalizeActions(const BSL_LibCtx_t *bsl, const BSL_SecurityActionSet_t *policy_actions, - BSL_BundleRef_t *bundle, const BSL_SecurityResponseSet_t *response_output) + BSL_BundleRef_t *bundle) { CHK_ARG_NONNULL(bsl); CHK_ARG_NONNULL(bsl->policy_reg); CHK_ARG_NONNULL(policy_actions); - CHK_ARG_NONNULL(response_output); CHK_ARG_NONNULL(bundle); size_t act_ct = BSL_SecurityActionSet_CountActions(policy_actions); @@ -76,7 +75,7 @@ int BSL_PolicyRegistry_FinalizeActions(const BSL_LibCtx_t *bsl, const BSL_Securi BSL_SecurityAction_t *act = BSL_SecActionList_get(policy_actions->actions, i); const BSL_PolicyDesc_t *policy = BSL_PolicyDict_get(bsl->policy_reg, act->pp_id); - if (BSL_SUCCESS != policy->finalize_fn(policy->user_data, policy_actions, bundle, response_output)) + if (BSL_SUCCESS != policy->finalize_fn(policy->user_data, policy_actions, bundle)) { return BSL_ERR_POLICY_FINAL; } diff --git a/src/backend/PublicInterfaceImpl.c b/src/backend/PublicInterfaceImpl.c index d370ae36..688adddd 100644 --- a/src/backend/PublicInterfaceImpl.c +++ b/src/backend/PublicInterfaceImpl.c @@ -229,15 +229,13 @@ int BSL_API_QuerySecurity(BSL_LibCtx_t *bsl, BSL_SecurityActionSet_t *output_act return BSL_SUCCESS; } -int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *response_output, BSL_BundleRef_t *bundle, - const BSL_SecurityActionSet_t *policy_actions) +int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *policy_actions) { CHK_ARG_NONNULL(bsl); - CHK_ARG_NONNULL(response_output); CHK_ARG_NONNULL(bundle); CHK_ARG_NONNULL(policy_actions); - int exec_code = BSL_SecCtx_ExecutePolicyActionSet(bsl, response_output, bundle, policy_actions); + int exec_code = BSL_SecCtx_ExecutePolicyActionSet(bsl, bundle, policy_actions); if (exec_code < BSL_SUCCESS) { BSL_LOG_ERR("Failed to execute policy action set"); @@ -266,7 +264,7 @@ int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *response } } - int finalize_status = BSL_PolicyRegistry_FinalizeActions(bsl, policy_actions, bundle, response_output); + int finalize_status = BSL_PolicyRegistry_FinalizeActions(bsl, policy_actions, bundle); BSL_LOG_INFO("Completed finalize: status=%d", finalize_status); return BSL_SUCCESS; diff --git a/src/backend/SecurityContext.c b/src/backend/SecurityContext.c index 442c227e..496c8f59 100644 --- a/src/backend/SecurityContext.c +++ b/src/backend/SecurityContext.c @@ -437,12 +437,11 @@ int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS return res; } -int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet_t *output_response, - BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *action_set) +int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, + const BSL_SecurityActionSet_t *action_set) { // NOLINTBEGIN CHK_ARG_NONNULL(lib); - CHK_ARG_NONNULL(output_response); CHK_ARG_NONNULL(bundle); CHK_PRECONDITION(BSL_SecurityActionSet_IsConsistent(action_set)); // NOLINTEND @@ -507,11 +506,9 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet BSL_SecOper_SetReasonCode(sec_oper, BSL_REASONCODE_FAILED_SECOP); } BSL_SecOper_SetConclusion(sec_oper, BSL_SECOP_CONCLUSION_FAILURE); - BSL_SecurityResponseSet_AppendResult(output_response, errcode, sec_oper->policy_action); break; // stop processing secops if there is a failure } BSL_SecOper_SetConclusion(sec_oper, BSL_SECOP_CONCLUSION_SUCCESS); - BSL_SecurityResponseSet_AppendResult(output_response, errcode, sec_oper->policy_action); } } BSL_free(outcome); diff --git a/src/backend/SecurityResultSet.c b/src/backend/SecurityResultSet.c deleted file mode 100644 index 9e477a11..00000000 --- a/src/backend/SecurityResultSet.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2025-2026 The Johns Hopkins University Applied Physics - * Laboratory LLC. - * - * This file is part of the Bundle Protocol Security Library (BSL). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This work was performed for the Jet Propulsion Laboratory, California - * Institute of Technology, sponsored by the United States Government under - * the prime contract 80NM0018D0004 between the Caltech and NASA under - * subcontract 1700763. - */ -/** @file - * @brief Security Result Set implementation for result after application of security operations. - * @ingroup backend_dyn - */ -#include "SecurityResultSet.h" - -size_t BSL_SecurityResponseSet_Sizeof(void) -{ - return sizeof(BSL_SecurityResponseSet_t); -} - -bool BSL_SecurityResponseSet_IsConsistent(const BSL_SecurityResponseSet_t *self) -{ - CHK_AS_BOOL(self != NULL); - ASSERT_PROPERTY(self->total_operations == BSL_SecResultSet_ResultCodes_size(self->results)); - ASSERT_PROPERTY(self->total_operations == BSL_SecResultSet_ErrorActionCodes_size(self->err_action_codes)); - return true; -} - -void BSL_SecurityResponseSet_Init(BSL_SecurityResponseSet_t *self) -{ - ASSERT_ARG_NONNULL(self); - memset(self, 0, sizeof(*self)); - BSL_SecResultSet_ResultCodes_init(self->results); - BSL_SecResultSet_ErrorActionCodes_init(self->err_action_codes); -} - -void BSL_SecurityResponseSet_Deinit(BSL_SecurityResponseSet_t *self) -{ - ASSERT_PRECONDITION(BSL_SecurityResponseSet_IsConsistent(self)); - BSL_SecResultSet_ResultCodes_clear(self->results); - BSL_SecResultSet_ErrorActionCodes_clear(self->err_action_codes); - memset(self, 0, sizeof(*self)); -} - -size_t BSL_SecurityResponseSet_CountResponses(const BSL_SecurityResponseSet_t *self) -{ - ASSERT_PRECONDITION(BSL_SecurityResponseSet_IsConsistent(self)); - return self->total_operations; -} - -void BSL_SecurityResponseSet_AppendResult(BSL_SecurityResponseSet_t *self, int64_t result, - BSL_PolicyAction_e policy_action) -{ - ASSERT_ARG_NONNULL(self); - BSL_SecResultSet_ResultCodes_push_back(self->results, result); - BSL_SecResultSet_ErrorActionCodes_push_back(self->err_action_codes, policy_action); - self->total_operations++; -} diff --git a/src/backend/SecurityResultSet.h b/src/backend/SecurityResultSet.h deleted file mode 100644 index d60d3cac..00000000 --- a/src/backend/SecurityResultSet.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2025-2026 The Johns Hopkins University Applied Physics - * Laboratory LLC. - * - * This file is part of the Bundle Protocol Security Library (BSL). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This work was performed for the Jet Propulsion Laboratory, California - * Institute of Technology, sponsored by the United States Government under - * the prime contract 80NM0018D0004 between the Caltech and NASA under - * subcontract 1700763. - */ -/** @file - * @brief Security Result Set implementation for result after application of security operations. - * @ingroup backend_dyn - */ -#ifndef BSLB_SECURITYRESULTSET_H_ -#define BSLB_SECURITYRESULTSET_H_ - -#include - -#include - -/** @struct BSL_SecResultSet_ResultCodes - * Defines a basic list of @c int64_t for result values. - */ -/** @struct BSL_SecResultSet_ErrorActionCodes_t - * Defines a basic list of ::BSL_PolicyAction_e. - */ -/// @cond Doxygen_Suppress -// NOLINTBEGIN -// GCOV_EXCL_START -M_ARRAY_DEF(BSL_SecResultSet_ResultCodes, int64_t, M_POD_OPLIST) -M_ARRAY_DEF(BSL_SecResultSet_ErrorActionCodes, BSL_PolicyAction_e, M_POD_OPLIST) -// GCOV_EXCL_STOP -// NOLINTEND -/// @endcond - -/// @brief Contains the results and outcomes after performing the security operations. -/// @note This struct is still in-concept -struct BSL_SecurityResponseSet_s -{ - /// @brief This maps to the Security Action sec_op_list, - /// and contains the result code of that security operation. - BSL_SecResultSet_ResultCodes_t results; - BSL_SecResultSet_ErrorActionCodes_t err_action_codes; - size_t total_operations; - size_t failure_count; -}; - -#endif /* BSLB_SECURITYRESULTSET_H_ */ diff --git a/src/mock_bpa/agent.c b/src/mock_bpa/agent.c index db46eaee..580478e4 100644 --- a/src/mock_bpa/agent.c +++ b/src/mock_bpa/agent.c @@ -712,8 +712,6 @@ static int MockBPA_Agent_process(MockBPA_Agent_t *agent, MockBPA_Agent_BSL_Ctx_t BSL_SecurityActionSet_t *action_set = BSL_calloc(1, BSL_SecurityActionSet_Sizeof()); BSL_SecurityActionSet_Init(action_set); - BSL_SecurityResponseSet_t *response_set = BSL_calloc(1, BSL_SecurityResponseSet_Sizeof()); - BSL_SecurityResponseSet_Init(response_set); BSL_BundleRef_t bundle_ref = { .data = bundle }; BSL_LOG_INFO("calling BSL_API_QuerySecurity"); @@ -726,7 +724,7 @@ static int MockBPA_Agent_process(MockBPA_Agent_t *agent, MockBPA_Agent_BSL_Ctx_t if (!returncode) { BSL_LOG_INFO("calling BSL_API_ApplySecurity"); - returncode = BSL_API_ApplySecurity(ctx->bsl, response_set, &bundle_ref, action_set); + returncode = BSL_API_ApplySecurity(ctx->bsl, &bundle_ref, action_set); if (returncode < 0) { BSL_LOG_ERR("Failed to apply security: code=%d", returncode); @@ -742,8 +740,6 @@ static int MockBPA_Agent_process(MockBPA_Agent_t *agent, MockBPA_Agent_BSL_Ctx_t BSL_SecurityActionSet_Deinit(action_set); BSL_free(action_set); - BSL_SecurityResponseSet_Deinit(response_set); - BSL_free(response_set); BSL_LOG_INFO("result code %d", returncode); return returncode; } diff --git a/src/policy_provider/SamplePolicyProvider.c b/src/policy_provider/SamplePolicyProvider.c index 2114a0aa..ec92aa40 100644 --- a/src/policy_provider/SamplePolicyProvider.c +++ b/src/policy_provider/SamplePolicyProvider.c @@ -306,8 +306,7 @@ int BSLP_QueryPolicy(void *user_data, BSL_SecurityActionSet_t *output_action_set return (int)BSL_SecurityActionSet_CountErrors(output_action_set); } -int BSLP_FinalizePolicy(void *user_data _U_, const BSL_SecurityActionSet_t *output_action_set _U_, - BSL_BundleRef_t *bundle, const BSL_SecurityResponseSet_t *response_output _U_) +int BSLP_FinalizePolicy(void *user_data _U_, const BSL_SecurityActionSet_t *output_action_set, BSL_BundleRef_t *bundle) { int error_ret = BSL_SUCCESS; BSLP_PolicyProvider_t *self = user_data; diff --git a/src/policy_provider/SamplePolicyProvider.h b/src/policy_provider/SamplePolicyProvider.h index e2bc6e65..1fe3e160 100644 --- a/src/policy_provider/SamplePolicyProvider.h +++ b/src/policy_provider/SamplePolicyProvider.h @@ -263,8 +263,7 @@ int BSLP_QueryPolicy(void *user_data, BSL_SecurityActionSet_t *output_action_set BSL_PolicyLocation_e location); /// Provides ::BSL_PolicyFinalize_f -int BSLP_FinalizePolicy(void *user_data, const BSL_SecurityActionSet_t *output_action_set, BSL_BundleRef_t *bundle, - const BSL_SecurityResponseSet_t *response_output); +int BSLP_FinalizePolicy(void *user_data, const BSL_SecurityActionSet_t *output_action_set, BSL_BundleRef_t *bundle); #ifdef __cplusplus } // extern C diff --git a/test/DefaultScUtils.c b/test/DefaultScUtils.c index 4873cdec..e7f29229 100644 --- a/test/DefaultScUtils.c +++ b/test/DefaultScUtils.c @@ -246,11 +246,6 @@ BSL_SecurityActionSet_t *BSL_TestUtils_InitMallocBIBActionSet(BIBTestContext *bi return action_set; } -BSL_SecurityResponseSet_t *BSL_TestUtils_MallocEmptyPolicyResponse(void) -{ - return BSL_calloc(1, BSL_SecurityResponseSet_Sizeof()); -} - int rfc9173_byte_gen_fn_a1(unsigned char *buf, int len) { if (len == 12) // IV diff --git a/test/DefaultScUtils.h b/test/DefaultScUtils.h index aa3f4b8b..176404fa 100644 --- a/test/DefaultScUtils.h +++ b/test/DefaultScUtils.h @@ -188,8 +188,7 @@ typedef struct RFC9173_A1_Params BSL_TestUtils_GetRFC9173_A2Params(const char *key_id); -BSL_SecurityActionSet_t *BSL_TestUtils_InitMallocBIBActionSet(BIBTestContext *bib_context); -BSL_SecurityResponseSet_t *BSL_TestUtils_MallocEmptyPolicyResponse(void); +BSL_SecurityActionSet_t *BSL_TestUtils_InitMallocBIBActionSet(BIBTestContext *bib_context); void BSL_TestUtils_SetupDefaultSecurityContext(BSL_LibCtx_t *bsl_lib); diff --git a/test/test_BackendPolicyProvider.c b/test/test_BackendPolicyProvider.c index 10087eff..b928bd51 100644 --- a/test/test_BackendPolicyProvider.c +++ b/test/test_BackendPolicyProvider.c @@ -245,13 +245,9 @@ void test_MultiplePolicyProviders(void) } } - BSL_SecurityResponseSet_t *response_set = BSL_TestUtils_MallocEmptyPolicyResponse(); - - TEST_ASSERT_EQUAL(0, BSL_PolicyRegistry_FinalizeActions(&LocalTestCtx.bsl, &action_set, - &LocalTestCtx.mock_bpa_ctr.bundle_ref, response_set)); + TEST_ASSERT_EQUAL( + 0, BSL_PolicyRegistry_FinalizeActions(&LocalTestCtx.bsl, &action_set, &LocalTestCtx.mock_bpa_ctr.bundle_ref)); BSL_SecurityActionSet_Deinit(&action_set); BSLP_PolicyProvider_Destroy(policy_provider2); - BSL_SecurityResponseSet_Deinit(response_set); - BSL_free(response_set); } diff --git a/test/test_BackendSecurityContext.c b/test/test_BackendSecurityContext.c index 03e961dd..8ed6dac9 100644 --- a/test/test_BackendSecurityContext.c +++ b/test/test_BackendSecurityContext.c @@ -157,11 +157,10 @@ void test_SecurityContext_BIB_Source(void) BIBTestContext_Init(&bib_test_context); BSL_TestUtils_InitBIB_AppendixA1(&bib_test_context, BSL_SECROLE_SOURCE, RFC9173_EXAMPLE_A1_KEY); - BSL_SecurityActionSet_t *malloced_actionset = BSL_TestUtils_InitMallocBIBActionSet(&bib_test_context); - BSL_SecurityResponseSet_t *malloced_responseset = BSL_TestUtils_MallocEmptyPolicyResponse(); + BSL_SecurityActionSet_t *malloced_actionset = BSL_TestUtils_InitMallocBIBActionSet(&bib_test_context); - TEST_ASSERT_EQUAL(0, BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset, - &mock_bpa_ctr->bundle_ref, malloced_actionset)); + TEST_ASSERT_EQUAL( + 0, BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, malloced_actionset)); MockBPA_CanonicalBlock_t **target_ptr = MockBPA_BlockByNum_get(mock_bpa_ctr->bundle->blocks_num, 2); TEST_ASSERT_NOT_NULL(target_ptr); @@ -178,8 +177,6 @@ void test_SecurityContext_BIB_Source(void) is_equal = BSL_TestUtils_IsB16StrEqualTo(RFC9173_TestVectors_AppendixA1.hex_bundle_bib, mock_bpa_ctr->encoded); TEST_ASSERT_TRUE(is_equal); - BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_free(malloced_responseset); BSL_SecurityActionSet_Deinit(malloced_actionset); BSL_free(malloced_actionset); BIBTestContext_Deinit(&bib_test_context); @@ -208,19 +205,16 @@ void test_SecurityContext_BIB_Verifier(void) BIBTestContext_Init(&bib_test_context); BSL_TestUtils_InitBIB_AppendixA1(&bib_test_context, BSL_SECROLE_VERIFIER, RFC9173_EXAMPLE_A1_KEY); - BSL_SecurityActionSet_t *malloced_actionset = BSL_TestUtils_InitMallocBIBActionSet(&bib_test_context); - BSL_SecurityResponseSet_t *malloced_responseset = BSL_TestUtils_MallocEmptyPolicyResponse(); + BSL_SecurityActionSet_t *malloced_actionset = BSL_TestUtils_InitMallocBIBActionSet(&bib_test_context); - TEST_ASSERT_EQUAL(0, BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset, - &mock_bpa_ctr->bundle_ref, malloced_actionset)); + TEST_ASSERT_EQUAL( + 0, BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, malloced_actionset)); TEST_ASSERT_EQUAL(0, mock_bpa_ctr_encode(mock_bpa_ctr)); bool is_match = (BSL_TestUtils_IsB16StrEqualTo(RFC9173_TestVectors_AppendixA1.hex_bundle_bib, mock_bpa_ctr->encoded)); BSL_SecurityActionSet_Deinit(malloced_actionset); BSL_free(malloced_actionset); - BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_free(malloced_responseset); BIBTestContext_Deinit(&bib_test_context); TEST_ASSERT_TRUE(is_match); @@ -255,11 +249,10 @@ void test_SecurityContext_BIB_Verifier_Failure(void) BSL_IdValPair_Deinit(&bib_test_context.opt_test_key); BSL_IdValPair_SetTextstr(&bib_test_context.opt_test_key, old_id, RFC9173_EXAMPLE_A2_KEY); - BSL_SecurityActionSet_t *malloced_actionset = BSL_TestUtils_InitMallocBIBActionSet(&bib_test_context); - BSL_SecurityResponseSet_t *malloced_responseset = BSL_TestUtils_MallocEmptyPolicyResponse(); + BSL_SecurityActionSet_t *malloced_actionset = BSL_TestUtils_InitMallocBIBActionSet(&bib_test_context); - TEST_ASSERT_EQUAL(BSL_SUCCESS, BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset, - &mock_bpa_ctr->bundle_ref, malloced_actionset)); + TEST_ASSERT_EQUAL(BSL_SUCCESS, BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, + malloced_actionset)); TEST_ASSERT_EQUAL( BSL_SecurityAction_GetSecOperAtIndex(BSL_SecurityActionSet_GetActionAtIndex(malloced_actionset, 0), 0) @@ -268,8 +261,6 @@ void test_SecurityContext_BIB_Verifier_Failure(void) BSL_SecurityActionSet_Deinit(malloced_actionset); BSL_free(malloced_actionset); - BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_free(malloced_responseset); BIBTestContext_Deinit(&bib_test_context); } @@ -295,13 +286,12 @@ void test_SecurityContext_BIB_Acceptor(void) BIBTestContext_Init(&bib_test_context); BSL_TestUtils_InitBIB_AppendixA1(&bib_test_context, BSL_SECROLE_ACCEPTOR, RFC9173_EXAMPLE_A1_KEY); - BSL_SecurityActionSet_t *malloced_actionset = BSL_TestUtils_InitMallocBIBActionSet(&bib_test_context); - BSL_SecurityResponseSet_t *malloced_responseset = BSL_TestUtils_MallocEmptyPolicyResponse(); + BSL_SecurityActionSet_t *malloced_actionset = BSL_TestUtils_InitMallocBIBActionSet(&bib_test_context); - int encode_result = -1; - bool is_equal_test_vec = false; - int sec_context_result = BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset, - &mock_bpa_ctr->bundle_ref, malloced_actionset); + int encode_result = -1; + bool is_equal_test_vec = false; + int sec_context_result = + BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, malloced_actionset); // Note, we use the goto statements to better cleanup if failure happens if (sec_context_result != 0) @@ -325,8 +315,6 @@ void test_SecurityContext_BIB_Acceptor(void) cleanup: BSL_SecurityActionSet_Deinit(malloced_actionset); BSL_free(malloced_actionset); - BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_free(malloced_responseset); BIBTestContext_Deinit(&bib_test_context); TEST_ASSERT_EQUAL(0, sec_context_result); @@ -393,18 +381,14 @@ void test_RFC9173_AppendixA_Example3_Acceptor(void) BSL_SecurityActionSet_AppendAction(malloced_actionset, malloced_action); - BSL_SecurityResponseSet_t *malloced_responseset = BSL_TestUtils_MallocEmptyPolicyResponse(); - - const int exec_result = BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset, - &mock_bpa_ctr->bundle_ref, malloced_actionset); + const int exec_result = + BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, malloced_actionset); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_result); BSL_SecurityAction_Deinit(malloced_action); BSL_free(malloced_action); BSL_SecurityActionSet_Deinit(malloced_actionset); BSL_free(malloced_actionset); - BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_free(malloced_responseset); BSL_PrimaryBlock_deinit(&primary_block); BIBTestContext_Deinit(&bib_context); BCBTestContext_Deinit(&bcb_context); @@ -477,11 +461,8 @@ void test_RFC9173_AppendixA_Example3_Source(void) BSL_SecurityActionSet_AppendAction(malloced_actionset, malloced_action); - BSL_SecurityResponseSet_t *malloced_responseset = BSL_TestUtils_MallocEmptyPolicyResponse(); - BSL_SecurityResponseSet_Init(malloced_responseset); - - const int exec_result = BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset, - &mock_bpa_ctr->bundle_ref, malloced_actionset); + const int exec_result = + BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, malloced_actionset); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_result); BSL_PrimaryBlock_deinit(&primary_block); @@ -490,17 +471,10 @@ void test_RFC9173_AppendixA_Example3_Source(void) TEST_ASSERT_TRUE(primary_block.block_count >= 4); TEST_ASSERT_TRUE(primary_block.block_count <= 5); - const size_t response_count = BSL_SecurityResponseSet_CountResponses(malloced_responseset); - TEST_ASSERT_EQUAL(3, response_count); - - BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_SecurityAction_Deinit(malloced_action); BSL_free(malloced_action); BSL_SecurityActionSet_Deinit(malloced_actionset); BSL_free(malloced_actionset); - BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_free(malloced_responseset); BSL_PrimaryBlock_deinit(&primary_block); BIBTestContext_Deinit(&bib_context); BCBTestContext_Deinit(&bcb_context); @@ -586,10 +560,8 @@ void test_RFC9173_AppendixA_Example4_Acceptor(void) BSL_SecurityActionSet_AppendAction(malloced_actionset, malloced_action); - BSL_SecurityResponseSet_t *malloced_responseset = BSL_TestUtils_MallocEmptyPolicyResponse(); - - const int exec_result = BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset, - &mock_bpa_ctr->bundle_ref, malloced_actionset); + const int exec_result = + BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, malloced_actionset); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_result); // After all the security results have been stripped, this is the bundle's result. @@ -604,8 +576,6 @@ void test_RFC9173_AppendixA_Example4_Acceptor(void) BSL_free(malloced_action); BSL_SecurityActionSet_Deinit(malloced_actionset); BSL_free(malloced_actionset); - BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_free(malloced_responseset); BSL_PrimaryBlock_deinit(&primary_block); BIBTestContext_Deinit(&bib_context); BCBTestContext_Deinit(&bcb_context); @@ -678,10 +648,8 @@ void test_RFC9173_AppendixA_Example4_Source(void) BSL_SecurityActionSet_AppendAction(malloced_actionset, malloced_action); - BSL_SecurityResponseSet_t *malloced_responseset = BSL_TestUtils_MallocEmptyPolicyResponse(); - - const int exec_result = BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, malloced_responseset, - &mock_bpa_ctr->bundle_ref, malloced_actionset); + const int exec_result = + BSL_SecCtx_ExecutePolicyActionSet(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, malloced_actionset); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_result); BSL_PrimaryBlock_deinit(&primary_block); @@ -693,8 +661,6 @@ void test_RFC9173_AppendixA_Example4_Source(void) BSL_free(malloced_action); BSL_SecurityActionSet_Deinit(malloced_actionset); BSL_free(malloced_actionset); - BSL_SecurityResponseSet_Deinit(malloced_responseset); - BSL_free(malloced_responseset); BSL_PrimaryBlock_deinit(&primary_block); BIBTestContext_Deinit(&bib_context); BCBTestContext_Deinit(&bcb_context); diff --git a/test/test_DynamicMemCbs.c b/test/test_DynamicMemCbs.c index b2fcf592..40a6a67f 100644 --- a/test/test_DynamicMemCbs.c +++ b/test/test_DynamicMemCbs.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -163,9 +162,7 @@ void test_dyn_mem_cbs_BSL_32(void) { _setUp(); - BSL_PrimaryBlock_t primary_block; - BSL_SecurityResponseSet_t response_set; - BSL_SecurityResponseSet_Init(&response_set); + BSL_PrimaryBlock_t primary_block; BSL_CanonicalBlock_t res_blk; int query_result = -1; int apply_result = -1; @@ -187,8 +184,7 @@ void test_dyn_mem_cbs_BSL_32(void) TEST_ASSERT_EQUAL(0, query_result); TEST_ASSERT_EQUAL(2, BSL_SecurityActionSet_CountOperations(&action_set)); - apply_result = - BSL_API_ApplySecurity(&LocalTestCtx.bsl, &response_set, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); + apply_result = BSL_API_ApplySecurity(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); TEST_ASSERT_EQUAL(0, apply_result); for (size_t i = 0; i < BSL_SecurityActionSet_CountActions(&action_set); i++) @@ -213,7 +209,6 @@ void test_dyn_mem_cbs_BSL_32(void) TEST_ASSERT_EQUAL(12, res_blk.type_code); BSL_PrimaryBlock_deinit(&primary_block); - BSL_SecurityResponseSet_Deinit(&response_set); _tearDown(); diff --git a/test/test_PublicInterfaceImpl.c b/test/test_PublicInterfaceImpl.c index e2f37d98..9ede1d49 100644 --- a/test/test_PublicInterfaceImpl.c +++ b/test/test_PublicInterfaceImpl.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -573,10 +572,8 @@ void test_comprehensive(BSL_PolicyLocation_e policy_loc, const char *src_eid, co const char *secsrc_eid, BSL_SecRole_e sec_role, int sec_block_type, uint8_t target_block, BSL_PolicyAction_e policy_act, bool good_key, int sec_blks_ct, int expected_act_ct) { - BSL_PrimaryBlock_t primary_block; - BSL_SecurityResponseSet_t response_set; - BSL_SecurityResponseSet_Init(&response_set); - BSL_TlmCounters_t tlm = BSL_TLM_COUNTERS_ZERO; + BSL_PrimaryBlock_t primary_block; + BSL_TlmCounters_t tlm = BSL_TLM_COUNTERS_ZERO; int query_result = -1; int apply_result = -1; @@ -637,8 +634,7 @@ void test_comprehensive(BSL_PolicyLocation_e policy_loc, const char *src_eid, co TEST_ASSERT_EQUAL(0, query_result); TEST_ASSERT_EQUAL(expected_act_ct, BSL_SecurityActionSet_CountOperations(&action_set)); - apply_result = BSL_API_ApplySecurity(&LocalTestCtx.bsl, &response_set, - &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); + apply_result = BSL_API_ApplySecurity(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); TEST_ASSERT_EQUAL(0, apply_result); BSL_PrimaryBlock_deinit(&primary_block); @@ -714,8 +710,7 @@ void test_comprehensive(BSL_PolicyLocation_e policy_loc, const char *src_eid, co TEST_ASSERT_EQUAL(0, query_result); TEST_ASSERT_EQUAL(expected_act_ct, BSL_SecurityActionSet_CountOperations(&action_set)); - apply_result = BSL_API_ApplySecurity(&LocalTestCtx.bsl, &response_set, - &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); + apply_result = BSL_API_ApplySecurity(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); TEST_ASSERT_EQUAL(0, apply_result); BSL_PrimaryBlock_deinit(&primary_block); @@ -810,8 +805,7 @@ void test_comprehensive(BSL_PolicyLocation_e policy_loc, const char *src_eid, co TEST_ASSERT_EQUAL(0, query_result); TEST_ASSERT_EQUAL(expected_act_ct, BSL_SecurityActionSet_CountOperations(&action_set)); - apply_result = BSL_API_ApplySecurity(&LocalTestCtx.bsl, &response_set, - &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); + apply_result = BSL_API_ApplySecurity(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); TEST_ASSERT_EQUAL(0, apply_result); BSL_PrimaryBlock_deinit(&primary_block); @@ -848,16 +842,13 @@ void test_comprehensive(BSL_PolicyLocation_e policy_loc, const char *src_eid, co break; } } - BSL_SecurityResponseSet_Deinit(&response_set); } // Recommended BSL_6 be removed // But, here's the fixture anyways, can be used for a future PP enhancement ticket (like #68) void n_test_BSL_6(void) { - BSL_PrimaryBlock_t primary_block; - BSL_SecurityResponseSet_t response_set; - BSL_SecurityResponseSet_Init(&response_set); + BSL_PrimaryBlock_t primary_block; BSL_CanonicalBlock_t res_blk; int query_result = -1; int apply_result = -1; @@ -881,8 +872,7 @@ void n_test_BSL_6(void) TEST_ASSERT_EQUAL(1, action_set.action_count); TEST_ASSERT_EQUAL(1, BSL_SecurityAction_CountSecOpers(BSL_SecurityActionSet_GetActionAtIndex(&action_set, 0))); - apply_result = - BSL_API_ApplySecurity(&LocalTestCtx.bsl, &response_set, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); + apply_result = BSL_API_ApplySecurity(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); TEST_ASSERT_EQUAL(0, apply_result); TEST_ASSERT_EQUAL( BSL_SECOP_CONCLUSION_FAILURE, @@ -891,16 +881,13 @@ void n_test_BSL_6(void) BSL_BundleCtx_GetBundleMetadata(&LocalTestCtx.mock_bpa_ctr.bundle_ref, &primary_block); TEST_ASSERT_EQUAL(2, primary_block.block_count); - BSL_SecurityResponseSet_Deinit(&response_set); BSL_PrimaryBlock_deinit(&primary_block); } // Recreate MockBPA test BSL_43 void test_BSL_32(void) { - BSL_PrimaryBlock_t primary_block; - BSL_SecurityResponseSet_t response_set; - BSL_SecurityResponseSet_Init(&response_set); + BSL_PrimaryBlock_t primary_block; BSL_CanonicalBlock_t res_blk; int query_result = -1; int apply_result = -1; @@ -922,8 +909,7 @@ void test_BSL_32(void) TEST_ASSERT_EQUAL(0, query_result); TEST_ASSERT_EQUAL(2, BSL_SecurityActionSet_CountOperations(&action_set)); - apply_result = - BSL_API_ApplySecurity(&LocalTestCtx.bsl, &response_set, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); + apply_result = BSL_API_ApplySecurity(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &action_set); TEST_ASSERT_EQUAL(0, apply_result); for (size_t i = 0; i < BSL_SecurityActionSet_CountActions(&action_set); i++) @@ -949,6 +935,5 @@ void test_BSL_32(void) TEST_ASSERT_EQUAL(0, BSL_BundleCtx_GetBlockMetadata(&LocalTestCtx.mock_bpa_ctr.bundle_ref, 4, &res_blk)); TEST_ASSERT_EQUAL(12, res_blk.type_code); - BSL_SecurityResponseSet_Deinit(&response_set); BSL_PrimaryBlock_deinit(&primary_block); } From 4bcf6bed10ea3aacc34e537cf2cb6e7193d70654 Mon Sep 17 00:00:00 2001 From: William Fei Date: Wed, 15 Jul 2026 10:15:05 -0400 Subject: [PATCH 2/4] remove SecOutcome --- src/BPSecLib_Private.h | 61 ++++++++++---- src/CMakeLists.txt | 1 - src/backend/AbsSecBlock.h | 4 +- src/backend/SecOperation.c | 53 +++++++++--- src/backend/SecOperation.h | 16 ++-- src/backend/SecOutcome.c | 124 ----------------------------- src/backend/SecOutcome.h | 56 ------------- src/backend/SecurityContext.c | 71 +++++++---------- src/cose_sc/CoseContext.c | 25 +++--- src/cose_sc/CoseContext.h | 3 +- src/default_sc/BCB_AES_GCM.c | 14 ++-- src/default_sc/BIB_HMAC_SHA2.c | 13 ++- src/default_sc/DefaultSecContext.h | 6 +- test/test_BackendSecurityContext.c | 15 ++-- test/test_CoseContext.c | 42 +++------- test/test_DefaultSecurityContext.c | 114 ++++++++++---------------- 16 files changed, 205 insertions(+), 413 deletions(-) delete mode 100644 src/backend/SecOutcome.c delete mode 100644 src/backend/SecOutcome.h diff --git a/src/BPSecLib_Private.h b/src/BPSecLib_Private.h index 838e5a23..0ef6d4af 100644 --- a/src/BPSecLib_Private.h +++ b/src/BPSecLib_Private.h @@ -325,10 +325,7 @@ int BSL_SeqWriter_Put(BSL_SeqWriter_t *obj, const uint8_t *buf, size_t bufsize); /** Static initializer for an invalid ::BSL_HostEID_t. * Even after this, BSL_HostEID_Init() must be used to get into a valid state. */ -#define BSL_HOSTEID_INIT_INVALID \ - { \ - .handle = NULL \ - } +#define BSL_HOSTEID_INIT_INVALID { .handle = NULL } /** Initialize an abstract EID. * @@ -382,10 +379,7 @@ int BSL_HostEID_EncodeToCBOR(const BSL_HostEID_t *eid, BSL_Data_t *encoded_bytes /** Static initializer for an invalid ::BSL_HostEIDPattern_t. * Even after this, BSL_HostEIDPattern_Init() must be used to get into a valid state. */ -#define BSL_HOSTEID_INIT_INVALID \ - { \ - .handle = NULL \ - } +#define BSL_HOSTEID_INIT_INVALID { .handle = NULL } /** Initialize an abstract EID Pattern. * @@ -826,6 +820,42 @@ void BSL_SecOper_AppendOption(BSL_SecOper_t *self, const BSL_IdValPair_t *option */ void BSL_SecOper_AppendParam(BSL_SecOper_t *self, const BSL_IdValPair_t *param); +/** Add an empty security parameter. + * + * @param[in,out] self This security operation. + * @param[in] param_id Security parameter ID. + * @return The parameter owned by this operation. + */ +BSL_IdValPair_t *BSL_SecOper_AddParam(BSL_SecOper_t *self, int64_t param_id); + +/** Add an empty security result. + * + * @param[in,out] self This security operation. + * @param[in] result_id Security result ID. + * @return The result owned by this operation. + */ +BSL_IdValPair_t *BSL_SecOper_AddResult(BSL_SecOper_t *self, int64_t result_id); + +/** Get the count of parameters contained within this security operation. + * + * @param[in] self This security operation + * @return Count of security parameters. + */ +size_t BSL_SecOper_CountParams(const BSL_SecOper_t *self); + +/** Get the count of results contained within this security operation. + * + * @param[in] self This security operation + * @return Count of security results. + */ +size_t BSL_SecOper_CountResults(const BSL_SecOper_t *self); + +/** Clear all parameters and results contained within this security operation. + * + * @param[in,out] self This security operation + */ +void BSL_SecOper_ClearParamsAndResults(BSL_SecOper_t *self); + /** Return true if this security operation's role is SOURCE * @param[in] self This Security Operation * @return boolean @@ -1240,13 +1270,10 @@ typedef bool (*BSL_SecCtx_Validate_f)(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle * * @param[in] lib The library context. * @param[in,out] bundle The bundle to modify. - * @param[in] sec_oper The security operation to perform. - * @param[in] asb For verifier or acceptor, this is the existing ASB structure. - * @param[in,out] sec_outcome The pre-allocated outcome to populate + * @param[in, out] sec_oper Security operation inputs and generated outputs. * @return 0 if security operation performed successfully. */ -typedef int (*BSL_SecCtx_Execute_f)(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, - BSL_SecOutcome_t *sec_outcome); +typedef int (*BSL_SecCtx_Execute_f)(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper); /** @brief Security Context descriptor (interface) */ @@ -1262,16 +1289,16 @@ struct BSL_SecCtxDesc_s * @warning This is exposed for testing only. */ int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, - BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome); + BSL_SecOper_t *sec_oper); /// @overload execute as verifier int BSL_ExecBIBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, - BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome); + BSL_SecOper_t *sec_oper); /// @overload execute as source int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, - BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome); + BSL_SecOper_t *sec_oper); /// @overload execute as verifier int BSL_ExecBCBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, - BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome); + BSL_SecOper_t *sec_oper); #ifdef __cplusplus } // extern C diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83f285a6..62093875 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -157,7 +157,6 @@ set(BSL_DYNAMIC_C ${CMAKE_CURRENT_SOURCE_DIR}/backend/PolicyProvider.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/TelemetryCounters.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecOperation.c - ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecOutcome.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityAction.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityActionSet.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityContext.c diff --git a/src/backend/AbsSecBlock.h b/src/backend/AbsSecBlock.h index e3d3da2c..6de19790 100644 --- a/src/backend/AbsSecBlock.h +++ b/src/backend/AbsSecBlock.h @@ -115,10 +115,10 @@ struct BSL_AbsSecBlock_s */ BSL_AbsSecBlock_Target_t *BSL_AbsSecBlock_AddTarget(BSL_AbsSecBlock_t *self, uint64_t target_block_num); -/** Remove security parameters and results found in `outcome` from this ASB +/** Remove the target and its security results from this ASB * * @param[in,out] self This ASB - * @param[in] outcome Security Operation outcome containing params and results + * @param[in] target_block_num Block number of the target to remove * @return Negative on error, otherwise count of things removed. */ int BSL_AbsSecBlock_StripResults(BSL_AbsSecBlock_t *self, uint64_t target_block_num); diff --git a/src/backend/SecOperation.c b/src/backend/SecOperation.c index 3f1987ba..1d0abbff 100644 --- a/src/backend/SecOperation.c +++ b/src/backend/SecOperation.c @@ -38,8 +38,8 @@ void BSL_SecOper_Init(BSL_SecOper_t *self) memset(self, 0, sizeof(*self)); BSLB_IdValPairPtrMap_init(self->_options); - BSLB_IdValPairPtrMap_init(self->_params_in); - BSLB_IdValPairPtrMap_init(self->_results_in); + BSLB_IdValPairPtrMap_init(self->_params); + BSLB_IdValPairPtrMap_init(self->_results); } void BSL_SecOper_InitSet(BSL_SecOper_t *self, const BSL_SecOper_t *src) @@ -57,8 +57,8 @@ void BSL_SecOper_InitSet(BSL_SecOper_t *self, const BSL_SecOper_t *src) self->_role = src->_role; self->_service_type = src->_service_type; BSLB_IdValPairPtrMap_init_set(self->_options, src->_options); - BSLB_IdValPairPtrMap_init_set(self->_params_in, src->_params_in); - BSLB_IdValPairPtrMap_init_set(self->_results_in, src->_results_in); + BSLB_IdValPairPtrMap_init_set(self->_params, src->_params); + BSLB_IdValPairPtrMap_init_set(self->_results, src->_results); ASSERT_POSTCONDITION(BSL_SecOper_IsConsistent(self)); } @@ -66,8 +66,8 @@ void BSL_SecOper_InitSet(BSL_SecOper_t *self, const BSL_SecOper_t *src) void BSL_SecOper_Deinit(BSL_SecOper_t *self) { ASSERT_ARG_NONNULL(self); - BSLB_IdValPairPtrMap_clear(self->_results_in); - BSLB_IdValPairPtrMap_clear(self->_params_in); + BSLB_IdValPairPtrMap_clear(self->_results); + BSLB_IdValPairPtrMap_clear(self->_params); BSLB_IdValPairPtrMap_clear(self->_options); } @@ -84,8 +84,8 @@ void BSL_SecOper_Set(BSL_SecOper_t *self, const BSL_SecOper_t *src) self->_role = src->_role; self->_service_type = src->_service_type; BSLB_IdValPairPtrMap_set(self->_options, src->_options); - BSLB_IdValPairPtrMap_set(self->_params_in, src->_params_in); - BSLB_IdValPairPtrMap_set(self->_results_in, src->_results_in); + BSLB_IdValPairPtrMap_set(self->_params, src->_params); + BSLB_IdValPairPtrMap_set(self->_results, src->_results); ASSERT_POSTCONDITION(BSL_SecOper_IsConsistent(self)); } @@ -145,12 +145,43 @@ void BSL_SecOper_AppendParam(BSL_SecOper_t *self, const BSL_IdValPair_t *param) BSLB_IdValPairPtr_t *item_ptr = BSLB_IdValPairPtr_new_from(*param); - BSLB_IdValPairPtrMap_set_at(self->_params_in, param->id, item_ptr); + BSLB_IdValPairPtrMap_set_at(self->_params, param->id, item_ptr); BSLB_IdValPairPtr_release(item_ptr); ASSERT_POSTCONDITION(BSL_SecOper_IsConsistent(self)); } +BSL_IdValPair_t *BSL_SecOper_AddParam(BSL_SecOper_t *self, int64_t param_id) +{ + ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self)); + return BSLB_IdValPairPtrMap_add(self->_params, param_id); +} + +BSL_IdValPair_t *BSL_SecOper_AddResult(BSL_SecOper_t *self, int64_t result_id) +{ + ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self)); + return BSLB_IdValPairPtrMap_add(self->_results, result_id); +} + +size_t BSL_SecOper_CountParams(const BSL_SecOper_t *self) +{ + ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self)); + return BSLB_IdValPairPtrMap_size(self->_params); +} + +size_t BSL_SecOper_CountResults(const BSL_SecOper_t *self) +{ + ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self)); + return BSLB_IdValPairPtrMap_size(self->_results); +} + +void BSL_SecOper_ClearParamsAndResults(BSL_SecOper_t *self) +{ + ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self)); + BSLB_IdValPairPtrMap_reset(self->_params); + BSLB_IdValPairPtrMap_reset(self->_results); +} + uint64_t BSL_SecOper_GetSecurityBlockNum(const BSL_SecOper_t *self) { ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self)); @@ -177,7 +208,7 @@ const BSL_IdValPair_t *BSL_SecOper_FindParam(const BSL_SecOper_t *self, int64_t { ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self)); - BSLB_IdValPairPtr_t *const *found = BSLB_IdValPairPtrMap_cget(self->_params_in, param_id); + BSLB_IdValPairPtr_t *const *found = BSLB_IdValPairPtrMap_cget(self->_params, param_id); return found ? BSLB_IdValPairPtr_cref(*found) : NULL; } @@ -185,7 +216,7 @@ const BSL_IdValPair_t *BSL_SecOper_FindResult(const BSL_SecOper_t *self, int64_t { ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self)); - BSLB_IdValPairPtr_t *const *found = BSLB_IdValPairPtrMap_cget(self->_results_in, result_id); + BSLB_IdValPairPtr_t *const *found = BSLB_IdValPairPtrMap_cget(self->_results, result_id); return found ? BSLB_IdValPairPtr_cref(*found) : NULL; } diff --git a/src/backend/SecOperation.h b/src/backend/SecOperation.h index 4129cff0..6ff56394 100644 --- a/src/backend/SecOperation.h +++ b/src/backend/SecOperation.h @@ -60,21 +60,17 @@ struct BSL_SecOper_s /// @brief Options set by the policy provider BSLB_IdValPairPtrMap_t _options; - /** @name Existing security verifier/acceptor. - * These fields apply when this operation is on an existing operation. - */ - /// @{ - /** @brief Index of the existing target block in the ASB if the #_role is not source. * This will be distinct because the same source+function can only * target each block no more than once. */ size_t _target_index; - /// @brief Parameters from the ASB if the #_role is not source - BSLB_IdValPairPtrMap_t _params_in; - /// @brief Results from the ASB if the #_role is not source - BSLB_IdValPairPtrMap_t _results_in; - /// @} + + /// @brief Security parameters used or produced by this operation. + BSLB_IdValPairPtrMap_t _params; + + /// @brief Security results used or produced by this operation. + BSLB_IdValPairPtrMap_t _results; }; #endif /* BSLB_SECOPERATIONS_H_ */ diff --git a/src/backend/SecOutcome.c b/src/backend/SecOutcome.c deleted file mode 100644 index 8defadc5..00000000 --- a/src/backend/SecOutcome.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2025-2026 The Johns Hopkins University Applied Physics - * Laboratory LLC. - * - * This file is part of the Bundle Protocol Security Library (BSL). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This work was performed for the Jet Propulsion Laboratory, California - * Institute of Technology, sponsored by the United States Government under - * the prime contract 80NM0018D0004 between the Caltech and NASA under - * subcontract 1700763. - */ -/** - * @file SecOutcome.h - * @ingroup backend_dyn - * @brief Defines the result of a security operation - */ -#include - -#include "AbsSecBlock.h" -#include "SecOutcome.h" - -size_t BSL_SecOutcome_Sizeof(void) -{ - return sizeof(BSL_SecOutcome_t); -} - -void BSL_SecOutcome_Init(BSL_SecOutcome_t *self, const BSL_SecOper_t *sec_oper) -{ - ASSERT_ARG_NONNULL(self); - ASSERT_ARG_NONNULL(sec_oper); - - ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(sec_oper)); - - memset(self, 0, sizeof(*self)); - self->is_success = 0; - BSLB_IdValPairPtrList_init(self->param_list); - BSLB_IdValPairPtrList_init(self->result_list); - self->sec_oper = sec_oper; - - ASSERT_POSTCONDITION(BSL_SecOutcome_IsConsistent(self)); -} - -void BSL_SecOutcome_Deinit(BSL_SecOutcome_t *self) -{ - ASSERT_PRECONDITION(BSL_SecOutcome_IsConsistent(self)); - - BSLB_IdValPairPtrList_clear(self->param_list); - BSLB_IdValPairPtrList_clear(self->result_list); - memset(self, 0, sizeof(*self)); -} - -bool BSL_SecOutcome_IsConsistent(const BSL_SecOutcome_t *self) -{ - CHK_AS_BOOL(self != NULL); - CHK_AS_BOOL(self->sec_oper != NULL); - - // Invariant: If it is not successful at end, it should not return any results - const size_t result_len = BSLB_IdValPairPtrList_size(self->result_list); - if (self->is_success) - { - CHK_AS_BOOL(result_len > 0); - } - - return true; -} - -BSL_IdValPair_t *BSL_SecOutcome_AppendResult(BSL_SecOutcome_t *self) -{ - ASSERT_PRECONDITION(BSL_SecOutcome_IsConsistent(self)); - BSLB_IdValPairPtr_t **item_ptr = BSLB_IdValPairPtrList_push_new(self->result_list); - - *item_ptr = BSLB_IdValPairPtr_new(); - - return BSLB_IdValPairPtr_ref(*item_ptr); -} - -size_t BSL_SecOutcome_CountResults(const BSL_SecOutcome_t *self) -{ - ASSERT_PRECONDITION(BSL_SecOutcome_IsConsistent(self)); - return BSLB_IdValPairPtrList_size(self->result_list); -} - -const BSL_IdValPair_t *BSL_SecOutcome_GetResultAtIndex(const BSL_SecOutcome_t *self, size_t index) -{ - ASSERT_PRECONDITION(BSL_SecOutcome_IsConsistent(self)); - ASSERT_PRECONDITION(index < BSLB_IdValPairPtrList_size(self->result_list)); - - return BSLB_IdValPairPtr_cref(*BSLB_IdValPairPtrList_cget(self->result_list, index)); -} - -size_t BSL_SecOutcome_CountParams(const BSL_SecOutcome_t *self) -{ - ASSERT_PRECONDITION(BSL_SecOutcome_IsConsistent(self)); - - return BSLB_IdValPairPtrList_size(self->param_list); -} - -const BSL_IdValPair_t *BSL_SecOutcome_GetParamAt(const BSL_SecOutcome_t *self, size_t index) -{ - ASSERT_PRECONDITION(BSL_SecOutcome_IsConsistent(self)); - ASSERT_PRECONDITION(index < BSLB_IdValPairPtrList_size(self->param_list)); - - return BSLB_IdValPairPtr_cref(*BSLB_IdValPairPtrList_cget(self->param_list, index)); -} - -BSL_IdValPair_t *BSL_SecOutcome_AppendParam(BSL_SecOutcome_t *self) -{ - ASSERT_PRECONDITION(BSL_SecOutcome_IsConsistent(self)); - BSLB_IdValPairPtr_t **item_ptr = BSLB_IdValPairPtrList_push_new(self->param_list); - - *item_ptr = BSLB_IdValPairPtr_new(); - - return BSLB_IdValPairPtr_ref(*item_ptr); -} diff --git a/src/backend/SecOutcome.h b/src/backend/SecOutcome.h deleted file mode 100644 index 3740267b..00000000 --- a/src/backend/SecOutcome.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2025-2026 The Johns Hopkins University Applied Physics - * Laboratory LLC. - * - * This file is part of the Bundle Protocol Security Library (BSL). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This work was performed for the Jet Propulsion Laboratory, California - * Institute of Technology, sponsored by the United States Government under - * the prime contract 80NM0018D0004 between the Caltech and NASA under - * subcontract 1700763. - */ - -/** - * @file SecOutcome.h - * @ingroup backend_dyn - * @brief Defines the result of a security operation - * - * @details - * - * Forthcoming. - * - * @author Bill.Van.Besien@jhuapl.edu - */ -#ifndef BSLB_SECOUTCOME_H_ -#define BSLB_SECOUTCOME_H_ - -#include - -#include "IdValPair.h" - -struct BSL_SecOutcome_s -{ - /// @brief Boolean indicating true when successful - bool is_success; - - /// @brief Non-NULL pointer to Security Operation that provided the input. - const BSL_SecOper_t *sec_oper; - - /// @brief List of security parameters with metadata for receiver. Must be encoded into the BTSD. - BSLB_IdValPairPtrList_t param_list; - - /// @brief List of security results with metadata for receiver. Must be encoded into BTSD. - BSLB_IdValPairPtrList_t result_list; -}; - -#endif /* BSLB_SECOUTCOME_H_ */ diff --git a/src/backend/SecurityContext.c b/src/backend/SecurityContext.c index 496c8f59..9aece75b 100644 --- a/src/backend/SecurityContext.c +++ b/src/backend/SecurityContext.c @@ -31,7 +31,6 @@ #include "CBOR.h" #include "PublicInterfaceImpl.h" #include "SecOperation.h" -#include "SecOutcome.h" #include "SecurityActionSet.h" static int Encode_ASB(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, uint64_t blk_num, const BSL_AbsSecBlock_t *asb) @@ -73,7 +72,7 @@ static int Encode_ASB(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, uint64_t blk_n /** Common handling of informing new ASB content after an operation. */ static int BSL_ExecAnySource_Post(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, - const BSL_SecOutcome_t *outcome, BSL_AbsSecBlock_t *asb) + BSL_AbsSecBlock_t *asb) { BSL_CanonicalBlock_t sec_blk; if (BSL_BundleCtx_GetBlockMetadata(bundle, sec_oper->sec_block_num, &sec_blk) != BSL_SUCCESS) @@ -91,11 +90,11 @@ static int BSL_ExecAnySource_Post(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, co } // target-independent data - BSLB_IdValPairPtrList_it_t param_it; - for (BSLB_IdValPairPtrList_it(param_it, outcome->param_list); !BSLB_IdValPairPtrList_end_p(param_it); - BSLB_IdValPairPtrList_next(param_it)) + BSLB_IdValPairPtrMap_it_t param_it; + for (BSLB_IdValPairPtrMap_it(param_it, sec_oper->_params); !BSLB_IdValPairPtrMap_end_p(param_it); + BSLB_IdValPairPtrMap_next(param_it)) { - BSLB_IdValPairPtr_t **ptr = BSLB_IdValPairPtrList_ref(param_it); + BSLB_IdValPairPtr_t **ptr = BSLB_IdValPairPtrMap_ref(param_it)->value_ptr; // copy shared ptr BSLB_IdValPairPtrList_push_back(asb->params, *ptr); } @@ -103,11 +102,11 @@ static int BSL_ExecAnySource_Post(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, co // target-specific data BSL_AbsSecBlock_Target_t *tgt = BSL_AbsSecBlock_AddTarget(asb, sec_oper->target_block_num); - BSLB_IdValPairPtrList_it_t result_it; - for (BSLB_IdValPairPtrList_it(result_it, outcome->result_list); !BSLB_IdValPairPtrList_end_p(result_it); - BSLB_IdValPairPtrList_next(result_it)) + BSLB_IdValPairPtrMap_it_t result_it; + for (BSLB_IdValPairPtrMap_it(result_it, sec_oper->_results); !BSLB_IdValPairPtrMap_end_p(result_it); + BSLB_IdValPairPtrMap_next(result_it)) { - BSLB_IdValPairPtr_t **ptr = BSLB_IdValPairPtrList_ref(result_it); + BSLB_IdValPairPtr_t **ptr = BSLB_IdValPairPtrMap_ref(result_it)->value_ptr; // copy shared ptr BSLB_IdValPairPtrList_push_back(tgt->results, *ptr); } @@ -122,12 +121,11 @@ static int BSL_ExecAnySource_Post(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, co } int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, - BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome) + BSL_SecOper_t *sec_oper) { CHK_ARG_NONNULL(sec_context_fn); CHK_ARG_NONNULL(bundle); CHK_ARG_NONNULL(sec_oper); - CHK_ARG_NONNULL(outcome); BSL_TlmCounters_IncrementCounter(lib, BSL_TLM_SECOP_SOURCE_COUNT, 1); @@ -142,8 +140,8 @@ int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS BSL_LOG_DEBUG("Created new BIB block number = %" PRIu64, sec_oper->sec_block_num); CHK_PROPERTY(sec_oper->sec_block_num > 1); - const int bib_result = (*sec_context_fn)(lib, bundle, sec_oper, outcome); - if (bib_result != 0) // || outcome->is_success == false) + const int bib_result = (*sec_context_fn)(lib, bundle, sec_oper); + if (bib_result != 0) { BSL_LOG_ERR("BIB Source failed!"); BSL_TlmCounters_IncrementCounter(lib, BSL_TLM_SECOP_FAIL_COUNT, 1); @@ -160,7 +158,7 @@ int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS BSL_AbsSecBlock_t asb; BSL_AbsSecBlock_Init(&asb); - res = BSL_ExecAnySource_Post(lib, bundle, sec_oper, outcome, &asb); + res = BSL_ExecAnySource_Post(lib, bundle, sec_oper, &asb); if (BSL_SUCCESS != res) { BSL_TlmCounters_IncrementCounter(lib, BSL_TLM_SECOP_FAIL_COUNT, 1); @@ -214,7 +212,7 @@ static int BSL_ExecAnyVerifierAcceptor_Pre(BSL_LibCtx_t *lib, BSL_BundleRef_t *b // index by ID const BSL_IdValPair_t *param = BSLB_IdValPairPtr_cref(*ptr); - BSLB_IdValPairPtrMap_set_at(sec_oper->_params_in, param->id, *ptr); + BSLB_IdValPairPtrMap_set_at(sec_oper->_params, param->id, *ptr); } sec_oper->_target_index = 0; @@ -238,7 +236,7 @@ static int BSL_ExecAnyVerifierAcceptor_Pre(BSL_LibCtx_t *lib, BSL_BundleRef_t *b // index by ID const BSL_IdValPair_t *result = BSLB_IdValPairPtr_cref(*ptr); - BSLB_IdValPairPtrMap_set_at(sec_oper->_results_in, result->id, *ptr); + BSLB_IdValPairPtrMap_set_at(sec_oper->_results, result->id, *ptr); } // first one wins @@ -249,12 +247,11 @@ static int BSL_ExecAnyVerifierAcceptor_Pre(BSL_LibCtx_t *lib, BSL_BundleRef_t *b } int BSL_ExecBIBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, - BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome) + BSL_SecOper_t *sec_oper) { CHK_ARG_NONNULL(lib); CHK_ARG_NONNULL(bundle); CHK_PRECONDITION(BSL_SecOper_IsConsistent(sec_oper)); - CHK_PRECONDITION(BSL_SecOutcome_IsConsistent(outcome)); BSL_AbsSecBlock_t asb; BSL_AbsSecBlock_Init(&asb); @@ -267,8 +264,8 @@ int BSL_ExecBIBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_ return res; } - const int sec_context_result = (*sec_context_fn)(lib, bundle, sec_oper, outcome); - if (sec_context_result != BSL_SUCCESS) // || outcome->is_success == false) + const int sec_context_result = (*sec_context_fn)(lib, bundle, sec_oper); + if (sec_context_result != BSL_SUCCESS) { BSL_LOG_ERR("BIB Sec Ctx processing for verifier/acceptor failed!"); BSL_AbsSecBlock_Deinit(&asb); @@ -324,12 +321,11 @@ int BSL_ExecBIBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_ } int BSL_ExecBCBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, - BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome) + BSL_SecOper_t *sec_oper) { CHK_ARG_NONNULL(sec_context_fn); CHK_ARG_NONNULL(bundle); CHK_ARG_NONNULL(sec_oper); - CHK_ARG_NONNULL(outcome); BSL_AbsSecBlock_t asb; BSL_AbsSecBlock_Init(&asb); @@ -342,7 +338,7 @@ int BSL_ExecBCBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_ return res; } - const int sec_context_result = (*sec_context_fn)(lib, bundle, sec_oper, outcome); + const int sec_context_result = (*sec_context_fn)(lib, bundle, sec_oper); if (sec_context_result != BSL_SUCCESS) { BSL_LOG_ERR("BCB Sec Ctx processing for verifier/acceptor failed!"); @@ -396,12 +392,11 @@ int BSL_ExecBCBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_ } int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, - BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome) + BSL_SecOper_t *sec_oper) { CHK_ARG_NONNULL(sec_context_fn); CHK_ARG_NONNULL(bundle); CHK_ARG_NONNULL(sec_oper); - CHK_ARG_NONNULL(outcome); BSL_TlmCounters_IncrementCounter(lib, BSL_TLM_SECOP_SOURCE_COUNT, 1); @@ -416,8 +411,8 @@ int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS BSL_LOG_DEBUG("Created new BCB block number = %" PRIu64, sec_oper->sec_block_num); CHK_PROPERTY(sec_oper->sec_block_num > 1); - res = (*sec_context_fn)(lib, bundle, sec_oper, outcome); - if (res != 0) // || outcome->is_success == false) + res = (*sec_context_fn)(lib, bundle, sec_oper); + if (res != 0) { BSL_LOG_ERR("BCB Source failed!"); BSL_TlmCounters_IncrementCounter(lib, BSL_TLM_SECOP_FAIL_COUNT, 1); @@ -427,7 +422,7 @@ int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS BSL_AbsSecBlock_t asb; BSL_AbsSecBlock_Init(&asb); - res = BSL_ExecAnySource_Post(lib, bundle, sec_oper, outcome, &asb); + res = BSL_ExecAnySource_Post(lib, bundle, sec_oper, &asb); if (BSL_SUCCESS != res) { BSL_TlmCounters_IncrementCounter(lib, BSL_TLM_SECOP_FAIL_COUNT, 1); @@ -449,12 +444,10 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle /** * Notes: * - It should evaluate every security operation, even if earlier ones failed. - * - The outcome can indicate in the policy action response how exactly it fared (pass, fail, etc) + * - The operation conclusion indicates how processing fared (pass, fail, etc.) * - BCB will be a special case, since it actively manipulates the BTSD * */ - BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); - BSL_SecActionList_it_t act_it; for (BSL_SecActionList_it(act_it, action_set->actions); !BSL_SecActionList_end_p(act_it); BSL_SecActionList_next(act_it)) @@ -463,7 +456,7 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle for (size_t i = 0; i < BSL_SecurityAction_CountSecOpers(act); i++) { BSL_SecOper_t *sec_oper = BSL_SecurityAction_GetSecOperAtIndex(act, i); - BSL_SecOutcome_Init(outcome, sec_oper); + BSL_SecOper_ClearParamsAndResults(sec_oper); const BSL_SecCtxDesc_t *sec_ctx = BSL_SecCtxDict_cget(lib->sc_reg, sec_oper->context_id); int errcode; @@ -476,27 +469,25 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle { if (BSL_SecOper_IsRoleSource(sec_oper)) { - errcode = BSL_ExecBIBSource(sec_ctx->execute, lib, bundle, sec_oper, outcome); + errcode = BSL_ExecBIBSource(sec_ctx->execute, lib, bundle, sec_oper); } else { - errcode = BSL_ExecBIBVerifierAcceptor(sec_ctx->execute, lib, bundle, sec_oper, outcome); + errcode = BSL_ExecBIBVerifierAcceptor(sec_ctx->execute, lib, bundle, sec_oper); } } else { if (BSL_SecOper_IsRoleSource(sec_oper)) { - errcode = BSL_ExecBCBSource(sec_ctx->execute, lib, bundle, sec_oper, outcome); + errcode = BSL_ExecBCBSource(sec_ctx->execute, lib, bundle, sec_oper); } else { - errcode = BSL_ExecBCBVerifierAcceptor(sec_ctx->execute, lib, bundle, sec_oper, outcome); + errcode = BSL_ExecBCBVerifierAcceptor(sec_ctx->execute, lib, bundle, sec_oper); } } - BSL_SecOutcome_Deinit(outcome); - if (errcode != BSL_SUCCESS) { BSL_LOG_ERR("Security Op failed: %d", errcode); @@ -511,8 +502,6 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle BSL_SecOper_SetConclusion(sec_oper, BSL_SECOP_CONCLUSION_SUCCESS); } } - BSL_free(outcome); - return BSL_SUCCESS; } diff --git a/src/cose_sc/CoseContext.c b/src/cose_sc/CoseContext.c index 29cbe32c..6466d8ef 100644 --- a/src/cose_sc/CoseContext.c +++ b/src/cose_sc/CoseContext.c @@ -60,10 +60,8 @@ typedef struct { /// Bundle context associated with this operation BSL_BundleRef_t *bundle; - /// Operation source - const BSL_SecOper_t *sec_oper; - /// Operation outcome - BSL_SecOutcome_t *sec_outcome; + /// Operation source and output + BSL_SecOper_t *sec_oper; /// Security source cache BSL_HostEID_t sec_src_eid; @@ -177,12 +175,10 @@ static void BSLX_CoseSc_Deinit(BSLX_CoseSc_t *self) memset(self, 0, sizeof(*self)); } -static void BSLX_CoseSc_Prepare(BSLX_CoseSc_t *self, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, - BSL_SecOutcome_t *sec_outcome) +static void BSLX_CoseSc_Prepare(BSLX_CoseSc_t *self, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper) { self->bundle = bundle; self->sec_oper = sec_oper; - self->sec_outcome = sec_outcome; self->is_bib = BSL_SecOper_IsBIB(sec_oper); self->is_source = BSL_SecOper_IsRoleSource(sec_oper); self->overwrite_btsd = !BSL_SecOper_IsRoleVerifier(sec_oper); @@ -349,7 +345,7 @@ bool BSLX_CoseSc_Validate(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, BSL_Se { BSLX_CoseSc_t ctx; BSLX_CoseSc_Init(&ctx); - BSLX_CoseSc_Prepare(&ctx, bundle, sec_oper, NULL); + BSLX_CoseSc_Prepare(&ctx, bundle, sec_oper); if (BSL_SUCCESS == ctx.status) { @@ -1132,11 +1128,11 @@ static void BSLX_CoseSc_Mac0_Source(BSLX_CoseSc_t *ctx) if (BSL_SUCCESS == ctx->status) { { - BSL_IdValPair_t *param = BSL_SecOutcome_AppendParam(ctx->sec_outcome); + BSL_IdValPair_t *param = BSL_SecOper_AddParam(ctx->sec_oper, BSLX_COSESC_PARAM_AAD_SCOPE); BSL_IdValPair_SetRaw(param, BSLX_COSESC_PARAM_AAD_SCOPE, aad_scope_enc.ptr, aad_scope_enc.len); } { - BSL_IdValPair_t *result = BSL_SecOutcome_AppendResult(ctx->sec_outcome); + BSL_IdValPair_t *result = BSL_SecOper_AddResult(ctx->sec_oper, BSLX_COSESC_RESULT_COSE_MAC0); BSL_IdValPair_SetBytestr(result, BSLX_COSESC_RESULT_COSE_MAC0, msg_enc); } } @@ -1604,11 +1600,11 @@ static void BSLX_CoseSc_Encrypt0_Source(BSLX_CoseSc_t *ctx) if (BSL_SUCCESS == ctx->status) { { - BSL_IdValPair_t *param = BSL_SecOutcome_AppendParam(ctx->sec_outcome); + BSL_IdValPair_t *param = BSL_SecOper_AddParam(ctx->sec_oper, BSLX_COSESC_PARAM_AAD_SCOPE); BSL_IdValPair_SetRaw(param, BSLX_COSESC_PARAM_AAD_SCOPE, aad_scope_enc.ptr, aad_scope_enc.len); } { - BSL_IdValPair_t *result = BSL_SecOutcome_AppendResult(ctx->sec_outcome); + BSL_IdValPair_t *result = BSL_SecOper_AddResult(ctx->sec_oper, BSLX_COSESC_RESULT_COSE_ENCRYPT0); BSL_IdValPair_SetBytestr(result, BSLX_COSESC_RESULT_COSE_ENCRYPT0, msg_enc); } } @@ -1749,12 +1745,11 @@ static void BSLX_CoseSc_Encrypt0_VerifyAccept(BSLX_CoseSc_t *ctx, const BSL_IdVa BSLX_CoseMsg_Encrypt0_Deinit(&msg); } -int BSLX_CoseSc_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, // NOSONAR - BSL_SecOutcome_t *sec_outcome) +int BSLX_CoseSc_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper) // NOSONAR { BSLX_CoseSc_t ctx; BSLX_CoseSc_Init(&ctx); - BSLX_CoseSc_Prepare(&ctx, bundle, sec_oper, sec_outcome); + BSLX_CoseSc_Prepare(&ctx, bundle, sec_oper); if (BSL_SUCCESS == ctx.status) { diff --git a/src/cose_sc/CoseContext.h b/src/cose_sc/CoseContext.h index c45d73a1..7d1b7c50 100644 --- a/src/cose_sc/CoseContext.h +++ b/src/cose_sc/CoseContext.h @@ -131,8 +131,7 @@ int BSLX_CoseSc_AadScope_Decode(QCBORDecodeContext *dec, BSLX_CoseSc_AadScope_t bool BSLX_CoseSc_Validate(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper); /// Match signature ::BSL_SecCtx_Execute_f -int BSLX_CoseSc_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, - BSL_SecOutcome_t *sec_outcome); +int BSLX_CoseSc_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper); #ifdef __cplusplus } // extern C diff --git a/src/default_sc/BCB_AES_GCM.c b/src/default_sc/BCB_AES_GCM.c index bf9a51f7..8eebc789 100644 --- a/src/default_sc/BCB_AES_GCM.c +++ b/src/default_sc/BCB_AES_GCM.c @@ -534,12 +534,10 @@ void BSLX_BCB_Deinit(BSLX_BCB_t *bcb_context) memset(bcb_context, 0, sizeof(*bcb_context)); } -int BSLX_BCB_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, // NOSONAR - BSL_SecOutcome_t *sec_outcome) +int BSLX_BCB_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper) // NOSONAR { CHK_ARG_NONNULL(bundle); CHK_ARG_NONNULL(sec_oper); - CHK_ARG_NONNULL(sec_outcome); CHK_PRECONDITION(BSL_SecOper_GetSecurityBlockNum(sec_oper) > 0); @@ -711,33 +709,33 @@ int BSLX_BCB_Execute(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle, const BSL_S if (bcb_context.authtag.len > 0) { BSL_LOG_INFO("Appending BCB Auth Tag"); - BSL_IdValPair_t *auth_tag = BSL_SecOutcome_AppendResult(sec_outcome); + BSL_IdValPair_t *auth_tag = BSL_SecOper_AddResult(sec_oper, RFC9173_BCB_RESULTID_AUTHTAG); BSL_IdValPair_SetBytestr(auth_tag, RFC9173_BCB_RESULTID_AUTHTAG, bcb_context.authtag); } if (bcb_context.iv.len > 0) { BSL_LOG_INFO("Appending BCB source IV"); - BSL_IdValPair_t *iv_param = BSL_SecOutcome_AppendParam(sec_outcome); + BSL_IdValPair_t *iv_param = BSL_SecOper_AddParam(sec_oper, RFC9173_BCB_SECPARAM_IV); BSL_IdValPair_SetBytestr(iv_param, RFC9173_BCB_SECPARAM_IV, bcb_context.iv); } { BSL_LOG_INFO("Appending BCB AES param"); - BSL_IdValPair_t *aes_param = BSL_SecOutcome_AppendParam(sec_outcome); + BSL_IdValPair_t *aes_param = BSL_SecOper_AddParam(sec_oper, RFC9173_BCB_SECPARAM_AESVARIANT); BSL_IdValPair_SetInt64(aes_param, RFC9173_BCB_SECPARAM_AESVARIANT, bcb_context.aes_variant); } if (bcb_context.wrapped_key.len > 0) { BSL_LOG_INFO("Appending BCB wrapped key param"); - BSL_IdValPair_t *aes_wrapped_key_param = BSL_SecOutcome_AppendParam(sec_outcome); + BSL_IdValPair_t *aes_wrapped_key_param = BSL_SecOper_AddParam(sec_oper, RFC9173_BCB_SECPARAM_WRAPPEDKEY); BSL_IdValPair_SetBytestr(aes_wrapped_key_param, RFC9173_BCB_SECPARAM_WRAPPEDKEY, bcb_context.wrapped_key); } { BSL_LOG_INFO("Appending BCB scope flag param"); - BSL_IdValPair_t *scope_flag_param = BSL_SecOutcome_AppendParam(sec_outcome); + BSL_IdValPair_t *scope_flag_param = BSL_SecOper_AddParam(sec_oper, RFC9173_BCB_SECPARAM_AADSCOPE); BSL_IdValPair_SetInt64(scope_flag_param, RFC9173_BCB_SECPARAM_AADSCOPE, bcb_context.aad_scope); } } diff --git a/src/default_sc/BIB_HMAC_SHA2.c b/src/default_sc/BIB_HMAC_SHA2.c index ebf87c34..f5bade62 100644 --- a/src/default_sc/BIB_HMAC_SHA2.c +++ b/src/default_sc/BIB_HMAC_SHA2.c @@ -400,14 +400,11 @@ int BSLX_BIB_GenHMAC(BSLX_BIB_t *self, const BSL_Data_t *ippt_data) return BSL_SUCCESS; } -int BSLX_BIB_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, // NOSONAR - BSL_SecOutcome_t *sec_outcome) +int BSLX_BIB_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper) // NOSONAR { CHK_ARG_NONNULL(lib); CHK_ARG_NONNULL(bundle); CHK_ARG_NONNULL(sec_oper); - CHK_ARG_NONNULL(sec_outcome); - CHK_PRECONDITION(BSL_SecOper_IsConsistent(sec_oper)); BSLX_BIB_t bib_context; @@ -542,24 +539,24 @@ int BSLX_BIB_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOp { { BSL_LOG_DEBUG("Appending SHA variant param"); - BSL_IdValPair_t *scope_flag_param = BSL_SecOutcome_AppendParam(sec_outcome); + BSL_IdValPair_t *scope_flag_param = BSL_SecOper_AddParam(sec_oper, RFC9173_BIB_PARAMID_SHA_VARIANT); BSL_IdValPair_SetInt64(scope_flag_param, RFC9173_BIB_PARAMID_SHA_VARIANT, bib_context.sha_variant); } { BSL_LOG_DEBUG("Appending IPPT scope flag param"); - BSL_IdValPair_t *scope_flag_param = BSL_SecOutcome_AppendParam(sec_outcome); + BSL_IdValPair_t *scope_flag_param = BSL_SecOper_AddParam(sec_oper, RFC9173_BIB_PARAMID_INTEG_SCOPE_FLAG); BSL_IdValPair_SetInt64(scope_flag_param, RFC9173_BIB_PARAMID_INTEG_SCOPE_FLAG, bib_context.ippt_scope); } { BSL_LOG_DEBUG("Appending BIB wrapped key param"); - BSL_IdValPair_t *bib_result = BSL_SecOutcome_AppendResult(sec_outcome); + BSL_IdValPair_t *bib_result = BSL_SecOper_AddResult(sec_oper, RFC9173_BIB_RESULTID_HMAC); BSL_IdValPair_SetBytestr(bib_result, RFC9173_BIB_RESULTID_HMAC, bib_context.hmac_result_val); } if (bib_context.wrapped_key.len > 0) { BSL_LOG_DEBUG("Appending BIB wrapped key param"); - BSL_IdValPair_t *wrapped_key_param = BSL_SecOutcome_AppendParam(sec_outcome); + BSL_IdValPair_t *wrapped_key_param = BSL_SecOper_AddParam(sec_oper, RFC9173_BIB_PARAMID_WRAPPED_KEY); BSL_IdValPair_SetBytestr(wrapped_key_param, RFC9173_BIB_PARAMID_WRAPPED_KEY, bib_context.wrapped_key); } } diff --git a/src/default_sc/DefaultSecContext.h b/src/default_sc/DefaultSecContext.h index 09a9fc40..c87a4008 100644 --- a/src/default_sc/DefaultSecContext.h +++ b/src/default_sc/DefaultSecContext.h @@ -56,8 +56,7 @@ enum BSLX_BIB_Options_e bool BSLX_BIB_Validate(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper); /// Match signature ::BSL_SecCtx_Execute_f -int BSLX_BIB_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, - BSL_SecOutcome_t *sec_outcome); +int BSLX_BIB_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper); /// Internal BCB option enumerations enum BSLX_BCB_Options_e @@ -82,7 +81,6 @@ enum BSLX_BCB_Options_e bool BSLX_BCB_Validate(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper); /// Match signature ::BSL_SecCtx_Execute_f -int BSLX_BCB_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, - BSL_SecOutcome_t *sec_outcome); +int BSLX_BCB_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper); #endif /* BSLX_SECCTXERR_H_ */ diff --git a/test/test_BackendSecurityContext.c b/test/test_BackendSecurityContext.c index 8ed6dac9..a4d3515b 100644 --- a/test/test_BackendSecurityContext.c +++ b/test/test_BackendSecurityContext.c @@ -59,14 +59,11 @@ static bool BSL_TestSecCtx_Validate(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, return (sec_oper->target_block_num != 111); } -static int BSL_TestSecCtx_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, - BSL_SecOutcome_t *sec_outcome) +static int BSL_TestSecCtx_Execute(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper) { (void)lib; (void)bundle; (void)sec_oper; - (void)sec_outcome; - return BSL_SUCCESS; } @@ -188,8 +185,8 @@ void test_SecurityContext_BIB_Source(void) * Steps: * - Get a BIB secured bundle from RFC9173 Appendix A1.4. * - Create a BIB-Verify security operation with hard-coded arguments (From RFC9173 A1 ASB) - * - Use the high-level security context interface to create a security outcome. - * - Confirm the bundle's BIB HMAC matches the outcome's HMAC. + * - Use the high-level security context interface to execute a security operation. + * - Confirm the bundle's BIB HMAC matches the operation's HMAC. * * Notes: * - Common repeated patterns are in the process of being factored out @@ -227,11 +224,11 @@ void test_SecurityContext_BIB_Verifier(void) * - Get a BIB secured bundle from RFC9173 Appendix A1.4. * - Create a BIB-Verify security operation with hard-coded arguments (From RFC9173 A1 ASB) * - Manipulate the arguments so they use a different key - * - Use the high-level security context interface to create a security outcome. + * - Use the high-level security context interface to execute a security operation. * - Confirm that the execution failed (return code != 0) * * Notes: - * - Check more than return code, look deeper into outcome. + * - Check more than return code, look deeper into operation. */ void test_SecurityContext_BIB_Verifier_Failure(void) { @@ -271,7 +268,7 @@ void test_SecurityContext_BIB_Verifier_Failure(void) * Steps: * - Get a BIB secured bundle from RFC9173 Appendix A1.4. * - Create a BIB-Acceptor security operation with hard-coded arguments (From RFC9173 A1 ASB) - * - Use the high-level security context interface to create a security outcome. + * - Use the high-level security context interface to execute a security operation. * - Confirm that the execution succeeds. * - Check that the BIB result was removed from the bundle (by making sure the encoding matches bundle in A1.1) * diff --git a/test/test_CoseContext.c b/test/test_CoseContext.c index 36e4ed81..41f44d68 100644 --- a/test/test_CoseContext.c +++ b/test/test_CoseContext.c @@ -282,7 +282,7 @@ void test_CoseSc_InvalidOptions_Verifier(void) * - Create a BIB security operation with hard-coded options * - Run ::BSLX_CoseSc_Validate function and confirm result is 0. * - Run ::BSLX_CoseSc_Execute function and confirm result is 0. - * - Capture the outcome from the above function to confirm 1 result (a COSE_Mac0 message) + * - Check the operation after the above function to confirm 1 result (a COSE_Mac0 message) * - Capture the MAC tag and ensure it matches the value in the test vector. */ void test_AppendixA_Example1_BIB_Source(void) @@ -346,20 +346,17 @@ void test_AppendixA_Example1_BIB_Source(void) BSL_IdValPair_Deinit(&option); } - BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); - BSL_SecOutcome_Init(outcome, &sec_oper); - bool valid_status = BSLX_CoseSc_Validate(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_TRUE(valid_status); // Confirm running operation as source executes without error - int exec_status = BSL_ExecBIBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, - &sec_oper, outcome); + int exec_status = + BSL_ExecBIBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_status); // Confirm it produced only 1 result - TEST_ASSERT_EQUAL(1, BSL_SecOutcome_CountResults(outcome)); - const BSL_IdValPair_t *result = BSL_SecOutcome_GetResultAtIndex(outcome, 0); + TEST_ASSERT_EQUAL(1, BSL_SecOper_CountResults(&sec_oper)); + const BSL_IdValPair_t *result = BSL_SecOper_FindResult(&sec_oper, BSLX_COSESC_RESULT_COSE_MAC0); TEST_ASSERT_NOT_NULL(result); TEST_ASSERT_EQUAL(BSLX_COSESC_RESULT_COSE_MAC0, BSL_IdValPair_GetId(result)); TEST_ASSERT_TRUE(BSL_IdValPair_IsBytestr(result)); @@ -379,8 +376,6 @@ void test_AppendixA_Example1_BIB_Source(void) TEST_ASSERT_EQUAL(0, BSL_TestUtils_EncodeBundleToCBOR(&LocalTestCtx)); TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(exA_1_mac0, LocalTestCtx.mock_bpa_ctr.encoded)); - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); } @@ -487,9 +482,6 @@ void test_AppendixA_Example1_BIB_VerifyAccept(BSL_SecRole_e role, int mismatch) BSL_Data_Deinit(&value); } - BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); - BSL_SecOutcome_Init(outcome, &sec_oper); - bool valid_status = BSLX_CoseSc_Validate(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL(true, valid_status); @@ -498,7 +490,7 @@ void test_AppendixA_Example1_BIB_VerifyAccept(BSL_SecRole_e role, int mismatch) : BSL_ERR_SECURITY_OPERATION_FAILED; // Confirm running operation as source executes without error int exec_status = BSL_ExecBIBVerifierAcceptor(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, - &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper, outcome); + &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL_INT(expect_status, exec_status); if (alter_blk) @@ -518,8 +510,6 @@ void test_AppendixA_Example1_BIB_VerifyAccept(BSL_SecRole_e role, int mismatch) TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(exA_nosec, LocalTestCtx.mock_bpa_ctr.encoded)); } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); } @@ -601,20 +591,17 @@ void test_AppendixA_Example4_BCB_Source(void) BSL_IdValPair_Deinit(&option); } - BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); - BSL_SecOutcome_Init(outcome, &sec_oper); - bool valid_status = BSLX_CoseSc_Validate(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_TRUE(valid_status); // Confirm running operation as source executes without error - int exec_status = BSL_ExecBCBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, - &sec_oper, outcome); + int exec_status = + BSL_ExecBCBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_status); // Confirm it produced only 1 result - TEST_ASSERT_EQUAL(1, BSL_SecOutcome_CountResults(outcome)); - const BSL_IdValPair_t *result = BSL_SecOutcome_GetResultAtIndex(outcome, 0); + TEST_ASSERT_EQUAL(1, BSL_SecOper_CountResults(&sec_oper)); + const BSL_IdValPair_t *result = BSL_SecOper_FindResult(&sec_oper, BSLX_COSESC_RESULT_COSE_ENCRYPT0); TEST_ASSERT_NOT_NULL(result); TEST_ASSERT_EQUAL(BSLX_COSESC_RESULT_COSE_ENCRYPT0, BSL_IdValPair_GetId(result)); TEST_ASSERT_TRUE(BSL_IdValPair_IsBytestr(result)); @@ -635,8 +622,6 @@ void test_AppendixA_Example4_BCB_Source(void) TEST_ASSERT_EQUAL(0, BSL_TestUtils_EncodeBundleToCBOR(&LocalTestCtx)); TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(exA_4_enc0, LocalTestCtx.mock_bpa_ctr.encoded)); - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); } @@ -740,9 +725,6 @@ void test_AppendixA_Example4_BCB_VerifyAccept(BSL_SecRole_e role, int mismatch) BSL_Data_Deinit(&value); } - BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); - BSL_SecOutcome_Init(outcome, &sec_oper); - bool valid_status = BSLX_CoseSc_Validate(&LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL(true, valid_status); @@ -751,7 +733,7 @@ void test_AppendixA_Example4_BCB_VerifyAccept(BSL_SecRole_e role, int mismatch) : BSL_ERR_SECURITY_OPERATION_FAILED; // Confirm running operation as source executes without error int exec_status = BSL_ExecBCBVerifierAcceptor(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, - &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper, outcome); + &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL_INT(expect_status, exec_status); if (alter_blk) @@ -772,7 +754,5 @@ void test_AppendixA_Example4_BCB_VerifyAccept(BSL_SecRole_e role, int mismatch) TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(exA_nosec, LocalTestCtx.mock_bpa_ctr.encoded)); } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); } diff --git a/test/test_DefaultSecurityContext.c b/test/test_DefaultSecurityContext.c index c29f5478..0d196e46 100644 --- a/test/test_DefaultSecurityContext.c +++ b/test/test_DefaultSecurityContext.c @@ -82,7 +82,7 @@ void tearDown(void) * - Decode it into a BSL_BundleCtx struct * - Create a BIB security operation with hard-coded arguments (From RFC9173 A1 ASB) * - Run the DefaultSecuritContext's BSLX_BIB_Execute function and confirm result is 0. - * - Capture the outcome from the above function to confirm 1 result (the authentication code) + * - Check the operation after the above function to confirm 1 result (the authentication code) * - Capture the auth code and ensure it matches the value in the test vector. * * Notes: @@ -101,17 +101,14 @@ void test_RFC9173_AppendixA_Example1_BIB_Source(void) BIBTestContext_Init(&bib_test_context); BSL_TestUtils_InitBIB_AppendixA1(&bib_test_context, BSL_SECROLE_SOURCE, RFC9173_EXAMPLE_A1_KEY); - BSL_SecOutcome_t *sec_outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); - BSL_SecOutcome_Init(sec_outcome, &bib_test_context.sec_oper); - /// Confirm running BIB as source executes without error - int bib_exec_status = - BSLX_BIB_Execute(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, &bib_test_context.sec_oper, sec_outcome); + int bib_exec_status = BSLX_BIB_Execute(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, &bib_test_context.sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, bib_exec_status); /// Confirm it produced only 1 result - TEST_ASSERT_EQUAL(1, BSL_SecOutcome_CountResults(sec_outcome)); - const BSL_IdValPair_t *bib_result = BSL_SecOutcome_GetResultAtIndex(sec_outcome, 0); + TEST_ASSERT_EQUAL(1, BSL_SecOper_CountResults(&bib_test_context.sec_oper)); + const BSL_IdValPair_t *bib_result = BSL_SecOper_FindResult(&bib_test_context.sec_oper, RFC9173_BIB_RESULTID_HMAC); + TEST_ASSERT_NOT_NULL(bib_result); /// Confirm the context and result result is the right ID (Defined in RFC) TEST_ASSERT_EQUAL(RFC9173_BIB_RESULTID_HMAC, bib_result->id); @@ -123,8 +120,6 @@ void test_RFC9173_AppendixA_Example1_BIB_Source(void) TEST_ASSERT_TRUE(is_equal); BSL_Data_Deinit(&mac_view); - BSL_SecOutcome_Deinit(sec_outcome); - BSL_free(sec_outcome); BIBTestContext_Deinit(&bib_test_context); } @@ -142,7 +137,7 @@ void test_RFC9173_AppendixA_Example1_BIB_Source(void) * - Decode it into a BSL_BundleCtx struct * - Create a BCB security operation with hard-coded arguments (From RFC9173 A2 ASB) * - Run the DefaultSecuritContext's BSLX_BCB_Execute function and confirm result is 0. - * - Capture the outcome from the above function to confirm 1 result (the auth tag) is present + * - Check the operation after the above function to confirm 1 result (the auth tag) is present * - Capture the auth tag and ensure it matches the value in the test vector. * * Notes: @@ -160,17 +155,15 @@ void test_RFC9173_AppendixA_Example2_BCB_Source(void) BCBTestContext_Init(&bcb_test_context); BSL_TestUtils_InitBCB_Appendix2(&bcb_test_context, BSL_SECROLE_SOURCE); - BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); - BSL_SecOutcome_Init(outcome, &bcb_test_context.sec_oper); - // Execute BCB as source, confirm result is 0 (success) - int bcb_exec_result = - BSLX_BCB_Execute(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, &bcb_test_context.sec_oper, outcome); + int bcb_exec_result = BSLX_BCB_Execute(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, &bcb_test_context.sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, bcb_exec_result); // Confirm the output produces one result (the AES-GCM auth code) - TEST_ASSERT_EQUAL(1, BSL_SecOutcome_CountResults(outcome)); - const BSL_IdValPair_t *auth_tag_result = BSL_SecOutcome_GetResultAtIndex(outcome, 0); + TEST_ASSERT_EQUAL(1, BSL_SecOper_CountResults(&bcb_test_context.sec_oper)); + const BSL_IdValPair_t *auth_tag_result = + BSL_SecOper_FindResult(&bcb_test_context.sec_oper, RFC9173_BCB_RESULTID_AUTHTAG); + TEST_ASSERT_NOT_NULL(auth_tag_result); // Confirm that AUTHTAG result id is there TEST_ASSERT_EQUAL(RFC9173_BCB_RESULTID_AUTHTAG, auth_tag_result->id); @@ -196,8 +189,6 @@ void test_RFC9173_AppendixA_Example2_BCB_Source(void) BSL_Log_DumpAsHexString(logstr, sizeof(logstr), target_block->btsd, target_block->btsd_len)); TEST_ASSERT_EQUAL_MEMORY(ApxA2_Ciphertext, target_block->btsd, sizeof(ApxA2_Ciphertext)); - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BCBTestContext_Deinit(&bcb_test_context); } @@ -211,18 +202,11 @@ void test_RFC9173_AppendixA_Example2_BCB_Acceptor(void) BCBTestContext_Init(&bcb_test_context); BSL_TestUtils_InitBCB_Appendix2(&bcb_test_context, BSL_SECROLE_ACCEPTOR); - BSL_SecOutcome_t *outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); - BSL_SecOutcome_Init(outcome, &bcb_test_context.sec_oper); - /// Confirm that BCB executes with SUCCESS int bcb_exec_result = BSL_ExecBCBVerifierAcceptor(BSLX_BCB_Execute, &LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, - &bcb_test_context.sec_oper, outcome); + &bcb_test_context.sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, bcb_exec_result); - /// Confirm that running as ACCEPTOR consumes result. - size_t result_count = BSL_SecOutcome_CountResults(outcome); - TEST_ASSERT_EQUAL(0, result_count); - /// Confirm that the target block is decrypted correctly. MockBPA_CanonicalBlock_t **target_ptr = MockBPA_BlockByNum_get(mock_bpa_ctr->bundle->blocks_num, 1); TEST_ASSERT_NOT_NULL(target_ptr); @@ -237,8 +221,6 @@ void test_RFC9173_AppendixA_Example2_BCB_Acceptor(void) BSL_Log_DumpAsHexString(logstr, sizeof(logstr), target_block->btsd, target_block->btsd_len)); TEST_ASSERT_EQUAL_MEMORY(ApxA2_PayloadData, target_block->btsd, sizeof(ApxA2_PayloadData)); - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BCBTestContext_Deinit(&bcb_test_context); } @@ -303,7 +285,6 @@ void test_sec_source_keywrap(bool wrap, bool bib) 0, BSL_TestUtils_LoadBundleFromCBOR(&LocalTestCtx, RFC9173_TestVectors_AppendixA1.hex_bundle_original)); mock_bpa_ctr_t *mock_bpa_ctr = &LocalTestCtx.mock_bpa_ctr; - BSL_SecOutcome_t *sec_outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); const BSL_IdValPair_t *result; BIBTestContext bibcontext; BCBTestContext bcbcontext; @@ -334,14 +315,12 @@ void test_sec_source_keywrap(bool wrap, bool bib) BSL_SecOper_AppendOption(&bibcontext.sec_oper, &bibcontext.opt_test_key); BSL_SecOper_AppendOption(&bibcontext.sec_oper, &bibcontext.opt_use_key_wrap); - BSL_SecOutcome_Init(sec_outcome, &bibcontext.sec_oper); - - int bib_exec_status = - BSLX_BIB_Execute(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, &bibcontext.sec_oper, sec_outcome); + int bib_exec_status = BSLX_BIB_Execute(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, &bibcontext.sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, bib_exec_status); - TEST_ASSERT_EQUAL(1, BSL_SecOutcome_CountResults(sec_outcome)); - result = BSL_SecOutcome_GetResultAtIndex(sec_outcome, 0); + TEST_ASSERT_EQUAL(1, BSL_SecOper_CountResults(&bibcontext.sec_oper)); + result = BSL_SecOper_FindResult(&bibcontext.sec_oper, RFC9173_BIB_RESULTID_HMAC); + TEST_ASSERT_NOT_NULL(result); TEST_ASSERT_EQUAL(RFC9173_BIB_RESULTID_HMAC, result->id); } @@ -370,14 +349,12 @@ void test_sec_source_keywrap(bool wrap, bool bib) BSL_SecOper_AppendOption(&bcbcontext.sec_oper, &bcbcontext.opt_test_key_id); BSL_SecOper_AppendOption(&bcbcontext.sec_oper, &bcbcontext.opt_use_key_wrap); - BSL_SecOutcome_Init(sec_outcome, &bcbcontext.sec_oper); - - int bcb_exec_status = - BSLX_BCB_Execute(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, &bcbcontext.sec_oper, sec_outcome); + int bcb_exec_status = BSLX_BCB_Execute(&LocalTestCtx.bsl, &mock_bpa_ctr->bundle_ref, &bcbcontext.sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, bcb_exec_status); - TEST_ASSERT_EQUAL(1, BSL_SecOutcome_CountResults(sec_outcome)); - result = BSL_SecOutcome_GetResultAtIndex(sec_outcome, 0); + TEST_ASSERT_EQUAL(1, BSL_SecOper_CountResults(&bcbcontext.sec_oper)); + result = BSL_SecOper_FindResult(&bcbcontext.sec_oper, RFC9173_BCB_RESULTID_AUTHTAG); + TEST_ASSERT_NOT_NULL(result); TEST_ASSERT_EQUAL(RFC9173_BCB_RESULTID_AUTHTAG, result->id); } @@ -385,27 +362,26 @@ void test_sec_source_keywrap(bool wrap, bool bib) char logstr[500]; if (wrap) { - int got = 0; - for (size_t i = 0; i < BSL_SecOutcome_CountParams(sec_outcome); i++) + const BSL_IdValPair_t *sec_param; + if (bib) + { + sec_param = BSL_SecOper_FindParam(&bibcontext.sec_oper, RFC9173_BIB_PARAMID_WRAPPED_KEY); + } + else { - const BSL_IdValPair_t *sec_param = BSL_SecOutcome_GetParamAt(sec_outcome, i); - if (sec_param->id == ((bib) ? RFC9173_BIB_PARAMID_WRAPPED_KEY : RFC9173_BCB_SECPARAM_WRAPPEDKEY)) - { - got++; - BSL_LOG_INFO("GOT WRAPPED KEY PARAM:"); - BSL_LOG_INFO( - "EXPECTED wrapped key: %s", - BSL_Log_DumpAsHexString(logstr, sizeof(logstr), wrapped_key_data.ptr, wrapped_key_data.len)); - BSL_Data_t view; - TEST_ASSERT_EQUAL_INT(0, BSL_IdValPair_GetAsBytestr(sec_param, &view)); - BSL_LOG_INFO("ACTUAL wrapped key: %s", - BSL_Log_DumpAsHexString(logstr, sizeof(logstr), view.ptr, view.len)); - TEST_ASSERT_EQUAL(wrapped_key_data.len, view.len); - TEST_ASSERT_EQUAL_MEMORY(wrapped_key_data.ptr, view.ptr, wrapped_key_data.len); - BSL_Data_Deinit(&view); - } + sec_param = BSL_SecOper_FindParam(&bcbcontext.sec_oper, RFC9173_BCB_SECPARAM_WRAPPEDKEY); } - TEST_ASSERT_EQUAL(1, got); + + TEST_ASSERT_NOT_NULL(sec_param); + BSL_LOG_INFO("GOT WRAPPED KEY PARAM:"); + BSL_LOG_INFO("EXPECTED wrapped key: %s", + BSL_Log_DumpAsHexString(logstr, sizeof(logstr), wrapped_key_data.ptr, wrapped_key_data.len)); + BSL_Data_t view; + TEST_ASSERT_EQUAL_INT(0, BSL_IdValPair_GetAsBytestr(sec_param, &view)); + BSL_LOG_INFO("ACTUAL wrapped key: %s", BSL_Log_DumpAsHexString(logstr, sizeof(logstr), view.ptr, view.len)); + TEST_ASSERT_EQUAL(wrapped_key_data.len, view.len); + TEST_ASSERT_EQUAL_MEMORY(wrapped_key_data.ptr, view.ptr, wrapped_key_data.len); + BSL_Data_Deinit(&view); } { @@ -441,13 +417,10 @@ void test_sec_source_keywrap(bool wrap, bool bib) BSL_Data_Deinit(&pt_data); } - BSL_SecOutcome_Deinit(sec_outcome); - BSL_Data_Deinit(&result_data); BSL_Data_Deinit(&cek_data); BSL_Data_Deinit(&kek_data); BSL_Data_Deinit(&wrapped_key_data); - BSL_free(sec_outcome); BIBTestContext_Deinit(&bibcontext); BCBTestContext_Deinit(&bcbcontext); } @@ -504,7 +477,6 @@ void test_sec_accept_keyunwrap(bool bib) } mock_bpa_ctr_t *mock_bpa_ctr = &LocalTestCtx.mock_bpa_ctr; - BSL_SecOutcome_t *sec_outcome = BSL_calloc(1, BSL_SecOutcome_Sizeof()); BIBTestContext bibcontext; BCBTestContext bcbcontext; BIBTestContext_Init(&bibcontext); @@ -524,10 +496,8 @@ void test_sec_accept_keyunwrap(bool bib) BSL_SecOper_AppendOption(&bibcontext.sec_oper, &bibcontext.opt_test_key); BSL_SecOper_AppendOption(&bibcontext.sec_oper, &bibcontext.opt_use_key_wrap); - BSL_SecOutcome_Init(sec_outcome, &bibcontext.sec_oper); - int bib_exec_status = BSL_ExecBIBVerifierAcceptor(BSLX_BIB_Execute, &LocalTestCtx.bsl, - &mock_bpa_ctr->bundle_ref, &bibcontext.sec_oper, sec_outcome); + &mock_bpa_ctr->bundle_ref, &bibcontext.sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, bib_exec_status); } else @@ -547,10 +517,8 @@ void test_sec_accept_keyunwrap(bool bib) BSL_SecOper_AppendOption(&bcbcontext.sec_oper, &bcbcontext.opt_test_key_id); BSL_SecOper_AppendOption(&bcbcontext.sec_oper, &bcbcontext.opt_use_key_wrap); - BSL_SecOutcome_Init(sec_outcome, &bcbcontext.sec_oper); - int bcb_exec_status = BSL_ExecBCBVerifierAcceptor(BSLX_BCB_Execute, &LocalTestCtx.bsl, - &mock_bpa_ctr->bundle_ref, &bcbcontext.sec_oper, sec_outcome); + &mock_bpa_ctr->bundle_ref, &bcbcontext.sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, bcb_exec_status); } @@ -583,10 +551,8 @@ void test_sec_accept_keyunwrap(bool bib) BSL_Data_Deinit(&pt_data); } - BSL_SecOutcome_Deinit(sec_outcome); BSL_Data_Deinit(&kek_data); BSL_Data_Deinit(&result_data); - BSL_free(sec_outcome); BIBTestContext_Deinit(&bibcontext); BCBTestContext_Deinit(&bcbcontext); } From 375429144247752f0a66c7e7da07884112efde0c Mon Sep 17 00:00:00 2001 From: William Fei Date: Wed, 15 Jul 2026 15:13:55 -0400 Subject: [PATCH 3/4] formatting --- src/BPSecLib_Public.h | 15 +++++++-------- src/Data.h | 6 +----- test/test_CoseContext.c | 20 ++++++++++---------- test/test_DefaultSecurityContext.c | 4 ++-- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/BPSecLib_Public.h b/src/BPSecLib_Public.h index dd169432..4b8cfb19 100644 --- a/src/BPSecLib_Public.h +++ b/src/BPSecLib_Public.h @@ -119,11 +119,7 @@ typedef enum BSL_BUNDLECRCTYPE_32 = 2, } BSL_BundleCRCType_e; -#define BSL_TLM_COUNTERS_ZERO \ - (BSL_TlmCounters_t) \ - { \ - 0 \ - } +#define BSL_TLM_COUNTERS_ZERO (BSL_TlmCounters_t) { 0 } /** @brief Defined indices for the counter structure to hold telemetry and counts * @@ -320,9 +316,12 @@ typedef struct } BSL_DynMemHostDescriptors_t; /// Default heap functions from libc -#define BSL_DynMemHostDescriptors_DEFAULT \ - { \ - .malloc_cb = malloc, .realloc_cb = realloc, .calloc_cb = calloc, .free_cb = free, \ +#define BSL_DynMemHostDescriptors_DEFAULT \ + { \ + .malloc_cb = malloc, \ + .realloc_cb = realloc, \ + .calloc_cb = calloc, \ + .free_cb = free, \ } /** Dynamic BPA descriptor. diff --git a/src/Data.h b/src/Data.h index 0b165179..40b6da09 100644 --- a/src/Data.h +++ b/src/Data.h @@ -58,11 +58,7 @@ typedef struct BSL_Data_s /** Static initializer for a data store. * @sa BSL_Data_Init() */ -#define BSL_DATA_INIT_NULL \ - (BSL_Data_t) \ - { \ - .owned = false, .ptr = NULL, .len = 0 \ - } +#define BSL_DATA_INIT_NULL (BSL_Data_t) { .owned = false, .ptr = NULL, .len = 0 } /** Static initializer for a view on a static byte string. * @sa BSL_Data_InitView() diff --git a/test/test_CoseContext.c b/test/test_CoseContext.c index 63cb1d59..624d213f 100644 --- a/test/test_CoseContext.c +++ b/test/test_CoseContext.c @@ -342,8 +342,8 @@ void test_AppendixA_Example1_BIB_Source(void) TEST_ASSERT_TRUE(valid_status); // Confirm running operation as source executes without error - int exec_status = BSL_ExecBIBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, - &sec_oper); + int exec_status = + BSL_ExecBIBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_status); // Confirm it produced only 1 result @@ -626,8 +626,8 @@ void test_CCSDS_Example_Mac_Source(void) TEST_ASSERT_TRUE(valid_status); // Confirm running operation as source executes without error - int exec_status = BSL_ExecBIBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, - &sec_oper); + int exec_status = + BSL_ExecBIBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_status); // Confirm it produced only 1 result @@ -896,8 +896,8 @@ void test_AppendixA_Example4_BCB_Source(void) TEST_ASSERT_TRUE(valid_status); // Confirm running operation as source executes without error - int exec_status = BSL_ExecBCBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, - &sec_oper); + int exec_status = + BSL_ExecBCBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_status); // Confirm it produced only 1 result @@ -1183,8 +1183,8 @@ void test_AppendixA_Example5_BCB_Source(void) TEST_ASSERT_TRUE(valid_status); // Confirm running operation as source executes without error - int exec_status = BSL_ExecBCBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, - &sec_oper); + int exec_status = + BSL_ExecBCBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_status); // Confirm it produced only 1 result @@ -1466,8 +1466,8 @@ void test_AppendixA_Example6_BCB_Source(void) TEST_ASSERT_TRUE(valid_status); // Confirm running operation as source executes without error - int exec_status = BSL_ExecBCBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, - &sec_oper); + int exec_status = + BSL_ExecBCBSource(&BSLX_CoseSc_Execute, &LocalTestCtx.bsl, &LocalTestCtx.mock_bpa_ctr.bundle_ref, &sec_oper); TEST_ASSERT_EQUAL(BSL_SUCCESS, exec_status); // Confirm it produced only 1 result diff --git a/test/test_DefaultSecurityContext.c b/test/test_DefaultSecurityContext.c index 690634d7..4a2a8738 100644 --- a/test/test_DefaultSecurityContext.c +++ b/test/test_DefaultSecurityContext.c @@ -433,8 +433,8 @@ void test_sec_accept_keyunwrap(bool bib) } mock_bpa_ctr_t *mock_bpa_ctr = &LocalTestCtx.mock_bpa_ctr; - BIBTestContext bibcontext; - BCBTestContext bcbcontext; + BIBTestContext bibcontext; + BCBTestContext bcbcontext; BIBTestContext_Init(&bibcontext); BCBTestContext_Init(&bcbcontext); if (bib) From c7c1aa4535c5a9c38af125b92f1fe772768dcaaa Mon Sep 17 00:00:00 2001 From: Brian Sipos Date: Wed, 15 Jul 2026 15:14:06 -0400 Subject: [PATCH 4/4] format on ubuntu --- src/BPSecLib_Private.h | 10 ++++++++-- src/BPSecLib_Public.h | 15 ++++++++------- src/Data.h | 6 +++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/BPSecLib_Private.h b/src/BPSecLib_Private.h index d4219893..05cd9010 100644 --- a/src/BPSecLib_Private.h +++ b/src/BPSecLib_Private.h @@ -293,7 +293,10 @@ int BSL_SeqWriter_Put(BSL_SeqWriter_t *obj, const uint8_t *buf, size_t bufsize); /** Static initializer for an invalid ::BSL_HostEID_t. * Even after this, BSL_HostEID_Init() must be used to get into a valid state. */ -#define BSL_HOSTEID_INIT_INVALID { .handle = NULL } +#define BSL_HOSTEID_INIT_INVALID \ + { \ + .handle = NULL \ + } /** Initialize an abstract EID. * @@ -347,7 +350,10 @@ int BSL_HostEID_EncodeToCBOR(const BSL_HostEID_t *eid, BSL_Data_t *encoded_bytes /** Static initializer for an invalid ::BSL_HostEIDPattern_t. * Even after this, BSL_HostEIDPattern_Init() must be used to get into a valid state. */ -#define BSL_HOSTEID_INIT_INVALID { .handle = NULL } +#define BSL_HOSTEID_INIT_INVALID \ + { \ + .handle = NULL \ + } /** Initialize an abstract EID Pattern. * diff --git a/src/BPSecLib_Public.h b/src/BPSecLib_Public.h index 4b8cfb19..dd169432 100644 --- a/src/BPSecLib_Public.h +++ b/src/BPSecLib_Public.h @@ -119,7 +119,11 @@ typedef enum BSL_BUNDLECRCTYPE_32 = 2, } BSL_BundleCRCType_e; -#define BSL_TLM_COUNTERS_ZERO (BSL_TlmCounters_t) { 0 } +#define BSL_TLM_COUNTERS_ZERO \ + (BSL_TlmCounters_t) \ + { \ + 0 \ + } /** @brief Defined indices for the counter structure to hold telemetry and counts * @@ -316,12 +320,9 @@ typedef struct } BSL_DynMemHostDescriptors_t; /// Default heap functions from libc -#define BSL_DynMemHostDescriptors_DEFAULT \ - { \ - .malloc_cb = malloc, \ - .realloc_cb = realloc, \ - .calloc_cb = calloc, \ - .free_cb = free, \ +#define BSL_DynMemHostDescriptors_DEFAULT \ + { \ + .malloc_cb = malloc, .realloc_cb = realloc, .calloc_cb = calloc, .free_cb = free, \ } /** Dynamic BPA descriptor. diff --git a/src/Data.h b/src/Data.h index 40b6da09..0b165179 100644 --- a/src/Data.h +++ b/src/Data.h @@ -58,7 +58,11 @@ typedef struct BSL_Data_s /** Static initializer for a data store. * @sa BSL_Data_Init() */ -#define BSL_DATA_INIT_NULL (BSL_Data_t) { .owned = false, .ptr = NULL, .len = 0 } +#define BSL_DATA_INIT_NULL \ + (BSL_Data_t) \ + { \ + .owned = false, .ptr = NULL, .len = 0 \ + } /** Static initializer for a view on a static byte string. * @sa BSL_Data_InitView()