interplane.Get Omega
Read in your language

omtls

omtls: a TLS 1.3 client (RFC 8446) written fresh in seeded Omega, for mailhand. Not audited by a cryptographer. Free (Apache-2.0).

Brought by drakestapleton

branch main Branches Tags History

omtls / tests / tlshook.om

147 lines · 3347 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note tests/tlshook.om: the TEST build's side of the TLS hooks (product builds link src/tlsprod.om instead).
3note A test driver may fix the ClientHello body and the X25519 private key (RFC 8448 replay), fix the clock, pin the
4note expected leaf certificate instead of validating a chain (the RFC 8448 server certificate has no SAN and expired in
5note 2026), and record the four traffic secrets (ot_th_sec, slot 64 * which) and, when asked, print them to stderr as
6note "LABEL secret-hex" lines. With nothing set, the hooks behave exactly as the product's.
7global ot_th_v ulong 16
8global ot_th_ch uchar 2048
9global ot_th_priv uchar 32
10global ot_th_leaf uchar 65536
11global ot_th_rnd uchar 4096
12global ot_th_sec uchar 512
13text ot_th_l1 "CLIENT_HANDSHAKE_TRAFFIC_SECRET "
14text ot_th_l2 "SERVER_HANDSHAKE_TRAFFIC_SECRET "
15text ot_th_l3 "CLIENT_TRAFFIC_SECRET_0 "
16text ot_th_l4 "SERVER_TRAFFIC_SECRET_0 "
17text ot_th_nl "\n"
18text ot_th_hex "0123456789abcdef"
19note ot_th_v: 0 CH length (0 none), 1 now override (0 none), 2 leaf length (0 none), 3 keylog on, 4 fixed random
20note length (0 none), 5 fixed random read position
21fn ot_th_setch b view uchar * priv view uchar 32 to void
22for i ulong len b
23put ot_th_ch i get b i
24end
25for i ulong 32
26put ot_th_priv i get priv i
27end
28put ot_th_v 0 len b
29end
30fn ot_th_setnow t ulong to void
31put ot_th_v 1 t
32end
33fn ot_th_pin d view uchar * to void
34for i ulong len d
35put ot_th_leaf i get d i
36end
37put ot_th_v 2 len d
38end
39fn ot_th_keylog on bool to void
40put ot_th_v 3 0
41if on
42put ot_th_v 3 1
43end
44end
45fn ot_th_fixrandom b view uchar * to void
46for i ulong len b
47put ot_th_rnd i get b i
48end
49put ot_th_v 4 len b
50put ot_th_v 5 0
51end
52
53fn ot_tl_hk_random b edit uchar * to bool
54n = get ot_th_v 4
55if gt n 0
56p = get ot_th_v 5
57for i ulong len b
58put b i get ot_th_rnd rem add p i n
59end
60put ot_th_v 5 rem add p len b n
61ret true
62end
63m = len b
64q = ulong 0
65while lt q m bound 1000000
66k = random b q sub m q 0
67if eq k -4
68continue
69end
70if le k 0
71ret false
72end
73q = add q ulong k
74end
75ret true
76end
77fn ot_tl_hk_ch ch edit uchar 2048 priv edit uchar 32 to ulong
78n = get ot_th_v 0
79if eq n 0
80ret 0
81end
82for i ulong n
83put ch i get ot_th_ch i
84end
85for i ulong 32
86put priv i get ot_th_priv i
87end
88ret n
89end
90note remember whether the first certificate equals the pinned one
91fn ot_tl_hk_leaf d view uchar * to void
92put ot_th_v 6 0
93n = get ot_th_v 2
94if or eq n 0 ne len d n
95ret
96end
97for i ulong n
98if ne get d i get ot_th_leaf i
99ret
100end
101end
102put ot_th_v 6 1
103end
104note with a pinned leaf: 0 when the first certificate was it, else 14 (untrusted); 255 means validate normally
105fn ot_tl_hk_cert to ulong
106if eq get ot_th_v 2 0
107ret 255
108end
109if eq get ot_th_v 6 1
110ret 0
111end
112ret 14
113end
114fn ot_tl_hk_now to long
115t = get ot_th_v 1
116if gt t 0
117ret long t
118end
119ret div realns 1000000000
120end
121fn ot_tl_klog which ulong s view uchar 64 to void
122for i ulong 64
123put ot_th_sec add mul which 64 i get s i
124end
125if eq get ot_th_v 3 0
126ret
127end
128if eq which 1
129k = write 2 ot_th_l1 0 len ot_th_l1
130end
131if eq which 2
132k = write 2 ot_th_l2 0 len ot_th_l2
133end
134if eq which 3
135k = write 2 ot_th_l3 0 len ot_th_l3
136end
137if eq which 4
138k = write 2 ot_th_l4 0 len ot_th_l4
139end
140h = new uchar 64 0
141for i ulong 32
142put h mul i 2 get ot_th_hex ulong shr get s i 4
143put h add mul i 2 1 get ot_th_hex ulong and get s i 15
144end
145k = write 2 h 0 64
146k = write 2 ot_th_nl 0 1
147end