Skip to content

Commit 9a5b456

Browse files
committed
[FAB-2658] Bug fix: pass correct block data to MCS
The MessageCryptoService complains: verifyBlock -> WARN 0cc Received fabricated block from [...]\ in DataUpdate: Failed casting SignedBlock to []byte on channel [foo] Because the object that was passed wasn't a []byte as expected but the object that contains the []byte as a field. I changed the signature of VerifyBlock to accept []byte instead of the previous interface type api.SignedBlock and removed the latter type. Change-Id: I7320c398b117072c0790f77d9c0f9305b1adf5ea Signed-off-by: Yacov Manevich <[email protected]>
1 parent dc7d4d4 commit 9a5b456

File tree

12 files changed

+15
-35
lines changed

12 files changed

+15
-35
lines changed

gossip/api/crypto.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type MessageCryptoService interface {
3232

3333
// VerifyBlock returns nil if the block is properly signed,
3434
// else returns error
35-
VerifyBlock(chainID common.ChainID, signedBlock SignedBlock) error
35+
VerifyBlock(chainID common.ChainID, signedBlock []byte) error
3636

3737
// Sign signs msg with this peer's signing key and outputs
3838
// the signature if no error occurred.
@@ -57,8 +57,3 @@ type MessageCryptoService interface {
5757

5858
// PeerIdentityType is the peer's certificate
5959
type PeerIdentityType []byte
60-
61-
// SignedBlock represents a fabric block that is signed according
62-
// to the latest block verification policy known to the peer
63-
type SignedBlock interface {
64-
}

gossip/comm/comm_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (*naiveSecProvider) GetPKIidOfCert(peerIdentity api.PeerIdentityType) commo
6565

6666
// VerifyBlock returns nil if the block is properly signed,
6767
// else returns error
68-
func (*naiveSecProvider) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
68+
func (*naiveSecProvider) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
6969
return nil
7070
}
7171

gossip/gossip/channel/channel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func (gc *gossipChannel) verifyBlock(msg *proto.GossipMessage, sender common.PKI
487487
gc.logger.Warning("Received empty payload from", sender)
488488
return false
489489
}
490-
err := gc.mcs.VerifyBlock(msg.Channel, msg.GetDataMsg().Payload)
490+
err := gc.mcs.VerifyBlock(msg.Channel, msg.GetDataMsg().Payload.Data)
491491
if err != nil {
492492
gc.logger.Warning("Received fabricated block from", sender, "in DataUpdate:", err)
493493
return false

gossip/gossip/channel/channel_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (cs *cryptoService) VerifyByChannel(channel common.ChainID, identity api.Pe
104104
return args.Get(0).(error)
105105
}
106106

107-
func (cs *cryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
107+
func (cs *cryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
108108
args := cs.Called(signedBlock)
109109
if args.Get(0) == nil {
110110
return nil

gossip/gossip/gossip_impl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func (g *gossipServiceImpl) validateMsg(msg proto.ReceivedMessage) bool {
387387
return true
388388
}
389389

390-
if err := g.mcs.VerifyBlock(msg.GetGossipMessage().Channel, blockMsg); err != nil {
390+
if err := g.mcs.VerifyBlock(msg.GetGossipMessage().Channel, blockMsg.Payload.Data); err != nil {
391391
g.logger.Warning("Could not verify block", blockMsg.Payload.SeqNum, ":", err)
392392
return false
393393
}

gossip/gossip/gossip_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (*naiveCryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) com
130130

131131
// VerifyBlock returns nil if the block is properly signed,
132132
// else returns error
133-
func (*naiveCryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
133+
func (*naiveCryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
134134
return nil
135135
}
136136

gossip/identity/identity_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (*naiveCryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) com
4242

4343
// VerifyBlock returns nil if the block is properly signed,
4444
// else returns error
45-
func (*naiveCryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
45+
func (*naiveCryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
4646
return nil
4747
}
4848

gossip/integration/integration_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (s *cryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) common
9595
return common.PKIidType(peerIdentity)
9696
}
9797

98-
func (s *cryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
98+
func (s *cryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
9999
return nil
100100
}
101101

gossip/service/gossip_service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (s *secImpl) GetPKIidOfCert(peerIdentity api.PeerIdentityType) gossipCommon
293293
return gossipCommon.PKIidType(peerIdentity)
294294
}
295295

296-
func (s *secImpl) VerifyBlock(chainID gossipCommon.ChainID, signedBlock api.SignedBlock) error {
296+
func (s *secImpl) VerifyBlock(chainID gossipCommon.ChainID, signedBlock []byte) error {
297297
return nil
298298
}
299299

gossip/service/gossip_service_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ func (*naiveCryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) gos
662662

663663
// VerifyBlock returns nil if the block is properly signed,
664664
// else returns error
665-
func (*naiveCryptoService) VerifyBlock(chainID gossipCommon.ChainID, signedBlock api.SignedBlock) error {
665+
func (*naiveCryptoService) VerifyBlock(chainID gossipCommon.ChainID, signedBlock []byte) error {
666666
return nil
667667
}
668668

gossip/state/state_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ package state
1818

1919
import (
2020
"bytes"
21+
"errors"
2122
"fmt"
2223
"strconv"
2324
"sync"
2425
"testing"
2526
"time"
2627

27-
"errors"
28-
2928
pb "github.com/golang/protobuf/proto"
3029
"github.com/hyperledger/fabric/common/configtx/test"
3130
"github.com/hyperledger/fabric/common/util"
@@ -97,7 +96,7 @@ func (*cryptoServiceMock) GetPKIidOfCert(peerIdentity api.PeerIdentityType) comm
9796

9897
// VerifyBlock returns nil if the block is properly signed,
9998
// else returns error
100-
func (*cryptoServiceMock) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
99+
func (*cryptoServiceMock) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
101100
return nil
102101
}
103102

peer/gossip/mcs/mcs.go

+3-17
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ limitations under the License.
1717
package mcs
1818

1919
import (
20+
"bytes"
2021
"errors"
2122
"fmt"
2223

23-
"bytes"
24-
2524
"github.com/hyperledger/fabric/bccsp"
2625
"github.com/hyperledger/fabric/bccsp/factory"
2726
"github.com/hyperledger/fabric/common/crypto"
28-
"github.com/hyperledger/fabric/common/localmsp"
2927
"github.com/hyperledger/fabric/common/policies"
3028
"github.com/hyperledger/fabric/common/util"
3129
"github.com/hyperledger/fabric/gossip/api"
@@ -54,12 +52,6 @@ type mspMessageCryptoService struct {
5452
deserializer mgmt.DeserializersManager
5553
}
5654

57-
// NewWithMockPolicyManagerGetter returns an instance of MessageCryptoService
58-
// with all defaults but the policies.ChannelPolicyManagerGetter that is mocked
59-
func NewWithMockPolicyManagerGetter() api.MessageCryptoService {
60-
return New(&MockChannelPolicyManagerGetter{}, localmsp.NewSigner(), mgmt.NewDeserializersManager())
61-
}
62-
6355
// New creates a new instance of mspMessageCryptoService
6456
// that implements MessageCryptoService.
6557
// The method takes in input:
@@ -109,15 +101,9 @@ func (s *mspMessageCryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityTy
109101

110102
// VerifyBlock returns nil if the block is properly signed,
111103
// else returns error
112-
func (s *mspMessageCryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
104+
func (s *mspMessageCryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
113105
// - Convert signedBlock to common.Block.
114-
// signedBlock is assumed to be a byte array
115-
blockBytes, ok := signedBlock.([]byte)
116-
if !ok {
117-
return fmt.Errorf("Failed casting SignedBlock to []byte on channel [%s]", chainID)
118-
}
119-
120-
block, err := utils.GetBlockFromBlockBytes(blockBytes)
106+
block, err := utils.GetBlockFromBlockBytes(signedBlock)
121107
if err != nil {
122108
return fmt.Errorf("Failed unmarshalling block bytes on channel [%s]: [%s]", chainID, err)
123109
}

0 commit comments

Comments
 (0)