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_hs.om

142 lines · 3416 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note fz_hs.om: fuzz target for each TLS 1.3 handshake-message parser of om/tls/tls.om, called directly
3note with the message already reassembled at c[TLHB], as tls_hsmsg leaves it (a whole message of
4note 4 + length bytes, possibly followed by more bytes). Input: S rest, S mod 8 selects:
5note 0 ServerHello tls_shhead, then tls_shext, then tls_ecdh (X25519 on the server share)
6note 1 EncryptedExtensions tls_ee
7note 2 CertificateRequest tls_cr
8note 3 Certificate tls_cert (x509_chain_verify against the store named by argument 1)
9note 4 CertificateVerify rest = L1 L0 leaf-entry[L] message: the entry (3-byte length, DER, 2 bytes)
10note is put at c[TLLF] as tls_leaf would, then tls_cv
11note 5 server Finished tls_sfin under a fixed server handshake secret
12note 6 KeyUpdate tls_kupd under fixed traffic secrets (an update_requested answer is sent)
13note 7 post-handshake rest is a decrypted record body; tls_post (NewSessionTicket, KeyUpdate,
14note messages split across or coalesced in records)
15note A message whose header length runs past the input is skipped: tls_hsmsg never hands one over.
16note Arguments: 1 = PEM trust store (om/tls/test/x509/vectors/pki/storeAll.pem).
17
18fn fz_hsput c edit uchar * m view uchar * to ulong
19n = len m
20if lt n 4
21ret 1
22end
23ml = add or shl ulong get m 1 16 or shl ulong get m 2 8 ulong get m 3 4
24if gt ml n
25ret 1
26end
27for i ulong n
28put c add TLHB i get m i
29end
30tls_pn c TLHF n 4
31ret 0
32end
33
34note fz_hspost: m is the body of one decrypted handshake record, into c[TLRB] for tls_post
35fn fz_hspost c edit uchar * m view uchar * to ulong
36n = len m
37if gt n 16640
38n = 16640
39end
40if eq n 0
41ret 0
42end
43for i ulong n
44put c add add TLRB 5 i get m i
45end
46tls_pn c add TLRB 3 n 2
47ret tls_post c
48end
49
50note fz_hscv: m = L1 L0 leaf-entry[L] CertificateVerify, over a fixed transcript hash
51fn fz_hscv c edit uchar * m view uchar * to ulong
52h = new uchar 32 0
53fz_fill h 0 32 217
54l = fz_be2 m 0
55if gt l sub len m 2
56ret 0
57end
58if gt l TLLFSZ
59ret 0
60end
61for i ulong l
62put c add TLLF i get m add 2 i
63end
64if ne fz_hsput c part m add 2 l sub sub len m 2 l 0
65ret 0
66end
67ret tls_cv c h
68end
69
70note fz_hsrun: x = S rest (the whole input); dispatch on S mod 8
71fn fz_hsrun c edit uchar * st view uchar * x view uchar * to ulong
72h = new uchar 32 0
73fz_fill h 0 32 217
74sel = rem ulong get x 0 8
75if eq sel 7
76ret fz_hspost c part x 1 sub len x 1
77end
78if eq sel 4
79ret fz_hscv c part x 1 sub len x 1
80end
81if ne fz_hsput c part x 1 sub len x 1 0
82ret 0
83end
84if eq sel 0
85r = tls_shhead c
86if eq r 0
87r = tls_shext c
88end
89if eq r 0
90r = tls_ecdh c
91end
92ret r
93end
94if eq sel 1
95ret tls_ee c
96end
97if eq sel 2
98ret tls_cr c
99end
100if eq sel 3
101ret tls_cert c st
102end
103if eq sel 5
104ret tls_sfin c h
105end
106ret tls_kupd c
107end
108
109fn main to int
110c = new uchar TLCSZ 0
111st = new uchar TLSTSZ 0
112fds = new ulong 2 0
113in = new uchar FZCAP 0
114n = fz_read in
115if lt n 1
116ret 0
117end
118s = fz_store st
119if ne tls_init c FZHOST 1 0
120ret 0
121end
122if ne fz_pair fds 0
123ret 0
124end
125tls_pn c TLFD get fds 0 4
126tls_pn c TLDL add ulong monons 2000000000 8
127put c TLPH 1
128put c TLSU 1
129put c TLWK 1
130put c TLRK 1
131fz_fill c TLEPK 32 1
132fz_fill c TLSHS 32 33
133fz_fill c TLSAP 32 65
134fz_fill c TLCAP 32 97
135fz_fill c TLWKEY 32 129
136fz_fill c TLWIV 12 161
137fz_fill c TLRKEY 32 173
138fz_fill c TLRIV 12 205
139r = fz_hsrun c view st part in 0 n
140fz_say r
141ret 0
142end