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 / crates / aienos-anchor / anchor_test.om

166 lines · 3572 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/crates/aienos-anchor/anchor_test.om: Behavioral self-test for aienos-anchor.
3note Compose with: si/directives/om2.om om/tls/sha2.om aienux/crates/aienos-anchor/anchor.om aienux/crates/aienos-anchor/anchor_test.om
4
5text at_k1 "host.arch"
6text at_v1 "aarch64"
7text at_v2 "aarch64-gb10"
8text at_src "boot-verify"
9text at_k2 "missing.key"
10
11fn main to int
12anchor_init
13key_a = new uchar 32 0x11
14key_b = new uchar 32 0x22
15rc = anchor_add_trusted key_a
16if ne rc ANCHOR_OK
17ret 1
18end
19
20note 1. Unknown key before any admission
21if ne anchor_query at_k1 ANCHOR_ANS_UNKNOWN
22ret 2
23end
24
25note 2. Admit fact seq 0
26anchor_stage_hdr 0 ANCHOR_KIND_ADMIT 1000
27rc = anchor_stage_kv at_k1 at_v1
28if ne rc ANCHOR_OK
29ret 3
30end
31rc = anchor_stage_source at_src
32if ne rc ANCHOR_OK
33ret 4
34end
35anchor_sign_staged key_a
36rc = anchor_append_staged
37if ne rc ANCHOR_OK
38ret 5
39end
40if ne anchor_query at_k1 ANCHOR_ANS_KNOWN
41ret 6
42end
43if ne get anchor_q_res 2 0
44ret 7
45end
46
47note 3. Reject untrusted signer
48anchor_stage_hdr 1 ANCHOR_KIND_ADMIT 1001
49rc = anchor_stage_kv at_k1 at_v2
50if ne rc ANCHOR_OK
51ret 8
52end
53anchor_sign_staged key_b
54if ne anchor_append_staged ANCHOR_ERR_UNTRUSTED
55ret 9
56end
57
58note 4. Reject out-of-order seq
59anchor_stage_hdr 5 ANCHOR_KIND_ADMIT 1001
60rc = anchor_stage_kv at_k1 at_v2
61anchor_sign_staged key_a
62if ne anchor_append_staged ANCHOR_ERR_OUT_OF_ORDER
63ret 10
64end
65
66note 5. Reject broken chain prev
67anchor_stage_hdr 1 ANCHOR_KIND_ADMIT 1001
68rc = anchor_stage_kv at_k1 at_v2
69bad_prev = new uchar 32 0x99
70anchor_stage_prev bad_prev
71anchor_sign_staged key_a
72if ne anchor_append_staged ANCHOR_ERR_BROKEN_CHAIN
73ret 11
74end
75
76note 6. Reject tampered signature
77anchor_stage_hdr 1 ANCHOR_KIND_ADMIT 1001
78rc = anchor_stage_kv at_k1 at_v2
79anchor_sign_staged key_a
80put anchor_st_sig 0 xor get anchor_st_sig 0 1
81if ne anchor_append_staged ANCHOR_ERR_BAD_SIG
82ret 12
83end
84
85note 7. Reject retract with non-empty value
86anchor_stage_hdr 1 ANCHOR_KIND_RETRACT 1002
87rc = anchor_stage_kv at_k1 at_v1
88anchor_sign_staged key_a
89if ne anchor_append_staged ANCHOR_ERR_RETRACT_VALUE
90ret 13
91end
92
93note 8. Reject retract of unknown key
94empty_v = new uchar 1 0
95anchor_stage_hdr 1 ANCHOR_KIND_RETRACT 1002
96rc = anchor_stage_kv at_k2 part empty_v 0 0
97anchor_sign_staged key_a
98if ne anchor_append_staged ANCHOR_ERR_RETRACT_UNKNOWN
99ret 14
100end
101
102note 9. Valid update seq 1 then retract seq 2
103anchor_stage_hdr 1 ANCHOR_KIND_ADMIT 1002
104rc = anchor_stage_kv at_k1 at_v2
105anchor_sign_staged key_a
106if ne anchor_append_staged ANCHOR_OK
107ret 15
108end
109anchor_stage_hdr 2 ANCHOR_KIND_RETRACT 1003
110rc = anchor_stage_kv at_k1 part empty_v 0 0
111anchor_sign_staged key_a
112if ne anchor_append_staged ANCHOR_OK
113ret 16
114end
115if ne anchor_query at_k1 ANCHOR_ANS_RETRACTED
116ret 17
117end
118if ne get anchor_q_res 2 2
119ret 18
120end
121
122note 10. Export all 3 entries and replay into a fresh anchor
123logbuf = new uchar 2048 0
124pos = ulong 0
125saved_head = new uchar 32 0
126for i ulong 32
127put saved_head i get anchor_head i
128end
129ebuf = new uchar 512 0
130for idx ulong 3
131elen = anchor_export_entry idx ebuf
132for j ulong elen bound 512
133put logbuf add pos j get ebuf j
134end
135pos = add pos elen
136end
137
138anchor_init
139rc = anchor_add_trusted key_a
140if ne rc ANCHOR_OK
141ret 19
142end
143rc = anchor_replay logbuf pos
144if ne rc ANCHOR_OK
145ret 20
146end
147if ne get anchor_cnt 0 3
148ret 21
149end
150for i ulong 32
151if ne get anchor_head i get saved_head i
152ret 22
153end
154end
155
156note 11. Tampered log byte must refuse replay
157put logbuf 20 xor get logbuf 20 0xff
158anchor_init
159rc = anchor_add_trusted key_a
160rc = anchor_replay logbuf pos
161if eq rc ANCHOR_OK
162ret 23
163end
164
165ret 0
166end