Add two clientmetric counters recording whether TLS DERP client
connections (both HTTPS upgrade and WebSocket paths where TLS state is
available) negotiated a post-quantum or classic key exchange:
- derphttp_connect_tls_pq
- derphttp_connect_tls_classic
Also propagate res.TLS from websocket.Dial in derphttp/websocket.go so
non-js WebSocket dials populate Client.tlsState and report PQ status.
Updates tailscale/corp#52720
Change-Id: Idcbc7fe4580e515632a4ade7a0bbfe9ae266e4f1
Signed-off-by: James Tucker <james@tailscale.com>
Some HTTP proxies (as seen in ChatGPT Work's sandbox) intercept TLS and
refuse DERP's "Upgrade: DERP" request but allow WebSocket upgrades,
like browsers use. derphttp could already speak DERP over WebSockets,
but only on js/wasm or with the ts_debug_websockets build tag and an
envknob, and that path dials with its own http.Client, skipping the
DERP node selection, proxy CONNECT, and TLS logic of the normal path.
Add derphttp.HookUpgradeWebsocket. When it's set and a client's HTTP
upgrade to DERP fails after any TLS handshake succeeded, the client
redials and calls the hook to do a WebSocket handshake over the new
connection instead. Once that works, the client keeps using WebSockets
for its reconnects until they fail, so it doesn't pay for a refused
upgrade every time.
The new feature/derpwebsocket package sets the hook. Neither tailscaled
nor tsnet links it in; programs that want the fallback, like tailcat,
import it.
Updates #22412
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change-Id: I20e4b29f1bca6e7e5e3b33f960ce9d331ec7dac9