BSL v1.0.0 - 29.g99f1b76
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
SamplePolicyProvider.c File Reference

Local implementation of locally-defined data structures. More...

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <m-array.h>
#include <BPSecLib_Private.h>
#include "SamplePolicyProvider.h"
+ Include dependency graph for SamplePolicyProvider.c:

Functions

static bool BSLP_PolicyPredicate_IsConsistent (const BSLP_PolicyPredicate_t *self)
 
static bool BSLP_PolicyRule_IsConsistent (const BSLP_PolicyRule_t *self)
 
static uint64_t BSLP_PolicyProvider_HandleFailures (BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper)
 
static uint64_t get_target_block_id (const BSL_BundleRef_t *bundle, uint64_t target_block_type)
 Look up all canonical blocks of a particular type.
 
int BSLP_QueryPolicy (void *user_data, BSL_SecurityActionSet_t *output_action_set, const BSL_BundleRef_t *bundle, BSL_PolicyLocation_e location)
 Note that criticality is HIGH.
 
int BSLP_FinalizePolicy (void *user_data, const BSL_SecurityActionSet_t *output_action_set, const BSL_BundleRef_t *bundle, const BSL_SecurityResponseSet_t *response_output)
 
void BSLP_Deinit (void *user_data)
 De-initialize policy provider user_data.
 
BSLP_PolicyProvider_tBSLP_PolicyProvider_Init (uint64_t pp_id)
 Initialize policy provider data Data owned by BPA, reference should be provided to BSL library context(s)
 
int BSLP_PolicyProvider_AddRule (BSLP_PolicyProvider_t *self, BSLP_PolicyRule_t *rule, const BSLP_PolicyPredicate_t *predicate)
 Add rule and corresponding predicate to policy provider.
 
void BSLP_PolicyProvider_Deinit (BSLP_PolicyProvider_t *self)
 Deinitialize policy provider data References to this data will become invalid.
 
void BSLP_PolicyPredicate_Init (BSLP_PolicyPredicate_t *self)
 Initialize policy predicate and associated host eid pattern structures.
 
void BSLP_PolicyPredicate_ShallowCopy (BSLP_PolicyPredicate_t *self, const BSLP_PolicyPredicate_t *src)
 Shallow copy of policy predicate.
 
int BSLP_PolicyPredicate_InitFrom (BSLP_PolicyPredicate_t *self, BSL_PolicyLocation_e location, const char *src_eid_pattern, const char *secsrc_eid_pattern, const char *dst_eid_pattern)
 Initialize policy predicate from c string patterns.
 
void BSLP_PolicyPredicate_Deinit (BSLP_PolicyPredicate_t *self)
 Deinitialize policy predicate and associated host eid pattern structures.
 
bool BSLP_PolicyPredicate_IsMatch (const BSLP_PolicyPredicate_t *self, BSL_PolicyLocation_e location, BSL_HostEID_t src_eid, BSL_HostEID_t dst_eid)
 Returns true if the given predicate matches the arguments.
 
int BSLP_PolicyRule_InitFrom (BSLP_PolicyRule_t *self, const char *desc, int64_t context_id, BSL_SecRole_e role, BSL_SecBlockType_e sec_block_type, uint64_t target_block_type, BSL_PolicyAction_e failure_action_code)
 Initialize this policy rule from parameters.
 
void BSLP_PolicyRule_Init (BSLP_PolicyRule_t *self)
 Initialize policy rule.
 
void BSLP_PolicyRule_InitSet (BSLP_PolicyRule_t *self, const BSLP_PolicyRule_t *src)
 Deinitialize policy rule.
 
void BSLP_PolicyRule_Deinit (BSLP_PolicyRule_t *self)
 De-initialize, release any resources, and zero this struct.
 
void BSLP_PolicyRule_CopyParam (BSLP_PolicyRule_t *self, const BSL_SecParam_t *param)
 Include a BPSec parameter to this rule.
 
void BSLP_PolicyRule_MoveParam (BSLP_PolicyRule_t *self, BSL_SecParam_t *param)
 Include a BPSec parameter to this rule.
 
