Fix make tls hello failed when reconnect the network

This commit is contained in:
wenyifan 2022-10-17 12:22:31 +08:00
parent ef230d49a0
commit ce15e23ce2
2 changed files with 73 additions and 75 deletions

View File

@ -3,15 +3,15 @@ mkdir bin
cd cmd/gost
set GOARCH=amd64
set GOOS=windows
go build --ldflags="-s -w" -v -x -a -o gost.exe
go build --ldflags="-s -w" -v -x -a -trimpath -o gost.exe
move gost.exe ../../bin
set GOARCH=amd64
set GOOS=linux
go build --ldflags="-s -w" -v -x -a -o gost
go build --ldflags="-s -w" -v -x -a -trimpath -o gost
move gost ../../bin
set GOARCH=arm64
set GOOS=linux
go build --ldflags="-s -w" -v -x -a -o gost_arm64
go build --ldflags="-s -w" -v -x -a -trimpath -o gost_arm64
move gost_arm64 ../../bin

48
ws.go
View File

@ -744,7 +744,28 @@ type websocketConn struct {
rb []byte
}
var wsTlsSpec = &utls.ClientHelloSpec{
func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, options *WSOptions) (net.Conn, error) {
if options == nil {
options = &WSOptions{}
}
timeout := options.HandshakeTimeout
if timeout <= 0 {
timeout = HandshakeTimeout
}
dialer := websocket.Dialer{
ReadBufferSize: options.ReadBufferSize,
WriteBufferSize: options.WriteBufferSize,
TLSClientConfig: tlsConfig,
HandshakeTimeout: timeout,
EnableCompression: options.EnableCompression,
NetDial: func(net, addr string) (net.Conn, error) {
return conn, nil
},
NetDialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
client := utls.UClient(conn, &utls.Config{InsecureSkipVerify: tlsConfig.InsecureSkipVerify, ServerName: tlsConfig.ServerName}, utls.HelloCustom)
client.ApplyPreset(&utls.ClientHelloSpec{
CipherSuites: []uint16{
utls.GREASE_PLACEHOLDER,
utls.TLS_AES_128_GCM_SHA256,
@ -813,30 +834,7 @@ var wsTlsSpec = &utls.ClientHelloSpec{
&utls.UtlsGREASEExtension{},
&utls.UtlsPaddingExtension{GetPaddingLen: utls.BoringPaddingStyle},
},
}
func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, options *WSOptions) (net.Conn, error) {
if options == nil {
options = &WSOptions{}
}
timeout := options.HandshakeTimeout
if timeout <= 0 {
timeout = HandshakeTimeout
}
dialer := websocket.Dialer{
ReadBufferSize: options.ReadBufferSize,
WriteBufferSize: options.WriteBufferSize,
TLSClientConfig: tlsConfig,
HandshakeTimeout: timeout,
EnableCompression: options.EnableCompression,
NetDial: func(net, addr string) (net.Conn, error) {
return conn, nil
},
NetDialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
client := utls.UClient(conn, &utls.Config{InsecureSkipVerify: tlsConfig.InsecureSkipVerify, ServerName: tlsConfig.ServerName}, utls.HelloCustom)
client.ApplyPreset(wsTlsSpec)
})
err := client.Handshake()
if err != nil {
return nil, err