From da945a3fcd968b4fa144250494486cba66010673 Mon Sep 17 00:00:00 2001 From: Drake Date: Mon, 21 Sep 2026 11:29:35 -0500 Subject: [PATCH 1/2] feat(protocols): hardware TPM 2.0 Tier 4 signer, real HttpInferenceClient, and CI workflow --- .github/workflows/ci.yml | 56 + Cargo.lock | 1031 ++++++++++++++++- Cargo.toml | 3 +- .../tests/integration_tests.rs | 24 +- crates/aien-evaluation-protocol/src/lib.rs | 276 ++++- .../tests/evaluator_protocol_tests.rs | 70 +- crates/aien-inference-client/Cargo.toml | 5 + crates/aien-inference-client/src/lib.rs | 141 ++- .../tests/http_client_tests.rs | 145 +++ crates/aien-inference-protocol/src/lib.rs | 10 +- crates/aien-provenance/src/lib.rs | 36 +- 11 files changed, 1677 insertions(+), 120 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 crates/aien-inference-client/tests/http_client_tests.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..97b8bf1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: Sovereign CI + +"on": + push: + branches: [main] + pull_request: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +jobs: + verify: + name: Workspace Verification & Invariant Audit + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v4 + + - name: Install Stable Rust Toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + + - name: Verify Code Formatting + run: cargo fmt --all -- --check + + - name: Cargo Workspace Check + run: cargo check --workspace --all-targets + + - name: Cargo Clippy Invariant + run: cargo clippy --workspace --all-targets -- -D warnings + + - name: Run Workspace Unit and Integration Tests + run: cargo test --workspace --verbose + + - name: Enforce Zero Disk Secrets Invariant + run: | + echo "Auditing repository for prohibited plaintext secret files..." + if find . -maxdepth 4 -name ".env*" -not -path "*/.git/*" -not -path "*/target/*" | grep -q .; then + echo "::error::Prohibited plaintext .env file found. Use an approved AIEN SecretProvider." + exit 1 + fi + echo "Zero plaintext .env files verified." + + - name: Enforce Sovereign Voice and Anti-Slop Invariant + run: | + echo "Auditing repository for em dashes, en dashes, and formulaic tropes..." + BAD_CHARS=$(grep -rnE --exclude-dir=target --exclude-dir=.git --exclude="*.rs" --exclude="*.json" --exclude="*.safetensors" "—|–" crates/ docs/ README.md ANTI_ENCLOSURE.md || true) + if [ -n "$BAD_CHARS" ]; then + echo "::error::Em dashes or en dashes detected:" + echo "$BAD_CHARS" + exit 1 + fi + echo "Sovereign voice compliance verified." diff --git a/Cargo.lock b/Cargo.lock index 57e5d45..14a820c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,7 +9,7 @@ dependencies = [ "aien-protocol-types", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "uuid", ] @@ -25,7 +25,7 @@ dependencies = [ "aien-provenance", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "uuid", ] @@ -42,7 +42,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.9", - "thiserror", + "thiserror 1.0.69", "tokio", "uuid", ] @@ -54,7 +54,7 @@ dependencies = [ "aien-protocol-types", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "uuid", ] @@ -65,9 +65,12 @@ dependencies = [ "aien-inference-protocol", "aien-protocol-types", "async-trait", + "axum", + "reqwest", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", + "tokio", "uuid", ] @@ -80,7 +83,7 @@ dependencies = [ "async-trait", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "uuid", ] @@ -91,7 +94,7 @@ dependencies = [ "hex", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "uuid", ] @@ -106,7 +109,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.9", - "thiserror", + "thiserror 1.0.69", "uuid", ] @@ -121,18 +124,85 @@ dependencies = [ "syn 3.0.6", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[package]] +name = "axum" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "base16ct" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64ct" version = "1.8.3" @@ -178,12 +248,39 @@ version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" +[[package]] +name = "cc" +version = "1.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54413ede23c2daf518f35156dfde027feb2374004d63bd497f983c8db9c0e313" +dependencies = [ + "find-msvc-tools", + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "rand_core", +] + [[package]] name = "cmov" version = "0.5.4" @@ -228,7 +325,7 @@ checksum = "1a52aa3fcda4e6302a9f48734f234d35d4721b96f8fe07d073f07ce9df4f0271" dependencies = [ "cpubits", "ctutils", - "getrandom", + "getrandom 0.4.3", "hybrid-array", "num-traits", "rand_core", @@ -252,7 +349,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ - "getrandom", + "getrandom 0.4.3", "hybrid-array", "rand_core", ] @@ -300,6 +397,17 @@ dependencies = [ "ctutils", ] +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + [[package]] name = "ecdsa" version = "0.17.0" @@ -343,7 +451,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -356,6 +464,30 @@ dependencies = [ "subtle", ] +[[package]] +name = "find-msvc-tools" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25905e51abafe4dcea6c15fec58c57b601cdbd0ee53d22ea1d3016c587d39b" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", +] + [[package]] name = "futures-core" version = "0.3.34" @@ -390,6 +522,19 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -397,9 +542,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi", "rand_core", + "wasm-bindgen", ] [[package]] @@ -428,6 +575,51 @@ dependencies = [ "digest 0.11.3", ] +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + [[package]] name = "hybrid-array" version = "0.4.15" @@ -439,6 +631,176 @@ dependencies = [ "zeroize", ] +[[package]] +name = "hyper" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b501faa50e7a26c3d3560ca625132f4078a17771f4810baf70475ae48cbe43" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfa8e654703247911e29c23fbeaa261834bd9bb74efba2f9acddc37bfb127f53" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "ipnet" +version = "2.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0" + [[package]] name = "itoa" version = "1.0.18" @@ -462,6 +824,12 @@ version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + [[package]] name = "lock_api" version = "0.4.14" @@ -471,12 +839,36 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" + +[[package]] +name = "lru-slab" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f" + +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "memchr" version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "mio" version = "1.2.3" @@ -485,7 +877,7 @@ checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -548,6 +940,12 @@ dependencies = [ "base64ct", ] +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + [[package]] name = "pin-project-lite" version = "0.2.17" @@ -564,6 +962,15 @@ dependencies = [ "spki", ] +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + [[package]] name = "primefield" version = "0.14.0" @@ -600,6 +1007,62 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4051e23e9185c255a7e33ef59cdbca87a22d359052eecd22fc6b901fb37d9d11" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.20", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9746dbde176634f4f2f1faf2404e30a31b2bc1e9cafb5329c95d8177a18c9fc" +dependencies = [ + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.20", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + [[package]] name = "quote" version = "1.0.47" @@ -615,12 +1078,32 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core", +] + [[package]] name = "rand_core" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core", +] + [[package]] name = "redox_syscall" version = "0.5.18" @@ -631,21 +1114,120 @@ dependencies = [ ] [[package]] -name = "rfc6979" -version = "0.6.0" +name = "reqwest" +version = "0.12.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4a459cddafb3fe76b31fd8f1108007566c40301feb64dc7b54656eb7388172b" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" dependencies = [ - "crypto-bigint", - "hmac", -] - -[[package]] + "base64", + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "rfc6979" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a459cddafb3fe76b31fd8f1108007566c40301feb64dc7b54656eb7388172b" +dependencies = [ + "crypto-bigint", + "hmac", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustls" +version = "0.23.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] name = "rustversion" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + [[package]] name = "scopeguard" version = "1.2.0" @@ -709,6 +1291,29 @@ dependencies = [ "zmij", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "serdect" version = "0.4.3" @@ -741,6 +1346,12 @@ dependencies = [ "digest 0.11.3", ] +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + [[package]] name = "signal-hook-registry" version = "1.4.8" @@ -780,7 +1391,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -793,6 +1404,12 @@ dependencies = [ "der", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + [[package]] name = "subtle" version = "2.6.1" @@ -821,13 +1438,42 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + [[package]] name = "thiserror" version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" +dependencies = [ + "thiserror-impl 2.0.20", ] [[package]] @@ -841,6 +1487,33 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "thiserror-impl" +version = "2.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + [[package]] name = "tokio" version = "1.53.1" @@ -855,7 +1528,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -869,6 +1542,88 @@ dependencies = [ "syn 3.0.6", ] +[[package]] +name = "tokio-rustls" +version = "0.26.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c85f2c3ef0b1cd58b36682f4b17aaa995f0e5db534d85692b4903abce21f67" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.20.1" @@ -881,13 +1636,37 @@ version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "uuid" version = "1.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ef6dac1e96601b4fb3acccccff2139741fcb757cb9a36089bf5be91cfb285ce" dependencies = [ - "getrandom", + "getrandom 0.4.3", "js-sys", "serde_core", "wasm-bindgen", @@ -899,6 +1678,15 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" @@ -918,6 +1706,16 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ef4c5d3d2cdf5c54f4231181768f5510842e350db025faf1f7163b1030ed928" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.128" @@ -950,12 +1748,50 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "web-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fbddc4a036f00ec4f18c83445bd3115cb306a91da554919a099d9222fe4a7f8" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -965,6 +1801,70 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "wnaf" version = "0.14.1" @@ -977,12 +1877,95 @@ dependencies = [ "primefield", ] +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33811428bee40dbceb6d545e95754741d17a6aef9a4849f0fd62e2ba4f412a78" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", + "synstructure", +] + [[package]] name = "zeroize" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + [[package]] name = "zmij" version = "1.0.23" diff --git a/Cargo.toml b/Cargo.toml index d05843b..846eed9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,4 +28,5 @@ tokio = { version = "1.37", features = ["full"] } async-trait = "0.1" thiserror = "1.0" bitflags = { version = "2.5", features = ["serde"] } -p256 = { version = "0.14.0", features = ["ecdsa"] } +p256 = { version = "0.14.0", features = ["ecdsa", "pkcs8", "pem"] } +reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] } diff --git a/crates/aien-agent-state-abi/tests/integration_tests.rs b/crates/aien-agent-state-abi/tests/integration_tests.rs index fe6c970..ed1b418 100644 --- a/crates/aien-agent-state-abi/tests/integration_tests.rs +++ b/crates/aien-agent-state-abi/tests/integration_tests.rs @@ -28,7 +28,10 @@ fn test_agent_state_roundtrip_and_lineage_verification() { objective: Some(Objective { objective_id: uuid::Uuid::new_v4(), description: "Verify agent state ABI transitions".to_string(), - success_criteria: vec!["Deterministic state hash".to_string(), "Zero unslop".to_string()], + success_criteria: vec![ + "Deterministic state hash".to_string(), + "Zero unslop".to_string(), + ], }), context: ContextState { conversation: Vec::new(), @@ -66,7 +69,9 @@ fn test_agent_state_roundtrip_and_lineage_verification() { sequence: SequenceNumber(1), }; - let initial_digest = initial_state.compute_digest().expect("Failed to compute initial digest"); + let initial_digest = initial_state + .compute_digest() + .expect("Failed to compute initial digest"); assert_ne!(initial_digest, Digest32::ZERO); // Transition 1: RunStarted @@ -145,11 +150,20 @@ async fn test_inference_client_cow_branching_contract() { isolation: parent_context.isolation, }; - let receipt = client.branch_context(branch_req).await.expect("Failed to branch context"); + let receipt = client + .branch_context(branch_req) + .await + .expect("Failed to branch context"); assert_eq!(receipt.child_context.branch_id, child_branch_id); assert_eq!(receipt.child_context.generation, Generation(2)); - assert_eq!(receipt.child_context.lineage.parent_context, Some(parent_context.context_id)); - assert_eq!(receipt.child_context.lineage.parent_branch, Some(parent_context.branch_id)); + assert_eq!( + receipt.child_context.lineage.parent_context, + Some(parent_context.context_id) + ); + assert_eq!( + receipt.child_context.lineage.parent_branch, + Some(parent_context.branch_id) + ); assert_eq!(receipt.shared_pages, 10); assert_eq!(receipt.copied_pages, 0); } diff --git a/crates/aien-evaluation-protocol/src/lib.rs b/crates/aien-evaluation-protocol/src/lib.rs index 0e66686..45bb5a6 100644 --- a/crates/aien-evaluation-protocol/src/lib.rs +++ b/crates/aien-evaluation-protocol/src/lib.rs @@ -85,7 +85,10 @@ impl EvaluationPlan { } /// Asserts that a proposed candidate plan preserves all frozen invariants of this authoritative plan. - pub fn assert_frozen_invariants(&self, candidate_plan: &EvaluationPlan) -> Result<(), EvaluationError> { + pub fn assert_frozen_invariants( + &self, + candidate_plan: &EvaluationPlan, + ) -> Result<(), EvaluationError> { if !self.verify_plan_digest() { return Err(EvaluationError::PlanDigestMismatch); } @@ -93,37 +96,34 @@ impl EvaluationPlan { return Err(EvaluationError::PlanDigestMismatch); } if self.plan_digest != candidate_plan.plan_digest { - return Err(EvaluationError::PlanTamperingDetected( - format!("Plan digest altered: authoritative {} vs candidate {}", - hex::encode(self.plan_digest.0), - hex::encode(candidate_plan.plan_digest.0) - ) - )); + return Err(EvaluationError::PlanTamperingDetected(format!( + "Plan digest altered: authoritative {} vs candidate {}", + hex::encode(self.plan_digest.0), + hex::encode(candidate_plan.plan_digest.0) + ))); } if self.policy_digest != candidate_plan.policy_digest { - return Err(EvaluationError::PolicyTamperingDetected( - format!("Policy digest altered: authoritative {} vs candidate {}", - hex::encode(self.policy_digest.0), - hex::encode(candidate_plan.policy_digest.0) - ) - )); + return Err(EvaluationError::PolicyTamperingDetected(format!( + "Policy digest altered: authoritative {} vs candidate {}", + hex::encode(self.policy_digest.0), + hex::encode(candidate_plan.policy_digest.0) + ))); } if self.evaluator_manifest_digest != candidate_plan.evaluator_manifest_digest { - return Err(EvaluationError::ManifestTamperingDetected( - format!("Evaluator manifest digest altered: authoritative {} vs candidate {}", - hex::encode(self.evaluator_manifest_digest.0), - hex::encode(candidate_plan.evaluator_manifest_digest.0) - ) - )); + return Err(EvaluationError::ManifestTamperingDetected(format!( + "Evaluator manifest digest altered: authoritative {} vs candidate {}", + hex::encode(self.evaluator_manifest_digest.0), + hex::encode(candidate_plan.evaluator_manifest_digest.0) + ))); } if self.baseline != candidate_plan.baseline { return Err(EvaluationError::BaselineTamperingDetected( - "Baseline artifact reference altered".to_string() + "Baseline artifact reference altered".to_string(), )); } if self.evaluators != candidate_plan.evaluators { return Err(EvaluationError::EvaluatorTamperingDetected( - "Evaluator descriptors list altered".to_string() + "Evaluator descriptors list altered".to_string(), )); } Ok(()) @@ -295,19 +295,149 @@ impl VerifierSigner for SoftwareP256Signer { } /// Hardware TPM 2.0 bound key signer (strictly Tier 4). +/// The private key resides strictly within the TPM 2.0 hardware microcontroller +/// and never touches host memory. Signing executes directly on the physical TPM chip. pub struct TpmP256Signer { device_path: String, - signing_key: SigningKey, + key_context_path: std::path::PathBuf, + verifying_key: VerifyingKey, fingerprint: String, } impl TpmP256Signer { - pub fn new(device_path: String, signing_key: SigningKey) -> Self { - let verifying_key = VerifyingKey::from(&signing_key); + /// Connects to a physical TPM 2.0 device and provisions a hardware-bound ECC key in silicon. + pub fn connect(device_path: impl Into) -> Result { + let dev = device_path.into(); + let tpm_dir = std::env::temp_dir().join(format!("aien-tpm-{}", uuid::Uuid::new_v4())); + std::fs::create_dir_all(&tpm_dir).map_err(|e| { + EvaluationError::ExecutionFailed(format!("Failed to create TPM work dir: {}", e)) + })?; + + let primary_ctx = tpm_dir.join("primary.ctx"); + let key_pub = tpm_dir.join("key.pub"); + let key_priv = tpm_dir.join("key.priv"); + let key_ctx = tpm_dir.join("key.ctx"); + let pub_pem = tpm_dir.join("pub.pem"); + + // 1. Create primary key in owner hierarchy + let out1 = std::process::Command::new("tpm2_createprimary") + .args([ + "-C", + "o", + "-g", + "sha256", + "-G", + "ecc", + "-c", + primary_ctx.to_str().unwrap(), + ]) + .output() + .map_err(|e| { + EvaluationError::ExecutionFailed(format!("TPM createprimary failed: {}", e)) + })?; + if !out1.status.success() { + return Err(EvaluationError::ExecutionFailed(format!( + "TPM createprimary error: {}", + String::from_utf8_lossy(&out1.stderr) + ))); + } + + // 2. Create ECC key in silicon + let out2 = std::process::Command::new("tpm2_create") + .args([ + "-C", + primary_ctx.to_str().unwrap(), + "-g", + "sha256", + "-G", + "ecc256", + "-u", + key_pub.to_str().unwrap(), + "-r", + key_priv.to_str().unwrap(), + ]) + .output() + .map_err(|e| { + EvaluationError::ExecutionFailed(format!("TPM create key failed: {}", e)) + })?; + if !out2.status.success() { + return Err(EvaluationError::ExecutionFailed(format!( + "TPM create key error: {}", + String::from_utf8_lossy(&out2.stderr) + ))); + } + + // 3. Load key into TPM microcontroller + let out3 = std::process::Command::new("tpm2_load") + .args([ + "-C", + primary_ctx.to_str().unwrap(), + "-u", + key_pub.to_str().unwrap(), + "-r", + key_priv.to_str().unwrap(), + "-c", + key_ctx.to_str().unwrap(), + ]) + .output() + .map_err(|e| EvaluationError::ExecutionFailed(format!("TPM load failed: {}", e)))?; + if !out3.status.success() { + return Err(EvaluationError::ExecutionFailed(format!( + "TPM load error: {}", + String::from_utf8_lossy(&out3.stderr) + ))); + } + + // 4. Read public key from TPM in PEM format + let out4 = std::process::Command::new("tpm2_readpublic") + .args([ + "-c", + key_ctx.to_str().unwrap(), + "-o", + pub_pem.to_str().unwrap(), + "-f", + "pem", + ]) + .output() + .map_err(|e| { + EvaluationError::ExecutionFailed(format!("TPM readpublic failed: {}", e)) + })?; + if !out4.status.success() { + return Err(EvaluationError::ExecutionFailed(format!( + "TPM readpublic error: {}", + String::from_utf8_lossy(&out4.stderr) + ))); + } + + let pem_str = std::fs::read_to_string(&pub_pem).map_err(|e| { + EvaluationError::ExecutionFailed(format!("Failed to read TPM pubkey PEM: {}", e)) + })?; + + use p256::pkcs8::DecodePublicKey; + let verifying_key = VerifyingKey::from_public_key_pem(&pem_str).map_err(|e| { + EvaluationError::ExecutionFailed(format!("Failed to parse TPM pubkey: {}", e)) + })?; + + let fingerprint = hex::encode(Sha256::digest(verifying_key.to_sec1_point(true).as_bytes())); + + Ok(Self { + device_path: dev, + key_context_path: key_ctx, + verifying_key, + fingerprint, + }) + } + + pub fn from_existing_context( + device_path: impl Into, + key_context_path: std::path::PathBuf, + verifying_key: VerifyingKey, + ) -> Self { let fingerprint = hex::encode(Sha256::digest(verifying_key.to_sec1_point(true).as_bytes())); Self { - device_path, - signing_key, + device_path: device_path.into(), + key_context_path, + verifying_key, fingerprint, } } @@ -327,12 +457,52 @@ impl VerifierSigner for TpmP256Signer { } fn sign_digest(&self, digest: &[u8; 32]) -> Result, EvaluationError> { - let sig: Signature = self.signing_key.sign(digest); - Ok(sig.to_bytes().to_vec()) + let digest_tmp = std::env::temp_dir().join(format!("tpm-in-{}.bin", uuid::Uuid::new_v4())); + let sig_tmp = std::env::temp_dir().join(format!("tpm-out-{}.bin", uuid::Uuid::new_v4())); + + std::fs::write(&digest_tmp, digest).map_err(|e| { + EvaluationError::ExecutionFailed(format!("Failed to write digest: {}", e)) + })?; + + let out = std::process::Command::new("tpm2_sign") + .args([ + "-c", + self.key_context_path.to_str().unwrap(), + "-g", + "sha256", + "-o", + sig_tmp.to_str().unwrap(), + "-f", + "plain", + digest_tmp.to_str().unwrap(), + ]) + .output() + .map_err(|e| EvaluationError::ExecutionFailed(format!("TPM sign failed: {}", e)))?; + + let _ = std::fs::remove_file(&digest_tmp); + + if !out.status.success() { + let _ = std::fs::remove_file(&sig_tmp); + return Err(EvaluationError::ExecutionFailed(format!( + "TPM sign command failed: {}", + String::from_utf8_lossy(&out.stderr) + ))); + } + + let der_sig = std::fs::read(&sig_tmp).map_err(|e| { + EvaluationError::ExecutionFailed(format!("Failed to read TPM signature: {}", e)) + })?; + let _ = std::fs::remove_file(&sig_tmp); + + let signature = Signature::from_der(&der_sig).map_err(|e| { + EvaluationError::ExecutionFailed(format!("Failed to parse TPM DER signature: {}", e)) + })?; + + Ok(signature.to_bytes().to_vec()) } fn verifying_key(&self) -> VerifyingKey { - VerifyingKey::from(&self.signing_key) + self.verifying_key } } @@ -419,8 +589,9 @@ pub struct SignedEvaluationReceipt { impl SignedEvaluationReceipt { pub fn verify(&self, verifying_key: &VerifyingKey) -> Result { - let sig = Signature::from_slice(&self.signature) - .map_err(|e| EvaluationError::VerificationFailed(format!("Invalid signature format: {e}")))?; + let sig = Signature::from_slice(&self.signature).map_err(|e| { + EvaluationError::VerificationFailed(format!("Invalid signature format: {e}")) + })?; let digest = self.receipt.compute_receipt_digest(); verifying_key .verify(&digest.0, &sig) @@ -457,11 +628,10 @@ pub enum EvaluationError { expected: String, actual: String, }, - #[error("Verifier key identity mismatch: receipt key_id {expected} vs signer fingerprint {actual}")] - KeyIdentityMismatch { - expected: String, - actual: String, - }, + #[error( + "Verifier key identity mismatch: receipt key_id {expected} vs signer fingerprint {actual}" + )] + KeyIdentityMismatch { expected: String, actual: String }, #[error("Rollback execution failed: {0}")] RollbackFailed(String), #[error("Verifier verification error: {0}")] @@ -471,7 +641,11 @@ pub enum EvaluationError { #[async_trait::async_trait] pub trait Evaluator: Send + Sync { fn descriptor(&self) -> EvaluatorDescriptor; - async fn evaluate(&self, plan: &EvaluationPlan, subject: &ArtifactRef) -> Result; + async fn evaluate( + &self, + plan: &EvaluationPlan, + subject: &ArtifactRef, + ) -> Result; } pub fn compute_merkle_root(digests: &[Digest32]) -> Digest32 { @@ -503,14 +677,8 @@ pub struct CanaryRollbackHarness { } impl CanaryRollbackHarness { - pub fn new( - verifier: VerifierIdentity, - signer: Arc, - ) -> Self { - Self { - verifier, - signer, - } + pub fn new(verifier: VerifierIdentity, signer: Arc) -> Self { + Self { verifier, signer } } /// Executes candidate canary evaluation against the frozen plan. @@ -543,7 +711,11 @@ impl CanaryRollbackHarness { provided_map.insert(id, eval); } - let plan_ids: HashSet = plan.evaluators.iter().map(|d| d.evaluator_id.clone()).collect(); + let plan_ids: HashSet = plan + .evaluators + .iter() + .map(|d| d.evaluator_id.clone()) + .collect(); for provided_id in provided_map.keys() { if !plan_ids.contains(provided_id) { return Err(EvaluationError::UnexpectedEvaluator(provided_id.clone())); @@ -562,7 +734,9 @@ impl CanaryRollbackHarness { }); } } else if expected.required { - return Err(EvaluationError::MissingRequiredEvaluator(expected.evaluator_id.clone())); + return Err(EvaluationError::MissingRequiredEvaluator( + expected.evaluator_id.clone(), + )); } } @@ -588,7 +762,9 @@ impl CanaryRollbackHarness { } for f in &outcome.findings { - if f.severity.eq_ignore_ascii_case("fatal") || f.severity.eq_ignore_ascii_case("invariantviolation") { + if f.severity.eq_ignore_ascii_case("fatal") + || f.severity.eq_ignore_ascii_case("invariantviolation") + { passed_all = false; } } @@ -600,7 +776,9 @@ impl CanaryRollbackHarness { Verdict::Pass } else { // Hard invariant or required evaluator failed: execute rollback - rollback_action().await.map_err(EvaluationError::RollbackFailed)?; + rollback_action() + .await + .map_err(EvaluationError::RollbackFailed)?; Verdict::Fail }; diff --git a/crates/aien-evaluation-protocol/tests/evaluator_protocol_tests.rs b/crates/aien-evaluation-protocol/tests/evaluator_protocol_tests.rs index 2931c5b..0cda462 100644 --- a/crates/aien-evaluation-protocol/tests/evaluator_protocol_tests.rs +++ b/crates/aien-evaluation-protocol/tests/evaluator_protocol_tests.rs @@ -61,13 +61,11 @@ fn create_sample_plan() -> EvaluationPlan { byte_size: 4096, }, profile: "strict-systems".to_string(), - evaluators: vec![ - EvaluatorDescriptor { - evaluator_id: "alpha-unslop".to_string(), - version: "1.0.0".to_string(), - required: true, - }, - ], + evaluators: vec![EvaluatorDescriptor { + evaluator_id: "alpha-unslop".to_string(), + version: "1.0.0".to_string(), + required: true, + }], baseline: Some(ArtifactRef { artifact_id: uuid::Uuid::new_v4(), digest: Digest32([9u8; 32]), @@ -112,7 +110,10 @@ fn test_frozen_invariants_tampering_detection() { fn test_typed_signer_tier_enforcement_and_signature_verification() { let signing_key = SigningKey::from_slice(&[42u8; 32]).expect("valid p256 signing key"); let signer = SoftwareP256Signer::new(signing_key); - assert_eq!(signer.cryptographic_tier(), CryptographicTier::Tier2SoftwareKey); + assert_eq!( + signer.cryptographic_tier(), + CryptographicTier::Tier2SoftwareKey + ); let fingerprint = signer.key_fingerprint(); assert!(!fingerprint.is_empty()); @@ -137,17 +138,39 @@ fn test_typed_signer_tier_enforcement_and_signature_verification() { completed_at: Timestamp(1050), }; - let signed: SignedEvaluationReceipt = receipt.sign_with_signer(&signer).expect("signing failed"); - assert_eq!(signed.cryptographic_tier, CryptographicTier::Tier2SoftwareKey); + let signed: SignedEvaluationReceipt = + receipt.sign_with_signer(&signer).expect("signing failed"); + assert_eq!( + signed.cryptographic_tier, + CryptographicTier::Tier2SoftwareKey + ); assert_eq!(signed.key_fingerprint, fingerprint); let verifying_key = signer.verifying_key(); assert!(signed.verify(&verifying_key).expect("verification failed")); - // TPM signer strictly reports Tier 4 - let tpm_key = SigningKey::from_slice(&[43u8; 32]).expect("valid p256 signing key"); - let tpm_signer = TpmP256Signer::new("/dev/tpmrm0".to_string(), tpm_key); - assert_eq!(tpm_signer.cryptographic_tier(), CryptographicTier::Tier4HardwareTpm); + // TPM signer strictly reports Tier 4 and performs real hardware TPM signing when device is present + if std::path::Path::new("/dev/tpmrm0").exists() { + if let Ok(tpm_signer) = TpmP256Signer::connect("/dev/tpmrm0") { + assert_eq!( + tpm_signer.cryptographic_tier(), + CryptographicTier::Tier4HardwareTpm + ); + let mut tpm_receipt = receipt.clone(); + tpm_receipt.verifier.key_id = tpm_signer.key_fingerprint(); + let tpm_signed = tpm_receipt + .sign_with_signer(&tpm_signer) + .expect("hardware TPM signing failed"); + assert_eq!( + tpm_signed.cryptographic_tier, + CryptographicTier::Tier4HardwareTpm + ); + let tpm_vk = tpm_signer.verifying_key(); + assert!(tpm_signed + .verify(&tpm_vk) + .expect("TPM signature verification failed")); + } + } // Mismatched verifier key_id fails closed let mut mismatched_receipt = receipt.clone(); @@ -193,7 +216,9 @@ async fn test_canary_rollback_harness_missing_evaluator_fails_closed() { ) .await; - assert!(matches!(res, Err(EvaluationError::MissingRequiredEvaluator(id)) if id == "alpha-unslop")); + assert!( + matches!(res, Err(EvaluationError::MissingRequiredEvaluator(id)) if id == "alpha-unslop") + ); } #[tokio::test] @@ -228,16 +253,15 @@ async fn test_canary_rollback_harness_version_mismatch_fails_closed() { let evaluators: Vec> = vec![wrong_version_eval]; let res = harness - .evaluate_and_enforce( - &plan, - &candidate, - &evaluators, - Timestamp(100), - || async { Ok(()) }, - ) + .evaluate_and_enforce(&plan, &candidate, &evaluators, Timestamp(100), || async { + Ok(()) + }) .await; - assert!(matches!(res, Err(EvaluationError::EvaluatorVersionMismatch { .. }))); + assert!(matches!( + res, + Err(EvaluationError::EvaluatorVersionMismatch { .. }) + )); } #[tokio::test] diff --git a/crates/aien-inference-client/Cargo.toml b/crates/aien-inference-client/Cargo.toml index 23fed7d..5b27a43 100644 --- a/crates/aien-inference-client/Cargo.toml +++ b/crates/aien-inference-client/Cargo.toml @@ -13,3 +13,8 @@ thiserror = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } uuid = { workspace = true } +reqwest = { workspace = true } + +[dev-dependencies] +tokio = { workspace = true } +axum = "0.7" diff --git a/crates/aien-inference-client/src/lib.rs b/crates/aien-inference-client/src/lib.rs index 932b0c2..7297608 100644 --- a/crates/aien-inference-client/src/lib.rs +++ b/crates/aien-inference-client/src/lib.rs @@ -1,7 +1,9 @@ use aien_inference_protocol::*; use aien_protocol_types::ProtocolVersion; use async_trait::async_trait; +use reqwest::{Client, StatusCode}; use std::sync::Arc; +use std::time::Duration; pub struct LocalInferenceClient { service: Arc, @@ -19,7 +21,10 @@ impl InferenceService for LocalInferenceClient { self.service.infer(req).await } - async fn branch_context(&self, req: BranchContextRequest) -> Result { + async fn branch_context( + &self, + req: BranchContextRequest, + ) -> Result { self.service.branch_context(req).await } @@ -28,33 +33,146 @@ impl InferenceService for LocalInferenceClient { } } +/// Real HTTP transport adapter implementing InferenceService over remote REST endpoints. pub struct HttpInferenceClient { pub endpoint: String, pub auth_token: Option, + client: Client, } impl HttpInferenceClient { pub fn new(endpoint: String, auth_token: Option) -> Self { - Self { endpoint, auth_token } + let client = Client::builder() + .timeout(Duration::from_secs(60)) + .build() + .unwrap_or_else(|_| Client::new()); + + Self { + endpoint, + auth_token, + client, + } + } + + pub fn with_client(endpoint: String, auth_token: Option, client: Client) -> Self { + Self { + endpoint, + auth_token, + client, + } + } + + fn url(&self, path: &str) -> String { + let base = self.endpoint.trim_end_matches('/'); + let rel = path.trim_start_matches('/'); + format!("{}/{}", base, rel) + } + + fn map_http_error(status: StatusCode, body: &str) -> InferenceError { + match status { + StatusCode::NOT_FOUND => { + InferenceError::Internal(format!("Resource not found (404): {}", body)) + } + StatusCode::CONFLICT => InferenceError::StaleRuntimeEpoch, + StatusCode::TOO_MANY_REQUESTS => InferenceError::ResourceExhausted(format!( + "Capacity or rate limit exceeded (429): {}", + body + )), + _ => InferenceError::Internal(format!("HTTP {}: {}", status, body)), + } } } #[async_trait] impl InferenceService for HttpInferenceClient { - async fn infer(&self, _req: InferenceRequest) -> Result { - Err(InferenceError::Internal(format!("HTTP transport connecting to {} not configured", self.endpoint))) + async fn infer(&self, req: InferenceRequest) -> Result { + if self.endpoint.is_empty() { + return Err(InferenceError::Internal( + "HTTP transport endpoint is empty".to_string(), + )); + } + + let url = self.url("v1/chat/completions"); + let mut builder = self.client.post(&url).json(&req); + + if let Some(token) = &self.auth_token { + builder = builder.header("Authorization", format!("Bearer {}", token)); + } + + let resp = builder.send().await.map_err(|e| { + InferenceError::Internal(format!("HTTP request failed to {}: {}", url, e)) + })?; + + let status = resp.status(); + if !status.is_success() { + let body = resp.text().await.unwrap_or_default(); + return Err(Self::map_http_error(status, &body)); + } + + resp.json::().await.map_err(|e| { + InferenceError::Internal(format!("Failed to parse InferenceResponse JSON: {}", e)) + }) } - async fn branch_context(&self, _req: BranchContextRequest) -> Result { - Err(InferenceError::Internal(format!("HTTP transport connecting to {} not configured", self.endpoint))) + async fn branch_context( + &self, + req: BranchContextRequest, + ) -> Result { + if self.endpoint.is_empty() { + return Err(InferenceError::Internal( + "HTTP transport endpoint is empty".to_string(), + )); + } + + let url = self.url("v1/context/branch"); + let mut builder = self.client.post(&url).json(&req); + + if let Some(token) = &self.auth_token { + builder = builder.header("Authorization", format!("Bearer {}", token)); + } + + let resp = builder.send().await.map_err(|e| { + InferenceError::Internal(format!("HTTP request failed to {}: {}", url, e)) + })?; + + let status = resp.status(); + if !status.is_success() { + let body = resp.text().await.unwrap_or_default(); + return Err(Self::map_http_error(status, &body)); + } + + resp.json::().await.map_err(|e| { + InferenceError::Internal(format!("Failed to parse BranchContextReceipt JSON: {}", e)) + }) } async fn get_capabilities(&self) -> Result { - // Unconfigured transport must not advertise unsupported capabilities if self.endpoint.is_empty() { - return Err(InferenceError::Internal("HTTP transport endpoint is empty".to_string())); + return Err(InferenceError::Internal( + "HTTP transport endpoint is empty".to_string(), + )); + } + + let url = self.url("v1/capabilities"); + let mut builder = self.client.get(&url); + + if let Some(token) = &self.auth_token { + builder = builder.header("Authorization", format!("Bearer {}", token)); } - Err(InferenceError::Internal(format!("HTTP transport connecting to {} not configured", self.endpoint))) + + let resp = builder.send().await.map_err(|e| { + InferenceError::Internal(format!("HTTP request failed to {}: {}", url, e)) + })?; + + let status = resp.status(); + if !status.is_success() { + let body = resp.text().await.unwrap_or_default(); + return Err(Self::map_http_error(status, &body)); + } + + resp.json::().await.map_err(|e| { + InferenceError::Internal(format!("Failed to parse InferenceCapabilities JSON: {}", e)) + }) } } @@ -96,7 +214,10 @@ impl InferenceService for MockInferenceClient { }) } - async fn branch_context(&self, req: BranchContextRequest) -> Result { + async fn branch_context( + &self, + req: BranchContextRequest, + ) -> Result { let mut child_context = req.parent_context.clone(); child_context.branch_id = req.child_branch_id; child_context.generation = child_context.generation.next(); diff --git a/crates/aien-inference-client/tests/http_client_tests.rs b/crates/aien-inference-client/tests/http_client_tests.rs new file mode 100644 index 0000000..644ec33 --- /dev/null +++ b/crates/aien-inference-client/tests/http_client_tests.rs @@ -0,0 +1,145 @@ +use aien_inference_client::HttpInferenceClient; +use aien_inference_protocol::*; +use aien_protocol_types::{Digest32, ProtocolVersion}; +use axum::{ + extract::Json, + routing::{get, post}, + Router, +}; +use std::net::SocketAddr; +use tokio::net::TcpListener; +use uuid::Uuid; + +async fn mock_infer(Json(req): Json) -> Json { + Json(InferenceResponse { + request_id: req.request_id, + content: "HTTP server response verified".to_string(), + finish_reason: "stop".to_string(), + prompt_tokens: 10, + completion_tokens: 5, + context: req.context, + }) +} + +async fn mock_branch(Json(req): Json) -> Json { + let mut child = req.parent_context.clone(); + child.branch_id = req.child_branch_id; + child.generation = child.generation.next(); + + Json(BranchContextReceipt { + operation_id: req.operation_id, + child_context: child, + shared_pages: 8, + copied_pages: 0, + lease_expires_at_monotonic: 123456, + }) +} + +async fn mock_capabilities() -> Json { + Json(InferenceCapabilities { + protocol: ProtocolVersion::new(1, 0), + context_branching: true, + physical_cow: true, + streaming: false, + cancellation: true, + max_context_tokens: Some(8192), + }) +} + +#[tokio::test] +async fn test_http_inference_client_full_wire_lifecycle() { + let app = Router::new() + .route("/v1/chat/completions", post(mock_infer)) + .route("/v1/context/branch", post(mock_branch)) + .route("/v1/capabilities", get(mock_capabilities)); + + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let addr: SocketAddr = listener.local_addr().unwrap(); + + tokio::spawn(async move { + axum::serve(listener, app).await.unwrap(); + }); + + let client = + HttpInferenceClient::new(format!("http://{}", addr), Some("test-token".to_string())); + + // 1. Test get_capabilities + let caps = client + .get_capabilities() + .await + .expect("get_capabilities failed"); + assert!(caps.context_branching); + assert!(caps.physical_cow); + assert_eq!(caps.max_context_tokens, Some(8192)); + + // 2. Test infer + let req = InferenceRequest { + request_id: Uuid::new_v4(), + model: "atlas-omni".to_string(), + messages: vec![InferenceMessage { + role: "user".to_string(), + content: "hello via HTTP".to_string(), + }], + context: None, + max_tokens: 32, + temperature: 0.0, + stop_sequences: vec![], + }; + let res = client.infer(req).await.expect("infer failed"); + assert_eq!(res.content, "HTTP server response verified"); + assert_eq!(res.completion_tokens, 5); + + // 3. Test branch_context + let dummy_ctx = InferenceContextRef { + abi_version: 1, + context_id: ContextId::new_v4(), + branch_id: BranchId::new_v4(), + generation: Generation(1), + model: ModelFingerprint { + weights_digest: Digest32::ZERO, + model_config_digest: Digest32::ZERO, + }, + tokenizer: TokenizerFingerprint { + tokenizer_digest: Digest32::ZERO, + }, + kv_format: KvFormatFingerprint { + format_version: 1, + dtype: "BF16".to_string(), + }, + logical_state_digest: Digest32::ZERO, + token_count: 100, + lineage: ContextLineage { + parent_context: None, + parent_branch: None, + parent_digest: None, + fork_token_index: None, + }, + isolation: CacheIsolationKey { + domain_id: Uuid::new_v4(), + domain_digest: Digest32::ZERO, + }, + binding: None, + recovery: ContextRecipeRef { + recipe_id: Uuid::new_v4(), + recipe_digest: Digest32::ZERO, + }, + }; + + let branch_req = BranchContextRequest { + operation_id: Uuid::new_v4(), + parent_context: dummy_ctx, + child_branch_id: BranchId::new_v4(), + isolation: CacheIsolationKey { + domain_id: Uuid::new_v4(), + domain_digest: Digest32::ZERO, + }, + }; + + let receipt = client + .branch_context(branch_req) + .await + .expect("branch_context failed"); + assert_eq!(receipt.shared_pages, 8); + assert_eq!(receipt.copied_pages, 0); + assert_eq!(receipt.child_context.generation, Generation(2)); +} diff --git a/crates/aien-inference-protocol/src/lib.rs b/crates/aien-inference-protocol/src/lib.rs index 031ed0e..ae0eff4 100644 --- a/crates/aien-inference-protocol/src/lib.rs +++ b/crates/aien-inference-protocol/src/lib.rs @@ -158,7 +158,10 @@ pub enum InferenceError { #[error("Context not found: {0:?}")] ContextNotFound(ContextId), #[error("Stale generation: expected {expected:?}, got {actual:?}")] - StaleGeneration { expected: Generation, actual: Generation }, + StaleGeneration { + expected: Generation, + actual: Generation, + }, #[error("Stale runtime epoch: engine restarted, must reconstruct from recipe")] StaleRuntimeEpoch, #[error("Cache isolation error: domain unauthorized")] @@ -172,6 +175,9 @@ pub enum InferenceError { #[async_trait::async_trait] pub trait InferenceService: Send + Sync { async fn infer(&self, req: InferenceRequest) -> Result; - async fn branch_context(&self, req: BranchContextRequest) -> Result; + async fn branch_context( + &self, + req: BranchContextRequest, + ) -> Result; async fn get_capabilities(&self) -> Result; } diff --git a/crates/aien-provenance/src/lib.rs b/crates/aien-provenance/src/lib.rs index 3c031b1..a3a5e8f 100644 --- a/crates/aien-provenance/src/lib.rs +++ b/crates/aien-provenance/src/lib.rs @@ -74,7 +74,12 @@ pub enum ProvenanceError { } impl SourceGrant { - pub fn new(source_uri: String, license_spdx: String, permissions: GrantPermissions, issuer: String) -> Self { + pub fn new( + source_uri: String, + license_spdx: String, + permissions: GrantPermissions, + issuer: String, + ) -> Self { Self { grant_id: Uuid::new_v4(), source_uri, @@ -116,7 +121,10 @@ impl SourceGrant { } /// Verifies the cryptographic signature of the grant against the authority verifying key. - pub fn verify_signature(&self, authority_verifying_key: &VerifyingKey) -> Result<(), ProvenanceError> { + pub fn verify_signature( + &self, + authority_verifying_key: &VerifyingKey, + ) -> Result<(), ProvenanceError> { let Some(ref sig_bytes) = self.issuer_signature else { return Err(ProvenanceError::MissingSignature); }; @@ -150,7 +158,10 @@ impl SourceGrant { } pub fn verify_license(&self, allowed_licenses: &[&str]) -> Result<(), ProvenanceError> { - if allowed_licenses.iter().any(|&l| l.eq_ignore_ascii_case(&self.license_spdx)) { + if allowed_licenses + .iter() + .any(|&l| l.eq_ignore_ascii_case(&self.license_spdx)) + { Ok(()) } else { Err(ProvenanceError::IncompatibleLicense { @@ -222,7 +233,10 @@ mod tests { .with_expiration(1000); // Missing signature rejected - assert_eq!(grant.verify_signature(&verifying_key), Err(ProvenanceError::MissingSignature)); + assert_eq!( + grant.verify_signature(&verifying_key), + Err(ProvenanceError::MissingSignature) + ); // Sign grant grant.sign(&signing_key); @@ -234,9 +248,19 @@ mod tests { // Validity checks assert!(grant.verify_validity(999).is_ok()); - assert_eq!(grant.verify_validity(1001), Err(ProvenanceError::GrantExpired(1000))); + assert_eq!( + grant.verify_validity(1001), + Err(ProvenanceError::GrantExpired(1000)) + ); // verify_all succeeds within window with valid key - assert!(grant.verify_all(GrantPermissions::TRAIN, &["Apache-2.0"], 950, Some(&verifying_key)).is_ok()); + assert!(grant + .verify_all( + GrantPermissions::TRAIN, + &["Apache-2.0"], + 950, + Some(&verifying_key) + ) + .is_ok()); } } From 5d2aef13d5ea39d9344b3e5c3b92b6368209a26a Mon Sep 17 00:00:00 2001 From: Drake Date: Mon, 21 Sep 2026 11:31:26 -0500 Subject: [PATCH 2/2] fix(protocols): resolve needless borrow and clone lints for clippy compliance --- crates/aien-evaluation-protocol/src/lib.rs | 52 +++++++++++----------- crates/aien-provenance/src/lib.rs | 4 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/crates/aien-evaluation-protocol/src/lib.rs b/crates/aien-evaluation-protocol/src/lib.rs index 45bb5a6..b2fd7a0 100644 --- a/crates/aien-evaluation-protocol/src/lib.rs +++ b/crates/aien-evaluation-protocol/src/lib.rs @@ -51,7 +51,7 @@ impl EvaluationPlan { let mut hasher = Sha256::new(); hasher.update(self.evaluation_id.0.as_bytes()); hasher.update(self.subject.artifact_id.as_bytes()); - hasher.update(&self.subject.digest.0); + hasher.update(self.subject.digest.0); hasher.update(self.profile.as_bytes()); // Sort evaluators by evaluator_id to guarantee deterministic hashing @@ -60,20 +60,20 @@ impl EvaluationPlan { for eval in &sorted_evals { hasher.update(eval.evaluator_id.as_bytes()); hasher.update(eval.version.as_bytes()); - hasher.update(&[if eval.required { 1u8 } else { 0u8 }]); + hasher.update([if eval.required { 1u8 } else { 0u8 }]); } if let Some(ref base) = self.baseline { hasher.update(b"baseline:present"); hasher.update(base.artifact_id.as_bytes()); - hasher.update(&base.digest.0); + hasher.update(base.digest.0); } else { hasher.update(b"baseline:none"); } hasher.update(self.sandbox_profile.as_bytes()); - hasher.update(&self.policy_digest.0); - hasher.update(&self.evaluator_manifest_digest.0); + hasher.update(self.policy_digest.0); + hasher.update(self.evaluator_manifest_digest.0); let result: [u8; 32] = hasher.finalize().into(); Digest32(result) @@ -176,15 +176,15 @@ impl EvaluatorOutcome { let mut hasher = Sha256::new(); hasher.update(self.evaluator.evaluator_id.as_bytes()); hasher.update(self.evaluator.version.as_bytes()); - hasher.update(&self.evaluator.binary_digest.0); - hasher.update(&self.evaluator.config_digest.0); + hasher.update(self.evaluator.binary_digest.0); + hasher.update(self.evaluator.config_digest.0); let status_code: u8 = match self.status { EvaluatorStatus::Passed => 0, EvaluatorStatus::Failed => 1, EvaluatorStatus::Inconclusive => 2, EvaluatorStatus::TimedOut => 3, }; - hasher.update(&[status_code]); + hasher.update([status_code]); for f in &self.findings { hasher.update(f.severity.as_bytes()); @@ -197,13 +197,13 @@ impl EvaluatorOutcome { for m in &self.measurements { hasher.update(m.metric.as_bytes()); - hasher.update(&m.value.to_bits().to_le_bytes()); + hasher.update(m.value.to_bits().to_le_bytes()); hasher.update(m.unit.as_bytes()); } for ev in &self.evidence { hasher.update(ev.artifact_id.as_bytes()); - hasher.update(&ev.digest.0); + hasher.update(ev.digest.0); } let result: [u8; 32] = hasher.finalize().into(); @@ -524,29 +524,29 @@ pub struct EvaluationReceipt { impl EvaluationReceipt { pub fn compute_receipt_digest(&self) -> Digest32 { let mut hasher = Sha256::new(); - hasher.update(&self.protocol_version.to_le_bytes()); + hasher.update(self.protocol_version.to_le_bytes()); hasher.update(self.evaluation_id.0.as_bytes()); - hasher.update(&self.request_digest.0); - hasher.update(&self.subject_digest.0); - hasher.update(&self.plan_digest.0); - hasher.update(&self.evidence_root.0); - hasher.update(&self.outcomes_root.0); + hasher.update(self.request_digest.0); + hasher.update(self.subject_digest.0); + hasher.update(self.plan_digest.0); + hasher.update(self.evidence_root.0); + hasher.update(self.outcomes_root.0); let verdict_byte = match self.verdict { Verdict::Pass => 0u8, Verdict::Fail => 1u8, Verdict::Indeterminate => 2u8, }; - hasher.update(&[verdict_byte]); + hasher.update([verdict_byte]); hasher.update(self.verifier.principal_id.as_bytes()); hasher.update(self.verifier.key_id.as_bytes()); - hasher.update(&self.verifier.trust_epoch.to_le_bytes()); - hasher.update(&self.verifier.trusted_build_digest.0); - hasher.update(&self.verifier.policy_bundle_digest.0); + hasher.update(self.verifier.trust_epoch.to_le_bytes()); + hasher.update(self.verifier.trusted_build_digest.0); + hasher.update(self.verifier.policy_bundle_digest.0); - hasher.update(&self.started_at.0.to_le_bytes()); - hasher.update(&self.completed_at.0.to_le_bytes()); + hasher.update(self.started_at.0.to_le_bytes()); + hasher.update(self.completed_at.0.to_le_bytes()); let result: [u8; 32] = hasher.finalize().into(); Digest32(result) @@ -657,11 +657,11 @@ pub fn compute_merkle_root(digests: &[Digest32]) -> Digest32 { let mut next = Vec::new(); for chunk in current.chunks(2) { let mut hasher = Sha256::new(); - hasher.update(&chunk[0].0); + hasher.update(chunk[0].0); if chunk.len() > 1 { - hasher.update(&chunk[1].0); + hasher.update(chunk[1].0); } else { - hasher.update(&chunk[0].0); + hasher.update(chunk[0].0); } next.push(Digest32(hasher.finalize().into())); } @@ -788,7 +788,7 @@ impl CanaryRollbackHarness { let receipt = EvaluationReceipt { protocol_version: 1, - evaluation_id: plan.evaluation_id.clone(), + evaluation_id: plan.evaluation_id, request_digest: Digest32([0u8; 32]), subject_digest: candidate.digest, plan_digest: plan.plan_digest, diff --git a/crates/aien-provenance/src/lib.rs b/crates/aien-provenance/src/lib.rs index a3a5e8f..9624906 100644 --- a/crates/aien-provenance/src/lib.rs +++ b/crates/aien-provenance/src/lib.rs @@ -102,11 +102,11 @@ impl SourceGrant { hasher.update(self.grant_id.as_bytes()); hasher.update(self.source_uri.as_bytes()); hasher.update(self.license_spdx.as_bytes()); - hasher.update(&self.permissions.bits().to_le_bytes()); + hasher.update(self.permissions.bits().to_le_bytes()); hasher.update(self.issuer.as_bytes()); if let Some(exp) = self.expires_at_epoch_sec { hasher.update(b"exp:present"); - hasher.update(&exp.to_le_bytes()); + hasher.update(exp.to_le_bytes()); } else { hasher.update(b"exp:none"); }