BSL v1.0.0 - 16.g9d98179
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
AbsSecBlock.c File Reference

Concrete implementation of the Abstract Security Block defined in RFC 9172. More...

#include <qcbor/qcbor_encode.h>
#include <qcbor/qcbor_spiffy_decode.h>
#include <BPSecLib_Private.h>
#include "AbsSecBlock.h"
+ Include dependency graph for AbsSecBlock.c:

Functions

size_t BSL_AbsSecBlock_Sizeof (void)
 Returns the size of the ::BSL_AbsSecBlock_t struct in bytes.
 
bool BSL_AbsSecBlock_IsConsistent (const BSL_AbsSecBlock_t *self)
 Checks internal consistency and sanity of this structure.
 
void BSL_AbsSecBlock_Print (const BSL_AbsSecBlock_t *self)
 Prints to LOG INFO.
 
void BSL_AbsSecBlock_InitEmpty (BSL_AbsSecBlock_t *self)
 Initialize a pre-allocated ASB with no contents.
 
void BSL_AbsSecBlock_Init (BSL_AbsSecBlock_t *self, int64_t sec_context_id, BSL_HostEID_t source_eid)
 Populate a pre-allocated Abstract Security Block.
 
void BSL_AbsSecBlock_Deinit (BSL_AbsSecBlock_t *self)
 Deinitializes and clears this ASB, clearing and releasing any owned memory.
 
bool BSL_AbsSecBlock_IsEmpty (const BSL_AbsSecBlock_t *self)
 Returns true if this ASB contains nothing (i.e., no targets, params and results)
 
int64_t BSL_AbsSecBlock_GetContextID (const BSL_AbsSecBlock_t *self)
 Get the security context ID from a security block.
 
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_AddTarget (BSL_AbsSecBlock_t *self, uint64_t target_block_id)
 Adds a given block ID as a security target covered by this ASB.
 
void BSL_AbsSecBlock_AddParam (BSL_AbsSecBlock_t *self, const BSL_SecParam_t *param)
 Add a security parameter to this security block (does NOT copy)
 
void BSL_AbsSecBlock_AddResult (BSL_AbsSecBlock_t *self, const BSL_SecResult_t *result)
 Add a security result to this security block (does NOT copy)
 
static size_t BSL_AbsSecBlock_GetResultCnt (const BSL_AbsSecBlock_t *self, uint64_t target_block_id)
 
int BSL_AbsSecBlock_StripResults (BSL_AbsSecBlock_t *self, uint64_t target_block_num)
 Remove security parameters and results found in outcome from this ASB.
 
ssize_t BSL_AbsSecBlock_EncodeToCBOR (const BSL_AbsSecBlock_t *self, BSL_Data_t *buf)
 Encodes this ASB into a CBOR string into the space pre-allocated indicated by the argument.
 
int BSL_AbsSecBlock_DecodeFromCBOR (BSL_AbsSecBlock_t *self, const BSL_Data_t *buf)
 Decodes and populates this ASB from a CBOR string.
 

Detailed Description

Concrete implementation of the Abstract Security Block defined in RFC 9172.

Function Documentation

◆ BSL_AbsSecBlock_AddParam()

void BSL_AbsSecBlock_AddParam ( BSL_AbsSecBlock_t *  self,
const BSL_SecParam_t *  param 
)

Add a security parameter to this security block (does NOT copy)

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis security block
[in]paramNon-Null Security parameter pointer to copy into list

References ASSERT_ARG_NONNULL, ASSERT_POSTCONDITION, ASSERT_PRECONDITION, and BSL_AbsSecBlock_IsConsistent().

Referenced by BSL_ExecBCBSource(), and BSL_ExecBIBSource().

◆ BSL_AbsSecBlock_AddResult()

void BSL_AbsSecBlock_AddResult ( BSL_AbsSecBlock_t *  self,
const BSL_SecResult_t *  out 
)

Add a security result to this security block (does NOT copy)

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis security block
[in]resultNon-Null Security result pointer to copy into list

References ASSERT_ARG_NONNULL, ASSERT_POSTCONDITION, ASSERT_PRECONDITION, and BSL_AbsSecBlock_IsConsistent().

Referenced by BSL_ExecBCBSource(), and BSL_ExecBIBSource().

◆ BSL_AbsSecBlock_AddTarget()

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.

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis ASB.
[in]target_block_idID of a block, 0 indicates primary block as usual.

References ASSERT_POSTCONDITION, ASSERT_PRECONDITION, and BSL_AbsSecBlock_IsConsistent().

Referenced by BSL_ExecBCBSource(), and BSL_ExecBIBSource().

◆ BSL_AbsSecBlock_ContainsTarget()

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.

Parameters
[in]selfThis ASB.
[in]target_block_numID of a block, 0 indicates primary block
Returns
true if ASB contains target

References ASSERT_PRECONDITION, and BSL_AbsSecBlock_IsConsistent().

Referenced by BSL_API_QuerySecurity(), and TestASBDecodeEncodeClosure().

◆ BSL_AbsSecBlock_DecodeFromCBOR()

int BSL_AbsSecBlock_DecodeFromCBOR ( BSL_AbsSecBlock_t *  self,
const BSL_Data_t buf 
)

◆ BSL_AbsSecBlock_Deinit()

void BSL_AbsSecBlock_Deinit ( BSL_AbsSecBlock_t *  self)

Deinitializes and clears this ASB, clearing and releasing any owned memory.

Parameters
[in,out]selfThis ASB

References ASSERT_PRECONDITION, BSL_AbsSecBlock_IsConsistent(), and BSL_HostEID_Deinit().

