BSL v1.0.0 - 16.g9d98179
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
bsl_test_utils.h File Reference
#include <m-string.h>
#include <backend/PublicInterfaceImpl.h>
#include <backend/SecOperation.h>
#include <backend/SecParam.h>
#include <backend/SecResult.h>
#include <backend/SecurityActionSet.h>
#include <mock_bpa/ctr.h>
+ Include dependency graph for bsl_test_utils.h:
+ This graph shows which files directly or indirectly include this file:

Data Structures

struct  BIBTestContext
 
struct  BCBTestContext
 
struct  RFC9173_TestVectors_AppendixA1
 Hard-coded single struct with fields populated from test vector in Appendix A1 for BIB. More...
 
struct  RFC9173_TestVectorsA2
 
struct  RFC9173_TestVectors_A4_Modified
 
struct  RFC9173_A1_Params
 
struct  RFC9173_AppendixA2_BCB
 
struct  BSL_TestContext_t
 

Macros

#define TEST_CASE(...)
 
#define TEST_RANGE(...)
 
#define TEST_MATRIX(...)
 
#define RFC9173_EXAMPLE_A1_KEY   "9100"
 Key ID for the Appendix A1 key in OpenSSL.
 
#define RFC9173_EXAMPLE_A2_KEY   "9102"
 Key ID for the Appendix A2 key in OpenSSL.
 
#define RFC9173_EXAMPLE_A3_KEY   "9103"
 Key ID for the Appendix A3 key in OpenSSL.
 
#define RFC9173_EXAMPLE_A4_BCB_KEY   "9104"
 Key ID for the Appendix A4 key in OpenSSL.
 
#define BSL_SAMPLE_PP_ID   1
 Sample policy provider ID.
 
#define BSL_SAMPLE_PP_ID_2   2
 
#define quick_data_t(field, tgt)
 

Functions

void BIBTestContext_Init (BIBTestContext *obj)
 
void BIBTestContext_Deinit (BIBTestContext *obj)
 
void BSL_TestUtils_InitBIB_AppendixA1 (BIBTestContext *context, BSL_SecRole_e role, const char *key_id)
 
void BCBTestContext_Init (BCBTestContext *obj)
 
void BCBTestContext_Deinit (BCBTestContext *obj)
 
void BSL_TestUtils_InitBCB_Appendix2 (BCBTestContext *context, BSL_SecRole_e role)
 
RFC9173_A1_Params BSL_TestUtils_GetRFC9173_A1Params (const char *key_id)
 
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)
 
void BSL_TestUtils_SetupDefaultSecurityContext (BSL_LibCtx_t *bsl_lib)
 
int BSL_TestUtils_LoadBundleFromCBOR (BSL_TestContext_t *test_ctx, const char *cbor_seq)
 
BSL_HostEIDPattern_t BSL_TestUtils_GetEidPatternFromText (const char *text)
 
void BSL_TestUtils_PrintHexToBuffer (const char *message, uint8_t *buff, size_t bufflen)
 
bool BSL_TestUtils_IsB16StrEqualTo (const char *b16_string, BSL_Data_t encoded_val)
 
int BSL_TestUtils_EncodeBase16 (string_t output, const BSL_Data_t *input, bool uppercase)
 Encode to base16 text form.
 
int BSL_TestUtils_DecodeBase16 (BSL_Data_t *output, const string_t input)
 Decode base16 text form.
 
int BSL_TestUtils_ModifyEIDs (BSL_BundleRef_t *input_bundle, const char *src_eid, const char *dest_eid, const char *report_to_eid)
 Modify bundle's source eid, destination eid, and report-to eid.
 
int rfc9173_byte_gen_fn_a1 (unsigned char *buf, int len)
 
int rfc9173_byte_gen_fn_a2_kek (unsigned char *buf, int len)
 
int rfc9173_byte_gen_fn_a2_cek (unsigned char *buf, int len)
 
int rfc9173_byte_gen_fn_a4 (unsigned char *buf, int len)
 
BSL_SeqReader_t * BSL_TestUtils_FlatReader (const void *buf, size_t bufsize)
 Initialize a flat-buffer reader object.
 
