Skip to content

Commit d26b8b4

Browse files
committed
[FAB-1449] Add getPkiID to the commReceivedMsg
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 <[email protected]>
1 parent 06c336d commit d26b8b4

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

gossip/comm/comm.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,17 @@ func (p *RemotePeer) String() string {
6666

6767
// ReceivedMessage is a GossipMessage wrapper that
6868
// enables the user to send a message to the origin from which
69-
// the ReceivedMessage was sent from
69+
// the ReceivedMessage was sent from.
70+
// It also allows to know the identity of the sender
7071
type ReceivedMessage interface {
7172

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

7576
// GetGossipMessage returns the underlying GossipMessage
7677
GetGossipMessage() *proto.GossipMessage
78+
79+
// GetPKIID returns the PKI-ID of the remote peer
80+
// that sent the message
81+
GetPKIID() common.PKIidType
7782
}

gossip/comm/comm_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ func TestBasic(t *testing.T) {
164164
t.Parallel()
165165
comm1, _ := newCommInstance(2000, naiveSec)
166166
comm2, _ := newCommInstance(3000, naiveSec)
167+
defer comm1.Stop()
168+
defer comm2.Stop()
167169
m1 := comm1.Accept(acceptAll)
168170
m2 := comm2.Accept(acceptAll)
169171
out := make(chan uint64, 2)
@@ -179,6 +181,22 @@ func TestBasic(t *testing.T) {
179181
waitForMessages(t, out, 2, "Didn't receive 2 messages")
180182
}
181183

184+
func TestGetPKIID(t *testing.T) {
185+
t.Parallel()
186+
comm1, _ := newCommInstance(6000, naiveSec)
187+
comm2, _ := newCommInstance(7000, naiveSec)
188+
defer comm1.Stop()
189+
defer comm2.Stop()
190+
m1 := comm1.Accept(acceptAll)
191+
comm2.Send(createGossipMsg(), remotePeer(6000))
192+
select {
193+
case <-time.After(time.Second * 10):
194+
t.Fatal("Didn't receive a message in time")
195+
case msg := <-m1:
196+
assert.Equal(t, comm2.GetPKIid(), msg.GetPKIID())
197+
}
198+
}
199+
182200
func TestBlackListPKIid(t *testing.T) {
183201
t.Parallel()
184202
comm1, _ := newCommInstance(1611, naiveSec)

gossip/comm/mock/mock_comm.go

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ func (packet *packetMock) GetGossipMessage() *proto.GossipMessage {
101101
return packet.msg.(*proto.GossipMessage)
102102
}
103103

104+
func (packet *packetMock) GetPKIID() common.PKIidType {
105+
return nil
106+
}
107+
104108
func (mock *commMock) start() {
105109
logger.Debug("Starting communication mock module...")
106110
for {

gossip/comm/msg.go

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package comm
1919
import (
2020
"sync"
2121

22+
"github.com/hyperledger/fabric/gossip/common"
2223
"github.com/hyperledger/fabric/gossip/proto"
2324
)
2425

@@ -38,3 +39,9 @@ func (m *ReceivedMessageImpl) Respond(msg *proto.GossipMessage) {
3839
func (m *ReceivedMessageImpl) GetGossipMessage() *proto.GossipMessage {
3940
return m.GossipMessage
4041
}
42+
43+
// GetPKIID returns the PKI-ID of the remote peer
44+
// that sent the message
45+
func (m *ReceivedMessageImpl) GetPKIID() common.PKIidType {
46+
return m.conn.pkiID
47+
}

gossip/gossip/pull/pullstore_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/hyperledger/fabric/gossip/comm"
26+
"github.com/hyperledger/fabric/gossip/common"
2627
"github.com/hyperledger/fabric/gossip/discovery"
2728
"github.com/hyperledger/fabric/gossip/gossip/algo"
2829
"github.com/hyperledger/fabric/gossip/proto"
@@ -56,6 +57,10 @@ func (pm *pullMsg) GetGossipMessage() *proto.GossipMessage {
5657
return pm.msg
5758
}
5859

60+
func (pm *pullMsg) GetPKIID() common.PKIidType {
61+
return nil
62+
}
63+
5964
type pullInstance struct {
6065
self discovery.NetworkMember
6166
mediator Mediator

0 commit comments

Comments
 (0)