mirror of
https://github.com/aler9/rtsp-simple-server
synced 2026-04-22 15:07:19 +08:00
d4c6f95291
when dumpPackets is true, embed TLS master keys into the dump, in a format which is natively compatible with Wireshark.
44 lines
1.1 KiB
Go
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
|
|
}
|