Referenced by BSL_API_QuerySecurity(), BSL_ExecBCBAcceptor(), BSL_ExecBCBSource(), BSL_ExecBIBAccept(), BSL_ExecBIBSource(), LLVMFuzzerTestOneInput(), TEST_CASE(), and TestASBDecodeEncodeClosure().

◆ BSL_AbsSecBlock_EncodeToCBOR()

ssize_t BSL_AbsSecBlock_EncodeToCBOR ( const BSL_AbsSecBlock_t *  self,
BSL_Data_t buf 
)

Encodes this ASB into a CBOR string into the space pre-allocated indicated by the argument.

Parameters
[in]selfThis ASB.
[in]bufA buffer with allocated space for the encoded CBOR or a zero-length buffer to calculate the needed size.
Returns
Integer contains number of bytes written to buffer, negative indicates error.

References BSL_AbsSecBlock_IsConsistent(), BSL_Data_Deinit(), BSL_Data_InitBuffer(), BSL_ERR_ENCODING, BSL_HostEID_EncodeToCBOR(), BSL_LOG_DEBUG, BSL_LOG_ERR, BSL_SecParam_GetAsBytestr(), BSL_SecParam_GetAsUInt64(), BSL_SecParam_GetId(), BSL_SecParam_IsBytestr(), BSL_SecParam_IsInt64(), BSL_SecResult_GetAsBytestr(), BSL_SUCCESS, buf, CHK_PRECONDITION, encoder, BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by Encode_ASB(), LLVMFuzzerTestOneInput(), and TestASBDecodeEncodeClosure().

◆ BSL_AbsSecBlock_GetContextID()

int64_t BSL_AbsSecBlock_GetContextID ( const BSL_AbsSecBlock_t *  self)

Get the security context ID from a security block.

Parameters
[in]selfThis ASB.
Returns
The context ID integer.

References ASSERT_ARG_NONNULL.

Referenced by TestASBDecodeEncodeClosure().

◆ BSL_AbsSecBlock_GetResultCnt()

static size_t BSL_AbsSecBlock_GetResultCnt ( const BSL_AbsSecBlock_t *  self,
uint64_t  target_block_id 
)
static

◆ BSL_AbsSecBlock_Init()

void BSL_AbsSecBlock_Init ( BSL_AbsSecBlock_t *  self,
int64_t  sec_context_id,
BSL_HostEID_t  source_eid 
)

Populate a pre-allocated Abstract Security Block.

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis ASB
[in]sec_context_idSecurity Context ID
[in]source_eidSource EID in format native to host BPA.

References ASSERT_ARG_NONNULL, ASSERT_POSTCONDITION, and BSL_AbsSecBlock_IsConsistent().

Referenced by BSL_ExecBCBSource(), and BSL_ExecBIBSource().

◆ BSL_AbsSecBlock_InitEmpty()

void BSL_AbsSecBlock_InitEmpty ( BSL_AbsSecBlock_t *  self)

Initialize a pre-allocated ASB with no contents.

Parameters
[in,out]selfThis ASB

References ASSERT_ARG_NONNULL.

Referenced by BSL_API_QuerySecurity(), BSL_ExecBCBAcceptor(), BSL_ExecBIBAccept(), LLVMFuzzerTestOneInput(), TEST_CASE(), and TestASBDecodeEncodeClosure().

◆ BSL_AbsSecBlock_IsConsistent()

◆ BSL_AbsSecBlock_IsEmpty()

bool BSL_AbsSecBlock_IsEmpty ( const BSL_AbsSecBlock_t *  self)

Returns true if this ASB contains nothing (i.e., no targets, params and results)

Parameters
[in]selfThis ASB.
Returns
true if ASB is empty

References ASSERT_ARG_NONNULL.

Referenced by BSL_ExecBCBAcceptor(), and BSL_ExecBIBAccept().

◆ BSL_AbsSecBlock_Print()

void BSL_AbsSecBlock_Print ( const BSL_AbsSecBlock_t *  self)

Prints to LOG INFO.

Todo:
  • Can be backend-only.
Parameters
[in]selfThis ASB
Todo:
Refactor to dump this to a pre-allocated string.

References BSL_Log_DumpAsHexString(), BSL_LOG_INFO, BSL_SecParam_IsBytestr(), and BSL_SecParam_IsInt64().

Referenced by BSL_AbsSecBlock_ContainsResult().

◆ BSL_AbsSecBlock_Sizeof()

size_t BSL_AbsSecBlock_Sizeof ( void  )

Returns the size of the ::BSL_AbsSecBlock_t struct in bytes.

Returns
size of the struct

Referenced by BSL_API_QuerySecurity(), LLVMFuzzerTestOneInput(), TEST_CASE(), and TestASBDecodeEncodeClosure().

◆ BSL_AbsSecBlock_StripResults()

int BSL_AbsSecBlock_StripResults ( BSL_AbsSecBlock_t *  self,
uint64_t  target_block_num 
)

Remove security parameters and results found in outcome from this ASB.

Todo:
  • Can be backend-only.
Parameters
[in,out]selfThis ASB
[in]outcomeSecurity Operation outcome containing params and results
Returns
Negative on error, otherwise count of things removed.

References ASSERT_PROPERTY, BSL_AbsSecBlock_GetResultCnt(), BSL_AbsSecBlock_IsConsistent(), BSL_ERR_PROPERTY_CHECK_FAILED, BSL_LOG_ERR, CHK_POSTCONDITION, and CHK_PRECONDITION.

Referenced by BSL_ExecBCBAcceptor(), and BSL_ExecBIBAccept().