@@ -101,7 +101,8 @@ static int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *
101101
102102 CHK_PROPERTY (created_block_num > 1 );
103103
104- const int bib_result = (* sec_context_fn )(lib , bundle , sec_oper , outcome );
104+ sec_oper -> sec_block_num = created_block_num ;
105+ const int bib_result = (* sec_context_fn )(lib , bundle , sec_oper , outcome );
105106 if (bib_result != 0 ) // || outcome->is_success == false)
106107 {
107108 BSL_LOG_ERR ("BIB Source failed!" );
@@ -151,8 +152,8 @@ static int BSL_ExecBIBSource(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *
151152 return res ;
152153}
153154
154- static int BSL_ExecBIBAccept (BSL_SecCtx_Execute_f sec_context_fn , BSL_LibCtx_t * lib , BSL_BundleRef_t * bundle ,
155- BSL_SecOper_t * sec_oper , BSL_SecOutcome_t * outcome )
155+ static int BSL_ExecBIBVerifierAcceptor (BSL_SecCtx_Execute_f sec_context_fn , BSL_LibCtx_t * lib , BSL_BundleRef_t * bundle ,
156+ BSL_SecOper_t * sec_oper , BSL_SecOutcome_t * outcome )
156157{
157158 CHK_ARG_NONNULL (lib );
158159 CHK_ARG_NONNULL (bundle );
@@ -201,76 +202,70 @@ static int BSL_ExecBIBAccept(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t *
201202 const int sec_context_result = (* sec_context_fn )(lib , bundle , sec_oper , outcome );
202203 if (sec_context_result != BSL_SUCCESS ) // || outcome->is_success == false)
203204 {
204- BSL_LOG_ERR ("BIB Acceptor failed!" );
205+ BSL_LOG_ERR ("BIB Sec Ctx processing for verifier/acceptor failed!" );
205206 BSL_AbsSecBlock_Deinit (& abs_sec_block );
206207 BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
207208 return BSL_ERR_SECURITY_OPERATION_FAILED ;
208209 }
209210
210- bool auth_success = BSL_SecOutcome_IsInAbsSecBlock (outcome , & abs_sec_block );
211- if (!auth_success )
211+ if (!BSL_SecOutcome_IsInAbsSecBlock (outcome , & abs_sec_block ))
212212 {
213- BSL_LOG_ERR ("BIB Accepting failed" );
213+ BSL_LOG_ERR ("ASB Does not contain expeceted sec params and outcomes" );
214+ BSL_AbsSecBlock_Deinit (& abs_sec_block );
214215 BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
216+ return BSL_ERR_SECURITY_OPERATION_FAILED ;
217+ }
218+
219+ // If secop is to verify, processing is complete
220+ if (BSL_SecOper_IsRoleVerifier (sec_oper ))
221+ {
222+ BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_VERIFIER_COUNT , 1 );
223+ BSL_AbsSecBlock_Deinit (& abs_sec_block );
224+ return BSL_SUCCESS ;
215225 }
216226
217227 // TODO/FIXME - This logic seems to be correct, but should be refactored and simplified.
218228 // There are too many branches/conditionals each with their own return statement.
219229
220- if (BSL_SecOper_IsRoleAcceptor (sec_oper ))
230+ // If secop is to accept, BIB must be removed from bundle
231+ uint64_t target_block_num = BSL_SecOper_GetTargetBlockNum (sec_oper );
232+ int status = BSL_AbsSecBlock_StripResults (& abs_sec_block , target_block_num );
233+ if (status < 0 )
221234 {
222- uint64_t target_block_num = BSL_SecOper_GetTargetBlockNum (sec_oper );
223- int status = BSL_AbsSecBlock_StripResults (& abs_sec_block , target_block_num );
224- if (status < 0 )
235+ BSL_LOG_ERR ("Failure to strip ASB of results" );
236+ BSL_AbsSecBlock_Deinit (& abs_sec_block );
237+ BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
238+ return BSL_ERR_FAILURE ;
239+ }
240+
241+ if (BSL_AbsSecBlock_IsEmpty (& abs_sec_block ))
242+ {
243+ if (BSL_BundleCtx_RemoveBlock (bundle , sec_blk .block_num ) != BSL_SUCCESS )
225244 {
226- BSL_LOG_ERR ("Failure to strip ASB of results " );
245+ BSL_LOG_ERR ("Failed to remove block when ASB is empty " );
227246 BSL_AbsSecBlock_Deinit (& abs_sec_block );
228247 BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
229- return BSL_ERR_FAILURE ;
248+ return BSL_ERR_HOST_CALLBACK_FAILED ;
230249 }
231-
232- if (BSL_AbsSecBlock_IsEmpty (& abs_sec_block ))
233- {
234- if (BSL_BundleCtx_RemoveBlock (bundle , sec_blk .block_num ) != BSL_SUCCESS )
235- {
236- BSL_LOG_ERR ("Failed to remove block when ASB is empty" );
237- BSL_AbsSecBlock_Deinit (& abs_sec_block );
238- BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
239- return BSL_ERR_HOST_CALLBACK_FAILED ;
240- }
241- }
242- else
243- {
244- int res = Encode_ASB (lib , bundle , sec_blk .block_num , & abs_sec_block );
245- if (res != BSL_SUCCESS )
246- {
247- BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
248- return res ;
249- }
250- }
251- BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_ACCEPTOR_COUNT , 1 );
252- }
253-
254- BSL_AbsSecBlock_Deinit (& abs_sec_block );
255-
256- // TODO(bvb) Check postconditions that the block actually was removed
257- if (auth_success )
258- {
259- BSL_LOG_INFO ("BIB Accept SUCCESS" );
260250 }
261251 else
262252 {
263- BSL_LOG_ERR ("BIB Accept FAIL" );
264- BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
253+ int res = Encode_ASB (lib , bundle , sec_blk .block_num , & abs_sec_block );
254+ if (res != BSL_SUCCESS )
255+ {
256+ BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
257+ return res ;
258+ }
265259 }
260+ BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_ACCEPTOR_COUNT , 1 );
261+ BSL_AbsSecBlock_Deinit (& abs_sec_block );
266262
267- return auth_success ? BSL_SUCCESS : BSL_ERR_SECURITY_OPERATION_FAILED ;
263+ return BSL_SUCCESS ;
268264}
269265
270- static int BSL_ExecBCBAcceptor (BSL_SecCtx_Execute_f sec_context_fn , BSL_LibCtx_t * lib , BSL_BundleRef_t * bundle ,
271- BSL_SecOper_t * sec_oper , BSL_SecOutcome_t * outcome )
266+ static int BSL_ExecBCBVerifierAcceptor (BSL_SecCtx_Execute_f sec_context_fn , BSL_LibCtx_t * lib , BSL_BundleRef_t * bundle ,
267+ BSL_SecOper_t * sec_oper , BSL_SecOutcome_t * outcome )
272268{
273- (void )lib ;
274269 CHK_ARG_NONNULL (sec_context_fn );
275270 CHK_ARG_NONNULL (bundle );
276271 CHK_ARG_NONNULL (sec_oper );
@@ -319,7 +314,7 @@ static int BSL_ExecBCBAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t
319314 BSL_SecParam_t results_as_params [result_count ];
320315 for (size_t i = 0 ; i < result_count ; i ++ )
321316 {
322- BSL_SecResult_t * result = BSLB_SecResultList_get (abs_sec_block .results , i );
317+ const BSL_SecResult_t * result = BSLB_SecResultList_get (abs_sec_block .results , i );
323318 if (result -> target_block_num == sec_oper -> target_block_num )
324319 {
325320 BSL_Data_t as_data ;
@@ -332,62 +327,61 @@ static int BSL_ExecBCBAcceptor(BSL_SecCtx_Execute_f sec_context_fn, BSL_LibCtx_t
332327 }
333328
334329 const int sec_context_result = (* sec_context_fn )(lib , bundle , sec_oper , outcome );
335- if (sec_context_result != BSL_SUCCESS ) // || outcome->is_success == false)
330+ if (sec_context_result != BSL_SUCCESS )
336331 {
337- BSL_LOG_ERR ("BCB Acceptor failed!" );
332+ BSL_LOG_ERR ("BCB Sec Ctx processing for verifier/acceptor failed!" );
338333 BSL_AbsSecBlock_Deinit (& abs_sec_block );
339334 BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
340335 return BSL_ERR_SECURITY_OPERATION_FAILED ;
341336 }
342337
343- // TODO/FIXME - This logic seems to be correct, but should be refactored and simplified.
344- // There are too many branches/conditionals each with their own return statement.
338+ // If secop is to verify, processing is complete
339+ if (BSL_SecOper_IsRoleVerifier (sec_oper ))
340+ {
341+ BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_VERIFIER_COUNT , 1 );
342+ BSL_AbsSecBlock_Deinit (& abs_sec_block );
343+ return BSL_SUCCESS ;
344+ }
345+
346+ // If secop is to accept, BCB must be removed from bundle
347+ uint64_t target_block_num = BSL_SecOper_GetTargetBlockNum (sec_oper );
348+ int status = BSL_AbsSecBlock_StripResults (& abs_sec_block , target_block_num );
349+ if (status < 0 )
350+ {
351+ BSL_LOG_ERR ("Failure to strip ASB of results" );
352+ BSL_AbsSecBlock_Deinit (& abs_sec_block );
353+ BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
354+ return BSL_ERR_FAILURE ;
355+ }
345356
346- if (BSL_SecOper_IsRoleAcceptor ( sec_oper ))
357+ if (BSL_AbsSecBlock_IsEmpty ( & abs_sec_block ))
347358 {
348- uint64_t target_block_num = BSL_SecOper_GetTargetBlockNum (sec_oper );
349- int status = BSL_AbsSecBlock_StripResults (& abs_sec_block , target_block_num );
350- if (status < 0 )
359+ if (BSL_BundleCtx_RemoveBlock (bundle , sec_blk .block_num ) != BSL_SUCCESS )
351360 {
352- BSL_LOG_ERR ("Failure to strip ASB of results " );
361+ BSL_LOG_ERR ("Failed to remove block when ASB is empty " );
353362 BSL_AbsSecBlock_Deinit (& abs_sec_block );
354363 BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
355- return BSL_ERR_FAILURE ;
364+ return BSL_ERR_HOST_CALLBACK_FAILED ;
356365 }
357-
358- if (BSL_AbsSecBlock_IsEmpty (& abs_sec_block ))
359- {
360- if (BSL_BundleCtx_RemoveBlock (bundle , sec_blk .block_num ) != BSL_SUCCESS )
361- {
362- BSL_LOG_ERR ("Failed to remove block when ASB is empty" );
363- BSL_AbsSecBlock_Deinit (& abs_sec_block );
364- BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
365- return BSL_ERR_HOST_CALLBACK_FAILED ;
366- }
367- }
368- else
366+ }
367+ else
368+ {
369+ int res = Encode_ASB (lib , bundle , sec_blk .block_num , & abs_sec_block );
370+ if (res != BSL_SUCCESS )
369371 {
370- int res = Encode_ASB (lib , bundle , sec_blk .block_num , & abs_sec_block );
371- if (res != BSL_SUCCESS )
372- {
373- BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
374- return res ;
375- }
372+ BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_FAIL_COUNT , 1 );
373+ return res ;
376374 }
377- BSL_TlmCounters_IncrementCounter (lib , BSL_TLM_SECOP_ACCEPTOR_COUNT , 1 );
378375 }
379-
376+ BSL_TlmCounters_IncrementCounter ( lib , BSL_TLM_SECOP_ACCEPTOR_COUNT , 1 );
380377 BSL_AbsSecBlock_Deinit (& abs_sec_block );
381378
382- // TODO(bvb) Check postconditions that the block actually was removed
383379 return BSL_SUCCESS ;
384380}
385381
386382static int BSL_ExecBCBSource (BSL_SecCtx_Execute_f sec_context_fn , BSL_LibCtx_t * lib , BSL_BundleRef_t * bundle ,
387383 BSL_SecOper_t * sec_oper , BSL_SecOutcome_t * outcome )
388384{
389- (void )lib ;
390-
391385 CHK_ARG_NONNULL (sec_context_fn );
392386 CHK_ARG_NONNULL (bundle );
393387 CHK_ARG_NONNULL (sec_oper );
@@ -497,7 +491,7 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet
497491 {
498492 errcode = BSL_SecOper_IsRoleSource (sec_oper ) == true
499493 ? BSL_ExecBIBSource (sec_ctx -> execute , lib , bundle , sec_oper , outcome )
500- : BSL_ExecBIBAccept (sec_ctx -> execute , lib , bundle , sec_oper , outcome );
494+ : BSL_ExecBIBVerifierAcceptor (sec_ctx -> execute , lib , bundle , sec_oper , outcome );
501495 }
502496 else
503497 {
@@ -507,7 +501,7 @@ int BSL_SecCtx_ExecutePolicyActionSet(BSL_LibCtx_t *lib, BSL_SecurityResponseSet
507501 }
508502 else
509503 {
510- errcode = BSL_ExecBCBAcceptor (sec_ctx -> execute , lib , bundle , sec_oper , outcome );
504+ errcode = BSL_ExecBCBVerifierAcceptor (sec_ctx -> execute , lib , bundle , sec_oper , outcome );
511505 }
512506 }
513507
0 commit comments