代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package filter
import (
"context"
"time"
"github.com/hyperledger/fabric/common/crypto"
"github.com/hyperledger/fabric/core/handlers/auth"
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
"github.com/pkg/errors"
)
// NewExpirationCheckFilter creates a new Filter that checks identity expiration
func NewExpirationCheckFilter() auth.Filter {
return &expirationCheckFilter{}
}
type expirationCheckFilter struct {
next peer.EndorserServer
}
// Init initializes the Filter with the next EndorserServer
func (f *expirationCheckFilter) Init(next peer.EndorserServer) {
f.next = next
}
func validateProposal(signedProp *peer.SignedProposal) error {
prop, err := utils.GetProposal(signedProp.ProposalBytes)
if err != nil {
return errors.Wrap(err, "failed parsing proposal")
}
hdr, err := utils.GetHeader(prop.Header)
if err != nil {
return errors.Wrap(err, "failed parsing header")
}
sh, err := utils.GetSignatureHeader(hdr.SignatureHeader)
if err != nil {
return errors.Wrap(err, "failed parsing signature header")
}
expirationTime := crypto.ExpiresAt(sh.Creator)
if !expirationTime.IsZero() && time.Now().After(expirationTime) {
return errors.New("identity expired")
}
return nil
}
// ProcessProposal processes a signed proposal
func (f *expirationCheckFilter) ProcessProposal(ctx context.Context, signedProp *peer.SignedProposal) (*peer.ProposalResponse, error) {
if err := validateProposal(signedProp); err != nil {
return nil, err
}
return f.next.ProcessProposal(ctx, signedProp)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。