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

79 lines · 2137 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note fz_x509.om: fuzz target for om/tls/x509.om (DER/ASN.1 certificate parsing, chain building and
3note verification, name/SAN/EKU/name-constraint checks, RSA/ECDSA signature verification).
4note Input: M rest, M mod 4 selects:
5note 0 x509_parse of rest as one DER certificate
6note 1 x509_chain_verify of rest as a TLS certificate_list (entries: 3-byte length, DER, 2-byte
7note extensions length, extensions), now 1792972800, host www.example.test
8note 2 as 1 with rest = T[8] H name[H] list: the verification time and hostname from the input
9note 3 x509_cv_verify: rest = S1 S0 L1 L0 list[L] ms; the leaf of list checks ms = 130-byte signed
10note content || signature (scheme S), as tls_cv passes it (pki/cv.msg is such a content)
11note Arguments: 1 = PEM trust store (om/tls/test/x509/vectors/pki/storeAll.pem).
12
13note fz_xcv: the list is copied out of x (one array may not be passed twice in one call: error 19)
14fn fz_xcv x view uchar * to ulong
15cl = new uchar 65536 0
16sch = fz_be2 x 0
17l = fz_be2 x 2
18if gt add l 134 len x
19ret 0
20end
21for i ulong l
22put cl i get x add 4 i
23end
24ret x509_cv_verify part cl 0 l sch part x add 4 l sub sub len x 4 l 130
25end
26
27fn fz_xhq x view uchar * st view uchar * to ulong
28hq = new uchar 300 0
29if lt len x 9
30ret 0
31end
32for i ulong 8
33put hq i get x i
34end
35h = ulong get x 8
36if gt h sub len x 9
37h = sub len x 9
38end
39if gt h 255
40h = 255
41end
42for i ulong h
43put hq add 8 i get x add 9 i
44end
45ret x509_chain_verify part x add 9 h sub sub len x 9 h st part hq 0 add 8 h
46end
47
48fn fz_xrun x view uchar * st view uchar * to ulong
49r = new ulong X5RSZ 0
50hq = new uchar 32 0
51md = and ulong get x 0 3
52if eq md 0
53ret x509_parse part x 1 sub len x 1 r
54end
55if eq md 3
56ret fz_xcv part x 1 sub len x 1
57end
58if eq md 2
59ret fz_xhq part x 1 sub len x 1 st
60end
61tls_pn hq 0 1792972800 8
62for i ulong len FZHOST
63put hq add 8 i get FZHOST i
64end
65ret x509_chain_verify part x 1 sub len x 1 st part hq 0 add 8 len FZHOST
66end
67
68fn main to int
69st = new uchar TLSTSZ 0
70in = new uchar FZCAP 0
71n = fz_read in
72if lt n 1
73ret 0
74end
75s = fz_store st
76r = fz_xrun part in 0 n view st
77fz_say r
78ret 0
79end