Skip to content

Commit 25b2da7

Browse files
authored
Remove ResponseSet and SecOutcome (#241)
* remove ResponseSet * remove SecOutcome
1 parent f37a1c5 commit 25b2da7

29 files changed

Lines changed: 272 additions & 817 deletions

src/BPSecLib_Private.h

Lines changed: 46 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,42 @@ void BSL_SecOper_AppendOption(BSL_SecOper_t *self, const BSL_IdValPair_t *option
808808
*/
809809
void BSL_SecOper_AppendParam(BSL_SecOper_t *self, const BSL_IdValPair_t *param);
810810

811+
/** Add an empty security parameter.
812+
*
813+
* @param[in,out] self This security operation.
814+
* @param[in] param_id Security parameter ID.
815+
* @return The parameter owned by this operation.
816+
*/
817+
BSL_IdValPair_t *BSL_SecOper_AddParam(BSL_SecOper_t *self, int64_t param_id);
818+
819+
/** Add an empty security result.
820+
*
821+
* @param[in,out] self This security operation.
822+
* @param[in] result_id Security result ID.
823+
* @return The result owned by this operation.
824+
*/
825+
BSL_IdValPair_t *BSL_SecOper_AddResult(BSL_SecOper_t *self, int64_t result_id);
826+
827+
/** Get the count of parameters contained within this security operation.
828+
*
829+
* @param[in] self This security operation
830+
* @return Count of security parameters.
831+
*/
832+
size_t BSL_SecOper_CountParams(const BSL_SecOper_t *self);
833+
834+
/** Get the count of results contained within this security operation.
835+
*
836+
* @param[in] self This security operation
837+
* @return Count of security results.
838+
*/
839+
size_t BSL_SecOper_CountResults(const BSL_SecOper_t *self);
840+
841+
/** Clear all parameters and results contained within this security operation.
842+
*
843+
* @param[in,out] self This security operation
844+
*/
845+
void BSL_SecOper_ClearParamsAndResults(BSL_SecOper_t *self);
846+
811847
/** Return true if this security operation's role is SOURCE
812848
* @param[in] self This Security Operation
813849
* @return boolean
@@ -934,75 +970,6 @@ const BSL_IdValPair_t *BSL_AbsSecBlock_FindResult(BSL_AbsSecBlock_t *self, uint6
934970
*/
935971
int BSL_TlmCounters_IncrementCounter(BSL_LibCtx_t *bsl, BSL_TlmCounterIndex_e tlm_index, uint64_t count);
936972

937-
/** @brief Represents the output following execution of a security operation.
938-
*/
939-
typedef struct BSL_SecOutcome_s BSL_SecOutcome_t;
940-
941-
/// @brief Returns the size of the ::BSL_SecOutcome_s structure.
942-
size_t BSL_SecOutcome_Sizeof(void);
943-
944-
/** Populate a pre-allocated security outcome struct.
945-
*
946-
* @param[in,out] self Non-Null pointer to this security outcome.
947-
* @param[in] sec_oper Security operation containing the necessary info.
948-
*/
949-
void BSL_SecOutcome_Init(BSL_SecOutcome_t *self, const BSL_SecOper_t *sec_oper);
950-
951-
/** Release any resources owned by this security outcome.
952-
*
953-
* @param[in,out] self Non-Null pointer to this security outcome.
954-
*/
955-
void BSL_SecOutcome_Deinit(BSL_SecOutcome_t *self);
956-
957-
/** Return true if internal invariants hold
958-
*
959-
* @param[in] self This sec outcome.
960-
* @return true if invariants hold
961-
*/
962-
bool BSL_SecOutcome_IsConsistent(const BSL_SecOutcome_t *self);
963-
964-
/** Append a Security Result to this outcome.
965-
*
966-
* @param[in,out] self Non-NULL pointer to this security outcome.
967-
* @return Non-NULL pointer to security result just appended.
968-
*/
969-
BSL_IdValPair_t *BSL_SecOutcome_AppendResult(BSL_SecOutcome_t *self);
970-
971-
/** Get the result at index i. Panics if i is out of range.
972-
*
973-
* @param[in] self This outcome
974-
* @param[in] index Index in the list to retrieve
975-
* @return Sec Result at index
976-
*/
977-
const BSL_IdValPair_t *BSL_SecOutcome_GetResultAtIndex(const BSL_SecOutcome_t *self, size_t index);
978-
979-
/** Get the number of results
980-
*
981-
* @param[in] self this sec outcome
982-
* @return number of results in sec outcome
983-
*/
984-
size_t BSL_SecOutcome_CountResults(const BSL_SecOutcome_t *self);
985-
986-
/** Append a Security Parameter to this outcome.
987-
*
988-
* @param[in,out] self Non-NULL pointer to this security outcome.
989-
* @return Non-NULL pointer to the initialized security parameter.
990-
*/
991-
BSL_IdValPair_t *BSL_SecOutcome_AppendParam(BSL_SecOutcome_t *self);
992-
993-
/** @brief Returns number of parameters in this outcome.
994-
* @param[in] self This outcome
995-
* @return Number of parameters
996-
*/
997-
size_t BSL_SecOutcome_CountParams(const BSL_SecOutcome_t *self);
998-
999-
/** Get the security parameter from the security outcome at the provided index
1000-
* @param[in] self security outcome
1001-
* @param[in] index index to retrieve security parameter from
1002-
* @return Security parameter
1003-
*/
1004-
const BSL_IdValPair_t *BSL_SecOutcome_GetParamAt(const BSL_SecOutcome_t *self, size_t index);
1005-
1006973
/**
1007974
* @return size of security operation
1008975
*/
@@ -1134,40 +1101,6 @@ const BSL_SecurityAction_t *BSL_SecurityActionSet_GetActionAtIndex(const BSL_Sec
11341101
*/
11351102
size_t BSL_SecurityActionSet_CountErrors(const BSL_SecurityActionSet_t *self);
11361103

1137-
/// @brief Returns size of this struct type
1138-
size_t BSL_SecurityResponseSet_Sizeof(void);
1139-
1140-
/** Initialize with the given count of operations and failures
1141-
*
1142-
*/
1143-
void BSL_SecurityResponseSet_Init(BSL_SecurityResponseSet_t *self);
1144-
1145-
/** Zeroize itself and release any owned resources
1146-
*
1147-
* @param[in,out] self This response set.
1148-
*/
1149-
void BSL_SecurityResponseSet_Deinit(BSL_SecurityResponseSet_t *self);
1150-
1151-
/** Return true if internal consistency checks pass.
1152-
*
1153-
* @param[in] self This response set.
1154-
*/
1155-
bool BSL_SecurityResponseSet_IsConsistent(const BSL_SecurityResponseSet_t *self);
1156-
1157-
/** Return number of responses (operations acted upon)
1158-
*
1159-
* @param[in] self This response set.
1160-
*/
1161-
size_t BSL_SecurityResponseSet_CountResponses(const BSL_SecurityResponseSet_t *self);
1162-
1163-
/** Append a result code to the security response set
1164-
* @param[in,out] self the response set to append result to
1165-
* @param[in] result the result code to append
1166-
* @param[in] policy_action the on-failure policy action associated with the response
1167-
*/
1168-
void BSL_SecurityResponseSet_AppendResult(BSL_SecurityResponseSet_t *self, int64_t result,
1169-
BSL_PolicyAction_e policy_action);
1170-
11711104
/** Queries the policy provider for any security operations to take on the bundle.
11721105
*
11731106
* @note The caller is obligated to allocate space for the policy_action_set output.
@@ -1194,12 +1127,11 @@ int BSL_PolicyRegistry_InspectActions(const BSL_LibCtx_t *bsl, BSL_SecurityActio
11941127
* @param[in] policy_actions A policy action set, which may contain error codes and other info. @preallocated
11951128
* Caller-allocated, zeroed space for action set
11961129
* @param[in,out] bundle Bundle seeking security operations
1197-
* @param[in] response_output results from security context
11981130
* @param[in] location Where in the BPA lifecycle this query arises from
11991131
* @return 0 if success
12001132
*/
12011133
int BSL_PolicyRegistry_FinalizeActions(const BSL_LibCtx_t *bsl, const BSL_SecurityActionSet_t *policy_actions,
1202-
BSL_BundleRef_t *bundle, const BSL_SecurityResponseSet_t *response_output);
1134+
BSL_BundleRef_t *bundle);
12031135

12041136
/// @brief Callback interface to query policy provider to populate the action set
12051137
typedef int (*BSL_PolicyInspect_f)(void *user_data, BSL_SecurityActionSet_t *output_action_set,
@@ -1208,7 +1140,7 @@ typedef int (*BSL_PolicyInspect_f)(void *user_data, BSL_SecurityActionSet_t *out
12081140
/// @brief Callback interface to finalize policy provider over the action set. Finalize should ignore actions from
12091141
/// different policy providers
12101142
typedef int (*BSL_PolicyFinalize_f)(void *user_data, const BSL_SecurityActionSet_t *output_action_set,
1211-
BSL_BundleRef_t *bundle, const BSL_SecurityResponseSet_t *response_output);
1143+
BSL_BundleRef_t *bundle);
12121144

12131145
/// @brief Callback interface for policy provider to shut down and release any resources
12141146
typedef void (*BSL_PolicyDeinit_f)(void *user_data);
@@ -1225,13 +1157,12 @@ struct BSL_PolicyDesc_s
12251157
/** Call the underlying security context to perform the given action set
12261158
*
12271159
* @param[in] lib This BSL context
1228-
* @param[out] output_response Pointer to allocated, zeroed memory into which the response is populated
12291160
* @param[in,out] bundle Pointer to bundle, which may be modified.
12301161
* @param[in] action_set Action containing all params and operations.
12311162
* @return 0 on success, negative on failure.
12321163
*/
1233-
int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet_t *output_response,
1234-
BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *action_set);
1164+
int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle,
1165+
const BSL_SecurityActionSet_t *action_set);
12351166

12361167
/** Call the underlying security context to validate the given action set
12371168
*
@@ -1258,13 +1189,10 @@ typedef bool (*BSL_SecCtx_Validate_f)(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle
12581189
*
12591190
* @param[in] lib The library context.
12601191
* @param[in,out] bundle The bundle to modify.
1261-
* @param[in] sec_oper The security operation to perform.
1262-
* @param[in] asb For verifier or acceptor, this is the existing ASB structure.
1263-
* @param[in,out] sec_outcome The pre-allocated outcome to populate
1192+
* @param[in, out] sec_oper Security operation inputs and generated outputs.
12641193
* @return 0 if security operation performed successfully.
12651194
*/
1266-
typedef int (*BSL_SecCtx_Execute_f)(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, const BSL_SecOper_t *sec_oper,
1267-
BSL_SecOutcome_t *sec_outcome);
1195+
typedef int (*BSL_SecCtx_Execute_f)(BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle, BSL_SecOper_t *sec_oper);
12681196

12691197
/** @brief Security Context descriptor (interface)
12701198
*/
@@ -1280,22 +1208,22 @@ struct BSL_SecCtxDesc_s
12801208
* @warning This is exposed for testing only.
12811209
*/
12821210
int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle,
1283-
BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome);
1211+
BSL_SecOper_t *sec_oper);
12841212
/** Internal function to execute an operation as verifier or acceptor.
12851213
* @overload
12861214
*/
12871215
int BSL_ExecBIBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle,
1288-
BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome);
1216+
BSL_SecOper_t *sec_oper);
12891217
/** Internal function to execute an operation as source.
12901218
* @overload
12911219
*/
12921220
int BSL_ExecBCBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle,
1293-
BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome);
1221+
BSL_SecOper_t *sec_oper);
12941222
/** Internal function to execute an operation as verifier or acceptor.
12951223
* @overload
12961224
*/
12971225
int BSL_ExecBCBVerifierAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *lib, BSL_BundleRef_t *bundle,
1298-
BSL_SecOper_t *sec_oper, BSL_SecOutcome_t *outcome);
1226+
BSL_SecOper_t *sec_oper);
12991227

