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 / test.om

884 lines · 26993 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/argus/test.om: Comprehensive Pure-Omega test suite for ARGUS Event ABI,
3note Class-Gated Admission Ring, Shadow-State Detectors, and Containment Invariants (I1..I5).
4note Compose with: si/directives/om2.om aienux/argus/event.om aienux/argus/ring.om aienux/argus/contain.om aienux/argus/test.om om/tls/sha2.om
5
6text s_pass "PASS "
7text s_fail "FAIL "
8text s_nl "\n"
9text s_t01 "event_wire_roundtrip_and_sha256_chain"
10text s_t02 "event_validate_class_floor_and_version"
11text s_t03 "event_validate_consumer_flag_and_external_effect"
12text s_t04 "event_validate_containment_v12_and_i2"
13text s_t05 "creq_152_byte_wire_roundtrip_and_negatives"
14text s_t06 "ring_watermarks_and_conservation"
15text s_t07 "ring_malformed_push_and_drop_synthesis"
16text s_t08 "core_forged_revoked_stale_subject_detectors"
17text s_t09 "core_sequence_anomaly_and_authority_replay"
18text s_t10 "core_world_provenance_and_telemetry_loss"
19text s_t11 "contain_full_lifecycle_confirmed"
20text s_t12 "contain_i2_synthetic_and_i3b_rate_limit"
21text s_t13 "contain_i5d_unauthorized_execution"
22text s_t14 "contain_i1b_scope_exceeded"
23text s_t15 "contain_unmatched_echo_and_unconfirmed"
24text s_t16 "contain_escalate_then_deny_lifecycle"
25text s_sum "ARGUS_TEST_PASS total=16 failed=0\n"
26text s_fsum "ARGUS_TEST_FAIL\n"
27
28fn argus_write_all fd int buf view uchar * to bool
29total = len buf
30off = ulong 0
31note Each write advances off by at least 1 byte on progress; 4096 covers test output lines.
32while lt off total bound 4096
33n = write fd buf off sub total off
34if le n 0
35ret false
36end
37off = add off ulong n
38end
39ret true
40end
41
42fn report name view uchar * ok bool to uint
43if ok
44w1 = argus_write_all 1 s_pass
45w2 = argus_write_all 1 name
46w3 = argus_write_all 1 s_nl
47if and w1 and w2 w3
48ret 0
49end
50ret 1
51end
52w1 = argus_write_all 1 s_fail
53w2 = argus_write_all 1 name
54w3 = argus_write_all 1 s_nl
55if and w1 and w2 w3
56ret 1
57end
58ret 1
59end
60
61fn mk_ev dst edit ArgusEvent cls uchar k ushort oc uchar seq ulong to void
62put dst version ARGUS_ABI_VERSION
63put dst class_ cls
64put dst kind k
65put dst effect_class ARGUS_EFFECT_NONE
66put dst outcome oc
67put dst flags 0
68put dst sequence seq
69put dst tick 10
70put dst principal 7
71put dst code 0
72put dst cap_id 1
73put dst object_id 0
74put dst cap_generation 100
75put dst world_generation 0
76put dst resource 42
77end
78
79fn test_01_chain_part ev view ArgusEvent mach view uchar 32 edig view uchar 32 to bool
80d1 = new uchar 32 0
81d2 = new uchar 32 0
82argus_event_digest ev mach edig d1
83ev2 = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
84mk_ev ev2 ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK 1
85put ev2 code -5
86argus_event_digest ev2 mach edig d2
87if not argus_eq32 d1 d2
88ret false
89end
90note 1-bit flip in event changes digest
91put ev2 resource 43
92argus_event_digest ev2 mach edig d2
93if argus_eq32 d1 d2
94ret false
95end
96note Chain extend is deterministic and non-zero
97c1 = new uchar 32 0
98c2 = new uchar 32 0
99argus_chain_extend c1 ev mach edig
100argus_chain_extend c2 ev mach edig
101if not argus_eq32 c1 c2
102ret false
103end
104zero = new uchar 32 0
105if argus_eq32 c1 zero
106ret false
107end
108ret true
109end
110
111fn test_01_wire_and_chain to bool
112ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
113mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK 1
114put ev code -5
115mach = new uchar 32 0x11
116edig = new uchar 32 0x22
117wire = new uchar 128 0
118if ne argus_event_encode ev mach edig wire ARGUS_OK
119ret false
120end
121ev2 = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
122mach2 = new uchar 32 0
123edig2 = new uchar 32 0
124if ne argus_event_decode wire ev2 mach2 edig2 ARGUS_OK
125ret false
126end
127if ne get ev2 kind ARGUS_EV_CAPABILITY_GRANTED
128ret false
129end
130if ne get ev2 code -5
131ret false
132end
133if ne get ev2 cap_generation 100
134ret false
135end
136if not argus_eq32 mach mach2
137ret false
138end
139if not argus_eq32 edig edig2
140ret false
141end
142ret test_01_chain_part ev mach edig
143end
144
145fn test_02_class_floor_and_version to bool
146ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
147mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK 1
148if ne argus_event_validate ev ARGUS_OK
149ret false
150end
151note Stronger class (CRITICAL for SECURITY kind) accepted
152put ev class_ ARGUS_CLASS_CRITICAL
153if ne argus_event_validate ev ARGUS_OK
154ret false
155end
156note Weaker class (AUDIT for SECURITY kind) refused
157put ev class_ ARGUS_CLASS_AUDIT
158if ne argus_event_validate ev ARGUS_ERR_MALFORMED
159ret false
160end
161note Wrong version -> ARGUS_ERR_VERSION
162put ev class_ ARGUS_CLASS_SECURITY
163put ev version 2
164if ne argus_event_validate ev ARGUS_ERR_VERSION
165ret false
166end
167note Sequence 0 and U64_MAX refused
168put ev version ARGUS_ABI_VERSION
169put ev sequence 0
170if ne argus_event_validate ev ARGUS_ERR_MALFORMED
171ret false
172end
173put ev sequence ARGUS_U64_MAX
174if ne argus_event_validate ev ARGUS_ERR_MALFORMED
175ret false
176end
177note Unknown kind refused
178put ev sequence 1
179put ev kind 999
180if ne argus_event_validate ev ARGUS_ERR_MALFORMED
181ret false
182end
183ret true
184end
185
186fn test_03_consumer_and_external to bool
187ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
188mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK 1
189note CONSUMER flag on non-consumer kind refused
190put ev flags ARGUS_FLAG_CONSUMER
191if ne argus_event_validate ev ARGUS_ERR_MALFORMED
192ret false
193end
194note TELEMETRY_DROPPED requires CONSUMER flag
195mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_TELEMETRY_DROPPED ARGUS_OUTCOME_ERROR 2
196if ne argus_event_validate ev ARGUS_ERR_MALFORMED
197ret false
198end
199put ev flags ARGUS_FLAG_CONSUMER
200if ne argus_event_validate ev ARGUS_OK
201ret false
202end
203note EXTERNAL_EFFECT_COMMITTED requires effect_class EXTERNAL
204mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_EXTERNAL_EFFECT_COMMITTED ARGUS_OUTCOME_OK 3
205if ne argus_event_validate ev ARGUS_ERR_MALFORMED
206ret false
207end
208put ev effect_class ARGUS_EFFECT_EXTERNAL
209if ne argus_event_validate ev ARGUS_OK
210ret false
211end
212note CAPABILITY_USE_SUMMARY requires outcome OK and world_gen (MIN) <= cap_gen (MAX)
213mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USE_SUMMARY ARGUS_OUTCOME_OK 4
214put ev world_generation 101
215put ev cap_generation 100
216if ne argus_event_validate ev ARGUS_ERR_MALFORMED
217ret false
218end
219put ev world_generation 90
220if ne argus_event_validate ev ARGUS_OK
221ret false
222end
223put ev outcome ARGUS_OUTCOME_DENIED
224if ne argus_event_validate ev ARGUS_ERR_MALFORMED
225ret false
226end
227ret true
228end
229
230fn test_04_containment_v12_and_i2 to bool
231ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
232note 90 PROPOSED requires CONSUMER flag, request_id != 0, status PROPOSED, outcome OK
233mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_PROPOSED ARGUS_OUTCOME_OK 1
234put ev flags ARGUS_FLAG_CONSUMER
235put ev world_generation 1
236put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_PROPOSED ARGUS_F_REVOKED_CAPABILITY_USED
237if ne argus_event_validate ev ARGUS_OK
238ret false
239end
240note request_id == 0 refused
241put ev world_generation 0
242if ne argus_event_validate ev ARGUS_ERR_MALFORMED
243ret false
244end
245note 92 EXECUTED DONE on REVOKE_CAPABILITY without SYNTHETIC is OK (live executor)
246mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_EXECUTED ARGUS_OUTCOME_OK 2
247put ev world_generation 1
248put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_DONE ARGUS_F_REVOKED_CAPABILITY_USED
249if ne argus_event_validate ev ARGUS_OK
250ret false
251end
252note I2: 92 EXECUTED DONE on FREEZE_PRINCIPAL without SYNTHETIC is REFUSED
253put ev object_id argus_contain_pack ARGUS_CONTAIN_FREEZE_PRINCIPAL ARGUS_CSTATUS_DONE ARGUS_F_REVOKED_CAPABILITY_USED
254if ne argus_event_validate ev ARGUS_ERR_MALFORMED
255ret false
256end
257note With SYNTHETIC flag it is accepted
258put ev flags ARGUS_FLAG_SYNTHETIC
259if ne argus_event_validate ev ARGUS_OK
260ret false
261end
262ret true
263end
264
265fn test_05_creq_wire_roundtrip to bool
266req = new ArgusContainReq 10 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_CRITICAL ARGUS_F_REVOKED_CAPABILITY_USED 7 3 55 1 9 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
267mach = new uchar 32 0x33
268fdig = new uchar 32 0x44
269tdig = new uchar 32 0x55
270wire = new uchar 152 0
271if ne argus_creq_encode req mach fdig tdig wire ARGUS_OK
272ret false
273end
274req2 = new ArgusContainReq 0 0 0 0 0 0 0 0 0 0 0 0 0 0
275m2 = new uchar 32 0
276f2 = new uchar 32 0
277t2 = new uchar 32 0
278if ne argus_creq_decode wire req2 m2 f2 t2 ARGUS_OK
279ret false
280end
281if ne get req2 request_id 1
282ret false
283end
284if ne get req2 target_cap_gen 55
285ret false
286end
287if ne get req2 finding_sequence 9
288ret false
289end
290note Negative controls: bad version, nonzero reserved, unknown flags, zero request_id
291put wire 150 9
292if ne argus_creq_decode wire req2 m2 f2 t2 ARGUS_ERR_VERSION
293ret false
294end
295put wire 150 ARGUS_CONTAIN_REQ_VERSION
296put wire 151 1
297if ne argus_creq_decode wire req2 m2 f2 t2 ARGUS_ERR_MALFORMED
298ret false
299end
300put wire 151 0
301put wire 148 0x04
302if ne argus_creq_decode wire req2 m2 f2 t2 ARGUS_ERR_MALFORMED
303ret false
304end
305ret true
306end
307
308fn test_06_ring_watermarks_conservation to bool
309note Capacity 16: INFO=8, AUDIT=12, SECURITY=15, CRITICAL=16
310if ne argus_ring_init 16 ARGUS_OK
311ret false
312end
313if ne argus_ring_saturation_point 16 ARGUS_CLASS_INFORMATIONAL 8
314ret false
315end
316if ne argus_ring_saturation_point 16 ARGUS_CLASS_AUDIT 12
317ret false
318end
319if ne argus_ring_saturation_point 16 ARGUS_CLASS_SECURITY 15
320ret false
321end
322if ne argus_ring_saturation_point 16 ARGUS_CLASS_CRITICAL 16
323ret false
324end
325ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
326mach = new uchar 32 0
327edig = new uchar 32 0
328note Push 12 AUDIT events -> all 12 succeed, 13th is refused FULL
329i = ulong 1
330while le i 12 bound 16
331mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USED ARGUS_OUTCOME_OK i
332if ne argus_ring_push ev mach edig ARGUS_OK
333ret false
334end
335i = add i 1
336end
337mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USED ARGUS_OUTCOME_OK 13
338if ne argus_ring_push ev mach edig ARGUS_ERR_FULL
339ret false
340end
341note Push 3 SECURITY events (depth 12->15) succeed, 4th refused FULL
342i = ulong 14
343while le i 16 bound 8
344mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK i
345if ne argus_ring_push ev mach edig ARGUS_OK
346ret false
347end
348i = add i 1
349end
350mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK 17
351if ne argus_ring_push ev mach edig ARGUS_ERR_FULL
352ret false
353end
354note Push 1 CRITICAL event (depth 15->16) succeeds, 2nd triggers critical_overflow
355mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CAPABILITY_REVOKED ARGUS_OUTCOME_OK 18
356if ne argus_ring_push ev mach edig ARGUS_OK
357ret false
358end
359mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CAPABILITY_REVOKED ARGUS_OUTCOME_OK 19
360if ne argus_ring_push ev mach edig ARGUS_ERR_FULL
361ret false
362end
363note Check conservation: 19 attempts = 16 pushed + 0 mal + 0 crit_ref + 1 sec_ref + 1 audit_ref + 0 info_ref + 1 crit_overflow
364st = new ArgusRingStats 0 0 0 0 0 0 0 0 0 0
365argus_ring_stats st
366if ne get st pushed 16
367ret false
368end
369if ne get st critical_overflow 1
370ret false
371end
372if ne get st ref_sec 1
373ret false
374end
375if ne get st ref_audit 1
376ret false
377end
378note Pop FIFO check
379pop_ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
380if ne argus_ring_pop pop_ev mach edig ARGUS_OK
381ret false
382end
383if ne get pop_ev sequence 1
384ret false
385end
386ret true
387end
388
389fn test_07_ring_malformed_and_drops to bool
390if ne argus_ring_init 4 ARGUS_OK
391ret false
392end
393ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
394mach = new uchar 32 0
395edig = new uchar 32 0
396note Malformed: kind 90 CONTAINMENT_PROPOSED refused by ring
397mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_PROPOSED ARGUS_OUTCOME_OK 1
398if ne argus_ring_push ev mach edig ARGUS_ERR_MALFORMED
399ret false
400end
401note Malformed: weakened class (AUDIT on CRITICAL kind) refused
402mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_REVOKED ARGUS_OUTCOME_OK 2
403if ne argus_ring_push ev mach edig ARGUS_ERR_MALFORMED
404ret false
405end
406st = new ArgusRingStats 0 0 0 0 0 0 0 0 0 0
407argus_ring_stats st
408if ne get st ref_malformed 2
409ret false
410end
411note Fill ring to 4 and trigger drops on AUDIT and CRITICAL
412i = ulong 1
413while le i 4 bound 8
414mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CAPABILITY_REVOKED ARGUS_OUTCOME_OK i
415if ne argus_ring_push ev mach edig ARGUS_OK
416ret false
417end
418i = add i 1
419end
420mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USED ARGUS_OUTCOME_OK 5
421rc_a = argus_ring_push ev mach edig
422mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CAPABILITY_REVOKED ARGUS_OUTCOME_OK 6
423rc_c = argus_ring_push ev mach edig
424if or ne rc_a ARGUS_ERR_FULL ne rc_c ARGUS_ERR_FULL
425ret false
426end
427note Drain drops: CRITICAL MUST come before AUDIT
428nseq = new ulong 1 1
429drop1 = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
430drop2 = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
431if ne argus_ring_drain_one drop1 nseq ARGUS_OK
432ret false
433end
434if ne argus_ring_drain_one drop2 nseq ARGUS_OK
435ret false
436end
437if ne get drop1 object_id uint ARGUS_CLASS_CRITICAL
438ret false
439end
440if ne get drop2 object_id uint ARGUS_CLASS_AUDIT
441ret false
442end
443note Synthesized drop events must pass argus_event_validate!
444if ne argus_event_validate drop1 ARGUS_OK
445ret false
446end
447if ne argus_event_validate drop2 ARGUS_OK
448ret false
449end
450note No more drops pending
451if ne argus_ring_drain_one drop1 nseq ARGUS_ERR_STATE
452ret false
453end
454ret true
455end
456
457fn test_08_core_cap_detectors to bool
458argus_core_init
459ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
460f = new ArgusFinding 0 0 0 0 0 0 0 0 0 0 0
461mach = new uchar 32 0
462edig = new uchar 32 0
463note 1. Use of unseen slot -> FORGED_CAPABILITY
464mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USED ARGUS_OUTCOME_OK 1
465put ev cap_id 5
466put ev cap_generation 10
467if ne argus_core_ingest ev mach edig f ARGUS_F_FORGED_CAPABILITY
468ret false
469end
470note 2. Grant slot 5 gen 10 subject 7 -> clean
471mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK 2
472put ev cap_id 5
473put ev cap_generation 10
474put ev principal 7
475if ne argus_core_ingest ev mach edig f ARGUS_F_NONE
476ret false
477end
478note 3. Valid use -> clean
479mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USED ARGUS_OUTCOME_OK 3
480put ev cap_id 5
481put ev cap_generation 10
482put ev principal 7
483if ne argus_core_ingest ev mach edig f ARGUS_F_NONE
484ret false
485end
486note 4. Stale generation use -> STALE_GENERATION
487mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USED ARGUS_OUTCOME_OK 4
488put ev cap_id 5
489put ev cap_generation 9
490put ev principal 7
491if ne argus_core_ingest ev mach edig f ARGUS_F_STALE_GENERATION
492ret false
493end
494note 5. Subject mismatch -> SUBJECT_MISMATCH
495mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USED ARGUS_OUTCOME_OK 5
496put ev cap_id 5
497put ev cap_generation 10
498put ev principal 99
499if ne argus_core_ingest ev mach edig f ARGUS_F_SUBJECT_MISMATCH
500ret false
501end
502note 6. Revoke slot 5 -> clean, then use -> REVOKED_CAPABILITY_USED
503mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CAPABILITY_REVOKED ARGUS_OUTCOME_OK 6
504put ev cap_id 5
505put ev cap_generation 10
506if ne argus_core_ingest ev mach edig f ARGUS_F_NONE
507ret false
508end
509mk_ev ev ARGUS_CLASS_AUDIT ARGUS_EV_CAPABILITY_USED ARGUS_OUTCOME_OK 7
510put ev cap_id 5
511put ev cap_generation 10
512put ev principal 7
513if ne argus_core_ingest ev mach edig f ARGUS_F_REVOKED_CAPABILITY_USED
514ret false
515end
516ret true
517end
518
519fn test_09_sequence_and_replay to bool
520argus_core_init
521ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
522f = new ArgusFinding 0 0 0 0 0 0 0 0 0 0 0
523mach = new uchar 32 0
524edig = new uchar 32 0
525note Revoke unseen slot -> AUTHORITY_REPLAY and NOT applied
526mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CAPABILITY_REVOKED ARGUS_OUTCOME_OK 1
527put ev cap_id 2
528put ev cap_generation 5
529if ne argus_core_ingest ev mach edig f ARGUS_F_AUTHORITY_REPLAY
530ret false
531end
532note Grant slot 2 gen 5 -> clean
533mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK 2
534put ev cap_id 2
535put ev cap_generation 5
536if ne argus_core_ingest ev mach edig f ARGUS_F_NONE
537ret false
538end
539note Re-grant same gen 5 -> AUTHORITY_REPLAY
540mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK 3
541put ev cap_id 2
542put ev cap_generation 5
543if ne argus_core_ingest ev mach edig f ARGUS_F_AUTHORITY_REPLAY
544ret false
545end
546note Replayed sequence 3 -> SEQUENCE_ANOMALY
547mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_CAPABILITY_GRANTED ARGUS_OUTCOME_OK 3
548put ev cap_id 2
549put ev cap_generation 6
550if ne argus_core_ingest ev mach edig f ARGUS_F_SEQUENCE_ANOMALY
551ret false
552end
553if ne argus_core_not_applied 3
554ret false
555end
556ret true
557end
558
559fn test_10_world_and_telemetry_loss to bool
560argus_core_init
561ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
562f = new ArgusFinding 0 0 0 0 0 0 0 0 0 0 0
563mach = new uchar 32 0
564edig = new uchar 32 0
565mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_WORLD_COMMITTED ARGUS_OUTCOME_OK 1
566put ev object_id 1
567put ev world_generation 1
568if ne argus_core_ingest ev mach edig f ARGUS_F_NONE
569ret false
570end
571mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_WORLD_COMMITTED ARGUS_OUTCOME_OK 2
572put ev object_id 1
573put ev world_generation 2
574if ne argus_core_ingest ev mach edig f ARGUS_F_NONE
575ret false
576end
577note Skipped generation 2 -> 4 raises WORLD_PROVENANCE_INCONSISTENT
578mk_ev ev ARGUS_CLASS_SECURITY ARGUS_EV_WORLD_COMMITTED ARGUS_OUTCOME_OK 3
579put ev object_id 1
580put ev world_generation 4
581if ne argus_core_ingest ev mach edig f ARGUS_F_WORLD_PROVENANCE_INCONSISTENT
582ret false
583end
584note TELEMETRY_DROPPED for CRITICAL raises TELEMETRY_LOSS
585mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_TELEMETRY_DROPPED ARGUS_OUTCOME_ERROR 1
586put ev flags ARGUS_FLAG_CONSUMER
587put ev object_id uint ARGUS_CLASS_CRITICAL
588put ev resource 3
589if ne argus_core_ingest ev mach edig f ARGUS_F_TELEMETRY_LOSS
590ret false
591end
592ret true
593end
594
595fn test_11_contain_confirmed to bool
596argus_contain_init
597req = new ArgusContainReq 1 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_CRITICAL ARGUS_F_REVOKED_CAPABILITY_USED 7 5 10 0 7 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
598mach = new uchar 32 0
599fdig = new uchar 32 0xaa
600tdig = new uchar 32 0
601rdig = new uchar 32 0
602if ne argus_contain_propose req mach fdig tdig rdig ARGUS_OK
603ret false
604end
605rid = get req request_id
606note 1. DECIDED GRANT
607ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
608mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_DECIDED ARGUS_OUTCOME_OK 10
609put ev principal 7
610put ev cap_id 5
611put ev cap_generation 10
612put ev world_generation rid
613put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_GRANT ARGUS_F_REVOKED_CAPABILITY_USED
614if ne argus_contain_observe ev rdig ARGUS_F_NONE
615ret false
616end
617note 2. Matching kind 4 CAPABILITY_REVOKED on (5, 10)
618mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CAPABILITY_REVOKED ARGUS_OUTCOME_OK 11
619put ev cap_id 5
620put ev cap_generation 10
621if ne argus_contain_observe ev rdig ARGUS_F_NONE
622ret false
623end
624note 3. EXECUTED DONE with resource = 1 -> CONFIRMED
625mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_EXECUTED ARGUS_OUTCOME_OK 12
626put ev principal 7
627put ev cap_id 5
628put ev cap_generation 10
629put ev world_generation rid
630put ev resource 1
631put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_DONE ARGUS_F_REVOKED_CAPABILITY_USED
632if ne argus_contain_observe ev rdig ARGUS_F_NONE
633ret false
634end
635h = new ArgusContainHealth 0 0 0 0 0 0 0 0 0 0
636argus_contain_health h
637if ne get h proposed 1
638ret false
639end
640if ne get h granted 1
641ret false
642end
643if ne get h confirmed 1
644ret false
645end
646ret true
647end
648
649fn test_12_contain_i2_and_rate_limit to bool
650argus_contain_init
651mach = new uchar 32 0
652fdig = new uchar 32 0
653tdig = new uchar 32 0
654rdig = new uchar 32 0
655note I2: non-live FREEZE_PRINCIPAL without SYNTHETIC refused
656req = new ArgusContainReq 1 ARGUS_CONTAIN_FREEZE_PRINCIPAL ARGUS_SEV_HIGH ARGUS_F_SUBJECT_MISMATCH 7 5 10 0 1 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
657if ne argus_contain_propose req mach fdig tdig rdig ARGUS_ERR_MALFORMED
658ret false
659end
660note I3.b: 16 live proposals succeed, 17th in same window returns ARGUS_ERR_FULL
661put req containment ARGUS_CONTAIN_REVOKE_CAPABILITY
662i = uint 0
663while lt i ARGUS_CONTAIN_WINDOW_MAX bound 32
664put req target_cap_id add 1 i
665if ne argus_contain_propose req mach fdig tdig rdig ARGUS_OK
666ret false
667end
668i = add i 1
669end
670put req target_cap_id 50
671if ne argus_contain_propose req mach fdig tdig rdig ARGUS_ERR_FULL
672ret false
673end
674h = new ArgusContainHealth 0 0 0 0 0 0 0 0 0 0
675argus_contain_health h
676if ne get h rate_limited 1
677ret false
678end
679ret true
680end
681
682fn test_13_contain_i5d_unauth_exec to bool
683argus_contain_init
684req = new ArgusContainReq 1 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_CRITICAL ARGUS_F_FORGED_CAPABILITY 7 6 20 0 1 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
685mach = new uchar 32 0
686fdig = new uchar 32 0
687tdig = new uchar 32 0
688rdig = new uchar 32 0
689if ne argus_contain_propose req mach fdig tdig rdig ARGUS_OK
690ret false
691end
692rid = get req request_id
693note EXECUTED DONE before GRANT -> EXECUTION_UNAUTHORIZED
694ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
695mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_EXECUTED ARGUS_OUTCOME_OK 2
696put ev principal 7
697put ev cap_id 6
698put ev cap_generation 20
699put ev world_generation rid
700put ev resource 1
701put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_DONE ARGUS_F_FORGED_CAPABILITY
702if ne argus_contain_observe ev rdig ARGUS_F_CONTAINMENT_EXECUTION_UNAUTHORIZED
703ret false
704end
705note kind 4 revoke on target while still PROPOSED -> EXECUTION_UNAUTHORIZED
706mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CAPABILITY_REVOKED ARGUS_OUTCOME_OK 3
707put ev cap_id 6
708put ev cap_generation 20
709if ne argus_contain_observe ev rdig ARGUS_F_CONTAINMENT_EXECUTION_UNAUTHORIZED
710ret false
711end
712ret true
713end
714
715fn test_14_contain_i1b_scope_exceeded to bool
716argus_contain_init
717req = new ArgusContainReq 1 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_CRITICAL ARGUS_F_FORGED_CAPABILITY 7 8 30 0 1 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
718mach = new uchar 32 0
719fdig = new uchar 32 0
720tdig = new uchar 32 0
721rdig = new uchar 32 0
722if ne argus_contain_propose req mach fdig tdig rdig ARGUS_OK
723ret false
724end
725rid = get req request_id
726ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
727mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_DECIDED ARGUS_OUTCOME_OK 2
728put ev principal 7
729put ev cap_id 8
730put ev cap_generation 30
731put ev world_generation rid
732put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_GRANT ARGUS_F_FORGED_CAPABILITY
733if ne argus_contain_observe ev rdig ARGUS_F_NONE
734ret false
735end
736note EXECUTED DONE reporting 2 slots revoked -> SCOPE_EXCEEDED
737mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_EXECUTED ARGUS_OUTCOME_OK 3
738put ev principal 7
739put ev cap_id 8
740put ev cap_generation 30
741put ev world_generation rid
742put ev resource 2
743put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_DONE ARGUS_F_FORGED_CAPABILITY
744if ne argus_contain_observe ev rdig ARGUS_F_CONTAINMENT_SCOPE_EXCEEDED
745ret false
746end
747h = new ArgusContainHealth 0 0 0 0 0 0 0 0 0 0
748argus_contain_health h
749if ne get h failed_scope 1
750ret false
751end
752ret true
753end
754
755fn test_15_contain_unmatched_and_unconfirmed to bool
756argus_contain_init
757req = new ArgusContainReq 1 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_CRITICAL ARGUS_F_FORGED_CAPABILITY 7 9 40 0 1 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
758mach = new uchar 32 0
759fdig = new uchar 32 0
760tdig = new uchar 32 0
761rdig = new uchar 32 0
762if ne argus_contain_propose req mach fdig tdig rdig ARGUS_OK
763ret false
764end
765rid = get req request_id
766bad_dig = new uchar 32 0
767for i ulong 32
768put bad_dig i get rdig i
769end
770put bad_dig 0 xor get bad_dig 0 1
771note Flipped echo digest in DECIDED -> DECISION_UNMATCHED
772ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
773mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_DECIDED ARGUS_OUTCOME_OK 2
774put ev principal 7
775put ev cap_id 9
776put ev cap_generation 40
777put ev world_generation rid
778put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_GRANT ARGUS_F_FORGED_CAPABILITY
779if ne argus_contain_observe ev bad_dig ARGUS_F_CONTAINMENT_DECISION_UNMATCHED
780ret false
781end
782note Valid GRANT then DONE without prior kind 4 -> EXECUTION_UNCONFIRMED
783if ne argus_contain_observe ev rdig ARGUS_F_NONE
784ret false
785end
786mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_EXECUTED ARGUS_OUTCOME_OK 3
787put ev principal 7
788put ev cap_id 9
789put ev cap_generation 40
790put ev world_generation rid
791put ev resource 1
792put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_DONE ARGUS_F_FORGED_CAPABILITY
793if ne argus_contain_observe ev rdig ARGUS_F_CONTAINMENT_EXECUTION_UNCONFIRMED
794ret false
795end
796ret true
797end
798
799fn test_16_contain_escalate_deny to bool
800argus_contain_init
801req = new ArgusContainReq 1 ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_SEV_CRITICAL ARGUS_F_FORGED_CAPABILITY 7 11 50 0 1 0 0 0 ARGUS_CONTAIN_REQ_VERSION 0
802mach = new uchar 32 0
803fdig = new uchar 32 0
804tdig = new uchar 32 0
805rdig = new uchar 32 0
806if ne argus_contain_propose req mach fdig tdig rdig ARGUS_OK
807ret false
808end
809rid = get req request_id
810ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
811note PROPOSED -> ESCALATED -> DENIED
812mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_DECIDED ARGUS_OUTCOME_ERROR 2
813put ev principal 7
814put ev cap_id 11
815put ev cap_generation 50
816put ev world_generation rid
817put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_ESCALATE ARGUS_F_FORGED_CAPABILITY
818if ne argus_contain_observe ev rdig ARGUS_F_NONE
819ret false
820end
821mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_DECIDED ARGUS_OUTCOME_DENIED 3
822put ev principal 7
823put ev cap_id 11
824put ev cap_generation 50
825put ev world_generation rid
826put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_DENY ARGUS_F_FORGED_CAPABILITY
827if ne argus_contain_observe ev rdig ARGUS_F_NONE
828ret false
829end
830note Subsequent decision on closed DENIED request -> DECISION_UNMATCHED
831mk_ev ev ARGUS_CLASS_CRITICAL ARGUS_EV_CONTAINMENT_DECIDED ARGUS_OUTCOME_OK 4
832put ev principal 7
833put ev cap_id 11
834put ev cap_generation 50
835put ev world_generation rid
836put ev object_id argus_contain_pack ARGUS_CONTAIN_REVOKE_CAPABILITY ARGUS_CSTATUS_GRANT ARGUS_F_FORGED_CAPABILITY
837if ne argus_contain_observe ev rdig ARGUS_F_CONTAINMENT_DECISION_UNMATCHED
838ret false
839end
840h = new ArgusContainHealth 0 0 0 0 0 0 0 0 0 0
841argus_contain_health h
842if ne get h escalated 1
843ret false
844end
845if ne get h denied 1
846ret false
847end
848if ne get h decisions_unmatched 1
849ret false
850end
851ret true
852end
853
854fn main to int
855failed = uint 0
856failed = add failed report s_t01 test_01_wire_and_chain
857failed = add failed report s_t02 test_02_class_floor_and_version
858failed = add failed report s_t03 test_03_consumer_and_external
859failed = add failed report s_t04 test_04_containment_v12_and_i2
860failed = add failed report s_t05 test_05_creq_wire_roundtrip
861failed = add failed report s_t06 test_06_ring_watermarks_conservation
862failed = add failed report s_t07 test_07_ring_malformed_and_drops
863failed = add failed report s_t08 test_08_core_cap_detectors
864failed = add failed report s_t09 test_09_sequence_and_replay
865failed = add failed report s_t10 test_10_world_and_telemetry_loss
866failed = add failed report s_t11 test_11_contain_confirmed
867failed = add failed report s_t12 test_12_contain_i2_and_rate_limit
868failed = add failed report s_t13 test_13_contain_i5d_unauth_exec
869failed = add failed report s_t14 test_14_contain_i1b_scope_exceeded
870failed = add failed report s_t15 test_15_contain_unmatched_and_unconfirmed
871failed = add failed report s_t16 test_16_contain_escalate_deny
872if eq failed 0
873w = argus_write_all 1 s_sum
874if w
875ret 0
876end
877ret 1
878end
879w = argus_write_all 1 s_fsum
880if w
881ret 1
882end
883ret 1
884end