Move common types to its own package

This commit is contained in:
Andy Wang 2020-04-09 00:39:40 +01:00
parent 140c8022f5
commit 97858197cd
10 changed files with 22 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package client
import ( import (
"crypto/rand" "crypto/rand"
"encoding/binary" "encoding/binary"
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/util" "github.com/cbeuw/Cloak/internal/util"
"net" "net"
"time" "time"
@ -57,7 +58,7 @@ func genStegClientHello(ai authenticationPayload, serverName string) (ret client
} }
type DirectTLS struct { type DirectTLS struct {
*util.TLSConn *common.TLSConn
browser browser browser browser
} }
@ -66,13 +67,13 @@ type DirectTLS struct {
func (tls *DirectTLS) Handshake(rawConn net.Conn, authInfo authInfo) (sessionKey [32]byte, err error) { func (tls *DirectTLS) Handshake(rawConn net.Conn, authInfo authInfo) (sessionKey [32]byte, err error) {
payload, sharedSecret := makeAuthenticationPayload(authInfo, rand.Reader, time.Now()) payload, sharedSecret := makeAuthenticationPayload(authInfo, rand.Reader, time.Now())
chOnly := tls.browser.composeClientHello(genStegClientHello(payload, authInfo.MockDomain)) chOnly := tls.browser.composeClientHello(genStegClientHello(payload, authInfo.MockDomain))
chWithRecordLayer := util.AddRecordLayer(chOnly, util.Handshake, util.VersionTLS11) chWithRecordLayer := common.AddRecordLayer(chOnly, common.Handshake, common.VersionTLS11)
_, err = rawConn.Write(chWithRecordLayer) _, err = rawConn.Write(chWithRecordLayer)
if err != nil { if err != nil {
return return
} }
log.Trace("client hello sent successfully") log.Trace("client hello sent successfully")
tls.TLSConn = &util.TLSConn{Conn: rawConn} tls.TLSConn = &common.TLSConn{Conn: rawConn}
buf := make([]byte, 1024) buf := make([]byte, 1024)
log.Trace("waiting for ServerHello") log.Trace("waiting for ServerHello")

View File

@ -2,6 +2,7 @@ package client
import ( import (
"encoding/binary" "encoding/binary"
"github.com/cbeuw/Cloak/internal/common"
"net" "net"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -12,7 +13,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
func MakeSession(connConfig remoteConnConfig, authInfo authInfo, dialer util.Dialer, isAdmin bool) *mux.Session { func MakeSession(connConfig remoteConnConfig, authInfo authInfo, dialer common.Dialer, isAdmin bool) *mux.Session {
log.Info("Attempting to start a new session") log.Info("Attempting to start a new session")
if !isAdmin { if !isAdmin {
// sessionID is usergenerated. There shouldn't be a security concern because the scope of // sessionID is usergenerated. There shouldn't be a security concern because the scope of

View File

@ -5,6 +5,7 @@ import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/util" "github.com/cbeuw/Cloak/internal/util"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"net" "net"
@ -16,7 +17,7 @@ import (
) )
type WSOverTLS struct { type WSOverTLS struct {
*util.WebSocketConn *common.WebSocketConn
cdnDomainPort string cdnDomainPort string
} }
@ -44,7 +45,7 @@ func (ws *WSOverTLS) Handshake(rawConn net.Conn, authInfo authInfo) (sessionKey
return sessionKey, fmt.Errorf("failed to handshake: %v", err) return sessionKey, fmt.Errorf("failed to handshake: %v", err)
} }
ws.WebSocketConn = &util.WebSocketConn{Conn: c} ws.WebSocketConn = &common.WebSocketConn{Conn: c}
buf := make([]byte, 128) buf := make([]byte, 128)
n, err := ws.Read(buf) n, err := ws.Read(buf)

View File

@ -1,4 +1,4 @@
package util package common
import "net" import "net"

View File

@ -1,4 +1,4 @@
package util package common
import ( import (
"encoding/binary" "encoding/binary"

View File

@ -1,4 +1,4 @@
package util package common
import ( import (
"errors" "errors"

View File

@ -2,7 +2,7 @@ package multiplex
import ( import (
"bytes" "bytes"
"github.com/cbeuw/Cloak/internal/util" "github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/connutil" "github.com/cbeuw/connutil"
"io" "io"
"math/rand" "math/rand"
@ -51,8 +51,8 @@ func makeSessionPair(numConn int) (*Session, *Session, []*connPair) {
paris := make([]*connPair, numConn) paris := make([]*connPair, numConn)
for i := 0; i < numConn; i++ { for i := 0; i < numConn; i++ {
c, s := connutil.AsyncPipe() c, s := connutil.AsyncPipe()
clientConn := &util.TLSConn{Conn: c} clientConn := &common.TLSConn{Conn: c}
serverConn := &util.TLSConn{Conn: s} serverConn := &common.TLSConn{Conn: s}
paris[i] = &connPair{ paris[i] = &connPair{
clientConn: clientConn, clientConn: clientConn,
serverConn: serverConn, serverConn: serverConn,

View File

@ -4,8 +4,8 @@ import (
"crypto" "crypto"
"errors" "errors"
"fmt" "fmt"
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/ecdh" "github.com/cbeuw/Cloak/internal/ecdh"
"github.com/cbeuw/Cloak/internal/util"
"net" "net"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -49,7 +49,7 @@ func (TLS) makeResponder(clientHelloSessionId []byte, sharedSecret [32]byte) Res
go originalConn.Close() go originalConn.Close()
return return
} }
preparedConn = &util.TLSConn{Conn: originalConn} preparedConn = &common.TLSConn{Conn: originalConn}
return return
} }
return respond return respond

View File

@ -5,8 +5,8 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/server/usermanager" "github.com/cbeuw/Cloak/internal/server/usermanager"
"github.com/cbeuw/Cloak/internal/util"
"io/ioutil" "io/ioutil"
"net" "net"
"strings" "strings"
@ -33,7 +33,7 @@ type rawConfig struct {
type State struct { type State struct {
BindAddr []net.Addr BindAddr []net.Addr
ProxyBook map[string]net.Addr ProxyBook map[string]net.Addr
ProxyDialer util.Dialer ProxyDialer common.Dialer
Now func() time.Time Now func() time.Time
AdminUID []byte AdminUID []byte
@ -46,7 +46,7 @@ type State struct {
// TODO: this doesn't have to be a net.Addr; resolution is done in Dial automatically // TODO: this doesn't have to be a net.Addr; resolution is done in Dial automatically
RedirHost net.Addr RedirHost net.Addr
RedirPort string RedirPort string
RedirDialer util.Dialer RedirDialer common.Dialer
usedRandomM sync.RWMutex usedRandomM sync.RWMutex
usedRandom map[[32]byte]int64 usedRandom map[[32]byte]int64

View File

@ -2,7 +2,7 @@ package server
import ( import (
"errors" "errors"
"github.com/cbeuw/Cloak/internal/util" "github.com/cbeuw/Cloak/internal/common"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"net" "net"
"net/http" "net/http"
@ -132,6 +132,6 @@ func (ws *wsHandshakeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
log.Errorf("failed to upgrade connection to ws: %v", err) log.Errorf("failed to upgrade connection to ws: %v", err)
return return
} }
ws.conn = &util.WebSocketConn{Conn: c} ws.conn = &common.WebSocketConn{Conn: c}
ws.finished <- struct{}{} ws.finished <- struct{}{}
} }