github.com/xxf098/lite-proxy@v0.15.1-0.20230422081941-12c69f323218/transport/vmess/tls.go (about) 1 package vmess 2 3 import ( 4 "context" 5 "crypto/tls" 6 "net" 7 8 C "github.com/xxf098/lite-proxy/constant" 9 ) 10 11 type TLSConfig struct { 12 Host string 13 SkipCertVerify bool 14 SessionCache tls.ClientSessionCache 15 NextProtos []string 16 } 17 18 func StreamTLSConn(conn net.Conn, cfg *TLSConfig) (net.Conn, error) { 19 tlsConfig := &tls.Config{ 20 ServerName: cfg.Host, 21 InsecureSkipVerify: cfg.SkipCertVerify, 22 ClientSessionCache: cfg.SessionCache, 23 NextProtos: cfg.NextProtos, 24 } 25 26 tlsConn := tls.Client(conn, tlsConfig) 27 ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTLSTimeout) 28 defer cancel() 29 err := tlsConn.HandshakeContext(ctx) 30 return tlsConn, err 31 }