Add verified TEE inference client with OHTTP and RSA-PSS signature verification#297
Merged
Conversation
…erification) Expose the client side of the OpenGradient verified-inference protocol so any integrator (the chat-app relay, third-party tools, and the new local proxy) can route an OpenAI-style request to a TEE through an untrusted relay and cryptographically verify the response, sharing one non-drifting implementation. - tee_ohttp.py: client-side Oblivious HTTP (RFC 9458) encapsulation + single-shot and chunked-streaming response decryption, wire-compatible with the tee-gateway recipient and the chat-app browser client. - tee_verify.py: RSA-PSS response signature verification, request canonicalization (build_inner_request), and tee_id/PCR helpers, mirroring the gateway's signing. - tee_ohttp_client.py: high-level OhttpRelayClient tying registry + OHTTP + verify together; verifies before returning (buffers streams) so no unverified token is surfaced. Caller supplies relay auth headers. - tee_registry: surface on-chain pcr_hash on TEEEndpoint for reproducible-build PCR pinning. - Tests round-trip the OHTTP crypto against the real tee-gateway recipient code and verify signatures against an independently-constructed gateway signature. https://claude.ai/code/session_01PdYbDC47zuBGiZex7ZHMSs
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Minor release adding the OHTTP client + signature-verification utilities (OhttpRelayClient, verify_response, build_inner_request, TEEEndpoint.pcr_hash). Lets downstream packages (e.g. opengradient-local) pin opengradient>=1.1.0. https://claude.ai/code/session_01PdYbDC47zuBGiZex7ZHMSs
…am tool-calls, CI-runnable crypto tests - tee_ohttp.encapsulate_request: thread key_id (and validate kem/kdf/aead) from the registry OhttpConfig so a TEE that rotated its key_id still decapsulates. - tee_verify.build_inner_request: reject non-list 'tools' and non-dict messages with UnsupportedRequestError (was AttributeError / silent dict->keys coercion); preserve tool_choice on the wire while keeping it out of the signed hash. - OhttpRelayClient: wrap chunked-decrypt ValueError as VerificationError; pass the config's key/alg ids; aggregate streamed delta.tool_calls so honest tool-call streams verify against the gateway's signed json.dumps(tool_calls). - Tests: add a self-contained OHTTP recipient so encapsulation/decryption + end-to-end verification run in CI without a tee-gateway checkout (real gateway still cross-checked when present, via a sys.path-restoring fixture). https://claude.ai/code/session_01PdYbDC47zuBGiZex7ZHMSs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a complete client-side implementation for verified, private TEE (Trusted Execution Environment) inference through an untrusted relay. It enables end-to-end cryptographic verification of inference responses without trusting the relay, host, or OpenGradient infrastructure.
Key Changes
New Modules
tee_verify.py— Cryptographic verification of TEE responseskeccak256(requestHash || outputHash || timestamp)sort_keys=True)TeeProofdataclass capturing verified provenance (TEE ID, hashes, timestamp, signature)pem_from_der(),tee_id_for_key(),canonical_request_bytes(),response_content_for_hash()build_inner_request()converts OpenAI-style chat bodies to canonical form, stripping attachment bytes from the hash while preserving them in the wire requesttee_ohttp.py— Client-side Oblivious HTTP (RFC 9458) encapsulationEncapsulatedRequestdataclass with wire bytes and response secretsChunkedResponseDecrypterfor incremental stream decryption with final-frame validationtee_ohttp_client.py— High-level relay client combining all three piecesOhttpRelayClientclass for sending verified, private chat completionsVerifiedChatResponsedataclass with body, content, proof, and optional stream framesRelayErrorexception for relay/inner response errorsauth_headersprovider callbacktee_registry.py(modified) — Enhanced with OHTTP config supportOhttpConfigdataclass for TEE's HPKE public key and algorithm identifiersTEEEndpointnow carriesohttp_configandsigning_public_key_derTests
tee_verify_test.py— Signature verification against independently-built gateway signaturestee_ohttp_test.py— Wire-compatibility round-trips with actual tee-gateway codetee_ohttp_client_test.py— End-to-end integration testsPublic API Exports
Updated
src/opengradient/client/__init__.pyandsrc/opengradient/__init__.pyto export:TEERegistry,TEEEndpointOhttpRelayClient,VerifiedChatResponse,RelayErrorTeeProof,VerificationErrorbuild_inner_request(),verify_response()Dependencies
Added to
pyproject.toml:pyhpke— HPKE sender context (matches gateway's recipient implementation)cryptography— RSA-PSS signature verification and key serializationhttps://claude.ai/code/session_01PdYbDC47zuBGiZex7ZHMSs