diff --git a/whisper/whisperv5/filter.go b/whisper/whisperv5/filter.go index d571160d7f..5775462a7a 100644 --- a/whisper/whisperv5/filter.go +++ b/whisper/whisperv5/filter.go @@ -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 } diff --git a/whisper/whisperv5/filter_test.go b/whisper/whisperv5/filter_test.go index 4ce87eee22..2f3a679111 100644 --- a/whisper/whisperv5/filter_test.go +++ b/whisper/whisperv5/filter_test.go @@ -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()