From cb7679f1e46d3e6966c1377702842a396e4d581f Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 6 Sep 2018 10:31:01 +0300 Subject: [PATCH] use the ID corresponding to signKey for published messages --- pubsub.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pubsub.go b/pubsub.go index 091bbc2e..4c0ed55c 100644 --- a/pubsub.go +++ b/pubsub.go @@ -92,6 +92,8 @@ type PubSub struct { // key for signing messages; nil when signing is disabled (default for now) signKey crypto.PrivKey + // source ID for signed messages; corresponds to signKey + signID peer.ID // strict mode rejects all unsigned messages prior to validation signStrict bool @@ -194,7 +196,8 @@ func WithValidateThrottle(n int) Option { func WithMessageSigning(strict bool) Option { return func(p *PubSub) error { - p.signKey = p.host.Peerstore().PrivKey(p.host.ID()) + p.signID = p.host.ID() + p.signKey = p.host.Peerstore().PrivKey(p.signID) p.signStrict = strict return nil } @@ -673,6 +676,7 @@ func (p *PubSub) Publish(topic string, data []byte) error { Seqno: seqno, } if p.signKey != nil { + m.From = []byte(p.signID) err := signMessage(p.signKey, m) if err != nil { return err