BSL_SeqWriter_t * BSL_TestUtils_FlatWriter (void **buf, size_t *bufsize)
 Initialize a flat-buffer reader object.
 

Variables

static const uint8_t ApxA1_BIBBlock []
 
static const uint8_t ApxA1_AbsSecBlock []
 
static const uint8_t ApxA1_IPPT []
 
static const uint8_t ApxA1_HMAC []
 
static const uint8_t ApxA1_Key []
 
static const uint8_t ApxA2_InitVec [] = { 0x54, 0x77, 0x65, 0x6c, 0x76, 0x65, 0x31, 0x32, 0x31, 0x32, 0x31, 0x32 }
 
static const uint8_t ApxA2_AuthTag []
 
static const uint8_t ApxA2_KeyEncKey []
 
static const uint8_t ApxA2_ContentEncKey []
 
static const uint8_t ApxA2_Ciphertext []
 
static const uint8_t ApxA2_WrappedKey []
 
static const uint8_t ApxA2_PayloadData []
 
static const struct RFC9173_TestVectors_AppendixA1 RFC9173_TestVectors_AppendixA1
 
static const RFC9173_TestVectorsA2 RFC9173_TestVectors_AppendixA2
 
static const struct RFC9173_TestVectors_A4_Modified RFC9173_TestVectors_AppendixA4
 

Macro Definition Documentation

◆ BSL_SAMPLE_PP_ID

#define BSL_SAMPLE_PP_ID   1

Sample policy provider ID.

◆ BSL_SAMPLE_PP_ID_2

#define BSL_SAMPLE_PP_ID_2   2

◆ quick_data_t

#define quick_data_t (   field,
  tgt 
)
Value:
field.len = sizeof(tgt); \
field.ptr = ((uint8_t *)tgt)

◆ RFC9173_EXAMPLE_A1_KEY

#define RFC9173_EXAMPLE_A1_KEY   "9100"

Key ID for the Appendix A1 key in OpenSSL.

◆ RFC9173_EXAMPLE_A2_KEY

#define RFC9173_EXAMPLE_A2_KEY   "9102"

Key ID for the Appendix A2 key in OpenSSL.

◆ RFC9173_EXAMPLE_A3_KEY

#define RFC9173_EXAMPLE_A3_KEY   "9103"

Key ID for the Appendix A3 key in OpenSSL.

◆ RFC9173_EXAMPLE_A4_BCB_KEY

#define RFC9173_EXAMPLE_A4_BCB_KEY   "9104"

Key ID for the Appendix A4 key in OpenSSL.

◆ TEST_CASE

#define TEST_CASE (   ...)

◆ TEST_MATRIX

#define TEST_MATRIX (   ...)

◆ TEST_RANGE

#define TEST_RANGE (   ...)

Function Documentation

◆ BCBTestContext_Deinit()

◆ BCBTestContext_Init()

◆ BIBTestContext_Deinit()

◆ BIBTestContext_Init()

◆ BSL_TestUtils_DecodeBase16()

int BSL_TestUtils_DecodeBase16 ( BSL_Data_t output,
const string_t  input 
)

Decode base16 text form.

This is defined in Section 8 of RFC 4648 [15].

Note
This function uses heap allocation for its output.
Parameters
[out]outputThe output buffer, which will be sized to its data.
[in]inputThe input buffer to read, which must be null terminated. Whitespace in the input must have already been removed with strip_space().
Returns
Zero upon success.

References BSL_CHKERR1, BSL_Data_Resize(), BSL_TestUtils_DecodeBase16_char(), and BSL_Data_t::ptr.

Referenced by BSL_TestUtils_IsB16StrEqualTo(), BSL_TestUtils_LoadBundleFromCBOR(), test_bsl_loopback_bundle(), test_bsl_loopback_eid(), test_bsl_mock_encode_canonical(), test_BSL_TestUtils_DecodeBase16_valid(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), test_DecodeBase16(), test_qcbor_decode_only_head(), test_qcbor_decode_with_head(), test_qcbor_decode_without_head(), test_sec_accept_keyunwrap(), and test_sec_source_keywrap().

◆ BSL_TestUtils_EncodeBase16()

