From 4fcc7ae04663707ea25c3c1e92e6e7089230221a Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Mon, 18 Sep 2017 19:06:20 +0200 Subject: [PATCH] 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. --- whisper/whisperv5/filter.go | 5 +++++ whisper/whisperv5/filter_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) 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()