REALITY client
Source files: 6 · checked against Etemenanki 2f00a88
Etemenanki/reality/src/client/mod.rsEtemenanki/reality/src/client/hello.rsEtemenanki/reality/src/client/connect.rsEtemenanki/reality/tests/client.rsEtemenanki/reality/tests/unit/client/handshake.rsEtemenanki/reality/tests/unit/client/hello.rs
The REALITY client seals its authentication into a ClientHello that looks like Chrome’s, sends it to a REALITY server, and takes the server’s flight the way Xray’s client does: a REALITY server sends a certificate whose signature field is an HMAC under the connection’s auth key. A real certificate means the hello reached dest itself (a wrong public key, a wrong shortId, or a server that is not a REALITY server), and the handshake fails, as it does for Xray.
This page covers reality/src/client/. The auth key, the session_id seal and the certificate check are on the overview; the record layer and message parsers on TLS 1.3 subset; RealityStream, which the client returns, on Server. The protocols crate’s TransportKind::Reality, which dials with this client, is on Transports: REALITY.
Responsibilities
Section titled “Responsibilities”| The client does | It leaves to others |
|---|---|
Decode its settings once, when a ClientConfig is built. |
Reading a config: front ends lower the server’s public key, SNI and shortId into a spec. |
| Write a Chrome 133 ClientHello with fresh key shares and seal the session_id into it. | Connecting the TCP socket to the server: the caller. |
| Check the server’s flight and finish the handshake. | The proxy protocol on top: VLESS, and Vision. |
Key types
Section titled “Key types”ClientConfig
Section titled “ClientConfig”#[derive(Clone, Debug)]pub struct ClientConfig { server_name: String, public_key: PublicKey, short_id: ShortId, client_version: ClientVersion }
impl ClientConfig { pub fn new(server_name: &str, public_key: &str, short_id: &str) -> Result<Self, ConfigError>; pub fn from_bytes(server_name: &str, public_key: &[u8; 32], short_id: [u8; 8]) -> Result<Self, ConfigError>; pub fn with_client_version(self, version: [u8; 3]) -> Self;}| Setting | Xray’s name | Format |
|---|---|---|
server_name |
serverName |
The SNI sent; the server matches it exactly against its names |
public_key |
publicKey (password) |
new: unpadded base64url of 32 bytes; from_bytes: the 32 bytes |
short_id |
shortId |
new: up to 16 hex digits ("" allowed); from_bytes: the 8 zero-padded bytes |
with_client_version |
Three bytes sealed into the hello; default 26.6.27, Xray-core’s own version, which is what a server with minClientVer filters on |
The fingerprint is Chrome’s, the only one this client sends; there is no setting for it. Debug redacts the key and the shortId.
connect
Section titled “connect”pub async fn connect<S>(socket: S, config: &ClientConfig) -> io::Result<RealityStream<S>>where S: AsyncRead + AsyncWrite + Unpin;connect takes a socket already connected to the server, sends the hello, reads the server’s flight, sends the client’s Finished and returns the established stream. An error means the server is not one this config can reach (a wrong key or shortId, or a real site), or the socket failed.
The sans-I/O handshake
Section titled “The sans-I/O handshake”pub(crate) struct Handshake { /* key shares, the sealed hello, the auth key, the flight state */ }
impl Handshake { pub(crate) fn start(config: &ClientConfig) -> Result<(Self, Vec<u8>), Fatal>; // and the record to send pub(crate) fn advance(&mut self, received: &[u8]) -> Result<Option<Established>, Fatal>;}
pub(crate) struct Established { pub(crate) to_send: Vec<u8>, // the client's ChangeCipherSpec and Finished pub(crate) session: Session, pub(crate) consumed: usize, // bytes of the input up to the server's Finished}The Chrome 133 ClientHello
Section titled “The Chrome 133 ClientHello”chrome_hello in reality/src/client/hello.rs writes Chrome 133’s hello as uTLS’s HelloChrome_133 writes it, the chrome fingerprint Xray’s REALITY client uses:
| Field | Value |
|---|---|
legacy_version |
0x0303 |
random |
32 bytes from OpenSSL |
legacy_session_id |
32 zero bytes at offset 39 of the message, sealed afterwards |
| Cipher suites | A GREASE value, then 0x1301, 0x1302, 0x1303 and Chrome’s twelve TLS 1.2 suites, which this client never gets to use |
| Compression | Null only |
| Extensions | A GREASE extension first (empty) and another last (one zero byte), the rest between them in a fresh random order |
The extensions between the two GREASE ones, shuffled for each hello with a Fisher–Yates shuffle over OpenSSL’s randomness, as Chrome shuffles them:
| Extension | Content |
|---|---|
server_name |
One host name, the configured SNI |
extended_master_secret, session_ticket, signed_certificate_timestamp |
Empty |
renegotiation_info |
Empty renegotiated connection |
supported_groups |
GREASE, X25519MLKEM768, X25519, secp256r1, secp384r1 |
ec_point_formats |
Uncompressed |
application_layer_protocol_negotiation |
h2, http/1.1 |
status_request |
OCSP, empty lists |
signature_algorithms |
Chrome’s eight, in its order |
key_share |
A one-byte GREASE share, the X25519MLKEM768 share, the X25519 share |
psk_key_exchange_modes |
psk_dhe_ke |
supported_versions |
GREASE, TLS 1.3, TLS 1.2 |
compress_certificate |
Brotli |
application_settings (code point 17613) |
h2: ALPS under the code point Chrome moved to |
encrypted_client_hello |
GREASE ECH: an outer extension with HKDF-SHA256 and AES-128-GCM, a random config id, a fresh X25519 key as the encapsulated key, and 144, 176, 208 or 240 random payload bytes |
GREASE values (RFC 8701) are 0x?a?a from a random nibble, one each for the suites, the groups (also used for the GREASE key share), the versions and the two GREASE extensions; the first and last extension never get the same value.
The two key shares use separate X25519 keys, as Chrome sends them, and the hybrid share comes first. XTLS/REALITY since 2026-10 requires exactly that order, so the hello passes both the strict and the lenient server rule (see Server).
Data flow
Section titled “Data flow”sequenceDiagram participant C as connect participant S as REALITY server Note over C: generate shares, write the hello, seal the session_id C->>S: ClientHello record S->>C: ServerHello, ChangeCipherSpec, encrypted flight Note over C: key exchange, certificate HMAC, CertificateVerify, Finished C->>S: ChangeCipherSpec, Finished Note over C: RealityStream with the rest of the input
Handshake::start:
- Generates the key shares: a standalone X25519 key, and an X25519MLKEM768 share with an X25519 key of its own.
- Draws the 32-byte random from OpenSSL and writes the Chrome hello.
- Derives the auth key from X25519 between the standalone key and the server’s public key, as Xray’s client does; a public key OpenSSL refuses, or an all-zero secret, fails with
DecryptError. - Seals the version, the current time in Unix seconds and the shortId into the session_id in place.
- Frames the hello as one plaintext handshake record.
The sealed hello is kept for the transcript.
advance
Section titled “advance”advance takes everything the server sent so far and consumes whole records:
- A record header must carry version
0x0303, except a plaintext handshake record (IllegalParameterotherwise), and at most 16640 bytes (RecordOverflow). - The first handshake record must hold a ServerHello that
ServerHello::parseaccepts (DecodeErrorotherwise). The client completes the key exchange for the server’s group with its own share for that group (IllegalParameterif that fails), starts the transcript with its hello and the ServerHello, and derives the handshake traffic secrets. - A ChangeCipherSpec record must hold the one byte
1and is skipped. - Application data records after the ServerHello are opened under the server’s handshake key and must carry non-empty handshake content. Messages are reassembled with a 64 KiB bound per message.
- Any other record is
UnexpectedMessage.
The server’s encrypted messages must come in exactly this order: EncryptedExtensions, Certificate, CertificateVerify, Finished. The flight keeps the message it expects next (Expect), and any other message at that point is UnexpectedMessage. A Finished alone proves only that the server holds the handshake secret, which anyone with a key share of its own has; the REALITY certificate and its CertificateVerify prove that it holds the REALITY key, so a Finished is taken only after both checked out. Each message is checked as it arrives:
| Message | Check | Fails with |
|---|---|---|
| EncryptedExtensions | Parses; it may name an ALPN protocol, which VLESS does not read | DecodeError, IllegalParameter |
| Certificate | The leaf is a REALITY certificate made under the client’s auth key: an Ed25519 key whose HMAC fills the signature field | DecryptError |
| CertificateVerify | Uses Ed25519 (0x0807) and verifies with the certificate’s key over the transcript before it |
DecryptError |
| Finished | The server’s MAC over the transcript before it | DecryptError |
| Any message out of this order, or of another type | UnexpectedMessage |
After the server’s Finished, finish derives the application secrets over the transcript through it, and writes the client’s ChangeCipherSpec and Finished (sealed under the client’s handshake key). The returned Session reads with the server’s application key and writes with the client’s.
connect’s I/O
Section titled “connect’s I/O”connect writes and flushes the hello record, then reads in 16 KiB chunks and calls advance until it returns the established state. More than 32 KiB of flight without completing the handshake fails with RecordOverflow; the server closing first fails with UnexpectedEof (REALITY: server closed during the handshake). It then writes and flushes the ChangeCipherSpec and Finished, and wraps the socket in a client RealityStream that starts with the bytes after the server’s Finished.
Those bytes may include the empty record a REALITY server sends in place of dest’s session ticket; the stream reads it as an empty record. A real NewSessionTicket from a server is read and dropped: there is no resumption.
Invariants
Section titled “Invariants”- Every hello is fresh: new key shares, a new random, a new extension order and new GREASE values.
- The auth key uses the standalone X25519 share, and the hello carries the hybrid share before it.
- A certificate that is not a REALITY certificate under the client’s auth key fails the handshake; the client never falls back to talking to dest.
- The handshake completes only after the REALITY certificate and its CertificateVerify have verified, so no VLESS request reaches a server that cannot prove the REALITY key.
Limits
Section titled “Limits”| Limit | Value | Constant |
|---|---|---|
| Server flight before the handshake completes | 32 KiB | MAX_FLIGHT_BYTES |
| One handshake message in the flight | 64 KiB | MAX_CLIENT_HELLO |
| Read chunk | 16 KiB | READ_CHUNK |
| File | Covers |
|---|---|
reality/tests/unit/client/hello.rs |
The Chrome hello parses as a TLS 1.3 ClientHello with both shares, the session_id offset constants match, a GREASE value sits in each greased field, successive hellos shuffle their extensions, and 200 fresh hellos all parse. |
reality/tests/unit/client/handshake.rs |
The real client against the server’s handshake steps for every suite and group, with application data both ways; a wrong server key not authenticated by the server’s decision; a tampered flight refused; a_server_that_proves_no_reality_key_is_never_accepted, a flight from a server with its own key share but no REALITY certificate, refused whatever messages it leaves out. |
reality/tests/client.rs |
client::connect against server::accept over an in-memory pipe with a local OpenSSL dest: echo both ways, and a client with the wrong key camouflaged by the server and refused by the client when dest’s real certificate arrives. |
The interop tests against a real Xray server are on Transports: REALITY.