Files
rtsp-simple-server/internal/packetdumper/dial_tls_context.go
T
Alessandro Ros d4c6f95291 dump unencrypted TLS sessions (#5624)
when dumpPackets is true, embed TLS master keys into the dump, in a
format which is natively compatible with Wireshark.
2026-04-04 14:46:43 +02:00

44 lines
1.1 KiB
Go

package packetdumper
import (
"context"
"crypto/tls"
"net"
)
// DialTLSContext provides the DialTLSContext function.
type DialTLSContext struct {
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
TLSConfig *tls.Config
}
// Do provides DialTLSContext.
func (t *DialTLSContext) Do(ctx context.Context, network, addr string) (net.Conn, error) {
netConn, err := t.DialContext(ctx, network, addr)
if err != nil {
return nil, err
}
// clone TLS config and fill ServerName if empty.
// this is the same behavior of http.Client.
// https://cs.opensource.google/go/go/+/master:src/net/http/transport.go;l=1754;drc=a4b534f5e42fe58d58c0ff0562d76680cedb0466
tlsConfig := t.TLSConfig
if tlsConfig == nil {
tlsConfig = &tls.Config{}
} else {
tlsConfig = tlsConfig.Clone()
}
if tlsConfig.ServerName == "" {
host, _, _ := net.SplitHostPort(addr)
tlsConfig.ServerName = host
}
pdConn := netConn.(*conn)
pdConn.expectingSecrets = 4
tlsConfig.KeyLogWriter = &connKeyLogWriter{c: pdConn}
return tls.Client(netConn, tlsConfig), nil
}