fix: sort public keys in deriveKeys so both sides compute matching send/recv keys
This commit is contained in:
11
sdk/agent.go
11
sdk/agent.go
@@ -1,6 +1,7 @@
|
|||||||
package sdk
|
package sdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
@@ -635,10 +636,16 @@ func isBroadcastMAC(dst []byte) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func deriveKeys(psk, localPub, remotePub []byte) ([32]byte, [32]byte) {
|
func deriveKeys(psk, localPub, remotePub []byte) ([32]byte, [32]byte) {
|
||||||
|
var first, second []byte
|
||||||
|
if bytes.Compare(localPub, remotePub) <= 0 {
|
||||||
|
first, second = localPub, remotePub
|
||||||
|
} else {
|
||||||
|
first, second = remotePub, localPub
|
||||||
|
}
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write(psk)
|
h.Write(psk)
|
||||||
h.Write(localPub)
|
h.Write(first)
|
||||||
h.Write(remotePub)
|
h.Write(second)
|
||||||
var sendKey [32]byte
|
var sendKey [32]byte
|
||||||
copy(sendKey[:], h.Sum(nil))
|
copy(sendKey[:], h.Sum(nil))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user