int BSL_TestUtils_EncodeBase16 ( string_t  output,
const BSL_Data_t input,
bool  uppercase 
)

Encode to base16 text form.

This is defined in Section 8 of RFC 4648 [15].

Note
This function uses heap allocation for its output.
Parameters
[out]outputThe output buffer, which will be appended to.
[in]inputThe input buffer to read.
uppercaseTrue to use upper-case letters, false to use lower-case.
Returns
Zero upon success.

References BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by printencoded().

◆ BSL_TestUtils_FlatReader()

◆ BSL_TestUtils_FlatWriter()

◆ BSL_TestUtils_GetEidPatternFromText()

◆ BSL_TestUtils_GetRFC9173_A1Params()

◆ BSL_TestUtils_GetRFC9173_A2Params()

RFC9173_A1_Params BSL_TestUtils_GetRFC9173_A2Params ( const char *  key_id)

◆ BSL_TestUtils_InitBCB_Appendix2()

◆ BSL_TestUtils_InitBIB_AppendixA1()

◆ BSL_TestUtils_InitMallocBIBActionSet()

◆ BSL_TestUtils_IsB16StrEqualTo()

◆ BSL_TestUtils_LoadBundleFromCBOR()

◆ BSL_TestUtils_MallocEmptyPolicyResponse()

◆ BSL_TestUtils_ModifyEIDs()

int BSL_TestUtils_ModifyEIDs ( BSL_BundleRef_t input_bundle,
const char *  src_eid,
const char *  dest_eid,
const char *  report_to_eid 
)

Modify bundle's source eid, destination eid, and report-to eid.

Parameters
[in,out]input_bundlebundle to modify
[in]src_eidEID to set bundle source EID to. Set to NULL if bundle source EID should remain unchanged.
[in]dest_eidEID to set bundle destination EID to. Set to NULL if bundle destination EID should remain unchanged.
[in]report_to_eidEID to set bundle report-to EID to. Set to NULL if bundle report-to EID should remain unchanged.

References BSL_BundleCtx_GetBundleMetadata(), BSL_PrimaryBlock_deinit(), BSL_PrimaryBlock_t::field_dest_eid, BSL_PrimaryBlock_t::field_report_to_eid, BSL_PrimaryBlock_t::field_src_node_id, and mock_bpa_eid_from_text().

Referenced by n_test_BSL_6(), test_BSL_32(), TEST_CASE(), and test_dyn_mem_cbs_BSL_32().

◆ BSL_TestUtils_PrintHexToBuffer()

void BSL_TestUtils_PrintHexToBuffer ( const char *  message,
uint8_t *  buff,
size_t  bufflen 
)

◆ BSL_TestUtils_SetupDefaultSecurityContext()

◆ rfc9173_byte_gen_fn_a1()

int rfc9173_byte_gen_fn_a1 ( unsigned char *  buf,
int  len 
)

◆ rfc9173_byte_gen_fn_a2_cek()

int rfc9173_byte_gen_fn_a2_cek ( unsigned char *  buf,
int  len 
)

◆ rfc9173_byte_gen_fn_a2_kek()

int rfc9173_byte_gen_fn_a2_kek ( unsigned char *  buf,
int  len 
)

References buf.

◆ rfc9173_byte_gen_fn_a4()

int rfc9173_byte_gen_fn_a4 ( unsigned char *  buf,
int  len 
)

Variable Documentation

◆ ApxA1_AbsSecBlock

const uint8_t ApxA1_AbsSecBlock[]
static
Initial value:
= {
0x81, 0x01, 0x01, 0x01, 0x82, 0x02, 0x82, 0x02, 0x01, 0x82, 0x82, 0x01, 0x07, 0x82, 0x03, 0x00, 0x81, 0x81,
0x82, 0x01, 0x58, 0x40, 0x3b, 0xdc, 0x69, 0xb3, 0xa3, 0x4a, 0x2b, 0x5d, 0x3a, 0x85, 0x54, 0x36, 0x8b, 0xd1,
0xe8, 0x08, 0xf6, 0x06, 0x21, 0x9d, 0x2a, 0x10, 0xa8, 0x46, 0xea, 0xe3, 0x88, 0x6a, 0xe4, 0xec, 0xc8, 0x3c,
0x4e, 0xe5, 0x50, 0xfd, 0xfb, 0x1c, 0xc6, 0x36, 0xb9, 0x04, 0xe2, 0xf1, 0xa7, 0x3e, 0x30, 0x3d, 0xcd, 0x4b,
0x6c, 0xce, 0xce, 0x00, 0x3e, 0x95, 0xe8, 0x16, 0x4d, 0xcc, 0x89, 0xa1, 0x56, 0xe1
}

