mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-16 17:03:46 +00:00
whisper: The filter's symmetric key hash wasn't properly set at init.
The consequence is that symmetric messages would not be delivered to their intended recipients, because the comparison between two hashes would be false.
This commit is contained in:
parent
019dca9ba2
commit
4fcc7ae046
2 changed files with 37 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
)
|
||||
|
||||
|
|
@ -68,6 +69,10 @@ func (fs *Filters) Install(watcher *Filter) (string, error) {
|
|||
return "", fmt.Errorf("failed to generate unique ID")
|
||||
}
|
||||
|
||||
if watcher.expectsSymmetricEncryption() {
|
||||
watcher.SymKeyHash = crypto.Keccak256Hash(watcher.KeySym);
|
||||
}
|
||||
|
||||
fs.watchers[id] = watcher
|
||||
return id, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,6 +132,38 @@ func TestInstallFilters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestInstallSymKeyGeneratesHash(t *testing.T) {
|
||||
InitSingleTest()
|
||||
|
||||
w := New(&Config{})
|
||||
filters := NewFilters(w)
|
||||
filter, _ := generateFilter(t, true)
|
||||
|
||||
// save the current SymKeyHash for comparison
|
||||
initialSymKeyHash := filter.SymKeyHash
|
||||
|
||||
// ensure the SymKeyHash is invalid, for Install to recreate it
|
||||
var invalid common.Hash
|
||||
filter.SymKeyHash = invalid
|
||||
|
||||
_, err := filters.Install(filter)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error installing the filter: %v", err);
|
||||
}
|
||||
|
||||
identicalBytes := true
|
||||
for i, b := range filter.SymKeyHash {
|
||||
if b != initialSymKeyHash[i] {
|
||||
identicalBytes = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if identicalBytes == false {
|
||||
t.Fatalf("The filter's symmetric key hash was not properly generated by Install")
|
||||
}
|
||||
}
|
||||
|
||||
func TestComparePubKey(t *testing.T) {
|
||||
InitSingleTest()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue