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 / om / tls / test / fuzz / fz_flight.om

211 lines · 5579 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note fz_flight.om: fuzz target for the client's whole server-flight path in om/tls/tls.om: the record
3note layer (tls_rdrec: framing, CCS, AEAD open, inner type and padding), handshake reassembly
4note (tls_hsmsg), ServerHello (tls_rdsh) and the encrypted flight (tls_rdenc: EncryptedExtensions,
5note CertificateRequest, Certificate + chain verification, CertificateVerify, Finished), exactly as
6note tls_connect runs them after a real ClientHello (tls_mkch).
7note Input: R1 R0 raw[R] chunks. raw is what the server sends before its keys exist (plaintext
8note ServerHello, CCS, alerts, any forged records). The chunks (common.om fz_feed) follow, sealed
9note under the server handshake key that the input's ServerHello gives this ClientHello.
10note To seal the chunks before the client reads anything, a byte copy m of the client state (same
11note ClientHello, same transcript) first reads raw from its own socket pair, which is shut so it sees
12note the end instead of waiting; when its tls_rdsh succeeds, its read key becomes the sealing key.
13note All the client's input is then in its socket and the write side is shut: no read can block.
14note Arguments: 1 = PEM trust store (om/tls/test/x509/vectors/pki/storeAll.pem).
15
16note fz_fdset: connection fd and a 2 s deadline into a state (no wait can reach it: see above)
17fn fz_fdset c edit uchar * fd ulong to void
18tls_pn c TLFD fd 4
19tls_pn c TLDL add ulong monons 2000000000 8
20end
21
22note fz_mirror: m (after its tls_rdsh) turns into the server's sealing side, writing to fd
23fn fz_mirror m edit uchar * fd ulong to void
24for i ulong 32
25put m add TLWKEY i get m add TLRKEY i
26end
27for i ulong 12
28put m add TLWIV i get m add TLRIV i
29end
30tls_pn m TLWS 0 8
31put m TLWK 1
32tls_pn m TLFD fd 4
33end
34
35note fz_pre: m reads raw from pair a (shut at once); on success, m seals the chunks into the client's
36note pair b. Returns the client's end of b plus 1, or 0 when no socket pair could be made.
37fn fz_pre m edit uchar * th edit ulong 40 x view uchar * r ulong to ulong
38a = new ulong 2 0
39b = new ulong 2 0
40if ne fz_pair a 0
41ret 0
42end
43if ne fz_pair b 0
44ret 0
45end
46fz_fdset m get a 0
47s = fz_send int get a 1 x 2 r
48s = fz_send int get b 1 x 2 r
49z = shutdown int get a 1 1
50if eq tls_rdsh m th 0
51fz_mirror m get b 1
52s = fz_feed m x add 2 r
53end
54z = shutdown int get b 1 1
55ret add get b 0 1
56end
57
58note fz_detch: make the ClientHello tls_mkch wrote deterministic, so a seed's CertificateVerify and
59note Finished (which sign or MAC the transcript) stay valid: random = 64..95, legacy_session_id =
60note 96..127, x25519 private key = 1..32 (its public key replaces the old one in key_share, both in
61note the x25519 entry and as the tail of the X25519MLKEM768 entry), and the hybrid's ML-KEM-768 key
62note pair (fz_detkem). Every other ClientHello byte is tls_mkch's own.
63fn fz_detch c edit uchar * to ulong
64k = new uchar 32 0
65o = new uchar 32 0
66fz_fill k 0 32 1
67if ne x25519_base o k 0
68ret 1
69end
70b = add TLWB 5
71n = add tls_gn c add b 1 3 4
72p = fz_find c b n
73if eq p 0
74ret 1
75end
76r = sub add b n add p 32
77q = ulong 0
78if ge r 32
79q = fz_find c add p 32 r
80end
81if and ne get c TLKGEN 0 eq q 0
82ret 1
83end
84if ne fz_detkem c b p 0
85ret 1
86end
87for i ulong 32
88put c add TLEPK i get k i
89put c add TLEPU i get o i
90put c add p i get o i
91if ne q 0
92put c add q i get o i
93end
94end
95fz_fill c add b 6 32 64
96fz_fill c add b 39 32 96
97tls_mov c TLSID add b 39 32
98ret 0
99end
100
101note fz_detkem: while tls_kemset holds an ML-KEM-768 key pair (c[TLKGEN]), the hybrid entry is ek ||
102note x25519 public key, so its ek is the 1184 bytes before p (the first copy of that public key in
103note the ClientHello at c[b..]). The pair is made again from the seed 128..191: dk where tls_kemset
104note keeps it (c[TLKDK], 2400 bytes), the new ek over the old one. 0, or 1 when the bytes before p
105note are not the held ek or the key pair fails.
106fn fz_detkem c edit uchar * b ulong p ulong to ulong
107if eq get c TLKGEN 0
108ret 0
109end
110if lt p add b 1184
111ret 1
112end
113e = sub p 1184
114for i ulong 1184
115if ne get c add e i get c add TLKDK add 1152 i
116ret 1
117end
118end
119s = new uchar 64 0
120fz_fill s 0 64 128
121ek = new uchar 1184 0
122if ne mlkem_keygen_seed s ek part c TLKDK 2400 0
123ret 1
124end
125for i ulong 1184
126put c add e i get ek i
127end
128ret 0
129end
130
131note fz_find: the offset in c[b, b+n) of the 32-byte public key c[TLEPU..]; 0 when absent
132fn fz_find c view uchar * b ulong n ulong to ulong
133for j ulong sub n 31
134d = ulong 0
135for i ulong 32
136d = or d xor ulong get c add add b j i ulong get c add TLEPU i
137end
138if eq d 0
139ret add b j
140end
141end
142ret 0
143end
144
145note fz_dump: with argument 2, the ClientHello message is written to that file (gen_seeds.py reads it)
146fn fz_dump c view uchar * n ulong to void
147p = new uchar 4096 0
148k = fz_arg 2 p
149if eq k 0
150ret
151end
152f = fopen p 0 k 524865 420
153if lt f 0
154ret
155end
156w = write int f c add TLWB 5 n
157x = fclose int f
158end
159
160fn fz_flrun c edit uchar * m edit uchar * x view uchar * to ulong
161th = new ulong 40 0
162t2 = new ulong 40 0
163st = new uchar TLSTSZ 0
164s = fz_store st
165if ne tls_init c FZHOST 1 0
166ret 0
167end
168sha256_init th
169if ne tls_mkch c 0
170ret 0
171end
172if ne fz_detch c 0
173ret 0
174end
175n = add tls_gn c add TLWB 6 3 4
176fz_dump c n
177sha256_update th part c add TLWB 5 n
178for i ulong TLCSZ
179put m i get c i
180end
181for i ulong 40
182put t2 i get th i
183end
184r = fz_be2 x 0
185if gt r sub len x 2
186r = sub len x 2
187end
188f = fz_pre m t2 x r
189if eq f 0
190ret 0
191end
192fz_fdset c sub f 1
193e = tls_rdsh c th
194if eq e 0
195e = tls_rdenc c st th
196end
197ret e
198end
199
200fn main to int
201c = new uchar TLCSZ 0
202m = new uchar TLCSZ 0
203in = new uchar FZCAP 0
204n = fz_read in
205if lt n 2
206ret 0
207end
208r = fz_flrun c m part in 0 n
209fz_say r
210ret 0
211end