Skip to content

Commit e06936b

Browse files
committed
docs(spec): align SPEC.md with v1.3.0 (F7)
Document COWRIE_CAP_V2 preimage and bounds, mandatory COWRIE_DECLASSIFY_V1 downgrade rejection (v1_downgrade_rejected), COWRIE_TAINT_SET_V1 session taint roots, CWNL0002 durable nonce ledger with skew-guarded pruning, StatelessChallengeVerifier (COWRIE_CHAL_V2), offline EvidenceBundle and TrustBundle verification, fail-closed StatePage pins + probe_header, MAX_DECODED_BYTES=64 MiB JSON parser budget, and updated 37 Bend / 40 Lean formal verification counts. Remove withdrawn Wire Firewall wording.
1 parent af022ab commit e06936b

1 file changed

Lines changed: 36 additions & 11 deletions

File tree

‎SPEC.md‎

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Cowrie Wire & AI Container Specification (v1.2.0)
1+
# Cowrie Wire & AI Container Specification (v1.3.0)
22

3-
**Status:** Frozen v1.2 (`2026-11-23`) — 100% Plane A `COWR v1` golden-CID compatible; adds 16 KB Zone-Map shards (`CWZM`), crash-safe hash-chained `.cwwal` + `LiveIvfStore`, symmetric 4-runtime KV/StatePage + WAL + `Ed25519` parity (`vLLM` `CowrieKVConnectorV1`, `llama.cpp`, `Eureka LLM`, `Eureka Creative v7`), pure-Rust RFC 8032 `Ed25519` owner-declassification tokens (`COWRIE_DECLASSIFY_V1`), transparent stdio JSON-RPC `cowrie mcp-proxy`, zero-import `wasm32-unknown-unknown` (`80.7 KiB` gzipped), and `26/26` machine-checked `Bend 2.0.35 --verdict` formal invariants (`formal/PROOF.bend`) on top of all `v1.1` hardening.
4-
**Lineage:** Successor to legacy `Neumenon/cowrie-legacy` canonical codec, re-architected for tri-consumer AI runtimes.
5-
**Scope:** Bijective canonical binary frames (`Plane A`), deterministic progressive attention lenses (`Plane B`), 16 KB-aligned zero-copy tensor / `StatePage` / co-located IVF arenas (`Plane C`), and out-of-band authority + causal taint + `Ed25519` declassification + 16 KB Zone-Maps + RFC 6962 Merkle seals (`Plane D`).
3+
**Status:** Frozen v1.3.0 (`2026-11-30`) — 100% Plane A `COWR v1` golden-CID compatible; adds `COWRIE_CAP_V2` single-use scoped capability tokens (with mandatory `COWRIE_DECLASSIFY_V1` downgrade rejection), deterministic multi-CID session taint roots (`COWRIE_TAINT_SET_V1`), durable `CWNL0002` nonce ledger with skew-guarded expiry pruning, `StatelessChallengeVerifier` (`COWRIE_CHAL_V2`), offline-verifiable `CWRF` `EvidenceBundle` + `TrustBundle` audit packages (`cowrie verify-bundle`), fail-closed StatePage C-ABI pins + O(1) header probe (`cowrie_statepage_probe_header`), bounded JSON parser & MCP stdio framing, and **37 Bend laws + 40 Lean 4 theorems** (`formal/PROOF.bend`, `formal/CowrieProofs.lean`) on top of all `v1.2` formats (`CWZM`, `.cwwal`, `LiveIvfStore`, 4-runtime KV/StatePage parity, zero-import `wasm32-unknown-unknown`).
4+
**Lineage:** Successor to legacy `Neumenon/cowrie-legacy` canonical codec, re-architected for tri-consumer AI runtimes.
5+
**Scope:** Bijective canonical binary frames (`Plane A`), deterministic progressive attention lenses (`Plane B`), 16 KB-aligned zero-copy tensor / `StatePage` / co-located IVF arenas (`Plane C`), and out-of-band authority + causal taint + `Ed25519` `COWRIE_CAP_V2` capabilities + `EvidenceBundle` offline audit chains + 16 KB Zone-Maps + RFC 6962 Merkle seals (`Plane D`).
66

