Move common types to its own package

pull/110/head
Andy Wang 4 years ago
parent 140c8022f5
commit 97858197cd

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

@ -2,6 +2,7 @@ package client
import (
"encoding/binary"
"github.com/cbeuw/Cloak/internal/common"
"net"
"sync"
"sync/atomic"
@ -12,7 +13,7 @@ import (
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")
if !isAdmin {
// sessionID is usergenerated. There shouldn't be a security concern because the scope of

@ -5,6 +5,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/util"
"github.com/gorilla/websocket"
"net"
@ -16,7 +17,7 @@ import (
)
type WSOverTLS struct {
*util.WebSocketConn
*common.WebSocketConn
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)
}
ws.WebSocketConn = &util.WebSocketConn{Conn: c}
ws.WebSocketConn = &common.WebSocketConn{Conn: c}
buf := make([]byte, 128)
n, err := ws.Read(buf)

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

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

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

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

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

@ -5,8 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/cbeuw/Cloak/internal/common"
"github.com/cbeuw/Cloak/internal/server/usermanager"
"github.com/cbeuw/Cloak/internal/util"
"io/ioutil"
"net"
"strings"
@ -33,7 +33,7 @@ type rawConfig struct {
type State struct {
BindAddr []net.Addr
ProxyBook map[string]net.Addr
ProxyDialer util.Dialer
ProxyDialer common.Dialer
Now func() time.Time
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
RedirHost net.Addr
RedirPort string
RedirDialer util.Dialer
RedirDialer common.Dialer
usedRandomM sync.RWMutex
usedRandom map[[32]byte]int64

@ -2,7 +2,7 @@ package server
import (
"errors"
"github.com/cbeuw/Cloak/internal/util"
"github.com/cbeuw/Cloak/internal/common"
"github.com/gorilla/websocket"
"net"
"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)
return
}
ws.conn = &util.WebSocketConn{Conn: c}
ws.conn = &common.WebSocketConn{Conn: c}
ws.finished <- struct{}{}
}

Loading…
Cancel
Save