This commit is contained in:
wenyifan
2023-11-14 00:32:42 +08:00
parent 696d10fc28
commit 6108000cce
4 changed files with 120 additions and 7 deletions

View File

@ -2,7 +2,7 @@ package tls
import (
"context"
"crypto/tls"
tls "github.com/refraction-networking/utls"
"net"
"time"
@ -57,8 +57,20 @@ func (d *tlsDialer) Handshake(ctx context.Context, conn net.Conn, options ...dia
conn.SetDeadline(time.Now().Add(d.md.handshakeTimeout))
defer conn.SetDeadline(time.Time{})
}
tlsConn := tls.Client(conn, d.options.TLSConfig)
tlsConfig := d.options.TLSConfig
utlsConf := &tls.Config{InsecureSkipVerify: tlsConfig.InsecureSkipVerify, ServerName: tlsConfig.ServerName, ClientAuth: tls.ClientAuthType(tlsConfig.ClientAuth), ClientCAs: tlsConfig.ClientCAs, RootCAs: tlsConfig.RootCAs}
if len(tlsConfig.Certificates) > 0 {
for _, certificate := range tlsConfig.Certificates {
utlsConf.Certificates = append(utlsConf.Certificates, tls.Certificate{
Certificate: certificate.Certificate,
PrivateKey: certificate.PrivateKey,
OCSPStaple: certificate.OCSPStaple,
SignedCertificateTimestamps: certificate.SignedCertificateTimestamps,
Leaf: certificate.Leaf,
})
}
}
tlsConn := tls.UClient(conn, utlsConf, tls.HelloChrome_102)
if err := tlsConn.HandshakeContext(ctx); err != nil {
conn.Close()
return nil, err