◆ ApxA1_BIBBlock

const uint8_t ApxA1_BIBBlock[]
static
Initial value:
= {
0x85, 0x0b, 0x02, 0x00, 0x00, 0x58, 0x56, 0x81, 0x01, 0x01, 0x01, 0x82, 0x02, 0x82, 0x02, 0x01, 0x82, 0x82, 0x01,
0x07, 0x82, 0x03, 0x00, 0x81, 0x81, 0x82, 0x01, 0x58, 0x40, 0x3b, 0xdc, 0x69, 0xb3, 0xa3, 0x4a, 0x2b, 0x5d, 0x3a,
0x85, 0x54, 0x36, 0x8b, 0xd1, 0xe8, 0x08, 0xf6, 0x06, 0x21, 0x9d, 0x2a, 0x10, 0xa8, 0x46, 0xea, 0xe3, 0x88, 0x6a,
0xe4, 0xec, 0xc8, 0x3c, 0x4e, 0xe5, 0x50, 0xfd, 0xfb, 0x1c, 0xc6, 0x36, 0xb9, 0x04, 0xe2, 0xf1, 0xa7, 0x3e, 0x30,
0x3d, 0xcd, 0x4b, 0x6c, 0xce, 0xce, 0x00, 0x3e, 0x95, 0xe8, 0x16, 0x4d, 0xcc, 0x89, 0xa1, 0x56, 0xe1
}

◆ ApxA1_HMAC

const uint8_t ApxA1_HMAC[]
static
Initial value:
= { 0x3b, 0xdc, 0x69, 0xb3, 0xa3, 0x4a, 0x2b, 0x5d, 0x3a, 0x85, 0x54, 0x36, 0x8b,
0xd1, 0xe8, 0x08, 0xf6, 0x06, 0x21, 0x9d, 0x2a, 0x10, 0xa8, 0x46, 0xea, 0xe3,
0x88, 0x6a, 0xe4, 0xec, 0xc8, 0x3c, 0x4e, 0xe5, 0x50, 0xfd, 0xfb, 0x1c, 0xc6,
0x36, 0xb9, 0x04, 0xe2, 0xf1, 0xa7, 0x3e, 0x30, 0x3d, 0xcd, 0x4b, 0x6c, 0xce,
0xce, 0x00, 0x3e, 0x95, 0xe8, 0x16, 0x4d, 0xcc, 0x89, 0xa1, 0x56, 0xe1 }

Referenced by BSL_TestUtils_InitBIB_AppendixA1(), and test_RFC9173_AppendixA_Example1_BIB_Source().

◆ ApxA1_IPPT

const uint8_t ApxA1_IPPT[]
static
Initial value:
= { 0x00, 0x58, 0x23, 0x52, 0x65, 0x61, 0x64, 0x79, 0x20, 0x74, 0x6f, 0x20, 0x67,
0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x61, 0x20, 0x33, 0x32, 0x2d,
0x62, 0x79, 0x74, 0x65, 0x20, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64 }

◆ ApxA1_Key

const uint8_t ApxA1_Key[]
static
Initial value:
= { 0x1a, 0x2b, 0x1a, 0x2b, 0x1a, 0x2b, 0x1a, 0x2b,
0x1a, 0x2b, 0x1a, 0x2b, 0x1a, 0x2b, 0x1a, 0x2b }

◆ ApxA2_AuthTag

const uint8_t ApxA2_AuthTag[]
static
Initial value:
= { 0xef, 0xa4, 0xb5, 0xac, 0x01, 0x08, 0xe3, 0x81,
0x6c, 0x56, 0x06, 0x47, 0x98, 0x01, 0xbc, 0x04 }

