interplane.Get Omega
Read in your language

omtls

omtls: a TLS 1.3 client (RFC 8446) written fresh in seeded Omega, for mailhand. Not audited by a cryptographer. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

omtls / tests / drv / x509.om

428 lines · 8590 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note tests/drv/x509.om: ot_x5_ and ot_pk_tls cases. Arguments: case files ("--time" first: also print
3note one TIME line per trust-store load and per chain check). Paths are relative to the case file,
4note except those starting "/". Line forms:
5note R <name> <expected ot_x5_roots result> <bundle>
6note C <name> <expected code> <now> <host> <bundle> <leaf.der> [<cert.der> ...]
7note (host "-" is the empty host; the bundle is reloaded only when it differs from the last one)
8note V <name> OK|BAD <scheme (decimal)> <leaf.der> <message file> <signature file>
9note P <name> OK|BAD <cert.der> [<max_ms>] ot_x5_add alone: OK = the certificate parses; with max_ms
10note the ot_x5_add call must also return within that many milliseconds (monotonic clock)
11note Z <name> <now> <host> <bundle> <leaf.der> <issuer.der>: robustness: every strict prefix of the leaf is
12note refused by ot_x5_add, and with each single byte of the leaf inverted ot_x5_add and ot_x5_check
13note return (a trap fails the whole run)
14text ot_x5_ar "x509"
15text ot_x5_wR "R"
16text ot_x5_wC "C"
17text ot_x5_wV "V"
18text ot_x5_wP "P"
19text ot_x5_wZ "Z"
20text ot_x5_mA "a strict prefix was accepted"
21text ot_x5_mB "over its time bound, ms="
22text ot_x5_wK "OK"
23text ot_x5_wX "BAD"
24text ot_x5_wT "--time"
25text ot_x5_m1 "wrong code "
26text ot_x5_m2 "accepted, expected BAD"
27text ot_x5_m3 "refused, expected OK"
28text ot_x5_m4 "malformed case line"
29text ot_x5_m5 "cannot read case file"
30text ot_x5_m6 "cannot read a file it names"
31text ot_x5_m7 "wrong trust-store load result "
32text ot_x5_m8 "trust store did not load: "
33text ot_x5_m9 "leaf SPKI not available"
34text ot_x5_t1 "TIME "
35text ot_x5_t2 " roots_ns="
36text ot_x5_t3 " certs="
37text ot_x5_t4 " check_ns="
38text ot_x5_t5 " not_loaded="
39note ot_x5_zrl: the bundle path loaded last (length in ot_x5_zrs 0), ot_x5_zrs 1 its load result + 8,
40note ot_x5_zrs 2 timing on
41global ot_x5_zrl uchar 4096
42global ot_x5_zrs ulong 3
43
44note ot_x5_zfp: the path of token k into ot_x5_zip; its length (absolute paths are not prefixed)
45fn ot_x5_zfp k ulong to ulong
46o = ot_x5_ztk k
47n = ot_x5_ztl k
48if eq get ot_x5_zib o 47
49if gt n 4000
50ret 0
51end
52for i ulong n bound 16777216
53put ot_x5_zip i get ot_x5_zib add o i
54end
55ret n
56end
57ret ot_x5_zipath k
58end
59
60note ot_x5_zload: the file of token k into b; its length or -1
61fn ot_x5_zload k ulong b edit uchar * to long
62n = ot_x5_zfp k
63if eq n 0
64ret -1
65end
66fd = fopen ot_x5_zip 0 n 0 0
67if lt fd 0
68ret -1
69end
70t = ulong 0
71while true bound 1000000
72r = read int fd b t sub len b t
73if lt r 0
74c = fclose int fd
75ret -1
76end
77if eq r 0
78break
79end
80t = add t ulong r
81if eq t len b
82c = fclose int fd
83ret -1
84end
85end
86c = fclose int fd
87ret long t
88end
89
90note ot_x5_zroots: load the bundle of token k unless it is the one loaded last; the load result
91fn ot_x5_zroots k ulong to long
92p = new uchar 4096 0
93n = ot_x5_zfp k
94if eq n 0
95ret -1
96end
97same = and eq n get ot_x5_zrs 0 gt get ot_x5_zrs 1 0
98if same
99for i ulong n bound 16777216
100if ne get ot_x5_zip i get ot_x5_zrl i
101same = false
102end
103end
104end
105if same
106ret sub long get ot_x5_zrs 1 8
107end
108for i ulong n bound 16777216
109put p i get ot_x5_zip i
110put ot_x5_zrl i get ot_x5_zip i
111end
112t0 = monons
113r = ot_x5_roots part p 0 n
114t1 = monons
115put ot_x5_zrs 0 n
116put ot_x5_zrs 1 ulong add r 8
117if gt get ot_x5_zrs 2 0
118ot_x5_ziw ot_x5_t1
119ot_x5_zitw 1
120ot_x5_ziw ot_x5_t2
121ot_x5_zil sub t1 t0
122ot_x5_ziw ot_x5_t3
123ot_x5_zil r
124ot_x5_ziw ot_x5_t5
125ot_x5_ziu get ot_x5_st 5
126ot_x5_ziw ot_x5_zsN
127end
128ret r
129end
130
131fn ot_x5_zR to void
132e = ot_x5_ztdec 2
133put ot_x5_zrs 0 0
134r = ot_x5_zroots 3
135if ne r e
136ot_x5_ziw ot_x5_zsF
137ot_x5_ziw ot_x5_ar
138ot_x5_ziw ot_x5_zsL
139ot_x5_ziu get ot_x5_zik 70
140ot_x5_ziw ot_x5_zsS
141ot_x5_zitw 1
142ot_x5_ziw ot_x5_zsC
143ot_x5_ziw ot_x5_m7
144ot_x5_zil r
145ot_x5_ziw ot_x5_zsN
146put ot_x5_zik 69 add get ot_x5_zik 69 1
147ret
148end
149ot_x5_zipass
150end
151
152note ot_x5_zcode: report a C case whose result r is not the expected one
153fn ot_x5_zcode r long to void
154put ot_x5_zik 69 add get ot_x5_zik 69 1
155ot_x5_ziw ot_x5_zsF
156ot_x5_ziw ot_x5_ar
157ot_x5_ziw ot_x5_zsL
158ot_x5_ziu get ot_x5_zik 70
159ot_x5_ziw ot_x5_zsS
160ot_x5_zitw 1
161ot_x5_ziw ot_x5_zsC
162ot_x5_ziw ot_x5_m1
163ot_x5_zil r
164ot_x5_ziw ot_x5_zsN
165end
166
167fn ot_x5_zC b edit uchar * to void
168if lt ot_x5_ztn 6
169ot_x5_zifail ot_x5_ar ot_x5_m4
170ret
171end
172x = ot_x5_ztdec 2
173now = ot_x5_ztdec 3
174r = ot_x5_zroots 5
175if lt r 0
176ot_x5_zifail ot_x5_ar ot_x5_m8
177ret
178end
179ot_x5_reset
180for k ulong sub ot_x5_ztn 6 bound 16777216
181n = ot_x5_zload add k 6 b
182if lt n 0
183ot_x5_zifail ot_x5_ar ot_x5_m6
184ret
185end
186a = ot_x5_add part b 0 ulong n
187end
188ot_x5_zhost b
189hl = ot_x5_ztl 4
190if ot_x5_zteq 4 ot_x5_zsm
191hl = 0
192end
193t0 = monons
194c = ot_x5_check part b 0 hl now
195t1 = monons
196if gt get ot_x5_zrs 2 0
197ot_x5_ziw ot_x5_t1
198ot_x5_zitw 1
199ot_x5_ziw ot_x5_t4
200ot_x5_zil sub t1 t0
201ot_x5_ziw ot_x5_zsN
202end
203if ne long c x
204ot_x5_zcode long c
205ret
206end
207ot_x5_zipass
208end
209
210note ot_x5_zhost: the host token into b[0 ..)
211fn ot_x5_zhost b edit uchar * to void
212o = ot_x5_ztk 4
213for i ulong ot_x5_ztl 4 bound 16777216
214put b i get ot_x5_zib add o i
215end
216end
217
218note ot_x5_zkey: the leaf file of token 4, loaded into b, through ot_x5_add, ot_x5_leafspki and ot_pk_tlskey
219fn ot_x5_zkey b edit uchar * to bool
220k = new uchar 65536 0
221n = ot_x5_zload 4 b
222if lt n 0
223ret false
224end
225ot_x5_reset
226a = ot_x5_add part b 0 ulong n
227kl = ot_x5_leafspki k
228if lt kl 0
229ret false
230end
231ret ot_pk_tlskey part k 0 ulong kl
232end
233
234note ot_x5_zcv: ot_pk_tls with the scheme of token 3
235fn ot_x5_zcv m view uchar * s view uchar * to bool
236ret ot_pk_tls ulong ot_x5_ztdec 3 m s
237end
238
239fn ot_x5_zV b edit uchar * to void
240m = new uchar 65536 0
241s = new uchar 8192 0
242if ne ot_x5_ztn 7
243ot_x5_zifail ot_x5_ar ot_x5_m4
244ret
245end
246ml = ot_x5_zload 5 m
247sl = ot_x5_zload 6 s
248if or lt ml 0 lt sl 0
249ot_x5_zifail ot_x5_ar ot_x5_m6
250ret
251end
252r = false
253if ot_x5_zkey b
254ml2 = ulong ml
255sl2 = ulong sl
256r = ot_x5_zcv part m 0 ml2 part s 0 sl2
257end
258if ot_x5_zteq 2 ot_x5_wK
259if eq r false
260ot_x5_zifail ot_x5_ar ot_x5_m3
261ret
262end
263else
264if r
265ot_x5_zifail ot_x5_ar ot_x5_m2
266ret
267end
268end
269ot_x5_zipass
270end
271
272fn ot_x5_zP b edit uchar * to void
273if or lt ot_x5_ztn 4 gt ot_x5_ztn 5
274ot_x5_zifail ot_x5_ar ot_x5_m4
275ret
276end
277n = ot_x5_zload 3 b
278if lt n 0
279ot_x5_zifail ot_x5_ar ot_x5_m6
280ret
281end
282ot_x5_reset
283t0 = monons
284r = gt ot_x5_add part b 0 ulong n 0
285ms = div sub monons t0 1000000
286if eq ot_x5_ztn 5
287if gt ms ot_x5_ztdec 4
288ot_x5_ztime ms
289ret
290end
291end
292if ot_x5_zteq 2 ot_x5_wK
293if eq r false
294ot_x5_zifail ot_x5_ar ot_x5_m3
295ret
296end
297else
298if r
299ot_x5_zifail ot_x5_ar ot_x5_m2
300ret
301end
302end
303ot_x5_zipass
304end
305
306note ot_x5_ztime: report a P case over its time bound
307fn ot_x5_ztime ms long to void
308put ot_x5_zik 69 add get ot_x5_zik 69 1
309ot_x5_ziw ot_x5_zsF
310ot_x5_ziw ot_x5_ar
311ot_x5_ziw ot_x5_zsL
312ot_x5_ziu get ot_x5_zik 70
313ot_x5_ziw ot_x5_zsS
314ot_x5_zitw 1
315ot_x5_ziw ot_x5_zsC
316ot_x5_ziw ot_x5_mB
317ot_x5_zil ms
318ot_x5_ziw ot_x5_zsN
319end
320
321note ot_x5_zflip: the leaf in b[0 .. n) with byte k inverted, then the issuer file, then a check
322fn ot_x5_zflip b edit uchar * n ulong k ulong h view uchar * to void
323q = new uchar 65536 0
324m = ot_x5_zload 6 q
325put b k xor get b k 255
326ot_x5_reset
327a = ot_x5_add part b 0 n
328if ge m 0
329a = ot_x5_add part q 0 ulong m
330end
331c = ot_x5_check h ot_x5_ztdec 2
332put b k xor get b k 255
333end
334
335fn ot_x5_zZ b edit uchar * to void
336h = new uchar 256 0
337if ne ot_x5_ztn 7
338ot_x5_zifail ot_x5_ar ot_x5_m4
339ret
340end
341if lt ot_x5_zroots 4 0
342ot_x5_zifail ot_x5_ar ot_x5_m8
343ret
344end
345n = ot_x5_zload 5 b
346if lt n 0
347ot_x5_zifail ot_x5_ar ot_x5_m6
348ret
349end
350hl = ot_x5_ztl 3
351if gt hl 256
352ot_x5_zifail ot_x5_ar ot_x5_m4
353ret
354end
355o = ot_x5_ztk 3
356for i ulong hl bound 256
357put h i get ot_x5_zib add o i
358end
359for k ulong ulong n bound 16777216
360ot_x5_reset
361if gt ot_x5_add part b 0 k 0
362ot_x5_zifail ot_x5_ar ot_x5_mA
363ret
364end
365end
366for k ulong ulong n bound 16777216
367ot_x5_zflip b ulong n k part h 0 hl
368end
369ot_x5_zipass
370end
371
372fn ot_x5_zline b edit uchar * to void
373if ot_x5_zteq 0 ot_x5_wZ
374ot_x5_zZ b
375ret
376end
377if ot_x5_zteq 0 ot_x5_wP
378ot_x5_zP b
379ret
380end
381if ot_x5_zteq 0 ot_x5_wC
382ot_x5_zC b
383ret
384end
385if ot_x5_zteq 0 ot_x5_wR
386ot_x5_zR
387ret
388end
389if ot_x5_zteq 0 ot_x5_wV
390ot_x5_zV b
391ret
392end
393ot_x5_zifail ot_x5_ar ot_x5_m4
394end
395
396fn main to int
397b = new uchar 2097152 0
398a = ulong 1
399while lt long a argcnt bound 64
400k = argread a ot_x5_zip 0 4000
401if and eq k 6 eq a 1
402if ot_x5_zargt
403put ot_x5_zrs 2 1
404a = add a 1
405continue
406end
407end
408if eq ot_x5_ziread a false
409ot_x5_zifail ot_x5_ar ot_x5_m5
410else
411while ot_x5_ziline bound 1000000
412ot_x5_zline b
413end
414end
415a = add a 1
416end
417ret ot_x5_ziend ot_x5_ar
418end
419
420note ot_x5_zargt: ot_x5_zip holds "--time"
421fn ot_x5_zargt to bool
422for i ulong 6
423if ne get ot_x5_zip i get ot_x5_wT i
424ret false
425end
426end
427ret true
428end