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-artifact-tool / artifact_tool_test.om

489 lines · 10577 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/crates/aienos-artifact-tool/artifact_tool_test.om: Behavioral self-test for aienos-artifact-tool.
3note Compose with: si/directives/om2.om om/tls/sha2.om aienux/crates/aienos-artifact-tool/artifact_tool.om aienux/crates/aienos-artifact-tool/artifact_tool_test.om
4
5note Golden artifact_id hex from main.rs::tests::deterministic_pack_uses_the_shared_parser_and_id
6text t_golden_id "71976b5c38ec15f2307565ed3eea51fde4a5375970cd49338d6e16166238cf4b"
7text t_data4 "DATA"
8text t_bad_cmd "unknown"
9text t_arg_x "x"
10text t_ws_pre " \n\t"
11
12fn t_test_pack_and_golden_id to int
13at_manifest_reset
14at_manifest_set_entry 0
15idx = at_manifest_push_cap 3 7 1 1 4
16if lt idx 0
17ret 1
18end
19at_manifest_set_cap_bounds ulong idx 4 0 4
20at_manifest_set_res_pages 1 1 1 1
21at_manifest_set_res_limits 2 16 1000 2000 16
22code = new uchar 4 0
23put code 0 0xc0
24put code 1 0x03
25put code 2 0x5f
26put code 3 0xd6
27b1 = new uchar 512 0
28b2 = new uchar 512 0
29if ne at_pack code t_data4 b1 AT_OK
30ret 2
31end
32n1 = get at_pack_len 0
33if ne at_pack code t_data4 b2 AT_OK
34ret 3
35end
36n2 = get at_pack_len 0
37if ne n1 n2
38ret 4
39end
40if not at_bytes_eq part b1 0 n1 part b2 0 n2
41ret 5
42end
43hex_buf = new uchar 64 0
44if ne at_id_hex part b1 0 n1 hex_buf AT_OK
45ret 6
46end
47if not at_bytes_eq hex_buf t_golden_id
48ret 7
49end
50if ne at_inspect_artifact part b1 0 n1 AT_OK
51ret 8
52end
53if ne get at_art_meta 2 1
54ret 9
55end
56if ne get at_art_meta 7 4
57ret 10
58end
59if ne get at_art_meta 9 4
60ret 11
61end
62ret 0
63end
64
65fn t_test_sign_and_verify to int
66at_manifest_reset
67at_manifest_set_res_pages 1 1 1 0
68at_manifest_set_res_limits 0 0 1 1 1
69code = new uchar 4 0
70put code 0 0xc0
71put code 1 0x03
72put code 2 0x5f
73put code 3 0xd6
74buf = new uchar 512 0
75if ne at_pack code t_data4 buf AT_OK
76ret 12
77end
78n = get at_pack_len 0
79note Production mode refuses signing and fails closed on verify
80if ne at_sign_artifact part buf 0 n false AT_ERR_PROD_SIGN_OFF
81ret 13
82end
83if ne at_sign_artifact part buf 0 n true AT_OK
84ret 14
85end
86if ne at_verify_artifact part buf 0 n true AT_OK
87ret 15
88end
89if ne at_verify_artifact part buf 0 n false AT_ERR_UNTRUSTED
90ret 16
91end
92note Mutate one payload byte -> BadSignature (18)
93pay_off = get at_art_meta 4
94put buf pay_off xor get buf pay_off 1
95if ne at_verify_artifact part buf 0 n true AT_ERR_BAD_SIG
96ret 17
97end
98note Restore payload, mutate one signature byte -> BadSignature (18)
99put buf pay_off xor get buf pay_off 1
100sig_off = get at_art_meta 6
101put buf add sig_off 40 xor get buf add sig_off 40 1
102if ne at_verify_artifact part buf 0 n true AT_ERR_BAD_SIG
103ret 18
104end
105ret 0
106end
107
108fn t_test_corpus_all_29 to int
109base = new uchar 600 0
110if ne at_corpus_build_baseline base AT_OK
111ret 20
112end
113bn = get at_corpus_len 0
114if ne at_verify_artifact part base 0 bn true AT_OK
115ret 21
116end
117c1 = new uchar 600 0
118c2 = new uchar 600 0
119for i ulong AT_CORPUS_COUNT
120cid = add i 1
121if ne at_corpus_build_case cid c1 AT_OK
122ret 22
123end
124n1 = get at_corpus_len 0
125if ne at_corpus_build_case cid c2 AT_OK
126ret 23
127end
128n2 = get at_corpus_len 0
129if ne n1 n2
130ret 24
131end
132if not at_bytes_eq part c1 0 n1 part c2 0 n2
133ret 25
134end
135note Every corpus case must differ from baseline
136if at_bytes_eq part c1 0 n1 part base 0 bn
137ret 26
138end
139if ne at_corpus_expect cid AT_OK
140ret 27
141end
142ek = get at_corpus_exp 0
143ecode = int get at_corpus_exp 1
144vrc = at_verify_artifact part c1 0 n1 true
145if eq ek AT_EXP_REJ_VERIFIED
146if ne vrc ecode
147ret add 30 int cid
148end
149else
150if ne vrc AT_OK
151ret add 60 int cid
152end
153end
154end
155note Invalid case IDs rejected
156if ne at_corpus_build_case 0 c1 AT_ERR_BAD_CASE
157ret 28
158end
159if ne at_corpus_build_case 30 c1 AT_ERR_BAD_CASE
160ret 29
161end
162ret 0
163end
164
165fn t_stage_binding_rcp art view uchar * admitted bool to int
166ver_id = new uchar 32 7
167nonce = new uchar 16 0
168tmp = new uchar 32 0
169pol = new uchar 32 1
170gr = new uchar 32 2
171if ne at_parse_and_identify art AT_OK
172ret 90
173end
174at_rcp_reset
175put at_rcp_f 0 0
176if admitted
177put at_rcp_f 1 AT_DEC_ADMITTED
178put at_rcp_f 5 AT_EXEC_EXITED
179put at_rcp_f 8 0
180put at_rcp_f 9 0
181else
182put at_rcp_f 1 AT_DEC_REJECTED
183put at_rcp_f 5 AT_EXEC_NOT_RUN
184put at_rcp_f 8 3
185put at_rcp_f 9 17
186end
187put at_rcp_f 2 AT_TIER_QEMU
188put at_rcp_f 3 1
189put at_rcp_f 7 AT_RCP_RES_RECLAIMED
190at_rcp_nonce ver_id 1 nonce
191for i ulong 16
192put at_rcp_nonce_buf i get nonce i
193end
194for i ulong 32
195put tmp i get at_art_id i
196end
197at_rcp_set_digest 0 tmp
198for i ulong 32
199put tmp i get at_art_payload_sha i
200end
201at_rcp_set_digest 1 tmp
202for i ulong 32
203put tmp i get at_art_signer_fp i
204end
205at_rcp_set_digest 2 tmp
206at_rcp_set_digest 3 pol
207for i ulong 32
208put tmp i get at_art_req_caps_sha i
209end
210at_rcp_set_digest 4 tmp
211if admitted
212at_rcp_set_digest 5 gr
213end
214for i ulong 32
215put tmp i get at_art_res_env_sha i
216end
217at_rcp_set_digest 6 tmp
218at_rcp_set_digest 7 ver_id
219ret 0
220end
221
222fn t_test_receipt_check to int
223art = new uchar 600 0
224if ne at_corpus_build_baseline art AT_OK
225ret 91
226end
227an = get at_corpus_len 0
228note 1. Valid admitted receipt binds supplied artifact
229if ne t_stage_binding_rcp part art 0 an true 0
230ret 92
231end
232rec = new uchar 512 0
233if ne at_rcp_encode rec AT_OK
234ret 93
235end
236if ne at_rcp_check rec part art 0 an AT_OK
237ret 94
238end
239note 2. Valid rejected receipt with zero signer_fp is allowed
240if ne t_stage_binding_rcp part art 0 an false 0
241ret 95
242end
243z32 = new uchar 32 0
244at_rcp_set_digest 2 z32
245if ne at_rcp_encode rec AT_OK
246ret 96
247end
248if ne at_rcp_check rec part art 0 an AT_OK
249ret 97
250end
251note 3. Wrong artifact_id rejected
252if ne t_stage_binding_rcp part art 0 an true 0
253ret 98
254end
255bad9 = new uchar 32 9
256at_rcp_set_digest 0 bad9
257if ne at_rcp_encode rec AT_OK
258ret 99
259end
260if ne at_rcp_check rec part art 0 an AT_ERR_RCP_BIND_MISMATCH
261ret 100
262end
263note 4. Zero payload_digest in admitted receipt rejected
264if ne t_stage_binding_rcp part art 0 an true 0
265ret 101
266end
267at_rcp_set_digest 1 z32
268if ne at_rcp_encode rec AT_OK
269ret 102
270end
271if ne at_rcp_check rec part art 0 an AT_ERR_RCP_BIND_MISMATCH
272ret 103
273end
274note 5. Admitted receipt without granted_capability_digest rejected
275if ne t_stage_binding_rcp part art 0 an true 0
276ret 104
277end
278at_rcp_set_digest 5 z32
279if ne at_rcp_encode rec AT_OK
280ret 105
281end
282if ne at_rcp_check rec part art 0 an AT_ERR_RCP_NO_GRANTS
283ret 106
284end
285note 6. Signed receipt rejected by kernel-emitted check
286if ne t_stage_binding_rcp part art 0 an true 0
287ret 107
288end
289if ne at_rcp_encode rec AT_OK
290ret 108
291end
292put rec 400 1
293if ne at_rcp_check rec part art 0 an AT_ERR_RCP_MUST_UNSIGNED
294ret 109
295end
296note 7. Mutated artifact fails binding check
297put rec 400 0
298last_p = sub an 101
299put art last_p xor get art last_p 1
300if ne at_rcp_check rec part art 0 an AT_ERR_RCP_BIND_MISMATCH
301ret 110
302end
303note 8. Unparseable artifact: admitted rejected, rejected with zero fields accepted
304put art 0 88
305if ne at_rcp_check rec part art 0 an AT_ERR_RCP_ADMIT_BAD_ART
306ret 111
307end
308at_rcp_reset
309put at_rcp_f 1 AT_DEC_REJECTED
310put at_rcp_f 2 AT_TIER_QEMU
311put at_rcp_f 3 2
312put at_rcp_f 5 AT_EXEC_NOT_RUN
313put at_rcp_f 8 1
314put at_rcp_f 9 1
315ver_id = new uchar 32 7
316nonce = new uchar 16 0
317at_rcp_nonce ver_id 2 nonce
318for i ulong 16
319put at_rcp_nonce_buf i get nonce i
320end
321at_rcp_set_digest 7 ver_id
322if ne at_rcp_encode rec AT_OK
323ret 112
324end
325if ne at_rcp_check rec part art 0 an AT_OK
326ret 113
327end
328ret 0
329end
330
331fn t_test_receipt_sign_verify_hex to int
332art = new uchar 600 0
333if ne at_corpus_build_baseline art AT_OK
334ret 120
335end
336an = get at_corpus_len 0
337if ne t_stage_binding_rcp part art 0 an true 0
338ret 121
339end
340rec = new uchar 512 0
341if ne at_rcp_encode rec AT_OK
342ret 122
343end
344note Inspect unsigned receipt
345if ne at_rcp_inspect rec AT_OK
346ret 123
347end
348if ne get at_rcp_signed_flag 0 0
349ret 124
350end
351note Unsigned receipt fails verify with BadSignatureFormat (15)
352if ne at_rcp_verify rec true AT_ERR_BAD_SIG_FMT
353ret 125
354end
355note Production sign-test fails closed
356if ne at_rcp_sign_test rec false AT_ERR_PROD_SIGN_OFF
357ret 126
358end
359note Test sign-test succeeds and verifies in test mode, fails closed in prod mode
360if ne at_rcp_sign_test rec true AT_OK
361ret 127
362end
363if ne at_rcp_inspect rec AT_OK
364ret 128
365end
366if ne get at_rcp_signed_flag 0 1
367ret 129
368end
369if ne at_rcp_verify rec true AT_OK
370ret 130
371end
372if ne at_rcp_verify rec false AT_ERR_UNTRUSTED
373ret 131
374end
375note Re-signing an already-signed receipt fails with BadSignatureFormat (15)
376if ne at_rcp_sign_test rec true AT_ERR_BAD_SIG_FMT
377ret 132
378end
379note Roundtrip through from-hex with leading/trailing whitespace
380hex_full = new uchar 1031 0
381for i ulong 4
382put hex_full i get t_ws_pre i
383end
384if ne at_hex_encode rec part hex_full 4 1024 AT_OK
385ret 133
386end
387put hex_full 1028 13
388put hex_full 1029 10
389put hex_full 1030 32
390dec_rec = new uchar 512 0
391if ne at_rcp_from_hex hex_full dec_rec AT_OK
392ret 134
393end
394if not at_bytes_eq rec dec_rec
395ret 135
396end
397note Uppercase hex rejected by from-hex
398put hex_full 4 65
399if ne at_rcp_from_hex hex_full dec_rec AT_ERR_BAD_HEX
400ret 136
401end
402note Wrong length hex rejected
403if ne at_rcp_from_hex part hex_full 4 100 dec_rec AT_ERR_BAD_HEX
404ret 137
405end
406note Tampered receipt signature rejected with BadSignature (18)
407put rec 440 xor get rec 440 1
408if ne at_rcp_verify rec true AT_ERR_BAD_SIG
409ret 138
410end
411ret 0
412end
413
414fn t_test_cli_dispatch to int
415if ne at_cli_dispatch 6 at_kw_pack t_arg_x false AT_CMD_PACK
416ret 140
417end
418if ne at_cli_dispatch 5 at_kw_pack t_arg_x false AT_CMD_INVALID
419ret 141
420end
421if ne at_cli_dispatch 3 at_kw_inspect t_arg_x false AT_CMD_INSPECT
422ret 142
423end
424if ne at_cli_dispatch 3 at_kw_id t_arg_x false AT_CMD_ID
425ret 143
426end
427if ne at_cli_dispatch 4 at_kw_sign t_arg_x false AT_CMD_SIGN
428ret 144
429end
430if ne at_cli_dispatch 3 at_kw_verify t_arg_x false AT_CMD_VERIFY
431ret 145
432end
433if ne at_cli_dispatch 3 at_kw_neg_corpus t_arg_x false AT_CMD_INVALID
434ret 146
435end
436if ne at_cli_dispatch 3 at_kw_neg_corpus t_arg_x true AT_CMD_NEG_CORPUS
437ret 147
438end
439if ne at_cli_dispatch 4 at_kw_receipt at_kw_inspect false AT_CMD_RCP_INSPECT
440ret 148
441end
442if ne at_cli_dispatch 5 at_kw_receipt at_kw_check false AT_CMD_RCP_CHECK
443ret 149
444end
445if ne at_cli_dispatch 5 at_kw_receipt at_kw_from_hex false AT_CMD_RCP_FROM_HEX
446ret 150
447end
448if ne at_cli_dispatch 5 at_kw_receipt at_kw_sign_test false AT_CMD_RCP_SIGN_TEST
449ret 151
450end
451if ne at_cli_dispatch 4 at_kw_receipt at_kw_verify false AT_CMD_RCP_VERIFY
452ret 152
453end
454if ne at_cli_dispatch 3 at_kw_receipt at_kw_verify false AT_CMD_INVALID
455ret 153
456end
457if ne at_cli_dispatch 3 t_bad_cmd t_arg_x true AT_CMD_INVALID
458ret 154
459end
460ret 0
461end
462
463fn main to int
464rc = t_test_pack_and_golden_id
465if ne rc 0
466ret rc
467end
468rc = t_test_sign_and_verify
469if ne rc 0
470ret rc
471end
472rc = t_test_corpus_all_29
473if ne rc 0
474ret rc
475end
476rc = t_test_receipt_check
477if ne rc 0
478ret rc
479end
480rc = t_test_receipt_sign_verify_hex
481if ne rc 0
482ret rc
483end
484rc = t_test_cli_dispatch
485if ne rc 0
486ret rc
487end
488ret 0
489end