Skip to content

Commit 19e07d7

Browse files
committed
[FAB-2007] Gossip: External and internal endpoints IV
In the previous commit we extended the comm layer to support deep scanning of remote peers in order to know whether anchor peers are indeed in the organization it is claimed (in the genesis block) they are. This commit connects between the gossip join-channel logic and this capability into the discovery layer, and makes the gossip logic pass a predicate into the Connect() method of the discovery layer that determines at runtime (as soon as the remote peer is available) - whether the anchor peer is indeed in our organization or not. Also changed the test in a way to check that such a spoofing doesn't work anymore: I added a 3rd anchor peer which is from orgB but is claimed to be in orgA. When I ran the test, it passed and the gossip code complained as follows: ---------------------------------------------------------- WARN 007 Anchor peer localhost:11616 isn't in our org, but is claimed to be Signed-off-by: Yacov Manevich <[email protected]> Change-Id: I2d92628cc5428cc4194a0f3909eb13562b7588a4
1 parent 5eb459a commit 19e07d7

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

gossip/discovery/discovery.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ type Discovery interface {
117117

118118
// Connect makes this instance to connect to a remote instance
119119
// The sendInternalEndpoint param determines whether or not
120-
// to include the internal endpoint in the membership request.
121-
Connect(member NetworkMember, sendInternalEndpoint bool)
120+
// to include the internal endpoint in the membership request,
121+
Connect(member NetworkMember, sendInternalEndpoint func() bool)
122122
}

gossip/discovery/discovery_impl.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,17 @@ func (d *gossipDiscoveryImpl) Lookup(PKIID common.PKIidType) *NetworkMember {
132132
return nm
133133
}
134134

135-
func (d *gossipDiscoveryImpl) Connect(member NetworkMember, sendInternalEndpoint bool) {
135+
func (d *gossipDiscoveryImpl) Connect(member NetworkMember, sendInternalEndpoint func() bool) {
136136
d.logger.Debug("Entering", member)
137137
defer d.logger.Debug("Exiting")
138138

139-
req := d.createMembershipRequest(sendInternalEndpoint).NoopSign()
140-
141139
go func() {
142140
for i := 0; i < maxConnectionAttempts && !d.toDie(); i++ {
143141
peer := &NetworkMember{
144142
InternalEndpoint: member.InternalEndpoint,
145143
Endpoint: member.Endpoint,
146144
}
145+
147146
if !d.comm.Ping(peer) {
148147
if d.toDie() {
149148
return
@@ -152,6 +151,7 @@ func (d *gossipDiscoveryImpl) Connect(member NetworkMember, sendInternalEndpoint
152151
time.Sleep(getReconnectInterval())
153152
continue
154153
}
154+
req := d.createMembershipRequest(sendInternalEndpoint()).NoopSign()
155155
d.comm.SendToPeer(peer, req)
156156
return
157157
}

gossip/discovery/discovery_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func TestConnect(t *testing.T) {
355355
j := (i + 1) % 10
356356
endpoint := fmt.Sprintf("localhost:%d", 7611+j)
357357
netMember2Connect2 := NetworkMember{Endpoint: endpoint, PKIid: []byte(endpoint)}
358-
inst.Connect(netMember2Connect2, false)
358+
inst.Connect(netMember2Connect2, func() bool { return false })
359359
}
360360

361361
time.Sleep(time.Second * 3)

gossip/gossip/gossip_impl.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,22 @@ func (g *gossipServiceImpl) JoinChan(joinMsg api.JoinChannelMessage, chainID com
196196
g.logger.Infof("Anchor peer %s:%d isn't in our org(%v) and we have no external endpoint, skipping", ap.Host, ap.Port, string(ap.OrgID))
197197
continue
198198
}
199+
anchorPeerOrg := ap.OrgID
200+
isInOurOrg := func() bool {
201+
identity, err := g.comm.Handshake(&comm.RemotePeer{Endpoint: endpoint})
202+
if err != nil {
203+
g.logger.Warning("Deep probe of", endpoint, "failed:", err)
204+
return false
205+
}
206+
isAnchorPeerInMyOrg := bytes.Equal(g.selfOrg, g.secAdvisor.OrgByPeerIdentity(identity))
207+
if bytes.Equal(anchorPeerOrg, g.selfOrg) && !isAnchorPeerInMyOrg {
208+
g.logger.Warning("Anchor peer", endpoint, "isn't in our org, but is claimed to be")
209+
}
210+
return isAnchorPeerInMyOrg
211+
}
212+
199213
g.disc.Connect(discovery.NetworkMember{
200-
InternalEndpoint: endpoint, Endpoint: endpoint}, inOurOrg)
214+
InternalEndpoint: endpoint, Endpoint: endpoint}, isInOurOrg)
201215
}
202216
}
203217

gossip/gossip/orgs_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func TestMultipleOrgEndpointLeakage(t *testing.T) {
195195
anchorPeers: []api.AnchorPeer{
196196
{Host: "localhost", Port: 11611, OrgID: api.OrgIdentityType(orgA)},
197197
{Host: "localhost", Port: 11615, OrgID: api.OrgIdentityType(orgB)},
198+
{Host: "localhost", Port: 11616, OrgID: api.OrgIdentityType(orgA)},
198199
},
199200
}
200201

0 commit comments

Comments
 (0)