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

409 lines · 11730 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/open-humanity/test.om: comprehensive positive and negative control tests for
3note protocol/open-humanity/lib.om.
4note Compose with: si/directives/om2.om protocol/open-humanity/lib.om protocol/open-humanity/test.om
5
6text oht_pass "PASS "
7text oht_fail "FAIL "
8text oht_nl "\n"
9text oht_sum_ok "OPEN_HUMANITY_TEST PASS passed="
10text oht_sum_fl "OPEN_HUMANITY_TEST FAIL passed="
11text oht_fld " failed="
12
13text oht_n1 "wire_roundtrip_and_tamper_refusal"
14text oht_n2 "opt_in_distress_routing_and_resolution"
15text oht_n3 "opt_out_refusal_outbound_and_inbound"
16text oht_n4 "ttl_expiry_and_invalid_ttl_refusal"
17text oht_n5 "privacy_firewall_secrets_refusal"
18text oht_n6 "privacy_firewall_paths_and_obfuscation"
19text oht_n7 "privacy_path_scrubber_sanitizes_safely"
20text oht_n8 "authority_boundary_priv_esc_refusal"
21text oht_n9 "replay_self_resolve_and_queue_bound"
22
23text oht_clean_q "E0425 cannot find value x in crate::module at line 42"
24text oht_clean_a "Add use crate::module::x before invoking the helper function"
25text oht_aws "leak AKIA1234567890ABCDEF in build log"
26text oht_gh "token ghp_0123456789abcdefghijklmnopqrstuvwxyz found"
27text oht_ant "key sk-ant-abcdefghijklmnopqrstuvwx leaked"
28text oht_oai "key sk-proj-0123456789abcdefghijklm leaked"
29text oht_pem "-----BEGIN RSA PRIVATE KEY----- body"
30text oht_gen "config api_key = \"supersecretvalue123456\" here"
31text oht_upath "error at /Users/alice/private/main.rs:10"
32text oht_hpath "error at /home/bob/work/main.rs:10"
33text oht_wpath "error at C:\\Users\\eve\\proj\\main.rs"
34text oht_trav "include ../../etc/shadow failed"
35text oht_pct "obfuscated %41KIA1234567890ABCDEF secret"
36text oht_scrub_want "error at ~/private/main.rs:10"
37text oht_esc_sudo "try running sudo rm -rf /tmp/cache"
38text oht_esc_id "export OPEN_HUMANITY_IDENTITY from host"
39text oht_esc_exec "exec: /bin/sh to inspect"
40
41fn oht_rec name view uchar * ok bool tally edit ulong 2 to void
42w = false
43if ok
44put tally 0 add get tally 0 1
45w = oh_write_all 1 oht_pass
46else
47put tally 1 add get tally 1 1
48w = oh_write_all 1 oht_fail
49end
50w = and w oh_write_all 1 name
51w = and w oh_write_all 1 oht_nl
52if w
53ret
54end
55end
56
57fn oht_bytes_eq a view uchar * b view uchar * to bool
58if ne len a len b
59ret false
60end
61n = len a
62i = ulong 0
63while lt i n bound 1024
64if ne get a i get b i
65ret false
66end
67i = add i 1
68end
69ret true
70end
71
72fn test_wire_roundtrip to bool
73env = new OhEnv OH_VERSION 777 1 OH_CAT_RUST 1000 60000 0 0 0
74wire = new uchar 560 0
75wn = oh_serialize_envelope env oht_clean_q wire
76if eq wn 0
77ret false
78end
79if ne wn add OH_HDR_LEN len oht_clean_q
80ret false
81end
82parsed = new OhEnv 0 0 0 0 0 0 0 0 0
83pbuf = new uchar 512 0
84rc = oh_parse_envelope part wire 0 wn parsed pbuf
85if ne rc OH_OK
86ret false
87end
88if ne get parsed peer_id 777
89ret false
90end
91if ne get parsed consent 1
92ret false
93end
94if ne get parsed category OH_CAT_RUST
95ret false
96end
97if ne get parsed ttl_ms 60000
98ret false
99end
100if not oht_bytes_eq part pbuf 0 get parsed payload_len oht_clean_q
101ret false
102end
103note Negative control: flip 1 byte in payload -> BAD_DIGEST
104put wire OH_HDR_LEN xor get wire OH_HDR_LEN 1
105rc_tamper = oh_parse_envelope part wire 0 wn parsed pbuf
106if ne rc_tamper OH_ERR_BAD_DIGEST
107ret false
108end
109note Negative control: bad version -> BAD_VERSION
110put wire 2 uchar 9
111rc_ver = oh_parse_envelope part wire 0 wn parsed pbuf
112if ne rc_ver OH_ERR_BAD_VERSION
113ret false
114end
115note Negative control: bad magic -> BAD_MAGIC
116put wire 0 uchar 0
117rc_mag = oh_parse_envelope part wire 0 wn parsed pbuf
118ret eq rc_mag OH_ERR_BAD_MAGIC
119end
120
121fn test_optin_routing_resolution to bool
122pol = new OhPolicy 0 0 1 0 0
123oh_reset_state pol
124put pol opt_in ulong 1
125put pol now_ms ulong 5000
126env = new OhEnv OH_VERSION 101 1 OH_CAT_RUST 4000 60000 0 0 0
127req = new ulong 1 0
128rc1 = oh_submit_distress pol env oht_clean_q req
129if ne rc1 OH_OK
130ret false
131end
132rid = get req 0
133if ne rid 1
134ret false
135end
136if ne oh_queue_pending_count 1
137ret false
138end
139helper = new OhEnv OH_VERSION 202 1 OH_CAT_RUST 5000 60000 0 0 0
140rc2 = oh_resolve_distress pol rid helper oht_clean_a
141if ne rc2 OH_OK
142ret false
143end
144if ne oh_queue_pending_count 0
145ret false
146end
147note Audit trail must record ENQUEUED then RESOLVED
148if ne oh_audit_count 2
149ret false
150end
151if ne get oh_aud_kind 0 OH_AUD_ENQUEUED
152ret false
153end
154if ne get oh_aud_kind 1 OH_AUD_RESOLVED
155ret false
156end
157ret eq get oh_aud_peer 1 202
158end
159
160fn test_opt_out_refusals to bool
161pol = new OhPolicy 0 0 1 0 0
162oh_reset_state pol
163put pol now_ms ulong 5000
164env = new OhEnv OH_VERSION 101 1 OH_CAT_RUST 4500 60000 0 0 0
165req = new ulong 1 0
166note Node opt-in is 0 by default -> MUST refuse outbound distress
167if ne oh_submit_distress pol env oht_clean_q req OH_ERR_NODE_OPT_OUT
168ret false
169end
170note Enable node opt-in, but envelope consent_flag=0 -> MUST refuse
171put pol opt_in ulong 1
172put env consent ulong 0
173if ne oh_submit_distress pol env oht_clean_q req OH_ERR_NO_CONSENT
174ret false
175end
176note Submit valid request with consent=1
177put env consent ulong 1
178if ne oh_submit_distress pol env oht_clean_q req OH_OK
179ret false
180end
181note Now opt out node -> inbound resolution MUST be refused
182put pol opt_in ulong 0
183helper = new OhEnv OH_VERSION 202 1 OH_CAT_RUST 5000 60000 0 0 0
184ret eq oh_resolve_distress pol get req 0 helper oht_clean_a OH_ERR_NODE_OPT_OUT
185end
186
187fn test_ttl_refusals to bool
188pol = new OhPolicy 0 0 1 0 0
189oh_reset_state pol
190put pol opt_in ulong 1
191put pol now_ms ulong 10000
192req = new ulong 1 0
193note Zero TTL refused
194e0 = new OhEnv OH_VERSION 101 1 OH_CAT_SIMD 10000 0 0 0 0
195if ne oh_submit_distress pol e0 oht_clean_q req OH_ERR_TTL_INVALID
196ret false
197end
198note Oversized TTL (> 7 days) refused
199ebig = new OhEnv OH_VERSION 101 1 OH_CAT_SIMD 10000 add OH_MAX_TTL_MS 1 0 0 0
200if ne oh_submit_distress pol ebig oht_clean_q req OH_ERR_TTL_INVALID
201ret false
202end
203note Already expired envelope refused
204eexp = new OhEnv OH_VERSION 101 1 OH_CAT_SIMD 1000 5000 0 0 0
205if ne oh_submit_distress pol eexp oht_clean_q req OH_ERR_TTL_EXPIRED
206ret false
207end
208note Enqueue valid 2000ms request at now=10000, advance clock to 12000 -> resolution refused
209eok = new OhEnv OH_VERSION 101 1 OH_CAT_SIMD 10000 2000 0 0 0
210if ne oh_submit_distress pol eok oht_clean_q req OH_OK
211ret false
212end
213put pol now_ms ulong 12000
214helper = new OhEnv OH_VERSION 202 1 OH_CAT_SIMD 12000 2000 0 0 0
215if ne oh_resolve_distress pol get req 0 helper oht_clean_a OH_ERR_TTL_EXPIRED
216ret false
217end
218ret eq oh_queue_pending_count 0
219end
220
221fn test_privacy_secrets to bool
222if ne oh_privacy_check oht_aws OH_ERR_PRIV_AWS_KEY
223ret false
224end
225if ne oh_privacy_check oht_gh OH_ERR_PRIV_GITHUB_TOKEN
226ret false
227end
228if ne oh_privacy_check oht_ant OH_ERR_PRIV_ANTHROPIC_KEY
229ret false
230end
231if ne oh_privacy_check oht_oai OH_ERR_PRIV_OPENAI_KEY
232ret false
233end
234if ne oh_privacy_check oht_pem OH_ERR_PRIV_PEM_KEY
235ret false
236end
237if ne oh_privacy_check oht_gen OH_ERR_PRIV_GENERIC_SECRET
238ret false
239end
240note Answer firewall: secret inside peer resolution MUST also be refused
241pol = new OhPolicy 0 0 1 0 0
242oh_reset_state pol
243put pol opt_in ulong 1
244put pol now_ms ulong 1000
245env = new OhEnv OH_VERSION 101 1 OH_CAT_SEC 1000 60000 0 0 0
246req = new ulong 1 0
247if ne oh_submit_distress pol env oht_clean_q req OH_OK
248ret false
249end
250helper = new OhEnv OH_VERSION 202 1 OH_CAT_SEC 1000 60000 0 0 0
251ret eq oh_resolve_distress pol get req 0 helper oht_aws OH_ERR_PRIV_AWS_KEY
252end
253
254fn test_privacy_paths_obf to bool
255if ne oh_privacy_check oht_upath OH_ERR_PRIV_USER_PATH
256ret false
257end
258if ne oh_privacy_check oht_hpath OH_ERR_PRIV_USER_PATH
259ret false
260end
261if ne oh_privacy_check oht_wpath OH_ERR_PRIV_USER_PATH
262ret false
263end
264if ne oh_privacy_check oht_trav OH_ERR_PRIV_TRAVERSAL
265ret false
266end
267note Percent-encoded AWS key (%41KIA...) MUST be caught after obfuscation normalization
268if ne oh_privacy_check oht_pct OH_ERR_PRIV_AWS_KEY
269ret false
270end
271note Zero-width UTF-8 U+200B (E2 80 8B) inserted between A and KIA MUST be caught
272zw = new uchar 24 0
273put zw 0 uchar 65
274put zw 1 uchar 0xe2
275put zw 2 uchar 0x80
276put zw 3 uchar 0x8b
277put zw 4 uchar 75
278put zw 5 uchar 73
279put zw 6 uchar 65
280i = ulong 0
281while lt i 16 bound 16
282put zw add 7 i uchar add 65 rem i 10
283i = add i 1
284end
285ret eq oh_privacy_check part zw 0 23 OH_ERR_PRIV_AWS_KEY
286end
287
288fn test_path_scrubber to bool
289dst = new uchar 128 0
290n = oh_scrub_paths oht_upath dst
291if not oht_bytes_eq part dst 0 n oht_scrub_want
292ret false
293end
294ret eq oh_privacy_check part dst 0 n OH_OK
295end
296
297fn test_authority_boundary to bool
298pol = new OhPolicy 0 0 1 0 0
299oh_reset_state pol
300put pol opt_in ulong 1
301put pol now_ms ulong 2000
302req = new ulong 1 0
303env = new OhEnv OH_VERSION 101 1 OH_CAT_PROTO 2000 60000 OH_CAP_LOCAL_EXEC 0 0
304if ne oh_submit_distress pol env oht_clean_q req OH_ERR_AUTH_EXEC
305ret false
306end
307put env cap_flags OH_CAP_SECRET_ACCESS
308if ne oh_submit_distress pol env oht_clean_q req OH_ERR_AUTH_SECRET
309ret false
310end
311put env cap_flags OH_CAP_IDENTITY_MUTATE
312if ne oh_submit_distress pol env oht_clean_q req OH_ERR_AUTH_IDENTITY
313ret false
314end
315put env cap_flags OH_CAP_ADMIN_RIGHTS
316if ne oh_submit_distress pol env oht_clean_q req OH_ERR_AUTH_ADMIN
317ret false
318end
319put env cap_flags ulong 0x10
320if ne oh_submit_distress pol env oht_clean_q req OH_ERR_AUTH_UNKNOWN
321ret false
322end
323note Zero cap_flags with smuggled escalation directive in payload MUST still be refused
324put env cap_flags OH_CAP_NONE
325if ne oh_submit_distress pol env oht_esc_sudo req OH_ERR_AUTH_PAYLOAD_ESC
326ret false
327end
328if ne oh_submit_distress pol env oht_esc_id req OH_ERR_AUTH_PAYLOAD_ESC
329ret false
330end
331if ne oh_submit_distress pol env oht_esc_exec req OH_ERR_AUTH_PAYLOAD_ESC
332ret false
333end
334note Resolution with privilege flag MUST also be refused
335if ne oh_submit_distress pol env oht_clean_q req OH_OK
336ret false
337end
338helper = new OhEnv OH_VERSION 202 1 OH_CAT_PROTO 2000 60000 OH_CAP_LOCAL_EXEC 0 0
339if ne oh_resolve_distress pol get req 0 helper oht_clean_a OH_ERR_AUTH_EXEC
340ret false
341end
342put helper cap_flags OH_CAP_NONE
343ret eq oh_resolve_distress pol get req 0 helper oht_esc_sudo OH_ERR_AUTH_PAYLOAD_ESC
344end
345
346fn test_replay_self_and_bound to bool
347pol = new OhPolicy 0 0 1 0 0
348oh_reset_state pol
349put pol opt_in ulong 1
350put pol now_ms ulong 10000
351req = new ulong 1 0
352env = new OhEnv OH_VERSION 500 1 OH_CAT_AGENT 10000 60000 0 0 0
353if ne oh_submit_distress pol env oht_clean_q req OH_OK
354ret false
355end
356first_rid = get req 0
357note Duplicate distress (same peer + digest) -> REPLAY
358if ne oh_submit_distress pol env oht_clean_q req OH_ERR_REPLAY
359ret false
360end
361note Self-resolution by same peer_id -> SELF_RESOLVE
362selfh = new OhEnv OH_VERSION 500 1 OH_CAT_AGENT 10000 60000 0 0 0
363if ne oh_resolve_distress pol first_rid selfh oht_clean_a OH_ERR_SELF_RESOLVE
364ret false
365end
366note Fill remaining 31 queue slots with distinct peers -> 32nd succeeds, 33rd MUST hit QUEUE_FULL
367i = ulong 1
368while lt i OH_QUEUE_CAP bound 32
369put env peer_id add 500 i
370if ne oh_submit_distress pol env oht_clean_q req OH_OK
371ret false
372end
373i = add i 1
374end
375if ne oh_queue_pending_count OH_QUEUE_CAP
376ret false
377end
378put env peer_id ulong 9999
379ret eq oh_submit_distress pol env oht_clean_q req OH_ERR_QUEUE_FULL
380end
381
382fn main to int
383tally = new ulong 2 0
384oht_rec oht_n1 test_wire_roundtrip tally
385oht_rec oht_n2 test_optin_routing_resolution tally
386oht_rec oht_n3 test_opt_out_refusals tally
387oht_rec oht_n4 test_ttl_refusals tally
388oht_rec oht_n5 test_privacy_secrets tally
389oht_rec oht_n6 test_privacy_paths_obf tally
390oht_rec oht_n7 test_path_scrubber tally
391oht_rec oht_n8 test_authority_boundary tally
392oht_rec oht_n9 test_replay_self_and_bound tally
393passed = get tally 0
394failed = get tally 1
395ok = false
396if eq failed 0
397ok = oh_write_all 1 oht_sum_ok
398else
399ok = oh_write_all 1 oht_sum_fl
400end
401oh_write_u64 1 passed
402ok = and ok oh_write_all 1 oht_fld
403oh_write_u64 1 failed
404ok = and ok oh_write_all 1 oht_nl
405if and ok eq failed 0
406ret 0
407end
408ret 1
409end