Skip to content

Commit

Permalink
Merge pull request #216 from githablocal/master
Browse files Browse the repository at this point in the history
Make websocket url sub path configurable
  • Loading branch information
cbeuw authored Mar 7, 2023
2 parents e305871 + 6fe603c commit 0e0ec0e
Show file tree
Hide file tree
Showing 56 changed files with 145 additions and 78 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ Example:
`CDNOriginHost` is the domain name of the _origin_ server (i.e. the server running Cloak) under `CDN` mode. This only
has effect when `Transport` is set to `CDN`. If unset, it will default to the remote hostname supplied via the
commandline argument (in standalone mode), or by Shadowsocks (in plugin mode). After a TLS session is established with
the CDN server, this domain name will be used in the HTTP request to ask the CDN server to establish a WebSocket
connection with this host.
the CDN server, this domain name will be used in the `Host` header of the HTTP request to ask the CDN server to
establish a WebSocket connection with this host.

`CDNWsUrlPath` is the url path used to build websocket request sent under `CDN` mode, and also only has effect
when `Transport` is set to `CDN`. If unset, it will default to "/". This option is used to build the first line of the
HTTP request after a TLS session is extablished. It's mainly for a Cloak server behind a reverse proxy, while only
requests under specific url path are forwarded.

`NumConn` is the amount of underlying TCP connections you want to use. The default of 4 should be appropriate for most
people. Setting it too high will hinder the performance. Setting it to 0 will disable connection multiplexing and each
Expand Down
4 changes: 3 additions & 1 deletion cmd/ck-client/ck-client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.11
// +build go1.11