77
---
88

@@ -51,6 +51,7 @@ Fixed 8-byte canonical frame header carrying out-of-band trust and epistemic byt
5151

5252
### 2.4 Hardening Bounds (Mandatory for All Compliant Decoders)
5353
- **`MAX_DEPTH = 64`:** Any nested container at depth `> 64` MUST reject immediately with `ERR_MAX_DEPTH`.
54+
- **`MAX_DECODED_BYTES = 64 MiB` & `MAX_KEY_LEN = 65,536`:** Both the binary `COWR` decoder and the RFC 8259 JSON parser MUST track cumulative decoded memory footprint (`MAX_DECODED_BYTES`) and per-key byte length (`MAX_KEY_LEN`), failing closed with `ERR_ALLOC_LIMIT` before OOM.
5455
- **Zero-Allocation Wire Verification:** `verify_frame_zero_alloc` validates every canonical rule with zero heap allocations (`[u64; 4]` stack bitmask for `<= 256` keys).
5556
- **Byte-Bounded Allocation:** Wire counts (`nkeys`, array length, map length, tensor dims) MUST be validated against remaining buffer bytes and arithmetic overflow before allocation (`ERR_ALLOC_LIMIT`).
5657
- **Strict RFC 8259 JSON Bridge:** Rejects lone/mispaired UTF-16 surrogates (`\uD800\u0041`, `\uDC00`), unescaped `< 0x20` control bytes, duplicate object keys (`ERR_DUPLICATE_KEY`), and leading-zero numbers (`01`, `-01`); preserves whole floats (`1.0`), non-finite floats (`{"$float":"NaN"|"Infinity"|"-Infinity"}`), `Bytes` (`{"$bytes":"..."}`), `TensorRef` (`{"$tensor":...}`), and literal maps containing reserved `$` keys (`{"$map":{...}}`) losslessly.
@@ -96,10 +97,11 @@ Stores live recurrent SSM + attention KV state at `offset % 16384 == 0`, paired
9697
- `model_sha` (64 lowercase hex chars via `cowrie_model_fingerprint`: full-file SHA-NI for `<= 16 MiB`; `file_size + 64 × 64 KiB` strided windows for `> 16 MiB`)
9798
- `doc_cid` (eternal `CoreHash` or block-aligned prefix digest, 64 lowercase hex chars)
9899
- `runtime_id` (`[288..304)`, up to 16 ASCII bytes: `"llama.cpp"`, `"eureka-llm"`, `"eureka-creative"`, `"vllm-v1"`; when a caller specifies a non-empty `expected_runtime_id`, an empty or mismatched file `runtime_id` MUST fail closed with `ERR_RUNTIME_MISMATCH`) + `layout_ver: u16` (`[304..306)`)
99-
- `ctx_tokens`, `kv_quant` (`0 = FP16/BF16`, `1 = Q4_0`, `2 = Q8_0/FP8`, `3 = F32`), `ssm_dtype` (`0 = FP16`, `1 = BF16`, `2 = FP32`)
100+
- `ctx_tokens`, `kv_quant` (`0 = FP16`, `1 = Q4_0`, `2 = Q8_0/INT8`, `3 = F32`, `10 = BF16`, `11 = U8`, `12 = FP8 E4M3`, `13 = FP8 E5M2`, `14 = other`), `ssm_dtype` (`0 = FP16`, `1 = BF16`, `2 = FP32`)
100101
- `hash_mode` (`0 = flat SHA-256`, `1 = parallel 4 MiB chunked RFC 6962 Merkle SHA-256` over bounded `WorkerPool`, accelerated by x86_64 `SHA-NI` and ARMv8 `SHA2`)
101102
- Optional **RFC 2104 HMAC-SHA256** tag (`[308..340)`, `hmac_flag = 1` at `page0[75]` when `COWRIE_HMAC_KEY` is configured)
102103
- **HMAC Error Precedence:** When `hmac_flag == 1` (or caller provides an HMAC key), RFC 2104 `HMAC-SHA256` verification over Page-0 `[0..308)` MUST execute on a stack-snapshotted copy BEFORE semantic header parsing (`ERR_AUTH_MAC_MISMATCH` precedes `ERR_INVALID_CONTRACT` / `ERR_MODEL_MISMATCH`).
104+
- **Fail-Closed C-ABI Pins (`v1.3`):** `cowrie_statepage_open_strict` and `cowrie_statepage_verify_bytes` require non-empty `expected_model_sha`, `expected_doc_cid`, and `expected_runtime_id`, and reject `verify_hash == 0` with `ERR_INVALID_CONTRACT` (legacy unpinned `cowrie_statepage_open*` wrappers fail closed with `ERR_INVALID_CONTRACT`). For scheduler prefix-match lookups that do not read KV tensor payload bytes, `cowrie_statepage_probe_header` performs an O(1) read-only verification of Page 0 + 94-byte EOF trailer + HMAC + pins via `pread` without mapping payload bytes; full payload Merkle verification runs unconditionally once on worker load (`cowrie_statepage_open_strict`).
103105
- Supports both zero-copy `mmap` (`MappedStatePage`) and 16 KB-aligned `O_DIRECT` into double-buffered `cudaHostAlloc` pinned memory overlapped with dual-stream `cudaMemcpyAsync`.
104106

