mirror of https://github.com/cbeuw/Cloak
Add backwards compatibility fallback to firefox
This commit is contained in:
parent
51ed286f35
commit
8af137637e
|
|
@ -21,8 +21,10 @@ func MakeSession(connConfig RemoteConnConfig, authInfo AuthInfo, dialer common.D
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < connConfig.NumConn; i++ {
|
for i := 0; i < connConfig.NumConn; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
transportConfig := connConfig.Transport
|
||||||
go func() {
|
go func() {
|
||||||
makeconn:
|
makeconn:
|
||||||
|
transportConn := transportConfig.CreateTransport()
|
||||||
remoteConn, err := dialer.Dial("tcp", connConfig.RemoteAddr)
|
remoteConn, err := dialer.Dial("tcp", connConfig.RemoteAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to establish new connections to remote: %v", err)
|
log.Errorf("Failed to establish new connections to remote: %v", err)
|
||||||
|
|
@ -31,12 +33,20 @@ func MakeSession(connConfig RemoteConnConfig, authInfo AuthInfo, dialer common.D
|
||||||
goto makeconn
|
goto makeconn
|
||||||
}
|
}
|
||||||
|
|
||||||
transportConn := connConfig.TransportMaker()
|
|
||||||
sk, err := transportConn.Handshake(remoteConn, authInfo)
|
sk, err := transportConn.Handshake(remoteConn, authInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to prepare connection to remote: %v", err)
|
log.Errorf("Failed to prepare connection to remote: %v", err)
|
||||||
transportConn.Close()
|
transportConn.Close()
|
||||||
|
|
||||||
|
// In Cloak v2.11.0, we've updated uTLS version and subsequently increased the first packet size for chrome above 1500
|
||||||
|
// https://github.com/cbeuw/Cloak/pull/306#issuecomment-2862728738. As a backwards compatibility feature, if we fail
|
||||||
|
// to connect using chrome signature, retry with firefox which has a smaller packet size.
|
||||||
|
if transportConfig.mode == "direct" && transportConfig.browser == chrome {
|
||||||
|
transportConfig.browser = firefox
|
||||||
|
log.Warnf("failed to connect with chrome signature, falling back to retry with firefox")
|
||||||
|
}
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
|
|
||||||
goto makeconn
|
goto makeconn
|
||||||
}
|
}
|
||||||
// sessionKey given by each connection should be identical
|
// sessionKey given by each connection should be identical
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,11 @@ type RawConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RemoteConnConfig struct {
|
type RemoteConnConfig struct {
|
||||||
Singleplex bool
|
Singleplex bool
|
||||||
NumConn int
|
NumConn int
|
||||||
KeepAlive time.Duration
|
KeepAlive time.Duration
|
||||||
RemoteAddr string
|
RemoteAddr string
|
||||||
TransportMaker func() Transport
|
Transport TransportConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocalConnConfig struct {
|
type LocalConnConfig struct {
|
||||||
|
|
@ -230,10 +230,9 @@ func (raw *RawConfig) ProcessRawConfig(worldState common.WorldState) (local Loca
|
||||||
raw.CDNWsUrlPath = "/"
|
raw.CDNWsUrlPath = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
remote.TransportMaker = func() Transport {
|
remote.Transport = TransportConfig{
|
||||||
return &WSOverTLS{
|
mode: "cdn",
|
||||||
wsUrl: "ws://" + cdnDomainPort + raw.CDNWsUrlPath,
|
wsUrl: "ws://" + cdnDomainPort + raw.CDNWsUrlPath,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case "direct":
|
case "direct":
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
@ -249,10 +248,9 @@ func (raw *RawConfig) ProcessRawConfig(worldState common.WorldState) (local Loca
|
||||||
default:
|
default:
|
||||||
browser = chrome
|
browser = chrome
|
||||||
}
|
}
|
||||||
remote.TransportMaker = func() Transport {
|
remote.Transport = TransportConfig{
|
||||||
return &DirectTLS{
|
mode: "direct",
|
||||||
browser: browser,
|
browser: browser,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,26 @@ type Transport interface {
|
||||||
Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey [32]byte, err error)
|
Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey [32]byte, err error)
|
||||||
net.Conn
|
net.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TransportConfig struct {
|
||||||
|
mode string
|
||||||
|
|
||||||
|
wsUrl string
|
||||||
|
|
||||||
|
browser browser
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TransportConfig) CreateTransport() Transport {
|
||||||
|
switch t.mode {
|
||||||
|
case "cdn":
|
||||||
|
return &WSOverTLS{
|
||||||
|
wsUrl: t.wsUrl,
|
||||||
|
}
|
||||||
|
case "direct":
|
||||||
|
return &DirectTLS{
|
||||||
|
browser: t.browser,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue