Skip to content

reality: accept a ClientHello once, and learn the target's records ahead of the first client - #7

Merged
Miroshka000 merged 1 commit into
devfrom
fix/reality-replay-and-cold-start
Nov 12, 2026
Merged

Miroshka000 merged 1 commit into
devfrom
fix/reality-replay-and-cold-start

Conversation

@Miroshka000

Copy link
Copy Markdown

Two ways a REALITY server told itself apart from its target.

A recorded ClientHello could be replayed

The proof of a REALITY client sits in its ClientHello, so whoever recorded one can send it again for as long as its time stays valid (MaxTimeDiff, forever with none). The server answered the copy itself. Whoever replays cannot finish that handshake, but the server's behaviour towards it is its own and not the target's.

Now the server remembers the ClientHellos it accepted, by their random, and hands a second copy to the target like any stranger's, so the copy gets the target's own answer.

  • kept for both sides of the time check (2 * MaxTimeDiff), an hour with no check
  • two generations of at most 65536 entries each, so memory stays bounded; a full generation turns early
  • shared by a config and its clones

The first client got no post-handshake records

The target's post-handshake records were learned by a probe that the first client of each (target, SNI, ALPN, cipher suite) started and did not wait for. That client got none of the records the target sends, unlike every client after it.

  • the patterns of the usual handshakes (each server name, h2, each TLS 1.3 suite) are learned on the first connection of any kind, a stranger's included
  • the probe of any other key starts as soon as the target's ServerHello names the suite
  • a client whose pattern is still being learned waits for it, until 2 s after the probe began: a probe that hangs holds up only the clients of its first moments
  • a probe ends once the target has been quiet for 400 ms (or for as long as its own dial and handshake took), instead of always sitting out the 5 s window

Tests

  • TestRealityReplayedClientHelloGoesToTheTarget: a ClientHello recorded from a real client and sent again is forwarded, and what comes back has the shape of the target's own flight. With the guard taken out it fails.
  • TestRealityReplayGuard, TestRealityReplayGuardIsBounded, TestRealityReplayWindow
  • TestRealityPostHandshakeWarm, TestRealityPostHandshakeWaitIsBounded
  • TestRealityPostHandshakeRecordsImitated and TestRealityPostHandshakeALPN now expect the first connection to carry the target's records.

go test . passes on Windows (Go 1.26.8); go test -race -run Reality . passes in golang:1.27.

Not covered

No API change: the new fields of RealityConfig are unexported. Not run inside Citrus or on a live server yet.

…ead of the first client

Two ways a REALITY server told itself apart from its target.

A recorded ClientHello could be sent again for as long as its time stayed
valid (MaxTimeDiff, forever with none). The server answered the copy itself:
whoever replays cannot finish that handshake, but the server's behaviour
towards it is its own and not the target's. The server now remembers the
ClientHellos it accepted, by their random, for both sides of the time check
(an hour with no check), in two bounded generations shared with clones, and
hands a second copy to the target like any stranger's, so the copy gets the
target's own answer.

The target's post-handshake records were learned by a probe that the first
client of each (target, SNI, ALPN, cipher suite) started and did not wait
for, so that client got none of the records the target sends, unlike every
client after it. Now the patterns of the usual handshakes (each server name,
h2, each TLS 1.3 suite) are learned on the first connection of any kind; the
probe of another key starts as soon as the target's ServerHello names the
suite; a client whose pattern is still being learned waits for it, until two
seconds after the probe began, so a probe that hangs holds up only the
clients of its first moments; and a probe ends once the target has been quiet
for 400 ms, or for as long as its own dial and handshake took, instead of
always sitting out the five-second window.
@Miroshka000
Miroshka000 merged commit 4989099 into dev Nov 12, 2026
4 checks passed
@Miroshka000
Miroshka000 deleted the fix/reality-replay-and-cold-start branch November 12, 2026 11:25
Miroshka000 added a commit to Miroshka000/mikan that referenced this pull request Nov 12, 2026
…old by a replay

More of what set a mikan server apart from an ordinary one:

- an inbound no client has reached yet moves off www.microsoft.com, the
  site every installation started on, to a site next to its server; the
  node's such inbounds take one site from one search, retried once a day
  when nothing is found. An inbound with clients keeps its site, as a change
  would cut them off until their subscription is read again
- the REALITY window of a client's clock is 10 minutes, not 2 hours: it is
  how long a recorded ClientHello stays worth sending again
- the core (getmikan/utls#7): an accepted ClientHello is remembered and a
  copy of it goes to the target, and the first client after a start gets
  the target's post-handshake records as every later one does
- a new remote node's API answers the panel alone from the start
- X-Forwarded-For is read from a proxy on the server or its private
  networks, or one named in MIKAN_TRUSTED_PROXIES, and not from a peer that
  came straight from the internet

The API's reason of an automatic change has default_site.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant