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
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note tests/drv/der.om: ot_der_ and ot_b64_ cases. Arguments: vector files. Line forms (hex "-" = empty): |
| 3 | note R <name> OK <tag> <value-length> <hex> | R <name> BAD <hex> ot_der_rd over exactly the bytes; |
| 4 | note OK also needs the TLV to end at the last byte |
| 5 | note I|B|O|S <name> OK|BAD <hex of contents> ot_der_okint / okbool / okoid / okbits |
| 6 | note 6 <name> <hex of the decoded bytes>|BAD <base64 text> ot_b64_dec |
| 7 | text ot_x5_zar "der" |
| 8 | text ot_x5_zwR "R" |
| 9 | text ot_x5_zwI "I" |
| 10 | text ot_x5_zwB "B" |
| 11 | text ot_x5_zwO "O" |
| 12 | text ot_x5_zwS "S" |
| 13 | text ot_x5_zw6 "6" |
| 14 | text ot_x5_zwK "OK" |
| 15 | text ot_x5_zwX "BAD" |
| 16 | text ot_x5_zm1 "wrong tag or length" |
| 17 | text ot_x5_zm2 "accepted, expected BAD" |
| 18 | text ot_x5_zm3 "refused, expected OK" |
| 19 | text ot_x5_zm4 "malformed vector line" |
| 20 | text ot_x5_zm5 "cannot read vector file" |
| 21 | text ot_x5_zm6 "wrong decoded bytes" |
| 22 | |
| 23 | note ot_x5_zdres: compare a result with the OK/BAD token 2 |
| 24 | fn ot_x5_zdres r bool to void |
| 25 | if ot_x5_zteq 2 ot_x5_zwK |
| 26 | if r |
| 27 | ot_x5_zipass |
| 28 | else |
| 29 | ot_x5_zifail ot_x5_zar ot_x5_zm3 |
| 30 | end |
| 31 | ret |
| 32 | end |
| 33 | if ot_x5_zteq 2 ot_x5_zwX |
| 34 | if r |
| 35 | ot_x5_zifail ot_x5_zar ot_x5_zm2 |
| 36 | else |
| 37 | ot_x5_zipass |
| 38 | end |
| 39 | ret |
| 40 | end |
| 41 | ot_x5_zifail ot_x5_zar ot_x5_zm4 |
| 42 | end |
| 43 | |
| 44 | fn ot_x5_zdR to void |
| 45 | if ot_x5_zteq 2 ot_x5_zwX |
| 46 | n = ot_x5_zthex 3 0 |
| 47 | if lt n 0 |
| 48 | ot_x5_zifail ot_x5_zar ot_x5_zm4 |
| 49 | ret |
| 50 | end |
| 51 | ot_x5_zdres ot_der_rd 0 ulong n |
| 52 | ret |
| 53 | end |
| 54 | m = ot_x5_zthex 5 0 |
| 55 | if lt m 0 |
| 56 | ot_x5_zifail ot_x5_zar ot_x5_zm4 |
| 57 | ret |
| 58 | end |
| 59 | if eq ot_der_rd 0 ulong m false |
| 60 | ot_x5_zifail ot_x5_zar ot_x5_zm3 |
| 61 | ret |
| 62 | end |
| 63 | t = ot_x5_ztdec 3 |
| 64 | l = ot_x5_ztdec 4 |
| 65 | if or ne ot_der_tg ulong t ne ot_der_vl ulong l |
| 66 | ot_x5_zifail ot_x5_zar ot_x5_zm1 |
| 67 | ret |
| 68 | end |
| 69 | if ne ot_der_nd ulong m |
| 70 | ot_x5_zifail ot_x5_zar ot_x5_zm1 |
| 71 | ret |
| 72 | end |
| 73 | ot_x5_zipass |
| 74 | end |
| 75 | |
| 76 | note ot_x5_zdC: content checks; k 1 INTEGER, 2 BOOLEAN, 3 OID, 4 BIT STRING |
| 77 | fn ot_x5_zdC k ulong to void |
| 78 | n = ot_x5_zthex 3 0 |
| 79 | if lt n 0 |
| 80 | ot_x5_zifail ot_x5_zar ot_x5_zm4 |
| 81 | ret |
| 82 | end |
| 83 | u = ulong n |
| 84 | r = false |
| 85 | if eq k 1 |
| 86 | r = ot_der_okint 0 u |
| 87 | end |
| 88 | if eq k 2 |
| 89 | r = ot_der_okbool 0 u |
| 90 | end |
| 91 | if eq k 3 |
| 92 | r = ot_der_okoid 0 u |
| 93 | end |
| 94 | if eq k 4 |
| 95 | r = ot_der_okbits 0 u |
| 96 | end |
| 97 | ot_x5_zdres r |
| 98 | end |
| 99 | |
| 100 | note ot_x5_zd6: the base64 token is copied to store offset 65536 and decoded to offset 0; the expected |
| 101 | note bytes are put at offset 1048576 |
| 102 | fn ot_x5_zd6 to void |
| 103 | if ne ot_x5_ztn 4 |
| 104 | ot_x5_zifail ot_x5_zar ot_x5_zm4 |
| 105 | ret |
| 106 | end |
| 107 | o = ot_x5_ztk 3 |
| 108 | n = ot_x5_ztl 3 |
| 109 | for i ulong n bound 16777216 |
| 110 | put ot_der_m add 65536 i get ot_x5_zib add o i |
| 111 | end |
| 112 | r = ot_b64_dec 65536 add 65536 n 0 |
| 113 | if ot_x5_zteq 2 ot_x5_zwX |
| 114 | if lt r 0 |
| 115 | ot_x5_zipass |
| 116 | else |
| 117 | ot_x5_zifail ot_x5_zar ot_x5_zm2 |
| 118 | end |
| 119 | ret |
| 120 | end |
| 121 | x = ot_x5_zthex 2 1048576 |
| 122 | if lt x 0 |
| 123 | ot_x5_zifail ot_x5_zar ot_x5_zm4 |
| 124 | ret |
| 125 | end |
| 126 | if lt r 0 |
| 127 | ot_x5_zifail ot_x5_zar ot_x5_zm3 |
| 128 | ret |
| 129 | end |
| 130 | if or ne r x eq ot_der_eq 0 1048576 ulong x false |
| 131 | ot_x5_zifail ot_x5_zar ot_x5_zm6 |
| 132 | ret |
| 133 | end |
| 134 | ot_x5_zipass |
| 135 | end |
| 136 | |
| 137 | fn ot_x5_zdline to void |
| 138 | if ot_x5_zteq 0 ot_x5_zwR |
| 139 | ot_x5_zdR |
| 140 | ret |
| 141 | end |
| 142 | if ot_x5_zteq 0 ot_x5_zwI |
| 143 | ot_x5_zdC 1 |
| 144 | ret |
| 145 | end |
| 146 | if ot_x5_zteq 0 ot_x5_zwB |
| 147 | ot_x5_zdC 2 |
| 148 | ret |
| 149 | end |
| 150 | if ot_x5_zteq 0 ot_x5_zwO |
| 151 | ot_x5_zdC 3 |
| 152 | ret |
| 153 | end |
| 154 | if ot_x5_zteq 0 ot_x5_zwS |
| 155 | ot_x5_zdC 4 |
| 156 | ret |
| 157 | end |
| 158 | if ot_x5_zteq 0 ot_x5_zw6 |
| 159 | ot_x5_zd6 |
| 160 | ret |
| 161 | end |
| 162 | ot_x5_zifail ot_x5_zar ot_x5_zm4 |
| 163 | end |
| 164 | |
| 165 | fn main to int |
| 166 | a = ulong 1 |
| 167 | while lt long a argcnt bound 64 |
| 168 | if eq ot_x5_ziread a false |
| 169 | ot_x5_zifail ot_x5_zar ot_x5_zm5 |
| 170 | else |
| 171 | while ot_x5_ziline bound 1000000 |
| 172 | ot_x5_zdline |
| 173 | end |
| 174 | end |
| 175 | a = add a 1 |
| 176 | end |
| 177 | ret ot_x5_ziend ot_x5_zar |
| 178 | end |