Skip to content

Commit

Permalink
use the ID corresponding to signKey for published messages
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Sep 6, 2018
1 parent 8de4c59 commit cb7679f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cb7679f

Please sign in to comment.