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 / seed / authority / aegis_om2.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: AGPL-3.0-only |
| 3 | note Pure seeded OM-2 AEGIS resident authority policy evaluator and root.install |
| 4 | note verifier (ADR 0016 s.41, R8). Replaces policy & decision logic in |
| 5 | note src/runtime/rx_aegis.c. |
| 6 | |
| 7 | const RIGHT_PRIVILEGED ulong 0x3f0 |
| 8 | const RIGHT_KNOWN ulong 0x3ff |
| 9 | const AEGIS_SLOTS ulong 4 |
| 10 | const U32_MAX ulong 0xffffffff |
| 11 | |
| 12 | const OP_ACQUIRE ulong 1 |
| 13 | const OP_RELEASE ulong 2 |
| 14 | const APPROVE ulong 1 |
| 15 | |
| 16 | const VERDICT_GRANT ulong 1 |
| 17 | const VERDICT_DENY ulong 2 |
| 18 | const VERDICT_ESCALATE ulong 3 |
| 19 | const VERDICT_REVOKE ulong 4 |
| 20 | |
| 21 | const WHY_NO_RULE ulong 1000 |
| 22 | const WHY_PRIVILEGED ulong 1001 |
| 23 | const WHY_HUMAN ulong 1002 |
| 24 | const WHY_BAD_REQUEST ulong 1003 |
| 25 | const WHY_MISMATCH ulong 1006 |
| 26 | const WHY_DOMAIN ulong 1007 |
| 27 | |
| 28 | fn rule_match rules view ulong 112 base ulong req view ulong 4 res edit ulong 3 to ulong |
| 29 | if ne get rules add base 1 get req 0 |
| 30 | ret 0 |
| 31 | end |
| 32 | rsrc = get req 1 |
| 33 | if lt rsrc get rules add base 2 |
| 34 | ret 0 |
| 35 | end |
| 36 | if gt rsrc get rules add base 3 |
| 37 | ret 0 |
| 38 | end |
| 39 | mask = xor get rules add base 4 0xffffffffffffffff |
| 40 | if ne and get req 2 mask 0 |
| 41 | ret 0 |
| 42 | end |
| 43 | ml = get rules add base 5 |
| 44 | gl = get req 3 |
| 45 | if ne ml 0 |
| 46 | if or eq gl 0 gt gl ml |
| 47 | gl = ml |
| 48 | end |
| 49 | end |
| 50 | put res 0 gl |
| 51 | put res 1 get rules base |
| 52 | put res 2 get rules add base 6 |
| 53 | ret 1 |
| 54 | end |
| 55 | |
| 56 | note Evaluate AEGIS policy rules. |
| 57 | note rules[112]: up to 16 rules x 7 ulongs: |
| 58 | note 0=id, 1=subject, 2=res_lo, 3=res_hi, 4=rights, 5=max_lease, 6=needs_approval |
| 59 | note req[4]: 0=subject, 1=resource, 2=rights, 3=lease |
| 60 | note res[3]: 0=out_lease, 1=rule_or_why, 2=needs_approval |
| 61 | export fn aegis_evaluate rules view ulong 112 n_rules ulong req view ulong 4 res edit ulong 3 to ulong |
| 62 | put res 0 0 |
| 63 | put res 2 0 |
| 64 | rights = get req 2 |
| 65 | if or eq rights 0 ne and rights xor RIGHT_KNOWN 0xffffffffffffffff 0 |
| 66 | put res 1 WHY_BAD_REQUEST |
| 67 | ret VERDICT_DENY |
| 68 | end |
| 69 | if ne and rights RIGHT_PRIVILEGED 0 |
| 70 | put res 1 WHY_PRIVILEGED |
| 71 | ret VERDICT_DENY |
| 72 | end |
| 73 | n = n_rules |
| 74 | if gt n 16 |
| 75 | n = ulong 16 |
| 76 | end |
| 77 | for i ulong n bound 16 |
| 78 | if ne rule_match rules mul i 7 req res 0 |
| 79 | ret VERDICT_GRANT |
| 80 | end |
| 81 | end |
| 82 | put res 1 WHY_NO_RULE |
| 83 | ret VERDICT_DENY |
| 84 | end |
| 85 | |
| 86 | note Pure aegis.decide.k state transition. |
| 87 | note in_f[10]: 0..5=req[0..5], 6..7=ap[0..1], 8..9=dec[0..1] |
| 88 | note out_dec[8]: decision fields to publish. Returns 1 if publish, 0 if no-op. |
| 89 | export fn aegis_decide rules view ulong 112 n_rules ulong subject ulong in_f view ulong 10 out_dec edit ulong 8 to ulong |
| 90 | ev_req = new ulong 4 0 |
| 91 | ev_res = new ulong 3 0 |
| 92 | seq = get in_f 0 |
| 93 | if eq seq 0 |
| 94 | ret 0 |
| 95 | end |
| 96 | if eq get in_f 8 seq |
| 97 | if ne get in_f 9 VERDICT_ESCALATE |
| 98 | ret 0 |
| 99 | end |
| 100 | if ne get in_f 6 seq |
| 101 | ret 0 |
| 102 | end |
| 103 | end |
| 104 | put out_dec 0 seq |
| 105 | put out_dec 1 VERDICT_DENY |
| 106 | put out_dec 2 get in_f 1 |
| 107 | put out_dec 3 get in_f 2 |
| 108 | put out_dec 4 0 |
| 109 | put out_dec 5 get in_f 4 |
| 110 | put out_dec 6 0 |
| 111 | put out_dec 7 get in_f 5 |
| 112 | op = get in_f 5 |
| 113 | bad = ulong 0 |
| 114 | if ge get in_f 4 AEGIS_SLOTS |
| 115 | bad = ulong 1 |
| 116 | end |
| 117 | if gt get in_f 2 U32_MAX |
| 118 | bad = ulong 1 |
| 119 | end |
| 120 | if ne op OP_ACQUIRE |
| 121 | if ne op OP_RELEASE |
| 122 | bad = ulong 1 |
| 123 | end |
| 124 | end |
| 125 | if ne bad 0 |
| 126 | put out_dec 1 VERDICT_DENY |
| 127 | put out_dec 3 0 |
| 128 | put out_dec 6 WHY_BAD_REQUEST |
| 129 | ret 1 |
| 130 | end |
| 131 | if eq op OP_RELEASE |
| 132 | put out_dec 1 VERDICT_REVOKE |
| 133 | put out_dec 3 0 |
| 134 | ret 1 |
| 135 | end |
| 136 | put ev_req 0 subject |
| 137 | put ev_req 1 get in_f 1 |
| 138 | put ev_req 2 get in_f 2 |
| 139 | put ev_req 3 get in_f 3 |
| 140 | v = aegis_evaluate rules n_rules ev_req ev_res |
| 141 | put out_dec 4 get ev_res 0 |
| 142 | put out_dec 6 get ev_res 1 |
| 143 | if and eq v VERDICT_GRANT ne get ev_res 2 0 |
| 144 | if ne get in_f 6 seq |
| 145 | v = VERDICT_ESCALATE |
| 146 | else |
| 147 | if ne get in_f 7 APPROVE |
| 148 | v = VERDICT_DENY |
| 149 | put out_dec 6 WHY_HUMAN |
| 150 | end |
| 151 | end |
| 152 | end |
| 153 | if and ne v VERDICT_GRANT ne v VERDICT_ESCALATE |
| 154 | put out_dec 3 0 |
| 155 | put out_dec 4 0 |
| 156 | end |
| 157 | put out_dec 1 v |
| 158 | ret 1 |
| 159 | end |
| 160 | |
| 161 | note Verify root.install.k decision/request echo and client domain bounds. |
| 162 | note dec[8], req[6], client[3] = [domain_lo, domain_hi, max_rights]. |
| 163 | note Returns 0 if ok, else RX_AEGIS_WHY_MISMATCH (1006) or RX_AEGIS_WHY_DOMAIN (1007). |
| 164 | export fn aegis_install_check dec view ulong 8 req view ulong 6 client view ulong 3 to ulong |
| 165 | if or ne get dec 0 get req 0 ne get dec 2 get req 1 |
| 166 | ret WHY_MISMATCH |
| 167 | end |
| 168 | if or ne get dec 5 get req 4 ne get dec 7 get req 5 |
| 169 | ret WHY_MISMATCH |
| 170 | end |
| 171 | if ne and get dec 3 xor get req 2 0xffffffffffffffff 0 |
| 172 | ret WHY_MISMATCH |
| 173 | end |
| 174 | if eq get dec 1 VERDICT_REVOKE |
| 175 | ret 0 |
| 176 | end |
| 177 | res = get dec 2 |
| 178 | rights = get dec 3 |
| 179 | if or lt res get client 0 gt res get client 1 |
| 180 | ret WHY_DOMAIN |
| 181 | end |
| 182 | if or ne and rights xor get client 2 0xffffffffffffffff 0 or ne and rights RIGHT_PRIVILEGED 0 eq rights 0 |
| 183 | ret WHY_DOMAIN |
| 184 | end |
| 185 | ret 0 |
| 186 | end |