Files
tailscale/derp/derphttp/websocket.go
T
James Tucker aff6d18f39 derp/derphttp: report client metrics for PQ vs classic TLS connections
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 <[email protected]>
2026-12-04 01:00:12 -08:00

41 lines
928 B
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
//go:build js || ((linux || darwin) && ts_debug_websockets)
package derphttp
import (
"context"
"crypto/tls"
"log"
"net"
"github.com/coder/websocket"
"tailscale.com/net/wsconn"
)
const canWebsockets = true
func init() {
dialWebsocketFunc = dialWebsocket
}
func dialWebsocket(ctx context.Context, urlStr string) (net.Conn, *tls.ConnectionState, error) {
c, res, err := websocket.Dial(ctx, urlStr, &websocket.DialOptions{
Subprotocols: []string{"derp"},
})
if err != nil {
log.Printf("websocket Dial: %v, %+v", err, res)
return nil, nil, err
}
log.Printf("websocket: connected to %v", urlStr)
var tlsState *tls.ConnectionState
if res != nil && res.TLS != nil {
cs := *res.TLS
tlsState = &cs
}
netConn := wsconn.NetConn(context.Background(), c, websocket.MessageBinary, urlStr)
return netConn, tlsState, nil
}