fuzz: torcontrol: drive the control connection over a mocked socket

bitcoin/bitcoin: PR #36822

1 suggestion

Optional improvements

Link

[suggestion] · Auth-method oracle counts AUTH lines from discarded async replies

The fuzz harness treats methods in ignored async replies as offered, so its authentication assertions can miss regressions that use those methods without a corresponding offer in the processed PROTOCOLINFO reply.

Location: src/test/fuzz/torcontrol.cpp:145 (head).

Details and suggested fix

RecordLine() records every AUTH line, and Offered() unions its methods for the connection. For example, with a nonempty configured password, 650 AUTH METHODS=HASHEDPASSWORD followed by 250 OK leaves Offered("HASHEDPASSWORD") true. The controller correctly discards the first reply, but a regression that retained its lines in m_message would send the password while passing this assertion. Other inputs could still catch a missing method guard.

Collect the authentication data per reply and discard it when the terminating space-separated line has a code of at least 600. This preserves the approximate unanswered design while letting the assertion detect async-line leakage. Use the terminating line's code, not each line's code: ProcessBuffer() dispatches a reply containing 650-AUTH ... followed by 250 OK.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The historical threat model includes a process impersonating Tor and inducing Bitcoin Core to read and disclose local files. The SAFECOOKIE introduction accompanied a requirement that the authentication cookie be exactly 32 bytes, explicitly motivated by protecting files such as the wallet.

The authentication oracle is modeling an untrusted control endpoint, not merely a cooperative Tor instance. This history explains why possession of the cookie and validation of the server's proof matter, but does not establish any permission to reuse authentication state after reconnecting.

Source 1

Earlier SAFECOOKIE test work explicitly covered successful authentication, failed AUTHCHALLENGE, an invalid server nonce, a mismatched server hash, and invalid or missing cookie files.

The prior testing scope treats server-proof verification and nonce validation as meaningful authentication boundaries. Its captured description does not specify cross-reconnection nonce lifetime or claim to test nonce freshness across connections.

Source 1