13001228
#ifdef __cplusplus
13011229
} // extern C

src/BPSecLib_Public.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ typedef struct BSL_LibCtx_s BSL_LibCtx_t;
5959
*/
6060
size_t BSL_LibCtx_Sizeof(void);
6161

62-
// Forward declaration of this struct.
63-
// This contains information for BSL and the host BPA to process the Bundle.
64-
typedef struct BSL_SecurityResponseSet_s BSL_SecurityResponseSet_t;
65-
6662
// Forward declaration of this struct.
6763
// This contains actions for BSL to process the Bundle.
6864
typedef struct BSL_SecurityActionSet_s BSL_SecurityActionSet_t;
@@ -555,13 +551,11 @@ int BSL_API_QuerySecurity(BSL_LibCtx_t *bsl, BSL_SecurityActionSet_t *output_act
555551
/** @brief Performs the given security operations on a Bundle, modifying or even dropping it entirely.
556552
*
557553
* @param[in] bsl Pointer to BSL context structure.
558-
* @param[out] response_output Pointer to host-allocated output structure.
559554
* @param[in,out] bundle Reference to host-owned Bundle, which may be modified or dropped by the BSL.
560555
* @param[in] policy_actions Pointer to policy actions, which was populated using the `QuerySecurity` function.
561556
*/
562557
BSL_REQUIRE_CHECK
563-
int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *response_output, BSL_BundleRef_t *bundle,
564-
const BSL_SecurityActionSet_t *policy_actions);
558+
int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *policy_actions);
565559

