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