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 / protocol / interplane / v03 / test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note protocol/interplane/v03/test.om: comprehensive positive & negative controls for |
| 3 | note interplane v0.3.0 (crossaxis, crossveil, conformance, aien_adapter). |
| 4 | note Compose with: |
| 5 | note si/directives/om2.om om/tls/sha2.om |
| 6 | note protocol/interplane/v03/crossaxis.om |
| 7 | note protocol/interplane/v03/crossveil.om |
| 8 | note protocol/interplane/v03/conformance.om |
| 9 | note protocol/interplane/v03/aien_adapter.om |
| 10 | note protocol/interplane/v03/test.om |
| 11 | |
| 12 | text v3_pass "PASS interplane-v03 (crossaxis, crossveil, conformance, aien_adapter) all 7 suites passed\n" |
| 13 | text v3_fail "FAIL interplane-v03\n" |
| 14 | |
| 15 | note RFC 4231 Test Case 2: key = "Jefe", data = "what do ya want for nothing?" |
| 16 | note Expected HMAC-SHA256: 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843 |
| 17 | text rfc_key "Jefe" |
| 18 | text rfc_msg "what do ya want for nothing?" |
| 19 | text rfc_exp "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843" |
| 20 | |
| 21 | text td_p1 "conformance/fixtures/injection/01-basic.json" |
| 22 | text td_b1 "{\"id\":\"01-basic\",\"kind\":\"injection\"}" |
| 23 | text td_p2 "conformance/fixtures/approval/01-write.json" |
| 24 | text td_b2 "{\"id\":\"01-write\",\"kind\":\"approval\"}" |
| 25 | text td_b2_tamper "{\"id\":\"01-write\",\"kind\":\"tampered\"}" |
| 26 | |
| 27 | text desk_key "aien-approval-desk-key-v1" |
| 28 | text bind_msg "trace=t1|req=r1|app=a1|path=src/lib.om" |
| 29 | text bind_msg_tamper "trace=t1|req=r1|app=a1|path=src/evil.om" |
| 30 | |
| 31 | fn v3_slice_eq a view uchar * b view uchar * to bool |
| 32 | if ne len a len b |
| 33 | ret false |
| 34 | end |
| 35 | n = len a |
| 36 | if gt n ulong 1024 |
| 37 | ret false |
| 38 | end |
| 39 | i = ulong 0 |
| 40 | while lt i n bound 1024 |
| 41 | if ne get a i get b i |
| 42 | ret false |
| 43 | end |
| 44 | i = add i ulong 1 |
| 45 | end |
| 46 | ret true |
| 47 | end |
| 48 | |
| 49 | fn v3_test_crossaxis to bool |
| 50 | rules = new ulong 80 0 |
| 51 | cnt = new ulong 1 0 |
| 52 | spec = new ulong 5 0 |
| 53 | res = new ulong 3 0 |
| 54 | |
| 55 | note Rule 1: Alias (ns=1, name=10 -> cap=100) |
| 56 | put spec 0 ulong 1 |
| 57 | put spec 1 CA_RULE_ALIAS |
| 58 | put spec 2 ulong 1 |
| 59 | put spec 3 ulong 10 |
| 60 | put spec 4 ulong 100 |
| 61 | if ne ca_add_rule rules cnt spec CA_OK |
| 62 | ret false |
| 63 | end |
| 64 | |
| 65 | note Rule 2: Valid Passthrough (ns=0, name=20 -> cap=20) |
| 66 | put spec 0 ulong 2 |
| 67 | put spec 1 CA_RULE_PASSTHROUGH |
| 68 | put spec 2 ulong 0 |
| 69 | put spec 3 ulong 20 |
| 70 | put spec 4 ulong 20 |
| 71 | if ne ca_add_rule rules cnt spec CA_OK |
| 72 | ret false |
| 73 | end |
| 74 | |
| 75 | note Negative control: Passthrough with non-null namespace must be refused |
| 76 | put spec 0 ulong 3 |
| 77 | put spec 1 CA_RULE_PASSTHROUGH |
| 78 | put spec 2 ulong 1 |
| 79 | put spec 3 ulong 20 |
| 80 | put spec 4 ulong 20 |
| 81 | if ne ca_add_rule rules cnt spec CA_ERR_BAD_PASSTHROUGH |
| 82 | ret false |
| 83 | end |
| 84 | |
| 85 | note Negative control: Passthrough with from_name != to_cap must be refused |
| 86 | put spec 2 ulong 0 |
| 87 | put spec 4 ulong 21 |
| 88 | if ne ca_add_rule rules cnt spec CA_ERR_BAD_PASSTHROUGH |
| 89 | ret false |
| 90 | end |
| 91 | |
| 92 | note Exact lookup matches Rule 1 (Alias) and Rule 2 (Passthrough); unknown -> CA_ERR_UNKNOWN_CAP |
| 93 | if ne ca_map_tool rules get cnt 0 ulong 1 ulong 10 res CA_OK |
| 94 | ret false |
| 95 | end |
| 96 | if or ne get res 0 ulong 100 ne get res 2 ulong 0 |
| 97 | ret false |
| 98 | end |
| 99 | if ne ca_map_tool rules get cnt 0 ulong 0 ulong 20 res CA_OK |
| 100 | ret false |
| 101 | end |
| 102 | if or ne get res 0 ulong 20 ne get res 2 ulong 1 |
| 103 | ret false |
| 104 | end |
| 105 | if ne ca_map_tool rules get cnt 0 ulong 9 ulong 99 res CA_ERR_UNKNOWN_CAP |
| 106 | ret false |
| 107 | end |
| 108 | |
| 109 | note Deterministic domain selector with budget=10 |
| 110 | cm = new ulong 16 0 |
| 111 | cc = new ulong 16 0 |
| 112 | sel = new ulong 16 0 |
| 113 | put cm 0 ulong 1 |
| 114 | put cc 0 ulong 6 |
| 115 | put cm 1 ulong 2 |
| 116 | put cc 1 ulong 2 |
| 117 | put cm 2 ulong 1 |
| 118 | put cc 2 ulong 5 |
| 119 | n_sel = ca_select_domain ulong 3 ulong 1 ulong 10 cm cc sel |
| 120 | if ne n_sel ulong 1 |
| 121 | ret false |
| 122 | end |
| 123 | if or ne get sel 0 ulong 1 or ne get sel 1 ulong 2 ne get sel 2 ulong 3 |
| 124 | ret false |
| 125 | end |
| 126 | ret true |
| 127 | end |
| 128 | |
| 129 | fn v3_test_conformance_trust_digest to bool |
| 130 | c1 = new ulong 40 0 |
| 131 | c2 = new ulong 40 0 |
| 132 | c3 = new ulong 40 0 |
| 133 | d1 = new uchar 32 0 |
| 134 | d2 = new uchar 32 0 |
| 135 | d3 = new uchar 32 0 |
| 136 | sha256_init c1 |
| 137 | cf_trust_add_entry c1 td_p1 td_b1 |
| 138 | cf_trust_add_entry c1 td_p2 td_b2 |
| 139 | sha256_final c1 d1 |
| 140 | |
| 141 | sha256_init c2 |
| 142 | cf_trust_add_entry c2 td_p1 td_b1 |
| 143 | cf_trust_add_entry c2 td_p2 td_b2 |
| 144 | sha256_final c2 d2 |
| 145 | |
| 146 | if not cf_dig_eq d1 d2 |
| 147 | ret false |
| 148 | end |
| 149 | |
| 150 | note Tampering one fixture body must change TRUST-DIGEST |
| 151 | sha256_init c3 |
| 152 | cf_trust_add_entry c3 td_p1 td_b1 |
| 153 | cf_trust_add_entry c3 td_p2 td_b2_tamper |
| 154 | sha256_final c3 d3 |
| 155 | if cf_dig_eq d1 d3 |
| 156 | ret false |
| 157 | end |
| 158 | |
| 159 | note T3/T4 subset rule checks |
| 160 | if not cf_subset_admit ulong 3 ulong 7 |
| 161 | ret false |
| 162 | end |
| 163 | if cf_subset_admit ulong 8 ulong 7 |
| 164 | ret false |
| 165 | end |
| 166 | if cf_subset_admit ulong 0 ulong 7 |
| 167 | ret false |
| 168 | end |
| 169 | ret true |
| 170 | end |
| 171 | |
| 172 | fn v3_test_hmac_rfc4231 to bool |
| 173 | mac = new uchar 32 0 |
| 174 | hx = new uchar 64 0 |
| 175 | aien_hmac_sha256 rfc_key rfc_msg mac |
| 176 | cf_hex32 mac hx |
| 177 | if not v3_slice_eq hx rfc_exp |
| 178 | ret false |
| 179 | end |
| 180 | note ApprovalBinding tamper detection |
| 181 | m1 = new uchar 32 0 |
| 182 | m2 = new uchar 32 0 |
| 183 | aien_hmac_sha256 desk_key bind_msg m1 |
| 184 | aien_hmac_sha256 desk_key bind_msg_tamper m2 |
| 185 | if aien_mac_eq m1 m2 |
| 186 | ret false |
| 187 | end |
| 188 | ret true |
| 189 | end |
| 190 | |
| 191 | fn v3_test_aien_adapter to bool |
| 192 | note Fail-closed when gate is not linked |
| 193 | if ne aien_decide AIEN_CAP_READ_FILE ulong 0 ulong 1 ulong 1 CV_DEC_DENIED |
| 194 | ret false |
| 195 | end |
| 196 | note Read-only allowed when gate allows |
| 197 | if ne aien_decide AIEN_CAP_READ_FILE ulong 1 ulong 1 ulong 0 CV_DEC_AUTHORIZED |
| 198 | ret false |
| 199 | end |
| 200 | note World mutation requires approval when no grant |
| 201 | if ne aien_decide AIEN_CAP_WRITE_FILE ulong 1 ulong 1 ulong 0 CV_DEC_REQUIRES_APPROVAL |
| 202 | ret false |
| 203 | end |
| 204 | note World mutation authorized only with explicit grant |
| 205 | if ne aien_decide AIEN_CAP_WRITE_FILE ulong 1 ulong 1 ulong 1 CV_DEC_AUTHORIZED |
| 206 | ret false |
| 207 | end |
| 208 | note Unknown capability always denied |
| 209 | if ne aien_decide ulong 99 ulong 1 ulong 1 ulong 1 CV_DEC_DENIED |
| 210 | ret false |
| 211 | end |
| 212 | |
| 213 | note Two-phase single-use approval grant lifecycle |
| 214 | st = new ulong 1 0 |
| 215 | put st 0 GRANT_UNUSED |
| 216 | if ne aien_grant_reserve st AIEN_OK |
| 217 | ret false |
| 218 | end |
| 219 | note Double-reserve fails |
| 220 | if ne aien_grant_reserve st AIEN_ERR_GRANT_STATE |
| 221 | ret false |
| 222 | end |
| 223 | note Release returns to UNUSED |
| 224 | if ne aien_grant_release st AIEN_OK |
| 225 | ret false |
| 226 | end |
| 227 | note Reserve -> Commit -> Spent |
| 228 | if ne aien_grant_reserve st AIEN_OK |
| 229 | ret false |
| 230 | end |
| 231 | if ne aien_grant_commit st AIEN_OK |
| 232 | ret false |
| 233 | end |
| 234 | note Replay of spent grant MUST be refused |
| 235 | if ne aien_grant_reserve st AIEN_ERR_GRANT_REPLAY |
| 236 | ret false |
| 237 | end |
| 238 | if ne aien_grant_commit st AIEN_ERR_GRANT_REPLAY |
| 239 | ret false |
| 240 | end |
| 241 | if ne aien_grant_revoke st AIEN_ERR_GRANT_REPLAY |
| 242 | ret false |
| 243 | end |
| 244 | note Revoking an unused grant blocks subsequent reserve |
| 245 | st2 = new ulong 1 0 |
| 246 | put st2 0 GRANT_UNUSED |
| 247 | if ne aien_grant_revoke st2 AIEN_OK |
| 248 | ret false |
| 249 | end |
| 250 | if ne aien_grant_reserve st2 AIEN_ERR_GRANT_REVOKED |
| 251 | ret false |
| 252 | end |
| 253 | ret true |
| 254 | end |
| 255 | |
| 256 | fn main to int |
| 257 | ok = true |
| 258 | if not v3_test_crossaxis |
| 259 | ok = false |
| 260 | end |
| 261 | if not cf_verify_negctl_matrix |
| 262 | ok = false |
| 263 | end |
| 264 | if not v3_test_conformance_trust_digest |
| 265 | ok = false |
| 266 | end |
| 267 | if not v3_test_hmac_rfc4231 |
| 268 | ok = false |
| 269 | end |
| 270 | if not v3_test_aien_adapter |
| 271 | ok = false |
| 272 | end |
| 273 | if not ok |
| 274 | k = write int 1 v3_fail ulong 0 len v3_fail |
| 275 | if lt k long 0 |
| 276 | ret int 1 |
| 277 | end |
| 278 | ret int 1 |
| 279 | end |
| 280 | k = write int 1 v3_pass ulong 0 len v3_pass |
| 281 | if lt k long 0 |
| 282 | ret int 1 |
| 283 | end |
| 284 | ret int 0 |
| 285 | end |