566560
#ifdef __cplusplus
567561
} // extern C

src/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ set(BSL_DYNAMIC_H
152152
${CMAKE_CURRENT_SOURCE_DIR}/backend/IdValPair.h
153153
${CMAKE_CURRENT_SOURCE_DIR}/backend/PublicInterfaceImpl.h
154154
${CMAKE_CURRENT_SOURCE_DIR}/backend/SecOperation.h
155-
${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityResultSet.h
156155
${CMAKE_CURRENT_SOURCE_DIR}/backend/UtilDefs_SeqReadWrite.h
157156
)
158157

@@ -165,11 +164,9 @@ set(BSL_DYNAMIC_C
165164
${CMAKE_CURRENT_SOURCE_DIR}/backend/PolicyProvider.c
166165
${CMAKE_CURRENT_SOURCE_DIR}/backend/TelemetryCounters.c
167166
${CMAKE_CURRENT_SOURCE_DIR}/backend/SecOperation.c
168-
${CMAKE_CURRENT_SOURCE_DIR}/backend/SecOutcome.c
169167
${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityAction.c
170168
${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityActionSet.c
171169
${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityContext.c
172-
${CMAKE_CURRENT_SOURCE_DIR}/backend/SecurityResultSet.c
173170
${CMAKE_CURRENT_SOURCE_DIR}/backend/TextUtil.c
174171
${CMAKE_CURRENT_SOURCE_DIR}/backend/UtilDefs_SeqReadWrite.c
175172
)
@@ -189,7 +186,7 @@ target_link_libraries(bsl_dynamic PUBLIC qcbor::qcbor)
189186
add_library(bsl_mock_bpa)
190187
#target_compile_options(bsl_mock_bpa PRIVATE -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls)
191188
target_sources(
192-
bsl_mock_bpa PUBLIC
189+
bsl_mock_bpa PUBLIC
193190
${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa/log.h
194191
${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa/agent.h
195192
${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa/bundle.h

src/backend/AbsSecBlock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ struct BSL_AbsSecBlock_s
115115
*/
116116
BSL_AbsSecBlock_Target_t *BSL_AbsSecBlock_AddTarget(BSL_AbsSecBlock_t *self, uint64_t target_block_num);
117117

118-
/** Remove security parameters and results found in `outcome` from this ASB
118+
/** Remove the target and its security results from this ASB
119119
*
120120
* @param[in,out] self This ASB
121-
* @param[in] outcome Security Operation outcome containing params and results
121+
* @param[in] target_block_num Block number of the target to remove
122122
* @return Negative on error, otherwise count of things removed.
123123
*/
124124
int BSL_AbsSecBlock_StripResults(BSL_AbsSecBlock_t *self, uint64_t target_block_num);

src/backend/PolicyProvider.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ int BSL_PolicyRegistry_InspectActions(const BSL_LibCtx_t *bsl, BSL_SecurityActio
6262
}
6363

6464
int BSL_PolicyRegistry_FinalizeActions(const BSL_LibCtx_t *bsl, const BSL_SecurityActionSet_t *policy_actions,
65-
BSL_BundleRef_t *bundle, const BSL_SecurityResponseSet_t *response_output)
65+
BSL_BundleRef_t *bundle)
6666
{
6767
CHK_ARG_NONNULL(bsl);
6868
CHK_ARG_NONNULL(bsl->policy_reg);
6969
CHK_ARG_NONNULL(policy_actions);
70-
CHK_ARG_NONNULL(response_output);
7170
CHK_ARG_NONNULL(bundle);
7271

7372
size_t act_ct = BSL_SecurityActionSet_CountActions(policy_actions);
@@ -76,7 +75,7 @@ int BSL_PolicyRegistry_FinalizeActions(const BSL_LibCtx_t *bsl, const BSL_Securi
7675
BSL_SecurityAction_t *act = BSL_SecActionList_get(policy_actions->actions, i);
7776

7877
const BSL_PolicyDesc_t *policy = BSL_PolicyDict_get(bsl->policy_reg, act->pp_id);
79-
if (BSL_SUCCESS != policy->finalize_fn(policy->user_data, policy_actions, bundle, response_output))
78+
if (BSL_SUCCESS != policy->finalize_fn(policy->user_data, policy_actions, bundle))
8079
{
8180
return BSL_ERR_POLICY_FINAL;
8281
}

src/backend/PublicInterfaceImpl.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,13 @@ int BSL_API_QuerySecurity(BSL_LibCtx_t *bsl, BSL_SecurityActionSet_t *output_act
211211
return BSL_SUCCESS;
212212
}
213213

214-
int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *response_output, BSL_BundleRef_t *bundle,
215-
const BSL_SecurityActionSet_t *policy_actions)
214+
int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_BundleRef_t *bundle, const BSL_SecurityActionSet_t *policy_actions)
216215
{
217216
CHK_ARG_NONNULL(bsl);
218-
CHK_ARG_NONNULL(response_output);
219217
CHK_ARG_NONNULL(bundle);
220218
CHK_ARG_NONNULL(policy_actions);
221219

222-
int exec_code = BSL_SecCtx_ExecutePolicyActionSet(bsl, response_output, bundle, policy_actions);
220+
int exec_code = BSL_SecCtx_ExecutePolicyActionSet(bsl, bundle, policy_actions);
223221
if (exec_code < BSL_SUCCESS)
224222
{
225223
BSL_LOG_ERR("Failed to execute policy action set");
@@ -248,7 +246,7 @@ int BSL_API_ApplySecurity(BSL_LibCtx_t *bsl, BSL_SecurityResponseSet_t *response
248246
}
249247
}
250248

251-
int finalize_status = BSL_PolicyRegistry_FinalizeActions(bsl, policy_actions, bundle, response_output);
249+
int finalize_status = BSL_PolicyRegistry_FinalizeActions(bsl, policy_actions, bundle);
252250
BSL_LOG_INFO("Completed finalize: status=%d", finalize_status);
253251

254252
return BSL_SUCCESS;

0 commit comments

Comments
 (0)