int BSLP_PolicyRule_EvaluateAsSecOper (const BSLP_PolicyRule_t *self, const BSLP_PolicyPredicate_t *predicate, BSL_SecOper_t *sec_oper, const BSL_BundleRef_t *bundle, BSL_PolicyLocation_e location)
 Evaluate policy rule as security operation.
 

Detailed Description

Local implementation of locally-defined data structures.

Function Documentation

◆ BSLP_Deinit()

void BSLP_Deinit ( void *  user_data)

De-initialize policy provider user_data.

Called during de-initialization of each library instance.

Parameters
user_datareference to shared data. Not owned by library context's policy provider

Referenced by _setUp(), MockBPA_Agent_Init(), setUp(), and test_MultiplePolicyProviders().

◆ BSLP_FinalizePolicy()

◆ BSLP_PolicyPredicate_Deinit()

void BSLP_PolicyPredicate_Deinit ( BSLP_PolicyPredicate_t self)

Deinitialize policy predicate and associated host eid pattern structures.

Parameters
selfpolicy predicate

References BSL_HostEIDPattern_Deinit(), BSLP_PolicyPredicate_t::dst_eid_pattern, BSLP_PolicyPredicate_t::secsrc_eid_pattern, and BSLP_PolicyPredicate_t::src_eid_pattern.

Referenced by test_SamplePolicyProvider_WildcardPolicyRuleVerifiesBIB().

◆ BSLP_PolicyPredicate_Init()

void BSLP_PolicyPredicate_Init ( BSLP_PolicyPredicate_t self)

Initialize policy predicate and associated host eid pattern structures.

Parameters
selfpolicy predicate

References BSL_HostEIDPattern_Init(), BSLP_PolicyPredicate_t::dst_eid_pattern, BSLP_PolicyPredicate_t::location, BSLP_PolicyPredicate_t::secsrc_eid_pattern, and BSLP_PolicyPredicate_t::src_eid_pattern.

Referenced by BSLP_PolicyPredicate_InitFrom().

◆ BSLP_PolicyPredicate_InitFrom()

int BSLP_PolicyPredicate_InitFrom ( BSLP_PolicyPredicate_t self,
BSL_PolicyLocation_e  location,
const char *  src_eid_pattern,
const char *  secsrc_eid_pattern,
const char *  dst_eid_pattern 
)

Initialize policy predicate from c string patterns.

A policy predicate represents a way to match whether a rule applies to a bundle.

Parameters
[in]selfThis predicate
[in]locationThe BSL_PolicyLocation_e location in the BPA
[in]src_eid_patternc string pattern for SOURCE matching
[in]srcsrc_eid_patternc string pattern for SECURITY SOURCE matching
[in]dst_eid_patternc string pattern for DESTINATION matching
Returns
0 on success

References BSL_ERR_HOST_CALLBACK_FAILED, BSL_ERR_PROPERTY_CHECK_FAILED, BSL_HostEIDPattern_DecodeFromText(), BSL_SUCCESS, BSLP_PolicyPredicate_Init(), BSLP_PolicyPredicate_IsConsistent(), BSLP_PolicyPredicate_t::dst_eid_pattern, BSLP_PolicyPredicate_t::location, BSLP_PolicyPredicate_t::secsrc_eid_pattern, and BSLP_PolicyPredicate_t::src_eid_pattern.

Referenced by _setUp(), BSLP_RegisterPolicyFromBitstring(), BSLP_RegisterPolicyFromJSON(), setUp(), test_MultiplePolicyProviders(), test_PolicyProvider_Inspect_RFC9173_BIB(), test_PolicyProvider_InspectSingleBIBRuleset(), and test_SamplePolicyProvider_WildcardPolicyRuleVerifiesBIB().

◆ BSLP_PolicyPredicate_IsConsistent()

◆ BSLP_PolicyPredicate_IsMatch()

