1 Star 1 Fork 0

Hyperledger Fabric 国密/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
acl.go 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
Jtyoui 提交于 2021-07-22 15:59 . 国密
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package deliver
import (
"time"
"gitee.com/hyperledger-fabric-gm/fabric/protos/common"
"github.com/pkg/errors"
)
// ExpiresAtFunc is used to extract the time at which an identity expires.
type ExpiresAtFunc func(identityBytes []byte) time.Time
// ConfigSequencer provides the sequence number of the current config block.
type ConfigSequencer interface {
Sequence() uint64
}
// NewSessionAC creates an instance of SessionAccessControl. This constructor will
// return an error if a signature header cannot be extracted from the envelope.
func NewSessionAC(chain ConfigSequencer, env *common.Envelope, policyChecker PolicyChecker, channelID string, expiresAt ExpiresAtFunc) (*SessionAccessControl, error) {
signedData, err := env.AsSignedData()
if err != nil {
return nil, err
}
return &SessionAccessControl{
envelope: env,
channelID: channelID,
sequencer: chain,
policyChecker: policyChecker,
sessionEndTime: expiresAt(signedData[0].Identity),
}, nil
}
// SessionAccessControl holds access control related data for a common Envelope
// that is used to determine if a request is allowed for the identity
// associated with the request envelope.
type SessionAccessControl struct {
sequencer ConfigSequencer
policyChecker PolicyChecker
channelID string
envelope *common.Envelope
lastConfigSequence uint64
sessionEndTime time.Time
usedAtLeastOnce bool
}
// Evaluate uses the PolicyChecker to determine if a request should be allowed.
// The decision is cached until the identity expires or the chain configuration
// changes.
func (ac *SessionAccessControl) Evaluate() error {
if !ac.sessionEndTime.IsZero() && time.Now().After(ac.sessionEndTime) {
return errors.Errorf("client identity expired %v before", time.Since(ac.sessionEndTime))
}
policyCheckNeeded := !ac.usedAtLeastOnce
if currentConfigSequence := ac.sequencer.Sequence(); currentConfigSequence > ac.lastConfigSequence {
ac.lastConfigSequence = currentConfigSequence
policyCheckNeeded = true
}
if !policyCheckNeeded {
return nil
}
ac.usedAtLeastOnce = true
return ac.policyChecker.CheckPolicy(ac.envelope, ac.channelID)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/hyperledger-fabric-gm/fabric.git
git@gitee.com:hyperledger-fabric-gm/fabric.git
hyperledger-fabric-gm
fabric
fabric
v1.4.9

搜索帮助