feat(enclave,proxy): adopt length prefix for vsock connection#4
Merged
hyperfinitism merged 1 commit intomainfrom Jan 28, 2026
Merged
feat(enclave,proxy): adopt length prefix for vsock connection#4hyperfinitism merged 1 commit intomainfrom
hyperfinitism merged 1 commit intomainfrom
Conversation
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 introduces a length-prefix framing protocol for vsock communication between the proxy and enclave. Each message is now prefixed with a 4-byte big-endian length field, ensuring that both sides read the exact number of bytes for each message.
Additionally, the vsock buffer size is now unified between proxy and enclave, and can be configured via CLI arguments.
Background (Issue)
When running the full setup flow on a freshly created parent VM for the first time (setup → build enclave/proxy/client → run enclave → run proxy → run client), a JSON parsing error occurs during the key exchange request:
Subsequent runs (either re-running the client or rebuilding from scratch) do not reproduce this error.
Root Cause Analysis
The vsock stream is asynchronous. The proxy's single
read()call was returning whatever data was available in the buffer at the time, without waiting for the complete response. On the first run, attestation document generation may be slower (likely due to NSM initialization overhead), causing the response to be split across multiple network chunks. The proxy read only the first chunk (~4096 bytes) and returned it to the client, resulting in truncated JSON.Note that a similar issue has been observed in Humane-RAFW-MAA, where the initial SGX quote generation takes longer and causes cpp-httplib to time out (exceed the default timeout period = 5 sec).
What's Changed
proxy/src/main.rs--vsock-buffer-sizeCLI argument (default: 8192)max_body_sizeis now derived asvsock_buffer_size - 4(accounting for the length prefix)read_exact()to read the length prefix, then reads the exact payload sizemax_body_sizeenclave/src/main.rs--vsock-buffer-sizeCLI argument (default: 8192)max_request_sizeUnexpectedEofgracefully for connection terminationclient-config.jsonTesting
Tested on the environment described in
README.md: