Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 46 additions & 118 deletions src/BPSecLib_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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
*
Expand All @@ -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)
*/
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/BPSecLib_Public.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/backend/AbsSecBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/backend/PolicyProvider.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions src/backend/PublicInterfaceImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading