mirror of https://github.com/cbeuw/Cloak
Refactor client transport modules
This commit is contained in:
parent
896fd16938
commit
4029763123
|
|
@ -20,6 +20,8 @@ type CloakClient struct {
|
|||
session *mux.Session
|
||||
}
|
||||
|
||||
const appDataMaxLength = 16401
|
||||
|
||||
// On different invocations to NewCloakClient, authInfo.SessionId MUST be different
|
||||
func NewCloakClient(connConfig RemoteConnConfig, authInfo AuthInfo, dialer common.Dialer) *CloakClient {
|
||||
log.Info("Attempting to start a new session")
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ type RawConfig struct {
|
|||
BrowserSig string // nullable
|
||||
Transport string // nullable
|
||||
CDNOriginHost string // nullable
|
||||
CDNWsUrlPath string // nullable
|
||||
StreamTimeout int // nullable
|
||||
KeepAlive int // nullable
|
||||
}
|
||||
|
|
@ -47,7 +46,7 @@ type RemoteConnConfig struct {
|
|||
NumConn int
|
||||
KeepAlive time.Duration
|
||||
RemoteAddr string
|
||||
TransportMaker func() Transport
|
||||
TransportMaker func() transports.Transport
|
||||
}
|
||||
|
||||
type LocalConnConfig struct {
|
||||
|
|
@ -56,16 +55,7 @@ type LocalConnConfig struct {
|
|||
MockDomainList []string
|
||||
}
|
||||
|
||||
type AuthInfo struct {
|
||||
UID []byte
|
||||
SessionId uint32
|
||||
ProxyMethod string
|
||||
EncryptionMethod byte
|
||||
Unordered bool
|
||||
ServerPubKey crypto.PublicKey
|
||||
MockDomain string
|
||||
WorldState common.WorldState
|
||||
}
|
||||
type AuthInfo = transports.AuthInfo
|
||||
|
||||
// semi-colon separated value. This is for Android plugin options
|
||||
func ssvToJson(ssv string) (ret []byte) {
|
||||
|
|
@ -220,19 +210,18 @@ func (raw *RawConfig) ProcessRawConfig(worldState common.WorldState) (local Loca
|
|||
// Transport and (if TLS mode), browser
|
||||
switch strings.ToLower(raw.Transport) {
|
||||
case "cdn":
|
||||
var cdnDomainPort string
|
||||
cdnPort := raw.RemotePort
|
||||
var cdnHost string
|
||||
if raw.CDNOriginHost == "" {
|
||||
cdnDomainPort = net.JoinHostPort(raw.RemoteHost, raw.RemotePort)
|
||||
cdnHost = raw.RemoteHost
|
||||
} else {
|
||||
cdnDomainPort = net.JoinHostPort(raw.CDNOriginHost, raw.RemotePort)
|
||||
}
|
||||
if raw.CDNWsUrlPath == "" {
|
||||
raw.CDNWsUrlPath = "/"
|
||||
cdnHost = raw.CDNOriginHost
|
||||
}
|
||||
|
||||
remote.TransportMaker = func() Transport {
|
||||
return &WSOverTLS{
|
||||
wsUrl: "ws://" + cdnDomainPort + raw.CDNWsUrlPath,
|
||||
remote.TransportMaker = func() transports.Transport {
|
||||
return &transports.WSOverTLS{
|
||||
CDNHost: cdnHost,
|
||||
CDNPort: cdnPort,
|
||||
}
|
||||
}
|
||||
case "direct":
|
||||
|
|
@ -249,9 +238,9 @@ func (raw *RawConfig) ProcessRawConfig(worldState common.WorldState) (local Loca
|
|||
default:
|
||||
browser = chrome
|
||||
}
|
||||
remote.TransportMaker = func() Transport {
|
||||
return &DirectTLS{
|
||||
browser: browser,
|
||||
remote.TransportMaker = func() transports.Transport {
|
||||
return &transports.DirectTLS{
|
||||
Browser: browser,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"net"
|
||||
)
|
||||
|
||||
type Transport interface {
|
||||
Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey [32]byte, err error)
|
||||
net.Conn
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package client
|
||||
package transports
|
||||
|
||||
import (
|
||||
utls "github.com/refraction-networking/utls"
|
||||
|
|
@ -27,6 +27,7 @@ const (
|
|||
|
||||
type DirectTLS struct {
|
||||
*common.TLSConn
|
||||
Browser browsers.Browser
|
||||
browser browser
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +89,6 @@ func (tls *DirectTLS) Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey
|
|||
x25519KeyShare: payload.ciphertextWithTag[32:64],
|
||||
serverName: authInfo.MockDomain,
|
||||
}
|
||||
|
||||
var ch []byte
|
||||
ch, err = buildClientHello(tls.browser, fields)
|
||||
if err != nil {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package client
|
||||
package transports
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package client
|
||||
package transports
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package transports
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"github.com/cbeuw/Cloak/internal/common"
|
||||
"net"
|
||||
)
|
||||
|
||||
type Transport interface {
|
||||
Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey [32]byte, err error)
|
||||
net.Conn
|
||||
}
|
||||
|
||||
type AuthInfo struct {
|
||||
UID []byte
|
||||
SessionId uint32
|
||||
ProxyMethod string
|
||||
EncryptionMethod byte
|
||||
Unordered bool
|
||||
ServerPubKey crypto.PublicKey
|
||||
MockDomain string
|
||||
WorldState common.WorldState
|
||||
}
|
||||
|
|
@ -1,21 +1,21 @@
|
|||
package client
|
||||
package transports
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/cbeuw/Cloak/internal/common"
|
||||
"github.com/gorilla/websocket"
|
||||
utls "github.com/refraction-networking/utls"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type WSOverTLS struct {
|
||||
*common.WebSocketConn
|
||||
wsUrl string
|
||||
CDNHost string
|
||||
CDNPort string
|
||||
}
|
||||
|
||||
func (ws *WSOverTLS) Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey [32]byte, err error) {
|
||||
|
|
@ -41,7 +41,7 @@ func (ws *WSOverTLS) Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey
|
|||
return
|
||||
}
|
||||
|
||||
u, err := url.Parse(ws.wsUrl)
|
||||
u, err := url.Parse("ws://" + net.JoinHostPort(ws.CDNHost, ws.CDNPort))
|
||||
if err != nil {
|
||||
return sessionKey, fmt.Errorf("failed to parse ws url: %v", err)
|
||||
}
|
||||
Loading…
Reference in New Issue