clash/transport/vmess/tls.go

33 lines
711 B
Go
Raw Normal View History

2020-04-03 08:04:24 +00:00
package vmess
import (
"context"
2020-04-03 08:04:24 +00:00
"crypto/tls"
2022-07-11 04:37:27 +00:00
tlsC "github.com/Dreamacro/clash/component/tls"
2020-04-03 08:04:24 +00:00
"net"
C "github.com/Dreamacro/clash/constant"
2020-04-03 08:04:24 +00:00
)
type TLSConfig struct {
Host string
SkipCertVerify bool
NextProtos []string
2020-04-03 08:04:24 +00:00
}
func StreamTLSConn(conn net.Conn, cfg *TLSConfig) (net.Conn, error) {
2022-07-10 12:44:24 +00:00
tlsConfig := tlsC.MixinTLSConfig(&tls.Config{
2020-04-03 08:04:24 +00:00
ServerName: cfg.Host,
InsecureSkipVerify: cfg.SkipCertVerify,
NextProtos: cfg.NextProtos,
2022-07-10 12:44:24 +00:00
})
2020-04-03 08:04:24 +00:00
tlsConn := tls.Client(conn, tlsConfig)
// fix tls handshake not timeout
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTLSTimeout)
defer cancel()
err := tlsConn.HandshakeContext(ctx)
2020-04-03 08:04:24 +00:00
return tlsConn, err
}