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/capability/test.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 / capability / test.om` 863 lines ยท 20102 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/capability/test.om: Pure-Omega test suite for AIENOS 64-bit Capability Authority. 3 note Covers all positive invariants and negative controls from native/capability/tests/capability_test.c 4 note plus resource width checks and constant-time office token authorization. 5 note Compose with: si/directives/om2.om aienux/capability/lib.om aienux/capability/test.om 6 7 text s_pass "PASS " 8 text s_fail "FAIL " 9 text s_nl "\n" 10 text s_t01 "high_half_resource_and_width" 11 text s_t02 "forged_stale_subject_resource_rights_fail_closed" 12 text s_t03 "amplification_lease_epoch_revoked_ancestor_fail" 13 text s_t04 "child_lease_cannot_outlive_parent" 14 text s_t05 "privileged_rights_not_delegable_and_office_stays" 15 text s_t06 "promote_right_cannot_be_delegated" 16 text s_t07 "generation_exhaustion_fails_closed" 17 text s_t08 "kill_restart_invalidates_and_cognition_refused" 18 text s_t09 "reclaimed_ref_stays_dead_after_restart" 19 text s_t10 "generation_above_32_bits_is_kept" 20 text s_t11 "ordinary_cap_cannot_admin_and_depth_stops" 21 text s_t12 "table_fills_then_refuses" 22 text s_t13 "observer_ops_cascade_refusals_and_silence" 23 text s_t14 "validate_needs_every_requested_right" 24 text s_t15 "lease_ends_exactly_at_expiry_tick_and_overflow" 25 text s_t16 "validate_refuses_corrupt_non_live_parent" 26 text s_t17 "control_resource_cap_cannot_operate_authority" 27 text s_t18 "office_token_authorize_and_restart_rotation" 28 text s_sum "CAPABILITY_TEST_PASS total=18 failed=0\n" 29 text s_fsum "CAPABILITY_TEST_FAIL\n" 30 31 fn report name view uchar * ok bool to uint 32 if ok 33 w1 = cap_write_all 1 s_pass 34 w2 = cap_write_all 1 name 35 w3 = cap_write_all 1 s_nl 36 if and w1 and w2 w3 37 ret 0 38 end 39 ret 1 40 end 41 w1 = cap_write_all 1 s_fail 42 w2 = cap_write_all 1 name 43 w3 = cap_write_all 1 s_nl 44 if and w1 and w2 w3 45 ret 1 46 end 47 ret 1 48 end 49 50 fn mk_root_req subj uint res ulong rgt uint ticks ulong off view CapRef dst edit CapMint to void 51 put dst issuer 1 52 put dst subject subj 53 put dst resource res 54 put dst rights rgt 55 put dst lease_ticks ticks 56 put dst parent_id CAP_PARENT_NONE 57 put dst parent_generation 0 58 put dst auth_id get off cap_id 59 put dst auth_generation get off generation 60 end 61 62 fn mk_deleg_req subj uint res ulong rgt uint ticks ulong par view CapRef dst edit CapMint to void 63 put dst issuer 2 64 put dst subject subj 65 put dst resource res 66 put dst rights rgt 67 put dst lease_ticks ticks 68 put dst parent_id get par cap_id 69 put dst parent_generation get par generation 70 put dst auth_id get par cap_id 71 put dst auth_generation get par generation 72 end 73 74 fn test_01_high_half_resource to bool 75 if ne cap_start CAP_OK 76 ret false 77 end 78 off = new CapRef 0 0 79 if ne cap_office off CAP_OK 80 ret false 81 end 82 hi_res = ulong 0x123456789abcdef0 83 req = new CapMint 0 0 0 0 0 0 0 0 0 84 mk_root_req 42 hi_res CAP_RIGHT_READ 0 off req 85 cref = new CapRef 0 0 86 if ne cap_mint req cref CAP_OK 87 ret false 88 end 89 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 90 if ne cap_validate cref 42 hi_res CAP_RIGHT_READ ent CAP_OK 91 ret false 92 end 93 if ne get ent resource hi_res 94 ret false 95 end 96 note Low-32 collision must fail closed 97 if ne cap_validate cref 42 0x9abcdef0 CAP_RIGHT_READ ent CAP_ERR_RESOURCE 98 ret false 99 end 100 note Widen / narrow resource checks 101 if ne cap_widen_resource 0xdeadbeef 0xdeadbeef 102 ret false 103 end 104 n32 = new uint 1 0 105 if ne cap_narrow_resource 0xdeadbeef n32 CAP_OK 106 ret false 107 end 108 if ne get n32 0 0xdeadbeef 109 ret false 110 end 111 if ne cap_narrow_resource hi_res n32 CAP_ERR_RESOURCE 112 ret false 113 end 114 ret true 115 end 116 117 fn test_02_forged_stale_fail_closed to bool 118 if ne cap_start CAP_OK 119 ret false 120 end 121 off = new CapRef 0 0 122 rc0 = cap_office off 123 if ne rc0 CAP_OK 124 ret false 125 end 126 req = new CapMint 0 0 0 0 0 0 0 0 0 127 mk_root_req 7 100 CAP_RIGHT_READ 0 off req 128 cref = new CapRef 0 0 129 if ne cap_mint req cref CAP_OK 130 ret false 131 end 132 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 133 note Out of bounds cap_id 134 oob = new CapRef 256 get cref generation 135 if ne cap_validate oob 7 100 CAP_RIGHT_READ ent CAP_ERR_BOUNDS 136 ret false 137 end 138 if ne cap_inspect oob ent CAP_ERR_BOUNDS 139 ret false 140 end 141 note Stale generation 142 stale = new CapRef get cref cap_id add get cref generation 1 143 if ne cap_validate stale 7 100 CAP_RIGHT_READ ent CAP_ERR_STALE_GEN 144 ret false 145 end 146 if ne cap_inspect stale ent CAP_ERR_STALE_GEN 147 ret false 148 end 149 note Free slot inspect refused 150 free_ref = new CapRef 99 get off generation 151 if ne cap_inspect free_ref ent CAP_ERR_STATE 152 ret false 153 end 154 note Wrong subject, resource, rights 155 if ne cap_validate cref 8 100 CAP_RIGHT_READ ent CAP_ERR_SUBJECT 156 ret false 157 end 158 if ne cap_validate cref 7 101 CAP_RIGHT_READ ent CAP_ERR_RESOURCE 159 ret false 160 end 161 if ne cap_validate cref 7 100 CAP_RIGHT_WRITE ent CAP_ERR_RIGHTS 162 ret false 163 end 164 ret true 165 end 166 167 fn test_03_amplification_lease_epoch_revoke to bool 168 if ne cap_start CAP_OK 169 ret false 170 end 171 off = new CapRef 0 0 172 if ne cap_office off CAP_OK 173 ret false 174 end 175 req = new CapMint 0 0 0 0 0 0 0 0 0 176 r_rd = or CAP_RIGHT_READ CAP_RIGHT_DELEGATE 177 mk_root_req 10 555 r_rd 100 off req 178 par = new CapRef 0 0 179 if ne cap_mint req par CAP_OK 180 ret false 181 end 182 note Delegation narrowing succeeds 183 mk_deleg_req 11 555 CAP_RIGHT_READ 50 par req 184 ch = new CapRef 0 0 185 if ne cap_mint req ch CAP_OK 186 ret false 187 end 188 note Rights amplification refused 189 mk_deleg_req 12 555 or CAP_RIGHT_READ CAP_RIGHT_WRITE 50 par req 190 bad = new CapRef 0 0 191 if ne cap_mint req bad CAP_ERR_AMPLIFY 192 ret false 193 end 194 note Resource change during delegation refused 195 mk_deleg_req 12 556 CAP_RIGHT_READ 50 par req 196 if ne cap_mint req bad CAP_ERR_RESOURCE 197 ret false 198 end 199 note Revoking parent cascades to child 200 if ne cap_revoke off par CAP_OK 201 ret false 202 end 203 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 204 if ne cap_validate par 10 555 CAP_RIGHT_READ ent CAP_ERR_REVOKED 205 ret false 206 end 207 if ne cap_validate ch 11 555 CAP_RIGHT_READ ent CAP_ERR_REVOKED 208 ret false 209 end 210 note Epoch bump invalidates previously minted cap 211 mk_root_req 13 777 CAP_RIGHT_READ 0 off req 212 ep_cap = new CapRef 0 0 213 if ne cap_mint req ep_cap CAP_OK 214 ret false 215 end 216 if ne cap_bump_epoch off CAP_OK 217 ret false 218 end 219 if ne cap_validate ep_cap 13 777 CAP_RIGHT_READ ent CAP_ERR_EPOCH 220 ret false 221 end 222 ret true 223 end 224 225 fn test_04_child_lease_bound to bool 226 if ne cap_start CAP_OK 227 ret false 228 end 229 off = new CapRef 0 0 230 if ne cap_office off CAP_OK 231 ret false 232 end 233 req = new CapMint 0 0 0 0 0 0 0 0 0 234 mk_root_req 10 200 or CAP_RIGHT_READ CAP_RIGHT_DELEGATE 50 off req 235 par = new CapRef 0 0 236 if ne cap_mint req par CAP_OK 237 ret false 238 end 239 note Unbounded child lease refused when parent is bounded 240 mk_deleg_req 11 200 CAP_RIGHT_READ 0 par req 241 ch = new CapRef 0 0 242 if ne cap_mint req ch CAP_ERR_AMPLIFY 243 ret false 244 end 245 note Longer child lease refused 246 mk_deleg_req 11 200 CAP_RIGHT_READ 51 par req 247 if ne cap_mint req ch CAP_ERR_AMPLIFY 248 ret false 249 end 250 note Equal child lease succeeds 251 mk_deleg_req 11 200 CAP_RIGHT_READ 50 par req 252 if ne cap_mint req ch CAP_OK 253 ret false 254 end 255 ret true 256 end 257 258 fn test_05_privileged_not_delegable to bool 259 if ne cap_start CAP_OK 260 ret false 261 end 262 off = new CapRef 0 0 263 if ne cap_office off CAP_OK 264 ret false 265 end 266 req = new CapMint 0 0 0 0 0 0 0 0 0 267 note Privileged + DELEGATE refused 268 mk_root_req 1 CAP_RES_AUTHORITY or CAP_RIGHT_MINT CAP_RIGHT_DELEGATE 0 off req 269 bad = new CapRef 0 0 270 if ne cap_mint req bad CAP_ERR_NOT_DELEGABLE 271 ret false 272 end 273 note Sub-office with only REVOKE cannot revoke office with all privileged rights 274 mk_root_req 2 CAP_RES_AUTHORITY CAP_RIGHT_REVOKE 0 off req 275 sub_rev = new CapRef 0 0 276 if ne cap_mint req sub_rev CAP_OK 277 ret false 278 end 279 if ne cap_revoke sub_rev off CAP_ERR_UNAUTHORIZED 280 ret false 281 end 282 note Office stays live 283 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 284 if ne cap_validate off 0 CAP_RES_AUTHORITY CAP_RIGHT_MINT ent CAP_OK 285 ret false 286 end 287 ret true 288 end 289 290 fn test_06_promote_not_delegable to bool 291 if ne cap_start CAP_OK 292 ret false 293 end 294 off = new CapRef 0 0 295 if ne cap_office off CAP_OK 296 ret false 297 end 298 req = new CapMint 0 0 0 0 0 0 0 0 0 299 mk_root_req 5 CAP_RES_AUTHORITY or CAP_RIGHT_PROMOTE CAP_RIGHT_DELEGATE 0 off req 300 bad = new CapRef 0 0 301 if ne cap_mint req bad CAP_ERR_NOT_DELEGABLE 302 ret false 303 end 304 note Minting PROMOTE without DELEGATE succeeds 305 mk_root_req 5 CAP_RES_AUTHORITY CAP_RIGHT_PROMOTE 0 off req 306 prom = new CapRef 0 0 307 if ne cap_mint req prom CAP_OK 308 ret false 309 end 310 note Cannot delegate from PROMOTE cap 311 mk_deleg_req 6 CAP_RES_AUTHORITY CAP_RIGHT_PROMOTE 0 prom req 312 if ne cap_mint req bad CAP_ERR_NOT_DELEGABLE 313 ret false 314 end 315 ret true 316 end 317 318 fn test_07_generation_exhaustion to bool 319 nxt = new ulong 1 0 320 if ne cap_generation_advance CAP_U64_MAX nxt CAP_ERR_EXHAUSTED 321 ret false 322 end 323 if ne cap_start CAP_OK 324 ret false 325 end 326 off = new CapRef 0 0 327 if ne cap_office off CAP_OK 328 ret false 329 end 330 req = new CapMint 0 0 0 0 0 0 0 0 0 331 mk_root_req 1 10 CAP_RIGHT_READ 0 off req 332 c1 = new CapRef 0 0 333 if ne cap_mint req c1 CAP_OK 334 ret false 335 end 336 note Force generation on live slot refused 337 if ne cap_force_generation get c1 cap_id CAP_U64_MAX CAP_ERR_STATE 338 ret false 339 end 340 note Force generation to 0 refused 341 if ne cap_force_generation 2 0 CAP_ERR_EXHAUSTED 342 ret false 343 end 344 note Revoke slot 1, force its gen to U64_MAX -> reclaim must fail closed 345 if ne cap_revoke off c1 CAP_OK 346 ret false 347 end 348 if ne cap_force_generation get c1 cap_id CAP_U64_MAX CAP_OK 349 ret false 350 end 351 if ne cap_reclaim off get c1 cap_id CAP_ERR_EXHAUSTED 352 ret false 353 end 354 note Exhaust all free slots (2..255) -> mint must return CAP_ERR_EXHAUSTED 355 i = uint 2 356 while lt i CAP_MAX bound 256 357 if ne cap_force_generation i CAP_U64_MAX CAP_OK 358 ret false 359 end 360 i = add i 1 361 end 362 c2 = new CapRef 0 0 363 if ne cap_mint req c2 CAP_ERR_EXHAUSTED 364 ret false 365 end 366 ret true 367 end 368 369 fn test_08_kill_restart_cognition to bool 370 if ne cap_start CAP_OK 371 ret false 372 end 373 off = new CapRef 0 0 374 if ne cap_office off CAP_OK 375 ret false 376 end 377 req = new CapMint 0 0 0 0 0 0 0 0 0 378 mk_root_req 9 99 CAP_RIGHT_READ 0 off req 379 c1 = new CapRef 0 0 380 if ne cap_mint req c1 CAP_OK 381 ret false 382 end 383 note Cognition calls always fail closed 384 tok = new uchar 32 0 385 cap_copy_token tok 386 if ne cap_cognition_mint req tok CAP_ERR_UNAUTHORIZED 387 ret false 388 end 389 if ne cap_cognition_admin 1 off c1 CAP_ERR_UNAUTHORIZED 390 ret false 391 end 392 note Kill stops all mutating operations with CAP_ERR_IO 393 if ne cap_kill CAP_OK 394 ret false 395 end 396 c2 = new CapRef 0 0 397 if ne cap_mint req c2 CAP_ERR_IO 398 ret false 399 end 400 if ne cap_revoke off c1 CAP_ERR_IO 401 ret false 402 end 403 if ne cap_advance_clock off 1 CAP_ERR_IO 404 ret false 405 end 406 if ne cap_bump_epoch off CAP_ERR_IO 407 ret false 408 end 409 note Restart brings authority back with strictly higher generation 410 old_gen = get off generation 411 if ne cap_restart CAP_OK 412 ret false 413 end 414 off2 = new CapRef 0 0 415 if ne cap_office off2 CAP_OK 416 ret false 417 end 418 if le get off2 generation old_gen 419 ret false 420 end 421 note Old reference is stale after restart 422 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 423 if ne cap_validate c1 9 99 CAP_RIGHT_READ ent CAP_ERR_STALE_GEN 424 ret false 425 end 426 ret true 427 end 428 429 fn test_09_reclaimed_stays_dead_after_restart to bool 430 if ne cap_start CAP_OK 431 ret false 432 end 433 off = new CapRef 0 0 434 if ne cap_office off CAP_OK 435 ret false 436 end 437 req = new CapMint 0 0 0 0 0 0 0 0 0 438 mk_root_req 3 33 CAP_RIGHT_READ 0 off req 439 c1 = new CapRef 0 0 440 if ne cap_mint req c1 CAP_OK 441 ret false 442 end 443 if ne cap_revoke off c1 CAP_OK 444 ret false 445 end 446 if ne cap_reclaim off get c1 cap_id CAP_OK 447 ret false 448 end 449 if ne cap_restart CAP_OK 450 ret false 451 end 452 off2 = new CapRef 0 0 453 if ne cap_office off2 CAP_OK 454 ret false 455 end 456 if le get off2 generation add get c1 generation 1 457 ret false 458 end 459 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 460 if ne cap_validate c1 3 33 CAP_RIGHT_READ ent CAP_ERR_STALE_GEN 461 ret false 462 end 463 ret true 464 end 465 466 fn test_10_gen_above_32_bits to bool 467 if ne cap_start CAP_OK 468 ret false 469 end 470 off = new CapRef 0 0 471 if ne cap_office off CAP_OK 472 ret false 473 end 474 hi_gen = ulong 0x0000000100000005 475 if ne cap_force_generation 1 hi_gen CAP_OK 476 ret false 477 end 478 req = new CapMint 0 0 0 0 0 0 0 0 0 479 mk_root_req 4 44 CAP_RIGHT_READ 0 off req 480 c1 = new CapRef 0 0 481 if ne cap_mint req c1 CAP_OK 482 ret false 483 end 484 if ne get c1 cap_id 1 485 ret false 486 end 487 if ne get c1 generation hi_gen 488 ret false 489 end 490 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 491 if ne cap_validate c1 4 44 CAP_RIGHT_READ ent CAP_OK 492 ret false 493 end 494 note Low-32 truncated generation fails closed 495 trunc = new CapRef 1 5 496 if ne cap_validate trunc 4 44 CAP_RIGHT_READ ent CAP_ERR_STALE_GEN 497 ret false 498 end 499 ret true 500 end 501 502 fn test_11_ordinary_no_admin_and_depth to bool 503 if ne cap_start CAP_OK 504 ret false 505 end 506 off = new CapRef 0 0 507 if ne cap_office off CAP_OK 508 ret false 509 end 510 req = new CapMint 0 0 0 0 0 0 0 0 0 511 r_rd = or CAP_RIGHT_READ CAP_RIGHT_DELEGATE 512 mk_root_req 1 500 r_rd 0 off req 513 cur = new CapRef 0 0 514 if ne cap_mint req cur CAP_OK 515 ret false 516 end 517 note Ordinary cap cannot revoke, reclaim, advance clock, or bump epoch 518 if ne cap_revoke cur off CAP_ERR_UNAUTHORIZED 519 ret false 520 end 521 if ne cap_reclaim cur 2 CAP_ERR_UNAUTHORIZED 522 ret false 523 end 524 if ne cap_advance_clock cur 1 CAP_ERR_UNAUTHORIZED 525 ret false 526 end 527 if ne cap_bump_epoch cur CAP_ERR_UNAUTHORIZED 528 ret false 529 end 530 note Chain up to CAP_MAX_DEPTH = 8 succeeds 531 nxt = new CapRef 0 0 532 d = uint 0 533 while lt d CAP_MAX_DEPTH bound 16 534 mk_deleg_req add 2 d 500 r_rd 0 cur req 535 if ne cap_mint req nxt CAP_OK 536 ret false 537 end 538 put cur cap_id get nxt cap_id 539 put cur generation get nxt generation 540 d = add d 1 541 end 542 note 9th hop must fail with CAP_ERR_CHAIN 543 mk_deleg_req 99 500 CAP_RIGHT_READ 0 cur req 544 too_deep = new CapRef 0 0 545 if ne cap_mint req too_deep CAP_ERR_CHAIN 546 ret false 547 end 548 ret true 549 end 550 551 fn test_12_table_fills_then_refuses to bool 552 if ne cap_start CAP_OK 553 ret false 554 end 555 off = new CapRef 0 0 556 if ne cap_office off CAP_OK 557 ret false 558 end 559 req = new CapMint 0 0 0 0 0 0 0 0 0 560 mk_root_req 1 100 CAP_RIGHT_READ 0 off req 561 c = new CapRef 0 0 562 note Slot 0 is office; slots 1..255 = 255 mints succeed 563 i = uint 1 564 while lt i CAP_MAX bound 256 565 if ne cap_mint req c CAP_OK 566 ret false 567 end 568 i = add i 1 569 end 570 note 256th mint fails with CAP_ERR_FULL 571 if ne cap_mint req c CAP_ERR_FULL 572 ret false 573 end 574 ret true 575 end 576 577 fn check_obs_rev idx ulong exp_id uint to bool 578 ev = new CapObsEvent 0 0 0 0 0 0 0 0 0 579 if not cap_obs_get idx ev 580 ret false 581 end 582 if ne get ev op CAP_OBS_REVOKE 583 ret false 584 end 585 if ne get ev cap_id exp_id 586 ret false 587 end 588 ret true 589 end 590 591 fn check_obs_refusal idx ulong exp_op uint exp_rc int to bool 592 ev = new CapObsEvent 0 0 0 0 0 0 0 0 0 593 if not cap_obs_get idx ev 594 ret false 595 end 596 if ne get ev op exp_op 597 ret false 598 end 599 if ne get ev rc exp_rc 600 ret false 601 end 602 if ne get ev has_entry 0 603 ret false 604 end 605 ret true 606 end 607 608 fn test_13_observer_semantics to bool 609 if ne cap_start CAP_OK 610 ret false 611 end 612 cap_obs_clear 613 cap_set_observer true 614 off = new CapRef 0 0 615 if ne cap_office off CAP_OK 616 ret false 617 end 618 req = new CapMint 0 0 0 0 0 0 0 0 0 619 r_rd = or CAP_RIGHT_READ CAP_RIGHT_DELEGATE 620 mk_root_req 1 888 r_rd 0 off req 621 p = new CapRef 0 0 622 if ne cap_mint req p CAP_OK 623 ret false 624 end 625 mk_deleg_req 2 888 r_rd 0 p req 626 c = new CapRef 0 0 627 if ne cap_mint req c CAP_OK 628 ret false 629 end 630 mk_deleg_req 3 888 CAP_RIGHT_READ 0 c req 631 gc = new CapRef 0 0 632 if ne cap_mint req gc CAP_OK 633 ret false 634 end 635 note 3 MINT events 636 if ne cap_obs_count 3 637 ret false 638 end 639 note Validate (even denied) must NEVER emit an observer event 640 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 641 if ne cap_validate gc 999 888 CAP_RIGHT_READ ent CAP_ERR_SUBJECT 642 ret false 643 end 644 if ne cap_obs_count 3 645 ret false 646 end 647 note Cascade revoke must announce p, then c, then gc (ancestor first) 648 if ne cap_revoke off p CAP_OK 649 ret false 650 end 651 if ne cap_obs_count 6 652 ret false 653 end 654 if not check_obs_rev 3 get p cap_id 655 ret false 656 end 657 if not check_obs_rev 4 get c cap_id 658 ret false 659 end 660 if not check_obs_rev 5 get gc cap_id 661 ret false 662 end 663 note Refused admin op reports has_entry=0 and exact refusal code 664 if ne cap_reclaim off 200 CAP_ERR_STATE 665 ret false 666 end 667 if not check_obs_refusal 6 CAP_OBS_RECLAIM CAP_ERR_STATE 668 ret false 669 end 670 note Disable observer -> silent on subsequent ops 671 cap_set_observer false 672 if ne cap_advance_clock off 5 CAP_OK 673 ret false 674 end 675 if ne cap_obs_count 7 676 ret false 677 end 678 ret true 679 end 680 681 fn test_14_validate_needs_all_rights to bool 682 if ne cap_start CAP_OK 683 ret false 684 end 685 off = new CapRef 0 0 686 if ne cap_office off CAP_OK 687 ret false 688 end 689 req = new CapMint 0 0 0 0 0 0 0 0 0 690 mk_root_req 5 600 CAP_RIGHT_READ 0 off req 691 c1 = new CapRef 0 0 692 if ne cap_mint req c1 CAP_OK 693 ret false 694 end 695 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 696 if ne cap_validate c1 5 600 or CAP_RIGHT_READ CAP_RIGHT_WRITE ent CAP_ERR_RIGHTS 697 ret false 698 end 699 mk_root_req 5 600 or CAP_RIGHT_READ CAP_RIGHT_WRITE 0 off req 700 c2 = new CapRef 0 0 701 if ne cap_mint req c2 CAP_OK 702 ret false 703 end 704 if ne cap_validate c2 5 600 or CAP_RIGHT_READ CAP_RIGHT_WRITE ent CAP_OK 705 ret false 706 end 707 ret true 708 end 709 710 fn test_15_lease_exact_tick_and_overflow to bool 711 if ne cap_start CAP_OK 712 ret false 713 end 714 off = new CapRef 0 0 715 if ne cap_office off CAP_OK 716 ret false 717 end 718 req = new CapMint 0 0 0 0 0 0 0 0 0 719 mk_root_req 7 700 CAP_RIGHT_READ 10 off req 720 c = new CapRef 0 0 721 if ne cap_mint req c CAP_OK 722 ret false 723 end 724 if ne cap_advance_clock off 9 CAP_OK 725 ret false 726 end 727 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 728 if ne cap_validate c 7 700 CAP_RIGHT_READ ent CAP_OK 729 ret false 730 end 731 if ne cap_advance_clock off 1 CAP_OK 732 ret false 733 end 734 if ne cap_validate c 7 700 CAP_RIGHT_READ ent CAP_ERR_EXPIRED 735 ret false 736 end 737 note Clock overflow fails closed 738 if ne cap_advance_clock off CAP_U64_MAX CAP_ERR_OVERFLOW 739 ret false 740 end 741 if ne cap_clock 10 742 ret false 743 end 744 ret true 745 end 746 747 fn test_16_corrupt_non_live_parent to bool 748 if ne cap_start CAP_OK 749 ret false 750 end 751 off = new CapRef 0 0 752 if ne cap_office off CAP_OK 753 ret false 754 end 755 req = new CapMint 0 0 0 0 0 0 0 0 0 756 mk_root_req 1 900 or CAP_RIGHT_READ CAP_RIGHT_DELEGATE 0 off req 757 p = new CapRef 0 0 758 if ne cap_mint req p CAP_OK 759 ret false 760 end 761 mk_deleg_req 2 900 CAP_RIGHT_READ 0 p req 762 c = new CapRef 0 0 763 if ne cap_mint req c CAP_OK 764 ret false 765 end 766 note Corrupt parent to REVOKED directly without cascading child 767 if ne cap_corrupt_slot_state get p cap_id CAP_STATE_REVOKED CAP_OK 768 ret false 769 end 770 ent = new CapEntry 0 0 0 0 0 0 0 0 0 0 0 0 0 771 if ne cap_validate c 2 900 CAP_RIGHT_READ ent CAP_ERR_CHAIN 772 ret false 773 end 774 ret true 775 end 776 777 fn test_17_control_resource_cannot_admin to bool 778 if ne cap_start CAP_OK 779 ret false 780 end 781 off = new CapRef 0 0 782 if ne cap_office off CAP_OK 783 ret false 784 end 785 req = new CapMint 0 0 0 0 0 0 0 0 0 786 note Capability carrying CAP_RIGHT_EPOCH on non-authority resource 0x999 787 mk_root_req 8 0x999 CAP_RIGHT_EPOCH 0 off req 788 ctrl = new CapRef 0 0 789 if ne cap_mint req ctrl CAP_OK 790 ret false 791 end 792 if ne cap_bump_epoch ctrl CAP_ERR_RESOURCE 793 ret false 794 end 795 ret true 796 end 797 798 fn test_18_office_token_auth_and_rotation to bool 799 if ne cap_start CAP_OK 800 ret false 801 end 802 t1 = new uchar 32 0 803 cap_copy_token t1 804 if ne cap_authorize t1 CAP_OK 805 ret false 806 end 807 note Flip 1 bit -> must fail closed 808 bad = new uchar 32 0 809 for i ulong 32 810 put bad i get t1 i 811 end 812 put bad 15 xor get bad 15 1 813 if ne cap_authorize bad CAP_ERR_UNAUTHORIZED 814 ret false 815 end 816 note Restart rotates token -> old token rejected, new token accepted 817 if ne cap_restart CAP_OK 818 ret false 819 end 820 if ne cap_authorize t1 CAP_ERR_UNAUTHORIZED 821 ret false 822 end 823 t2 = new uchar 32 0 824 cap_copy_token t2 825 if ne cap_authorize t2 CAP_OK 826 ret false 827 end 828 ret true 829 end 830 831 fn main to int 832 failed = uint 0 833 failed = add failed report s_t01 test_01_high_half_resource 834 failed = add failed report s_t02 test_02_forged_stale_fail_closed 835 failed = add failed report s_t03 test_03_amplification_lease_epoch_revoke 836 failed = add failed report s_t04 test_04_child_lease_bound 837 failed = add failed report s_t05 test_05_privileged_not_delegable 838 failed = add failed report s_t06 test_06_promote_not_delegable 839 failed = add failed report s_t07 test_07_generation_exhaustion 840 failed = add failed report s_t08 test_08_kill_restart_cognition 841 failed = add failed report s_t09 test_09_reclaimed_stays_dead_after_restart 842 failed = add failed report s_t10 test_10_gen_above_32_bits 843 failed = add failed report s_t11 test_11_ordinary_no_admin_and_depth 844 failed = add failed report s_t12 test_12_table_fills_then_refuses 845 failed = add failed report s_t13 test_13_observer_semantics 846 failed = add failed report s_t14 test_14_validate_needs_all_rights 847 failed = add failed report s_t15 test_15_lease_exact_tick_and_overflow 848 failed = add failed report s_t16 test_16_corrupt_non_live_parent 849 failed = add failed report s_t17 test_17_control_resource_cannot_admin 850 failed = add failed report s_t18 test_18_office_token_auth_and_rotation 851 if eq failed 0 852 w = cap_write_all 1 s_sum 853 if w 854 ret 0 855 end 856 ret 1 857 end 858 w = cap_write_all 1 s_fsum 859 if w 860 ret 1 861 end 862 ret 1 863 end