Cocoon Wire Protocol
This page documents the WebSocket message format used for Cocoon confidential inference. Understanding the wire protocol is useful for implementing custom clients or debugging integration issues.
Connection
Message Flow
Message Types
1. Init (Client → Server)
The first message sent by the client after WebSocket connection:
Field | Type | Required | Description |
|---|---|---|---|
| string | Yes | Base64-encoded Ed25519 public key (32 bytes) |
| string | Yes | Model ID to use for inference |
| string[] | No | Requested disclosure fields |
2. Session (Server → Client)
Server responds with its public key and TEE attestation:
Field | Type | Description |
|---|---|---|
| string | Always |
| string | Base64 TEE Ed25519 public key |
| string | Base64 TDX attestation quote |
| string | Base64 cocoon proxy public key (optional) |
| string[] | Negotiated disclosure fields |
After receiving this message, both sides perform ECDH:
Convert Ed25519 keys to X25519 (Edwards → Montgomery curve)
Compute shared secret:
secret = X25519(my_private, their_public)Derive AES key:
key = SHA-256(secret)
3. Encrypted Request (Client → Server)
The inference request encrypted with the shared AES-256-GCM key:
The plaintext (before encryption) is a JSON object:
4. Chunk (Server → Client)
Encrypted response chunks streamed as they are generated:
The decrypted payload contains OpenAI-compatible SSE data:
Each SSE chunk may contain:
choices[0].delta.content— generated textchoices[0].delta.reasoning_content— chain-of-thought reasoning
5. Done Detail (Server → Client)
Encrypted usage data with attestation signature:
Decrypted payload:
The attestation is verified by:
Computing
SHA-256(raw_usage_json_bytes)Comparing with
usage_hashVerifying
Ed25519.verify(signature, SHA-256(usage_json), tee_public_key)
6. Done (Server → Client)
Final message indicating stream completion:
The usage field in done is a fallback — prefer the attested usage from done_detail.
Error (Server → Client)
Error message that can arrive at any point:
Encryption Details
Key Exchange
Step | Operation |
|---|---|
1 | Client generates Ed25519 keypair |
2 | Server generates Ed25519 keypair |
3 | Both convert Ed25519 → X25519 |
4 | Shared secret = |
5 | AES key = |
Per-Message Encryption
Parameter | Value |
|---|---|
Algorithm | AES-256-GCM |
Key size | 256 bits (from ECDH) |
Nonce size | 12 bytes (random per message) |
Auth tag | 16 bytes (appended to ciphertext) |
AAD | None |
Attestation Quote Binding
The TDX attestation quote's report_data field (64 bytes) contains:
This binds the TEE's public key to the hardware attestation, proving the key was generated inside the attested TEE instance.
TDX Quote Format
The SDK supports Intel TDX quote versions 3, 4, and 5:
Offset | Size | Field |
|---|---|---|
0 | 2 | Version (3, 4, or 5) |
2 | 2 | Attestation key type |
4 | 4 | TEE type (0x81 = TDX) |
48 | 584 | TD Report body |
TD Report Body Fields (used for image hash)
Field | Size | Description |
|---|---|---|
MRTD | 48 bytes | Measurement of initial TD contents |
MR_CONFIG_ID | 48 bytes | Configuration ID |
MR_OWNER | 48 bytes | Owner measurement |
MR_OWNER_CONFIG | 48 bytes | Owner configuration |
RTMR[0..3] | 4 × 48 bytes | Runtime measurements |
Report Data | 64 bytes | Custom data (contains key hash) |
Image Hash Computation
The image hash uniquely identifies the code running inside the TEE.