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:
Guillaume Ballet 2017-09-18 19:06:20 +02:00
parent 019dca9ba2
commit 4fcc7ae046
2 changed files with 37 additions and 0 deletions

View file

@ -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
}

View file

@ -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()