diff --git a/internal/server/auth.go b/internal/server/auth.go index e2ff1c9..8054f37 100644 --- a/internal/server/auth.go +++ b/internal/server/auth.go @@ -69,18 +69,19 @@ var ErrBadProxyMethod = errors.New("invalid proxy method") // is authorised. It also returns a finisher callback function to be called when the caller wishes to proceed with // the handshake func PrepareConnection(firstPacket []byte, sta *State, conn net.Conn) (info ClientInfo, finisher func([]byte) (net.Conn, error), err error) { + var transport Transport switch firstPacket[0] { case 0x47: - info.Transport = WebSocket{} + transport = WebSocket{} case 0x16: - info.Transport = TLS{} + transport = TLS{} default: err = ErrUnreconisedProtocol return } var ai authenticationInfo - ai, finisher, err = info.Transport.handshake(firstPacket, sta.staticPv, conn) + ai, finisher, err = transport.handshake(firstPacket, sta.staticPv, conn) if err != nil { return @@ -101,6 +102,6 @@ func PrepareConnection(firstPacket []byte, sta *State, conn net.Conn) (info Clie err = ErrBadProxyMethod return } - + info.Transport = transport return } diff --git a/internal/server/auth_test.go b/internal/server/auth_test.go index 1aa4cb1..15190f5 100644 --- a/internal/server/auth_test.go +++ b/internal/server/auth_test.go @@ -3,6 +3,7 @@ package server import ( "crypto" "encoding/hex" + "fmt" "github.com/cbeuw/Cloak/internal/ecdh" "testing" "time" @@ -123,6 +124,10 @@ func TestPrepareConnection(t *testing.T) { t.Error("failed to get correct session id") return } + if info.Transport.(fmt.Stringer).String() != "TLS" { + t.Errorf("wrong transport: %v", info.Transport) + return + } }) t.Run("TLS correct but replay", func(t *testing.T) { sta := getNewState()