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/aienux/allen/tls-cert.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 / aienux / allen / tls-cert.om` 1299 lines ยท 20413 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Bounded X509/TLS1.3 verifier for api.github.com; RFC5280,5480,5758,8446,9525. 3 note Supports uncompressed named P256/P384 and ECDSA-SHA256/P256 or ECDSA-SHA384/P384. 4 note No AIA, CRL/OCSP fetching, RSA, SHA1, explicit curves, policy/name constraints or fallback. 5 note Unsupported critical extensions and constrained CA paths fail closed, even if noncritical. 6 note Up to8 peer certificates, each <=8192 bytes, TLS body <=60000,32 extensions/certificate. 7 note Exact DER issuer/subject matching is deliberately conservative; no ambiguous normalization. 8 note Trust anchor is the local OS Sectigo Public Server Authentication Root E46 certificate. 9 note Source /etc/ssl/certs/Sectigo_Public_Server_Authentication_Root_E46.pem, read2026-10-25. 10 note DER SHA256 C90F26F0FB1B4018B22227519B5CA2B53E2CA5B3BE5CF18EFE1BEF47380C5383. 11 note Trust is in this root, never in a downloaded self-signed or leaf certificate. 12 note Root cross-signatures need not validate: path terminates at the locally trusted subject/key. 13 note Caller must supply trustworthy current Unix seconds. No network time or zero-time bypass. 14 global Certbuf uchar 65536 15 global Certlen ulong 1 16 global Certnow ulong 1 17 global Certkey uchar 65 18 global Cleaf uchar 65 19 global Certmsg uchar 4096 20 global Certsig uchar 128 21 global Cready ulong 1 22 global Cd ulong 4 23 global Cm ulong 288 24 global Ce ulong 64 25 global Cen ulong 1 26 global Ckey uchar 97 27 global Csig uchar 96 28 global Chash uchar 48 29 global Ctime ulong 8 30 global Cchain ulong 8 31 global Ccount ulong 1 32 text Chost "api.github.com" 33 text Cwild "*.github.com" 34 35 note Cd: tag,value-start,end. Definite minimal DER only, bounds checked before every access. 36 fn ctder p ulong e ulong to bool 37 if or gt e 65536 ge p e 38 ret false 39 end 40 if lt sub e p 2 41 ret false 42 end 43 t = get Certbuf p 44 if or eq and t 31 31 eq t 0 45 ret false 46 end 47 p = add p 1 48 n = ulong get Certbuf p 49 p = add p 1 50 if ge n 128 51 k = sub n 128 52 if or eq k 0 gt k 3 53 ret false 54 end 55 if gt k sub e p 56 ret false 57 end 58 if eq get Certbuf p 0 59 ret false 60 end 61 n = 0 62 for j ulong k 63 n = or shl n 8 ulong get Certbuf add p j 64 end 65 p = add p k 66 if lt n 128 67 ret false 68 end 69 end 70 if gt n sub e p 71 ret false 72 end 73 put Cd 0 ulong t 74 put Cd 1 p 75 put Cd 2 add p n 76 ret true 77 end 78 79 fn cttake p ulong e ulong t ulong to bool 80 if not ctder p e 81 ret false 82 end 83 ret eq get Cd 0 t 84 end 85 86 fn ctequal a ulong ae ulong b ulong be ulong to bool 87 if ne sub ae a sub be b 88 ret false 89 end 90 x = uchar 0 91 for i ulong sub ae a 92 u = get Certbuf add a i 93 v = get Certbuf add b i 94 x = or x xor u v 95 end 96 ret eq x 0 97 end 98 99 note Minimal nonnegative DER INTEGER; zero optionally allowed by caller. 100 fn ctint p ulong e ulong to bool 101 if ge p e 102 ret false 103 end 104 if ge get Certbuf p 128 105 ret false 106 end 107 if gt sub e p 1 108 if eq get Certbuf p 0 109 if lt get Certbuf add p 1 128 110 ret false 111 end 112 end 113 end 114 ret true 115 end 116 117 note OIDs are canonical base128 subidentifiers; max32 octets in this bounded profile. 118 fn ctoid p ulong e ulong to bool 119 if or ge p e gt sub e p 32 120 ret false 121 end 122 fresh = true 123 for i ulong sub e p 124 c = get Certbuf add p i 125 if and fresh eq c 128 126 ret false 127 end 128 fresh = eq and c 128 0 129 end 130 ret fresh 131 end 132 133 fn ctnum p ulong n ulong to ulong 134 v = ulong 0 135 for i ulong n 136 c = get Certbuf add p i 137 if or lt c 48 gt c 57 138 ret 10000 139 end 140 v = add mul v 10 sub ulong c 48 141 end 142 ret v 143 end 144 145 fn ctleap y ulong to bool 146 ret and eq rem y 4 0 or ne rem y 100 0 eq rem y 400 0 147 end 148 149 fn ctmonth y ulong m ulong to ulong 150 if eq m 2 151 if ctleap y 152 ret 29 153 end 154 ret 28 155 end 156 if or or eq m 4 eq m 6 or eq m 9 eq m 11 157 ret 30 158 end 159 ret 31 160 end 161 162 note Absolute Gregorian seconds since 0001-01-01 avoids negative Unix conversions. 163 fn cttime p ulong e ulong to bool 164 if not ctder p e 165 ret false 166 end 167 p = get Cd 1 168 n = sub get Cd 2 p 169 y = ulong 0 170 if eq get Cd 0 23 171 if ne n 13 172 ret false 173 end 174 y = ctnum p 2 175 if gt y 99 176 ret false 177 end 178 if lt y 50 179 y = add y 2000 180 else 181 y = add y 1900 182 end 183 p = add p 2 184 else 185 if ne get Cd 0 24 186 ret false 187 end 188 if ne n 15 189 ret false 190 end 191 y = ctnum p 4 192 if or lt y 2050 gt y 9999 193 ret false 194 end 195 p = add p 4 196 end 197 if ne get Certbuf add p 10 90 198 ret false 199 end 200 put Ctime 0 y 201 for i ulong 5 202 put Ctime add i 1 ctnum add p mul i 2 2 203 end 204 ret true 205 end 206 207 fn ctepoch to ulong 208 y = get Ctime 0 209 m = get Ctime 1 210 d = get Ctime 2 211 if or lt m 1 gt m 12 212 ret 0 213 end 214 if or lt d 1 gt d ctmonth y m 215 ret 0 216 end 217 if gt get Ctime 3 23 218 ret 0 219 end 220 if gt get Ctime 4 59 221 ret 0 222 end 223 if gt get Ctime 5 59 224 ret 0 225 end 226 y = sub y 1 227 days = add mul y 365 div y 4 228 days = sub days div y 100 229 days = add days div y 400 230 y = add y 1 231 for i ulong sub m 1 232 days = add days ctmonth y add i 1 233 end 234 days = add days sub d 1 235 v = add mul days 24 get Ctime 3 236 v = add mul v 60 get Ctime 4 237 ret add mul v 60 get Ctime 5 238 end 239 240 fn ctvalid b ulong p ulong e ulong to bool 241 if not cttake p e 48 242 ret false 243 end 244 p = get Cd 1 245 e = get Cd 2 246 if not cttime p e 247 ret false 248 end 249 p = get Cd 2 250 put Cm add b 11 ctepoch 251 if eq get Cm add b 11 0 252 ret false 253 end 254 if not cttime p e 255 ret false 256 end 257 if ne get Cd 2 e 258 ret false 259 end 260 put Cm add b 12 ctepoch 261 ret ge get Cm add b 12 get Cm add b 11 262 end 263 264 note Signature AlgorithmIdentifier requires absent parameters (RFC5758 section3.2). 265 fn ctalg p ulong e ulong to ulong 266 if not cttake p e 48 267 ret 0 268 end 269 p = get Cd 1 270 e = get Cd 2 271 if not cttake p e 6 272 ret 0 273 end 274 p = get Cd 1 275 if or ne get Cd 2 e ne sub e p 8 276 ret 0 277 end 278 if ne get Certbuf p 42 279 ret 0 280 end 281 if or ne get Certbuf add p 1 134 ne get Certbuf add p 2 72 282 ret 0 283 end 284 if or ne get Certbuf add p 3 206 ne get Certbuf add p 4 61 285 ret 0 286 end 287 if or ne get Certbuf add p 5 4 ne get Certbuf add p 6 3 288 ret 0 289 end 290 if eq get Certbuf add p 7 2 291 ret 32 292 end 293 if eq get Certbuf add p 7 3 294 ret 48 295 end 296 ret 0 297 end 298 299 note Name RDN/ATV syntax is checked; supported directory strings only. Empty subject is handled by SAN. 300 fn ctattr p ulong e ulong to bool 301 if not cttake p e 6 302 ret false 303 end 304 if not ctoid get Cd 1 get Cd 2 305 ret false 306 end 307 p = get Cd 2 308 if not ctder p e 309 ret false 310 end 311 if ne get Cd 2 e 312 ret false 313 end 314 t = get Cd 0 315 if not or or eq t 12 eq t 19 or eq t 20 or eq t 22 eq t 30 316 ret false 317 end 318 ret gt get Cd 2 get Cd 1 319 end 320 321 fn ctname p ulong e ulong to bool 322 if not cttake p e 48 323 ret false 324 end 325 p = get Cd 1 326 e = get Cd 2 327 while lt p e bound 4096 328 if not cttake p e 49 329 ret false 330 end 331 q = get Cd 1 332 r = get Cd 2 333 if eq q r 334 ret false 335 end 336 p = r 337 while lt q r bound 4096 338 if not cttake q r 48 339 ret false 340 end 341 q = get Cd 2 342 if not ctattr get Cd 1 q 343 ret false 344 end 345 end 346 end 347 ret eq p e 348 end 349 350 note Exact ecPublicKey OID and named curves; no explicit/implicit parameters. 351 fn ctcurve p ulong e ulong to ulong 352 if not cttake p e 48 353 ret 0 354 end 355 p = get Cd 1 356 e = get Cd 2 357 if not cttake p e 6 358 ret 0 359 end 360 p = get Cd 1 361 if ne sub get Cd 2 p 7 362 ret 0 363 end 364 if or ne get Certbuf p 42 ne get Certbuf add p 1 134 365 ret 0 366 end 367 if or ne get Certbuf add p 2 72 ne get Certbuf add p 3 206 368 ret 0 369 end 370 if or ne get Certbuf add p 4 61 ne get Certbuf add p 5 2 371 ret 0 372 end 373 if ne get Certbuf add p 6 1 374 ret 0 375 end 376 p = get Cd 2 377 if not cttake p e 6 378 ret 0 379 end 380 p = get Cd 1 381 if ne get Cd 2 e 382 ret 0 383 end 384 if eq sub e p 5 385 if or ne get Certbuf p 43 ne get Certbuf add p 1 129 386 ret 0 387 end 388 if or ne get Certbuf add p 2 4 ne get Certbuf add p 3 0 389 ret 0 390 end 391 if eq get Certbuf add p 4 34 392 ret 48 393 end 394 ret 0 395 end 396 if ne sub e p 8 397 ret 0 398 end 399 if or ne get Certbuf p 42 ne get Certbuf add p 1 134 400 ret 0 401 end 402 if or ne get Certbuf add p 2 72 ne get Certbuf add p 3 206 403 ret 0 404 end 405 if or ne get Certbuf add p 4 61 ne get Certbuf add p 5 3 406 ret 0 407 end 408 if or ne get Certbuf add p 6 1 ne get Certbuf add p 7 7 409 ret 0 410 end 411 ret 32 412 end 413 414 fn ctspki b ulong p ulong e ulong to bool 415 if not cttake p e 48 416 ret false 417 end 418 p = get Cd 1 419 e = get Cd 2 420 k = ctcurve p e 421 if eq k 0 422 ret false 423 end 424 p = get Cd 2 425 if not cttake p e 3 426 ret false 427 end 428 p = get Cd 1 429 if ne get Cd 2 e 430 ret false 431 end 432 if ne sub e p add mul k 2 2 433 ret false 434 end 435 if ne get Certbuf p 0 436 ret false 437 end 438 p = add p 1 439 if ne get Certbuf p 4 440 ret false 441 end 442 put Cm add b 7 p 443 put Cm add b 8 sub e p 444 put Cm add b 24 k 445 ret true 446 end 447 448 note Canonical BIT STRING with at most9 defined KeyUsage bits, named-bit trailing zeros trimmed. 449 fn ctusage b ulong p ulong e ulong to bool 450 if not cttake p e 3 451 ret false 452 end 453 p = get Cd 1 454 if ne get Cd 2 e 455 ret false 456 end 457 n = sub e p 458 if or lt n 2 gt n 3 459 ret false 460 end 461 u = ulong get Certbuf p 462 if gt u 7 463 ret false 464 end 465 last = ulong get Certbuf sub e 1 466 if eq last 0 467 ret false 468 end 469 if ne and last sub shl ulong 1 u 1 0 470 ret false 471 end 472 if eq and shr last u 1 0 473 ret false 474 end 475 if eq n 3 476 if or ne u 7 ne last 128 477 ret false 478 end 479 end 480 put Cm add b 15 ulong get Certbuf add p 1 481 put Cm add b 16 1 482 ret true 483 end 484 485 fn ctbasic b ulong p ulong e ulong crit bool to bool 486 if not cttake p e 48 487 ret false 488 end 489 p = get Cd 1 490 if ne get Cd 2 e 491 ret false 492 end 493 put Cm add b 20 1 494 if crit 495 put Cm add b 21 1 496 end 497 if eq p e 498 ret true 499 end 500 if not cttake p e 1 501 ret false 502 end 503 if ne sub get Cd 2 get Cd 1 1 504 ret false 505 end 506 if ne get Certbuf get Cd 1 255 507 ret false 508 end 509 put Cm add b 13 1 510 p = get Cd 2 511 if eq p e 512 ret true 513 end 514 if not cttake p e 2 515 ret false 516 end 517 p = get Cd 1 518 if ne get Cd 2 e 519 ret false 520 end 521 if not ctint p e 522 ret false 523 end 524 if gt sub e p 2 525 ret false 526 end 527 v = ulong 0 528 for i ulong sub e p 529 v = or shl v 8 ulong get Certbuf add p i 530 end 531 put Cm add b 14 v 532 ret true 533 end 534 535 fn ctdns p ulong e ulong to bool 536 n = sub e p 537 if or eq n 0 gt n 253 538 ret false 539 end 540 for i ulong n 541 c = get Certbuf add p i 542 if or eq c 0 ge c 128 543 ret false 544 end 545 end 546 if eq n len Chost 547 ok = true 548 for j ulong n 549 c = get Certbuf add p j 550 if and ge c 65 le c 90 551 c = add c 32 552 end 553 if ne c get Chost j 554 ok = false 555 end 556 end 557 ret ok 558 end 559 if eq n len Cwild 560 ok = true 561 for j ulong n 562 c = get Certbuf add p j 563 if and ge c 65 le c 90 564 c = add c 32 565 end 566 if ne c get Cwild j 567 ok = false 568 end 569 end 570 ret ok 571 end 572 ret false 573 end 574 575 note GeneralName CHOICE tags other than dNSName: [0] [1] [3]-[8] (RFC5280 4.2.1.6). 576 fn ctgname t ulong to bool 577 if or eq t 160 eq t 129 578 ret true 579 end 580 if and ge t 163 le t 165 581 ret true 582 end 583 ret and ge t 134 le t 136 584 end 585 586 fn ctsan b ulong p ulong e ulong to bool 587 if not cttake p e 48 588 ret false 589 end 590 p = get Cd 1 591 if or ne get Cd 2 e eq p e 592 ret false 593 end 594 put Cm add b 23 1 595 while lt p e bound 4096 596 if not ctder p e 597 ret false 598 end 599 p = get Cd 2 600 t = get Cd 0 601 if eq t 130 602 if ctdns get Cd 1 p 603 put Cm add b 18 1 604 end 605 else 606 note The required identity is DNS. Other legal GeneralName alternatives never match it. 607 if not ctgname t 608 ret false 609 end 610 end 611 end 612 ret eq p e 613 end 614 615 fn cteku b ulong p ulong e ulong to bool 616 if not cttake p e 48 617 ret false 618 end 619 p = get Cd 1 620 if or ne get Cd 2 e eq p e 621 ret false 622 end 623 put Cm add b 22 1 624 put Cm add b 17 0 625 while lt p e bound 4096 626 if not cttake p e 6 627 ret false 628 end 629 p = get Cd 1 630 q = get Cd 2 631 if not ctoid p q 632 ret false 633 end 634 if eq sub q p 8 635 if and eq get Certbuf p 43 eq get Certbuf add p 1 6 636 if and eq get Certbuf add p 2 1 eq get Certbuf add p 3 5 637 if and eq get Certbuf add p 4 5 eq get Certbuf add p 5 7 638 if and eq get Certbuf add p 6 3 eq get Certbuf add p 7 1 639 put Cm add b 17 1 640 end 641 end 642 end 643 end 644 end 645 p = q 646 end 647 ret eq p e 648 end 649 650 note Duplicate extension OIDs, including unknown ones, are refused before interpretation. 651 fn ctunique p ulong e ulong to bool 652 if not ctoid p e 653 ret false 654 end 655 n = get Cen 0 656 if ge n 32 657 ret false 658 end 659 for i ulong n 660 if ctequal p e get Ce mul i 2 get Ce add mul i 2 1 661 ret false 662 end 663 end 664 put Ce mul n 2 p 665 put Ce add mul n 2 1 e 666 put Cen 0 add n 1 667 ret true 668 end 669 670 fn ctextval b ulong id ulong p ulong e ulong crit bool to bool 671 if eq id 19 672 ret ctbasic b p e crit 673 end 674 if eq id 15 675 ret ctusage b p e 676 end 677 if eq id 17 678 ret ctsan b p e 679 end 680 if eq id 37 681 ret cteku b p e 682 end 683 note Constraints needing further path processing cannot be silently ignored even if noncritical. 684 if or or eq id 30 eq id 33 or eq id 36 eq id 54 685 ret false 686 end 687 if crit 688 ret false 689 end 690 ret true 691 end 692 693 fn ctextone b ulong p ulong e ulong to bool 694 if not cttake p e 6 695 ret false 696 end 697 p = get Cd 1 698 q = get Cd 2 699 if not ctunique p q 700 ret false 701 end 702 id = ulong 0 703 if eq sub q p 3 704 if and eq get Certbuf p 85 eq get Certbuf add p 1 29 705 id = ulong get Certbuf add p 2 706 end 707 end 708 p = q 709 crit = false 710 if not ctder p e 711 ret false 712 end 713 if eq get Cd 0 1 714 if ne sub get Cd 2 get Cd 1 1 715 ret false 716 end 717 if ne get Certbuf get Cd 1 255 718 ret false 719 end 720 crit = true 721 p = get Cd 2 722 end 723 if not cttake p e 4 724 ret false 725 end 726 p = get Cd 1 727 if ne get Cd 2 e 728 ret false 729 end 730 ret ctextval b id p e crit 731 end 732 733 fn ctexts b ulong p ulong e ulong to bool 734 if not cttake p e 163 735 ret false 736 end 737 p = get Cd 1 738 if ne get Cd 2 e 739 ret false 740 end 741 if not cttake p e 48 742 ret false 743 end 744 p = get Cd 1 745 if or ne get Cd 2 e eq p e 746 ret false 747 end 748 put Cen 0 0 749 while lt p e bound 4096 750 if not cttake p e 48 751 ret false 752 end 753 p = get Cd 2 754 if not ctextone b get Cd 1 p 755 ret false 756 end 757 end 758 ret eq p e 759 end 760 761 fn ctfront b ulong p ulong e ulong to ulong 762 if not cttake p e 160 763 ret 0 764 end 765 q = get Cd 1 766 p = get Cd 2 767 if not cttake q p 2 768 ret 0 769 end 770 if or ne get Cd 2 p ne sub p get Cd 1 1 771 ret 0 772 end 773 if ne get Certbuf get Cd 1 2 774 ret 0 775 end 776 if not cttake p e 2 777 ret 0 778 end 779 q = get Cd 1 780 p = get Cd 2 781 if not ctint q p 782 ret 0 783 end 784 if or gt sub p q 21 eq sub p q 0 785 ret 0 786 end 787 if and eq sub p q 21 ne get Certbuf q 0 788 ret 0 789 end 790 v = uchar 0 791 for i ulong sub p q 792 v = or v get Certbuf add q i 793 end 794 if eq v 0 795 ret 0 796 end 797 put Cm add b 2 ctalg p e 798 if eq get Cm add b 2 0 799 ret 0 800 end 801 ret get Cd 2 802 end 803 804 fn ctfields b ulong p ulong e ulong to ulong 805 put Cm add b 3 p 806 if not cttake p e 48 807 ret 0 808 end 809 p = get Cd 2 810 put Cm add b 4 p 811 if not ctname get Cm add b 3 p 812 ret 0 813 end 814 if not cttake p e 48 815 ret 0 816 end 817 q = get Cd 2 818 if not ctvalid b p q 819 ret 0 820 end 821 p = q 822 put Cm add b 5 p 823 if not cttake p e 48 824 ret 0 825 end 826 p = get Cd 2 827 put Cm add b 6 p 828 if not ctname get Cm add b 5 p 829 ret 0 830 end 831 if not cttake p e 48 832 ret 0 833 end 834 q = get Cd 2 835 if not ctspki b p q 836 ret 0 837 end 838 ret q 839 end 840 841 fn ctparse idx ulong p ulong e ulong to bool 842 b = mul idx 32 843 for i ulong 32 844 put Cm add b i 0 845 end 846 put Cm add b 14 8 847 put Cm add b 17 1 848 if not cttake p e 48 849 ret false 850 end 851 if ne get Cd 2 e 852 ret false 853 end 854 p = get Cd 1 855 put Cm b p 856 if not cttake p e 48 857 ret false 858 end 859 q = get Cd 2 860 put Cm add b 1 q 861 p = ctfront b get Cd 1 q 862 if eq p 0 863 ret false 864 end 865 p = ctfields b p q 866 if eq p 0 867 ret false 868 end 869 if lt p q 870 if not ctexts b p q 871 ret false 872 end 873 end 874 p = q 875 if ne ctalg p e get Cm add b 2 876 ret false 877 end 878 p = get Cd 2 879 if not cttake p e 3 880 ret false 881 end 882 p = get Cd 1 883 if or ne get Cd 2 e ge p e 884 ret false 885 end 886 if ne get Certbuf p 0 887 ret false 888 end 889 put Cm add b 9 add p 1 890 put Cm add b 10 e 891 put Cm add b 25 1 892 ret true 893 end 894 895 fn ctrawint p ulong e ulong width ulong off ulong to bool 896 if not ctint p e 897 ret false 898 end 899 if eq get Certbuf p 0 900 p = add p 1 901 end 902 n = sub e p 903 if or eq n 0 gt n width 904 ret false 905 end 906 for i ulong n 907 put Csig add off add sub width n i get Certbuf add p i 908 end 909 ret true 910 end 911 912 fn ctrawsig p ulong e ulong width ulong to bool 913 for i ulong 96 914 put Csig i 0 915 end 916 if not cttake p e 48 917 ret false 918 end 919 p = get Cd 1 920 if ne get Cd 2 e 921 ret false 922 end 923 if not cttake p e 2 924 ret false 925 end 926 p = get Cd 1 927 q = get Cd 2 928 if not ctrawint p q width 0 929 ret false 930 end 931 if not cttake q e 2 932 ret false 933 end 934 p = get Cd 1 935 if ne get Cd 2 e 936 ret false 937 end 938 ret ctrawint p e width width 939 end 940 941 fn ctsha256 p ulong e ulong to void 942 constants 943 hinit 944 for i ulong sub e p 945 hbyte get Certbuf add p i 946 end 947 finish 948 for j ulong 32 949 put Chash j get Hash j 950 end 951 end 952 953 fn ctsha384 p ulong e ulong to void 954 m = new uchar 65536 0 955 d = new uchar 64 0 956 for i ulong sub e p 957 put m i get Certbuf add p i 958 end 959 cs384hash m sub e p d 960 for j ulong 48 961 put Chash j get d j 962 end 963 end 964 965 fn ctvp256 to bool 966 w = new ulong 1024 0 967 b = new uchar 4096 0 968 for i ulong 65 969 put b add 3072 i get Ckey i 970 end 971 for j ulong 64 972 put b add 3200 j get Csig j 973 end 974 for k ulong 32 975 put b add 3296 k get Chash k 976 end 977 cp2init w 978 ret eq cp2vrfy w b 1 979 end 980 981 fn ctvp384 to bool 982 w = new ulong 1536 0 983 b = new uchar 4096 0 984 for i ulong 97 985 put b add 3072 i get Ckey i 986 end 987 for j ulong 96 988 put b add 3200 j get Csig j 989 end 990 for k ulong 48 991 put b add 3296 k get Chash k 992 end 993 cp3init w 994 ret eq cp3vrfy w b 1 995 end 996 997 fn ctchecksig child ulong issuer ulong to bool 998 c = mul child 32 999 b = mul issuer 32 1000 width = get Cm add c 2 1001 if ne width get Cm add b 24 1002 ret false 1003 end 1004 if not ctrawsig get Cm add c 9 get Cm add c 10 width 1005 ret false 1006 end 1007 ko = get Cm add b 7 1008 kn = get Cm add b 8 1009 for i ulong kn 1010 put Ckey i get Certbuf add ko i 1011 end 1012 if eq width 32 1013 ctsha256 get Cm c get Cm add c 1 1014 ret ctvp256 1015 end 1016 ctsha384 get Cm c get Cm add c 1 1017 ret ctvp384 1018 end 1019 1020 fn ctclock idx ulong to bool 1021 b = mul idx 32 1022 if gt get Certnow 0 `253402300799` 1023 ret false 1024 end 1025 now = add get Certnow 0 `62135596800` 1026 ret and ge now get Cm add b 11 le now get Cm add b 12 1027 end 1028 1029 fn ctca idx ulong below ulong to bool 1030 b = mul idx 32 1031 if not ctclock idx 1032 ret false 1033 end 1034 if or ne get Cm add b 13 1 ne get Cm add b 21 1 1035 ret false 1036 end 1037 if or ne get Cm add b 16 1 eq and get Cm add b 15 4 0 1038 ret false 1039 end 1040 if gt below get Cm add b 14 1041 ret false 1042 end 1043 ret eq get Cm add b 17 1 1044 end 1045 1046 fn ctleaf to bool 1047 if not ctclock 0 1048 ret false 1049 end 1050 if ne get Cm 24 32 1051 ret false 1052 end 1053 if ne get Cm 13 0 1054 ret false 1055 end 1056 if or ne get Cm 16 1 eq and get Cm 15 128 0 1057 ret false 1058 end 1059 if ne and get Cm 15 4 0 1060 ret false 1061 end 1062 if or ne get Cm 22 1 ne get Cm 17 1 1063 ret false 1064 end 1065 if or ne get Cm 23 1 ne get Cm 18 1 1066 ret false 1067 end 1068 w = new ulong 1024 0 1069 b = new uchar 4096 0 1070 cp2init w 1071 for i ulong 65 1072 put b add 3072 i get Certbuf add get Cm 7 i 1073 end 1074 cp2ld w C2X b 3073 1075 cp2ld w C2Y b 3105 1076 ret cp2oncv w 1077 end 1078 1079 fn certreset to void 1080 put Cready 0 0 1081 for i ulong 65 1082 put Certkey i 0 1083 put Cleaf i 0 1084 end 1085 for i ulong 97 1086 put Ckey i 0 1087 end 1088 for i ulong 96 1089 put Csig i 0 1090 end 1091 for i ulong 48 1092 put Chash i 0 1093 end 1094 for i ulong 4096 1095 put Certmsg i 0 1096 end 1097 for i ulong 128 1098 put Certsig i 0 1099 end 1100 for i ulong 288 1101 put Cm i 0 1102 end 1103 for i ulong 64 1104 put Ce i 0 1105 end 1106 for i ulong 8 1107 put Cchain i 0 1108 put Ctime i 0 1109 end 1110 put Cen 0 0 1111 put Ccount 0 0 1112 end 1113 1114 fn ctbe p ulong n ulong to ulong 1115 v = ulong 0 1116 for i ulong n 1117 v = or shl v 8 ulong get Certbuf add p i 1118 end 1119 ret v 1120 end 1121 1122 note Certificate-entry extensions are not negotiated by this client; unsolicited ones fail closed. 1123 fn ctlist to bool 1124 e = get Certlen 0 1125 if or lt e 4 gt e 60000 1126 ret false 1127 end 1128 if ne get Certbuf 0 0 1129 ret false 1130 end 1131 if ne ctbe 1 3 sub e 4 1132 ret false 1133 end 1134 p = ulong 4 1135 n = ulong 0 1136 while lt p e bound 9 1137 if or ge n 8 lt sub e p 5 1138 ret false 1139 end 1140 k = ctbe p 3 1141 p = add p 3 1142 if or eq k 0 gt k 8192 1143 ret false 1144 end 1145 if gt k sub e p 1146 ret false 1147 end 1148 q = add p k 1149 note Unused extra certificates may use unsupported algorithms; only parsed ones can be issuers. 1150 if not ctparse n p q 1151 if eq n 0 1152 ret false 1153 end 1154 end 1155 p = q 1156 if lt sub e p 2 1157 ret false 1158 end 1159 if ne ctbe p 2 0 1160 ret false 1161 end 1162 p = add p 2 1163 n = add n 1 1164 end 1165 put Ccount 0 n 1166 ret and eq p e gt n 0 1167 end 1168 1169 note Path building uses only supplied certificates plus the local root. Anchor is tried first. 1170 note Child's exact issuer Name DER equals candidate parent's subject Name DER. 1171 fn ctissued child ulong parent ulong to bool 1172 c = mul child 32 1173 q = mul parent 32 1174 ret ctequal get Cm add c 3 get Cm add c 4 get Cm add q 5 get Cm add q 6 1175 end 1176 1177 fn ctpath to bool 1178 if not ctleaf 1179 ret false 1180 end 1181 idx = ulong 0 1182 below = ulong 0 1183 for depth ulong 8 1184 if ne get Cchain idx 0 1185 ret false 1186 end 1187 put Cchain idx 1 1188 if ctissued idx 8 1189 if not ctca 8 below 1190 ret false 1191 end 1192 ret ctchecksig idx 8 1193 end 1194 next = ulong 8 1195 for j ulong get Ccount 0 1196 ok = eq get Cm add mul j 32 25 1 1197 if and ok ctissued idx j 1198 if ne next 8 1199 ret false 1200 end 1201 next = j 1202 end 1203 end 1204 if eq next 8 1205 ret false 1206 end 1207 if not ctca next below 1208 ret false 1209 end 1210 if not ctchecksig idx next 1211 ret false 1212 end 1213 idx = next 1214 below = add below 1 1215 end 1216 ret false 1217 end 1218 1219 fn cthexv c uchar to uchar 1220 if and ge c 48 le c 57 1221 ret sub c 48 1222 end 1223 if and ge c 97 le c 102 1224 ret sub c 87 1225 end 1226 trap 5 1227 end 1228 1229 note Decode vendor/cert-root.om Croot to Certbuf 64000..64574, above every accepted peer byte. 1230 fn ctroot to bool 1231 if ne len Croot 1148 1232 ret false 1233 end 1234 for i ulong 574 1235 h = cthexv get Croot mul i 2 1236 l = cthexv get Croot add mul i 2 1 1237 put Certbuf add 64000 i or shl h 4 l 1238 end 1239 ret true 1240 end 1241 1242 fn certcheck to bool 1243 certreset 1244 if not ctroot 1245 ret false 1246 end 1247 note The DER root is local and already trusted; parsing only exposes its subject, key and limits. 1248 if not ctparse 8 64000 64574 1249 ret false 1250 end 1251 if not ctlist 1252 ret false 1253 end 1254 if not ctpath 1255 ret false 1256 end 1257 for i ulong 65 1258 put Certkey i get Certbuf add get Cm 7 i 1259 put Cleaf i get Certkey i 1260 end 1261 put Cready 0 1 1262 ret true 1263 end 1264 1265 note TLS CertificateVerify: current validated leaf required, DER signature and SHA256 message. 1266 fn certsig n ulong siglen ulong to bool 1267 if ne get Cready 0 1 1268 ret false 1269 end 1270 if or gt n 4096 or eq siglen 0 gt siglen 128 1271 certreset 1272 ret false 1273 end 1274 for i ulong siglen 1275 put Certbuf add 60000 i get Certsig i 1276 end 1277 if not ctrawsig 60000 add 60000 siglen 32 1278 certreset 1279 ret false 1280 end 1281 constants 1282 hinit 1283 for j ulong n 1284 hbyte get Certmsg j 1285 end 1286 finish 1287 for k ulong 32 1288 put Chash k get Hash k 1289 end 1290 note Private copy: later caller writes to exported Certkey cannot change the authenticated key. 1291 for m ulong 65 1292 put Ckey m get Cleaf m 1293 end 1294 ok = ctvp256 1295 if not ok 1296 certreset 1297 end 1298 ret ok 1299 end