diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-08-07 15:25:04 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-08-07 15:25:04 +0200 |
commit | cba1d6585ab9b12ae3e0897db85675ba452c3f09 (patch) | |
tree | 13d0975bf53a107c2760c833fd07f36d860a338a /src/macs.go | |
parent | 8c34c4cbb3780c433148966a004f5a51aace0f64 (diff) | |
download | wireguard-go-cba1d6585ab9b12ae3e0897db85675ba452c3f09.tar.gz wireguard-go-cba1d6585ab9b12ae3e0897db85675ba452c3f09.zip |
Number of fixes in response to code review
This version cannot complete a handshake.
The program will panic upon receiving any message on the UDP socket.
Diffstat (limited to '')
-rw-r--r-- | src/macs.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/macs.go b/src/macs.go index beb5f76..d55e18f 100644 --- a/src/macs.go +++ b/src/macs.go @@ -18,12 +18,13 @@ type MACStateDevice struct { } type MACStatePeer struct { - mutex sync.RWMutex - cookieSet time.Time - cookie [blake2s.Size128]byte - lastMAC1 [blake2s.Size128]byte // TODO: Check if set - keyMAC1 [blake2s.Size]byte - keyMAC2 [blake2s.Size]byte + mutex sync.RWMutex + cookieSet time.Time + cookie [blake2s.Size128]byte + lastMAC1Set bool + lastMAC1 [blake2s.Size128]byte + keyMAC1 [blake2s.Size]byte + keyMAC2 [blake2s.Size]byte } /* Methods for verifing MAC fields @@ -184,6 +185,10 @@ func (device *Device) ConsumeMessageCookieReply(msg *MessageCookieReply) bool { state.mutex.Lock() defer state.mutex.Unlock() + if !state.lastMAC1Set { + return false + } + _, err := XChaCha20Poly1305Decrypt( cookie[:0], &msg.Nonce, @@ -246,7 +251,7 @@ func (state *MACStatePeer) AddMacs(msg []byte) { mac.Sum(mac1[:0]) }() copy(state.lastMAC1[:], mac1) - // TODO: Set lastMac flag + state.lastMAC1Set = true // set mac2 |