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 / aegis / aegis_test.om

416 lines · 11831 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/aegis/aegis_test.om: Pure-Omega test suite for AIENOS AEGIS
3note (Capability Graph, Path Confinement, Intent/Grant Crypto, J-Space Worlds, Policy & Broker).
4note Compose with: si/directives/om2.om om/tls/sha2.om aienux/aegis/aegis.om aienux/aegis/aegis_test.om
5
6text a_pass "PASS "
7text a_fail "FAIL "
8text a_nl "\n"
9text a_t01 "aegis_lexical_path_confinement"
10text a_t02 "aegis_cap_issue_sig_tamper_and_expiry"
11text a_t03 "aegis_attenuated_delegation_and_depth_limit"
12text a_t04 "aegis_cascading_subtree_revocation"
13text a_t05 "aegis_intent_boundaries_and_operator_grant_crypto"
14text a_t06 "aegis_standing_fetch_fs_read_and_negatives"
15text a_t07 "aegis_high_impact_boundary_requires_grant"
16text a_t08 "aegis_jspace_world_delta_and_rollback"
17text a_t09 "aegis_broker_audit_ledger_integrity"
18text a_t10 "aegis_mutant_control_skip_grant_caught"
19text a_sum "AEGIS_TEST_PASS total=10 failed=0\n"
20text a_fsum "AEGIS_TEST_FAIL\n"
21
22text p_ws "/workspace"
23text p_ws_eq "/workspace"
24text p_ws_sub "/workspace/project/file.om"
25text p_ws_sub2 "/workspace/project"
26text p_ws_sib "/workspace2/file.om"
27text p_ws_trav "/workspace/../etc/passwd"
28text p_rel "workspace/file.om"
29text p_root "/"
30text p_etc "/etc/passwd"
31text p_host_ok "interplane.io"
32text p_host_bad "evil.example"
33text p_host_star "*"
34text p_op_drake "operator-drake"
35text p_k_ab "ab"
36text p_v_c "c"
37text p_k_a "a"
38text p_v_bc "bc"
39text p_dev_nvme "/dev/nvme0n1"
40text p_empty ""
41
42fn awrite_all fd int buf view uchar * to bool
43total = len buf
44off = ulong 0
45while lt off total bound 4096
46n = write fd buf off sub total off
47if le n 0
48ret false
49end
50off = add off ulong n
51end
52ret true
53end
54
55fn areport name view uchar * ok bool to uint
56if ok
57w1 = awrite_all 1 a_pass
58w2 = awrite_all 1 name
59w3 = awrite_all 1 a_nl
60if and w1 and w2 w3
61ret 0
62end
63ret 1
64end
65w1 = awrite_all 1 a_fail
66w2 = awrite_all 1 name
67w3 = awrite_all 1 a_nl
68if and w1 and w2 w3
69ret 1
70end
71ret 1
72end
73
74fn init_test_aegis op_sec edit uchar 32 cap_sec edit uchar 32 to void
75for i ulong 32
76put op_sec i uchar add 0x10 and i 0x3f
77put cap_sec i uchar add 0x80 and i 0x3f
78end
79aegis_reset op_sec cap_sec
80end
81
82fn test_a01_path_within to bool
83if not aegis_path_within p_ws_sub p_ws
84ret false
85end
86if not aegis_path_within p_ws_eq p_ws
87ret false
88end
89if not aegis_path_within p_ws_sub p_root
90ret false
91end
92note Prefix sibling /workspace2 must NOT match /workspace
93if aegis_path_within p_ws_sib p_ws
94ret false
95end
96note Parent-dir traversal .. must be rejected
97if aegis_path_within p_ws_trav p_ws
98ret false
99end
100note Relative path must be rejected
101if aegis_path_within p_rel p_ws
102ret false
103end
104ret true
105end
106
107fn test_a02_cap_sig_and_expiry to bool
108op = new uchar 32 0
109cs = new uchar 32 0
110init_test_aegis op cs
111s = aegis_cap_issue 100 AEGIS_SCOPE_FS 0 0 1000
112if lt s 0
113ret false
114end
115su = ulong s
116aegis_cap_set_strings su p_ws part p_empty 0 0
117note Valid before expiry
118if ne aegis_cap_validate su 500 AEGIS_OK
119ret false
120end
121note Expired at 1001
122if ne aegis_cap_validate su 1001 AEGIS_ERR_EXPIRED
123ret false
124end
125note Tamper 1 byte of stored signature -> must fail AEGIS_ERR_BAD_SIG
126sb = mul su 32
127put aegis_cap_sig sb xor get aegis_cap_sig sb 0x01
128if ne aegis_cap_validate su 500 AEGIS_ERR_BAD_SIG
129ret false
130end
131ret true
132end
133
134fn test_a03_delegation_attenuation to bool
135op = new uchar 32 0
136cs = new uchar 32 0
137init_test_aegis op cs
138note Root RW cap on /workspace
139r = aegis_cap_issue 100 AEGIS_SCOPE_FS 0 0 0
140if lt r 0
141ret false
142end
143ru = ulong r
144aegis_cap_set_strings ru p_ws part p_empty 0 0
145note Attenuate to subdir /workspace/project, RO=1 -> OK
146c1 = aegis_cap_delegate_scoped ru 200 AEGIS_SCOPE_FS 1 p_ws_sub2
147if lt c1 0
148ret false
149end
150note Attempt RO -> RW escalation from c1 -> REFUSED
151if ne aegis_cap_delegate_scoped ulong c1 300 AEGIS_SCOPE_FS 0 p_ws_sub2 AEGIS_ERR_SCOPE
152ret false
153end
154note Attempt directory escape /etc/passwd -> REFUSED
155if ne aegis_cap_delegate_scoped ru 300 AEGIS_SCOPE_FS 1 p_etc AEGIS_ERR_SCOPE
156ret false
157end
158note Chain up to max depth (4), 5th delegation -> AEGIS_ERR_DEPTH
159c2 = aegis_cap_delegate_scoped ulong c1 201 AEGIS_SCOPE_FS 1 p_ws_sub2
160c3 = aegis_cap_delegate_scoped ulong c2 202 AEGIS_SCOPE_FS 1 p_ws_sub2
161c4 = aegis_cap_delegate_scoped ulong c3 203 AEGIS_SCOPE_FS 1 p_ws_sub2
162if or lt c2 0 or lt c3 0 lt c4 0
163ret false
164end
165if ne aegis_cap_delegate_scoped ulong c4 204 AEGIS_SCOPE_FS 1 p_ws_sub2 AEGIS_ERR_DEPTH
166ret false
167end
168ret true
169end
170
171fn test_a04_subtree_revocation to bool
172op = new uchar 32 0
173cs = new uchar 32 0
174init_test_aegis op cs
175root = aegis_cap_issue 100 AEGIS_SCOPE_FS 0 0 0
176aegis_cap_set_strings ulong root p_ws part p_empty 0 0
177sib = aegis_cap_issue 101 AEGIS_SCOPE_FS 1 0 0
178aegis_cap_set_strings ulong sib p_ws part p_empty 0 0
179child = aegis_cap_delegate_scoped ulong root 200 AEGIS_SCOPE_FS 0 p_ws_sub2
180gchild = aegis_cap_delegate_scoped ulong child 300 AEGIS_SCOPE_FS 1 p_ws_sub2
181if or lt child 0 lt gchild 0
182ret false
183end
184if ne aegis_cap_revoke ulong root AEGIS_OK
185ret false
186end
187if ne aegis_cap_validate ulong root 0 AEGIS_ERR_REVOKED
188ret false
189end
190if ne aegis_cap_validate ulong child 0 AEGIS_ERR_REVOKED
191ret false
192end
193if ne aegis_cap_validate ulong gchild 0 AEGIS_ERR_REVOKED
194ret false
195end
196note Unrelated sibling remains valid
197if ne aegis_cap_validate ulong sib 0 AEGIS_OK
198ret false
199end
200ret true
201end
202
203fn test_a05_intent_and_grant_crypto to bool
204op = new uchar 32 0
205cs = new uchar 32 0
206bad = new uchar 32 0x77
207init_test_aegis op cs
208note Parameter boundary separation: ("ab","c") != ("a","bc")
209aegis_intent_hash_kv 42 p_k_ab p_v_c
210id1 = new uchar 16 0
211for i ulong 16
212put id1 i get aegis_cur_iid i
213end
214aegis_intent_hash_kv 42 p_k_a p_v_bc
215id2 = new uchar 16 0
216for j ulong 16
217put id2 j get aegis_cur_iid j
218end
219if aegis_eq16 id1 id2
220ret false
221end
222note Valid grant verifies
223aegis_grant_issue_with_secret p_op_drake 1700000000 op
224if ne aegis_grant_verify_current AEGIS_OK
225ret false
226end
227note Grant signed with wrong secret rejected
228aegis_grant_issue_with_secret p_op_drake 1700000000 bad
229if ne aegis_grant_verify_current AEGIS_ERR_GRANT_SIG
230ret false
231end
232note Grant for different intent rejected
233aegis_grant_issue_with_secret p_op_drake 1700000000 op
234put aegis_cur_iid 0 xor get aegis_cur_iid 0 0xff
235if ne aegis_grant_verify_current AEGIS_ERR_GRANT_INTENT
236ret false
237end
238ret true
239end
240
241fn test_a06_standing_fetch_and_fs_read to bool
242op = new uchar 32 0
243cs = new uchar 32 0
244init_test_aegis op cs
245aegis_grant_clear
246sf = aegis_cap_issue 10 AEGIS_SCOPE_STANDING_FETCH 0 0 0
247aegis_cap_set_strings ulong sf p_host_ok part p_empty 0 0
248fs = aegis_cap_issue 10 AEGIS_SCOPE_FS 1 0 0
249aegis_cap_set_strings ulong fs p_ws part p_empty 0 0
250aegis_dispatch_ctx 0 0 100 0
251note StandingFetch to interplane.io approved autonomously without grant
252if ne aegis_broker_dispatch 10 ulong sf aegis_act_net_fetch p_host_ok AEGIS_OK
253ret false
254end
255note Wrong host refused
256if ne aegis_broker_dispatch 10 ulong sf aegis_act_net_fetch p_host_bad AEGIS_ERR_SCOPE
257ret false
258end
259note Wrong holder refused
260if ne aegis_broker_dispatch 99 ulong sf aegis_act_net_fetch p_host_ok AEGIS_ERR_HOLDER
261ret false
262end
263note fs.read within /workspace approved autonomously
264if ne aegis_broker_dispatch 10 ulong fs aegis_act_fs_read p_ws_sub AEGIS_OK
265ret false
266end
267note fs.write on RO cap refused by scope
268if ne aegis_broker_dispatch 10 ulong fs aegis_act_fs_write p_ws_sub AEGIS_ERR_SCOPE
269ret false
270end
271ret true
272end
273
274fn test_a07_high_impact_requires_grant to bool
275op = new uchar 32 0
276cs = new uchar 32 0
277bad = new uchar 32 0x55
278init_test_aegis op cs
279aegis_grant_clear
280adm = aegis_cap_issue 20 AEGIS_SCOPE_SYSADMIN 0 0 0
281aegis_dispatch_ctx 0 0 200 0
282note disk.format without grant -> AEGIS_ERR_MISSING_GRANT + DEC_REQUIRES_OP
283if ne aegis_broker_dispatch 20 ulong adm aegis_act_disk_format p_dev_nvme AEGIS_ERR_MISSING_GRANT
284ret false
285end
286if ne get aegis_last_dec 0 AEGIS_DEC_REQUIRES_OP
287ret false
288end
289note Forged grant -> AEGIS_ERR_GRANT_SIG + DEC_REJECTED
290aegis_compute_intent_id 20 ulong adm aegis_act_disk_format p_dev_nvme
291aegis_grant_issue_with_secret p_op_drake 200 bad
292if ne aegis_broker_dispatch 20 ulong adm aegis_act_disk_format p_dev_nvme AEGIS_ERR_GRANT_SIG
293ret false
294end
295if ne get aegis_last_dec 0 AEGIS_DEC_REJECTED
296ret false
297end
298note Valid operator grant -> AEGIS_OK + DEC_APPROVED
299aegis_compute_intent_id 20 ulong adm aegis_act_disk_format p_dev_nvme
300aegis_grant_issue_with_secret p_op_drake 200 op
301if ne aegis_broker_dispatch 20 ulong adm aegis_act_disk_format p_dev_nvme AEGIS_OK
302ret false
303end
304if ne get aegis_last_dec 0 AEGIS_DEC_APPROVED
305ret false
306end
307ret true
308end
309
310fn test_a08_jspace_world_delta to bool
311op = new uchar 32 0
312cs = new uchar 32 0
313init_test_aegis op cs
314aegis_grant_clear
315fs = aegis_cap_issue 30 AEGIS_SCOPE_FS 0 0 0
316aegis_cap_set_strings ulong fs p_ws part p_empty 0 0
317wi = aegis_world_create 777
318if lt wi 0
319ret false
320end
321note Reversible fs.write to active World 777 approved without grant!
322aegis_dispatch_ctx 777 1 300 0
323if ne aegis_broker_dispatch 30 ulong fs aegis_act_fs_write p_ws_sub AEGIS_OK
324ret false
325end
326if or ne get aegis_w_deltas ulong wi 1 ne get aegis_w_writes ulong wi 1
327ret false
328end
329note Rollback clears deltas and transitions World to ROLLEDBACK
330if ne aegis_world_rollback 777 AEGIS_OK
331ret false
332end
333if or ne get aegis_w_deltas ulong wi 0 ne get aegis_w_status ulong wi AEGIS_WORLD_ROLLEDBACK
334ret false
335end
336note Dispatching again to rolled-back World falls back to requiring OperatorGrant!
337if ne aegis_broker_dispatch 30 ulong fs aegis_act_fs_write p_ws_sub AEGIS_ERR_MISSING_GRANT
338ret false
339end
340ret true
341end
342
343fn test_a09_audit_ledger to bool
344op = new uchar 32 0
345cs = new uchar 32 0
346init_test_aegis op cs
347aegis_grant_clear
348fs = aegis_cap_issue 40 AEGIS_SCOPE_FS 0 0 0
349aegis_cap_set_strings ulong fs p_ws part p_empty 0 0
350aegis_dispatch_ctx 0 0 401 0
351r1 = aegis_broker_dispatch 40 ulong fs aegis_act_fs_read p_ws_sub
352aegis_dispatch_ctx 0 0 402 0
353r2 = aegis_broker_dispatch 40 ulong fs aegis_act_fs_write p_ws_sub
354aegis_dispatch_ctx 0 0 403 0
355r3 = aegis_broker_dispatch 40 ulong fs aegis_act_fs_read p_etc
356if or ne r1 AEGIS_OK or ne r2 AEGIS_ERR_MISSING_GRANT ne r3 AEGIS_ERR_SCOPE
357ret false
358end
359if ne get aegis_audit_cnt 0 3
360ret false
361end
362if or ne get aegis_audit_dec 0 AEGIS_DEC_APPROVED ne get aegis_audit_exec 0 1
363ret false
364end
365if or ne get aegis_audit_dec 1 AEGIS_DEC_REQUIRES_OP ne get aegis_audit_exec 1 0
366ret false
367end
368if or ne get aegis_audit_dec 2 AEGIS_DEC_REJECTED ne get aegis_audit_ts 2 403
369ret false
370end
371ret true
372end
373
374fn test_a10_mutant_skip_grant to bool
375op = new uchar 32 0
376cs = new uchar 32 0
377init_test_aegis op cs
378aegis_grant_clear
379adm = aegis_cap_issue 50 AEGIS_SCOPE_SYSADMIN 0 0 0
380aegis_dispatch_ctx 0 0 500 0
381note With mutant OFF: kernel.replace without grant MUST be refused
382if ne aegis_broker_dispatch 50 ulong adm aegis_act_kern_rep p_dev_nvme AEGIS_ERR_MISSING_GRANT
383ret false
384end
385note With mutant ON (skip_grant=1): unapproved kernel.replace slips through -> mutant detected!
386aegis_set_mutant_skip_grant 1
387rc_mut = aegis_broker_dispatch 50 ulong adm aegis_act_kern_rep p_dev_nvme
388aegis_set_mutant_skip_grant 0
389if eq rc_mut AEGIS_ERR_MISSING_GRANT
390ret false
391end
392ret true
393end
394
395fn main to int
396fails = uint 0
397fails = add fails areport a_t01 test_a01_path_within
398fails = add fails areport a_t02 test_a02_cap_sig_and_expiry
399fails = add fails areport a_t03 test_a03_delegation_attenuation
400fails = add fails areport a_t04 test_a04_subtree_revocation
401fails = add fails areport a_t05 test_a05_intent_and_grant_crypto
402fails = add fails areport a_t06 test_a06_standing_fetch_and_fs_read
403fails = add fails areport a_t07 test_a07_high_impact_requires_grant
404fails = add fails areport a_t08 test_a08_jspace_world_delta
405fails = add fails areport a_t09 test_a09_audit_ledger
406fails = add fails areport a_t10 test_a10_mutant_skip_grant
407if eq fails 0
408w = awrite_all 1 a_sum
409if w
410ret 0
411end
412ret 1
413end
414w2 = awrite_all 1 a_fsum
415ret 1
416end