41 BSL_SecCtxDict_init(lib->sc_reg);
49 if (lib->policy_registry.
deinit_fn != NULL)
52 (lib->policy_registry.
deinit_fn)(lib->policy_registry.user_data);
55 free(lib->policy_registry.user_data);
62 BSL_SecCtxDict_clear(lib->sc_reg);
70 CHK_ARG_EXPR(desc.
execute != NULL);
72 BSL_SecCtxDict_set_at(lib->sc_reg, sec_ctx_id, desc);
81 lib->policy_registry = desc;
89 CHK_ARG_NONNULL(output_action_set);
90 CHK_ARG_NONNULL(bundle);
92 CHK_PRECONDITION(bsl->policy_registry.
query_fn != NULL);
93 CHK_PRECONDITION(bsl->policy_registry.
deinit_fn != NULL);
95 BSL_LOG_INFO(
"Querying policy provider for security actions...");
97 if (bsl->policy_registry.
query_fn != NULL)
100 bsl->policy_registry.
query_fn(bsl->policy_registry.user_data, output_action_set, bundle, location);
101 BSL_LOG_INFO(
"Completed query: status=%d", query_status);
125 size_t total_blocks = 0;
132 CHK_PROPERTY(total_blocks == primary_block.
block_count);
134 for (
size_t i = 0; i < total_blocks; i++)
142 for (
size_t sec_op_index = 0; sec_op_index < output_action_set->
sec_operations_count; sec_op_index++)
145 if (block.
type_code != sec_oper->_service_type)
181 CHK_ARG_NONNULL(bsl);
182 CHK_ARG_NONNULL(response_output);
183 CHK_ARG_NONNULL(bundle);
184 CHK_ARG_NONNULL(policy_actions);
189 BSL_LOG_ERR(
"Failed to execute policy action set");
202 bool must_drop =
false;
206 int block_err_code = response_output->
results[oper_index];
212 BSL_LOG_DEBUG(
"Security operation [%lu] success, target block num = %lu", oper_index,
218 switch (err_action_code)
223 BSL_LOG_WARNING(
"Instructed to do nothing for failed security operation");
229 BSL_LOG_WARNING(
"***** Dropping block over which security operation failed *******");
235 BSL_LOG_WARNING(
"Dropping bundle due to block target num %lu security failure",
243 BSL_LOG_ERR(
"Unhandled policy action: %lu", err_action_code);
255 BSL_LOG_ERR(
"TODO Drop bundle using host interface");
Single entry-point include file for all of the BPSec Lib (BSL) frontend API.
#define BSL_LOG_DEBUG(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool BSL_AbsSecBlock_ContainsTarget(const BSL_AbsSecBlock_t *self, uint64_t target_block_num)
Returns true if a given ASB contains the given block number as a security target.
void BSL_AbsSecBlock_Deinit(BSL_AbsSecBlock_t *self)
Deinitializes and clears this ASB, clearing and releasing any owned memory.
BSL_PolicyAction_e
Codes indicating the fate of a block if a security operation over it fails.
@ BSL_POLICYACTION_UNDEFINED
Placeholder for zero - should never occur.
@ BSL_POLICYACTION_DROP_BUNDLE
Drop the entire bundle.
@ BSL_POLICYACTION_NOTHING
Do nothing, keep the block even if it fails.
@ BSL_POLICYACTION_DROP_BLOCK
Drop on the target block.
#define BSL_LOG_INFO(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
struct BSL_AbsSecBlock_s BSL_AbsSecBlock_t
Forward declaration of BSL_AbsSecBlock_t.
#define BSL_LOG_WARNING(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
int BSL_AbsSecBlock_DecodeFromCBOR(BSL_AbsSecBlock_t *self, BSL_Data_t encoded_cbor)
Decodes and populates this ASB from a CBOR string.
size_t BSL_AbsSecBlock_Sizeof(void)
Returns the size of the AbsSecBlock struct in bytes.
#define BSL_LOG_ERR(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
@ BSL_ERR_SECURITY_OPERATION_FAILED
Security operation failed (e.g., BIB did not have enough parameters)
@ BSL_ERR_NOT_FOUND
Requested value not found for key.
@ BSL_SUCCESS
Placeholder for non-error code.
@ BSL_ERR_SECURITY_CONTEXT_VALIDATION_FAILED
Indicates an HMAC signature did not match.
@ BSL_ERR_HOST_CALLBACK_FAILED
Callback to the host BPA returned a non-zero code.
Single entry-point include file for all of the "Public" BPSec Lib (BSL) frontend API.
BSL_PolicyLocation_e
Indicates where in the lifecycle of the BPA the bundle is querying for security policy.
int BSL_BundleCtx_GetBlockIds(const BSL_BundleRef_t *bundle, size_t array_count, uint64_t block_ids_array[array_count], size_t *result_count)
Returns an array in which each element contains the id of the corresponding block....
int BSL_BundleCtx_GetBlockMetadata(const BSL_BundleRef_t *bundle, uint64_t block_num, BSL_CanonicalBlock_t *result_block)
Returns information about the bundle Canonical block.
int BSL_BundleCtx_RemoveBlock(BSL_BundleRef_t *bundle, uint64_t block_num)
Requests the removal of a block from a bundle.
int BSL_BundleCtx_GetBundleMetadata(const BSL_BundleRef_t *bundle, BSL_PrimaryBlock_t *result_primary_block)
Calls the host interface to get a bundle primary block information.abort.
int BSL_API_InitLib(BSL_LibCtx_t *lib)
Initialize the BPSecLib (BSL) library context.
int BSL_API_QuerySecurity(const BSL_LibCtx_t *bsl, BSL_SecurityActionSet_t *output_action_set, const BSL_BundleRef_t *bundle, BSL_PolicyLocation_e location)
Query BSL to populate a BSL_SecurityActionSet_t containg security processing instructions.
int BSL_API_RegisterPolicyProvider(BSL_LibCtx_t *lib, BSL_PolicyDesc_t desc)
Register a Policy Provider module with the BSL.
int BSL_API_RegisterSecurityContext(BSL_LibCtx_t *lib, uint64_t sec_ctx_id, BSL_SecCtxDesc_t desc)
Register a security context module with the BSL.
int BSL_API_ApplySecurity(const BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *response_output, BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *policy_actions)
Performs the given security operations on a Bundle, modifying or even dropping it entirely.
int BSL_API_DeinitLib(BSL_LibCtx_t *lib)
Deinitialize and release any resources held by the BSL.
Private interface for the dynamic backend library context.
Implementation of construct holding details of security operations for a bundle.
bool BSL_SecCtx_ValidatePolicyActionSet(BSL_LibCtx_t *lib, const BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *action_set)
int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet_t *output_response, BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *action_set)
Call the underying security context to perform the given action.
SecurityResultSet implementation for result after application of security operations.
int BSL_Data_InitView(BSL_Data_t *data, size_t len, const BSL_DataPtr_t src)
Initialize a data struct as an overlay on optional external data.
Reference to a Bundle owned and stored in the host BPA.
Structure containing parsed Canonical Block fields.
uint64_t block_num
CBOR-decoded block number (should always be > 0)
void * btsd
Pointer to BTSD owned by the host BPA.
size_t btsd_len
Length in bytes of the BTSD pointer.
uint64_t type_code
CBOR-decoded block type code (should be > 0)
Heap data storage and views.
Concrete definition of library context.
Descriptor of opaque data and callbacks for Policy Provider.
BSL_PolicyInspect_f query_fn
Function pointer to query policy.
BSL_PolicyDeinit_f deinit_fn
Function to deinit the policy provider at termination of BPA.
Contains Bundle Primary Block fields and metadata.
size_t block_count
Helpful count of total canonical blocks in bundle, not a field of the header.
Security Context descriptor (interface)
BSL_SecCtx_Execute_f execute
Callback to execute a sec op within a given bundle.
BSL_SecCtx_Validate_f validate
Callback to validate a sec op within a given bundle.
uint64_t target_block_num
Bundle's block ID over which the security operation is applied.
uint64_t sec_block_num
Bundle's block ID which contains the security parameters and results for this operation.
BSL_PolicyAction_e failure_code
Code for handing what to do to the block or bundle if security processing fails.
Contains the populated security operations for this bundle.
BSL_SecOper_t sec_operations[BSL_SECURITYACTIONSET_MAX_OPS]
Fixed array of security operations (for simpler mem management)
size_t sec_operations_count
Count of sec_operations.
Contains the results and outcomes after performing the security operations.
int results[BSL_SECURITYRESPONSESET_ARRAYLEN]
This maps to the sec_operations in BSL_SecurityActionSet, and contains the result code of that securi...