package main
Expand All @@ -7,10 +8,11 @@ import (
"encoding/binary"
"flag"
"fmt"
"github.com/cbeuw/Cloak/internal/common"
"net"
"os"

"github.com/cbeuw/Cloak/internal/common"

"github.com/cbeuw/Cloak/internal/client"
mux "github.com/cbeuw/Cloak/internal/multiplex"
log "github.com/sirupsen/logrus"
Expand Down
1 change: 1 addition & 0 deletions cmd/ck-client/log.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !android
// +build !android

package main
Expand Down
4 changes: 3 additions & 1 deletion cmd/ck-client/log_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build android
// +build android

package main
Expand All @@ -28,9 +29,10 @@ import "C"

import (
"bufio"
log "github.com/sirupsen/logrus"
"os"
"unsafe"

log "github.com/sirupsen/logrus"
)

var (
Expand Down
1 change: 1 addition & 0 deletions cmd/ck-client/protector.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !android
// +build !android

package main
Expand Down
4 changes: 3 additions & 1 deletion cmd/ck-client/protector_android.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build android
// +build android

package main
Expand Down Expand Up @@ -65,8 +66,9 @@ void set_timeout(int sock) {
import "C"

import (
log "github.com/sirupsen/logrus"
"syscall"

log "github.com/sirupsen/logrus"
)

// In Android, once an app starts the VpnService, all outgoing traffic are routed by the system
Expand Down
7 changes: 4 additions & 3 deletions cmd/ck-server/ck-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package main
import (
"flag"
"fmt"
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/server"
log "github.com/sirupsen/logrus"
"net"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
"strings"

"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/server"
log "github.com/sirupsen/logrus"
)

var version string
Expand Down
3 changes: 2 additions & 1 deletion cmd/ck-server/ck-server_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"github.com/stretchr/testify/assert"
"net"
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseBindAddr(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions cmd/ck-server/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"crypto/rand"
"encoding/base64"

"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/ecdh"
)
Expand Down
3 changes: 2 additions & 1 deletion internal/client/TLS.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package client

import (
"encoding/binary"
"net"

"github.com/cbeuw/Cloak/internal/common"
log "github.com/sirupsen/logrus"
"net"
)

const appDataMaxLength = 16401
Expand Down
3 changes: 2 additions & 1 deletion internal/client/TLS_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package client

import (
"encoding/hex"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func htob(s string) []byte {
Expand Down
1 change: 1 addition & 0 deletions internal/client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"encoding/binary"

"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/ecdh"
log "github.com/sirupsen/logrus"
Expand Down
5 changes: 3 additions & 2 deletions internal/client/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package client

import (
"bytes"
"testing"
"time"

"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/multiplex"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func TestMakeAuthenticationPayload(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions internal/client/chrome.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package client
import (
"encoding/binary"
"encoding/hex"

"github.com/cbeuw/Cloak/internal/common"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/client/connector.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package client

import (
"github.com/cbeuw/Cloak/internal/common"
"net"
"sync"
"sync/atomic"
"time"

"github.com/cbeuw/Cloak/internal/common"

mux "github.com/cbeuw/Cloak/internal/multiplex"
log "github.com/sirupsen/logrus"
)
Expand Down
1 change: 1 addition & 0 deletions internal/client/firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package client
import (
"encoding/binary"
"encoding/hex"

"github.com/cbeuw/Cloak/internal/common"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/client/piper.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package client

import (
"github.com/cbeuw/Cloak/internal/common"
"io"
"net"
"sync"
"time"

"github.com/cbeuw/Cloak/internal/common"

mux "github.com/cbeuw/Cloak/internal/multiplex"
log "github.com/sirupsen/logrus"
)
Expand Down
11 changes: 8 additions & 3 deletions internal/client/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"crypto"
"encoding/json"
"fmt"
"github.com/cbeuw/Cloak/internal/common"
log "github.com/sirupsen/logrus"
"io/ioutil"
"net"
"strings"
"time"

"github.com/cbeuw/Cloak/internal/common"
log "github.com/sirupsen/logrus"

"github.com/cbeuw/Cloak/internal/ecdh"
mux "github.com/cbeuw/Cloak/internal/multiplex"
)
Expand All @@ -36,6 +37,7 @@ type RawConfig struct {
BrowserSig string // nullable
Transport string // nullable
CDNOriginHost string // nullable
CDNWsUrlPath string // nullable
StreamTimeout int // nullable
KeepAlive int // nullable
}
Expand Down Expand Up @@ -224,10 +226,13 @@ func (raw *RawConfig) ProcessRawConfig(worldState common.WorldState) (local Loca
} else {
cdnDomainPort = net.JoinHostPort(raw.CDNOriginHost, raw.RemotePort)
}
if raw.CDNWsUrlPath == "" {
raw.CDNWsUrlPath = "/"
}

remote.TransportMaker = func() Transport {
return &WSOverTLS{
cdnDomainPort: cdnDomainPort,
wsUrl: "ws://" + cdnDomainPort + raw.CDNWsUrlPath,
}
}
case "direct":
Expand Down
3 changes: 2 additions & 1 deletion internal/client/state_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package client

import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseConfig(t *testing.T) {
Expand Down
11 changes: 6 additions & 5 deletions internal/client/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/cbeuw/Cloak/internal/common"
"github.com/gorilla/websocket"
utls "gitlab.com/yawning/utls.git"
"net"
"net/http"
"net/url"

"github.com/cbeuw/Cloak/internal/common"
"github.com/gorilla/websocket"
utls "gitlab.com/yawning/utls.git"
)

type WSOverTLS struct {
*common.WebSocketConn
cdnDomainPort string
wsUrl string
}

func (ws *WSOverTLS) Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey [32]byte, err error) {
Expand All @@ -40,7 +41,7 @@ func (ws *WSOverTLS) Handshake(rawConn net.Conn, authInfo AuthInfo) (sessionKey
return
}

u, err := url.Parse("ws://" + ws.cdnDomainPort)
u, err := url.Parse(ws.wsUrl)
if err != nil {
return sessionKey, fmt.Errorf("failed to parse ws url: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/common/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bytes"
"encoding/hex"
"errors"
"github.com/stretchr/testify/assert"
"io"
"math/rand"
"testing"

"github.com/stretchr/testify/assert"
)

const gcmTagSize = 16
Expand Down
3 changes: 2 additions & 1 deletion internal/common/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package common

import (
"errors"
"github.com/gorilla/websocket"
"io"
"sync"
"time"

"github.com/gorilla/websocket"
)

// WebSocketConn implements io.ReadWriteCloser
Expand Down
3 changes: 2 additions & 1 deletion internal/multiplex/datagramBufferedPipe_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package multiplex

import (
"github.com/stretchr/testify/assert"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestDatagramBuffer_RW(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions internal/multiplex/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package multiplex

import (
"bytes"
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/connutil"
"github.com/stretchr/testify/assert"
"io"
"math/rand"
"net"
"sync"
"testing"

"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/connutil"
"github.com/stretchr/testify/assert"
)

func serveEcho(l net.Listener) {
Expand Down
1 change: 1 addition & 0 deletions internal/multiplex/obfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/binary"
"errors"
"fmt"

"github.com/cbeuw/Cloak/internal/common"
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/salsa20"
Expand Down
5 changes: 3 additions & 2 deletions internal/multiplex/obfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package multiplex
import (
"crypto/aes"
"crypto/cipher"
"github.com/stretchr/testify/assert"
"golang.org/x/crypto/chacha20poly1305"
"math/rand"
"reflect"
"testing"
"testing/quick"

"github.com/stretchr/testify/assert"
"golang.org/x/crypto/chacha20poly1305"
)

func TestGenerateObfs(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/multiplex/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package multiplex
import (
"errors"
"fmt"
"github.com/cbeuw/Cloak/internal/common"
"net"
"sync"
"sync/atomic"
"time"

"github.com/cbeuw/Cloak/internal/common"

log "github.com/sirupsen/logrus"
)

Expand Down
1 change: 1 addition & 0 deletions internal/multiplex/session_fuzz.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build gofuzz
// +build gofuzz

package multiplex
Expand Down
Loading

0 comments on commit 0e0ec0e

Please sign in to comment.