Skip to content

Commit

Permalink
[FAB-2658] Bug fix: pass correct block data to MCS
Browse files Browse the repository at this point in the history
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 <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Mar 7, 2017
1 parent dc7d4d4 commit 9a5b456
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 35 deletions.
7 changes: 1 addition & 6 deletions gossip/api/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type MessageCryptoService interface {

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

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

// PeerIdentityType is the peer's certificate
type PeerIdentityType []byte

// SignedBlock represents a fabric block that is signed according
// to the latest block verification policy known to the peer
type SignedBlock interface {
}
2 changes: 1 addition & 1 deletion gossip/comm/comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (*naiveSecProvider) GetPKIidOfCert(peerIdentity api.PeerIdentityType) commo

// VerifyBlock returns nil if the block is properly signed,
// else returns error
func (*naiveSecProvider) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
func (*naiveSecProvider) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion gossip/gossip/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func (gc *gossipChannel) verifyBlock(msg *proto.GossipMessage, sender common.PKI
gc.logger.Warning("Received empty payload from", sender)
return false
}
err := gc.mcs.VerifyBlock(msg.Channel, msg.GetDataMsg().Payload)
err := gc.mcs.VerifyBlock(msg.Channel, msg.GetDataMsg().Payload.Data)
if err != nil {
gc.logger.Warning("Received fabricated block from", sender, "in DataUpdate:", err)
return false
Expand Down
2 changes: 1 addition & 1 deletion gossip/gossip/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (cs *cryptoService) VerifyByChannel(channel common.ChainID, identity api.Pe
return args.Get(0).(error)
}

func (cs *cryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
func (cs *cryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
args := cs.Called(signedBlock)
if args.Get(0) == nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (g *gossipServiceImpl) validateMsg(msg proto.ReceivedMessage) bool {
return true
}

if err := g.mcs.VerifyBlock(msg.GetGossipMessage().Channel, blockMsg); err != nil {
if err := g.mcs.VerifyBlock(msg.GetGossipMessage().Channel, blockMsg.Payload.Data); err != nil {
g.logger.Warning("Could not verify block", blockMsg.Payload.SeqNum, ":", err)
return false
}
Expand Down
2 changes: 1 addition & 1 deletion gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (*naiveCryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) com

// VerifyBlock returns nil if the block is properly signed,
// else returns error
func (*naiveCryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
func (*naiveCryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion gossip/identity/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (*naiveCryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) com

// VerifyBlock returns nil if the block is properly signed,
// else returns error
func (*naiveCryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
func (*naiveCryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion gossip/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *cryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) common
return common.PKIidType(peerIdentity)
}

func (s *cryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
func (s *cryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion gossip/service/gossip_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (s *secImpl) GetPKIidOfCert(peerIdentity api.PeerIdentityType) gossipCommon
return gossipCommon.PKIidType(peerIdentity)
}

func (s *secImpl) VerifyBlock(chainID gossipCommon.ChainID, signedBlock api.SignedBlock) error {
func (s *secImpl) VerifyBlock(chainID gossipCommon.ChainID, signedBlock []byte) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion gossip/service/gossip_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func (*naiveCryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityType) gos

// VerifyBlock returns nil if the block is properly signed,
// else returns error
func (*naiveCryptoService) VerifyBlock(chainID gossipCommon.ChainID, signedBlock api.SignedBlock) error {
func (*naiveCryptoService) VerifyBlock(chainID gossipCommon.ChainID, signedBlock []byte) error {
return nil
}

Expand Down
5 changes: 2 additions & 3 deletions gossip/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ package state

import (
"bytes"
"errors"
"fmt"
"strconv"
"sync"
"testing"
"time"

"errors"

pb "github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/configtx/test"
"github.com/hyperledger/fabric/common/util"
Expand Down Expand Up @@ -97,7 +96,7 @@ func (*cryptoServiceMock) GetPKIidOfCert(peerIdentity api.PeerIdentityType) comm

// VerifyBlock returns nil if the block is properly signed,
// else returns error
func (*cryptoServiceMock) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
func (*cryptoServiceMock) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
return nil
}

Expand Down
20 changes: 3 additions & 17 deletions peer/gossip/mcs/mcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ limitations under the License.
package mcs

import (
"bytes"
"errors"
"fmt"

"bytes"

"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric/common/crypto"
"github.com/hyperledger/fabric/common/localmsp"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/gossip/api"
Expand Down Expand Up @@ -54,12 +52,6 @@ type mspMessageCryptoService struct {
deserializer mgmt.DeserializersManager
}

// NewWithMockPolicyManagerGetter returns an instance of MessageCryptoService
// with all defaults but the policies.ChannelPolicyManagerGetter that is mocked
func NewWithMockPolicyManagerGetter() api.MessageCryptoService {
return New(&MockChannelPolicyManagerGetter{}, localmsp.NewSigner(), mgmt.NewDeserializersManager())
}

// New creates a new instance of mspMessageCryptoService
// that implements MessageCryptoService.
// The method takes in input:
Expand Down Expand Up @@ -109,15 +101,9 @@ func (s *mspMessageCryptoService) GetPKIidOfCert(peerIdentity api.PeerIdentityTy

// VerifyBlock returns nil if the block is properly signed,
// else returns error
func (s *mspMessageCryptoService) VerifyBlock(chainID common.ChainID, signedBlock api.SignedBlock) error {
func (s *mspMessageCryptoService) VerifyBlock(chainID common.ChainID, signedBlock []byte) error {
// - Convert signedBlock to common.Block.
// signedBlock is assumed to be a byte array
blockBytes, ok := signedBlock.([]byte)
if !ok {
return fmt.Errorf("Failed casting SignedBlock to []byte on channel [%s]", chainID)
}

block, err := utils.GetBlockFromBlockBytes(blockBytes)
block, err := utils.GetBlockFromBlockBytes(signedBlock)
if err != nil {
return fmt.Errorf("Failed unmarshalling block bytes on channel [%s]: [%s]", chainID, err)
}
Expand Down

0 comments on commit 9a5b456

Please sign in to comment.