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

285 lines · 6725 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/interplane/v03/test.om: comprehensive positive & negative controls for
3note interplane v0.3.0 (crossaxis, crossveil, conformance, aien_adapter).
4note Compose with:
5note si/directives/om2.om om/tls/sha2.om
6note protocol/interplane/v03/crossaxis.om
7note protocol/interplane/v03/crossveil.om
8note protocol/interplane/v03/conformance.om
9note protocol/interplane/v03/aien_adapter.om
10note protocol/interplane/v03/test.om
11
12text v3_pass "PASS interplane-v03 (crossaxis, crossveil, conformance, aien_adapter) all 7 suites passed\n"
13text v3_fail "FAIL interplane-v03\n"
14
15note RFC 4231 Test Case 2: key = "Jefe", data = "what do ya want for nothing?"
16note Expected HMAC-SHA256: 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
17text rfc_key "Jefe"
18text rfc_msg "what do ya want for nothing?"
19text rfc_exp "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"
20
21text td_p1 "conformance/fixtures/injection/01-basic.json"
22text td_b1 "{\"id\":\"01-basic\",\"kind\":\"injection\"}"
23text td_p2 "conformance/fixtures/approval/01-write.json"
24text td_b2 "{\"id\":\"01-write\",\"kind\":\"approval\"}"
25text td_b2_tamper "{\"id\":\"01-write\",\"kind\":\"tampered\"}"
26
27text desk_key "aien-approval-desk-key-v1"
28text bind_msg "trace=t1|req=r1|app=a1|path=src/lib.om"
29text bind_msg_tamper "trace=t1|req=r1|app=a1|path=src/evil.om"
30
31fn v3_slice_eq a view uchar * b view uchar * to bool
32if ne len a len b
33ret false
34end
35n = len a
36if gt n ulong 1024
37ret false
38end
39i = ulong 0
40while lt i n bound 1024
41if ne get a i get b i
42ret false
43end
44i = add i ulong 1
45end
46ret true
47end
48
49fn v3_test_crossaxis to bool
50rules = new ulong 80 0
51cnt = new ulong 1 0
52spec = new ulong 5 0
53res = new ulong 3 0
54
55note Rule 1: Alias (ns=1, name=10 -> cap=100)
56put spec 0 ulong 1
57put spec 1 CA_RULE_ALIAS
58put spec 2 ulong 1
59put spec 3 ulong 10
60put spec 4 ulong 100
61if ne ca_add_rule rules cnt spec CA_OK
62ret false
63end
64
65note Rule 2: Valid Passthrough (ns=0, name=20 -> cap=20)
66put spec 0 ulong 2
67put spec 1 CA_RULE_PASSTHROUGH
68put spec 2 ulong 0
69put spec 3 ulong 20
70put spec 4 ulong 20
71if ne ca_add_rule rules cnt spec CA_OK
72ret false
73end
74
75note Negative control: Passthrough with non-null namespace must be refused
76put spec 0 ulong 3
77put spec 1 CA_RULE_PASSTHROUGH
78put spec 2 ulong 1
79put spec 3 ulong 20
80put spec 4 ulong 20
81if ne ca_add_rule rules cnt spec CA_ERR_BAD_PASSTHROUGH
82ret false
83end
84
85note Negative control: Passthrough with from_name != to_cap must be refused
86put spec 2 ulong 0
87put spec 4 ulong 21
88if ne ca_add_rule rules cnt spec CA_ERR_BAD_PASSTHROUGH
89ret false
90end
91
92note Exact lookup matches Rule 1 (Alias) and Rule 2 (Passthrough); unknown -> CA_ERR_UNKNOWN_CAP
93if ne ca_map_tool rules get cnt 0 ulong 1 ulong 10 res CA_OK
94ret false
95end
96if or ne get res 0 ulong 100 ne get res 2 ulong 0
97ret false
98end
99if ne ca_map_tool rules get cnt 0 ulong 0 ulong 20 res CA_OK
100ret false
101end
102if or ne get res 0 ulong 20 ne get res 2 ulong 1
103ret false
104end
105if ne ca_map_tool rules get cnt 0 ulong 9 ulong 99 res CA_ERR_UNKNOWN_CAP
106ret false
107end
108
109note Deterministic domain selector with budget=10
110cm = new ulong 16 0
111cc = new ulong 16 0
112sel = new ulong 16 0
113put cm 0 ulong 1
114put cc 0 ulong 6
115put cm 1 ulong 2
116put cc 1 ulong 2
117put cm 2 ulong 1
118put cc 2 ulong 5
119n_sel = ca_select_domain ulong 3 ulong 1 ulong 10 cm cc sel
120if ne n_sel ulong 1
121ret false
122end
123if or ne get sel 0 ulong 1 or ne get sel 1 ulong 2 ne get sel 2 ulong 3
124ret false
125end
126ret true
127end
128
129fn v3_test_conformance_trust_digest to bool
130c1 = new ulong 40 0
131c2 = new ulong 40 0
132c3 = new ulong 40 0
133d1 = new uchar 32 0
134d2 = new uchar 32 0
135d3 = new uchar 32 0
136sha256_init c1
137cf_trust_add_entry c1 td_p1 td_b1
138cf_trust_add_entry c1 td_p2 td_b2
139sha256_final c1 d1
140
141sha256_init c2
142cf_trust_add_entry c2 td_p1 td_b1
143cf_trust_add_entry c2 td_p2 td_b2
144sha256_final c2 d2
145
146if not cf_dig_eq d1 d2
147ret false
148end
149
150note Tampering one fixture body must change TRUST-DIGEST
151sha256_init c3
152cf_trust_add_entry c3 td_p1 td_b1
153cf_trust_add_entry c3 td_p2 td_b2_tamper
154sha256_final c3 d3
155if cf_dig_eq d1 d3
156ret false
157end
158
159note T3/T4 subset rule checks
160if not cf_subset_admit ulong 3 ulong 7
161ret false
162end
163if cf_subset_admit ulong 8 ulong 7
164ret false
165end
166if cf_subset_admit ulong 0 ulong 7
167ret false
168end
169ret true
170end
171
172fn v3_test_hmac_rfc4231 to bool
173mac = new uchar 32 0
174hx = new uchar 64 0
175aien_hmac_sha256 rfc_key rfc_msg mac
176cf_hex32 mac hx
177if not v3_slice_eq hx rfc_exp
178ret false
179end
180note ApprovalBinding tamper detection
181m1 = new uchar 32 0
182m2 = new uchar 32 0
183aien_hmac_sha256 desk_key bind_msg m1
184aien_hmac_sha256 desk_key bind_msg_tamper m2
185if aien_mac_eq m1 m2
186ret false
187end
188ret true
189end
190
191fn v3_test_aien_adapter to bool
192note Fail-closed when gate is not linked
193if ne aien_decide AIEN_CAP_READ_FILE ulong 0 ulong 1 ulong 1 CV_DEC_DENIED
194ret false
195end
196note Read-only allowed when gate allows
197if ne aien_decide AIEN_CAP_READ_FILE ulong 1 ulong 1 ulong 0 CV_DEC_AUTHORIZED
198ret false
199end
200note World mutation requires approval when no grant
201if ne aien_decide AIEN_CAP_WRITE_FILE ulong 1 ulong 1 ulong 0 CV_DEC_REQUIRES_APPROVAL
202ret false
203end
204note World mutation authorized only with explicit grant
205if ne aien_decide AIEN_CAP_WRITE_FILE ulong 1 ulong 1 ulong 1 CV_DEC_AUTHORIZED
206ret false
207end
208note Unknown capability always denied
209if ne aien_decide ulong 99 ulong 1 ulong 1 ulong 1 CV_DEC_DENIED
210ret false
211end
212
213note Two-phase single-use approval grant lifecycle
214st = new ulong 1 0
215put st 0 GRANT_UNUSED
216if ne aien_grant_reserve st AIEN_OK
217ret false
218end
219note Double-reserve fails
220if ne aien_grant_reserve st AIEN_ERR_GRANT_STATE
221ret false
222end
223note Release returns to UNUSED
224if ne aien_grant_release st AIEN_OK
225ret false
226end
227note Reserve -> Commit -> Spent
228if ne aien_grant_reserve st AIEN_OK
229ret false
230end
231if ne aien_grant_commit st AIEN_OK
232ret false
233end
234note Replay of spent grant MUST be refused
235if ne aien_grant_reserve st AIEN_ERR_GRANT_REPLAY
236ret false
237end
238if ne aien_grant_commit st AIEN_ERR_GRANT_REPLAY
239ret false
240end
241if ne aien_grant_revoke st AIEN_ERR_GRANT_REPLAY
242ret false
243end
244note Revoking an unused grant blocks subsequent reserve
245st2 = new ulong 1 0
246put st2 0 GRANT_UNUSED
247if ne aien_grant_revoke st2 AIEN_OK
248ret false
249end
250if ne aien_grant_reserve st2 AIEN_ERR_GRANT_REVOKED
251ret false
252end
253ret true
254end
255
256fn main to int
257ok = true
258if not v3_test_crossaxis
259ok = false
260end
261if not cf_verify_negctl_matrix
262ok = false
263end
264if not v3_test_conformance_trust_digest
265ok = false
266end
267if not v3_test_hmac_rfc4231
268ok = false
269end
270if not v3_test_aien_adapter
271ok = false
272end
273if not ok
274k = write int 1 v3_fail ulong 0 len v3_fail
275if lt k long 0
276ret int 1
277end
278ret int 1
279end
280k = write int 1 v3_pass ulong 0 len v3_pass
281if lt k long 0
282ret int 1
283end
284ret int 0
285end