Skip to content

Commit 1231f74

Browse files
committedSep 2, 2017
[FAB-6018] Make handshake sign even when no TLS
The private data pull needs to be able to determine if a peer is eligible of receiving a private RW set of a certain collection by evaluating a policy. The policy needs a signature and some signed message. If TLS is used, the peer can use the Authentication info from the handshake, but if the peer doesn't use TLS - the authentication info isn't populated. This commit makes the handshake sign anyway the connection established message, and removes the "IsAuthenticated" method. Note: This doesn't mean, of course - that not using TLS is secure now. It only means that the handshake message is signed, but that doesn't imply that an attacker cannot do a MITM if TLS isn't used. Change-Id: I376abda11060c1fe69c2b0b64d6b3d115f0114aa Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 34eb8fe commit 1231f74

File tree

5 files changed

+18
-54
lines changed

5 files changed

+18
-54
lines changed
 

‎gossip/comm/comm_impl.go

+16-25
Original file line numberDiff line numberDiff line change
@@ -405,20 +405,10 @@ func (c *commImpl) authenticateRemotePeer(stream stream) (*proto.ConnectionInfo,
405405
remoteCertHash := extractCertificateHashFromContext(ctx)
406406
var err error
407407
var cMsg *proto.SignedGossipMessage
408-
var signer proto.Signer
409408
useTLS := c.selfCertHash != nil
410409

411-
// If TLS is enabled, sign the connection message in order to bind
412-
// the TLS session to the peer's identity
413-
if useTLS {
414-
signer = func(msg []byte) ([]byte, error) {
415-
return c.idMapper.Sign(msg)
416-
}
417-
} else { // If we don't use TLS, we have no unique text to sign,
418-
// so don't sign anything
419-
signer = func(msg []byte) ([]byte, error) {
420-
return msg, nil
421-
}
410+
signer := func(msg []byte) ([]byte, error) {
411+
return c.idMapper.Sign(msg)
422412
}
423413

424414
// TLS enabled but not detected on other side
@@ -461,6 +451,10 @@ func (c *commImpl) authenticateRemotePeer(stream stream) (*proto.ConnectionInfo,
461451
ID: receivedMsg.PkiId,
462452
Identity: receivedMsg.Identity,
463453
Endpoint: remoteAddress,
454+
Auth: &proto.AuthInfo{
455+
Signature: m.Signature,
456+
SignedData: m.Payload,
457+
},
464458
}
465459

466460
// if TLS is enabled and detected, verify remote peer
@@ -470,19 +464,16 @@ func (c *commImpl) authenticateRemotePeer(stream stream) (*proto.ConnectionInfo,
470464
if !bytes.Equal(remoteCertHash, receivedMsg.TlsCertHash) {
471465
return nil, errors.Errorf("Expected %v in remote hash of TLS cert, but got %v", remoteCertHash, receivedMsg.TlsCertHash)
472466
}
473-
verifier := func(peerIdentity []byte, signature, message []byte) error {
474-
pkiID := c.idMapper.GetPKIidOfCert(api.PeerIdentityType(peerIdentity))
475-
return c.idMapper.Verify(pkiID, signature, message)
476-
}
477-
err = m.Verify(receivedMsg.Identity, verifier)
478-
if err != nil {
479-
c.logger.Errorf("Failed verifying signature from %s : %v", remoteAddress, err)
480-
return nil, err
481-
}
482-
connInfo.Auth = &proto.AuthInfo{
483-
Signature: m.Signature,
484-
SignedData: m.Payload,
485-
}
467+
}
468+
// Final step - verify the signature on the connection message itself
469+
verifier := func(peerIdentity []byte, signature, message []byte) error {
470+
pkiID := c.idMapper.GetPKIidOfCert(api.PeerIdentityType(peerIdentity))
471+
return c.idMapper.Verify(pkiID, signature, message)
472+
}
473+
err = m.Verify(receivedMsg.Identity, verifier)
474+
if err != nil {
475+
c.logger.Errorf("Failed verifying signature from %s : %v", remoteAddress, err)
476+
return nil, err
486477
}
487478

488479
c.logger.Debug("Authenticated", remoteAddress)

‎gossip/comm/comm_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ func TestHandshake(t *testing.T) {
203203
assert.Equal(t, expectedPKIID, msg.GetConnectionInfo().ID)
204204
assert.Equal(t, api.PeerIdentityType(endpoint), msg.GetConnectionInfo().Identity)
205205
assert.NotNil(t, msg.GetConnectionInfo().Auth)
206-
assert.True(t, msg.GetConnectionInfo().IsAuthenticated())
207206
sig, _ := (&naiveSecProvider{}).Sign(msg.GetConnectionInfo().Auth.SignedData)
208207
assert.Equal(t, sig, msg.GetConnectionInfo().Auth.Signature)
209208
}
@@ -230,8 +229,8 @@ func TestHandshake(t *testing.T) {
230229
}
231230
assert.Equal(t, common.PKIidType("localhost:9608"), msg.GetConnectionInfo().ID)
232231
assert.Equal(t, api.PeerIdentityType("localhost:9608"), msg.GetConnectionInfo().Identity)
233-
assert.Nil(t, msg.GetConnectionInfo().Auth)
234-
assert.False(t, msg.GetConnectionInfo().IsAuthenticated())
232+
sig, _ := (&naiveSecProvider{}).Sign(msg.GetConnectionInfo().Auth.SignedData)
233+
assert.Equal(t, sig, msg.GetConnectionInfo().Auth.Signature)
235234

236235
inst.Stop()
237236
s.Stop()

‎gossip/state/state.go

-5
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ func NewGossipStateProvider(chainID string, services *ServicesMediator, ledger l
175175
if !msg.IsRemoteStateMessage() {
176176
return false
177177
}
178-
// If we're not running with authentication, no point
179-
// in enforcing access control
180-
if !receivedMsg.GetConnectionInfo().IsAuthenticated() {
181-
return true
182-
}
183178
connInfo := receivedMsg.GetConnectionInfo()
184179
authErr := services.VerifyByChannel(msg.Channel, connInfo.Identity, connInfo.Auth.Signature, connInfo.Auth.SignedData)
185180
if authErr != nil {

‎protos/gossip/extensions.go

-6
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,6 @@ func (c *ConnectionInfo) String() string {
345345
return fmt.Sprintf("%s %v", c.Endpoint, c.ID)
346346
}
347347

348-
// IsAuthenticated returns whether the connection to the remote peer
349-
// was authenticated when the handshake took place
350-
func (c *ConnectionInfo) IsAuthenticated() bool {
351-
return c.Auth != nil
352-
}
353-
354348
// AuthInfo represents the authentication
355349
// data that was provided by the remote peer
356350
// at the connection time

‎protos/gossip/extensions_test.go

-15
Original file line numberDiff line numberDiff line change
@@ -673,21 +673,6 @@ func TestGossipMessageLeadershipMessageTagType(t *testing.T) {
673673
assert.Error(t, msg.IsTagLegal())
674674
}
675675

676-
func TestConnectionInfo_IsAuthenticated(t *testing.T) {
677-
connInfo := &ConnectionInfo{
678-
ID: common.PKIidType("peerID"),
679-
}
680-
681-
assert.False(t, connInfo.IsAuthenticated())
682-
683-
connInfo = &ConnectionInfo{
684-
ID: common.PKIidType("peerID"),
685-
Auth: &AuthInfo{},
686-
}
687-
688-
assert.True(t, connInfo.IsAuthenticated())
689-
}
690-
691676
func TestGossipMessageSign(t *testing.T) {
692677
idSigner := func(msg []byte) ([]byte, error) {
693678
return msg, nil

0 commit comments

Comments
 (0)
Please sign in to comment.