-
Notifications
You must be signed in to change notification settings - Fork 9
/
tls_wrapper.go
44 lines (39 loc) · 1.38 KB
/
tls_wrapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package shadowtls
import (
"context"
"crypto/tls"
"net"
"github.com/sagernet/sing/common"
)
type (
TLSSessionIDGeneratorFunc func(clientHello []byte, sessionID []byte) error
TLSHandshakeFunc func(
ctx context.Context,
conn net.Conn,
sessionIDGenerator TLSSessionIDGeneratorFunc, // for shadow-tls version 3
) error
)
func DefaultTLSHandshakeFunc(password string, config *tls.Config) TLSHandshakeFunc {
return func(ctx context.Context, conn net.Conn, sessionIDGenerator TLSSessionIDGeneratorFunc) error {
tlsConfig := &sTLSConfig{
Rand: config.Rand,
Time: config.Time,
VerifyPeerCertificate: config.VerifyPeerCertificate,
RootCAs: config.RootCAs,
NextProtos: config.NextProtos,
ServerName: config.ServerName,
InsecureSkipVerify: config.InsecureSkipVerify,
CipherSuites: config.CipherSuites,
MinVersion: config.MinVersion,
MaxVersion: config.MaxVersion,
CurvePreferences: common.Map(config.CurvePreferences, func(it tls.CurveID) sTLSCurveID {
return sTLSCurveID(it)
}),
SessionTicketsDisabled: config.SessionTicketsDisabled,
Renegotiation: sTLSRenegotiationSupport(config.Renegotiation),
SessionIDGenerator: generateSessionID(password),
}
tlsConn := sTLSClient(conn, tlsConfig)
return tlsConn.HandshakeContext(ctx)
}
}