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
omega-mv / aienux / argus / contain.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note aienux/argus/contain.om: Pure-Omega ARGUS Deterministic Shadow-State Core, |
| 3 | note Hard-Invariant Detectors, and Containment State Machine (Invariants I1..I5). |
| 4 | note Converted from upstream aienux native/argus/argus_core.c, argus_detect.c, and argus_contain.c. |
| 5 | |
| 6 | note Shadow capability slot states |
| 7 | const ARGUS_SH_UNSEEN uchar 0 |
| 8 | const ARGUS_SH_LIVE uchar 1 |
| 9 | const ARGUS_SH_REVOKED uchar 2 |
| 10 | |
| 11 | note Containment pending states |
| 12 | const ARGUS_ST_FREE uchar 0 |
| 13 | const ARGUS_ST_PROPOSED uchar 1 |
| 14 | const ARGUS_ST_GRANTED uchar 2 |
| 15 | const ARGUS_ST_ESCALATED uchar 3 |
| 16 | const ARGUS_ST_CONFIRMED uchar 4 |
| 17 | const ARGUS_ST_DENIED uchar 5 |
| 18 | const ARGUS_ST_FAILED uchar 6 |
| 19 | const ARGUS_ST_FAILED_SCOPE uchar 7 |
| 20 | const ARGUS_ST_EXPIRED uchar 8 |
| 21 | |
| 22 | const ARGUS_CONTAIN_PENDING ulong 32 |
| 23 | const ARGUS_CONTAIN_WINDOW_EVENTS ulong 4096 |
| 24 | const ARGUS_CONTAIN_WINDOW_MAX uint 16 |
| 25 | const ARGUS_STREAMS_MAX ulong 32 |
| 26 | const ARGUS_WORLDS_MAX ulong 8 |
| 27 | |
| 28 | note Shadow capability table (256 slots) |
| 29 | global argus_sh_state uchar 256 |
| 30 | global argus_sh_gen ulong 256 |
| 31 | global argus_sh_subj uint 256 |
| 32 | global argus_sh_rgt uint 256 |
| 33 | global argus_sh_res ulong 256 |
| 34 | global argus_sh_seq ulong 256 |
| 35 | |
| 36 | note Producer sequence stream table (32 streams) |
| 37 | global argus_strm_used uchar 32 |
| 38 | global argus_strm_key uint 32 |
| 39 | global argus_strm_seq ulong 32 |
| 40 | |
| 41 | note World lineage table (8 stores) |
| 42 | global argus_wld_used uchar 8 |
| 43 | global argus_wld_id uint 8 |
| 44 | global argus_wld_gen ulong 8 |
| 45 | |
| 46 | note Core health & SHA-256 event hash chain |
| 47 | note meta: 0=received, 1=rejected, 2=findings, 3=not_applied |
| 48 | global argus_core_meta ulong 8 |
| 49 | global argus_core_chain uchar 32 |
| 50 | |
| 51 | note Containment state machine globals (32 pending slots) |
| 52 | note cmeta: 0=events, 1=next_req_id, 2=win_start, 3=win_count |
| 53 | global argus_cmeta ulong 8 |
| 54 | note chealth: 0=proposed, 1=granted, 2=denied, 3=escalated, 4=confirmed, |
| 55 | note 5=failed_scope, 6=unmatched, 7=unauth, 8=unconfirmed, 9=rate_limited |
| 56 | global argus_chealth ulong 10 |
| 57 | |
| 58 | global argus_pend_st uchar 32 |
| 59 | global argus_pend_typ uchar 32 |
| 60 | global argus_pend_fcode ushort 32 |
| 61 | global argus_pend_princ uint 32 |
| 62 | global argus_pend_cid uint 32 |
| 63 | global argus_pend_cgen ulong 32 |
| 64 | global argus_pend_rid ulong 32 |
| 65 | global argus_pend_k4 uchar 32 |
| 66 | note 32 pending slots * 32-byte canonical request digest = 1024 bytes |
| 67 | global argus_pend_dig uchar 1024 |
| 68 | |
| 69 | note ---- Core Initialization & Helpers ---- |
| 70 | |
| 71 | fn argus_core_init to void |
| 72 | for i ulong 256 |
| 73 | put argus_sh_state i ARGUS_SH_UNSEEN |
| 74 | put argus_sh_gen i 0 |
| 75 | put argus_sh_subj i 0 |
| 76 | put argus_sh_rgt i 0 |
| 77 | put argus_sh_res i 0 |
| 78 | put argus_sh_seq i 0 |
| 79 | end |
| 80 | for i ulong 32 |
| 81 | put argus_strm_used i 0 |
| 82 | put argus_strm_key i 0 |
| 83 | put argus_strm_seq i 0 |
| 84 | put argus_core_chain i 0 |
| 85 | end |
| 86 | for i ulong 8 |
| 87 | put argus_wld_used i 0 |
| 88 | put argus_wld_id i 0 |
| 89 | put argus_wld_gen i 0 |
| 90 | put argus_core_meta i 0 |
| 91 | end |
| 92 | end |
| 93 | |
| 94 | fn argus_core_get_chain dst edit uchar 32 to void |
| 95 | for i ulong 32 |
| 96 | put dst i get argus_core_chain i |
| 97 | end |
| 98 | end |
| 99 | |
| 100 | fn argus_core_not_applied to ulong |
| 101 | ret get argus_core_meta 3 |
| 102 | end |
| 103 | |
| 104 | fn argus_check_stream flags ushort seq ulong to bool |
| 105 | sid = uint argus_stream_of flags |
| 106 | is_cons = uint 0 |
| 107 | if ne and flags ARGUS_FLAG_CONSUMER 0 |
| 108 | is_cons = uint 1 |
| 109 | end |
| 110 | key = or shl sid 1 is_cons |
| 111 | for i ulong 32 |
| 112 | if ne get argus_strm_used i 0 |
| 113 | if eq get argus_strm_key i key |
| 114 | prev = get argus_strm_seq i |
| 115 | if le seq prev |
| 116 | ret false |
| 117 | end |
| 118 | put argus_strm_seq i seq |
| 119 | ret true |
| 120 | end |
| 121 | end |
| 122 | end |
| 123 | for i ulong 32 |
| 124 | if eq get argus_strm_used i 0 |
| 125 | put argus_strm_used i 1 |
| 126 | put argus_strm_key i key |
| 127 | put argus_strm_seq i seq |
| 128 | ret true |
| 129 | end |
| 130 | end |
| 131 | ret true |
| 132 | end |
| 133 | |
| 134 | fn argus_check_world_commit store_id uint wgen ulong to bool |
| 135 | for i ulong 8 |
| 136 | if ne get argus_wld_used i 0 |
| 137 | if eq get argus_wld_id i store_id |
| 138 | prev = get argus_wld_gen i |
| 139 | if ne wgen add prev 1 |
| 140 | ret false |
| 141 | end |
| 142 | put argus_wld_gen i wgen |
| 143 | ret true |
| 144 | end |
| 145 | end |
| 146 | end |
| 147 | for i ulong 8 |
| 148 | if eq get argus_wld_used i 0 |
| 149 | put argus_wld_used i 1 |
| 150 | put argus_wld_id i store_id |
| 151 | put argus_wld_gen i wgen |
| 152 | ret true |
| 153 | end |
| 154 | end |
| 155 | ret false |
| 156 | end |
| 157 | |
| 158 | fn argus_set_finding dst edit ArgusFinding fcode ushort sev uchar ev view ArgusEvent prior ulong to void |
| 159 | put dst code fcode |
| 160 | put dst severity sev |
| 161 | put dst confidence ARGUS_CONF_DETERMINISTIC |
| 162 | put dst sync_allowed 0 |
| 163 | put dst containment ARGUS_CONTAIN_NONE |
| 164 | put dst detector fcode |
| 165 | put dst sequence get ev sequence |
| 166 | put dst prior_sequence prior |
| 167 | put dst principal get ev principal |
| 168 | put dst cap_id get ev cap_id |
| 169 | put dst cap_generation get ev cap_generation |
| 170 | put argus_core_meta 2 add get argus_core_meta 2 1 |
| 171 | end |
| 172 | |
| 173 | fn argus_detect_cap_use ev view ArgusEvent dst edit ArgusFinding to ushort |
| 174 | if ne get ev outcome ARGUS_OUTCOME_OK |
| 175 | ret ARGUS_F_NONE |
| 176 | end |
| 177 | cid = get ev cap_id |
| 178 | if ge cid ARGUS_CAP_MAX |
| 179 | ret ARGUS_F_NONE |
| 180 | end |
| 181 | idx = ulong cid |
| 182 | st = get argus_sh_state idx |
| 183 | sgen = get argus_sh_gen idx |
| 184 | sseq = get argus_sh_seq idx |
| 185 | if eq st ARGUS_SH_UNSEEN |
| 186 | argus_set_finding dst ARGUS_F_FORGED_CAPABILITY ARGUS_SEV_CRITICAL ev 0 |
| 187 | put dst containment ARGUS_CONTAIN_REVOKE_CAPABILITY |
| 188 | ret ARGUS_F_FORGED_CAPABILITY |
| 189 | end |
| 190 | if eq st ARGUS_SH_REVOKED |
| 191 | if le get ev cap_generation sgen |
| 192 | argus_set_finding dst ARGUS_F_REVOKED_CAPABILITY_USED ARGUS_SEV_CRITICAL ev sseq |
| 193 | put dst containment ARGUS_CONTAIN_REVOKE_CAPABILITY |
| 194 | ret ARGUS_F_REVOKED_CAPABILITY_USED |
| 195 | end |
| 196 | argus_set_finding dst ARGUS_F_FORGED_CAPABILITY ARGUS_SEV_CRITICAL ev sseq |
| 197 | put dst containment ARGUS_CONTAIN_REVOKE_CAPABILITY |
| 198 | ret ARGUS_F_FORGED_CAPABILITY |
| 199 | end |
| 200 | note LIVE slot: check generation (summary checks world_generation as MIN) |
| 201 | chk_gen = get ev cap_generation |
| 202 | if eq get ev kind ARGUS_EV_CAPABILITY_USE_SUMMARY |
| 203 | chk_gen = get ev world_generation |
| 204 | end |
| 205 | if lt chk_gen sgen |
| 206 | argus_set_finding dst ARGUS_F_STALE_GENERATION ARGUS_SEV_CRITICAL ev sseq |
| 207 | put dst containment ARGUS_CONTAIN_REVOKE_CAPABILITY |
| 208 | ret ARGUS_F_STALE_GENERATION |
| 209 | end |
| 210 | if ne get ev principal get argus_sh_subj idx |
| 211 | argus_set_finding dst ARGUS_F_SUBJECT_MISMATCH ARGUS_SEV_HIGH ev sseq |
| 212 | put dst containment ARGUS_CONTAIN_REVOKE_CAPABILITY |
| 213 | ret ARGUS_F_SUBJECT_MISMATCH |
| 214 | end |
| 215 | ret ARGUS_F_NONE |
| 216 | end |
| 217 | |
| 218 | fn argus_core_apply ev view ArgusEvent dst edit ArgusFinding to ushort |
| 219 | k = get ev kind |
| 220 | if eq k ARGUS_EV_TELEMETRY_DROPPED |
| 221 | lost = get ev object_id |
| 222 | if or eq lost uint ARGUS_CLASS_CRITICAL eq lost uint ARGUS_CLASS_SECURITY |
| 223 | argus_set_finding dst ARGUS_F_TELEMETRY_LOSS ARGUS_SEV_CRITICAL ev 0 |
| 224 | ret ARGUS_F_TELEMETRY_LOSS |
| 225 | end |
| 226 | ret ARGUS_F_NONE |
| 227 | end |
| 228 | if eq k ARGUS_EV_CAPABILITY_GRANTED |
| 229 | cid = get ev cap_id |
| 230 | if ge cid ARGUS_CAP_MAX |
| 231 | ret ARGUS_F_NONE |
| 232 | end |
| 233 | idx = ulong cid |
| 234 | st = get argus_sh_state idx |
| 235 | if and ne st ARGUS_SH_UNSEEN le get ev cap_generation get argus_sh_gen idx |
| 236 | put argus_core_meta 3 add get argus_core_meta 3 1 |
| 237 | argus_set_finding dst ARGUS_F_AUTHORITY_REPLAY ARGUS_SEV_CRITICAL ev get argus_sh_seq idx |
| 238 | ret ARGUS_F_AUTHORITY_REPLAY |
| 239 | end |
| 240 | put argus_sh_state idx ARGUS_SH_LIVE |
| 241 | put argus_sh_gen idx get ev cap_generation |
| 242 | put argus_sh_subj idx get ev principal |
| 243 | put argus_sh_rgt idx get ev object_id |
| 244 | put argus_sh_res idx get ev resource |
| 245 | put argus_sh_seq idx get ev sequence |
| 246 | ret ARGUS_F_NONE |
| 247 | end |
| 248 | if eq k ARGUS_EV_CAPABILITY_REVOKED |
| 249 | cid = get ev cap_id |
| 250 | if ge cid ARGUS_CAP_MAX |
| 251 | ret ARGUS_F_NONE |
| 252 | end |
| 253 | idx = ulong cid |
| 254 | if eq get argus_sh_state idx ARGUS_SH_UNSEEN |
| 255 | put argus_core_meta 3 add get argus_core_meta 3 1 |
| 256 | argus_set_finding dst ARGUS_F_AUTHORITY_REPLAY ARGUS_SEV_CRITICAL ev 0 |
| 257 | ret ARGUS_F_AUTHORITY_REPLAY |
| 258 | end |
| 259 | put argus_sh_state idx ARGUS_SH_REVOKED |
| 260 | put argus_sh_gen idx get ev cap_generation |
| 261 | put argus_sh_seq idx get ev sequence |
| 262 | ret ARGUS_F_NONE |
| 263 | end |
| 264 | if or eq k ARGUS_EV_CAPABILITY_USED eq k ARGUS_EV_CAPABILITY_USE_SUMMARY |
| 265 | ret argus_detect_cap_use ev dst |
| 266 | end |
| 267 | if eq k ARGUS_EV_WORLD_COMMITTED |
| 268 | if not argus_check_world_commit get ev object_id get ev world_generation |
| 269 | put argus_core_meta 3 add get argus_core_meta 3 1 |
| 270 | argus_set_finding dst ARGUS_F_WORLD_PROVENANCE_INCONSISTENT ARGUS_SEV_CRITICAL ev 0 |
| 271 | ret ARGUS_F_WORLD_PROVENANCE_INCONSISTENT |
| 272 | end |
| 273 | ret ARGUS_F_NONE |
| 274 | end |
| 275 | ret ARGUS_F_NONE |
| 276 | end |
| 277 | |
| 278 | note Ingest one event: validate -> chain -> detect -> apply. |
| 279 | note Returns finding code (ARGUS_F_NONE if clean) and populates dst on finding. |
| 280 | fn argus_core_ingest ev view ArgusEvent mach view uchar 32 evdig view uchar 32 dst edit ArgusFinding to ushort |
| 281 | put argus_core_meta 0 add get argus_core_meta 0 1 |
| 282 | vrc = argus_event_validate ev |
| 283 | if ne vrc ARGUS_OK |
| 284 | put argus_core_meta 1 add get argus_core_meta 1 1 |
| 285 | put argus_core_meta 3 add get argus_core_meta 3 1 |
| 286 | argus_set_finding dst ARGUS_F_MALFORMED_EVENT ARGUS_SEV_HIGH ev 0 |
| 287 | ret ARGUS_F_MALFORMED_EVENT |
| 288 | end |
| 289 | note Extend SHA-256 event hash chain |
| 290 | tmp_chain = new uchar 32 0 |
| 291 | for i ulong 32 |
| 292 | put tmp_chain i get argus_core_chain i |
| 293 | end |
| 294 | argus_chain_extend tmp_chain ev mach evdig |
| 295 | for i ulong 32 |
| 296 | put argus_core_chain i get tmp_chain i |
| 297 | end |
| 298 | note Sequence monotonicity check: anomaly is detected and NOT applied |
| 299 | if not argus_check_stream get ev flags get ev sequence |
| 300 | put argus_core_meta 3 add get argus_core_meta 3 1 |
| 301 | argus_set_finding dst ARGUS_F_SEQUENCE_ANOMALY ARGUS_SEV_HIGH ev 0 |
| 302 | ret ARGUS_F_SEQUENCE_ANOMALY |
| 303 | end |
| 304 | ret argus_core_apply ev dst |
| 305 | end |
| 306 | |
| 307 | note ---- Containment State Machine (Invariants I1..I5) ---- |
| 308 | |
| 309 | fn argus_contain_init to void |
| 310 | for i ulong 8 |
| 311 | put argus_cmeta i 0 |
| 312 | end |
| 313 | put argus_cmeta 1 1 |
| 314 | for i ulong 10 |
| 315 | put argus_chealth i 0 |
| 316 | end |
| 317 | for i ulong 32 |
| 318 | put argus_pend_st i ARGUS_ST_FREE |
| 319 | put argus_pend_typ i 0 |
| 320 | put argus_pend_fcode i 0 |
| 321 | put argus_pend_princ i 0 |
| 322 | put argus_pend_cid i 0 |
| 323 | put argus_pend_cgen i 0 |
| 324 | put argus_pend_rid i 0 |
| 325 | put argus_pend_k4 i 0 |
| 326 | end |
| 327 | for i ulong 1024 |
| 328 | put argus_pend_dig i 0 |
| 329 | end |
| 330 | end |
| 331 | |
| 332 | fn argus_contain_health dst edit ArgusContainHealth to void |
| 333 | put dst proposed get argus_chealth 0 |
| 334 | put dst granted get argus_chealth 1 |
| 335 | put dst denied get argus_chealth 2 |
| 336 | put dst escalated get argus_chealth 3 |
| 337 | put dst confirmed get argus_chealth 4 |
| 338 | put dst failed_scope get argus_chealth 5 |
| 339 | put dst decisions_unmatched get argus_chealth 6 |
| 340 | put dst executions_unauthorized get argus_chealth 7 |
| 341 | put dst executions_unconfirmed get argus_chealth 8 |
| 342 | put dst rate_limited get argus_chealth 9 |
| 343 | end |
| 344 | |
| 345 | fn argus_pend_is_open st uchar to bool |
| 346 | ret or eq st ARGUS_ST_PROPOSED or eq st ARGUS_ST_GRANTED eq st ARGUS_ST_ESCALATED |
| 347 | end |
| 348 | |
| 349 | fn argus_pend_find_rid rid ulong to int |
| 350 | for i ulong 32 |
| 351 | if ne get argus_pend_st i ARGUS_ST_FREE |
| 352 | if eq get argus_pend_rid i rid |
| 353 | ret int i |
| 354 | end |
| 355 | end |
| 356 | end |
| 357 | ret -1 |
| 358 | end |
| 359 | |
| 360 | fn argus_pend_echo_matches slot ulong ev view ArgusEvent evdig view uchar 32 to bool |
| 361 | obj = get ev object_id |
| 362 | if ne argus_contain_type_of obj get argus_pend_typ slot |
| 363 | ret false |
| 364 | end |
| 365 | if ne argus_contain_code_of obj get argus_pend_fcode slot |
| 366 | ret false |
| 367 | end |
| 368 | if ne get ev principal get argus_pend_princ slot |
| 369 | ret false |
| 370 | end |
| 371 | if ne get ev cap_id get argus_pend_cid slot |
| 372 | ret false |
| 373 | end |
| 374 | if ne get ev cap_generation get argus_pend_cgen slot |
| 375 | ret false |
| 376 | end |
| 377 | if ne get ev world_generation get argus_pend_rid slot |
| 378 | ret false |
| 379 | end |
| 380 | base = mul slot 32 |
| 381 | diff = uchar 0 |
| 382 | for i ulong 32 |
| 383 | diff = or diff xor get argus_pend_dig add base i get evdig i |
| 384 | end |
| 385 | ret eq diff 0 |
| 386 | end |
| 387 | |
| 388 | note Propose a containment request: enforces I1.c, I2, I3.b, computes canonical 152-byte digest. |
| 389 | fn argus_contain_propose req edit ArgusContainReq mach view uchar 32 fdig view uchar 32 tdig view uchar 32 dig_out edit uchar 32 to int |
| 390 | ct = get req containment |
| 391 | if or lt ct 1 gt ct ARGUS_CONTAIN_MAX |
| 392 | ret ARGUS_ERR_MALFORMED |
| 393 | end |
| 394 | if eq get req finding_sequence 0 |
| 395 | ret ARGUS_ERR_MALFORMED |
| 396 | end |
| 397 | note I2: only REVOKE_CAPABILITY has a live executor; non-live types require SYNTHETIC |
| 398 | if ne ct ARGUS_CONTAIN_REVOKE_CAPABILITY |
| 399 | if eq and get req flags ARGUS_CREQ_SYNTHETIC 0 |
| 400 | ret ARGUS_ERR_MALFORMED |
| 401 | end |
| 402 | end |
| 403 | note I3.b: global proposal budget per window |
| 404 | wcnt = get argus_cmeta 3 |
| 405 | if ge wcnt ulong ARGUS_CONTAIN_WINDOW_MAX |
| 406 | put argus_chealth 9 add get argus_chealth 9 1 |
| 407 | ret ARGUS_ERR_FULL |
| 408 | end |
| 409 | slot = int -1 |
| 410 | for i ulong 32 |
| 411 | if eq get argus_pend_st i ARGUS_ST_FREE |
| 412 | slot = int i |
| 413 | break |
| 414 | end |
| 415 | end |
| 416 | if lt slot 0 |
| 417 | ret ARGUS_ERR_FULL |
| 418 | end |
| 419 | rid = get argus_cmeta 1 |
| 420 | put argus_cmeta 1 add rid 1 |
| 421 | put req request_id rid |
| 422 | put req version ARGUS_CONTAIN_REQ_VERSION |
| 423 | put req reserved 0 |
| 424 | argus_creq_digest req mach fdig tdig dig_out |
| 425 | idx = ulong slot |
| 426 | put argus_pend_st idx ARGUS_ST_PROPOSED |
| 427 | put argus_pend_typ idx ct |
| 428 | put argus_pend_fcode idx get req finding_code |
| 429 | put argus_pend_princ idx get req principal |
| 430 | put argus_pend_cid idx get req target_cap_id |
| 431 | put argus_pend_cgen idx get req target_cap_gen |
| 432 | put argus_pend_rid idx rid |
| 433 | put argus_pend_k4 idx 0 |
| 434 | base = mul idx 32 |
| 435 | for i ulong 32 |
| 436 | put argus_pend_dig add base i get dig_out i |
| 437 | end |
| 438 | put argus_cmeta 3 add wcnt 1 |
| 439 | put argus_chealth 0 add get argus_chealth 0 1 |
| 440 | ret ARGUS_OK |
| 441 | end |
| 442 | |
| 443 | fn argus_contain_observe_revoke ev view ArgusEvent to ushort |
| 444 | cid = get ev cap_id |
| 445 | cgen = get ev cap_generation |
| 446 | for i ulong 32 |
| 447 | st = get argus_pend_st i |
| 448 | if argus_pend_is_open st |
| 449 | if and eq get argus_pend_cid i cid eq get argus_pend_cgen i cgen |
| 450 | if ne st ARGUS_ST_GRANTED |
| 451 | put argus_chealth 7 add get argus_chealth 7 1 |
| 452 | ret ARGUS_F_CONTAINMENT_EXECUTION_UNAUTHORIZED |
| 453 | end |
| 454 | k4 = add get argus_pend_k4 i 1 |
| 455 | put argus_pend_k4 i k4 |
| 456 | if gt k4 1 |
| 457 | put argus_pend_st i ARGUS_ST_FAILED_SCOPE |
| 458 | put argus_chealth 5 add get argus_chealth 5 1 |
| 459 | ret ARGUS_F_CONTAINMENT_SCOPE_EXCEEDED |
| 460 | end |
| 461 | ret ARGUS_F_NONE |
| 462 | end |
| 463 | end |
| 464 | end |
| 465 | ret ARGUS_F_NONE |
| 466 | end |
| 467 | |
| 468 | fn argus_contain_observe_decided idx ulong ev view ArgusEvent to ushort |
| 469 | st = get argus_pend_st idx |
| 470 | cst = argus_contain_status_of get ev object_id |
| 471 | if eq st ARGUS_ST_PROPOSED |
| 472 | if eq cst ARGUS_CSTATUS_GRANT |
| 473 | put argus_pend_st idx ARGUS_ST_GRANTED |
| 474 | put argus_chealth 1 add get argus_chealth 1 1 |
| 475 | ret ARGUS_F_NONE |
| 476 | end |
| 477 | if eq cst ARGUS_CSTATUS_DENY |
| 478 | put argus_pend_st idx ARGUS_ST_DENIED |
| 479 | put argus_chealth 2 add get argus_chealth 2 1 |
| 480 | ret ARGUS_F_NONE |
| 481 | end |
| 482 | if eq cst ARGUS_CSTATUS_ESCALATE |
| 483 | put argus_pend_st idx ARGUS_ST_ESCALATED |
| 484 | put argus_chealth 3 add get argus_chealth 3 1 |
| 485 | ret ARGUS_F_NONE |
| 486 | end |
| 487 | end |
| 488 | if eq st ARGUS_ST_ESCALATED |
| 489 | if eq cst ARGUS_CSTATUS_GRANT |
| 490 | put argus_pend_st idx ARGUS_ST_GRANTED |
| 491 | put argus_chealth 1 add get argus_chealth 1 1 |
| 492 | ret ARGUS_F_NONE |
| 493 | end |
| 494 | if eq cst ARGUS_CSTATUS_DENY |
| 495 | put argus_pend_st idx ARGUS_ST_DENIED |
| 496 | put argus_chealth 2 add get argus_chealth 2 1 |
| 497 | ret ARGUS_F_NONE |
| 498 | end |
| 499 | end |
| 500 | put argus_chealth 6 add get argus_chealth 6 1 |
| 501 | ret ARGUS_F_CONTAINMENT_DECISION_UNMATCHED |
| 502 | end |
| 503 | |
| 504 | fn argus_contain_observe_executed idx ulong ev view ArgusEvent to ushort |
| 505 | st = get argus_pend_st idx |
| 506 | cst = argus_contain_status_of get ev object_id |
| 507 | if ne st ARGUS_ST_GRANTED |
| 508 | if or eq cst ARGUS_CSTATUS_DONE eq cst ARGUS_CSTATUS_PARTIAL |
| 509 | put argus_chealth 7 add get argus_chealth 7 1 |
| 510 | ret ARGUS_F_CONTAINMENT_EXECUTION_UNAUTHORIZED |
| 511 | end |
| 512 | put argus_chealth 6 add get argus_chealth 6 1 |
| 513 | ret ARGUS_F_CONTAINMENT_DECISION_UNMATCHED |
| 514 | end |
| 515 | lo32 = uint and get ev resource 0xffffffff |
| 516 | bad_scope = eq cst ARGUS_CSTATUS_FAILED_SCOPE |
| 517 | if and eq cst ARGUS_CSTATUS_DONE ne lo32 1 |
| 518 | bad_scope = true |
| 519 | end |
| 520 | if and eq cst ARGUS_CSTATUS_PARTIAL gt lo32 1 |
| 521 | bad_scope = true |
| 522 | end |
| 523 | if bad_scope |
| 524 | put argus_pend_st idx ARGUS_ST_FAILED_SCOPE |
| 525 | put argus_chealth 5 add get argus_chealth 5 1 |
| 526 | ret ARGUS_F_CONTAINMENT_SCOPE_EXCEEDED |
| 527 | end |
| 528 | if eq cst ARGUS_CSTATUS_DONE |
| 529 | if eq get argus_pend_k4 idx 1 |
| 530 | put argus_pend_st idx ARGUS_ST_CONFIRMED |
| 531 | put argus_chealth 4 add get argus_chealth 4 1 |
| 532 | ret ARGUS_F_NONE |
| 533 | end |
| 534 | put argus_chealth 8 add get argus_chealth 8 1 |
| 535 | ret ARGUS_F_CONTAINMENT_EXECUTION_UNCONFIRMED |
| 536 | end |
| 537 | if or eq cst ARGUS_CSTATUS_FAILED eq cst ARGUS_CSTATUS_UNAVAILABLE |
| 538 | put argus_pend_st idx ARGUS_ST_FAILED |
| 539 | ret ARGUS_F_NONE |
| 540 | end |
| 541 | ret ARGUS_F_NONE |
| 542 | end |
| 543 | |
| 544 | note Observe an event for containment lifecycle tracking. Returns finding code (ARGUS_F_NONE if clean). |
| 545 | fn argus_contain_observe ev view ArgusEvent evdig view uchar 32 to ushort |
| 546 | evs = add get argus_cmeta 0 1 |
| 547 | put argus_cmeta 0 evs |
| 548 | wstart = get argus_cmeta 2 |
| 549 | if gt evs add wstart ARGUS_CONTAIN_WINDOW_EVENTS |
| 550 | put argus_cmeta 2 mul div sub evs 1 ARGUS_CONTAIN_WINDOW_EVENTS ARGUS_CONTAIN_WINDOW_EVENTS |
| 551 | put argus_cmeta 3 0 |
| 552 | end |
| 553 | k = get ev kind |
| 554 | if eq k ARGUS_EV_CAPABILITY_REVOKED |
| 555 | ret argus_contain_observe_revoke ev |
| 556 | end |
| 557 | if or eq k ARGUS_EV_CONTAINMENT_DECIDED eq k ARGUS_EV_CONTAINMENT_EXECUTED |
| 558 | ix = argus_pend_find_rid get ev world_generation |
| 559 | if lt ix 0 |
| 560 | put argus_chealth 6 add get argus_chealth 6 1 |
| 561 | ret ARGUS_F_CONTAINMENT_DECISION_UNMATCHED |
| 562 | end |
| 563 | idx = ulong ix |
| 564 | if or not argus_pend_is_open get argus_pend_st idx not argus_pend_echo_matches idx ev evdig |
| 565 | put argus_chealth 6 add get argus_chealth 6 1 |
| 566 | ret ARGUS_F_CONTAINMENT_DECISION_UNMATCHED |
| 567 | end |
| 568 | if eq k ARGUS_EV_CONTAINMENT_DECIDED |
| 569 | ret argus_contain_observe_decided idx ev |
| 570 | end |
| 571 | ret argus_contain_observe_executed idx ev |
| 572 | end |
| 573 | ret ARGUS_F_NONE |
| 574 | end |