Fix make tls hello failed when reconnect the network
This commit is contained in:
parent
ef230d49a0
commit
ce15e23ce2
@ -3,15 +3,15 @@ mkdir bin
|
|||||||
cd cmd/gost
|
cd cmd/gost
|
||||||
set GOARCH=amd64
|
set GOARCH=amd64
|
||||||
set GOOS=windows
|
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
|
move gost.exe ../../bin
|
||||||
|
|
||||||
set GOARCH=amd64
|
set GOARCH=amd64
|
||||||
set GOOS=linux
|
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
|
move gost ../../bin
|
||||||
|
|
||||||
set GOARCH=arm64
|
set GOARCH=arm64
|
||||||
set GOOS=linux
|
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
|
move gost_arm64 ../../bin
|
48
ws.go
48
ws.go
@ -744,7 +744,28 @@ type websocketConn struct {
|
|||||||
rb []byte
|
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{
|
CipherSuites: []uint16{
|
||||||
utls.GREASE_PLACEHOLDER,
|
utls.GREASE_PLACEHOLDER,
|
||||||
utls.TLS_AES_128_GCM_SHA256,
|
utls.TLS_AES_128_GCM_SHA256,
|
||||||
@ -813,30 +834,7 @@ var wsTlsSpec = &utls.ClientHelloSpec{
|
|||||||
&utls.UtlsGREASEExtension{},
|
&utls.UtlsGREASEExtension{},
|
||||||
&utls.UtlsPaddingExtension{GetPaddingLen: utls.BoringPaddingStyle},
|
&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()
|
err := client.Handshake()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user