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/apps/omega-strand-hub/gate.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 / apps / omega-strand-hub / gate.om` 2376 lines ยท 56681 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note omega-strand-hub/gate.om: pure seeded-Omega (om2) end-to-end verification gate 3 note Usage: ./strand-hub-gate [real_sp_1] [real_sp_2] 4 om2 5 6 const GT_IP uint `2130706433` 7 const GT_IO_TMO long `15000000000` 8 const OSPMAG ulong `3544421225449933903` 9 const FNV_OFF ulong `14695981039346656037` 10 const FNV_PRM ulong `1099511628211` 11 12 global g_srv uchar 512 13 global g_srvl ulong 1 14 global g_dir uchar 512 15 global g_dirl ulong 1 16 global g_port ulong 1 17 global g_rsp1 uchar 512 18 global g_rsp1l ulong 1 19 global g_rsp2 uchar 512 20 global g_rsp2l ulong 1 21 global g_pid int 1 22 global g_pass ulong 1 23 global g_fail ulong 1 24 25 global g_pk uchar 4096 26 global g_pkl ulong 1 27 global g_pkr ulong 1 28 29 global g_tx uchar 65536 30 global g_txl ulong 1 31 global g_rx uchar 262144 32 global g_rxl ulong 1 33 global g_rx_hend ulong 1 34 global g_rx_code ulong 1 35 global g_io uchar 65536 36 37 global g_pack uchar 32768 38 global g_packl ulong 1 39 global g_mp uchar 65536 40 global g_mpl ulong 1 41 global g_body uchar 16384 42 global g_bodyl ulong 1 43 44 global g_sha_a uchar 64 45 global g_sha_b uchar 64 46 global g_sha_c uchar 64 47 global g_sha_d uchar 64 48 global g_sha_r1 uchar 64 49 global g_sha_r2 uchar 64 50 global g_sha_e1 uchar 64 51 global g_sha_e2 uchar 64 52 global g_clip_sha uchar 64 53 global g_clip_man uchar 16384 54 global g_clip_manl ulong 1 55 global g_hdr_val uchar 128 56 global g_hdr_vall ulong 1 57 global g_orig_a uchar 1024 58 global g_orig_al ulong 1 59 60 note Independent FIPS 180-4 SHA-256 for oracle verification 61 global g_sh_k uint 64 62 global g_sh_h uint 8 63 global g_sh_w uint 64 64 global g_sh_v uint 8 65 global g_sh_buf uchar 64 66 global g_sh_len ulong 1 67 global g_sh_init ulong 1 68 global g_sh_hex uchar 64 69 global g_out uchar 2048 70 global g_outl ulong 1 71 72 text t_sha_k "`1116352408` `1899447441` `3049323471` `3921009573` `961987163` `1508970993` `2453635748` `2870763221` `3624381080` `310598401` `607225278` `1426881987` `1925078388` `2162078206` `2614888103` `3248222580` `3835390401` `4022224774` `264347078` `604807628` `770255983` `1249150122` `1555081692` `1996064986` `2554220882` `2821834349` `2952996808` `3210313671` `3336571891` `3584528711` `113926993` `338241895` `666307205` `773529912` `1294757372` `1396182291` `1695183700` `1986661051` `2177026350` `2456956037` `2730485921` `2820302411` `3259730800` `3345764771` `3516065817` `3600352804` `4094571909` `275423344` `430227734` `506948616` `659060556` `883997877` `958139571` `1322822218` `1537002063` `1747873779` `1955562222` `2024104815` `2227730452` `2361852424` `2428436474` `2756734187` `3204031479` `3329325298`" 73 74 text t_devnull "/dev/null" 75 text t_usage "usage: strand-hub-gate [real_sp1] [real_sp2]\n" 76 text t_pass_pre "PASS " 77 text t_fail_pre "FAIL " 78 text t_sum_pre "STRAND_HUB_GATE pass=" 79 text t_sum_mid " fail=" 80 text t_nl "\n" 81 82 text t_bnd "----OmStrandGateBnd99" 83 text t_http11 " HTTP/1.1" 84 text t_host_hdr "Host: 127.0.0.1" 85 text t_conn_hdr "Connection: close" 86 text t_cl_hdr "Content-Length: " 87 text t_ct_mp_hdr "Content-Type: multipart/form-data; boundary=----OmStrandGateBnd99" 88 text t_ct_form_hdr "Content-Type: application/x-www-form-urlencoded" 89 text t_ct_oct_hdr "Content-Type: application/octet-stream" 90 text t_ct_txt_hdr "Content-Type: text/plain" 91 92 text t_xsha_h "x-strand-sha256:" 93 text t_xbh_h "x-strand-base-hash:" 94 text t_xksha_h "x-spclip-sha256:" 95 text t_cd_h "content-disposition:" 96 text t_m_get_w "GET" 97 text t_m_head_w "HEAD" 98 text t_m_post_w "POST" 99 text t_suf_sp ".sp" 100 text t_suf_spclip ".spclip" 101 102 note ---- Output / logging helpers ---- 103 104 fn o_reset to void 105 put g_outl 0 0 106 end 107 108 fn o_b c uchar to void 109 n = get g_outl 0 110 if lt n 2048 111 put g_out n c 112 put g_outl 0 add n 1 113 end 114 end 115 116 fn o_txt t view uchar * to void 117 for i ulong len t bound 512 118 o_b get t i 119 end 120 end 121 122 fn o_u64 v ulong to void 123 buf = new uchar 24 0 124 p = ulong 24 125 n = v 126 if eq n 0 127 o_b 48 128 ret 129 end 130 while gt n 0 bound 24 131 p = sub p 1 132 put buf p uchar add 48 rem n 10 133 n = div n 10 134 end 135 while lt p 24 bound 24 136 o_b get buf p 137 p = add p 1 138 end 139 end 140 141 fn o_flush to void 142 n = get g_outl 0 143 if gt n 0 144 x = write 1 g_out 0 n 145 put g_outl 0 0 146 end 147 end 148 149 fn chk ok bool name view uchar * to void 150 o_reset 151 if ok 152 put g_pass 0 add get g_pass 0 1 153 o_txt t_pass_pre 154 else 155 put g_fail 0 add get g_fail 0 1 156 o_txt t_fail_pre 157 end 158 o_txt name 159 o_b 10 160 o_flush 161 end 162 163 note ---- Byte/hex/SHA-256 oracle ---- 164 165 fn to_low c uchar to uchar 166 if ge c 65 167 if le c 90 168 ret add c 32 169 end 170 end 171 ret c 172 end 173 174 fn hex_ch v ulong to uchar 175 d = and v 15 176 if lt d 10 177 ret uchar add 48 d 178 end 179 ret uchar add 87 d 180 end 181 182 fn sha_init_k to void 183 if ne get g_sh_init 0 0 184 ret 185 end 186 put g_sh_init 0 1 187 p = ulong 0 188 for i ulong 64 189 v = ulong 0 190 while lt p len t_sha_k bound 8 191 if ge get t_sha_k p 48 192 break 193 end 194 p = add p 1 195 end 196 while lt p len t_sha_k bound 16 197 c = get t_sha_k p 198 if lt c 48 199 break 200 end 201 v = add mul v 10 ulong sub c 48 202 p = add p 1 203 end 204 put g_sh_k i uint v 205 end 206 end 207 208 fn sha_start to void 209 sha_init_k 210 put g_sh_h 0 0x6a09e667 211 put g_sh_h 1 0xbb67ae85 212 put g_sh_h 2 0x3c6ef372 213 put g_sh_h 3 0xa54ff53a 214 put g_sh_h 4 0x510e527f 215 put g_sh_h 5 0x9b05688c 216 put g_sh_h 6 0x1f83d9ab 217 put g_sh_h 7 0x5be0cd19 218 put g_sh_len 0 0 219 end 220 221 fn sha_s0 a uint to uint 222 ret xor xor rotr a 2 rotr a 13 rotr a 22 223 end 224 225 fn sha_s1 e uint to uint 226 ret xor xor rotr e 6 rotr e 11 rotr e 25 227 end 228 229 fn sha_g0 x uint to uint 230 ret xor xor rotr x 7 rotr x 18 shr x 3 231 end 232 233 fn sha_g1 x uint to uint 234 ret xor xor rotr x 17 rotr x 19 shr x 10 235 end 236 237 fn sha_rnd i ulong to void 238 e = get g_sh_v 4 239 t1 = add get g_sh_v 7 sha_s1 e 240 t1 = add t1 xor and e get g_sh_v 5 and not e get g_sh_v 6 241 t1 = add t1 add get g_sh_k i get g_sh_w i 242 a = get g_sh_v 0 243 b = get g_sh_v 1 244 c = get g_sh_v 2 245 t2 = add sha_s0 a xor xor and a b and a c and b c 246 put g_sh_v 7 get g_sh_v 6 247 put g_sh_v 6 get g_sh_v 5 248 put g_sh_v 5 e 249 put g_sh_v 4 add get g_sh_v 3 t1 250 put g_sh_v 3 c 251 put g_sh_v 2 b 252 put g_sh_v 1 a 253 put g_sh_v 0 add t1 t2 254 end 255 256 fn sha_compress to void 257 for t ulong 16 258 q = mul t 4 259 w = shl uint get g_sh_buf q 24 260 w = or w shl uint get g_sh_buf add q 1 16 261 w = or w shl uint get g_sh_buf add q 2 8 262 w = or w uint get g_sh_buf add q 3 263 put g_sh_w t w 264 end 265 for t ulong 48 266 u = add t 16 267 x = add sha_g1 get g_sh_w sub u 2 get g_sh_w sub u 7 268 put g_sh_w u add x add sha_g0 get g_sh_w sub u 15 get g_sh_w sub u 16 269 end 270 for j ulong 8 271 put g_sh_v j get g_sh_h j 272 end 273 for i ulong 64 274 sha_rnd i 275 end 276 for j ulong 8 277 put g_sh_h j add get g_sh_h j get g_sh_v j 278 end 279 end 280 281 fn sha_b c uchar to void 282 n = get g_sh_len 0 283 bi = and n 63 284 put g_sh_buf bi c 285 put g_sh_len 0 add n 1 286 if eq bi 63 287 sha_compress 288 end 289 end 290 291 fn sha_finish to void 292 tot = get g_sh_len 0 293 bits = shl tot 3 294 sha_b 128 295 while ne and get g_sh_len 0 63 56 bound 64 296 sha_b 0 297 end 298 for i ulong 8 299 sh = mul sub 7 i 8 300 sha_b uchar and shr bits sh 255 301 end 302 for j ulong 8 303 v = ulong get g_sh_h j 304 for q ulong 4 305 sh = mul sub 3 q 8 306 b = uchar and shr v sh 255 307 hi = mul add mul j 4 q 2 308 put g_sh_hex hi hex_ch shr ulong b 4 309 put g_sh_hex add hi 1 hex_ch ulong b 310 end 311 end 312 end 313 314 fn sha_pack to void 315 sha_start 316 n = get g_packl 0 317 for i ulong n bound 32768 318 sha_b get g_pack i 319 end 320 sha_finish 321 end 322 323 note ---- Valid OLLMSP01 pack builder ---- 324 325 fn put_u64_le_pack off ulong v ulong to void 326 for i ulong 8 327 put g_pack add off i uchar and shr v mul i 8 255 328 end 329 end 330 331 fn build_valid_pack bl ulong sl ulong bh ulong npar ulong seed ulong to void 332 put_u64_le_pack 0 OSPMAG 333 put_u64_le_pack 8 bl 334 put_u64_le_pack 16 sl 335 put_u64_le_pack 24 bh 336 put_u64_le_pack 32 npar 337 for i ulong npar bound 4000 338 f = mul 0.001f64 f64 add add seed mul i 7 1 339 put_u64_le_pack add 48 mul i 8 bitcast ulong f 340 end 341 put g_packl 0 add 48 mul npar 8 342 recompute_pack_fnv 343 end 344 345 fn recompute_pack_fnv to void 346 n = get g_packl 0 347 fnv = FNV_OFF 348 if gt n 48 349 for i ulong sub n 48 bound 32768 350 fnv = mul xor fnv ulong get g_pack add 48 i FNV_PRM 351 end 352 end 353 put_u64_le_pack 40 fnv 354 end 355 356 note ---- Child server process launcher & reaper ---- 357 358 fn pk_reset to void 359 put g_pk 0 0 360 put g_pk 1 0 361 put g_pkl 0 2 362 end 363 364 fn pk_open to void 365 n = get g_pkl 0 366 put g_pkr 0 n 367 put g_pk n 0 368 put g_pk add n 1 0 369 put g_pkl 0 add n 2 370 c = add or ulong get g_pk 0 shl ulong get g_pk 1 8 1 371 put g_pk 0 uchar and c 255 372 put g_pk 1 uchar shr c 8 373 end 374 375 fn pk_b c uchar to void 376 n = get g_pkl 0 377 if lt n 4094 378 put g_pk n c 379 put g_pkl 0 add n 1 380 r = get g_pkr 0 381 k = add or ulong get g_pk r shl ulong get g_pk add r 1 8 1 382 put g_pk r uchar and k 255 383 put g_pk add r 1 uchar shr k 8 384 end 385 end 386 387 fn pk_u64 v ulong to void 388 buf = new uchar 24 0 389 p = ulong 24 390 n = v 391 if eq n 0 392 pk_b 48 393 ret 394 end 395 while gt n 0 bound 24 396 p = sub p 1 397 put buf p uchar add 48 rem n 10 398 n = div n 10 399 end 400 while lt p 24 bound 24 401 pk_b get buf p 402 p = add p 1 403 end 404 end 405 406 fn start_server max_up ulong to bool 407 pk_reset 408 pk_open 409 for i ulong get g_srvl 0 bound 512 410 pk_b get g_srv i 411 end 412 pk_open 413 for i ulong get g_dirl 0 bound 512 414 pk_b get g_dir i 415 end 416 pk_open 417 pk_u64 get g_port 0 418 pk_open 419 pk_u64 max_up 420 pid = fork 421 if lt pid 0 422 ret false 423 end 424 if eq pid 0 425 nul = fopen t_devnull 0 len t_devnull 2 0 426 if ge nul 0 427 x = dupfd int nul 0 0 428 x = dupfd int nul 1 0 429 x = dupfd int nul 2 0 430 end 431 x = execprog g_pk 0 get g_pkl 0 432 exit 127 433 end 434 put g_pid 0 int pid 435 x = sleepns `150000000` 436 ret true 437 end 438 439 fn stop_server to void 440 st = new uchar 4 0 441 pid = get g_pid 0 442 if gt pid 0 443 x = killpid pid 15 444 w = waitpid pid st 0 4 0 445 put g_pid 0 0 446 x = sleepns `50000000` 447 end 448 end 449 450 note ---- Loopback TCP HTTP client ---- 451 452 fn connect_hub to int 453 fd = socknew 2 524289 0 454 if lt fd 0 455 ret -1 456 end 457 port = get g_port 0 458 a = new uchar 16 0 459 put a 0 2 460 put a 2 uchar and shr port 8 255 461 put a 3 uchar and port 255 462 put a 4 uchar and shr GT_IP 24 255 463 put a 5 uchar and shr GT_IP 16 255 464 put a 6 uchar and shr GT_IP 8 255 465 put a 7 uchar and GT_IP 255 466 if ne connect int fd a 0 16 0 467 x = fclose int fd 468 ret -1 469 end 470 ret int fd 471 end 472 473 fn tx_reset to void 474 put g_txl 0 0 475 end 476 477 fn tx_b c uchar to void 478 n = get g_txl 0 479 if lt n 65536 480 put g_tx n c 481 put g_txl 0 add n 1 482 end 483 end 484 485 fn tx_txt t view uchar * to void 486 for i ulong len t bound 2048 487 tx_b get t i 488 end 489 end 490 491 fn tx_crlf to void 492 tx_b 13 493 tx_b 10 494 end 495 496 fn tx_u64 v ulong to void 497 buf = new uchar 24 0 498 p = ulong 24 499 n = v 500 if eq n 0 501 tx_b 48 502 ret 503 end 504 while gt n 0 bound 24 505 p = sub p 1 506 put buf p uchar add 48 rem n 10 507 n = div n 10 508 end 509 while lt p 24 bound 24 510 tx_b get buf p 511 p = add p 1 512 end 513 end 514 515 fn send_all_tx fd int to bool 516 n = get g_txl 0 517 off = ulong 0 518 while lt off n bound 100000 519 k = send fd g_tx off sub n off 16384 520 if le k 0 521 if eq k -4 522 continue 523 end 524 ret false 525 end 526 off = add off ulong k 527 end 528 ret true 529 end 530 531 fn send_all_mp fd int to bool 532 n = get g_mpl 0 533 off = ulong 0 534 while lt off n bound 100000 535 k = send fd g_mp off sub n off 16384 536 if le k 0 537 if eq k -4 538 continue 539 end 540 ret false 541 end 542 off = add off ulong k 543 end 544 ret true 545 end 546 547 fn send_all_body fd int to bool 548 n = get g_bodyl 0 549 off = ulong 0 550 while lt off n bound 20000 551 k = send fd g_body off sub n off 16384 552 if le k 0 553 if eq k -4 554 continue 555 end 556 ret false 557 end 558 off = add off ulong k 559 end 560 ret true 561 end 562 563 fn parse_rx_meta to void 564 put g_rx_hend 0 0 565 put g_rx_code 0 0 566 n = get g_rxl 0 567 if ge n 12 568 c0 = sub get g_rx 9 48 569 c1 = sub get g_rx 10 48 570 c2 = sub get g_rx 11 48 571 put g_rx_code 0 add mul add mul ulong c0 10 ulong c1 10 ulong c2 572 end 573 if ge n 4 574 for i ulong sub n 3 bound 65536 575 if eq get g_rx i 13 576 if eq get g_rx add i 1 10 577 if eq get g_rx add i 2 13 578 if eq get g_rx add i 3 10 579 put g_rx_hend 0 add i 4 580 ret 581 end 582 end 583 end 584 end 585 end 586 end 587 end 588 589 fn read_rx_all fd int to bool 590 put g_rxl 0 0 591 dl = add long monons GT_IO_TMO 592 for it ulong 100000 bound 100000 593 left = sub dl long monons 594 if le left 0 595 break 596 end 597 w = waitio fd 1 left 598 if le w 0 599 if eq w -4 600 continue 601 end 602 break 603 end 604 n = get g_rxl 0 605 if ge n 262144 606 r = recv fd g_io 0 4096 0 607 if le r 0 608 break 609 end 610 continue 611 end 612 r = recv fd g_rx n sub 262144 n 0 613 if lt r 0 614 if eq r -4 615 continue 616 end 617 break 618 end 619 if eq r 0 620 break 621 end 622 put g_rxl 0 add n ulong r 623 end 624 parse_rx_meta 625 ret gt get g_rx_hend 0 0 626 end 627 628 fn do_simple_req meth view uchar * path view uchar * to bool 629 fd = connect_hub 630 if lt fd 0 631 ret false 632 end 633 tx_reset 634 tx_txt meth 635 tx_b 32 636 tx_txt path 637 tx_txt t_http11 638 tx_crlf 639 tx_txt t_host_hdr 640 tx_crlf 641 tx_txt t_conn_hdr 642 tx_crlf 643 tx_crlf 644 ok = send_all_tx fd 645 if ok 646 ok = read_rx_all fd 647 end 648 x = fclose fd 649 ret ok 650 end 651 652 fn do_path_with_sha is_head bool pre view uchar * which ulong suf_k ulong to bool 653 fd = connect_hub 654 if lt fd 0 655 ret false 656 end 657 tx_reset 658 if is_head 659 tx_txt t_m_head_w 660 else 661 tx_txt t_m_get_w 662 end 663 tx_b 32 664 tx_txt pre 665 for i ulong 64 666 if eq which 1 667 tx_b get g_sha_a i 668 end 669 if eq which 2 670 tx_b get g_clip_sha i 671 end 672 if eq which 3 673 tx_b get g_sha_r1 i 674 end 675 end 676 if eq suf_k 1 677 tx_txt t_suf_sp 678 end 679 if eq suf_k 2 680 tx_txt t_suf_spclip 681 end 682 tx_txt t_http11 683 tx_crlf 684 tx_txt t_host_hdr 685 tx_crlf 686 tx_txt t_conn_hdr 687 tx_crlf 688 tx_crlf 689 ok = send_all_tx fd 690 if ok 691 ok = read_rx_all fd 692 end 693 x = fclose fd 694 ret ok 695 end 696 697 fn rx_match_at off ulong pat view uchar * to bool 698 for j ulong len pat bound 128 699 if ne get g_rx add off j get pat j 700 ret false 701 end 702 end 703 ret true 704 end 705 706 fn rx_body_contains pat view uchar * to bool 707 hend = get g_rx_hend 0 708 n = get g_rxl 0 709 pl = len pat 710 if or eq pl 0 gt add hend pl n 711 ret false 712 end 713 lim = add sub sub n hend pl 1 714 for i ulong lim bound 262144 715 if rx_match_at add hend i pat 716 ret true 717 end 718 end 719 ret false 720 end 721 722 fn rx_imatch_at off ulong pat view uchar * to bool 723 for j ulong len pat bound 64 724 if ne to_low get g_rx add off j get pat j 725 ret false 726 end 727 end 728 ret true 729 end 730 731 fn rx_copy_hdr_val p0 ulong pe ulong to bool 732 p = p0 733 while lt p pe bound 128 734 c = get g_rx p 735 if and ne c 32 ne c 9 736 break 737 end 738 p = add p 1 739 end 740 while lt p pe bound 128 741 c = get g_rx p 742 if or eq c 13 eq c 10 743 break 744 end 745 k = get g_hdr_vall 0 746 if lt k 128 747 put g_hdr_val k c 748 put g_hdr_vall 0 add k 1 749 end 750 p = add p 1 751 end 752 ret gt get g_hdr_vall 0 0 753 end 754 755 fn rx_hdr_extract pat view uchar * to bool 756 put g_hdr_vall 0 0 757 hend = get g_rx_hend 0 758 pl = len pat 759 i = ulong 0 760 while lt i hend bound 16384 761 ls = i 762 while lt i hend bound 16384 763 c = get g_rx i 764 i = add i 1 765 if eq c 10 766 break 767 end 768 end 769 if ge sub i ls pl 770 if rx_imatch_at ls pat 771 ret rx_copy_hdr_val add ls pl i 772 end 773 end 774 end 775 ret false 776 end 777 778 fn hdr_eq_sha_hex to bool 779 if ne get g_hdr_vall 0 64 780 ret false 781 end 782 for i ulong 64 783 if ne get g_hdr_val i get g_sh_hex i 784 ret false 785 end 786 end 787 ret true 788 end 789 790 fn hdr_eq_txt pat view uchar * to bool 791 if ne get g_hdr_vall 0 len pat 792 ret false 793 end 794 for i ulong len pat bound 128 795 if ne get g_hdr_val i get pat i 796 ret false 797 end 798 end 799 ret true 800 end 801 802 note ---- Multipart form builder helpers ---- 803 804 text t_mp_d1 "--" 805 text t_mp_cd1 "Content-Disposition: form-data; name=\"" 806 text t_mp_cd2 "\"; filename=\"" 807 text t_mp_q "\"" 808 809 fn mp_reset to void 810 put g_mpl 0 0 811 end 812 813 fn mp_b c uchar to void 814 n = get g_mpl 0 815 if lt n 65536 816 put g_mp n c 817 put g_mpl 0 add n 1 818 end 819 end 820 821 fn mp_txt t view uchar * to void 822 for i ulong len t bound 512 823 mp_b get t i 824 end 825 end 826 827 fn mp_crlf to void 828 mp_b 13 829 mp_b 10 830 end 831 832 fn mp_field k view uchar * v view uchar * to void 833 mp_txt t_mp_d1 834 mp_txt t_bnd 835 mp_crlf 836 mp_txt t_mp_cd1 837 mp_txt k 838 mp_txt t_mp_q 839 mp_crlf 840 mp_crlf 841 mp_txt v 842 mp_crlf 843 end 844 845 fn mp_field_sha k view uchar * which ulong to void 846 mp_txt t_mp_d1 847 mp_txt t_bnd 848 mp_crlf 849 mp_txt t_mp_cd1 850 mp_txt k 851 mp_txt t_mp_q 852 mp_crlf 853 mp_crlf 854 for i ulong 64 855 if eq which 0 856 mp_b get g_sh_hex i 857 else 858 mp_b get g_sha_a i 859 end 860 end 861 mp_crlf 862 end 863 864 text t_f_pack_k "pack" 865 text t_rt_up "/strands/upload" 866 867 fn mp_pack_part fnm view uchar * to void 868 mp_txt t_mp_d1 869 mp_txt t_bnd 870 mp_crlf 871 mp_txt t_mp_cd1 872 mp_txt t_f_pack_k 873 mp_txt t_mp_cd2 874 mp_txt fnm 875 mp_txt t_mp_q 876 mp_crlf 877 mp_crlf 878 n = get g_packl 0 879 for i ulong n bound 32768 880 mp_b get g_pack i 881 end 882 mp_crlf 883 mp_txt t_mp_d1 884 mp_txt t_bnd 885 mp_txt t_mp_d1 886 mp_crlf 887 end 888 889 fn post_mp_upload to bool 890 fd = connect_hub 891 if lt fd 0 892 ret false 893 end 894 tx_reset 895 tx_txt t_m_post_w 896 tx_b 32 897 tx_txt t_rt_up 898 tx_txt t_http11 899 tx_crlf 900 tx_txt t_host_hdr 901 tx_crlf 902 tx_txt t_ct_mp_hdr 903 tx_crlf 904 tx_txt t_cl_hdr 905 tx_u64 get g_mpl 0 906 tx_crlf 907 tx_txt t_conn_hdr 908 tx_crlf 909 tx_crlf 910 ok = send_all_tx fd 911 if ok 912 ok = send_all_mp fd 913 end 914 if ok 915 ok = read_rx_all fd 916 end 917 x = fclose fd 918 ret ok 919 end 920 921 fn body_reset to void 922 put g_bodyl 0 0 923 end 924 925 fn body_b c uchar to void 926 n = get g_bodyl 0 927 if lt n 16384 928 put g_body n c 929 put g_bodyl 0 add n 1 930 end 931 end 932 933 fn body_txt t view uchar * to void 934 for i ulong len t bound 512 935 body_b get t i 936 end 937 end 938 939 fn body_sha which ulong to void 940 for i ulong 64 941 if eq which 1 942 body_b get g_sha_a i 943 end 944 if eq which 2 945 body_b get g_sha_b i 946 end 947 if eq which 3 948 body_b get g_sha_c i 949 end 950 if eq which 4 951 body_b get g_sha_r1 i 952 end 953 if eq which 5 954 body_b get g_sha_r2 i 955 end 956 end 957 end 958 959 fn post_body_req path view uchar * ct view uchar * to bool 960 fd = connect_hub 961 if lt fd 0 962 ret false 963 end 964 tx_reset 965 tx_txt t_m_post_w 966 tx_b 32 967 tx_txt path 968 tx_txt t_http11 969 tx_crlf 970 tx_txt t_host_hdr 971 tx_crlf 972 tx_txt ct 973 tx_crlf 974 tx_txt t_cl_hdr 975 tx_u64 get g_bodyl 0 976 tx_crlf 977 tx_txt t_conn_hdr 978 tx_crlf 979 tx_crlf 980 ok = send_all_tx fd 981 if ok 982 ok = send_all_body fd 983 end 984 if ok 985 ok = read_rx_all fd 986 end 987 x = fclose fd 988 ret ok 989 end 990 991 note ---- Gate test cases (T01..T29) ---- 992 993 text t_p_health "/strands/health" 994 text t_p_css "/strands/hub.css" 995 text t_p_home "/strands/" 996 text t_p_itsv "/strands/index.tsv" 997 text t_p_ijson "/strands/index.json" 998 text t_p_ijson_tr "/strands/index.json?trunk=`0e513f7522e2689a`" 999 text t_p_ktsv "/strands/clips/index.tsv" 1000 text t_p_kjson "/strands/clips/index.json" 1001 text t_p_clip "/strands/clip" 1002 text t_p_cver "/strands/clip/verify" 1003 text t_p_pack_pre "/strands/pack/" 1004 text t_p_strand_pre "/strands/strand/" 1005 text t_p_clip_pre "/strands/clip/" 1006 text t_p_bad_trav "/strands/pack/../../etc/passwd.sp" 1007 text t_suf_empty "" 1008 1009 text t_k_name "name" 1010 text t_k_auth "author" 1011 text t_k_lic "license" 1012 text t_k_desc "description" 1013 text t_k_pt "parent_trunk" 1014 text t_k_exp "expected_sha256" 1015 text t_k_terms "terms" 1016 text t_k_prov "provenance" 1017 1018 text t_v_na "om2-arith-strand" 1019 text t_v_nb "om2-fold-strand" 1020 text t_v_nc "other-trunk-strand" 1021 text t_v_nd "merkle-child-l9-l10" 1022 text t_v_nbad "bad-strand" 1023 text t_v_au "drakestapleton" 1024 text t_v_au2 "community-dev" 1025 text t_v_l_ap "Apache-2.0" 1026 text t_v_l_mit "MIT" 1027 text t_v_l_cc "CC-BY-4.0" 1028 text t_v_d1 "Arith and loop specialist verified on omega-v2" 1029 text t_v_d2 "Constant folding specialist on same base trunk" 1030 text t_v_d3 "Different trunk specialist" 1031 text t_v_d4 "Child Merkle link chained atop om2-arith-strand" 1032 text t_v_bh_a "`0e513f7522e2689a`" 1033 text t_v_bh_wrong "deadbeefcafebabe" 1034 text t_v_pt_ck "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 1035 text t_v_prov1 "omega-mv:commit-test-receipt" 1036 text t_v_fn_a "arith_a.sp" 1037 text t_v_fn_b "fold_b.sp" 1038 text t_v_fn_c "other_c.sp" 1039 text t_v_fn_d "child_d.sp" 1040 text t_v_fn_evil "../../../etc/passwd" 1041 1042 text t_s_ok "ok\n" 1043 text t_s_css ".hub-hero" 1044 text t_s_script "alert(1)" 1121 text t_v_xss_d "quote \" slash \\ tab\tline" 1122 text t_v_fn_xss "xss_safe.sp" 1123 text t_s_esc_lt "<script>" 1124 text t_s_jesc_q "\\\"" 1125 text t_cf_s3 "&s3=" 1126 text t_cf_s4 "&s4=" 1127 text t_cf_p3 "&w1=1000&w2=0&w3=700&w4=500&mode=1&tau=600&clip_name=tri-helix&author=drake&license=Apache-2.0&action=download" 1128 text t_s_sc3 "strand_count=3" 1129 1130 fn verify_count_still_4 to bool 1131 if not do_simple_req t_m_get_w t_p_ijson 1132 ret false 1133 end 1134 ret and eq get g_rx_code 0 200 rx_body_contains t_s_c4 1135 end 1136 1137 fn run_basics_and_uploads to void 1138 ok = do_simple_req t_m_get_w t_p_health 1139 chk and ok and eq get g_rx_code 0 200 rx_body_contains t_s_ok t_t01 1140 1141 ok = do_simple_req t_m_get_w t_p_css 1142 chk and ok and eq get g_rx_code 0 200 and rx_body_contains t_s_css not rx_body_contains t_s_script t_t02 1143 1144 ok = do_simple_req t_m_get_w t_p_home 1145 chk and ok and eq get g_rx_code 0 200 and rx_body_contains t_s_hero and rx_body_contains t_s_magic not rx_body_contains t_s_script t_t03 1146 1147 ok1 = do_simple_req t_m_get_w t_p_ijson 1148 c1 = and ok1 and eq get g_rx_code 0 200 rx_body_contains t_s_c0 1149 ok2 = do_simple_req t_m_get_w t_p_itsv 1150 c2 = and ok2 eq get g_rx_code 0 200 1151 chk and c1 c2 t_t04 1152 1153 note T05: Strand A on trunk 0x0e513f7522e2689a, L8->L9, 32 params (304 bytes) 1154 build_valid_pack 8 9 0x0e513f7522e2689a 32 100 1155 for i ulong get g_packl 0 bound 1024 1156 put g_orig_a i get g_pack i 1157 end 1158 put g_orig_al 0 get g_packl 0 1159 sha_pack 1160 for i ulong 64 1161 put g_sha_a i get g_sh_hex i 1162 end 1163 mp_reset 1164 mp_field t_k_name t_v_na 1165 mp_field t_k_auth t_v_au 1166 mp_field t_k_lic t_v_l_ap 1167 mp_field t_k_desc t_v_d1 1168 mp_field t_k_pt t_v_pt_ck 1169 mp_field t_k_prov t_v_prov1 1170 mp_field_sha t_k_exp 0 1171 mp_pack_part t_v_fn_a 1172 ok = post_mp_upload 1173 h1 = and rx_hdr_extract t_xsha_h hdr_eq_sha_hex 1174 h2 = and rx_hdr_extract t_xbh_h hdr_eq_txt t_v_bh_a 1175 chk and ok and eq get g_rx_code 0 201 and h1 h2 t_t05 1176 1177 note T06: Strand B on SAME trunk 0x0e513f7522e2689a, L8->L10, 48 params 1178 build_valid_pack 8 10 0x0e513f7522e2689a 48 200 1179 sha_pack 1180 for i ulong 64 1181 put g_sha_b i get g_sh_hex i 1182 end 1183 mp_reset 1184 mp_field t_k_name t_v_nb 1185 mp_field t_k_auth t_v_au2 1186 mp_field t_k_lic t_v_l_mit 1187 mp_field t_k_desc t_v_d2 1188 mp_field t_k_pt t_v_pt_ck 1189 mp_pack_part t_v_fn_b 1190 ok = post_mp_upload 1191 h1 = and rx_hdr_extract t_xsha_h hdr_eq_sha_hex 1192 chk and ok and eq get g_rx_code 0 201 h1 t_t06 1193 1194 note T07: Strand C on DIFFERENT trunk 0x1122334455667788, L4->L5, 16 params 1195 build_valid_pack 4 5 0x1122334455667788 16 300 1196 sha_pack 1197 for i ulong 64 1198 put g_sha_c i get g_sh_hex i 1199 end 1200 mp_reset 1201 mp_field t_k_name t_v_nc 1202 mp_field t_k_auth t_v_au2 1203 mp_field t_k_lic t_v_l_cc 1204 mp_field t_k_desc t_v_d3 1205 mp_pack_part t_v_fn_c 1206 ok = post_mp_upload 1207 h1 = and rx_hdr_extract t_xsha_h hdr_eq_sha_hex 1208 chk and ok and eq get g_rx_code 0 201 h1 t_t07 1209 1210 note T08: Merkle child Strand D (L9->L10) chained onto Strand A (spec_L=9) 1211 build_valid_pack 9 10 0x9988776655443322 20 400 1212 sha_pack 1213 for i ulong 64 1214 put g_sha_d i get g_sh_hex i 1215 end 1216 mp_reset 1217 mp_field t_k_name t_v_nd 1218 mp_field t_k_auth t_v_au 1219 mp_field t_k_lic t_v_l_ap 1220 mp_field t_k_desc t_v_d4 1221 mp_field_sha t_k_pt 1 1222 mp_pack_part t_v_fn_d 1223 ok = post_mp_upload 1224 h1 = and rx_hdr_extract t_xsha_h hdr_eq_sha_hex 1225 chk and ok and eq get g_rx_code 0 201 h1 t_t08 1226 end 1227 1228 fn run_download_parity to void 1229 ok = do_path_with_sha false t_p_pack_pre 1 1 1230 hend = get g_rx_hend 0 1231 blen = sub get g_rxl 0 hend 1232 eq_bytes = and ok and eq get g_rx_code 0 200 eq blen get g_orig_al 0 1233 if eq_bytes 1234 for i ulong blen bound 1024 1235 if ne get g_rx add hend i get g_orig_a i 1236 eq_bytes = false 1237 break 1238 end 1239 end 1240 end 1241 ok2 = do_simple_req t_m_get_w t_p_ijson_tr 1242 chk and eq_bytes and ok2 rx_body_contains t_s_dl1 t_t09c 1243 end 1244 1245 fn run_catalog_and_download to void 1246 ok1 = verify_count_still_4 1247 ok2 = do_simple_req t_m_get_w t_p_ijson_tr 1248 c2 = and ok2 and eq get g_rx_code 0 200 rx_body_contains t_s_c2 1249 chk and ok1 c2 t_t09a 1250 1251 ok1 = do_path_with_sha false t_p_strand_pre 1 0 1252 c1 = and ok1 and eq get g_rx_code 0 200 rx_body_contains t_s_spclip_cmd 1253 ok2 = do_path_with_sha true t_p_pack_pre 1 1 1254 c2 = and ok2 eq get g_rx_code 0 200 1255 ok3 = do_simple_req t_m_get_w t_p_ijson_tr 1256 c3 = and ok3 rx_body_contains t_s_dl0 1257 chk and c1 and c2 c3 t_t09b 1258 run_download_parity 1259 end 1260 1261 fn run_neg_upload_controls_1 to void 1262 note T10: Duplicate SHA-256 -> 409 Conflict 1263 build_valid_pack 8 9 0x0e513f7522e2689a 32 100 1264 mp_reset 1265 mp_field t_k_name t_v_na 1266 mp_field t_k_auth t_v_au 1267 mp_pack_part t_v_fn_a 1268 ok = post_mp_upload 1269 chk and ok and eq get g_rx_code 0 409 verify_count_still_4 t_t10 1270 1271 note T11: Forged magic -> 400 1272 build_valid_pack 8 9 0x0e513f7522e2689a 16 501 1273 put g_pack 0 88 1274 mp_reset 1275 mp_field t_k_name t_v_nbad 1276 mp_field t_k_auth t_v_au 1277 mp_pack_part t_v_fn_a 1278 ok = post_mp_upload 1279 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t11 1280 1281 note T12: Truncated header (32 bytes) -> 400 1282 build_valid_pack 8 9 0x0e513f7522e2689a 16 502 1283 put g_packl 0 32 1284 mp_reset 1285 mp_field t_k_name t_v_nbad 1286 mp_field t_k_auth t_v_au 1287 mp_pack_part t_v_fn_a 1288 ok = post_mp_upload 1289 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t12 1290 1291 note T13: Truncated payload (8 bytes short) -> 400 1292 build_valid_pack 8 9 0x0e513f7522e2689a 16 503 1293 put g_packl 0 sub get g_packl 0 8 1294 mp_reset 1295 mp_field t_k_name t_v_nbad 1296 mp_field t_k_auth t_v_au 1297 mp_pack_part t_v_fn_a 1298 ok = post_mp_upload 1299 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t13 1300 1301 note T14: Trailing garbage byte (+1 byte) -> 400 1302 build_valid_pack 8 9 0x0e513f7522e2689a 16 504 1303 pl = get g_packl 0 1304 put g_pack pl 99 1305 put g_packl 0 add pl 1 1306 mp_reset 1307 mp_field t_k_name t_v_nbad 1308 mp_field t_k_auth t_v_au 1309 mp_pack_part t_v_fn_a 1310 ok = post_mp_upload 1311 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t14 1312 1313 note T15: 1-bit payload tamper (FNV-1a pack_hash mismatch) -> 400 1314 build_valid_pack 8 9 0x0e513f7522e2689a 16 505 1315 put g_pack 48 xor get g_pack 48 1 1316 mp_reset 1317 mp_field t_k_name t_v_nbad 1318 mp_field t_k_auth t_v_au 1319 mp_pack_part t_v_fn_a 1320 ok = post_mp_upload 1321 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t15 1322 1323 note T16: Non-finite NaN f64 weight (with valid recomputed FNV-1a!) -> 400 1324 build_valid_pack 8 9 0x0e513f7522e2689a 16 506 1325 put_u64_le_pack 48 0x7ff8000000000000 1326 recompute_pack_fnv 1327 mp_reset 1328 mp_field t_k_name t_v_nbad 1329 mp_field t_k_auth t_v_au 1330 mp_pack_part t_v_fn_a 1331 ok = post_mp_upload 1332 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t16 1333 end 1334 1335 text t_te_hdr "Transfer-Encoding: chunked" 1336 text t_fake_big_cl "Content-Length: `999999999`" 1337 1338 fn run_neg_upload_controls_2 to void 1339 note T17a: 16-hex parent_trunk disagrees with binary base_hash -> 400 1340 build_valid_pack 8 9 0x0e513f7522e2689a 16 507 1341 mp_reset 1342 mp_field t_k_name t_v_nbad 1343 mp_field t_k_auth t_v_au 1344 mp_field t_k_pt t_v_bh_wrong 1345 mp_pack_part t_v_fn_a 1346 ok = post_mp_upload 1347 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t17a 1348 1349 note T17b: 64-hex parent_trunk = Strand A (spec_L=9) but child has base_L=7 -> 400 1350 build_valid_pack 7 8 0x554433221100aabb 16 508 1351 mp_reset 1352 mp_field t_k_name t_v_nbad 1353 mp_field t_k_auth t_v_au 1354 mp_field_sha t_k_pt 1 1355 mp_pack_part t_v_fn_a 1356 ok = post_mp_upload 1357 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t17b 1358 1359 note T18: expected_sha256 mismatch -> 400 1360 build_valid_pack 8 9 0x0e513f7522e2689a 16 509 1361 sha_pack 1362 if eq get g_sh_hex 0 97 1363 put g_sh_hex 0 98 1364 else 1365 put g_sh_hex 0 97 1366 end 1367 mp_reset 1368 mp_field t_k_name t_v_nbad 1369 mp_field t_k_auth t_v_au 1370 mp_field_sha t_k_exp 0 1371 mp_pack_part t_v_fn_a 1372 ok = post_mp_upload 1373 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t18 1374 1375 note T19a: Path-traversal upload filename ../../../etc/passwd -> 400 1376 build_valid_pack 8 9 0x0e513f7522e2689a 16 510 1377 mp_reset 1378 mp_field t_k_name t_v_nbad 1379 mp_field t_k_auth t_v_au 1380 mp_pack_part t_v_fn_evil 1381 ok = post_mp_upload 1382 chk and ok and eq get g_rx_code 0 400 verify_count_still_4 t_t19a 1383 1384 note T19b: Path-traversal download URL -> 400 1385 ok = do_simple_req t_m_get_w t_p_bad_trav 1386 chk and ok eq get g_rx_code 0 400 t_t19b 1387 1388 note T20a: Oversized pack (2500 params = 20048 bytes > 16384 Phase-A cap) -> 413 1389 build_valid_pack 8 9 0x0e513f7522e2689a 2500 511 1390 mp_reset 1391 mp_field t_k_name t_v_nbad 1392 mp_field t_k_auth t_v_au 1393 mp_pack_part t_v_fn_a 1394 ok = post_mp_upload 1395 chk and ok and eq get g_rx_code 0 413 verify_count_still_4 t_t20a 1396 1397 note T20b: Oversized Content-Length header rejected immediately -> 413 1398 fd = connect_hub 1399 ok = false 1400 if ge fd 0 1401 tx_reset 1402 tx_txt t_m_post_w 1403 tx_b 32 1404 tx_txt t_rt_up 1405 tx_txt t_http11 1406 tx_crlf 1407 tx_txt t_host_hdr 1408 tx_crlf 1409 tx_txt t_ct_mp_hdr 1410 tx_crlf 1411 tx_txt t_fake_big_cl 1412 tx_crlf 1413 tx_txt t_conn_hdr 1414 tx_crlf 1415 tx_crlf 1416 ok = send_all_tx fd 1417 if ok 1418 ok = read_rx_all fd 1419 end 1420 x = fclose fd 1421 end 1422 chk and ok eq get g_rx_code 0 413 t_t20b 1423 1424 note T21a: Missing Content-Length on POST -> 411 1425 fd = connect_hub 1426 ok = false 1427 if ge fd 0 1428 tx_reset 1429 tx_txt t_m_post_w 1430 tx_b 32 1431 tx_txt t_rt_up 1432 tx_txt t_http11 1433 tx_crlf 1434 tx_txt t_host_hdr 1435 tx_crlf 1436 tx_txt t_ct_mp_hdr 1437 tx_crlf 1438 tx_txt t_conn_hdr 1439 tx_crlf 1440 tx_crlf 1441 ok = send_all_tx fd 1442 if ok 1443 ok = read_rx_all fd 1444 end 1445 x = fclose fd 1446 end 1447 chk and ok eq get g_rx_code 0 411 t_t21a 1448 1449 note T21b: Transfer-Encoding chunked smuggling refused -> 400 1450 fd = connect_hub 1451 ok = false 1452 if ge fd 0 1453 tx_reset 1454 tx_txt t_m_post_w 1455 tx_b 32 1456 tx_txt t_rt_up 1457 tx_txt t_http11 1458 tx_crlf 1459 tx_txt t_host_hdr 1460 tx_crlf 1461 tx_txt t_ct_mp_hdr 1462 tx_crlf 1463 tx_txt t_te_hdr 1464 tx_crlf 1465 tx_txt t_cl_hdr 1466 tx_u64 10 1467 tx_crlf 1468 tx_txt t_conn_hdr 1469 tx_crlf 1470 tx_crlf 1471 ok = send_all_tx fd 1472 if ok 1473 ok = read_rx_all fd 1474 end 1475 x = fclose fd 1476 end 1477 chk and ok eq get g_rx_code 0 400 t_t21b 1478 end 1479 1480 note ---- Strand Clip Editor & .spclip validator tests (T22..T27) ---- 1481 1482 text t_cf_s1 "s1=" 1483 text t_cf_s2 "&s2=" 1484 text t_cf_p1 "&w1=1200&w2=800&mode=1&tau=650&splice_layer=8&tokens=128&ft_seed=42&ft_steps=150&ft_lr_micro=3500&clip_name=arith-fold-mix&author=drake&license=Apache-2.0&action=save" 1485 text t_cf_p2 "&w1=1000&w2=-500&mode=0&tau=500&splice_layer=8&tokens=64&clip_name=anti-dna-poe&author=drake&license=MIT&action=download" 1486 text t_cf_incompat "&w1=1000&w2=1000&mode=1&tau=700&action=save" 1487 text t_cf_w0 "&w1=1000&w2=0&mode=1&tau=700&action=save" 1488 text t_cf_wneg_m1 "&w1=1000&w2=-500&mode=1&tau=700&action=save" 1489 text t_cf_wall_neg "&w1=-500&w2=-500&mode=0&tau=700&action=save" 1490 text t_cf_s1only "&w1=1000&mode=1&tau=700&action=save" 1491 text t_cf_badmode "&w1=1000&w2=1000&mode=9&tau=700&action=save" 1492 text t_cf_badsplice "&w1=1000&w2=1000&mode=1&tau=700&splice_layer=99&action=save" 1493 1494 fn run_clip_tests to void 1495 ok = do_simple_req t_m_get_w t_p_clip 1496 chk and ok and eq get g_rx_code 0 200 not rx_body_contains t_s_script t_t22a 1497 1498 note T22b: Compose 2-strand compatible clip (A + B) 1499 body_reset 1500 body_txt t_cf_s1 1501 body_sha 1 1502 body_txt t_cf_s2 1503 body_sha 2 1504 body_txt t_cf_p1 1505 ok = post_body_req t_p_clip t_ct_form_hdr 1506 has_k = rx_hdr_extract t_xksha_h 1507 if and has_k eq get g_hdr_vall 0 64 1508 for i ulong 64 1509 put g_clip_sha i get g_hdr_val i 1510 end 1511 end 1512 chk and ok and eq get g_rx_code 0 201 and has_k and rx_body_contains t_s_spclip_m1 and rx_body_contains t_s_w1200 rx_body_contains t_s_w800 t_t22b 1513 1514 note T22c: Download .spclip manifest and verify via POST /strands/clip/verify 1515 ok = do_path_with_sha false t_p_clip_pre 2 2 1516 hend = get g_rx_hend 0 1517 mlen = sub get g_rxl 0 hend 1518 c1 = and ok and eq get g_rx_code 0 200 and rx_body_contains t_s_mf01 rx_body_contains t_s_bsha_k 1519 if and c1 le mlen 16384 1520 for i ulong mlen bound 16384 1521 put g_clip_man i get g_rx add hend i 1522 end 1523 put g_clip_manl 0 mlen 1524 end 1525 body_reset 1526 for i ulong get g_clip_manl 0 bound 16384 1527 body_b get g_clip_man i 1528 end 1529 ok2 = post_body_req t_p_cver t_ct_txt_hdr 1530 c2 = and ok2 and eq get g_rx_code 0 200 rx_body_contains t_s_vtrue 1531 ok3 = do_simple_req t_m_get_w t_p_kjson 1532 c3 = and ok3 and eq get g_rx_code 0 200 rx_body_contains t_s_c1 1533 chk and c1 and c2 c3 t_t22c 1534 1535 note T23: Anti-DNA signed PoE clip (MODE=0, w1=1000, w2=-500) direct download + verify 1536 body_reset 1537 body_txt t_cf_s1 1538 body_sha 1 1539 body_txt t_cf_s2 1540 body_sha 2 1541 body_txt t_cf_p2 1542 ok = post_body_req t_p_clip t_ct_form_hdr 1543 hend = get g_rx_hend 0 1544 mlen = sub get g_rxl 0 hend 1545 c1 = and ok and eq get g_rx_code 0 200 and rx_body_contains t_s_m0 rx_body_contains t_s_wneg 1546 body_reset 1547 if le mlen 16384 1548 for i ulong mlen bound 16384 1549 body_b get g_rx add hend i 1550 end 1551 end 1552 ok2 = post_body_req t_p_cver t_ct_txt_hdr 1553 chk and c1 and ok2 and eq get g_rx_code 0 200 rx_body_contains t_s_vtrue t_t23 1554 end 1555 1556 fn run_clip_neg_tests to void 1557 note T24: NEGATIVE CONTROL - Incompatible parent trunks (Strand A + Strand C) -> 400 1558 body_reset 1559 body_txt t_cf_s1 1560 body_sha 1 1561 body_txt t_cf_s2 1562 body_sha 3 1563 body_txt t_cf_incompat 1564 ok = post_body_req t_p_clip t_ct_form_hdr 1565 chk and ok and eq get g_rx_code 0 400 rx_body_contains t_s_c3 t_t24 1566 1567 note T25a: NEGATIVE CONTROL - Zero weight w2=0 -> 400 1568 body_reset 1569 body_txt t_cf_s1 1570 body_sha 1 1571 body_txt t_cf_s2 1572 body_sha 2 1573 body_txt t_cf_w0 1574 ok = post_body_req t_p_clip t_ct_form_hdr 1575 chk and ok and eq get g_rx_code 0 400 rx_body_contains t_s_c4_err t_t25a 1576 1577 note T25b: NEGATIVE CONTROL - Negative weight in MODE=1 Entropy Gate -> 400 1578 body_reset 1579 body_txt t_cf_s1 1580 body_sha 1 1581 body_txt t_cf_s2 1582 body_sha 2 1583 body_txt t_cf_wneg_m1 1584 ok = post_body_req t_p_clip t_ct_form_hdr 1585 chk and ok and eq get g_rx_code 0 400 rx_body_contains t_s_c4_err t_t25b 1586 1587 note T25c: NEGATIVE CONTROL - All-negative weights in MODE=0 PoE -> 400 1588 body_reset 1589 body_txt t_cf_s1 1590 body_sha 1 1591 body_txt t_cf_s2 1592 body_sha 2 1593 body_txt t_cf_wall_neg 1594 ok = post_body_req t_p_clip t_ct_form_hdr 1595 chk and ok and eq get g_rx_code 0 400 rx_body_contains t_s_c4_err t_t25c 1596 1597 note T26a: NEGATIVE CONTROL - Single strand S=1 -> 400 1598 body_reset 1599 body_txt t_cf_s1 1600 body_sha 1 1601 body_txt t_cf_s1only 1602 ok = post_body_req t_p_clip t_ct_form_hdr 1603 chk and ok eq get g_rx_code 0 400 t_t26a 1604 1605 note T26b: NEGATIVE CONTROL - Invalid mode=9 and splice_layer=99 -> 400 1606 body_reset 1607 body_txt t_cf_s1 1608 body_sha 1 1609 body_txt t_cf_s2 1610 body_sha 2 1611 body_txt t_cf_badmode 1612 ok1 = post_body_req t_p_clip t_ct_form_hdr 1613 c1 = and ok1 eq get g_rx_code 0 400 1614 body_reset 1615 body_txt t_cf_s1 1616 body_sha 1 1617 body_txt t_cf_s2 1618 body_sha 2 1619 body_txt t_cf_badsplice 1620 ok2 = post_body_req t_p_clip t_ct_form_hdr 1621 c2 = and ok2 eq get g_rx_code 0 400 1622 chk and c1 c2 t_t26b 1623 1624 note T27: NEGATIVE CONTROL - 1-byte tampered .spclip manifest -> 400 error_code=9 1625 body_reset 1626 ml = get g_clip_manl 0 1627 for i ulong ml bound 16384 1628 c = get g_clip_man i 1629 if eq i 25 1630 c = xor c 1 1631 end 1632 body_b c 1633 end 1634 ok = post_body_req t_p_cver t_ct_txt_hdr 1635 chk and ok and eq get g_rx_code 0 400 and rx_body_contains t_s_vfalse rx_body_contains t_s_ec9 t_t27 1636 end 1637 1638 note ---- Phase B: Restart persistence + Optional real 14MB GB10 .sp streaming test ---- 1639 1640 text t_xh_n1 "X-Strand-Name: gb10-real-arith" 1641 text t_xh_n2 "X-Strand-Name: gb10-real-fold" 1642 text t_xh_au "X-Strand-Author: spark-gb10" 1643 text t_xh_lic "X-Strand-License: Apache-2.0" 1644 text t_xh_fn1 "X-Strand-Filename: S1_arith.sp" 1645 text t_xh_fn2 "X-Strand-Filename: S2_fold.sp" 1646 text t_xh_d1 "X-Strand-Description: Real GB10-trained OLLMSP01 specialist pack" 1647 1648 fn stream_upload_real_file which ulong to bool 1649 ffd = long -1 1650 if eq which 1 1651 ffd = fopen g_rsp1 0 get g_rsp1l 0 0 0 1652 else 1653 ffd = fopen g_rsp2 0 get g_rsp2l 0 0 0 1654 end 1655 if lt ffd 0 1656 ret false 1657 end 1658 fsz = fseek int ffd 0 2 1659 if le fsz 48 1660 x = fclose int ffd 1661 ret false 1662 end 1663 x = fseek int ffd 0 0 1664 sha_start 1665 fd = connect_hub 1666 if lt fd 0 1667 x = fclose int ffd 1668 ret false 1669 end 1670 tx_reset 1671 tx_txt t_m_post_w 1672 tx_b 32 1673 tx_txt t_rt_up 1674 tx_txt t_http11 1675 tx_crlf 1676 tx_txt t_host_hdr 1677 tx_crlf 1678 tx_txt t_ct_oct_hdr 1679 tx_crlf 1680 if eq which 1 1681 tx_txt t_xh_n1 1682 tx_crlf 1683 tx_txt t_xh_fn1 1684 tx_crlf 1685 else 1686 tx_txt t_xh_n2 1687 tx_crlf 1688 tx_txt t_xh_fn2 1689 tx_crlf 1690 end 1691 tx_txt t_xh_au 1692 tx_crlf 1693 tx_txt t_xh_lic 1694 tx_crlf 1695 tx_txt t_xh_d1 1696 tx_crlf 1697 tx_txt t_cl_hdr 1698 tx_u64 ulong fsz 1699 tx_crlf 1700 tx_txt t_conn_hdr 1701 tx_crlf 1702 tx_crlf 1703 ok = send_all_tx fd 1704 done = ulong 0 1705 tot = ulong fsz 1706 while and ok lt done tot bound 50000 1707 r = read int ffd g_io 0 65536 1708 if le r 0 1709 ok = false 1710 break 1711 end 1712 for i ulong ulong r bound 65536 1713 sha_b get g_io i 1714 end 1715 p = ulong 0 1716 while lt p ulong r bound 20000 1717 w = send fd g_io p sub ulong r p 16384 1718 if le w 0 1719 if eq w -4 1720 continue 1721 end 1722 ok = false 1723 break 1724 end 1725 p = add p ulong w 1726 end 1727 done = add done ulong r 1728 end 1729 x = fclose int ffd 1730 sha_finish 1731 if ok 1732 ok = read_rx_all fd 1733 end 1734 x = fclose fd 1735 if not ok 1736 ret false 1737 end 1738 if ne get g_rx_code 0 201 1739 ret false 1740 end 1741 if not rx_hdr_extract t_xsha_h 1742 ret false 1743 end 1744 if not hdr_eq_sha_hex 1745 ret false 1746 end 1747 for i ulong 64 1748 if eq which 1 1749 put g_sha_r1 i get g_sh_hex i 1750 else 1751 put g_sha_r2 i get g_sh_hex i 1752 end 1753 end 1754 ret true 1755 end 1756 1757 fn stream_verify_download_real1 to bool 1758 fd = connect_hub 1759 if lt fd 0 1760 ret false 1761 end 1762 tx_reset 1763 tx_txt t_m_get_w 1764 tx_b 32 1765 tx_txt t_p_pack_pre 1766 for i ulong 64 1767 tx_b get g_sha_r1 i 1768 end 1769 tx_txt t_suf_sp 1770 tx_txt t_http11 1771 tx_crlf 1772 tx_txt t_host_hdr 1773 tx_crlf 1774 tx_txt t_conn_hdr 1775 tx_crlf 1776 tx_crlf 1777 if not send_all_tx fd 1778 x = fclose fd 1779 ret false 1780 end 1781 put g_rxl 0 0 1782 hend = ulong 0 1783 sha_start 1784 tot_body = ulong 0 1785 for it ulong 200000 bound 200000 1786 r = recv fd g_io 0 65536 0 1787 if lt r 0 1788 if eq r -4 1789 continue 1790 end 1791 break 1792 end 1793 if eq r 0 1794 break 1795 end 1796 if eq hend 0 1797 for i ulong ulong r bound 65536 1798 rn = get g_rxl 0 1799 if lt rn 262144 1800 put g_rx rn get g_io i 1801 put g_rxl 0 add rn 1 1802 end 1803 end 1804 parse_rx_meta 1805 hend = get g_rx_hend 0 1806 if gt hend 0 1807 rn = get g_rxl 0 1808 if gt rn hend 1809 for i ulong sub rn hend bound 262144 1810 sha_b get g_rx add hend i 1811 end 1812 tot_body = add tot_body sub rn hend 1813 end 1814 end 1815 else 1816 for i ulong ulong r bound 65536 1817 sha_b get g_io i 1818 end 1819 tot_body = add tot_body ulong r 1820 end 1821 end 1822 x = fclose fd 1823 sha_finish 1824 if or ne get g_rx_code 0 200 eq tot_body 0 1825 ret false 1826 end 1827 for i ulong 64 1828 if ne get g_sh_hex i get g_sha_r1 i 1829 ret false 1830 end 1831 end 1832 ret true 1833 end 1834 1835 fn run_phase_b to void 1836 stop_server 1837 if not start_server `33554432` 1838 chk false t_t28 1839 ret 1840 end 1841 ok1 = do_simple_req t_m_get_w t_p_ijson 1842 c1 = and ok1 and eq get g_rx_code 0 200 and rx_body_contains t_s_c4 rx_body_contains t_s_dl1 1843 ok2 = do_simple_req t_m_get_w t_p_kjson 1844 c2 = and ok2 and eq get g_rx_code 0 200 rx_body_contains t_s_c2 1845 chk and c1 c2 t_t28 1846 1847 if gt get g_rsp1l 0 0 1848 ok_u1 = stream_upload_real_file 1 1849 chk ok_u1 t_t29a 1850 ok_d1 = false 1851 if ok_u1 1852 ok_d1 = stream_verify_download_real1 1853 end 1854 chk ok_d1 t_t29b 1855 if and ok_u1 gt get g_rsp2l 0 0 1856 ok_u2 = stream_upload_real_file 2 1857 ok_clip = false 1858 if ok_u2 1859 body_reset 1860 body_txt t_cf_s1 1861 body_sha 4 1862 body_txt t_cf_s2 1863 body_sha 5 1864 body_txt t_cf_p1 1865 if post_body_req t_p_clip t_ct_form_hdr 1866 if eq get g_rx_code 0 201 1867 ok_clip = true 1868 end 1869 end 1870 end 1871 chk ok_clip t_t29c 1872 end 1873 end 1874 end 1875 1876 fn run_xss_test to void 1877 note T30: XSS and JSON/TSV injection escaping on metadata 1878 build_valid_pack 8 9 0x0e513f7522e2689a 16 777 1879 mp_reset 1880 mp_field t_k_name t_v_xss_n 1881 mp_field t_k_auth t_v_au 1882 mp_field t_k_desc t_v_xss_d 1883 mp_pack_part t_v_fn_xss 1884 ok_up = post_mp_upload 1885 c_up = and ok_up eq get g_rx_code 0 201 1886 ok_hm = do_simple_req t_m_get_w t_p_home 1887 c_hm = and ok_hm and rx_body_contains t_s_esc_lt not rx_body_contains t_s_script 1888 ok_js = do_simple_req t_m_get_w t_p_ijson 1889 c_js = and ok_js and eq get g_rx_code 0 200 rx_body_contains t_s_jesc_q 1890 chk and c_up and c_hm c_js t_t30 1891 end 1892 1893 fn run_trihelix_test to void 1894 note T31: 3-strand clip with non-contiguous slots (s1, empty s2 with w2=0, s3, s4) -> S=3 verify 1895 body_reset 1896 body_txt t_cf_s1 1897 body_sha 1 1898 body_txt t_cf_s2 1899 body_txt t_cf_s3 1900 body_sha 2 1901 body_txt t_cf_s4 1902 body_sha 1 1903 body_txt t_cf_p3 1904 ok_c3 = post_body_req t_p_clip t_ct_form_hdr 1905 hend = get g_rx_hend 0 1906 mlen = sub get g_rxl 0 hend 1907 c_c3 = and ok_c3 and eq get g_rx_code 0 200 rx_body_contains t_s_sc3 1908 body_reset 1909 if le mlen 16384 1910 for i ulong mlen bound 16384 1911 body_b get g_rx add hend i 1912 end 1913 end 1914 ok_v3 = post_body_req t_p_cver t_ct_txt_hdr 1915 chk and c_c3 and ok_v3 and eq get g_rx_code 0 200 rx_body_contains t_s_vtrue t_t31 1916 end 1917 1918 text t_none_hdr "-" 1919 text t_xh_ld_pre "X-Strand-Description: " 1920 text t_xh_pt_b "X-Strand-Parent-Trunk: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" 1921 text t_xh_sha_pre "X-Strand-SHA256: " 1922 text t_xh_garb "GARBAGE" 1923 text t_xh_dotdot "X-Strand-Name: .." 1924 text t_xh_n_e1 "X-Strand-Name: pt-empty-s" 1925 text t_xh_n_e2 "X-Strand-Name: pt-bbb-s" 1926 text t_xh_n_ch "X-Strand-Name: tuned-child-clip" 1927 text t_xh_n_tr "X-Strand-Name: trunk-stress" 1928 text t_xh_prov_pre "X-Strand-Provenance: spclip:" 1929 text t_mp_cd_alt "Content-Disposition: form-data; name=\"pack\"; altname=\"oops\"; filename=\"alt_ok.sp\"" 1930 text t_s_fn_strand "filename=\"strand.sp\"" 1931 text t_s_div_sum "
" 1932 text t_s_strands_arr "\"strands\":[" 1933 text t_p_kjson_none "/strands/clips/index.json?trunk=ffffffffffffffff" 1934 text t_s_spmerge_w "spmerge BASE.ck" 1935 text t_cf_badft "&w1=1000&w2=1000&mode=1&tau=700&ft_steps=bogus&action=save" 1936 text t_cf_pw3 "&w1=1000&w2=1000&w3=1000&mode=1&tau=700&action=save" 1937 text t_cf_anti_s "&w1=1000&w2=-500&mode=0&tau=500&ft_steps=20&license=MIT&action=save" 1938 text t_m_bad_z "format=OMSPCLIP01\nmode=`0000000000000000000000000`\nbody_sha256=`0000000000000000000000000000000000000000000000000000000000000000`\n" 1939 text t_m_f_hdr1 "format=OMSPCLIP01GARBAGE\nname=f\nauthor=e\nlicense=MIT\nbase_hash=`0e513f7522e2689a`\nparent_trunk=\nsplice_layer=8\nmode=1\ntau_milli=700\ntokens=64\nft_seed=1\nft_steps=0\nft_lr_micro=0\nstrand_count=2\nstrand.1.sha256=" 1940 text t_m_f_hdr2 "format=OMSPCLIP01\nname=f\nauthor=e\nlicense=MIT\nbase_hash=`0e513f7522e2689a`\nparent_trunk=\nsplice_layer=0\nmode=1\ntau_milli=700\ntokens=64\nft_seed=1\nft_steps=0\nft_lr_micro=0\nstrand_count=2\nstrand.1.sha256=" 1941 text t_m_f_hdr3 "format=OMSPCLIP01\nname=f\nauthor=e\nlicense=MIT\nbase_hash=`0e513f7522e2689a`\nparent_trunk=\nsplice_layer=8\nmode=1\ntau_milli=700\ntokens=64\nft_seed=1\nft_steps=0\nft_lr_micro=0\nstrand_count=2\nstrand.1.sha256=" 1942 text t_m_f_m1 "\nstrand.1.base_hash=`0e513f7522e2689a`\nstrand.1.base_l=8\nstrand.1.spec_l=9\nstrand.1.weight_milli=1000\nstrand.1.filename=a.sp\nstrand.2.sha256=" 1943 text t_m_f_mbad "\nstrand.1.base_hash=deadbeefdeadbeef\nstrand.1.base_l=8\nstrand.1.spec_l=9\nstrand.1.weight_milli=1000\nstrand.1.filename=a.sp\nstrand.2.sha256=" 1944 text t_m_f_m2 "\nstrand.2.base_hash=`0e513f7522e2689a`\nstrand.2.base_l=8\nstrand.2.spec_l=10\nstrand.2.weight_milli=1000\nstrand.2.filename=b.sp\n" 1945 text t_m_f_bsha "body_sha256=" 1946 1947 fn send_raw_tx_and_read to bool 1948 fd = connect_hub 1949 if lt fd 0 1950 ret false 1951 end 1952 ok = send_all_tx fd 1953 if ok 1954 ok = read_rx_all fd 1955 end 1956 x = fclose fd 1957 ret ok 1958 end 1959 1960 fn send_oct_pack_with_hdrs extra1 view uchar * extra2 view uchar * with_garb_sha bool with_clip_prov bool to bool 1961 fd = connect_hub 1962 if lt fd 0 1963 ret false 1964 end 1965 tx_reset 1966 tx_txt t_m_post_w 1967 tx_b 32 1968 tx_txt t_rt_up 1969 tx_txt t_http11 1970 tx_crlf 1971 tx_txt t_host_hdr 1972 tx_crlf 1973 tx_txt t_ct_oct_hdr 1974 tx_crlf 1975 tx_txt extra1 1976 tx_crlf 1977 tx_txt t_xh_au 1978 tx_crlf 1979 if gt len extra2 1 1980 tx_txt extra2 1981 tx_crlf 1982 end 1983 if with_garb_sha 1984 tx_txt t_xh_sha_pre 1985 for i ulong 64 1986 tx_b get g_sh_hex i 1987 end 1988 tx_txt t_xh_garb 1989 tx_crlf 1990 end 1991 if with_clip_prov 1992 tx_txt t_xh_prov_pre 1993 for i ulong 64 1994 tx_b get g_clip_sha i 1995 end 1996 tx_crlf 1997 end 1998 tx_txt t_cl_hdr 1999 tx_u64 get g_packl 0 2000 tx_crlf 2001 tx_txt t_conn_hdr 2002 tx_crlf 2003 tx_crlf 2004 ok = send_all_tx fd 2005 if ok 2006 n = get g_packl 0 2007 off = ulong 0 2008 while lt off n bound 40000 2009 w = send fd g_pack off sub n off 16384 2010 if le w 0 2011 if eq w -4 2012 continue 2013 end 2014 ok = false 2015 break 2016 end 2017 off = add off ulong w 2018 end 2019 end 2020 if ok 2021 ok = read_rx_all fd 2022 end 2023 x = fclose fd 2024 ret ok 2025 end 2026 2027 fn run_hardening_t32 to void 2028 note T32: Long headers, 33-digit CL, 4200B URI, 25-zero clip/verify inputs -> zero Trap 4 crashes 2029 tx_reset 2030 tx_txt t_m_get_w 2031 tx_b 32 2032 tx_txt t_p_home 2033 tx_txt t_http11 2034 tx_crlf 2035 tx_txt t_host_hdr 2036 tx_crlf 2037 tx_txt t_xh_ld_pre 2038 for i ulong 300 2039 tx_b 65 2040 end 2041 tx_crlf 2042 tx_txt t_conn_hdr 2043 tx_crlf 2044 tx_crlf 2045 c1 = and send_raw_tx_and_read eq get g_rx_code 0 200 2046 2047 tx_reset 2048 tx_txt t_m_post_w 2049 tx_b 32 2050 tx_txt t_rt_up 2051 tx_txt t_http11 2052 tx_crlf 2053 tx_txt t_host_hdr 2054 tx_crlf 2055 tx_txt t_ct_oct_hdr 2056 tx_crlf 2057 tx_txt t_cl_hdr 2058 for i ulong 33 2059 tx_b 48 2060 end 2061 tx_crlf 2062 tx_txt t_conn_hdr 2063 tx_crlf 2064 tx_crlf 2065 c2 = and send_raw_tx_and_read eq get g_rx_code 0 400 2066 2067 tx_reset 2068 tx_txt t_m_get_w 2069 tx_b 32 2070 tx_txt t_p_home 2071 tx_b 63 2072 for i ulong 4200 2073 tx_b 97 2074 end 2075 tx_txt t_http11 2076 tx_crlf 2077 tx_txt t_host_hdr 2078 tx_crlf 2079 tx_txt t_conn_hdr 2080 tx_crlf 2081 tx_crlf 2082 c3 = and send_raw_tx_and_read eq get g_rx_code 0 400 2083 2084 body_reset 2085 body_b 119 2086 body_b 49 2087 body_b 61 2088 for i ulong 25 2089 body_b 48 2090 end 2091 body_b 38 2092 body_b 99 2093 body_b 108 2094 body_b 105 2095 body_b 112 2096 body_b 95 2097 body_b 110 2098 body_b 97 2099 body_b 109 2100 body_b 101 2101 body_b 61 2102 for i ulong 90 2103 body_b 120 2104 end 2105 c4 = and post_body_req t_p_clip t_ct_form_hdr eq get g_rx_code 0 400 2106 2107 body_reset 2108 body_txt t_m_bad_z 2109 c5 = and post_body_req t_p_cver t_ct_txt_hdr eq get g_rx_code 0 400 2110 2111 c6 = and do_simple_req t_m_get_w t_p_health eq get g_rx_code 0 200 2112 chk and c1 and c2 and c3 and c4 and c5 c6 t_t32 2113 end 2114 2115 fn run_hardening_t33_t34 to void 2116 note T33: Long multipart filename (170B -> 400 no crash) and altname attr (201) 2117 build_valid_pack 8 9 0x0e513f7522e2689a 12 811 2118 mp_reset 2119 mp_field t_k_name t_v_nbad 2120 mp_field t_k_auth t_v_au 2121 mp_txt t_mp_d1 2122 mp_txt t_bnd 2123 mp_crlf 2124 mp_txt t_mp_cd1 2125 mp_txt t_f_pack_k 2126 mp_txt t_mp_cd2 2127 for i ulong 170 2128 mp_b 97 2129 end 2130 mp_txt t_suf_sp 2131 mp_txt t_mp_q 2132 mp_crlf 2133 mp_crlf 2134 for i ulong get g_packl 0 bound 4096 2135 mp_b get g_pack i 2136 end 2137 mp_crlf 2138 mp_txt t_mp_d1 2139 mp_txt t_bnd 2140 mp_txt t_mp_d1 2141 mp_crlf 2142 c1 = and post_mp_upload eq get g_rx_code 0 400 2143 2144 build_valid_pack 8 9 0x0e513f7522e2689a 12 812 2145 mp_reset 2146 mp_field t_k_name t_v_nbad 2147 mp_field t_k_auth t_v_au 2148 mp_txt t_mp_d1 2149 mp_txt t_bnd 2150 mp_crlf 2151 mp_txt t_mp_cd_alt 2152 mp_crlf 2153 mp_crlf 2154 for i ulong get g_packl 0 bound 4096 2155 mp_b get g_pack i 2156 end 2157 mp_crlf 2158 mp_txt t_mp_d1 2159 mp_txt t_bnd 2160 mp_txt t_mp_d1 2161 mp_crlf 2162 c2 = and post_mp_upload eq get g_rx_code 0 201 2163 chk and c1 c2 t_t33 2164 2165 note T34: expected_sha256 overflow refused (400) + name=".." falls back to safe strand.sp 2166 build_valid_pack 8 9 0x0e513f7522e2689a 12 813 2167 sha_pack 2168 c3 = and send_oct_pack_with_hdrs t_xh_n_e1 t_none_hdr true false eq get g_rx_code 0 400 2169 c4 = and send_oct_pack_with_hdrs t_xh_dotdot t_none_hdr false false eq get g_rx_code 0 201 2170 for i ulong 64 2171 put g_sha_e1 i get g_sh_hex i 2172 end 2173 tx_reset 2174 tx_txt t_m_head_w 2175 tx_b 32 2176 tx_txt t_p_pack_pre 2177 for i ulong 64 2178 tx_b get g_sha_e1 i 2179 end 2180 tx_txt t_suf_sp 2181 tx_txt t_http11 2182 tx_crlf 2183 tx_txt t_host_hdr 2184 tx_crlf 2185 tx_txt t_conn_hdr 2186 tx_crlf 2187 tx_crlf 2188 c5 = and send_raw_tx_and_read and rx_hdr_extract t_cd_h and eq get g_rx_code 0 200 eq get g_hdr_val 22 115 2189 c6 = false 2190 if c5 2191 c6 = and eq get g_hdr_val 23 116 and eq get g_hdr_val 28 46 eq get g_hdr_val 29 115 2192 end 2193 chk and c3 and c4 c6 t_t34 2194 end 2195 2196 fn build_and_verify_forged_clip hdr view uchar * mid view uchar * to bool 2197 body_reset 2198 body_txt hdr 2199 body_sha 1 2200 body_txt mid 2201 body_sha 2 2202 body_txt t_m_f_m2 2203 sha_start 2204 for i ulong get g_bodyl 0 bound 16384 2205 sha_b get g_body i 2206 end 2207 sha_finish 2208 body_txt t_m_f_bsha 2209 for j ulong 64 2210 body_b get g_sh_hex j 2211 end 2212 body_b 10 2213 ret and post_body_req t_p_cver t_ct_txt_hdr eq get g_rx_code 0 400 2214 end 2215 2216 fn run_hardening_t35_t36 to void 2217 note T35: Pairwise parent_trunk conflict (e1 empty + A aaa + e2 bbb) -> 400, invalid ft_steps -> 400 2218 build_valid_pack 8 9 0x0e513f7522e2689a 12 814 2219 sha_pack 2220 for i ulong 64 2221 put g_sha_e2 i get g_sh_hex i 2222 end 2223 c_up = and send_oct_pack_with_hdrs t_xh_n_e2 t_xh_pt_b false false eq get g_rx_code 0 201 2224 body_reset 2225 body_txt t_cf_s1 2226 for i ulong 64 2227 body_b get g_sha_e1 i 2228 end 2229 body_txt t_cf_s2 2230 body_sha 1 2231 body_txt t_cf_s3 2232 for i ulong 64 2233 body_b get g_sha_e2 i 2234 end 2235 body_txt t_cf_pw3 2236 c_pw = and post_body_req t_p_clip t_ct_form_hdr eq get g_rx_code 0 400 2237 body_reset 2238 body_txt t_cf_s1 2239 body_sha 1 2240 body_txt t_cf_s2 2241 body_sha 2 2242 body_txt t_cf_badft 2243 c_ft = and post_body_req t_p_clip t_ct_form_hdr eq get g_rx_code 0 400 2244 chk and c_up and c_pw c_ft t_t35 2245 2246 note T36: Forged re-hashed .spclip variants refused (magic suffix, splice=0, forged slot base_hash) 2247 f1 = build_and_verify_forged_clip t_m_f_hdr1 t_m_f_m1 2248 f2 = build_and_verify_forged_clip t_m_f_hdr2 t_m_f_m1 2249 f3 = build_and_verify_forged_clip t_m_f_hdr3 t_m_f_mbad 2250 chk and f1 and f2 f3 t_t36 2251 end 2252 2253 fn run_hardening_t37_t39 to void 2254 note T37: Child strand linked to saved clip provenance (compatible 201, incompatible lower layer 400) 2255 build_valid_pack 8 9 0x0e513f7522e2689a 12 815 2256 sha_pack 2257 c_ch_ok = and send_oct_pack_with_hdrs t_xh_n_ch t_none_hdr false true eq get g_rx_code 0 201 2258 tx_reset 2259 tx_txt t_m_get_w 2260 tx_b 32 2261 tx_txt t_p_strand_pre 2262 for i ulong 64 2263 tx_b get g_sh_hex i 2264 end 2265 tx_txt t_http11 2266 tx_crlf 2267 tx_txt t_host_hdr 2268 tx_crlf 2269 tx_txt t_conn_hdr 2270 tx_crlf 2271 tx_crlf 2272 c_det = and send_raw_tx_and_read and eq get g_rx_code 0 200 rx_body_contains t_suf_spclip 2273 build_valid_pack 4 5 0x7777666655554444 12 816 2274 c_ch_bad = and send_oct_pack_with_hdrs t_xh_n_ch t_none_hdr false true eq get g_rx_code 0 400 2275 chk and c_ch_ok and c_det c_ch_bad t_t37 2276 2277 note T38: clips/index.json strands[] + ?trunk filter, no broken div-summary, Anti-DNA no neg spmerge 2278 j1 = and do_simple_req t_m_get_w t_p_kjson and eq get g_rx_code 0 200 rx_body_contains t_s_strands_arr 2279 j2 = and do_simple_req t_m_get_w t_p_kjson_none and eq get g_rx_code 0 200 rx_body_contains t_s_c0 2280 h1 = and do_simple_req t_m_get_w t_p_home and eq get g_rx_code 0 200 not rx_body_contains t_s_div_sum 2281 body_reset 2282 body_txt t_cf_s1 2283 body_sha 1 2284 body_txt t_cf_s2 2285 body_sha 2 2286 body_txt t_cf_anti_s 2287 a1 = and post_body_req t_p_clip t_ct_form_hdr and eq get g_rx_code 0 201 not rx_body_contains t_s_spmerge_w 2288 chk and j1 and j2 and h1 a1 t_t38 2289 2290 note T39: 68 distinct trunks stay alive on GET /strands/ and GET /strands/clip (no bound-64 Trap 4) 2291 all_up = true 2292 for k ulong 68 bound 68 2293 build_valid_pack 8 9 add 0x3000000000000000 k 4 add 900 k 2294 if not and send_oct_pack_with_hdrs t_xh_n_tr t_none_hdr false false eq get g_rx_code 0 201 2295 all_up = false 2296 break 2297 end 2298 end 2299 g1 = and do_simple_req t_m_get_w t_p_home eq get g_rx_code 0 200 2300 g2 = and do_simple_req t_m_get_w t_p_clip eq get g_rx_code 0 200 2301 chk and all_up and g1 g2 t_t39 2302 end 2303 2304 fn parse_port_arg to ulong 2305 buf = new uchar 32 0 2306 k = argread 3 buf 0 32 2307 if le k 0 2308 ret 18499 2309 end 2310 v = ulong 0 2311 for i ulong ulong k bound 32 2312 c = get buf i 2313 if or lt c 48 gt c 57 2314 ret 18499 2315 end 2316 v = add mul v 10 ulong sub c 48 2317 end 2318 ret v 2319 end 2320 2321 fn main to int 2322 if lt argcnt 4 2323 x = write 2 t_usage 0 len t_usage 2324 ret 2 2325 end 2326 k1 = argread 1 g_srv 0 511 2327 k2 = argread 2 g_dir 0 511 2328 if or le k1 0 le k2 0 2329 ret 2 2330 end 2331 put g_srvl 0 ulong k1 2332 put g_dirl 0 ulong k2 2333 put g_port 0 parse_port_arg 2334 put g_rsp1l 0 0 2335 put g_rsp2l 0 0 2336 if ge argcnt 5 2337 k4 = argread 4 g_rsp1 0 511 2338 if gt k4 0 2339 put g_rsp1l 0 ulong k4 2340 end 2341 end 2342 if ge argcnt 6 2343 k5 = argread 5 g_rsp2 0 511 2344 if gt k5 0 2345 put g_rsp2l 0 ulong k5 2346 end 2347 end 2348 if not start_server 16384 2349 ret 3 2350 end 2351 run_basics_and_uploads 2352 run_catalog_and_download 2353 run_neg_upload_controls_1 2354 run_neg_upload_controls_2 2355 run_clip_tests 2356 run_clip_neg_tests 2357 run_phase_b 2358 run_xss_test 2359 run_trihelix_test 2360 run_hardening_t32 2361 run_hardening_t33_t34 2362 run_hardening_t35_t36 2363 run_hardening_t37_t39 2364 stop_server 2365 o_reset 2366 o_txt t_sum_pre 2367 o_u64 get g_pass 0 2368 o_txt t_sum_mid 2369 o_u64 get g_fail 0 2370 o_txt t_nl 2371 o_flush 2372 if gt get g_fail 0 0 2373 ret 1 2374 end 2375 ret 0 2376 end