BSL v0.0.0
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
SecOperation.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 The Johns Hopkins University Applied Physics
3 * Laboratory LLC.
4 *
5 * This file is part of the Bundle Protocol Security Library (BSL).
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * This work was performed for the Jet Propulsion Laboratory, California
18 * Institute of Technology, sponsored by the United States Government under
19 * the prime contract 80NM0018D0004 between the Caltech and NASA under
20 * subcontract 1700763.
21 */
27#include "SecOperation.h"
28#include "SecParam.h"
29
30size_t BSL_SecOper_Sizeof(void)
31{
32 return sizeof(BSL_SecOper_t);
33}
34
35void BSL_SecOper_Init(BSL_SecOper_t *self, uint64_t context_id, uint64_t target_block_num, uint64_t sec_block_num,
36 BSL_SecBlockType_e sec_type, BSL_SecRole_e sec_role, BSL_PolicyAction_e failure_code)
37{
38 ASSERT_ARG_NONNULL(self);
39
40 memset(self, 0, sizeof(*self));
41 BSLB_SecParamList_init(self->_param_list);
42 self->context_id = context_id;
43 self->target_block_num = target_block_num;
44 self->sec_block_num = sec_block_num;
45 self->failure_code = failure_code;
46 self->_service_type = sec_type;
47 self->_role = sec_role;
48
49 ASSERT_POSTCONDITION(BSL_SecOper_IsConsistent(self));
50}
51
53{
54 ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self));
55 BSLB_SecParamList_clear(self->_param_list);
56 memset(self, 0, sizeof(*self));
57}
58
60{
61 ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self));
62
63 return BSLB_SecParamList_size(self->_param_list);
64}
65
67{
68 // NOLINTBEGIN
69 CHK_AS_BOOL(self != NULL);
70 CHK_AS_BOOL(self->context_id > 0);
71 CHK_AS_BOOL(self->target_block_num < 10000);
72 // CHK_AS_BOOL(self->sec_block_num > 0);
73 CHK_AS_BOOL(self->_service_type == BSL_SECBLOCKTYPE_BCB || self->_service_type == BSL_SECBLOCKTYPE_BIB);
74 CHK_AS_BOOL(self->_role == BSL_SECROLE_ACCEPTOR || self->_role == BSL_SECROLE_VERIFIER
75 || self->_role == BSL_SECROLE_SOURCE);
76 CHK_AS_BOOL(BSLB_SecParamList_size(self->_param_list) < 1000);
77 // NOLINTEND
78 return true;
79}
80
82{
83 ASSERT_ARG_EXPR(BSL_SecParam_IsConsistent(param));
84 ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self));
85
86 BSLB_SecParamList_push_back(self->_param_list, *param);
87
88 ASSERT_POSTCONDITION(BSL_SecOper_IsConsistent(self));
89}
90
92{
93 ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self));
94
95 return self->sec_block_num;
96}
97
99{
100 ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self));
101
102 return self->target_block_num;
103}
104
105const BSL_SecParam_t *BSL_SecOper_GetParamAt(const BSL_SecOper_t *self, size_t index)
106{
107 ASSERT_PRECONDITION(BSL_SecOper_IsConsistent(self));
108 ASSERT_PRECONDITION(index < BSLB_SecParamList_size(self->_param_list));
109
110 return BSLB_SecParamList_cget(self->_param_list, index);
111}
112
114{
115 ASSERT_PRECONDITION(self != NULL);
116 return self->_role == BSL_SECROLE_SOURCE;
117}
118
120{
121 ASSERT_PRECONDITION(self != NULL);
122 return self->_role == BSL_SECROLE_ACCEPTOR;
123}
124
126{
127 ASSERT_PRECONDITION(self != NULL);
128 return self->_service_type == BSL_SECBLOCKTYPE_BIB;
129}
BSL_SecBlockType_e
RFC 9172-specified block type codes for BIB and BCB.
@ BSL_SECBLOCKTYPE_BIB
RFC9172 code for BIB.
@ BSL_SECBLOCKTYPE_BCB
RFC9172 code for BCB.
BSL_PolicyAction_e
Codes indicating the fate of a block if a security operation over it fails.
struct BSL_SecOper_s BSL_SecOper_t
Represents a Security Operation produced by a policy provider to inform the security context.
BSL_SecRole_e
Security role of an operation.
@ BSL_SECROLE_SOURCE
Source producing the security result.
@ BSL_SECROLE_ACCEPTOR
Check and then remove the security result if correct.
@ BSL_SECROLE_VERIFIER
Only check the security result.
uint64_t BSL_SecOper_GetSecurityBlockNum(const BSL_SecOper_t *self)
Get the block number of the security block containing this sec operation.
bool BSL_SecOper_IsBIB(const BSL_SecOper_t *self)
Return true if this security operation is BIB.
void BSL_SecOper_Init(BSL_SecOper_t *self, uint64_t context_id, uint64_t target_block_num, uint64_t sec_block_num, BSL_SecBlockType_e sec_type, BSL_SecRole_e sec_role, BSL_PolicyAction_e failure_code)
Populate a pre-allocated Security Operation with the given values.
uint64_t BSL_SecOper_GetTargetBlockNum(const BSL_SecOper_t *self)
Get the block number of the target block covered by this security operation.
void BSL_SecOper_AppendParam(BSL_SecOper_t *self, const BSL_SecParam_t *param)
Add the given security parameter to this list of parameters.
size_t BSL_SecOper_CountParams(const BSL_SecOper_t *self)
Get the count of parameters contained within this security operation.
void BSL_SecOper_Deinit(BSL_SecOper_t *self)
Empty and release any resources used internally by this structure.
const BSL_SecParam_t * BSL_SecOper_GetParamAt(const BSL_SecOper_t *self, size_t index)
Returns a pointer to the Security Parameter at a given index in the list of all paramters.
bool BSL_SecOper_IsRoleSource(const BSL_SecOper_t *self)
Return true if this security operation's role is SOURCE.
bool BSL_SecOper_IsConsistent(const BSL_SecOper_t *self)
Returns true if internal consistency and sanity checks pass.
bool BSL_SecOper_IsRoleAccepter(const BSL_SecOper_t *self)
Return true if this security operation's role is Acceptor.
Defines a security operation.
bool BSL_SecParam_IsConsistent(const BSL_SecParam_t *self)
Return true if invariant conditions pass.
Definition SecParam.c:92
Defines the RFC 9172 Security Parameter of the Abstract Security Block.
uint64_t context_id
Security context ID.
uint64_t target_block_num
Bundle's block ID over which the security operation is applied.
BSL_SecRole_e _role
Private enumeration indicating the role (e.g., acceptor vs verifier)
uint64_t sec_block_num
Bundle's block ID which contains the security parameters and results for this operation.
BSL_PolicyAction_e failure_code
Code for handing what to do to the block or bundle if security processing fails.