Skip to content

Enforce the pinned host certificate even when the chain validates - #2069

Closed
ccowan93 wants to merge 1 commit into
moonlight-stream:masterfrom
ccowan93:fix/enforce-cert-pin
Closed

ccowan93 wants to merge 1 commit into
moonlight-stream:masterfrom
ccowan93:fix/enforce-cert-pin

Conversation

@ccowan93

Copy link
Copy Markdown
Contributor

NvHTTP compares the pinned server certificate only in handleSslErrors(). QNetworkAccessManager doesn't emit sslErrors() when the presented chain is valid against the system CAs and matches the host name, so in that case the pin is never checked. The request, including uniqueid and the rikey on launch/resume, then goes to whoever answered. Examples are TLS inspection proxies with an installed root, or a publicly trusted certificate for the host's address.

This checks the peer certificate against the pin in QNetworkReply::encrypted, which fires after the handshake and before the request is sent, and aborts on mismatch. A mismatch is reported exactly like an SSL handshake failure (401 "Server certificate mismatch"), so the existing HTTP fallback and re-pair flow is unchanged.

Note: this relies on a fresh handshake per request. That is already the case on every Qt version, because connection caching is disabled.

Tested with a harness linked against the release build's objects, calling NvHTTP::getAppList() against a local TLS server:

Scenario Before After
Genuine host (pinned self-signed cert) OK OK
Impostor, untrusted self-signed rejected, 0 requests reach server rejected, 0 requests
Impostor, cert from a CA the process trusts OK, request delivered rejected, 0 requests
Genuine host, extra trusted CA present OK OK

🤖 Generated with Claude Code

The pinned server certificate was only compared inside the sslErrors()
handler. QNetworkAccessManager does not emit sslErrors() when the
presented certificate chains to a CA trusted by the system and matches
the host name, so in that case the pin was never checked and the
request (including uniqueid and, for launch/resume, the remote input
key) was sent to whoever answered. This can happen behind a TLS
inspection proxy with an installed root CA, or with any publicly
trusted certificate for the host's address.

Check the peer certificate against the pin in the encrypted() signal,
which fires after the handshake and before any request data is sent,
and abort the request on mismatch. The failure is reported the same way
as an SSL handshake failure (401 "Server certificate mismatch").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cgutman

cgutman commented Oct 24, 2026

Copy link
Copy Markdown
Member

This behavior is intentional. It's intended that someone can have Sunshine provide a publicly/privately trusted certificate and clients can use that to authenticate connections to the host.

@cgutman cgutman closed this Oct 24, 2026
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.

2 participants