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 / aien-protocols / ext / probe.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note protocol/aien-protocols/ext/probe.om: pure-Omega port of aien-probe |
| 3 | note Implements probe request validation, challenge-response attestation hashing, |
| 4 | note response verification, and deterministic SLA verdict classification. |
| 5 | note Compose after si/directives/om2.om, om/tls/sha2.om, and protocol/aien-protocols/core/types.om. |
| 6 | |
| 7 | const PRB_OK ulong 0 |
| 8 | const PRB_ERR_KIND ulong 1 |
| 9 | const PRB_ERR_TARGET ulong 2 |
| 10 | const PRB_ERR_NONCE ulong 3 |
| 11 | const PRB_ERR_TIMEOUT ulong 4 |
| 12 | const PRB_ERR_ATTEST ulong 5 |
| 13 | |
| 14 | const PRB_KIND_LIVENESS ulong 1 |
| 15 | const PRB_KIND_CAPABILITY ulong 2 |
| 16 | const PRB_KIND_LATENCY ulong 3 |
| 17 | const PRB_KIND_INTEGRITY ulong 4 |
| 18 | |
| 19 | const PRB_VERDICT_PASS ulong 1 |
| 20 | const PRB_VERDICT_DEGRADED ulong 2 |
| 21 | const PRB_VERDICT_FAIL ulong 3 |
| 22 | const PRB_VERDICT_TIMEOUT ulong 4 |
| 23 | |
| 24 | const PRB_MAX_TARGET_LEN ulong 256 |
| 25 | const PRB_MAX_TIMEOUT_MS ulong 300000 |
| 26 | |
| 27 | text prb_dom_attest "aien-probe:v1|" |
| 28 | text prb_sep "|" |
| 29 | |
| 30 | fn prb_kind_valid k ulong to bool |
| 31 | ret and ge k PRB_KIND_LIVENESS le k PRB_KIND_INTEGRITY |
| 32 | end |
| 33 | |
| 34 | fn prb_target_valid target view uchar * to bool |
| 35 | n = len target |
| 36 | if or eq n ulong 0 gt n PRB_MAX_TARGET_LEN |
| 37 | ret false |
| 38 | end |
| 39 | i = ulong 0 |
| 40 | while lt i n bound 256 |
| 41 | b = get target i |
| 42 | if or lt b uchar 33 gt b uchar 126 |
| 43 | ret false |
| 44 | end |
| 45 | i = add i ulong 1 |
| 46 | end |
| 47 | ret true |
| 48 | end |
| 49 | |
| 50 | fn prb_validate_request kind ulong target view uchar * nonce view uchar 16 timeout_ms ulong to ulong |
| 51 | if not prb_kind_valid kind |
| 52 | ret PRB_ERR_KIND |
| 53 | end |
| 54 | if not prb_target_valid target |
| 55 | ret PRB_ERR_TARGET |
| 56 | end |
| 57 | if uuid_is_nil nonce |
| 58 | ret PRB_ERR_NONCE |
| 59 | end |
| 60 | if or eq timeout_ms ulong 0 gt timeout_ms PRB_MAX_TIMEOUT_MS |
| 61 | ret PRB_ERR_TIMEOUT |
| 62 | end |
| 63 | ret PRB_OK |
| 64 | end |
| 65 | |
| 66 | fn prb_attest_head ctx edit ulong 40 kind ulong target view uchar * nonce view uchar 16 to void |
| 67 | sha256_init ctx |
| 68 | sha256_update ctx prb_dom_attest |
| 69 | kb = new uchar 8 0 |
| 70 | klen = pt_put_u64_le kb ulong 0 kind |
| 71 | sha256_update ctx part kb ulong 0 klen |
| 72 | sha256_update ctx target |
| 73 | sha256_update ctx prb_sep |
| 74 | sha256_update ctx nonce |
| 75 | end |
| 76 | |
| 77 | fn prb_attest_finish ctx edit ulong 40 status_code ulong rtt_us ulong dst edit uchar 32 to void |
| 78 | buf = new uchar 16 0 |
| 79 | p0 = pt_put_u64_le buf ulong 0 status_code |
| 80 | p1 = pt_put_u64_le buf p0 rtt_us |
| 81 | sha256_update ctx part buf ulong 0 p1 |
| 82 | sha256_final ctx dst |
| 83 | end |
| 84 | |
| 85 | fn prb_verify_attestation ctx edit ulong 40 status_code ulong rtt_us ulong claimed view uchar 32 to ulong |
| 86 | exp = new uchar 32 0 |
| 87 | prb_attest_finish ctx status_code rtt_us exp |
| 88 | if not digest_eq exp claimed |
| 89 | ret PRB_ERR_ATTEST |
| 90 | end |
| 91 | ret PRB_OK |
| 92 | end |
| 93 | |
| 94 | fn prb_classify_verdict status_code ulong rtt_us ulong soft_sla_us ulong hard_sla_us ulong to ulong |
| 95 | if or eq hard_sla_us ulong 0 gt soft_sla_us hard_sla_us |
| 96 | ret PRB_VERDICT_FAIL |
| 97 | end |
| 98 | if gt rtt_us hard_sla_us |
| 99 | ret PRB_VERDICT_TIMEOUT |
| 100 | end |
| 101 | if ne status_code ulong 0 |
| 102 | ret PRB_VERDICT_FAIL |
| 103 | end |
| 104 | if gt rtt_us soft_sla_us |
| 105 | ret PRB_VERDICT_DEGRADED |
| 106 | end |
| 107 | ret PRB_VERDICT_PASS |
| 108 | end |