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/argus/bridge.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 / argus / bridge.om` 561 lines ยท 14149 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/argus/bridge.om: Pure-Omega ARGUS-AEGIS Bridge. 3 note Converted from upstream aienux native/argus/bridge/argus_aegis_bridge.{h,c}. 4 note Compose with: si/directives/om2.om aienux/argus/event.om aienux/argus/contain.om aienux/argus/bridge.om om/tls/sha2.om 5 6 const BRIDGE_REQUESTS ulong 32 7 const BRIDGE_FINDINGS ulong 128 8 const ARGUS_FLAG_STREAM_SHIFT ushort 2 9 const ARGUS_STREAM_BRIDGE ushort 16383 10 const BRIDGE_STREAM_FLAGS ushort 0xfffc 11 12 const BRIDGE_OBS_MINT uint 1 13 const BRIDGE_OBS_REVOKE uint 2 14 const BRIDGE_CAP_OK int 0 15 16 const BRIDGE_SUBJ_AEGIS uint 41 17 const BRIDGE_SUBJ_AEGIS_ROOT uint 42 18 const BRIDGE_SUBJ_CONTAIN uint 43 19 20 const BRIDGE_GATE_BUDGET ulong 8 21 const BRIDGE_GATE_WINDOW ulong 64 22 23 const BRIDGE_WHY_POLICY_GRANT ushort 1100 24 const BRIDGE_WHY_POLICY_DENY ushort 1101 25 const BRIDGE_WHY_POLICY_ESCALATE ushort 1102 26 const BRIDGE_WHY_PROTECTED ushort 1103 27 const BRIDGE_WHY_NOT_LIVE ushort 1104 28 const BRIDGE_WHY_SUBJECT_MISMATCH ushort 1105 29 const BRIDGE_WHY_BUDGET ushort 1107 30 const BRIDGE_WHY_BAD_REQUEST ushort 1108 31 const BRIDGE_WHY_NO_EXECUTOR ushort 1109 32 const BRIDGE_WHY_NOT_AUTO_ELIGIBLE ushort 1116 33 34 note Bridge state globals 35 global br_init uchar 1 36 global br_attached uchar 1 37 global br_mach uchar 32 38 global br_seq ulong 1 39 global br_err int 1 40 global br_clock ulong 1 41 42 note Saved BridgeRequest slots (32 entries, indexed by request_id % 32) 43 global br_req_id ulong 32 44 global br_req_mach uchar 1024 45 global br_req_dig uchar 1024 46 47 note Queued ArgusFinding ring (128 entries) 48 global br_find_cnt ulong 1 49 global br_f_code ushort 128 50 global br_f_sev uchar 128 51 global br_f_conf uchar 128 52 global br_f_sync uchar 128 53 global br_f_cont uchar 128 54 global br_f_det ushort 128 55 global br_f_seq ulong 128 56 global br_f_pseq ulong 128 57 global br_f_princ uint 128 58 global br_f_cid uint 128 59 global br_f_cgen ulong 128 60 61 note AEGIS containment gate state (coupled to bridge) 62 global br_gate_seq ulong 1 63 global br_gate_dec_id ulong 1 64 global br_gate_inert uchar 1 65 global br_gate_grants ulong 1 66 global br_gate_decs ulong 1 67 global br_gate_pol uchar 11 68 global br_gate_last_st uchar 1 69 global br_gate_last_why ushort 1 70 global br_gate_last_est uchar 1 71 global br_gate_last_erc int 1 72 global br_gate_last_rev uint 1 73 74 note Receipt staging buffer for receipt_sink (avoids >6 params) 75 global br_rcp_kind ushort 1 76 global br_rcp_st uchar 1 77 global br_rcp_typ uchar 1 78 global br_rcp_fcode ushort 1 79 global br_rcp_rid ulong 1 80 global br_rcp_princ uint 1 81 global br_rcp_cid uint 1 82 global br_rcp_cgen ulong 1 83 global br_rcp_res ulong 1 84 global br_rcp_why ushort 1 85 global br_rcp_rc int 1 86 global br_rcp_flags ushort 1 87 global br_rcp_dig uchar 32 88 89 fn br_zero_digest d view uchar 32 to bool 90 v = uchar 0 91 for i ulong 32 92 v = or v get d i 93 end 94 ret eq v 0 95 end 96 97 fn argus_bridge_init mach view uchar 32 to int 98 for i ulong 32 99 put br_mach i get mach i 100 put br_req_id i 0 101 end 102 for i ulong 1024 103 put br_req_mach i 0 104 put br_req_dig i 0 105 end 106 for i ulong 128 107 put br_f_code i 0 108 put br_f_sev i 0 109 put br_f_conf i 0 110 put br_f_sync i 0 111 put br_f_cont i 0 112 put br_f_det i 0 113 put br_f_seq i 0 114 put br_f_pseq i 0 115 put br_f_princ i 0 116 put br_f_cid i 0 117 put br_f_cgen i 0 118 end 119 for i ulong 11 120 put br_gate_pol i ARGUS_CSTATUS_ESCALATE 121 end 122 put br_gate_pol 1 ARGUS_CSTATUS_GRANT 123 put br_seq 0 1 124 put br_err 0 ARGUS_OK 125 put br_attached 0 0 126 put br_clock 0 0 127 put br_find_cnt 0 0 128 put br_gate_seq 0 1 129 put br_gate_dec_id 0 1 130 put br_gate_inert 0 0 131 put br_gate_grants 0 0 132 put br_gate_decs 0 0 133 put br_gate_last_st 0 0 134 put br_gate_last_why 0 0 135 put br_gate_last_est 0 0 136 put br_gate_last_erc 0 0 137 put br_gate_last_rev 0 0 138 put br_init 0 1 139 ret ARGUS_OK 140 end 141 142 fn argus_bridge_destroy to void 143 put br_init 0 0 144 put br_attached 0 0 145 end 146 147 fn argus_bridge_attach_gate to int 148 if eq get br_init 0 0 149 ret ARGUS_ERR_ARG 150 end 151 put br_attached 0 1 152 ret ARGUS_OK 153 end 154 155 fn argus_bridge_set_clock tick ulong to void 156 put br_clock 0 tick 157 end 158 159 fn argus_bridge_set_policy ctype uchar verdict uchar to void 160 if and ge ctype 1 le ctype ARGUS_CONTAIN_MAX 161 put br_gate_pol ulong ctype verdict 162 end 163 end 164 165 fn argus_bridge_set_inert v uchar to void 166 put br_gate_inert 0 v 167 end 168 169 fn argus_bridge_error to int 170 if eq get br_init 0 0 171 ret ARGUS_ERR_ARG 172 end 173 ret get br_err 0 174 end 175 176 fn argus_bridge_finding_count to ulong 177 ret get br_find_cnt 0 178 end 179 180 fn argus_bridge_append_finding f view ArgusFinding to int 181 cnt = get br_find_cnt 0 182 if ge cnt BRIDGE_FINDINGS 183 ret ARGUS_ERR_OVERFLOW 184 end 185 put br_f_code cnt get f code 186 put br_f_sev cnt get f severity 187 put br_f_conf cnt get f confidence 188 put br_f_sync cnt get f sync_allowed 189 put br_f_cont cnt get f containment 190 put br_f_det cnt get f detector 191 put br_f_seq cnt get f sequence 192 put br_f_pseq cnt get f prior_sequence 193 put br_f_princ cnt get f principal 194 put br_f_cid cnt get f cap_id 195 put br_f_cgen cnt get f cap_generation 196 put br_find_cnt 0 add cnt 1 197 ret ARGUS_OK 198 end 199 200 fn argus_bridge_take_finding dst edit ArgusFinding to bool 201 cnt = get br_find_cnt 0 202 if eq cnt 0 203 ret false 204 end 205 put dst code get br_f_code 0 206 put dst severity get br_f_sev 0 207 put dst confidence get br_f_conf 0 208 put dst sync_allowed get br_f_sync 0 209 put dst containment get br_f_cont 0 210 put dst detector get br_f_det 0 211 put dst sequence get br_f_seq 0 212 put dst prior_sequence get br_f_pseq 0 213 put dst principal get br_f_princ 0 214 put dst cap_id get br_f_cid 0 215 put dst cap_generation get br_f_cgen 0 216 rem_cnt = sub cnt 1 217 i = ulong 0 218 while lt i rem_cnt bound 128 219 nxt = add i 1 220 put br_f_code i get br_f_code nxt 221 put br_f_sev i get br_f_sev nxt 222 put br_f_conf i get br_f_conf nxt 223 put br_f_sync i get br_f_sync nxt 224 put br_f_cont i get br_f_cont nxt 225 put br_f_det i get br_f_det nxt 226 put br_f_seq i get br_f_seq nxt 227 put br_f_pseq i get br_f_pseq nxt 228 put br_f_princ i get br_f_princ nxt 229 put br_f_cid i get br_f_cid nxt 230 put br_f_cgen i get br_f_cgen nxt 231 i = nxt 232 end 233 put br_find_cnt 0 rem_cnt 234 ret true 235 end 236 237 fn br_find_req_slot rid ulong to int 238 for i ulong 32 239 if eq get br_req_id i rid 240 ret int i 241 end 242 end 243 ret -1 244 end 245 246 fn argus_bridge_ingest ev view ArgusEvent mach view uchar 32 evdig view uchar 32 to int 247 fcore = new ArgusFinding 0 0 0 0 0 0 0 0 0 0 0 248 fcont = new ArgusFinding 0 0 0 0 0 0 0 0 0 0 0 249 if eq get br_init 0 0 250 ret ARGUS_ERR_ARG 251 end 252 fc = argus_core_ingest ev mach evdig fcore 253 rc = ARGUS_OK 254 if ne fc ARGUS_F_NONE 255 rc = argus_bridge_append_finding fcore 256 if ne rc ARGUS_OK 257 put br_err 0 rc 258 ret rc 259 end 260 end 261 cc = argus_contain_observe ev evdig 262 if ne cc ARGUS_F_NONE 263 put fcont code cc 264 put fcont severity ARGUS_SEV_CRITICAL 265 put fcont confidence ARGUS_CONF_DETERMINISTIC 266 put fcont sync_allowed 0 267 put fcont containment ARGUS_CONTAIN_NONE 268 put fcont detector cc 269 put fcont sequence get ev sequence 270 put fcont prior_sequence 0 271 put fcont principal get ev principal 272 put fcont cap_id get ev cap_id 273 put fcont cap_generation get ev cap_generation 274 rc = argus_bridge_append_finding fcont 275 if ne rc ARGUS_OK 276 put br_err 0 rc 277 ret rc 278 end 279 end 280 ret ARGUS_OK 281 end 282 283 fn br_receipt_outcome st uchar rcode int to uchar 284 if or eq st ARGUS_CSTATUS_GRANT or eq st ARGUS_CSTATUS_DONE eq st ARGUS_CSTATUS_PARTIAL 285 ret ARGUS_OUTCOME_OK 286 end 287 if eq st ARGUS_CSTATUS_DENY 288 ret ARGUS_OUTCOME_DENIED 289 end 290 if and eq st ARGUS_CSTATUS_FAILED lt rcode 0 291 ret ARGUS_OUTCOME_DENIED 292 end 293 ret ARGUS_OUTCOME_ERROR 294 end 295 296 fn br_receipt_sink to void 297 ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 298 mach = new uchar 32 0 299 evdig = new uchar 32 0 300 if eq get br_init 0 0 301 ret 302 end 303 seq = get br_seq 0 304 if or eq seq 0 eq seq ARGUS_U64_MAX 305 put br_err 0 ARGUS_ERR_FULL 306 ret 307 end 308 rid = get br_rcp_rid 0 309 slot = br_find_req_slot rid 310 if lt slot 0 311 put br_err 0 ARGUS_ERR_STATE 312 ret 313 end 314 put br_seq 0 add seq 1 315 st = get br_rcp_st 0 316 kd = get br_rcp_kind 0 317 ev_code = get br_rcp_rc 0 318 if eq kd ARGUS_EV_CONTAINMENT_DECIDED 319 ev_code = int get br_rcp_why 0 320 end 321 ev_flags = BRIDGE_STREAM_FLAGS 322 if ne and get br_rcp_flags 0 ARGUS_CREQ_SYNTHETIC 0 323 ev_flags = or ev_flags ARGUS_FLAG_SYNTHETIC 324 end 325 put ev version ARGUS_ABI_VERSION 326 put ev class_ ARGUS_CLASS_CRITICAL 327 put ev kind kd 328 put ev effect_class ARGUS_EFFECT_NONE 329 put ev outcome br_receipt_outcome st get br_rcp_rc 0 330 put ev flags ev_flags 331 put ev sequence seq 332 put ev tick get br_clock 0 333 put ev principal get br_rcp_princ 0 334 put ev code ev_code 335 put ev cap_id get br_rcp_cid 0 336 put ev object_id argus_contain_pack get br_rcp_typ 0 st get br_rcp_fcode 0 337 put ev cap_generation get br_rcp_cgen 0 338 put ev world_generation rid 339 put ev resource get br_rcp_res 0 340 base = mul ulong slot 32 341 for i ulong 32 342 put mach i get br_req_mach add base i 343 put evdig i get br_rcp_dig i 344 end 345 irc = argus_bridge_ingest ev mach evdig 346 if and ne irc ARGUS_OK ne irc ARGUS_ERR_FULL 347 put br_err 0 irc 348 end 349 end 350 351 fn br_ingest_rec ev view ArgusEvent mach view uchar 32 evdig view uchar 32 to void 352 irc = argus_bridge_ingest ev mach evdig 353 if and ne irc ARGUS_OK ne irc ARGUS_ERR_FULL 354 put br_err 0 irc 355 end 356 end 357 358 fn argus_bridge_observer op uint cap_id uint cap_gen ulong subj uint rights uint res ulong to void 359 ev = new ArgusEvent 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 360 mach = new uchar 32 0 361 evdig = new uchar 32 0 362 if eq get br_init 0 0 363 ret 364 end 365 if and ne op BRIDGE_OBS_MINT ne op BRIDGE_OBS_REVOKE 366 ret 367 end 368 seq = get br_seq 0 369 if or eq seq 0 eq seq ARGUS_U64_MAX 370 put br_err 0 ARGUS_ERR_FULL 371 ret 372 end 373 put br_seq 0 add seq 1 374 put ev version ARGUS_ABI_VERSION 375 if eq op BRIDGE_OBS_MINT 376 put ev class_ ARGUS_CLASS_SECURITY 377 put ev kind ARGUS_EV_CAPABILITY_GRANTED 378 else 379 put ev class_ ARGUS_CLASS_CRITICAL 380 put ev kind ARGUS_EV_CAPABILITY_REVOKED 381 end 382 put ev effect_class ARGUS_EFFECT_NONE 383 put ev outcome ARGUS_OUTCOME_OK 384 put ev flags BRIDGE_STREAM_FLAGS 385 put ev sequence seq 386 put ev tick get br_clock 0 387 put ev principal subj 388 put ev code 0 389 put ev cap_id cap_id 390 put ev object_id rights 391 put ev cap_generation cap_gen 392 put ev world_generation 0 393 put ev resource res 394 for i ulong 32 395 put mach i get br_mach i 396 end 397 br_ingest_rec ev mach evdig 398 end 399 400 fn br_gate_is_protected subj uint to bool 401 if or eq subj BRIDGE_SUBJ_AEGIS or eq subj BRIDGE_SUBJ_AEGIS_ROOT eq subj BRIDGE_SUBJ_CONTAIN 402 ret true 403 end 404 ret false 405 end 406 407 fn br_gate_decide req view ArgusContainReq to void 408 decs = get br_gate_decs 0 409 if ge decs BRIDGE_GATE_WINDOW 410 put br_gate_decs 0 0 411 put br_gate_grants 0 0 412 end 413 put br_gate_decs 0 add get br_gate_decs 0 1 414 ct = get req containment 415 if or lt ct 1 gt ct ARGUS_CONTAIN_MAX 416 put br_gate_last_st 0 ARGUS_CSTATUS_DENY 417 put br_gate_last_why 0 BRIDGE_WHY_BAD_REQUEST 418 ret 419 end 420 if ne get br_gate_inert 0 0 421 put br_gate_last_st 0 ARGUS_CSTATUS_ESCALATE 422 put br_gate_last_why 0 BRIDGE_WHY_POLICY_ESCALATE 423 ret 424 end 425 if br_gate_is_protected get req principal 426 put br_gate_last_st 0 ARGUS_CSTATUS_DENY 427 put br_gate_last_why 0 BRIDGE_WHY_PROTECTED 428 ret 429 end 430 pol = get br_gate_pol ulong ct 431 if eq pol ARGUS_CSTATUS_DENY 432 put br_gate_last_st 0 ARGUS_CSTATUS_DENY 433 put br_gate_last_why 0 BRIDGE_WHY_POLICY_DENY 434 ret 435 end 436 if ne ct ARGUS_CONTAIN_REVOKE_CAPABILITY 437 put br_gate_last_st 0 ARGUS_CSTATUS_ESCALATE 438 put br_gate_last_why 0 BRIDGE_WHY_NO_EXECUTOR 439 ret 440 end 441 if ne and get req flags ARGUS_CREQ_KNOWN 0 442 put br_gate_last_st 0 ARGUS_CSTATUS_ESCALATE 443 put br_gate_last_why 0 BRIDGE_WHY_NOT_AUTO_ELIGIBLE 444 ret 445 end 446 cid = get req target_cap_id 447 if ge cid ARGUS_CAP_MAX 448 put br_gate_last_st 0 ARGUS_CSTATUS_DENY 449 put br_gate_last_why 0 BRIDGE_WHY_NOT_LIVE 450 ret 451 end 452 idx = ulong cid 453 if ne get argus_sh_state idx ARGUS_SH_LIVE 454 put br_gate_last_st 0 ARGUS_CSTATUS_DENY 455 put br_gate_last_why 0 BRIDGE_WHY_NOT_LIVE 456 ret 457 end 458 if ne get argus_sh_gen idx get req target_cap_gen 459 put br_gate_last_st 0 ARGUS_CSTATUS_DENY 460 put br_gate_last_why 0 BRIDGE_WHY_NOT_LIVE 461 ret 462 end 463 if ne get argus_sh_subj idx get req principal 464 put br_gate_last_st 0 ARGUS_CSTATUS_DENY 465 put br_gate_last_why 0 BRIDGE_WHY_SUBJECT_MISMATCH 466 ret 467 end 468 if ge get br_gate_grants 0 BRIDGE_GATE_BUDGET 469 put br_gate_last_st 0 ARGUS_CSTATUS_ESCALATE 470 put br_gate_last_why 0 BRIDGE_WHY_BUDGET 471 ret 472 end 473 if ne pol ARGUS_CSTATUS_GRANT 474 put br_gate_last_st 0 ARGUS_CSTATUS_ESCALATE 475 put br_gate_last_why 0 BRIDGE_WHY_POLICY_ESCALATE 476 ret 477 end 478 put br_gate_grants 0 add get br_gate_grants 0 1 479 put br_gate_last_st 0 ARGUS_CSTATUS_GRANT 480 put br_gate_last_why 0 BRIDGE_WHY_POLICY_GRANT 481 end 482 483 fn br_stage_receipt kd ushort st uchar req view ArgusContainReq dig view uchar 32 res ulong to void 484 put br_rcp_kind 0 kd 485 put br_rcp_st 0 st 486 put br_rcp_typ 0 get req containment 487 put br_rcp_fcode 0 get req finding_code 488 put br_rcp_rid 0 get req request_id 489 put br_rcp_princ 0 get req principal 490 put br_rcp_cid 0 get req target_cap_id 491 put br_rcp_cgen 0 get req target_cap_gen 492 put br_rcp_res 0 res 493 put br_rcp_flags 0 get req flags 494 for i ulong 32 495 put br_rcp_dig i get dig i 496 end 497 end 498 499 fn br_save_req rid ulong mach view uchar 32 tdig view uchar 32 dig view uchar 32 to void 500 slot = rem rid BRIDGE_REQUESTS 501 put br_req_id slot rid 502 base = mul slot 32 503 use_tdig = br_zero_digest mach 504 for i ulong 32 505 if use_tdig 506 put br_req_mach add base i get tdig i 507 else 508 put br_req_mach add base i get mach i 509 end 510 put br_req_dig add base i get dig i 511 end 512 end 513 514 fn br_execute_grant req view ArgusContainReq dig view uchar 32 to void 515 argus_bridge_observer BRIDGE_OBS_REVOKE get req target_cap_id get req target_cap_gen get req principal 0 0 516 put br_gate_seq 0 add get br_gate_seq 0 1 517 put br_gate_last_est 0 ARGUS_CSTATUS_DONE 518 put br_gate_last_erc 0 0 519 put br_gate_last_rev 0 1 520 put br_rcp_why 0 0 521 put br_rcp_rc 0 0 522 br_stage_receipt ARGUS_EV_CONTAINMENT_EXECUTED ARGUS_CSTATUS_DONE req dig 1 523 br_receipt_sink 524 end 525 526 fn argus_bridge_submit req view ArgusContainReq mach view uchar 32 fdig view uchar 32 tdig view uchar 32 to int 527 dig = new uchar 32 0 528 if or eq get br_init 0 0 eq get br_attached 0 0 529 ret ARGUS_ERR_ARG 530 end 531 argus_creq_digest req mach fdig tdig dig 532 br_save_req get req request_id mach tdig dig 533 br_gate_decide req 534 did = get br_gate_dec_id 0 535 put br_gate_dec_id 0 add did 1 536 put br_gate_seq 0 add get br_gate_seq 0 1 537 dst = get br_gate_last_st 0 538 put br_rcp_why 0 get br_gate_last_why 0 539 put br_rcp_rc 0 0 540 br_stage_receipt ARGUS_EV_CONTAINMENT_DECIDED dst req dig did 541 br_receipt_sink 542 put br_gate_last_est 0 0 543 put br_gate_last_erc 0 0 544 put br_gate_last_rev 0 0 545 if eq dst ARGUS_CSTATUS_GRANT 546 br_execute_grant req dig 547 end 548 ret argus_bridge_error 549 end 550 551 fn argus_bridge_last_decision to uchar 552 ret get br_gate_last_st 0 553 end 554 555 fn argus_bridge_last_why to ushort 556 ret get br_gate_last_why 0 557 end 558 559 fn argus_bridge_last_exec_status to uchar 560 ret get br_gate_last_est 0 561 end