bool BSLP_PolicyPredicate_IsMatch ( const BSLP_PolicyPredicate_t self,
BSL_PolicyLocation_e  location,
BSL_HostEID_t  src_eid,
BSL_HostEID_t  dst_eid 
)

Returns true if the given predicate matches the arguments.

Parameters
[in]selfThis predicate
[in]locationLocation in the BPA
[in]src_eidSource EID
[in]dst_eidDestination EID

References ASSERT_ARG_EXPR, BSL_HostEIDPattern_IsMatch(), BSL_LOG_DEBUG, BSLP_PolicyPredicate_IsConsistent(), BSLP_PolicyPredicate_t::dst_eid_pattern, BSLP_PolicyPredicate_t::location, and BSLP_PolicyPredicate_t::src_eid_pattern.

Referenced by BSLP_PolicyRule_EvaluateAsSecOper(), and BSLP_QueryPolicy().

◆ BSLP_PolicyPredicate_ShallowCopy()

void BSLP_PolicyPredicate_ShallowCopy ( BSLP_PolicyPredicate_t self,
const BSLP_PolicyPredicate_t src 
)

Shallow copy of policy predicate.

Parameters
selfdestination policy predicate
srcsource policy predicate

References BSLP_PolicyPredicate_t::dst_eid_pattern, BSL_HostEIDPattern_t::handle, BSLP_PolicyPredicate_t::location, BSLP_PolicyPredicate_t::secsrc_eid_pattern, and BSLP_PolicyPredicate_t::src_eid_pattern.

◆ BSLP_PolicyProvider_AddRule()

int BSLP_PolicyProvider_AddRule ( BSLP_PolicyProvider_t self,
BSLP_PolicyRule_t rule,
const BSLP_PolicyPredicate_t predicate 
)

◆ BSLP_PolicyProvider_Deinit()

void BSLP_PolicyProvider_Deinit ( BSLP_PolicyProvider_t self)

Deinitialize policy provider data References to this data will become invalid.

Parameters
selfpolicy provider data to de-initialize

References BSL_free(), BSLP_PolicyProvider_t::mutex, BSLP_PolicyProvider_t::predicates, and BSLP_PolicyProvider_t::rules.

Referenced by _tearDown(), main(), tearDown(), and test_MultiplePolicyProviders().

◆ BSLP_PolicyProvider_HandleFailures()

◆ BSLP_PolicyProvider_Init()

BSLP_PolicyProvider_t * BSLP_PolicyProvider_Init ( uint64_t  pp_id)

Initialize policy provider data Data owned by BPA, reference should be provided to BSL library context(s)

Parameters
pp_idpolicy provider id (must be > 0)
Returns
valid pointer to dynamically allocated policy provider

References ASSERT_ARG_EXPR, ASSERT_ARG_NONNULL, BSL_malloc(), BSLP_PolicyProvider_t::mutex, BSLP_PolicyProvider_t::pp_id, BSLP_PolicyProvider_t::predicates, and BSLP_PolicyProvider_t::rules.

Referenced by _setUp(), MockBPA_Agent_Init(), setUp(), and test_MultiplePolicyProviders().

◆ BSLP_PolicyRule_CopyParam()

void BSLP_PolicyRule_CopyParam ( BSLP_PolicyRule_t self,
const BSL_SecParam_t *  param 
)

Include a BPSec parameter to this rule.

Used immediately after Init.

Parameters
[in]selfThis rule
[in,out]paramPointer to the Parameter to move from.

References ASSERT_ARG_EXPR, ASSERT_POSTCONDITION, BSL_SecParam_IsConsistent(), BSLP_PolicyRule_IsConsistent(), and BSLP_PolicyRule_t::params.

Referenced by _setUp(), BSLP_RegisterPolicyFromBitstring(), BSLP_RegisterPolicyFromJSON(), and setUp().

◆ BSLP_PolicyRule_Deinit()

void BSLP_PolicyRule_Deinit ( BSLP_PolicyRule_t self)

De-initialize, release any resources, and zero this struct.

Parameters
[in]selfThis rule

