41 CHK_ARG_NONNULL(sec_context_fn);
42 CHK_ARG_NONNULL(bundle);
43 CHK_ARG_NONNULL(sec_oper);
44 CHK_ARG_NONNULL(outcome);
47 uint64_t created_block_id = 0;
51 BSL_LOG_ERR(
"Failed to create BIB block, error=%d", created_result);
55 CHK_PROPERTY(created_block_id > 0);
57 const int bib_result = (*sec_context_fn)(lib, bundle, sec_oper, outcome);
67 BSL_LOG_ERR(
"Could not get BIB block (id=%lu)", created_block_id);
76 BSL_LOG_ERR(
"Could not get local security source EID");
83 size_t n_results = BSL_SecOutcome_CountResults(outcome);
84 for (
size_t index = 0; index < n_results; index++)
89 size_t n_params = BSL_SecOutcome_CountParams(outcome);
90 for (
size_t index = 0; index < n_params; index++)
98 BSL_LOG_ERR(
"Failed to prealloc sufficient BTSD space for ASB");
104 BSL_LOG_ERR(
"Could not get BIB block (id=%lu)", created_block_id);
108 CHK_PROPERTY(sec_blk.
btsd != NULL);
129 BSL_LOG_ERR(
"Could not get BIB block (id=%lu)", created_block_id);
133 CHK_POSTCONDITION(sec_blk.
btsd != NULL);
134 CHK_POSTCONDITION(sec_blk.
btsd_len == (
size_t)encode_result);
141 CHK_ARG_NONNULL(lib);
142 CHK_ARG_NONNULL(bundle);
144 CHK_PRECONDITION(BSL_SecOutcome_IsConsistent(outcome));
166 for (
size_t i = 0; i < BSLB_SecParamList_size(abs_sec_block.params); i++)
168 const BSL_SecParam_t *param = BSLB_SecParamList_cget(abs_sec_block.params, i);
170 BSLB_SecParamList_push_back(sec_oper->_param_list, *param);
173 const int sec_context_result = (*sec_context_fn)(lib, bundle, sec_oper, outcome);
181 bool auth_success = BSL_SecOutcome_IsInAbsSecBlock(outcome, &abs_sec_block);
205 BSL_LOG_ERR(
"Failed to remove block when ASB is empty");
222 BSL_LOG_ERR(
"Failed to re-encode ASB into sec block BTSD");
254 CHK_ARG_NONNULL(sec_context_fn);
255 CHK_ARG_NONNULL(bundle);
256 CHK_ARG_NONNULL(sec_oper);
257 CHK_ARG_NONNULL(outcome);
279 for (
size_t i = 0; i < BSLB_SecParamList_size(abs_sec_block.params); i++)
281 const BSL_SecParam_t *param = BSLB_SecParamList_cget(abs_sec_block.params, i);
283 BSLB_SecParamList_push_back(sec_oper->_param_list, *param);
286 const size_t result_count = BSLB_SecResultList_size(abs_sec_block.results);
288 for (
size_t i = 0; i < result_count; i++)
290 BSL_SecResult_t *result = BSLB_SecResultList_get(abs_sec_block.results, i);
297 BSLB_SecParamList_push_back(sec_oper->_param_list, *result_param);
301 const int sec_context_result = (*sec_context_fn)(lib, bundle, sec_oper, outcome);
327 BSL_LOG_ERR(
"Failed to remove block when ASB is empty");
344 BSL_LOG_ERR(
"Failed to re-encode ASB into sec block BTSD");
367 CHK_ARG_NONNULL(sec_context_fn);
368 CHK_ARG_NONNULL(bundle);
369 CHK_ARG_NONNULL(sec_oper);
370 CHK_ARG_NONNULL(outcome);
381 const int res = (*sec_context_fn)(lib, bundle, sec_oper, outcome);
421 size_t n_results = BSL_SecOutcome_CountResults(outcome);
422 for (
size_t index = 0; index < n_results; index++)
424 const BSL_SecResult_t *result_ptr = BSL_SecOutcome_GetResultAtIndex(outcome, index);
428 size_t n_params = BSL_SecOutcome_CountParams(outcome);
429 for (
size_t index = 0; index < n_params; index++)
431 const BSL_SecParam_t *param_ptr = BSL_SecOutcome_GetParamAt(outcome, index);
436 const size_t est_btsd_size = 500 + ((n_params + n_results) * 100);
439 BSL_LOG_ERR(
"Failed to allocate space for ASB in BTSD");
451 ASSERT_PROPERTY(sec_blk.
btsd != NULL);
452 ASSERT_PROPERTY(sec_blk.
btsd_len > 0);
456 if (encode_result <= 0)
467 BSL_LOG_ERR(
"Failed to allocate space for ASB in BTSD");
477 CHK_ARG_NONNULL(lib);
478 CHK_ARG_NONNULL(output_response);
479 CHK_ARG_NONNULL(bundle);
491 size_t fail_count = 0;
495 memset(outcome, 0, BSL_SecOutcome_Sizeof());
499 ASSERT_PROPERTY(sec_ctx != NULL);
502 BSL_SecOutcome_Init(outcome, sec_oper, 100000);
508 ? BSL_ExecBIBSource(sec_ctx->
execute, lib, bundle, sec_oper, outcome)
509 : BSL_ExecBIBAccept(sec_ctx->
execute, lib, bundle, sec_oper, outcome);
515 errcode = BSL_ExecBCBSource(sec_ctx->
execute, lib, bundle, sec_oper, outcome);
519 errcode = BSL_ExecBCBAcceptor(sec_ctx->
execute, lib, bundle, sec_oper, outcome);
523 BSL_SecOutcome_Deinit(outcome);
529 output_response->
results[sec_oper_index] = -1;
535 output_response->failure_count = fail_count;
Concrete implementation of ASB and its functionality.
Single entry-point include file for all of the BPSec Lib (BSL) frontend API.
@ BSL_SECBLOCKTYPE_BIB
RFC9172 code for BIB.
@ BSL_SECBLOCKTYPE_BCB
RFC9172 code for BCB.
void BSL_AbsSecBlock_Deinit(BSL_AbsSecBlock_t *self)
Deinitializes and clears this ASB, clearing and releasing any owned memory.
void BSL_AbsSecBlock_AddResult(BSL_AbsSecBlock_t *self, const BSL_SecResult_t *result)
Add a security result to this security block (does NOT copy)
#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.
void BSL_AbsSecBlock_AddTarget(BSL_AbsSecBlock_t *self, uint64_t target_block_id)
Adds a given block ID as a security target covered by this ASB.
int BSL_AbsSecBlock_StripResults(BSL_AbsSecBlock_t *self, uint64_t target_block_num)
Remove security parameters and results found in outcome from this ASB.
void BSL_AbsSecBlock_Init(BSL_AbsSecBlock_t *self, uint64_t sec_context_id, BSL_HostEID_t source_eid)
Populate a pre-allocated Absract Security Block.
void BSL_AbsSecBlock_InitEmpty(BSL_AbsSecBlock_t *self)
Initialize a pre-allocated ASB with no contents.
int BSL_AbsSecBlock_DecodeFromCBOR(BSL_AbsSecBlock_t *self, BSL_Data_t encoded_cbor)
Decodes and populates this ASB from a CBOR string.
bool BSL_AbsSecBlock_IsEmpty(const BSL_AbsSecBlock_t *self)
Returns true if this ASB contains nothing (i.e., no tarets, params and results)
size_t BSL_AbsSecBlock_Sizeof(void)
Returns the size of the AbsSecBlock struct in bytes.
int BSL_AbsSecBlock_EncodeToCBOR(const BSL_AbsSecBlock_t *self, BSL_Data_t allocated_target)
Encodes this ASB into a CBOR string into the space pre-allocated indicated by the argument.
int(* BSL_SecCtx_Execute_f)(BSL_LibCtx_t *lib, const BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *sec_outcome)
Signature for Security Context executor for a sec OP.
void BSL_AbsSecBlock_AddParam(BSL_AbsSecBlock_t *self, const BSL_SecParam_t *param)
Add a security parameter to this security block (does NOT copy)
#define BSL_LOG_ERR(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool BSL_AbsSecBlock_IsConsistent(const BSL_AbsSecBlock_t *self)
Checks internal consistency and sanity of this structure.
@ BSL_ERR_SECURITY_CONTEXT_PARTIAL_FAIL
General code where at least some security operations failed.
@ BSL_ERR_ENCODING
CBOR encoding failure.
@ BSL_ERR_DECODING
CBOR decoding failure.
@ BSL_ERR_SECURITY_OPERATION_FAILED
Security operation failed (e.g., BIB did not have enough parameters)
@ BSL_SUCCESS
Placeholder for non-error code.
@ BSL_ERR_HOST_CALLBACK_FAILED
Callback to the host BPA returned a non-zero code.
@ BSL_ERR_BUNDLE_OPERATION_FAILED
Bundle manipulation failed (add/remove or change BTSD)
@ BSL_ERR_FAILURE
Uncategorized failed (prefer to avoid)
int BSL_BundleCtx_CreateBlock(BSL_BundleRef_t *bundle, uint64_t block_type_code, uint64_t *block_num)
Request the creation of a new block of a given type in the bundle.
int BSL_Host_GetSecSrcEID(BSL_HostEID_t *eid)
Get the local EID used when this node is a security source.
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_HostEID_Init(BSL_HostEID_t *eid)
Initialize an abstract EID.
int BSL_BundleCtx_ReallocBTSD(BSL_BundleRef_t *bundle, uint64_t block_num, size_t bytesize)
Requests the re-allocation of a block's BTSD, useful for BCB.
int BSL_BundleCtx_RemoveBlock(BSL_BundleRef_t *bundle, uint64_t block_num)
Requests the removal of a block from a bundle.
Private interface for the dynamic backend library context.
bool BSL_SecOper_IsBIB(const BSL_SecOper_t *self)
Return true if this security operation is BIB.
uint64_t BSL_SecOper_GetTargetBlockNum(const BSL_SecOper_t *self)
Get the block number of the target block covered by this security operation.
bool BSL_SecOper_IsRoleSource(const BSL_SecOper_t *self)
Return true if this security operation's role is SOURCE.
bool BSL_SecOper_IsConsistent(const BSL_SecOper_t *self)
Returns true if internal consistency and sanity checks pass.
bool BSL_SecOper_IsRoleAccepter(const BSL_SecOper_t *self)
Return true if this security operation's role is Acceptor.
Defines a security operation.
int BSL_SecParam_InitBytestr(BSL_SecParam_t *self, uint64_t param_id, BSL_Data_t value)
Initialize as a parameter containing a bytestring.
size_t BSL_SecParam_Sizeof(void)
Return size of BSL_SecParam_t struct type.
bool BSL_SecParam_IsConsistent(const BSL_SecParam_t *self)
Return true if invariant conditions pass.
bool BSL_SecResult_IsConsistent(const BSL_SecResult_t *self)
Return true when internal invariant checks pass.
const BSL_SecOper_t * BSL_SecurityActionSet_GetSecOperAtIndex(const BSL_SecurityActionSet_t *self, size_t index)
Returns the Security Operation at the given index.
bool BSL_SecurityActionSet_IsConsistent(const BSL_SecurityActionSet_t *self)
Return true if internal sanity and consistency checks pass.
size_t BSL_SecurityActionSet_CountSecOpers(const BSL_SecurityActionSet_t *self)
Count number of security operations present in this policy action set.
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.
void BSL_SecurityResponseSet_Init(BSL_SecurityResponseSet_t *self, size_t noperations, size_t nfailed)
Initialize with the given count of operations and nailures.
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.
Heap data storage and views.
BSL_DataPtr_t ptr
Pointer to the front of the buffer.
Opaque pointer to BPA-specific Endpoint ID storage.
Concrete definition of library context.
Security Context descriptor (interface)
BSL_SecCtx_Execute_f execute
Callback to execute a sec op within a given bundle.
uint64_t context_id
Security context ID.
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.
uint8_t _bytes[BSL_DEFAULT_BYTESTR_LEN+1]
Result as byte array, up to a given maximum.
uint64_t target_block_num
Target block id, put in here for convenience.
size_t _bytelen
Length of data (in bytes) of the contained bytestring. Always less than BSL_DEFAULT_BYTESTR_LEN.
Contains the populated security operations for this bundle.
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...