|
BSL v1.1.1 - 39.g9f43410
AMMOS Bundle Protocol Security Library (BSL)
|
#include "PolicyParser.h"#include "bsl/front/TextUtil.h"#include "bsl/cose_sc/CoseContext.h"#include "bsl/default_sc/DefaultSecContext.h"#include <jansson.h>#include <errno.h>#include <strings.h>
Include dependency graph for PolicyParser.c:Typedefs | |
| typedef int(* | BSLP_OptionHandler_f) (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value) |
| Type for individual option handling according to each SC. | |
Functions | |
| static int | BSLP_GetTextAsInt (int64_t *as_int, const char *ptr, size_t len) |
| Read a text value as long integer. | |
| static int | BSLP_GetNumberInt (const json_t *value, int64_t *as_int) |
| Read a JSON value as long integer, either directly or from text. | |
| static int | BSLP_GetBytesHex (const json_t *value, BSL_Data_t *as_bytes) |
| Read a JSON value as hexadecimal bytes from text. | |
| static int | BSLP_GetBoolean (const json_t *value, bool *as_bool) |
| Read a JSON value as a boolean, either directly or from text. | |
| static int | BSLP_PolicyOptions_SC1 (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value) |
| Handle options for Security context ID 1. | |
| static int | BSLP_PolicyOptions_SC2 (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value) |
| Handle options for Security context ID 2. | |
| static int | BSLP_PolicyOptions_SC3 (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value) |
| Handle options for Security context ID 3. | |
| static int | BSLP_PolicyParser_ReadOneRule (BSLP_PolicyProvider_t *policy, const json_t *policy_rule_elm) |
| int | BSLP_PolicyParser_FromJSON (const char *policy_cfg_path, BSLP_PolicyProvider_t *policy) |
| Initialize local policy provider from JSON file. | |
| static void | BSLP_RegisterPolicyFromBitstring (const BSLP_PolicyParser_BitstringConfig_t policy_bits, BSLP_PolicyProvider_t *policy, BSLB_IdValPairPtrMap_t options) |
| int | BSLP_PolicyParser_FromBitstringList (const char *policies, BSLP_PolicyProvider_t *policy) |
| Initialize local policy provider from list of bit strings. | |
| typedef int(* BSLP_OptionHandler_f) (BSLB_IdValPairPtrMap_t options, const char *id_str, json_t *value) |
Type for individual option handling according to each SC.
|
static |
Read a JSON value as a boolean, either directly or from text.
| [in] | value | The value to interpret. |
| [out] | as_bool | The output value. |
References BSL_ERR_POLICY_CONFIG, BSL_LOG_ERR, and BSL_SUCCESS.
Referenced by BSLP_PolicyOptions_SC1(), and BSLP_PolicyOptions_SC2().
|
static |
Read a JSON value as hexadecimal bytes from text.
| [in] | value | The value to interpret. |
| [out] | as_bytes | The output value. |
References BSL_TextUtil_Base16_Decode().
Referenced by BSLP_PolicyOptions_SC3().
|
static |
Read a JSON value as long integer, either directly or from text.
| [in] | value | The value to interpret. |
| [out] | as_int | The output value. |
References BSL_ERR_POLICY_CONFIG, BSL_LOG_ERR, BSL_SUCCESS, and BSLP_GetTextAsInt().
Referenced by BSLP_PolicyOptions_SC1(), BSLP_PolicyOptions_SC2(), and BSLP_PolicyOptions_SC3().
|
static |
Read a text value as long integer.
The entire text must be consumed to be valid.
| [out] | as_int | The output value. |
| [in] | ptr | The text pointer. |
| len | The text length (excluding null terminator). |
References BSL_ERR_POLICY_CONFIG, BSL_LOG_ERR, and BSL_SUCCESS.
Referenced by BSLP_GetNumberInt(), and BSLP_PolicyOptions_SC3().
|
static |
Handle options for Security context ID 1.
Matches BSLP_OptionHandler_f signature.
References BSL_ERR_POLICY_CONFIG, BSL_IdValPair_SetInt64(), BSL_IdValPair_SetTextstr(), BSL_LOG_ERR, BSL_SUCCESS, BSLB_IdValPairPtrMap_add(), BSLP_GetBoolean(), BSLP_GetNumberInt(), BSLX_BIB_OPT_KEY_ID, BSLX_BIB_OPT_SCOPE, BSLX_BIB_OPT_SHA_VARIANT, and BSLX_BIB_OPT_USE_KEY_WRAP.
Referenced by BSLP_PolicyParser_ReadOneRule().
|
static |
Handle options for Security context ID 2.
Matches BSLP_OptionHandler_f signature.
References BSL_ERR_POLICY_CONFIG, BSL_IdValPair_SetInt64(), BSL_IdValPair_SetTextstr(), BSL_LOG_ERR, BSL_SUCCESS, BSLB_IdValPairPtrMap_add(), BSLP_GetBoolean(), BSLP_GetNumberInt(), BSLX_BCB_OPT_AES_VARIANT, BSLX_BCB_OPT_KEY_ID, BSLX_BCB_OPT_SCOPE, and BSLX_BCB_OPT_USE_KEY_WRAP.
Referenced by BSLP_PolicyParser_ReadOneRule().
|
static |
Handle options for Security context ID 3.
Matches BSLP_OptionHandler_f signature.
References BSL_CBOR_Encode_Twopass(), BSL_Data_Deinit(), BSL_Data_Init(), BSL_DATA_INIT_VIEW_CSTR, BSL_ERR_POLICY_CONFIG, BSL_IdValPair_SetBytestr(), BSL_IdValPair_SetInt64(), BSL_IdValPair_SetRaw(), BSL_LOG_DEBUG, BSL_LOG_ERR, BSL_SUCCESS, BSLB_IdValPairPtrMap_add(), BSLP_GetBytesHex(), BSLP_GetNumberInt(), BSLP_GetTextAsInt(), BSLX_CoseSc_AadScope_Encode(), BSLX_COSESC_OPTION_AAD_SCOPE, BSLX_COSESC_OPTION_IV_BASE, BSLX_COSESC_OPTION_IV_COUNTER_OFFSET, BSLX_COSESC_OPTION_KEY_ID, BSLX_COSESC_OPTION_SALT_BASE, BSLX_COSESC_OPTION_SALT_COUNTER_OFFSET, BSLX_COSESC_OPTION_SALT_LENGTH, BSLX_COSESC_OPTION_TGT_ALG, BSL_Data_t::len, and BSL_Data_t::ptr.
Referenced by BSLP_PolicyParser_ReadOneRule().
| int BSLP_PolicyParser_FromBitstringList | ( | const char * | policies, |
| BSLP_PolicyProvider_t * | policy | ||
| ) |
Initialize local policy provider from list of bit strings.
| [in] | policies | comma separated policy bit strings as described by BSLP_PolicyParser_BitstringConfig_t |
| [in,out] | policy | policy provider to configure. Must be initialize/allocated |
References BSL_LOG_ERR, BSL_SUCCESS, BSLP_RegisterPolicyFromBitstring(), CHK_ARG_NONNULL, and policy.
Referenced by main().
| int BSLP_PolicyParser_FromJSON | ( | const char * | policy_cfg_path, |
| BSLP_PolicyProvider_t * | policy | ||
| ) |
Initialize local policy provider from JSON file.
| [in] | policy_cfg_path | path to JSON file containing policy configuration |
| [in,out] | policy | policy provider to configure. Must be initialize/allocated |
References BSL_ERR_POLICY_CONFIG, BSL_LOG_DEBUG, BSL_LOG_ERR, BSL_SUCCESS, BSLP_PolicyParser_ReadOneRule(), CHK_ARG_NONNULL, and policy.
Referenced by main(), test_PolicyParser_ReadConfigEmpty(), test_PolicyParser_ReadConfigInvalid(), and test_PolicyParser_ReadConfigValid().
|
static |
References BSL_ERR_POLICY_CONFIG, BSL_IdValPair_Set(), BSL_LOG_CRIT, BSL_LOG_DEBUG, BSL_LOG_ERR, BSL_LOG_INFO, BSL_POLICYACTION_DROP_BLOCK, BSL_POLICYACTION_DROP_BUNDLE, BSL_POLICYACTION_NOTHING, BSL_POLICYLOCATION_APPIN, BSL_POLICYLOCATION_APPOUT, BSL_POLICYLOCATION_CLIN, BSL_POLICYLOCATION_CLOUT, BSL_SECBLOCKTYPE_BCB, BSL_SECBLOCKTYPE_BIB, BSL_SECROLE_ACCEPTOR, BSL_SECROLE_SOURCE, BSL_SECROLE_VERIFIER, BSL_SUCCESS, BSLP_PolicyOptions_SC1(), BSLP_PolicyOptions_SC2(), BSLP_PolicyOptions_SC3(), BSLP_PolicyPredicate_InitFrom(), BSLP_PolicyProvider_AddRule(), BSLP_PolicyRule_AddOption(), BSLP_PolicyRule_InitFrom(), BSLX_COSESC_CTX_ID, policy, RFC9173_CONTEXTID_BCB_AES_GCM, and RFC9173_CONTEXTID_BIB_HMAC_SHA2.
Referenced by BSLP_PolicyParser_FromJSON().
|
static |
References BSL_BLOCK_TYPE_BUNDLE_AGE, BSL_BLOCK_TYPE_PAYLOAD, BSL_BLOCK_TYPE_PRIMARY, BSL_IdValPair_Set(), BSL_IdValPair_SetInt64(), BSL_IdValPair_SetTextstr(), BSL_LOG_DEBUG, BSL_LOG_INFO, BSL_POLICYACTION_DROP_BLOCK, BSL_POLICYACTION_DROP_BUNDLE, BSL_POLICYACTION_NOTHING, BSL_POLICYLOCATION_CLIN, BSL_POLICYLOCATION_CLOUT, BSL_SECBLOCKTYPE_BCB, BSL_SECBLOCKTYPE_BIB, BSL_SECROLE_ACCEPTOR, BSL_SECROLE_SOURCE, BSL_SECROLE_VERIFIER, BSLB_IdValPairPtrMap_add(), BSLP_PolicyPredicate_InitFrom(), BSLP_PolicyProvider_AddRule(), BSLP_PolicyRule_AddOption(), BSLP_PolicyRule_InitFrom(), BSLX_BCB_OPT_AES_VARIANT, BSLX_BCB_OPT_KEY_ID, BSLX_BCB_OPT_SCOPE, BSLX_BCB_OPT_USE_KEY_WRAP, BSLX_BIB_OPT_KEY_ID, BSLX_BIB_OPT_SCOPE, BSLX_BIB_OPT_SHA_VARIANT, BSLX_BIB_OPT_USE_KEY_WRAP, policy, RFC9173_BCB_AADSCOPEFLAGID_INC_NONE, RFC9173_BCB_AES_VARIANT_A128GCM, and RFC9173_BIB_SHA_HMAC512.
Referenced by BSLP_PolicyParser_FromBitstringList().