interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / aienux / argus / bridge_test.om

271 lines · 6644 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/argus/bridge_test.om: Behavioral self-test for Pure-Omega ARGUS-AEGIS Bridge.
3note Compose with: si/directives/om2.om aienux/argus/event.om aienux/argus/contain.om aienux/argus/bridge.om aienux/argus/bridge_test.om om/tls/sha2.om
4
5text s_pass "PASS "
6text s_fail "FAIL "
7text s_nl "\n"
8text s_t1 "bridge_init_attach_and_observer_mint"
9text s_t2 "bridge_submit_grant_execute_confirm_lifecycle"
10text s_t3 "bridge_submit_protected_subject_denied"
11text s_t4 "bridge_submit_non_revoke_escalates_and_zero_mach_fallback"
12text s_t5 "bridge_budget_exhaustion_escalates"
13text s_t6 "bridge_findings_queue_fifo_and_unattached_refusal"
14text s_sum "ARGUS_BRIDGE_TEST_PASS total=6 failed=0\n"
15text s_fsum "ARGUS_BRIDGE_TEST_FAIL\n"
16
17fn brt_write_all fd int buf view uchar * to bool
18total = len buf
19off = ulong 0
20while lt off total bound 4096
21n = write fd buf off sub total off
22if le n 0
23ret false
24end
25off = add off ulong n
26end
27ret true
28end
29
30fn brt_report name view uchar * ok bool to uint
31if ok
32w1 = brt_write_all 1 s_pass
33w2 = brt_write_all 1 name
34w3 = brt_write_all 1 s_nl
35if and w1 and w2 w3
36ret 0
37end
38ret 1
39end
40w1 = brt_write_all 1 s_fail
41w2 = brt_write_all 1 name
42w3 = brt_write_all 1 s_nl
43if and w1 and w2 w3
44ret 1
45end
46ret 1
47end
48
49fn brt_setup mach edit uchar 32 to void
50for i ulong 32
51put mach i uchar add 10 i
52end
53argus_core_init
54argus_contain_init
55rc1 = argus_bridge_init mach
56rc2 = argus_bridge_attach_gate
57argus_bridge_set_clock 100
58if or ne rc1 ARGUS_OK ne rc2 ARGUS_OK
59trap 8
60end
61end
62
63fn test_1_observer_mint to bool
64mach = new uchar 32 0
65brt_setup mach
66argus_bridge_observer BRIDGE_OBS_MINT 5 1 77 3 999
67if ne argus_bridge_error ARGUS_OK
68ret false
69end
70if ne get argus_sh_state 5 ARGUS_SH_LIVE
71ret false
72end
73if ne get argus_sh_subj 5 77
74ret false
75end
76if ne argus_bridge_finding_count 0
77ret false
78end
79ret true
80end
81
82fn test_2_grant_execute_confirm to bool
83mach = new uchar 32 0
84brt_setup mach
85argus_bridge_observer BRIDGE_OBS_MINT 3 10 55 1 500
86fdig = new uchar 32 1
87tdig = new uchar 32 2
88dig = new uchar 32 0
89req = new ArgusContainReq 1 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_CRITICAL ARGUS_F_REVOKED_CAPABILITY_USED 55 3 10 0 1 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
90prc = argus_contain_propose req mach fdig tdig dig
91if ne prc ARGUS_OK
92ret false
93end
94src = argus_bridge_submit req mach fdig tdig
95if ne src ARGUS_OK
96ret false
97end
98if ne argus_bridge_last_decision ARGUS_CSTATUS_GRANT
99ret false
100end
101if ne argus_bridge_last_exec_status ARGUS_CSTATUS_DONE
102ret false
103end
104if ne get argus_sh_state 3 ARGUS_SH_REVOKED
105ret false
106end
107h = new ArgusContainHealth 0 0 0 0 0 0 0 0 0 0
108argus_contain_health h
109if ne get h confirmed 1
110ret false
111end
112if ne argus_bridge_finding_count 0
113ret false
114end
115ret true
116end
117
118fn test_3_protected_denied to bool
119mach = new uchar 32 0
120brt_setup mach
121argus_bridge_observer BRIDGE_OBS_MINT 4 20 BRIDGE_SUBJ_AEGIS 1 600
122fdig = new uchar 32 3
123tdig = new uchar 32 4
124dig = new uchar 32 0
125req = new ArgusContainReq 2 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_HIGH ARGUS_F_FORGED_CAPABILITY BRIDGE_SUBJ_AEGIS 4 20 0 2 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
126prc = argus_contain_propose req mach fdig tdig dig
127if ne prc ARGUS_OK
128ret false
129end
130src = argus_bridge_submit req mach fdig tdig
131if ne src ARGUS_OK
132ret false
133end
134if ne argus_bridge_last_decision ARGUS_CSTATUS_DENY
135ret false
136end
137if ne argus_bridge_last_why BRIDGE_WHY_PROTECTED
138ret false
139end
140if ne get argus_sh_state 4 ARGUS_SH_LIVE
141ret false
142end
143h = new ArgusContainHealth 0 0 0 0 0 0 0 0 0 0
144argus_contain_health h
145if ne get h denied 1
146ret false
147end
148ret true
149end
150
151fn test_4_non_revoke_escalate_zero_mach to bool
152mach = new uchar 32 0
153brt_setup mach
154zmach = new uchar 32 0
155fdig = new uchar 32 5
156tdig = new uchar 32 9
157dig = new uchar 32 0
158req = new ArgusContainReq 3 ARGUS_CONTAIN_FREEZE_PRINCIPAL ARGUS_SEV_HIGH ARGUS_F_FORGED_CAPABILITY 88 ARGUS_CAP_NONE 0 0 3 0 0 ARGUS_CREQ_SYNTHETIC ARGUS_CONTAIN_REQ_VERSION 0
159prc = argus_contain_propose req zmach fdig tdig dig
160if ne prc ARGUS_OK
161ret false
162end
163src = argus_bridge_submit req zmach fdig tdig
164if ne src ARGUS_OK
165ret false
166end
167if ne argus_bridge_last_decision ARGUS_CSTATUS_ESCALATE
168ret false
169end
170if ne argus_bridge_last_why BRIDGE_WHY_NO_EXECUTOR
171ret false
172end
173h = new ArgusContainHealth 0 0 0 0 0 0 0 0 0 0
174argus_contain_health h
175if ne get h escalated 1
176ret false
177end
178ret true
179end
180
181fn test_5_budget_exhaustion to bool
182mach = new uchar 32 0
183brt_setup mach
184fdig = new uchar 32 6
185tdig = new uchar 32 7
186dig = new uchar 32 0
187req = new ArgusContainReq 1 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_CRITICAL ARGUS_F_REVOKED_CAPABILITY_USED 90 10 1 0 1 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
188i = uint 0
189while lt i 9 bound 10
190cid = add i 10
191argus_bridge_observer BRIDGE_OBS_MINT cid 1 90 1 100
192put req incident_id ulong add i 1
193put req target_cap_id cid
194put req request_id 0
195put req finding_sequence ulong add i 1
196prc = argus_contain_propose req mach fdig tdig dig
197if ne prc ARGUS_OK
198ret false
199end
200src = argus_bridge_submit req mach fdig tdig
201if ne src ARGUS_OK
202ret false
203end
204if lt i 8
205if ne argus_bridge_last_decision ARGUS_CSTATUS_GRANT
206ret false
207end
208else
209if ne argus_bridge_last_decision ARGUS_CSTATUS_ESCALATE
210ret false
211end
212if ne argus_bridge_last_why BRIDGE_WHY_BUDGET
213ret false
214end
215end
216i = add i 1
217end
218ret true
219end
220
221fn test_6_findings_fifo_and_unattached to bool
222mach = new uchar 32 0
223brt_setup mach
224ev = new ArgusEvent ARGUS_ABI_VERSION ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USED ARGUS_EFFECT_NONE ARGUS_OUTCOME_OK 0 1 10 44 0 99 0 1 0 123
225evdig = new uchar 32 0
226irc = argus_bridge_ingest ev mach evdig
227if ne irc ARGUS_OK
228ret false
229end
230if ne argus_bridge_finding_count 1
231ret false
232end
233f = new ArgusFinding 0 0 0 0 0 0 0 0 0 0 0
234got = argus_bridge_take_finding f
235if not got
236ret false
237end
238if ne get f code ARGUS_F_FORGED_CAPABILITY
239ret false
240end
241if ne argus_bridge_finding_count 0
242ret false
243end
244argus_bridge_destroy
245tdig = new uchar 32 0
246req = new ArgusContainReq 9 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_HIGH ARGUS_F_FORGED_CAPABILITY 55 1 1 1 1 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
247src = argus_bridge_submit req mach evdig tdig
248if ne src ARGUS_ERR_ARG
249ret false
250end
251ret true
252end
253
254fn main to int
255fails = uint 0
256fails = add fails brt_report s_t1 test_1_observer_mint
257fails = add fails brt_report s_t2 test_2_grant_execute_confirm
258fails = add fails brt_report s_t3 test_3_protected_denied
259fails = add fails brt_report s_t4 test_4_non_revoke_escalate_zero_mach
260fails = add fails brt_report s_t5 test_5_budget_exhaustion
261fails = add fails brt_report s_t6 test_6_findings_fifo_and_unattached
262if eq fails 0
263ok = brt_write_all 1 s_sum
264if ok
265ret 0
266end
267ret 1
268end
269ok = brt_write_all 1 s_fsum
270ret 1
271end