Referenced by BSL_TestUtils_InitBCB_Appendix2(), setUp(), and test_RFC9173_AppendixA_Example2_BCB_Source().

◆ ApxA2_Ciphertext

const uint8_t ApxA2_Ciphertext[]
static
Initial value:
= { 0x3a, 0x09, 0xc1, 0xe6, 0x3f, 0xe2, 0x3a, 0x7f, 0x66, 0xa5, 0x9c, 0x73,
0x03, 0x83, 0x72, 0x41, 0xe0, 0x70, 0xb0, 0x26, 0x19, 0xfc, 0x59, 0xc5,
0x21, 0x4a, 0x22, 0xf0, 0x8c, 0xd7, 0x07, 0x95, 0xe7, 0x3e, 0x9a }

Referenced by test_RFC9173_AppendixA_Example2_BCB_Source().

◆ ApxA2_ContentEncKey

const uint8_t ApxA2_ContentEncKey[]
static
Initial value:
= { 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69,
0x6f, 0x70, 0x61, 0x73, 0x64, 0x66, 0x67, 0x68 }

◆ ApxA2_InitVec

const uint8_t ApxA2_InitVec[] = { 0x54, 0x77, 0x65, 0x6c, 0x76, 0x65, 0x31, 0x32, 0x31, 0x32, 0x31, 0x32 }
static

◆ ApxA2_KeyEncKey

const uint8_t ApxA2_KeyEncKey[]
static
Initial value:
= { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70 }

Referenced by BSL_TestUtils_InitBCB_Appendix2().

◆ ApxA2_PayloadData

const uint8_t ApxA2_PayloadData[]
static
Initial value:
= { 0x52, 0x65, 0x61, 0x64, 0x79, 0x20, 0x74, 0x6f, 0x20, 0x67, 0x65, 0x6e,
0x65, 0x72, 0x61, 0x74, 0x65, 0x20, 0x61, 0x20, 0x33, 0x32, 0x2d, 0x62,
0x79, 0x74, 0x65, 0x20, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64 }

Referenced by test_RFC9173_AppendixA_Example2_BCB_Acceptor().

◆ ApxA2_WrappedKey

const uint8_t ApxA2_WrappedKey[]
static
Initial value:
= { 0x69, 0xc4, 0x11, 0x27, 0x6f, 0xec, 0xdd, 0xc4, 0x78, 0x0d, 0xf4, 0x2c,
0x8a, 0x2a, 0xf8, 0x92, 0x96, 0xfa, 0xbf, 0x34, 0xd7, 0xfa, 0xe7, 0x00 }

Referenced by BSL_TestUtils_InitBCB_Appendix2(), and setUp().

◆ RFC9173_TestVectors_AppendixA1

◆ RFC9173_TestVectors_AppendixA2

const RFC9173_TestVectorsA2 RFC9173_TestVectors_AppendixA2
static

◆ RFC9173_TestVectors_AppendixA4

const struct RFC9173_TestVectors_A4_Modified RFC9173_TestVectors_AppendixA4
static
Initial value:
= {
.cbor_bundle_original = ("9f88070000820282010282028202018202820201820018"
"281A000F424085010100005823526561647920746F2067"
"656E657261746520612033322D62797465207061796C6F"
"6164ff"),
.cbor_bundle_final = ("9f88070000820282010282028202018202820201820018"
"281A000F4240850B030000585681010101820282020182"
"8201078203008181820158403BDC69B3A34A2B5D3A8554"
"368BD1E808F606219D2A10A846EAE3886AE4ECC83C4EE5"
"50FDFB1CC636B904E2F1A73E303DCD4B6CCECE003E95E8"
"164DCC89A156E1850C0201005850810102018202820201"
"8482014C5477656C766531323132313282020182035818"
"69C411276FECDDC4780DF42C8A2AF89296FABF34D7FAE7"
"008204008181820150EFA4B5AC0108E3816C5606479801"
"BC04850101000058233A09C1E63FE23A7F66A59C730383"
"7241E070B02619FC59C5214A22F08CD70795E73E9Aff"),
}

Referenced by TEST_CASE().