MakeSession no longer needs to know if the Session should be admin

This commit is contained in:
Andy Wang 2020-10-15 23:02:51 +01:00
parent f96925982f
commit 3f3259d4d3
3 changed files with 17 additions and 15 deletions

View File

@ -4,6 +4,7 @@ package main
import ( import (
"encoding/base64" "encoding/base64"
"encoding/binary"
"flag" "flag"
"fmt" "fmt"
"github.com/cbeuw/Cloak/internal/common" "github.com/cbeuw/Cloak/internal/common"
@ -151,10 +152,11 @@ func main() {
if adminUID != nil { if adminUID != nil {
log.Infof("API base is %v", localConfig.LocalAddr) log.Infof("API base is %v", localConfig.LocalAddr)
authInfo.UID = adminUID authInfo.UID = adminUID
authInfo.SessionId = 0
remoteConfig.NumConn = 1 remoteConfig.NumConn = 1
seshMaker = func() *mux.Session { seshMaker = func() *mux.Session {
return client.MakeSession(remoteConfig, authInfo, d, true) return client.MakeSession(remoteConfig, authInfo, d)
} }
} else { } else {
var network string var network string
@ -165,7 +167,12 @@ func main() {
} }
log.Infof("Listening on %v %v for %v client", network, localConfig.LocalAddr, authInfo.ProxyMethod) log.Infof("Listening on %v %v for %v client", network, localConfig.LocalAddr, authInfo.ProxyMethod)
seshMaker = func() *mux.Session { seshMaker = func() *mux.Session {
return client.MakeSession(remoteConfig, authInfo, d, false) // sessionID is usergenerated. There shouldn't be a security concern because the scope of
// sessionID is limited to its UID.
quad := make([]byte, 4)
common.RandRead(authInfo.WorldState.Rand, quad)
authInfo.SessionId = binary.BigEndian.Uint32(quad)
return client.MakeSession(remoteConfig, authInfo, d)
} }
} }

View File

@ -1,7 +1,6 @@
package client package client
import ( import (
"encoding/binary"
"github.com/cbeuw/Cloak/internal/common" "github.com/cbeuw/Cloak/internal/common"
"net" "net"
"sync" "sync"
@ -12,18 +11,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
func MakeSession(connConfig RemoteConnConfig, authInfo AuthInfo, dialer common.Dialer, isAdmin bool) *mux.Session { // On different invocations to MakeSession, authInfo.SessionId MUST be different
func MakeSession(connConfig RemoteConnConfig, authInfo AuthInfo, dialer common.Dialer) *mux.Session {
log.Info("Attempting to start a new session") log.Info("Attempting to start a new session")
//TODO: let caller set this
if !isAdmin {
// sessionID is usergenerated. There shouldn't be a security concern because the scope of
// sessionID is limited to its UID.
quad := make([]byte, 4)
common.RandRead(authInfo.WorldState.Rand, quad)
authInfo.SessionId = binary.BigEndian.Uint32(quad)
} else {
authInfo.SessionId = 0
}
connsCh := make(chan net.Conn, connConfig.NumConn) connsCh := make(chan net.Conn, connConfig.NumConn)
var _sessionKey atomic.Value var _sessionKey atomic.Value
@ -48,6 +38,7 @@ func MakeSession(connConfig RemoteConnConfig, authInfo AuthInfo, dialer common.D
time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
goto makeconn goto makeconn
} }
// sessionKey given by each connection should be identical
_sessionKey.Store(sk) _sessionKey.Store(sk)
connsCh <- transportConn connsCh <- transportConn
wg.Done() wg.Done()

View File

@ -3,6 +3,7 @@ package test
import ( import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"encoding/binary"
"fmt" "fmt"
"github.com/cbeuw/Cloak/internal/client" "github.com/cbeuw/Cloak/internal/client"
"github.com/cbeuw/Cloak/internal/common" "github.com/cbeuw/Cloak/internal/common"
@ -185,7 +186,10 @@ func establishSession(lcc client.LocalConnConfig, rcc client.RemoteConnConfig, a
netToCkServerD, ckServerListener := connutil.DialerListener(10 * 1024) netToCkServerD, ckServerListener := connutil.DialerListener(10 * 1024)
clientSeshMaker := func() *mux.Session { clientSeshMaker := func() *mux.Session {
return client.MakeSession(rcc, ai, netToCkServerD, false) quad := make([]byte, 4)
common.RandRead(ai.WorldState.Rand, quad)
ai.SessionId = binary.BigEndian.Uint32(quad)
return client.MakeSession(rcc, ai, netToCkServerD)
} }
var proxyToCkClientD common.Dialer var proxyToCkClientD common.Dialer