Skip to content

Commit

Permalink
[FAB-1449] Add getPkiID to the commReceivedMsg
Browse files Browse the repository at this point in the history
Some messages in gossip aren't signed,
because they are sent only point-to-point
so the identity of the sender can be extracted
from the PKI-ID that's sent during the comm layer authentication.

In order to support multi-channel related access control
for messages that are point-to-point I need to add getPkiID to the interface.
The idea is that the gossip layer would drop point-to-point
messages that came from peers that are not in the channel.

Change-Id: I0468a26764366fb5d02f8db846969209eea024d3
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Dec 19, 2016
1 parent 06c336d commit d26b8b4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gossip/comm/comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,17 @@ func (p *RemotePeer) String() string {

// ReceivedMessage is a GossipMessage wrapper that
// enables the user to send a message to the origin from which
// the ReceivedMessage was sent from
// the ReceivedMessage was sent from.
// It also allows to know the identity of the sender
type ReceivedMessage interface {

// Respond sends a GossipMessage to the origin from which this ReceivedMessage was sent from
Respond(msg *proto.GossipMessage)

// GetGossipMessage returns the underlying GossipMessage
GetGossipMessage() *proto.GossipMessage

// GetPKIID returns the PKI-ID of the remote peer
// that sent the message
GetPKIID() common.PKIidType
}
18 changes: 18 additions & 0 deletions gossip/comm/comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func TestBasic(t *testing.T) {
t.Parallel()
comm1, _ := newCommInstance(2000, naiveSec)
comm2, _ := newCommInstance(3000, naiveSec)
defer comm1.Stop()
defer comm2.Stop()
m1 := comm1.Accept(acceptAll)
m2 := comm2.Accept(acceptAll)
out := make(chan uint64, 2)
Expand All @@ -179,6 +181,22 @@ func TestBasic(t *testing.T) {
waitForMessages(t, out, 2, "Didn't receive 2 messages")
}

func TestGetPKIID(t *testing.T) {
t.Parallel()
comm1, _ := newCommInstance(6000, naiveSec)
comm2, _ := newCommInstance(7000, naiveSec)
defer comm1.Stop()
defer comm2.Stop()
m1 := comm1.Accept(acceptAll)
comm2.Send(createGossipMsg(), remotePeer(6000))
select {
case <-time.After(time.Second * 10):
t.Fatal("Didn't receive a message in time")
case msg := <-m1:
assert.Equal(t, comm2.GetPKIid(), msg.GetPKIID())
}
}

func TestBlackListPKIid(t *testing.T) {
t.Parallel()
comm1, _ := newCommInstance(1611, naiveSec)
Expand Down
4 changes: 4 additions & 0 deletions gossip/comm/mock/mock_comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func (packet *packetMock) GetGossipMessage() *proto.GossipMessage {
return packet.msg.(*proto.GossipMessage)
}

func (packet *packetMock) GetPKIID() common.PKIidType {
return nil
}

func (mock *commMock) start() {
logger.Debug("Starting communication mock module...")
for {
Expand Down
7 changes: 7 additions & 0 deletions gossip/comm/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package comm
import (
"sync"

"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/proto"
)

Expand All @@ -38,3 +39,9 @@ func (m *ReceivedMessageImpl) Respond(msg *proto.GossipMessage) {
func (m *ReceivedMessageImpl) GetGossipMessage() *proto.GossipMessage {
return m.GossipMessage
}

// GetPKIID returns the PKI-ID of the remote peer
// that sent the message
func (m *ReceivedMessageImpl) GetPKIID() common.PKIidType {
return m.conn.pkiID
}
5 changes: 5 additions & 0 deletions gossip/gossip/pull/pullstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/hyperledger/fabric/gossip/comm"
"github.com/hyperledger/fabric/gossip/common"
"github.com/hyperledger/fabric/gossip/discovery"
"github.com/hyperledger/fabric/gossip/gossip/algo"
"github.com/hyperledger/fabric/gossip/proto"
Expand Down Expand Up @@ -56,6 +57,10 @@ func (pm *pullMsg) GetGossipMessage() *proto.GossipMessage {
return pm.msg
}

func (pm *pullMsg) GetPKIID() common.PKIidType {
return nil
}

type pullInstance struct {
self discovery.NetworkMember
mediator Mediator
Expand Down

0 comments on commit d26b8b4

Please sign in to comment.