105107
### 3.4 Plane C Profile B — Co-Located 16 KB IVF-INT8 Index (`CWIV`, `flags & 0x02`) & `LiveIvfStore`
@@ -133,7 +135,7 @@ Lenses are pure functions of `Plane A` (zero model calls); any `tier > 3` fails
133135

134136
---
135137

136-
## 5. Plane D — Authority Bitfield, Causal Taint, `Ed25519` Declassification & MCP Wire Proxy
138+
## 5. Plane D — Authority Bitfield, Causal Taint, `COWRIE_CAP_V2`, `EvidenceBundle` & MCP Proxy
137139

138140
| Bit / Value | Symbol | Meaning |
139141
|---|---|---|
@@ -143,16 +145,39 @@ Lenses are pure functions of `Plane A` (zero model calls); any `tier > 3` fails
143145
| `0x08` | `MODEL_SYNTH` | Model-synthesized summary or derived claim |
144146
| `0x80` | `BIT_TAINTED` | Sticky transitive taint flag: set automatically on any frame derived from any parent having `(auth & (0x04 | 0x80)) != 0` |
145147

146-
- **Fail-Closed Privileged Gates:** `shell_exec`, `cred_read`, `net_exfil`, and `fs_write` fail closed (`ERR_TAINTED_EXECUTION_BLOCKED`) on tainted, unknown, empty, or colliding argument IDs.
147-
- **Scoped Asymmetric Declassification (`COWRIE_DECLASSIFY_V1`, `v1.2`):** Pure-Rust RFC 8032 `Ed25519` signatures over `"COWRIE_DECLASSIFY_V1\0" || target_cid_34 || action_u8 || expiry_u64_le` (`64 B` message, strict `S < L` and canonical curve-point verification) allow an operator's public key to approve one specific reviewed 34-byte CID for one specific `ToolAction` before `expiry_unix_secs` without sharing symmetric keys or approving any other tainted CID in context.
148-
- **Transparent MCP Wire Firewall (`cowrie mcp-proxy`, `v1.2`):** Wraps unmodified stdio JSON-RPC MCP servers, logging tool responses into `.cwwal`, sealing external fetch/search/browser/email results as `0x04 UNTRUSTED_EXT`, and blocking tainted privileged `tools/call` messages at the wire (`-32025 ERR_TAINTED_EXECUTION_BLOCKED`) unless covered by valid `Ed25519` `_cowrie_declassify` tokens.
148+
- **Fail-Closed Privileged Gates:** `shell_exec`, `cred_read`, `net_exfil`, and `fs_write` fail closed (`ERR_TAINTED_EXECUTION_BLOCKED`) on tainted, unknown, empty, or colliding argument IDs. Secret-path access (`~/.ssh`, `/etc/shadow`, cloud credentials, `.env`, `.git/hooks`, etc.) is refused fail-closed even on untainted sessions unless explicitly allowlisted, after RFC 8089 `file://localhost/` decoding, interior quote/backslash normalization, and deepest-existing-ancestor symlink resolution.
149+
- **Single-Use Scoped Capability Tokens (`COWRIE_CAP_V2`, `v1.3`):** Pure-Rust RFC 8032 `Ed25519` (strict `S < L`, canonical `y < p`, and small-order Curve25519 torsion rejection on both `pubkey` and `R`) over the length-prefixed preimage:
150+
```
151+
"COWRIE_CAP_V2\0"
152+
|| target_cid[34]
153+
|| action_u8[1] // 1=shell_exec, 2=cred_read, 3=fs_write, 4=net_exfil
154+
|| issued_at_u64_le[8]
155+
|| expiry_u64_le[8]
156+
|| nonce[16] // MUST be non-zero
157+
|| args_hash[32] // SHA-256(encode_frame(strip_cowrie_control_args(args), VERIFIED_TOOL, OBSERVED))
158+
|| tool_name_len_u32_le[4] || tool_name_utf8
159+
|| destination_len_u32_le[4] || destination_utf8
160+
|| session_id_len_u32_le[4] || session_id_utf8
161+
```
162+
Fields `tool_name`, `destination`, and `session_id` MUST be non-empty and `<= 1024` bytes (`MAX_CAP_FIELD_LEN`); `expiry > issued_at`; `expiry - issued_at <= max_ttl_secs` (`DEFAULT_MAX_CAP_TTL_SECS = 300`); `issued_at <= now + MAX_CLOCK_SKEW_SECS` (`30s`); and `now <= expiry`.
163+
- **Session Taint Snapshot Root (`COWRIE_TAINT_SET_V1`, `v1.3`):** To prevent signature explosion on multi-read tainted sessions without weakening taint binding, a single `COWRIE_CAP_V2` token MAY bind to the exact deduplicated set of active tainted CIDs via `target_cid = 0x53 0x20 || SHA-256("COWRIE_TAINT_SET_V1\0" || sorted_unique_cids)` (distinct `0x53 0x20` prefix prevents cross-type collision with `0x12 0x20` frame CIDs; JSON tokens may supply `"session_taint_root": "<64-hex>"` or the 68-hex `target_cid`). Per-CID `0x12 0x20` tokens covering all deduplicated tainted CIDs remain accepted for backward compatibility.
164+
- **Mandatory V1 Downgrade Rejection (`v1_downgrade_rejected`):** Legacy `COWRIE_DECLASSIFY_V1\0` tokens lack tool/args/destination/session/nonce binding and MUST be rejected fail-closed (`ERR_AUTH_MAC_MISMATCH`) by all v1.3 enforcement gates (`mcp-proxy`, `CowrieToolGuard`, `EvidenceBundle`). Legacy `cowrie_declassify_*` symbols are retained strictly for ABI compatibility and regression testing.
165+
- **Durable Single-Use Nonce Ledger (`CWNL0002`, `v1.3`):** Replay protection across restarts uses an `O_NOFOLLOW`, `0600`, `fsync`'d binary journal starting with 8-byte magic `"CWNL0002"` followed by fixed 24-byte records `nonce[16] || expiry_u64_le[8]` (legacy 16-byte `CWNL0001` logs are rejected fail-closed). Entries satisfying `expiry + MAX_CLOCK_SKEW_SECS < now` are pruned on load and periodically on `consume`, with crash-safe atomic `O_CREAT|O_EXCL 0600` temp-file + `sync_all` + `rename` compaction.
166+
- **Stateless Challenge-Response Verifier (`StatelessChallengeVerifier`, `COWRIE_CHAL_V2\0`):** For zero-disk or serverless deployments (e.g. edge workers), the verifier mints an ephemeral single-use challenge nonce `nonce = HMAC-SHA256(secret, "COWRIE_CHAL_V2\0" || epoch_u64_le || issued_at_u64_le || expiry_u64_le || tool_name || args_hash || destination || session_id)[..16]`, stores one active slot, and unconditionally burns the slot and increments `epoch` on `verify_and_consume`, eliminating replay without a persistent nonce file.
167+
- **Offline `EvidenceBundle` & `TrustBundle` Verification (`v1.3`):** Portable `CWRF` shards (`tensor_count == 0`, `flags == 0`, every frame strictly `AUTH_SYS_POLICY | EPI_OBSERVED`) containing ordered frames `[manifest ("cowrie.evidence_bundle.v1"), trust_bundle ("cowrie.trust_bundle.v1"), cwwal_segments... ("cowrie.cwwal_segment.v1"), approvals... ("cowrie.approval.v1"), evidence_seal ("cowrie.evidence_seal.v1")]`, verified 100% offline against a pinned 32-byte `tenant_root_pubkey`:
168+
1. Outer `CWRF` 16 KB alignment, zero-padding, canonical frames, and RFC 6962 Merkle root.
169+
2. Root-signed `TrustBundle`: `Ed25519` over `"COWRIE_TRUST_BUNDLE_V1\0" || SHA-256(encode_frame(trust_bundle_without_root_sig, SYS_POLICY, OBSERVED))`.
170+
3. Ordered `EvidenceSeal`: `content_digest = SHA-256("COWRIE_EVIDENCE_BUNDLE_V1\0" || frame_cid[0] || ... || frame_cid[N-2])`, signed via `Ed25519` over `"COWRIE_EVIDENCE_SEAL_V1\0" || content_digest || SHA-256(encode_frame(seal_without_sig, SYS_POLICY, OBSERVED))`.
171+
4. Full byte-for-byte `.cwwal` hash-chain replay (`CWAL` v1/v2 + `CWLR`) and optional `anchor_min_next_seq` / `anchor_head_hash` rollback protection.
172+
5. Per-approval (`allow`/`break_glass`) key-lifecycle check (`valid_from <= ts`, `valid_until == 0 || ts <= valid_until`, `revoked_at == 0 || ts < revoked_at`, and fail-closed rejection when `state == "revoked" && revoked_at == 0`), `canonical_args_hash(args) == token.args_hash`, intra-bundle `(nonce, destination, session_id)` uniqueness, and `COWRIE_CAP_V2\0` signature verification at historical `issued_at`.
173+
- **Transparent Stdio MCP Proxy (`cowrie mcp-proxy`, `v1.3`):** Wraps unmodified stdio JSON-RPC MCP servers with bounded line framing (default 16 MiB, draining oversize lines cleanly without OOM), logs tool responses into `.cwwal`, seals external fetch/search/browser/email results and unknown tools fail-closed as `0x04 UNTRUSTED_EXT` (ignoring server-supplied `--trust-server-annotations` hints), strips `_cowrie_*` control keys from both `params` and `params.arguments`, blocks secret paths and tainted privileged `tools/call` messages (`-32025 ERR_TAINTED_EXECUTION_BLOCKED`) unless authorized by a valid single-use `COWRIE_CAP_V2` token (per-CID or `session_taint_root`).
149174

150175
---
151176

152177
## 6. Deterministic Status ABI (`ERR_*` Codes `0..=33`)
153178

154-
`0 = OK`, `1..=29` unchanged from v1.0, plus v1.1/v1.2 security extensions:
179+
`0 = OK`, `1..=29` unchanged from v1.0, plus v1.1–v1.3 security extensions:
155180
- `30 = ERR_SSM_DTYPE_MISMATCH`
156181
- `31 = ERR_RUNTIME_MISMATCH`
157-
- `32 = ERR_AUTH_MAC_MISMATCH` (covers both `CWSP` `HMAC-SHA256` and `Ed25519` `COWRIE_DECLASSIFY_V1` signature/expiry failures)
182+
- `32 = ERR_AUTH_MAC_MISMATCH` (covers `CWSP` `HMAC-SHA256`, `COWRIE_CAP_V2` signature/expiry/replay/V1-downgrade rejection, `StatelessChallengeVerifier`, and `EvidenceBundle`/`TrustBundle` signature and key-revocation failures)
158183
- `33 = ERR_INTERNAL` (FFI panic-guard trap; never unwinds across `extern "C"`)

0 commit comments

Comments
 (0)