Skip to content

Commit

Permalink
Fix UsedRandom race
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw committed Mar 5, 2019
1 parent fd28847 commit cd399dc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
3 changes: 1 addition & 2 deletions gqserver/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ func IsSS(input *ClientHello, sta *State) bool {

sta.M.Lock()
used := sta.UsedRandom[random]
sta.UsedRandom[random] = int(sta.Now().Unix())
sta.M.Unlock()

if used != 0 {
log.Println("Replay! Duplicate random")
return false
}

sta.PutUsedRandom(random)

h := sha256.New()
t := int(sta.Now().Unix()) / (12 * 60 * 60)
h.Write([]byte(fmt.Sprintf("%v", t) + sta.Key))
Expand Down
7 changes: 0 additions & 7 deletions gqserver/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ func (sta *State) SetAESKey() {
sta.AESKey = h.Sum(nil)
}

// PutUsedRandom adds a random field into map UsedRandom
func (sta *State) PutUsedRandom(random [32]byte) {
sta.M.Lock()
sta.UsedRandom[random] = int(sta.Now().Unix())
sta.M.Unlock()
}

// UsedRandomCleaner clears the cache of used random fields every 12 hours
func (sta *State) UsedRandomCleaner() {
for {
Expand Down

0 comments on commit cd399dc

Please sign in to comment.