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

863 lines · 20102 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/capability/test.om: Pure-Omega test suite for AIENOS 64-bit Capability Authority.
3note Covers all positive invariants and negative controls from native/capability/tests/capability_test.c
4note plus resource width checks and constant-time office token authorization.
5note Compose with: si/directives/om2.om aienux/capability/lib.om aienux/capability/test.om
6
7text s_pass "PASS "
8text s_fail "FAIL "
9text s_nl "\n"
10text s_t01 "high_half_resource_and_width"
11text s_t02 "forged_stale_subject_resource_rights_fail_closed"
12text s_t03 "amplification_lease_epoch_revoked_ancestor_fail"
13text s_t04 "child_lease_cannot_outlive_parent"
14text s_t05 "privileged_rights_not_delegable_and_office_stays"
15text s_t06 "promote_right_cannot_be_delegated"
16text s_t07 "generation_exhaustion_fails_closed"
17text s_t08 "kill_restart_invalidates_and_cognition_refused"
18text s_t09 "reclaimed_ref_stays_dead_after_restart"
19text s_t10 "generation_above_32_bits_is_kept"
20text s_t11 "ordinary_cap_cannot_admin_and_depth_stops"
21text s_t12 "table_fills_then_refuses"
22text s_t13 "observer_ops_cascade_refusals_and_silence"
23text s_t14 "validate_needs_every_requested_right"
24text s_t15 "lease_ends_exactly_at_expiry_tick_and_overflow"
25text s_t16 "validate_refuses_corrupt_non_live_parent"
26text s_t17 "control_resource_cap_cannot_operate_authority"
27text s_t18 "office_token_authorize_and_restart_rotation"
28text s_sum "CAPABILITY_TEST_PASS total=18 failed=0\n"
29text s_fsum "CAPABILITY_TEST_FAIL\n"
30
31fn report name view uchar * ok bool to uint
32if ok
33w1 = cap_write_all 1 s_pass
34w2 = cap_write_all 1 name
35w3 = cap_write_all 1 s_nl
36if and w1 and w2 w3
37ret 0
38end
39ret 1
40end
41w1 = cap_write_all 1 s_fail
42w2 = cap_write_all 1 name
43w3 = cap_write_all 1 s_nl
44if and w1 and w2 w3
45ret 1
46end
47ret 1
48end
49
50fn mk_root_req subj uint res ulong rgt uint ticks ulong off view CapRef dst edit CapMint to void
51put dst issuer 1
52put dst subject subj
53put dst resource res
54put dst rights rgt
55put dst lease_ticks ticks
56put dst parent_id CAP_PARENT_NONE
57put dst parent_generation 0
58put dst auth_id get off cap_id
59put dst auth_generation get off generation
60end
61
62fn mk_deleg_req subj uint res ulong rgt uint ticks ulong par view CapRef dst edit CapMint to void
63put dst issuer 2
64put dst subject subj
65put dst resource res
66put dst rights rgt
67put dst lease_ticks ticks
68put dst parent_id get par cap_id
69put dst parent_generation get par generation
70put dst auth_id get par cap_id
71put dst auth_generation get par generation
72end
73
74fn test_01_high_half_resource to bool
75if ne cap_start CAP_OK
76ret false
77end
78off = new CapRef 0 0
79if ne cap_office off CAP_OK
80ret false
81end
82hi_res = ulong 0x123456789abcdef0
83req = new CapMint 0 0 0 0 0 0 0 0 0
84mk_root_req 42 hi_res CAP_RIGHT_READ 0 off req
85cref = new CapRef 0 0
86if ne cap_mint req cref CAP_OK
87ret false
88end
89ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
90if ne cap_validate cref 42 hi_res CAP_RIGHT_READ ent CAP_OK
91ret false
92end
93if ne get ent resource hi_res
94ret false
95end
96note Low-32 collision must fail closed
97if ne cap_validate cref 42 0x9abcdef0 CAP_RIGHT_READ ent CAP_ERR_RESOURCE
98ret false
99end
100note Widen / narrow resource checks
101if ne cap_widen_resource 0xdeadbeef 0xdeadbeef
102ret false
103end
104n32 = new uint 1 0
105if ne cap_narrow_resource 0xdeadbeef n32 CAP_OK
106ret false
107end
108if ne get n32 0 0xdeadbeef
109ret false
110end
111if ne cap_narrow_resource hi_res n32 CAP_ERR_RESOURCE
112ret false
113end
114ret true
115end
116
117fn test_02_forged_stale_fail_closed to bool
118if ne cap_start CAP_OK
119ret false
120end
121off = new CapRef 0 0
122rc0 = cap_office off
123if ne rc0 CAP_OK
124ret false
125end
126req = new CapMint 0 0 0 0 0 0 0 0 0
127mk_root_req 7 100 CAP_RIGHT_READ 0 off req
128cref = new CapRef 0 0
129if ne cap_mint req cref CAP_OK
130ret false
131end
132ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
133note Out of bounds cap_id
134oob = new CapRef 256 get cref generation
135if ne cap_validate oob 7 100 CAP_RIGHT_READ ent CAP_ERR_BOUNDS
136ret false
137end
138if ne cap_inspect oob ent CAP_ERR_BOUNDS
139ret false
140end
141note Stale generation
142stale = new CapRef get cref cap_id add get cref generation 1
143if ne cap_validate stale 7 100 CAP_RIGHT_READ ent CAP_ERR_STALE_GEN
144ret false
145end
146if ne cap_inspect stale ent CAP_ERR_STALE_GEN
147ret false
148end
149note Free slot inspect refused
150free_ref = new CapRef 99 get off generation
151if ne cap_inspect free_ref ent CAP_ERR_STATE
152ret false
153end
154note Wrong subject, resource, rights
155if ne cap_validate cref 8 100 CAP_RIGHT_READ ent CAP_ERR_SUBJECT
156ret false
157end
158if ne cap_validate cref 7 101 CAP_RIGHT_READ ent CAP_ERR_RESOURCE
159ret false
160end
161if ne cap_validate cref 7 100 CAP_RIGHT_WRITE ent CAP_ERR_RIGHTS
162ret false
163end
164ret true
165end
166
167fn test_03_amplification_lease_epoch_revoke to bool
168if ne cap_start CAP_OK
169ret false
170end
171off = new CapRef 0 0
172if ne cap_office off CAP_OK
173ret false
174end
175req = new CapMint 0 0 0 0 0 0 0 0 0
176r_rd = or CAP_RIGHT_READ CAP_RIGHT_DELEGATE
177mk_root_req 10 555 r_rd 100 off req
178par = new CapRef 0 0
179if ne cap_mint req par CAP_OK
180ret false
181end
182note Delegation narrowing succeeds
183mk_deleg_req 11 555 CAP_RIGHT_READ 50 par req
184ch = new CapRef 0 0
185if ne cap_mint req ch CAP_OK
186ret false
187end
188note Rights amplification refused
189mk_deleg_req 12 555 or CAP_RIGHT_READ CAP_RIGHT_WRITE 50 par req
190bad = new CapRef 0 0
191if ne cap_mint req bad CAP_ERR_AMPLIFY
192ret false
193end
194note Resource change during delegation refused
195mk_deleg_req 12 556 CAP_RIGHT_READ 50 par req
196if ne cap_mint req bad CAP_ERR_RESOURCE
197ret false
198end
199note Revoking parent cascades to child
200if ne cap_revoke off par CAP_OK
201ret false
202end
203ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
204if ne cap_validate par 10 555 CAP_RIGHT_READ ent CAP_ERR_REVOKED
205ret false
206end
207if ne cap_validate ch 11 555 CAP_RIGHT_READ ent CAP_ERR_REVOKED
208ret false
209end
210note Epoch bump invalidates previously minted cap
211mk_root_req 13 777 CAP_RIGHT_READ 0 off req
212ep_cap = new CapRef 0 0
213if ne cap_mint req ep_cap CAP_OK
214ret false
215end
216if ne cap_bump_epoch off CAP_OK
217ret false
218end
219if ne cap_validate ep_cap 13 777 CAP_RIGHT_READ ent CAP_ERR_EPOCH
220ret false
221end
222ret true
223end
224
225fn test_04_child_lease_bound to bool
226if ne cap_start CAP_OK
227ret false
228end
229off = new CapRef 0 0
230if ne cap_office off CAP_OK
231ret false
232end
233req = new CapMint 0 0 0 0 0 0 0 0 0
234mk_root_req 10 200 or CAP_RIGHT_READ CAP_RIGHT_DELEGATE 50 off req
235par = new CapRef 0 0
236if ne cap_mint req par CAP_OK
237ret false
238end
239note Unbounded child lease refused when parent is bounded
240mk_deleg_req 11 200 CAP_RIGHT_READ 0 par req
241ch = new CapRef 0 0
242if ne cap_mint req ch CAP_ERR_AMPLIFY
243ret false
244end
245note Longer child lease refused
246mk_deleg_req 11 200 CAP_RIGHT_READ 51 par req
247if ne cap_mint req ch CAP_ERR_AMPLIFY
248ret false
249end
250note Equal child lease succeeds
251mk_deleg_req 11 200 CAP_RIGHT_READ 50 par req
252if ne cap_mint req ch CAP_OK
253ret false
254end
255ret true
256end
257
258fn test_05_privileged_not_delegable to bool
259if ne cap_start CAP_OK
260ret false
261end
262off = new CapRef 0 0
263if ne cap_office off CAP_OK
264ret false
265end
266req = new CapMint 0 0 0 0 0 0 0 0 0
267note Privileged + DELEGATE refused
268mk_root_req 1 CAP_RES_AUTHORITY or CAP_RIGHT_MINT CAP_RIGHT_DELEGATE 0 off req
269bad = new CapRef 0 0
270if ne cap_mint req bad CAP_ERR_NOT_DELEGABLE
271ret false
272end
273note Sub-office with only REVOKE cannot revoke office with all privileged rights
274mk_root_req 2 CAP_RES_AUTHORITY CAP_RIGHT_REVOKE 0 off req
275sub_rev = new CapRef 0 0
276if ne cap_mint req sub_rev CAP_OK
277ret false
278end
279if ne cap_revoke sub_rev off CAP_ERR_UNAUTHORIZED
280ret false
281end
282note Office stays live
283ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
284if ne cap_validate off 0 CAP_RES_AUTHORITY CAP_RIGHT_MINT ent CAP_OK
285ret false
286end
287ret true
288end
289
290fn test_06_promote_not_delegable to bool
291if ne cap_start CAP_OK
292ret false
293end
294off = new CapRef 0 0
295if ne cap_office off CAP_OK
296ret false
297end
298req = new CapMint 0 0 0 0 0 0 0 0 0
299mk_root_req 5 CAP_RES_AUTHORITY or CAP_RIGHT_PROMOTE CAP_RIGHT_DELEGATE 0 off req
300bad = new CapRef 0 0
301if ne cap_mint req bad CAP_ERR_NOT_DELEGABLE
302ret false
303end
304note Minting PROMOTE without DELEGATE succeeds
305mk_root_req 5 CAP_RES_AUTHORITY CAP_RIGHT_PROMOTE 0 off req
306prom = new CapRef 0 0
307if ne cap_mint req prom CAP_OK
308ret false
309end
310note Cannot delegate from PROMOTE cap
311mk_deleg_req 6 CAP_RES_AUTHORITY CAP_RIGHT_PROMOTE 0 prom req
312if ne cap_mint req bad CAP_ERR_NOT_DELEGABLE
313ret false
314end
315ret true
316end
317
318fn test_07_generation_exhaustion to bool
319nxt = new ulong 1 0
320if ne cap_generation_advance CAP_U64_MAX nxt CAP_ERR_EXHAUSTED
321ret false
322end
323if ne cap_start CAP_OK
324ret false
325end
326off = new CapRef 0 0
327if ne cap_office off CAP_OK
328ret false
329end
330req = new CapMint 0 0 0 0 0 0 0 0 0
331mk_root_req 1 10 CAP_RIGHT_READ 0 off req
332c1 = new CapRef 0 0
333if ne cap_mint req c1 CAP_OK
334ret false
335end
336note Force generation on live slot refused
337if ne cap_force_generation get c1 cap_id CAP_U64_MAX CAP_ERR_STATE
338ret false
339end
340note Force generation to 0 refused
341if ne cap_force_generation 2 0 CAP_ERR_EXHAUSTED
342ret false
343end
344note Revoke slot 1, force its gen to U64_MAX -> reclaim must fail closed
345if ne cap_revoke off c1 CAP_OK
346ret false
347end
348if ne cap_force_generation get c1 cap_id CAP_U64_MAX CAP_OK
349ret false
350end
351if ne cap_reclaim off get c1 cap_id CAP_ERR_EXHAUSTED
352ret false
353end
354note Exhaust all free slots (2..255) -> mint must return CAP_ERR_EXHAUSTED
355i = uint 2
356while lt i CAP_MAX bound 256
357if ne cap_force_generation i CAP_U64_MAX CAP_OK
358ret false
359end
360i = add i 1
361end
362c2 = new CapRef 0 0
363if ne cap_mint req c2 CAP_ERR_EXHAUSTED
364ret false
365end
366ret true
367end
368
369fn test_08_kill_restart_cognition to bool
370if ne cap_start CAP_OK
371ret false
372end
373off = new CapRef 0 0
374if ne cap_office off CAP_OK
375ret false
376end
377req = new CapMint 0 0 0 0 0 0 0 0 0
378mk_root_req 9 99 CAP_RIGHT_READ 0 off req
379c1 = new CapRef 0 0
380if ne cap_mint req c1 CAP_OK
381ret false
382end
383note Cognition calls always fail closed
384tok = new uchar 32 0
385cap_copy_token tok
386if ne cap_cognition_mint req tok CAP_ERR_UNAUTHORIZED
387ret false
388end
389if ne cap_cognition_admin 1 off c1 CAP_ERR_UNAUTHORIZED
390ret false
391end
392note Kill stops all mutating operations with CAP_ERR_IO
393if ne cap_kill CAP_OK
394ret false
395end
396c2 = new CapRef 0 0
397if ne cap_mint req c2 CAP_ERR_IO
398ret false
399end
400if ne cap_revoke off c1 CAP_ERR_IO
401ret false
402end
403if ne cap_advance_clock off 1 CAP_ERR_IO
404ret false
405end
406if ne cap_bump_epoch off CAP_ERR_IO
407ret false
408end
409note Restart brings authority back with strictly higher generation
410old_gen = get off generation
411if ne cap_restart CAP_OK
412ret false
413end
414off2 = new CapRef 0 0
415if ne cap_office off2 CAP_OK
416ret false
417end
418if le get off2 generation old_gen
419ret false
420end
421note Old reference is stale after restart
422ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
423if ne cap_validate c1 9 99 CAP_RIGHT_READ ent CAP_ERR_STALE_GEN
424ret false
425end
426ret true
427end
428
429fn test_09_reclaimed_stays_dead_after_restart to bool
430if ne cap_start CAP_OK
431ret false
432end
433off = new CapRef 0 0
434if ne cap_office off CAP_OK
435ret false
436end
437req = new CapMint 0 0 0 0 0 0 0 0 0
438mk_root_req 3 33 CAP_RIGHT_READ 0 off req
439c1 = new CapRef 0 0
440if ne cap_mint req c1 CAP_OK
441ret false
442end
443if ne cap_revoke off c1 CAP_OK
444ret false
445end
446if ne cap_reclaim off get c1 cap_id CAP_OK
447ret false
448end
449if ne cap_restart CAP_OK
450ret false
451end
452off2 = new CapRef 0 0
453if ne cap_office off2 CAP_OK
454ret false
455end
456if le get off2 generation add get c1 generation 1
457ret false
458end
459ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
460if ne cap_validate c1 3 33 CAP_RIGHT_READ ent CAP_ERR_STALE_GEN
461ret false
462end
463ret true
464end
465
466fn test_10_gen_above_32_bits to bool
467if ne cap_start CAP_OK
468ret false
469end
470off = new CapRef 0 0
471if ne cap_office off CAP_OK
472ret false
473end
474hi_gen = ulong 0x0000000100000005
475if ne cap_force_generation 1 hi_gen CAP_OK
476ret false
477end
478req = new CapMint 0 0 0 0 0 0 0 0 0
479mk_root_req 4 44 CAP_RIGHT_READ 0 off req
480c1 = new CapRef 0 0
481if ne cap_mint req c1 CAP_OK
482ret false
483end
484if ne get c1 cap_id 1
485ret false
486end
487if ne get c1 generation hi_gen
488ret false
489end
490ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
491if ne cap_validate c1 4 44 CAP_RIGHT_READ ent CAP_OK
492ret false
493end
494note Low-32 truncated generation fails closed
495trunc = new CapRef 1 5
496if ne cap_validate trunc 4 44 CAP_RIGHT_READ ent CAP_ERR_STALE_GEN
497ret false
498end
499ret true
500end
501
502fn test_11_ordinary_no_admin_and_depth to bool
503if ne cap_start CAP_OK
504ret false
505end
506off = new CapRef 0 0
507if ne cap_office off CAP_OK
508ret false
509end
510req = new CapMint 0 0 0 0 0 0 0 0 0
511r_rd = or CAP_RIGHT_READ CAP_RIGHT_DELEGATE
512mk_root_req 1 500 r_rd 0 off req
513cur = new CapRef 0 0
514if ne cap_mint req cur CAP_OK
515ret false
516end
517note Ordinary cap cannot revoke, reclaim, advance clock, or bump epoch
518if ne cap_revoke cur off CAP_ERR_UNAUTHORIZED
519ret false
520end
521if ne cap_reclaim cur 2 CAP_ERR_UNAUTHORIZED
522ret false
523end
524if ne cap_advance_clock cur 1 CAP_ERR_UNAUTHORIZED
525ret false
526end
527if ne cap_bump_epoch cur CAP_ERR_UNAUTHORIZED
528ret false
529end
530note Chain up to CAP_MAX_DEPTH = 8 succeeds
531nxt = new CapRef 0 0
532d = uint 0
533while lt d CAP_MAX_DEPTH bound 16
534mk_deleg_req add 2 d 500 r_rd 0 cur req
535if ne cap_mint req nxt CAP_OK
536ret false
537end
538put cur cap_id get nxt cap_id
539put cur generation get nxt generation
540d = add d 1
541end
542note 9th hop must fail with CAP_ERR_CHAIN
543mk_deleg_req 99 500 CAP_RIGHT_READ 0 cur req
544too_deep = new CapRef 0 0
545if ne cap_mint req too_deep CAP_ERR_CHAIN
546ret false
547end
548ret true
549end
550
551fn test_12_table_fills_then_refuses to bool
552if ne cap_start CAP_OK
553ret false
554end
555off = new CapRef 0 0
556if ne cap_office off CAP_OK
557ret false
558end
559req = new CapMint 0 0 0 0 0 0 0 0 0
560mk_root_req 1 100 CAP_RIGHT_READ 0 off req
561c = new CapRef 0 0
562note Slot 0 is office; slots 1..255 = 255 mints succeed
563i = uint 1
564while lt i CAP_MAX bound 256
565if ne cap_mint req c CAP_OK
566ret false
567end
568i = add i 1
569end
570note 256th mint fails with CAP_ERR_FULL
571if ne cap_mint req c CAP_ERR_FULL
572ret false
573end
574ret true
575end
576
577fn check_obs_rev idx ulong exp_id uint to bool
578ev = new CapObsEvent 0 0 0 0 0 0 0 0 0
579if not cap_obs_get idx ev
580ret false
581end
582if ne get ev op CAP_OBS_REVOKE
583ret false
584end
585if ne get ev cap_id exp_id
586ret false
587end
588ret true
589end
590
591fn check_obs_refusal idx ulong exp_op uint exp_rc int to bool
592ev = new CapObsEvent 0 0 0 0 0 0 0 0 0
593if not cap_obs_get idx ev
594ret false
595end
596if ne get ev op exp_op
597ret false
598end
599if ne get ev rc exp_rc
600ret false
601end
602if ne get ev has_entry 0
603ret false
604end
605ret true
606end
607
608fn test_13_observer_semantics to bool
609if ne cap_start CAP_OK
610ret false
611end
612cap_obs_clear
613cap_set_observer true
614off = new CapRef 0 0
615if ne cap_office off CAP_OK
616ret false
617end
618req = new CapMint 0 0 0 0 0 0 0 0 0
619r_rd = or CAP_RIGHT_READ CAP_RIGHT_DELEGATE
620mk_root_req 1 888 r_rd 0 off req
621p = new CapRef 0 0
622if ne cap_mint req p CAP_OK
623ret false
624end
625mk_deleg_req 2 888 r_rd 0 p req
626c = new CapRef 0 0
627if ne cap_mint req c CAP_OK
628ret false
629end
630mk_deleg_req 3 888 CAP_RIGHT_READ 0 c req
631gc = new CapRef 0 0
632if ne cap_mint req gc CAP_OK
633ret false
634end
635note 3 MINT events
636if ne cap_obs_count 3
637ret false
638end
639note Validate (even denied) must NEVER emit an observer event
640ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
641if ne cap_validate gc 999 888 CAP_RIGHT_READ ent CAP_ERR_SUBJECT
642ret false
643end
644if ne cap_obs_count 3
645ret false
646end
647note Cascade revoke must announce p, then c, then gc (ancestor first)
648if ne cap_revoke off p CAP_OK
649ret false
650end
651if ne cap_obs_count 6
652ret false
653end
654if not check_obs_rev 3 get p cap_id
655ret false
656end
657if not check_obs_rev 4 get c cap_id
658ret false
659end
660if not check_obs_rev 5 get gc cap_id
661ret false
662end
663note Refused admin op reports has_entry=0 and exact refusal code
664if ne cap_reclaim off 200 CAP_ERR_STATE
665ret false
666end
667if not check_obs_refusal 6 CAP_OBS_RECLAIM CAP_ERR_STATE
668ret false
669end
670note Disable observer -> silent on subsequent ops
671cap_set_observer false
672if ne cap_advance_clock off 5 CAP_OK
673ret false
674end
675if ne cap_obs_count 7
676ret false
677end
678ret true
679end
680
681fn test_14_validate_needs_all_rights to bool
682if ne cap_start CAP_OK
683ret false
684end
685off = new CapRef 0 0
686if ne cap_office off CAP_OK
687ret false
688end
689req = new CapMint 0 0 0 0 0 0 0 0 0
690mk_root_req 5 600 CAP_RIGHT_READ 0 off req
691c1 = new CapRef 0 0
692if ne cap_mint req c1 CAP_OK
693ret false
694end
695ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
696if ne cap_validate c1 5 600 or CAP_RIGHT_READ CAP_RIGHT_WRITE ent CAP_ERR_RIGHTS
697ret false
698end
699mk_root_req 5 600 or CAP_RIGHT_READ CAP_RIGHT_WRITE 0 off req
700c2 = new CapRef 0 0
701if ne cap_mint req c2 CAP_OK
702ret false
703end
704if ne cap_validate c2 5 600 or CAP_RIGHT_READ CAP_RIGHT_WRITE ent CAP_OK
705ret false
706end
707ret true
708end
709
710fn test_15_lease_exact_tick_and_overflow to bool
711if ne cap_start CAP_OK
712ret false
713end
714off = new CapRef 0 0
715if ne cap_office off CAP_OK
716ret false
717end
718req = new CapMint 0 0 0 0 0 0 0 0 0
719mk_root_req 7 700 CAP_RIGHT_READ 10 off req
720c = new CapRef 0 0
721if ne cap_mint req c CAP_OK
722ret false
723end
724if ne cap_advance_clock off 9 CAP_OK
725ret false
726end
727ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
728if ne cap_validate c 7 700 CAP_RIGHT_READ ent CAP_OK
729ret false
730end
731if ne cap_advance_clock off 1 CAP_OK
732ret false
733end
734if ne cap_validate c 7 700 CAP_RIGHT_READ ent CAP_ERR_EXPIRED
735ret false
736end
737note Clock overflow fails closed
738if ne cap_advance_clock off CAP_U64_MAX CAP_ERR_OVERFLOW
739ret false
740end
741if ne cap_clock 10
742ret false
743end
744ret true
745end
746
747fn test_16_corrupt_non_live_parent to bool
748if ne cap_start CAP_OK
749ret false
750end
751off = new CapRef 0 0
752if ne cap_office off CAP_OK
753ret false
754end
755req = new CapMint 0 0 0 0 0 0 0 0 0
756mk_root_req 1 900 or CAP_RIGHT_READ CAP_RIGHT_DELEGATE 0 off req
757p = new CapRef 0 0
758if ne cap_mint req p CAP_OK
759ret false
760end
761mk_deleg_req 2 900 CAP_RIGHT_READ 0 p req
762c = new CapRef 0 0
763if ne cap_mint req c CAP_OK
764ret false
765end
766note Corrupt parent to REVOKED directly without cascading child
767if ne cap_corrupt_slot_state get p cap_id CAP_STATE_REVOKED CAP_OK
768ret false
769end
770ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0
771if ne cap_validate c 2 900 CAP_RIGHT_READ ent CAP_ERR_CHAIN
772ret false
773end
774ret true
775end
776
777fn test_17_control_resource_cannot_admin to bool
778if ne cap_start CAP_OK
779ret false
780end
781off = new CapRef 0 0
782if ne cap_office off CAP_OK
783ret false
784end
785req = new CapMint 0 0 0 0 0 0 0 0 0
786note Capability carrying CAP_RIGHT_EPOCH on non-authority resource 0x999
787mk_root_req 8 0x999 CAP_RIGHT_EPOCH 0 off req
788ctrl = new CapRef 0 0
789if ne cap_mint req ctrl CAP_OK
790ret false
791end
792if ne cap_bump_epoch ctrl CAP_ERR_RESOURCE
793ret false
794end
795ret true
796end
797
798fn test_18_office_token_auth_and_rotation to bool
799if ne cap_start CAP_OK
800ret false
801end
802t1 = new uchar 32 0
803cap_copy_token t1
804if ne cap_authorize t1 CAP_OK
805ret false
806end
807note Flip 1 bit -> must fail closed
808bad = new uchar 32 0
809for i ulong 32
810put bad i get t1 i
811end
812put bad 15 xor get bad 15 1
813if ne cap_authorize bad CAP_ERR_UNAUTHORIZED
814ret false
815end
816note Restart rotates token -> old token rejected, new token accepted
817if ne cap_restart CAP_OK
818ret false
819end
820if ne cap_authorize t1 CAP_ERR_UNAUTHORIZED
821ret false
822end
823t2 = new uchar 32 0
824cap_copy_token t2
825if ne cap_authorize t2 CAP_OK
826ret false
827end
828ret true
829end
830
831fn main to int
832failed = uint 0
833failed = add failed report s_t01 test_01_high_half_resource
834failed = add failed report s_t02 test_02_forged_stale_fail_closed
835failed = add failed report s_t03 test_03_amplification_lease_epoch_revoke
836failed = add failed report s_t04 test_04_child_lease_bound
837failed = add failed report s_t05 test_05_privileged_not_delegable
838failed = add failed report s_t06 test_06_promote_not_delegable
839failed = add failed report s_t07 test_07_generation_exhaustion
840failed = add failed report s_t08 test_08_kill_restart_cognition
841failed = add failed report s_t09 test_09_reclaimed_stays_dead_after_restart
842failed = add failed report s_t10 test_10_gen_above_32_bits
843failed = add failed report s_t11 test_11_ordinary_no_admin_and_depth
844failed = add failed report s_t12 test_12_table_fills_then_refuses
845failed = add failed report s_t13 test_13_observer_semantics
846failed = add failed report s_t14 test_14_validate_needs_all_rights
847failed = add failed report s_t15 test_15_lease_exact_tick_and_overflow
848failed = add failed report s_t16 test_16_corrupt_non_live_parent
849failed = add failed report s_t17 test_17_control_resource_cannot_admin
850failed = add failed report s_t18 test_18_office_token_auth_and_rotation
851if eq failed 0
852w = cap_write_all 1 s_sum
853if w
854ret 0
855end
856ret 1
857end
858w = cap_write_all 1 s_fsum
859if w
860ret 1
861end
862ret 1
863end