p2p: use bytes.Equal for key comparison

Updates https://github.com/tendermint/tendermint/issues/850

My security alarms falsely blarred when I skimmed and noticed
keys being compared with `==`, without the proper context
so I mistakenly filed an issue, yet the purpose of that
comparison was to check if the local ephemeral public key
was just the least, sorted lexicographically.

Anyways, let's use the proper bytes.Equal check, to save future labor.
This commit is contained in:
Emmanuel Odeke
2017-11-18 21:35:59 -07:00
parent f8c969f5a5
commit 5c34d087d9

View File

@ -67,8 +67,12 @@ func MakeSecretConnection(conn io.ReadWriteCloser, locPrivKey crypto.PrivKeyEd25
// Sort by lexical order. // Sort by lexical order.
loEphPub, hiEphPub := sort32(locEphPub, remEphPub) loEphPub, hiEphPub := sort32(locEphPub, remEphPub)
// Check if the local ephemeral public key
// was the least, lexicographically sorted.
locIsLeast := bytes.Equal(locEphPub[:], loEphPub[:])
// Generate nonces to use for secretbox. // Generate nonces to use for secretbox.
recvNonce, sendNonce := genNonces(loEphPub, hiEphPub, locEphPub == loEphPub) recvNonce, sendNonce := genNonces(loEphPub, hiEphPub, locIsLeast)
// Generate common challenge to sign. // Generate common challenge to sign.
challenge := genChallenge(loEphPub, hiEphPub) challenge := genChallenge(loEphPub, hiEphPub)