This commit is contained in:
wenyifan
2023-11-15 15:45:09 +08:00
parent 52aa2027d0
commit 3038eb66d8
5 changed files with 118 additions and 77 deletions

View File

@ -2,8 +2,8 @@ package mtls
import (
"context"
"crypto/tls"
"errors"
tls "github.com/refraction-networking/utls"
"net"
"sync"
"time"
@ -123,7 +123,20 @@ func (d *mtlsDialer) Handshake(ctx context.Context, conn net.Conn, options ...di
}
func (d *mtlsDialer) initSession(ctx context.Context, conn net.Conn) (*muxSession, error) {
tlsConn := tls.Client(conn, d.options.TLSConfig)
tlsConfig := d.options.TLSConfig
var 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_Auto)
if err := tlsConn.HandshakeContext(ctx); err != nil {
return nil, err
}