References BSL_LOG_INFO, BSLP_PolicyRule_t::description, BSLP_PolicyRule_t::params, and string_clear().

Referenced by test_SamplePolicyProvider_WildcardPolicyRuleVerifiesBIB().

◆ BSLP_PolicyRule_EvaluateAsSecOper()

◆ BSLP_PolicyRule_Init()

void BSLP_PolicyRule_Init ( BSLP_PolicyRule_t self)

Initialize policy rule.

Parameters
selfpolicy rule

References BSLP_PolicyRule_t::description, and BSLP_PolicyRule_t::params.

Referenced by BSLP_PolicyRule_InitFrom().

◆ BSLP_PolicyRule_InitFrom()

int BSLP_PolicyRule_InitFrom ( BSLP_PolicyRule_t self,
const char *  desc,
int64_t  context_id,
BSL_SecRole_e  role,
BSL_SecBlockType_e  sec_block_type,
uint64_t  target_block_type,
BSL_PolicyAction_e  failure_action_code 
)

Initialize this policy rule from parameters.

Parameters
[in]selfThis policy rule
[in]destDescription of this rule (C-string). Will copy characters of parameter from index 0 to BSLP_POLICY_RULE_DESCRIPTION_MAX_STRLEN - 1.
[in]context_idSecurity context ID
[in]roleSuch as source, acceptor, etc
[in]sec_block_typeBlock type (BIB or BCB)
[in]target_block_typeTarget block type (anything, such as primary or payload)
[in]failure_action_codeCode to indicate fate of security block/bundle if error occurs
Returns
Zero on success

References BSL_ERR_PROPERTY_CHECK_FAILED, BSL_SUCCESS, BSLP_PolicyRule_Init(), BSLP_PolicyRule_IsConsistent(), BSLP_PolicyRule_t::context_id, BSLP_PolicyRule_t::description, BSLP_PolicyRule_t::failure_action_code, BSLP_PolicyRule_t::role, BSLP_PolicyRule_t::sec_block_type, and BSLP_PolicyRule_t::target_block_type.

Referenced by _setUp(), BSLP_RegisterPolicyFromBitstring(), BSLP_RegisterPolicyFromJSON(), setUp(), test_MultiplePolicyProviders(), test_PolicyProvider_Inspect_RFC9173_BIB(), test_PolicyProvider_InspectSingleBIBRuleset(), and test_SamplePolicyProvider_WildcardPolicyRuleVerifiesBIB().

◆ BSLP_PolicyRule_InitSet()

◆ BSLP_PolicyRule_IsConsistent()

◆ BSLP_PolicyRule_MoveParam()

void BSLP_PolicyRule_MoveParam ( BSLP_PolicyRule_t self,
BSL_SecParam_t *  param 
)

Include a BPSec parameter to this rule.

Used immediately after Init.

Parameters
[in]selfThis rule
[in,out]paramPointer to the Parameter to move from.

References ASSERT_ARG_EXPR, ASSERT_POSTCONDITION, BSL_SecParam_IsConsistent(), BSLP_PolicyRule_IsConsistent(), and BSLP_PolicyRule_t::params.

Referenced by test_MultiplePolicyProviders(), and test_PolicyProvider_Inspect_RFC9173_BIB().

◆ BSLP_QueryPolicy()

◆ get_target_block_id()

static uint64_t get_target_block_id ( const BSL_BundleRef_t bundle,
uint64_t  target_block_type 
)
static

Look up all canonical blocks of a particular type.

Returns
The first block found, or zero if not found. A warning will be logged if there are others.

References BSL_PrimaryBlock_t::block_count, BSL_PrimaryBlock_t::block_numbers, BSL_BundleCtx_GetBlockMetadata(), BSL_BundleCtx_GetBundleMetadata(), BSL_LOG_ERR, BSL_LOG_WARNING, BSL_PrimaryBlock_deinit(), BSL_SUCCESS, and BSL_CanonicalBlock_t::type_code.

Referenced by BSLP_PolicyRule_EvaluateAsSecOper(), and BSLP_QueryPolicy().