diff --git a/cmd/ck-client/ck-client.go b/cmd/ck-client/ck-client.go index 9e99a89..40cc3fc 100644 --- a/cmd/ck-client/ck-client.go +++ b/cmd/ck-client/ck-client.go @@ -127,7 +127,7 @@ func main() { } if *isAdmin { - sta := client.InitState("", "", "", "", time.Now, 0) + sta := client.InitState("", "", "", "", time.Now) err := sta.ParseConfig(pluginOpts) if err != nil { log.Fatal(err) @@ -139,12 +139,7 @@ func main() { return } - // sessionID is usergenerated. There shouldn't be a security concern because the scope of - // sessionID is limited to its UID. - rand.Seed(time.Now().UnixNano()) - sessionID := rand.Uint32() - - sta := client.InitState(localHost, localPort, remoteHost, remotePort, time.Now, sessionID) + sta := client.InitState(localHost, localPort, remoteHost, remotePort, time.Now) err := sta.ParseConfig(pluginOpts) if err != nil { log.Fatal(err) @@ -167,6 +162,11 @@ func main() { start: log.Println("Attemtping to start a new session") + // sessionID is usergenerated. There shouldn't be a security concern because the scope of + // sessionID is limited to its UID. + rand.Seed(time.Now().UnixNano()) + sessionID := rand.Uint32() + sta.SetSessionID(sessionID) var UNLIMITED int64 = 1e12 valve := mux.MakeValve(1e12, 1e12, &UNLIMITED, &UNLIMITED) obfs := mux.MakeObfs(sta.UID) diff --git a/internal/client/state.go b/internal/client/state.go index 93ee3c7..d304c53 100644 --- a/internal/client/state.go +++ b/internal/client/state.go @@ -42,19 +42,20 @@ type State struct { NumConn int } -func InitState(localHost, localPort, remoteHost, remotePort string, nowFunc func() time.Time, sessionID uint32) *State { +func InitState(localHost, localPort, remoteHost, remotePort string, nowFunc func() time.Time) *State { ret := &State{ SS_LOCAL_HOST: localHost, SS_LOCAL_PORT: localPort, SS_REMOTE_HOST: remoteHost, SS_REMOTE_PORT: remotePort, Now: nowFunc, - sessionID: sessionID, } ret.keyPairs = make(map[int64]*keyPair) return ret } +func (sta *State) SetSessionID(id uint32) { sta.sessionID = id } + // semi-colon separated value. This is for Android plugin options func ssvToJson(ssv string) (ret []byte) { unescape := func(s string) string {