diff --git a/src/BPSecLib_Private.h b/src/BPSecLib_Private.h index 24061ecf..05cd9010 100644 --- a/src/BPSecLib_Private.h +++ b/src/BPSecLib_Private.h @@ -808,6 +808,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 @@ -934,75 +970,6 @@ const BSL_IdValPair_t *BSL_AbsSecBlock_FindResult(BSL_AbsSecBlock_t *self, uint6 */ int BSL_TlmCounters_IncrementCounter(BSL_LibCtx_t *bsl, BSL_TlmCounterIndex_e tlm_index, uint64_t count); -/** @brief Represents the output following execution of a security operation. - */ -typedef struct BSL_SecOutcome_s BSL_SecOutcome_t; - -/// @brief Returns the size of the ::BSL_SecOutcome_s structure. -size_t BSL_SecOutcome_Sizeof(void); - -/** Populate a pre-allocated security outcome struct. - * - * @param[in,out] self Non-Null pointer to this security outcome. - * @param[in] sec_oper Security operation containing the necessary info. - */ -void BSL_SecOutcome_Init(BSL_SecOutcome_t *self, const BSL_SecOper_t *sec_oper); - -/** Release any resources owned by this security outcome. - * - * @param[in,out] self Non-Null pointer to this security outcome. - */ -void BSL_SecOutcome_Deinit(BSL_SecOutcome_t *self); - -/** Return true if internal invariants hold - * - * @param[in] self This sec outcome. - * @return true if invariants hold - */ -bool BSL_SecOutcome_IsConsistent(const BSL_SecOutcome_t *self); - -/** Append a Security Result to this outcome. - * - * @param[in,out] self Non-NULL pointer to this security outcome. - * @return Non-NULL pointer to security result just appended. - */ -BSL_IdValPair_t *BSL_SecOutcome_AppendResult(BSL_SecOutcome_t *self); - -/** Get the result at index i. Panics if i is out of range. - * - * @param[in] self This outcome - * @param[in] index Index in the list to retrieve - * @return Sec Result at index - */ -const BSL_IdValPair_t *BSL_SecOutcome_GetResultAtIndex(const BSL_SecOutcome_t *self, size_t index); - -/** Get the number of results - * - * @param[in] self this sec outcome - * @return number of results in sec outcome - */ -size_t BSL_SecOutcome_CountResults(const BSL_SecOutcome_t *self); - -/** Append a Security Parameter to this outcome. - * - * @param[in,out] self Non-NULL pointer to this security outcome. - * @return Non-NULL pointer to the initialized security parameter. - */ -BSL_IdValPair_t *BSL_SecOutcome_AppendParam(BSL_SecOutcome_t *self); - -/** @brief Returns number of parameters in this outcome. - * @param[in] self This outcome - * @return Number of parameters - */ -size_t BSL_SecOutcome_CountParams(const BSL_SecOutcome_t *self); - -/** Get the security parameter from the security outcome at the provided index - * @param[in] self security outcome - * @param[in] index index to retrieve security parameter from - * @return Security parameter - */ -const BSL_IdValPair_t *BSL_SecOutcome_GetParamAt(const BSL_SecOutcome_t *self, size_t index); - /** * @return size of security operation */ @@ -1134,40 +1101,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. @@ -1194,12 +1127,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, @@ -1208,7 +1140,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); @@ -1225,13 +1157,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 * @@ -1258,13 +1189,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) */ @@ -1280,22 +1208,22 @@ 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); /** Internal function to execute an operation as verifier or acceptor. * @overload */ 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); /** Internal function to execute an operation as source. * @overload */ 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); /** Internal function to execute an operation as verifier or acceptor. * @overload */ 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/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 ca162221..580b713c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -147,7 +147,6 @@ set(BSL_DYNAMIC_H ${CMAKE_CURRENT_SOURCE_DIR}/backend/IdValPair.h ${CMAKE_CURRENT_SOURCE_DIR}/backend/PublicInterfaceImpl.h ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecOperation.h - ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityResultSet.h ${CMAKE_CURRENT_SOURCE_DIR}/backend/UtilDefs_SeqReadWrite.h ) @@ -160,11 +159,9 @@ 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 - ${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityResultSet.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/TextUtil.c ${CMAKE_CURRENT_SOURCE_DIR}/backend/UtilDefs_SeqReadWrite.c ) @@ -184,7 +181,7 @@ target_link_libraries(bsl_dynamic PUBLIC qcbor::qcbor) add_library(bsl_mock_bpa) #target_compile_options(bsl_mock_bpa PRIVATE -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls) target_sources( - bsl_mock_bpa PUBLIC + bsl_mock_bpa PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa/log.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa/agent.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa/bundle.h 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/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 8c7b40ff..4d7ad98b 100644 --- a/src/backend/PublicInterfaceImpl.c +++ b/src/backend/PublicInterfaceImpl.c @@ -211,15 +211,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"); @@ -248,7 +246,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/SecOperation.c b/src/backend/SecOperation.c index e621da4c..dfbecc33 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) @@ -58,8 +58,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)); } @@ -67,8 +67,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); } @@ -86,8 +86,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)); } @@ -147,12 +147,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)); @@ -186,7 +217,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; } @@ -194,13 +225,13 @@ size_t BSL_SecOper_ResultCount(const BSL_SecOper_t *self) { ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self)); - return BSLB_IdValPairPtrMap_size(self->_results_in); + return BSLB_IdValPairPtrMap_size(self->_results); } const BSL_IdValPair_t *BSL_SecOper_FindResult(const BSL_SecOper_t *self, int64_t result_id) { 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 485c4d47..0d743e3f 100644 --- a/src/backend/SecOperation.h +++ b/src/backend/SecOperation.h @@ -65,21 +65,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 d0fb40c0..64ee8aa6 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 needed ASB content before an operation. */ static int BSL_ExecAnySource_Pre(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle _U_, BSL_SecOper_t *sec_oper, - BSL_SecOutcome_t *outcome _U_, BSL_AbsSecBlock_t *asb) + BSL_AbsSecBlock_t *asb) { asb->sec_context_id = sec_oper->context_id; @@ -91,7 +90,7 @@ static int BSL_ExecAnySource_Pre(BSL_LibCtx_t *lib _U_, BSL_BundleRef_t *bundle /** Common handling of informing new ASB content after an operation. */ static int BSL_ExecAnySource_Post(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper, - const BSL_SecOutcome_t *outcome, BSL_AbsSecBlock_t *asb) + BSL_AbsSecBlock_t *asb) { // un-reference outside of execution sec_oper->sec_src_eid = NULL; @@ -104,11 +103,11 @@ static int BSL_ExecAnySource_Post(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BS } // 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); } @@ -116,11 +115,11 @@ static int BSL_ExecAnySource_Post(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BS // 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); } @@ -135,12 +134,11 @@ static int BSL_ExecAnySource_Post(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BS } 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); int retval = BSL_SUCCESS; @@ -163,7 +161,7 @@ int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS BSL_AbsSecBlock_Init(&asb); if (BSL_SUCCESS == retval) { - res = BSL_ExecAnySource_Pre(lib, bundle, sec_oper, outcome, &asb); + res = BSL_ExecAnySource_Pre(lib, bundle, sec_oper, &asb); if (BSL_SUCCESS != res) { retval = BSL_ERR_BUNDLE_OPERATION_FAILED; @@ -172,8 +170,8 @@ int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS if (BSL_SUCCESS == retval) { - 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("BIB Source failed!"); retval = BSL_ERR_SECURITY_OPERATION_FAILED; @@ -182,7 +180,7 @@ int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS if (BSL_SUCCESS == retval) { - res = BSL_ExecAnySource_Post(lib, bundle, sec_oper, outcome, &asb); + res = BSL_ExecAnySource_Post(lib, bundle, sec_oper, &asb); if (BSL_SUCCESS != res) { retval = BSL_ERR_SECURITY_OPERATION_FAILED; @@ -246,7 +244,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; @@ -270,7 +268,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 @@ -281,12 +279,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); @@ -299,8 +296,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); @@ -359,12 +356,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); @@ -377,7 +373,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!"); @@ -431,12 +427,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); int retval = BSL_SUCCESS; @@ -459,7 +454,7 @@ int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS BSL_AbsSecBlock_Init(&asb); if (BSL_SUCCESS == retval) { - res = BSL_ExecAnySource_Pre(lib, bundle, sec_oper, outcome, &asb); + res = BSL_ExecAnySource_Pre(lib, bundle, sec_oper, &asb); if (BSL_SUCCESS != res) { retval = BSL_ERR_BUNDLE_OPERATION_FAILED; @@ -468,8 +463,8 @@ int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS if (BSL_SUCCESS == retval) { - 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!"); retval = BSL_ERR_SECURITY_OPERATION_FAILED; @@ -482,7 +477,7 @@ int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS if (BSL_SUCCESS == retval) { - res = BSL_ExecAnySource_Post(lib, bundle, sec_oper, outcome, &asb); + res = BSL_ExecAnySource_Post(lib, bundle, sec_oper, &asb); if (BSL_SUCCESS != res) { retval = BSL_ERR_SECURITY_OPERATION_FAILED; @@ -496,15 +491,14 @@ int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BS } BSL_AbsSecBlock_Deinit(&asb); - return res; + return retval; } -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 @@ -512,12 +506,10 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet /** * 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)) @@ -526,7 +518,7 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet 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; @@ -539,27 +531,25 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet { 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); @@ -569,15 +559,11 @@ 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); - return BSL_SUCCESS; } 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/cose_sc/CoseContext.c b/src/cose_sc/CoseContext.c index d9b8dc6b..65a7bc33 100644 --- a/src/cose_sc/CoseContext.c +++ b/src/cose_sc/CoseContext.c @@ -81,10 +81,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; /// True if this operation is integrity, false for confidentiality bool is_bib; @@ -234,14 +232,12 @@ 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) { int res; 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); @@ -453,7 +449,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) { @@ -1304,7 +1300,7 @@ static void BSLX_CoseSc_AddAadScope(BSLX_CoseSc_t *ctx) // GCOV_EXCL_STOP else { - 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); } @@ -1346,7 +1342,7 @@ static void BSLX_CoseSc_Mac0_Source(BSLX_CoseSc_t *ctx) // GCOV_EXCL_STOP else { - 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); } BSL_Data_Deinit(&msg_enc); @@ -1756,7 +1752,7 @@ static void BSLX_CoseSc_Mac_Source(BSLX_CoseSc_t *ctx) // GCOV_EXCL_STOP else { - BSL_IdValPair_t *result = BSL_SecOutcome_AppendResult(ctx->sec_outcome); + BSL_IdValPair_t *result = BSL_SecOper_AddResult(ctx->sec_oper, BSLX_COSESC_RESULT_COSE_MAC); BSL_IdValPair_SetBytestr(result, BSLX_COSESC_RESULT_COSE_MAC, msg_enc); } BSL_Data_Deinit(&msg_enc); @@ -2247,7 +2243,7 @@ static void BSLX_CoseSc_Encrypt0_Source(BSLX_CoseSc_t *ctx) // GCOV_EXCL_STOP else { - 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); } BSL_Data_Deinit(&msg_enc); @@ -2359,7 +2355,7 @@ static void BSLX_CoseSc_Encrypt_Source(BSLX_CoseSc_t *ctx) // GCOV_EXCL_STOP else { - BSL_IdValPair_t *result = BSL_SecOutcome_AppendResult(ctx->sec_outcome); + BSL_IdValPair_t *result = BSL_SecOper_AddResult(ctx->sec_oper, BSLX_COSESC_RESULT_COSE_ENCRYPT); BSL_IdValPair_SetBytestr(result, BSLX_COSESC_RESULT_COSE_ENCRYPT, msg_enc); } BSL_Data_Deinit(&msg_enc); @@ -2439,12 +2435,11 @@ static void BSLX_CoseSc_Encrypt_VerifyAccept(BSLX_CoseSc_t *ctx, const BSL_IdVal BSLX_CoseMsg_Encrypt_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 31a20dec..27584efb 100644 --- a/src/cose_sc/CoseContext.h +++ b/src/cose_sc/CoseContext.h @@ -161,8 +161,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 fe7711be..716272ce 100644 --- a/src/default_sc/BCB_AES_GCM.c +++ b/src/default_sc/BCB_AES_GCM.c @@ -526,12 +526,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); @@ -703,33 +701,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 b855b6c1..8d643f1f 100644 --- a/src/default_sc/BIB_HMAC_SHA2.c +++ b/src/default_sc/BIB_HMAC_SHA2.c @@ -390,14 +390,11 @@ int BSLX_BIB_GenHMAC(BSLX_BIB_t *self, const BSL_Data_t *ippt_data) return retval; } -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; @@ -532,24 +529,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/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 ec712f33..08d6f33f 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 b3021178..a3aab398 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 399ab2dc..1311dee9 100644 --- a/test/DefaultScUtils.h +++ b/test/DefaultScUtils.h @@ -179,8 +179,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..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; } @@ -157,11 +154,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 +174,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); @@ -191,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 @@ -208,19 +202,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); @@ -233,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) { @@ -255,11 +246,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 +258,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); } @@ -280,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) * @@ -295,13 +283,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 +312,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 +378,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 +458,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 +468,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 +557,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 +573,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 +645,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 +658,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_CoseContext.c b/test/test_CoseContext.c index 57973486..624d213f 100644 --- a/test/test_CoseContext.c +++ b/test/test_CoseContext.c @@ -271,7 +271,7 @@ static const char *exA_1_mac0 = "9f890700028201692f2f6473742f7376638201692f2f737 * - 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) @@ -338,20 +338,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)); @@ -378,8 +375,6 @@ void test_AppendixA_Example1_BIB_Source(void) TEST_ASSERT_EQUAL_size_t(95, stats.stats[BSL_CRYPTO_KEYSTATS_BYTES_PROCESSED]); } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); BSL_Crypto_ReleaseKeyHandle(keyhandle); } @@ -490,9 +485,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); @@ -501,7 +493,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) @@ -528,8 +520,6 @@ void test_AppendixA_Example1_BIB_VerifyAccept(BSL_SecRole_e role, int mismatch) } } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); BSL_Crypto_ReleaseKeyHandle(keyhandle); } @@ -632,20 +622,17 @@ void test_CCSDS_Example_Mac_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_MAC); TEST_ASSERT_NOT_NULL(result); TEST_ASSERT_EQUAL(BSLX_COSESC_RESULT_COSE_MAC, BSL_IdValPair_GetId(result)); TEST_ASSERT_TRUE(BSL_IdValPair_IsBytestr(result)); @@ -672,8 +659,6 @@ void test_CCSDS_Example_Mac_Source(void) TEST_ASSERT_EQUAL_size_t(48, stats.stats[BSL_CRYPTO_KEYSTATS_BYTES_PROCESSED]); } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); BSL_Crypto_ReleaseKeyHandle(keyhandle); } @@ -773,9 +758,6 @@ void test_CCSDS_Example_Mac_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); @@ -784,7 +766,7 @@ void test_CCSDS_Example_Mac_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) @@ -812,8 +794,6 @@ void test_CCSDS_Example_Mac_VerifyAccept(BSL_SecRole_e role, int mismatch) } } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); BSL_Crypto_ReleaseKeyHandle(keyhandle); } @@ -912,20 +892,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)); @@ -953,8 +930,6 @@ void test_AppendixA_Example4_BCB_Source(void) TEST_ASSERT_EQUAL_size_t(98, stats.stats[BSL_CRYPTO_KEYSTATS_BYTES_PROCESSED]); } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); BSL_Crypto_ReleaseKeyHandle(keyhandle); } @@ -1062,9 +1037,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); @@ -1073,7 +1045,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) @@ -1101,8 +1073,6 @@ void test_AppendixA_Example4_BCB_VerifyAccept(BSL_SecRole_e role, int mismatch) } } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); BSL_Crypto_ReleaseKeyHandle(keyhandle); } @@ -1209,20 +1179,17 @@ void test_AppendixA_Example5_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_ENCRYPT); TEST_ASSERT_NOT_NULL(result); TEST_ASSERT_EQUAL(BSLX_COSESC_RESULT_COSE_ENCRYPT, BSL_IdValPair_GetId(result)); TEST_ASSERT_TRUE(BSL_IdValPair_IsBytestr(result)); @@ -1249,8 +1216,6 @@ void test_AppendixA_Example5_BCB_Source(void) TEST_ASSERT_EQUAL_size_t(32, stats.stats[BSL_CRYPTO_KEYSTATS_BYTES_PROCESSED]); } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); BSL_Crypto_ReleaseKeyHandle(keyhandle); } @@ -1350,9 +1315,6 @@ void test_AppendixA_Example5_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); @@ -1361,7 +1323,7 @@ void test_AppendixA_Example5_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) @@ -1389,8 +1351,6 @@ void test_AppendixA_Example5_BCB_VerifyAccept(BSL_SecRole_e role, int mismatch) } } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); BSL_Crypto_ReleaseKeyHandle(keyhandle); } @@ -1502,20 +1462,17 @@ void test_AppendixA_Example6_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_ENCRYPT); TEST_ASSERT_NOT_NULL(result); TEST_ASSERT_EQUAL(BSLX_COSESC_RESULT_COSE_ENCRYPT, BSL_IdValPair_GetId(result)); TEST_ASSERT_TRUE(BSL_IdValPair_IsBytestr(result)); @@ -1542,8 +1499,6 @@ void test_AppendixA_Example6_BCB_Source(void) TEST_ASSERT_EQUAL_size_t(32, stats.stats[BSL_CRYPTO_KEYSTATS_BYTES_PROCESSED]); } - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BSL_SecOper_Deinit(&sec_oper); BSL_Crypto_ReleaseKeyHandle(keyhandle); } diff --git a/test/test_DefaultSecurityContext.c b/test/test_DefaultSecurityContext.c index 665466c4..4a2a8738 100644 --- a/test/test_DefaultSecurityContext.c +++ b/test/test_DefaultSecurityContext.c @@ -86,7 +86,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: @@ -105,17 +105,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); @@ -126,8 +123,6 @@ void test_RFC9173_AppendixA_Example1_BIB_Source(void) TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(RFC9173_TestVectors_AppendixA1.hex_hmac, mac_view)); BSL_Data_Deinit(&mac_view); - BSL_SecOutcome_Deinit(sec_outcome); - BSL_free(sec_outcome); BIBTestContext_Deinit(&bib_test_context); } @@ -145,7 +140,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: @@ -163,17 +158,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); @@ -195,8 +188,6 @@ void test_RFC9173_AppendixA_Example2_BCB_Source(void) TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(ApxA2_Ciphertext, btsd_view)); BSL_Data_Deinit(&btsd_view); - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BCBTestContext_Deinit(&bcb_test_context); } @@ -210,18 +201,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); @@ -232,8 +216,6 @@ void test_RFC9173_AppendixA_Example2_BCB_Acceptor(void) TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(ApxA2_PayloadData, btsd_view)); BSL_Data_Deinit(&btsd_view); - BSL_SecOutcome_Deinit(outcome); - BSL_free(outcome); BCBTestContext_Deinit(&bcb_test_context); } @@ -283,7 +265,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; @@ -314,14 +295,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); } @@ -350,35 +329,33 @@ 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); } 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) { - 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_Data_t view; - TEST_ASSERT_EQUAL_INT(0, BSL_IdValPair_GetAsBytestr(sec_param, &view)); - TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(wrapped_key_hex, view)); - BSL_Data_Deinit(&view); - } + sec_param = BSL_SecOper_FindParam(&bibcontext.sec_oper, RFC9173_BIB_PARAMID_WRAPPED_KEY); } - TEST_ASSERT_EQUAL(1, got); + else + { + sec_param = BSL_SecOper_FindParam(&bcbcontext.sec_oper, RFC9173_BCB_SECPARAM_WRAPPEDKEY); + } + + TEST_ASSERT_NOT_NULL(sec_param); + BSL_Data_t view; + TEST_ASSERT_EQUAL_INT(0, BSL_IdValPair_GetAsBytestr(sec_param, &view)); + TEST_ASSERT_TRUE(BSL_TestUtils_IsB16StrEqualTo(wrapped_key_hex, view)); + BSL_Data_Deinit(&view); } { @@ -402,11 +379,8 @@ void test_sec_source_keywrap(bool wrap, bool bib) BSL_Data_Deinit(&btsd_view); } - BSL_SecOutcome_Deinit(sec_outcome); - BSL_Data_Deinit(&cek_data); BSL_Data_Deinit(&kek_data); - BSL_free(sec_outcome); BIBTestContext_Deinit(&bibcontext); BCBTestContext_Deinit(&bcbcontext); } @@ -459,9 +433,8 @@ 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 bibcontext; + BCBTestContext bcbcontext; BIBTestContext_Init(&bibcontext); BCBTestContext_Init(&bcbcontext); if (bib) @@ -479,10 +452,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 @@ -502,10 +473,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); } @@ -523,10 +492,8 @@ void test_sec_accept_keyunwrap(bool bib) BSL_Data_Deinit(&btsd_view); } - 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); } 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 a0c1bc80..a4fe79af 100644 --- a/test/test_PublicInterfaceImpl.c +++ b/test/test_PublicInterfaceImpl.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -561,10 +560,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; @@ -625,8 +622,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); @@ -702,8 +698,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); @@ -798,8 +793,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); @@ -836,16 +830,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; @@ -869,8 +860,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, @@ -879,16 +869,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; @@ -910,8 +897,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++) @@ -937,6 +923,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); }