/
sigfilter.go
66 lines (53 loc) · 1.71 KB
/
sigfilter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//此源码被清华学神尹成大魔王专业翻译分析并修改
//尹成QQ77025077
//尹成微信18510341407
//尹成所在QQ群721929980
//尹成邮箱 yinc13@mails.tsinghua.edu.cn
//尹成毕业于清华大学,微软区块链领域全球最有价值专家
//https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
/*
版权所有IBM公司。保留所有权利。
SPDX许可证标识符:Apache-2.0
**/
package msgprocessor
import (
"fmt"
"github.com/hyperledger/fabric/common/policies"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/pkg/errors"
)
//sigfiltersupport提供签名筛选器所需的资源
type SigFilterSupport interface {
//policyManager返回对当前策略管理器的引用
PolicyManager() policies.Manager
}
//sigfilter存储应用于将请求传递到的策略的名称
//确定客户是否被授权
type SigFilter struct {
policyName string
support SigFilterSupport
}
//newsigfilter创建一个新的签名筛选器,每次评估时都调用策略管理器
//检索策略的最新版本
func NewSigFilter(policyName string, support SigFilterSupport) *SigFilter {
return &SigFilter{
policyName: policyName,
support: support,
}
}
//应用应用应用给定的策略,导致拒绝或转发,从不接受
func (sf *SigFilter) Apply(message *cb.Envelope) error {
signedData, err := message.AsSignedData()
if err != nil {
return fmt.Errorf("could not convert message to signedData: %s", err)
}
policy, ok := sf.support.PolicyManager().GetPolicy(sf.policyName)
if !ok {
return fmt.Errorf("could not find policy %s", sf.policyName)
}
err = policy.Evaluate(signedData)
if err != nil {
return errors.Wrap(errors.WithStack(ErrPermissionDenied), err.Error())
}
return nil
}