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/omtls/blob/main/tests/drv/x509.om # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omtls / tests / drv / x509.om` 428 lines ยท 8590 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note tests/drv/x509.om: ot_x5_ and ot_pk_tls cases. Arguments: case files ("--time" first: also print 3 note one TIME line per trust-store load and per chain check). Paths are relative to the case file, 4 note except those starting "/". Line forms: 5 note R 6 note C [ ...] 7 note (host "-" is the empty host; the bundle is reloaded only when it differs from the last one) 8 note V OK|BAD 9 note P OK|BAD [] ot_x5_add alone: OK = the certificate parses; with max_ms 10 note the ot_x5_add call must also return within that many milliseconds (monotonic clock) 11 note Z : robustness: every strict prefix of the leaf is 12 note refused by ot_x5_add, and with each single byte of the leaf inverted ot_x5_add and ot_x5_check 13 note return (a trap fails the whole run) 14 text ot_x5_ar "x509" 15 text ot_x5_wR "R" 16 text ot_x5_wC "C" 17 text ot_x5_wV "V" 18 text ot_x5_wP "P" 19 text ot_x5_wZ "Z" 20 text ot_x5_mA "a strict prefix was accepted" 21 text ot_x5_mB "over its time bound, ms=" 22 text ot_x5_wK "OK" 23 text ot_x5_wX "BAD" 24 text ot_x5_wT "--time" 25 text ot_x5_m1 "wrong code " 26 text ot_x5_m2 "accepted, expected BAD" 27 text ot_x5_m3 "refused, expected OK" 28 text ot_x5_m4 "malformed case line" 29 text ot_x5_m5 "cannot read case file" 30 text ot_x5_m6 "cannot read a file it names" 31 text ot_x5_m7 "wrong trust-store load result " 32 text ot_x5_m8 "trust store did not load: " 33 text ot_x5_m9 "leaf SPKI not available" 34 text ot_x5_t1 "TIME " 35 text ot_x5_t2 " roots_ns=" 36 text ot_x5_t3 " certs=" 37 text ot_x5_t4 " check_ns=" 38 text ot_x5_t5 " not_loaded=" 39 note ot_x5_zrl: the bundle path loaded last (length in ot_x5_zrs 0), ot_x5_zrs 1 its load result + 8, 40 note ot_x5_zrs 2 timing on 41 global ot_x5_zrl uchar 4096 42 global ot_x5_zrs ulong 3 43 44 note ot_x5_zfp: the path of token k into ot_x5_zip; its length (absolute paths are not prefixed) 45 fn ot_x5_zfp k ulong to ulong 46 o = ot_x5_ztk k 47 n = ot_x5_ztl k 48 if eq get ot_x5_zib o 47 49 if gt n 4000 50 ret 0 51 end 52 for i ulong n bound `16777216` 53 put ot_x5_zip i get ot_x5_zib add o i 54 end 55 ret n 56 end 57 ret ot_x5_zipath k 58 end 59 60 note ot_x5_zload: the file of token k into b; its length or -1 61 fn ot_x5_zload k ulong b edit uchar * to long 62 n = ot_x5_zfp k 63 if eq n 0 64 ret -1 65 end 66 fd = fopen ot_x5_zip 0 n 0 0 67 if lt fd 0 68 ret -1 69 end 70 t = ulong 0 71 while true bound `1000000` 72 r = read int fd b t sub len b t 73 if lt r 0 74 c = fclose int fd 75 ret -1 76 end 77 if eq r 0 78 break 79 end 80 t = add t ulong r 81 if eq t len b 82 c = fclose int fd 83 ret -1 84 end 85 end 86 c = fclose int fd 87 ret long t 88 end 89 90 note ot_x5_zroots: load the bundle of token k unless it is the one loaded last; the load result 91 fn ot_x5_zroots k ulong to long 92 p = new uchar 4096 0 93 n = ot_x5_zfp k 94 if eq n 0 95 ret -1 96 end 97 same = and eq n get ot_x5_zrs 0 gt get ot_x5_zrs 1 0 98 if same 99 for i ulong n bound `16777216` 100 if ne get ot_x5_zip i get ot_x5_zrl i 101 same = false 102 end 103 end 104 end 105 if same 106 ret sub long get ot_x5_zrs 1 8 107 end 108 for i ulong n bound `16777216` 109 put p i get ot_x5_zip i 110 put ot_x5_zrl i get ot_x5_zip i 111 end 112 t0 = monons 113 r = ot_x5_roots part p 0 n 114 t1 = monons 115 put ot_x5_zrs 0 n 116 put ot_x5_zrs 1 ulong add r 8 117 if gt get ot_x5_zrs 2 0 118 ot_x5_ziw ot_x5_t1 119 ot_x5_zitw 1 120 ot_x5_ziw ot_x5_t2 121 ot_x5_zil sub t1 t0 122 ot_x5_ziw ot_x5_t3 123 ot_x5_zil r 124 ot_x5_ziw ot_x5_t5 125 ot_x5_ziu get ot_x5_st 5 126 ot_x5_ziw ot_x5_zsN 127 end 128 ret r 129 end 130 131 fn ot_x5_zR to void 132 e = ot_x5_ztdec 2 133 put ot_x5_zrs 0 0 134 r = ot_x5_zroots 3 135 if ne r e 136 ot_x5_ziw ot_x5_zsF 137 ot_x5_ziw ot_x5_ar 138 ot_x5_ziw ot_x5_zsL 139 ot_x5_ziu get ot_x5_zik 70 140 ot_x5_ziw ot_x5_zsS 141 ot_x5_zitw 1 142 ot_x5_ziw ot_x5_zsC 143 ot_x5_ziw ot_x5_m7 144 ot_x5_zil r 145 ot_x5_ziw ot_x5_zsN 146 put ot_x5_zik 69 add get ot_x5_zik 69 1 147 ret 148 end 149 ot_x5_zipass 150 end 151 152 note ot_x5_zcode: report a C case whose result r is not the expected one 153 fn ot_x5_zcode r long to void 154 put ot_x5_zik 69 add get ot_x5_zik 69 1 155 ot_x5_ziw ot_x5_zsF 156 ot_x5_ziw ot_x5_ar 157 ot_x5_ziw ot_x5_zsL 158 ot_x5_ziu get ot_x5_zik 70 159 ot_x5_ziw ot_x5_zsS 160 ot_x5_zitw 1 161 ot_x5_ziw ot_x5_zsC 162 ot_x5_ziw ot_x5_m1 163 ot_x5_zil r 164 ot_x5_ziw ot_x5_zsN 165 end 166 167 fn ot_x5_zC b edit uchar * to void 168 if lt ot_x5_ztn 6 169 ot_x5_zifail ot_x5_ar ot_x5_m4 170 ret 171 end 172 x = ot_x5_ztdec 2 173 now = ot_x5_ztdec 3 174 r = ot_x5_zroots 5 175 if lt r 0 176 ot_x5_zifail ot_x5_ar ot_x5_m8 177 ret 178 end 179 ot_x5_reset 180 for k ulong sub ot_x5_ztn 6 bound `16777216` 181 n = ot_x5_zload add k 6 b 182 if lt n 0 183 ot_x5_zifail ot_x5_ar ot_x5_m6 184 ret 185 end 186 a = ot_x5_add part b 0 ulong n 187 end 188 ot_x5_zhost b 189 hl = ot_x5_ztl 4 190 if ot_x5_zteq 4 ot_x5_zsm 191 hl = 0 192 end 193 t0 = monons 194 c = ot_x5_check part b 0 hl now 195 t1 = monons 196 if gt get ot_x5_zrs 2 0 197 ot_x5_ziw ot_x5_t1 198 ot_x5_zitw 1 199 ot_x5_ziw ot_x5_t4 200 ot_x5_zil sub t1 t0 201 ot_x5_ziw ot_x5_zsN 202 end 203 if ne long c x 204 ot_x5_zcode long c 205 ret 206 end 207 ot_x5_zipass 208 end 209 210 note ot_x5_zhost: the host token into b[0 ..) 211 fn ot_x5_zhost b edit uchar * to void 212 o = ot_x5_ztk 4 213 for i ulong ot_x5_ztl 4 bound `16777216` 214 put b i get ot_x5_zib add o i 215 end 216 end 217 218 note ot_x5_zkey: the leaf file of token 4, loaded into b, through ot_x5_add, ot_x5_leafspki and ot_pk_tlskey 219 fn ot_x5_zkey b edit uchar * to bool 220 k = new uchar 65536 0 221 n = ot_x5_zload 4 b 222 if lt n 0 223 ret false 224 end 225 ot_x5_reset 226 a = ot_x5_add part b 0 ulong n 227 kl = ot_x5_leafspki k 228 if lt kl 0 229 ret false 230 end 231 ret ot_pk_tlskey part k 0 ulong kl 232 end 233 234 note ot_x5_zcv: ot_pk_tls with the scheme of token 3 235 fn ot_x5_zcv m view uchar * s view uchar * to bool 236 ret ot_pk_tls ulong ot_x5_ztdec 3 m s 237 end 238 239 fn ot_x5_zV b edit uchar * to void 240 m = new uchar 65536 0 241 s = new uchar 8192 0 242 if ne ot_x5_ztn 7 243 ot_x5_zifail ot_x5_ar ot_x5_m4 244 ret 245 end 246 ml = ot_x5_zload 5 m 247 sl = ot_x5_zload 6 s 248 if or lt ml 0 lt sl 0 249 ot_x5_zifail ot_x5_ar ot_x5_m6 250 ret 251 end 252 r = false 253 if ot_x5_zkey b 254 ml2 = ulong ml 255 sl2 = ulong sl 256 r = ot_x5_zcv part m 0 ml2 part s 0 sl2 257 end 258 if ot_x5_zteq 2 ot_x5_wK 259 if eq r false 260 ot_x5_zifail ot_x5_ar ot_x5_m3 261 ret 262 end 263 else 264 if r 265 ot_x5_zifail ot_x5_ar ot_x5_m2 266 ret 267 end 268 end 269 ot_x5_zipass 270 end 271 272 fn ot_x5_zP b edit uchar * to void 273 if or lt ot_x5_ztn 4 gt ot_x5_ztn 5 274 ot_x5_zifail ot_x5_ar ot_x5_m4 275 ret 276 end 277 n = ot_x5_zload 3 b 278 if lt n 0 279 ot_x5_zifail ot_x5_ar ot_x5_m6 280 ret 281 end 282 ot_x5_reset 283 t0 = monons 284 r = gt ot_x5_add part b 0 ulong n 0 285 ms = div sub monons t0 `1000000` 286 if eq ot_x5_ztn 5 287 if gt ms ot_x5_ztdec 4 288 ot_x5_ztime ms 289 ret 290 end 291 end 292 if ot_x5_zteq 2 ot_x5_wK 293 if eq r false 294 ot_x5_zifail ot_x5_ar ot_x5_m3 295 ret 296 end 297 else 298 if r 299 ot_x5_zifail ot_x5_ar ot_x5_m2 300 ret 301 end 302 end 303 ot_x5_zipass 304 end 305 306 note ot_x5_ztime: report a P case over its time bound 307 fn ot_x5_ztime ms long to void 308 put ot_x5_zik 69 add get ot_x5_zik 69 1 309 ot_x5_ziw ot_x5_zsF 310 ot_x5_ziw ot_x5_ar 311 ot_x5_ziw ot_x5_zsL 312 ot_x5_ziu get ot_x5_zik 70 313 ot_x5_ziw ot_x5_zsS 314 ot_x5_zitw 1 315 ot_x5_ziw ot_x5_zsC 316 ot_x5_ziw ot_x5_mB 317 ot_x5_zil ms 318 ot_x5_ziw ot_x5_zsN 319 end 320 321 note ot_x5_zflip: the leaf in b[0 .. n) with byte k inverted, then the issuer file, then a check 322 fn ot_x5_zflip b edit uchar * n ulong k ulong h view uchar * to void 323 q = new uchar 65536 0 324 m = ot_x5_zload 6 q 325 put b k xor get b k 255 326 ot_x5_reset 327 a = ot_x5_add part b 0 n 328 if ge m 0 329 a = ot_x5_add part q 0 ulong m 330 end 331 c = ot_x5_check h ot_x5_ztdec 2 332 put b k xor get b k 255 333 end 334 335 fn ot_x5_zZ b edit uchar * to void 336 h = new uchar 256 0 337 if ne ot_x5_ztn 7 338 ot_x5_zifail ot_x5_ar ot_x5_m4 339 ret 340 end 341 if lt ot_x5_zroots 4 0 342 ot_x5_zifail ot_x5_ar ot_x5_m8 343 ret 344 end 345 n = ot_x5_zload 5 b 346 if lt n 0 347 ot_x5_zifail ot_x5_ar ot_x5_m6 348 ret 349 end 350 hl = ot_x5_ztl 3 351 if gt hl 256 352 ot_x5_zifail ot_x5_ar ot_x5_m4 353 ret 354 end 355 o = ot_x5_ztk 3 356 for i ulong hl bound 256 357 put h i get ot_x5_zib add o i 358 end 359 for k ulong ulong n bound `16777216` 360 ot_x5_reset 361 if gt ot_x5_add part b 0 k 0 362 ot_x5_zifail ot_x5_ar ot_x5_mA 363 ret 364 end 365 end 366 for k ulong ulong n bound `16777216` 367 ot_x5_zflip b ulong n k part h 0 hl 368 end 369 ot_x5_zipass 370 end 371 372 fn ot_x5_zline b edit uchar * to void 373 if ot_x5_zteq 0 ot_x5_wZ 374 ot_x5_zZ b 375 ret 376 end 377 if ot_x5_zteq 0 ot_x5_wP 378 ot_x5_zP b 379 ret 380 end 381 if ot_x5_zteq 0 ot_x5_wC 382 ot_x5_zC b 383 ret 384 end 385 if ot_x5_zteq 0 ot_x5_wR 386 ot_x5_zR 387 ret 388 end 389 if ot_x5_zteq 0 ot_x5_wV 390 ot_x5_zV b 391 ret 392 end 393 ot_x5_zifail ot_x5_ar ot_x5_m4 394 end 395 396 fn main to int 397 b = new uchar `2097152` 0 398 a = ulong 1 399 while lt long a argcnt bound 64 400 k = argread a ot_x5_zip 0 4000 401 if and eq k 6 eq a 1 402 if ot_x5_zargt 403 put ot_x5_zrs 2 1 404 a = add a 1 405 continue 406 end 407 end 408 if eq ot_x5_ziread a false 409 ot_x5_zifail ot_x5_ar ot_x5_m5 410 else 411 while ot_x5_ziline bound `1000000` 412 ot_x5_zline b 413 end 414 end 415 a = add a 1 416 end 417 ret ot_x5_ziend ot_x5_ar 418 end 419 420 note ot_x5_zargt: ot_x5_zip holds "--time" 421 fn ot_x5_zargt to bool 422 for i ulong 6 423 if ne get ot_x5_zip i get ot_x5_wT i 424 ret false 425 end 426 end 427 ret true 428 end