1 Star 0 Fork 0

小庄 / fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sigfilter.go 2.81 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package msgprocessor
import (
"fmt"
cb "github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/protoutil"
"github.com/pkg/errors"
)
// SigFilterSupport provides the resources required for the signature filter
type SigFilterSupport interface {
// PolicyManager returns a reference to the current policy manager
PolicyManager() policies.Manager
// OrdererConfig returns the config.Orderer for the channel and whether the Orderer config exists
OrdererConfig() (channelconfig.Orderer, bool)
}
// SigFilter stores the name of the policy to apply to deliver requests to
// determine whether a client is authorized
type SigFilter struct {
normalPolicyName string
maintenancePolicyName string
support SigFilterSupport
}
// NewSigFilter creates a new signature filter, at every evaluation, the policy manager is called
// to retrieve the latest version of the policy.
//
// normalPolicyName is applied when Orderer/ConsensusType.State = NORMAL
// maintenancePolicyName is applied when Orderer/ConsensusType.State = MAINTENANCE
func NewSigFilter(normalPolicyName, maintenancePolicyName string, support SigFilterSupport) *SigFilter {
return &SigFilter{
normalPolicyName: normalPolicyName,
maintenancePolicyName: maintenancePolicyName,
support: support,
}
}
// Apply applies the policy given, resulting in Reject or Forward, never Accept
func (sf *SigFilter) Apply(message *cb.Envelope) error {
ordererConf, ok := sf.support.OrdererConfig()
if !ok {
logger.Panic("Programming error: orderer config not found")
}
signedData, err := protoutil.EnvelopeAsSignedData(message)
if err != nil {
return fmt.Errorf("could not convert message to signedData: %s", err)
}
// In maintenance mode, we typically require the signature of /Channel/Orderer/Writers.
// This will filter out configuration changes that are not related to consensus-type migration
// (e.g on /Channel/Application), and will block Deliver requests from peers (which are normally /Channel/Readers).
var policyName = sf.normalPolicyName
if ordererConf.ConsensusState() == orderer.ConsensusType_STATE_MAINTENANCE {
policyName = sf.maintenancePolicyName
}
policy, ok := sf.support.PolicyManager().GetPolicy(policyName)
if !ok {
return fmt.Errorf("could not find policy %s", policyName)
}
err = policy.EvaluateSignedData(signedData)
if err != nil {
logger.Debugf("SigFilter evaluation failed: %s, policyName: %s, ConsensusState: %s", err.Error(), policyName, ordererConf.ConsensusState())
return errors.Wrap(errors.WithStack(ErrPermissionDenied), err.Error())
}
return nil
}
1
https://gitee.com/zhuanglicheng/fabric.git
git@gitee.com:zhuanglicheng/fabric.git
zhuanglicheng
fabric
fabric
v2.1.1

搜索帮助