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