From 54605d8c8e2c6c4b2619cf392ac430fecd7a4282 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Dec 2014 21:54:34 +0100 Subject: During env open check for pub error which indicated unencrypted payload. --- whisper/envelope.go | 6 +++++- whisper/whisper.go | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'whisper') diff --git a/whisper/envelope.go b/whisper/envelope.go index 683e88128..dc8d3cda4 100644 --- a/whisper/envelope.go +++ b/whisper/envelope.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/rlp" + "github.com/obscuren/ecies" ) const ( @@ -76,7 +77,10 @@ func (self *Envelope) Open(prv *ecdsa.PrivateKey) (msg *Message, err error) { message.Payload = data[dataStart:] if prv != nil { message.Payload, err = crypto.Decrypt(prv, message.Payload) - if err != nil { + switch err { + case ecies.ErrInvalidPublicKey: // Payload isn't encrypted + return &message, err + default: return nil, fmt.Errorf("unable to open envelope. Decrypt failed: %v", err) } } diff --git a/whisper/whisper.go b/whisper/whisper.go index f91b61d9a..b16ccd1e9 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/p2p" + "github.com/obscuren/ecies" "gopkg.in/fatih/set.v0" ) @@ -229,7 +230,7 @@ func (self *Whisper) envelopes() (envelopes []*Envelope) { func (self *Whisper) postEvent(envelope *Envelope) { for _, key := range self.keys { - if message, err := envelope.Open(key); err == nil { + if message, err := envelope.Open(key); err == nil || (err != nil && err == ecies.ErrInvalidPublicKey) { // Create a custom filter? self.filters.Notify(filter.Generic{ Str1: string(crypto.FromECDSA(key)), Str2: string(crypto.FromECDSAPub(message.Recover())), -- cgit v1.2.3