2020-09-21 09:51:15 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-11-19 14:17:15 +00:00
|
|
|
"crypto/ecdsa"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-10-03 07:39:02 +00:00
|
|
|
"fmt"
|
2020-09-21 09:51:15 +00:00
|
|
|
|
2021-05-31 08:55:40 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-10-21 13:11:18 +00:00
|
|
|
bearer "github.com/nspcc-dev/neofs-api-go/v2/acl"
|
2020-09-21 09:51:15 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
2020-12-14 12:07:20 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2020-10-02 11:39:32 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
2020-10-21 13:11:18 +00:00
|
|
|
v2signature "github.com/nspcc-dev/neofs-api-go/v2/signature"
|
2020-09-28 10:54:24 +00:00
|
|
|
core "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
2020-10-22 12:37:59 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2020-11-19 08:38:50 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2020-12-02 23:45:25 +00:00
|
|
|
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
2020-10-03 07:46:57 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl"
|
2020-10-03 07:50:41 +00:00
|
|
|
eaclV2 "github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl/v2"
|
2021-11-10 07:08:33 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
acl "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/util/signature"
|
2020-09-21 09:51:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2020-10-03 05:09:58 +00:00
|
|
|
// Service checks basic ACL rules.
|
|
|
|
Service struct {
|
2020-10-03 05:19:22 +00:00
|
|
|
*cfg
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
putStreamBasicChecker struct {
|
2020-10-03 05:09:58 +00:00
|
|
|
source *Service
|
2021-03-15 10:53:08 +00:00
|
|
|
next objectSvc.PutObjectStream
|
2020-10-03 07:50:41 +00:00
|
|
|
|
|
|
|
*eACLCfg
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getStreamBasicChecker struct {
|
2020-12-02 23:45:25 +00:00
|
|
|
objectSvc.GetObjectStream
|
|
|
|
|
2020-09-22 16:18:41 +00:00
|
|
|
info requestInfo
|
2020-10-03 07:50:41 +00:00
|
|
|
|
|
|
|
*eACLCfg
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
rangeStreamBasicChecker struct {
|
|
|
|
objectSvc.GetObjectRangeStream
|
|
|
|
|
|
|
|
info requestInfo
|
|
|
|
|
|
|
|
*eACLCfg
|
|
|
|
}
|
|
|
|
|
2020-09-21 09:51:15 +00:00
|
|
|
searchStreamBasicChecker struct {
|
2020-12-10 12:26:40 +00:00
|
|
|
objectSvc.SearchStream
|
|
|
|
|
|
|
|
info requestInfo
|
2020-09-21 09:51:15 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
*eACLCfg
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
requestInfo struct {
|
2020-10-03 05:23:54 +00:00
|
|
|
basicACL basicACLHelper
|
2020-09-21 16:12:52 +00:00
|
|
|
requestRole acl.Role
|
2020-11-18 07:46:26 +00:00
|
|
|
isInnerRing bool
|
2020-09-21 16:12:52 +00:00
|
|
|
operation acl.Operation // put, get, head, etc.
|
2020-11-19 14:22:45 +00:00
|
|
|
cnrOwner *owner.ID // container owner
|
2020-10-03 07:40:50 +00:00
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
cid *cid.ID
|
2020-10-03 07:40:50 +00:00
|
|
|
|
2020-12-14 12:07:20 +00:00
|
|
|
oid *objectSDK.ID
|
|
|
|
|
2020-10-03 07:40:50 +00:00
|
|
|
senderKey []byte
|
2020-10-21 13:11:18 +00:00
|
|
|
|
|
|
|
bearer *bearer.BearerToken // bearer token of request
|
2020-12-28 15:59:42 +00:00
|
|
|
|
|
|
|
srcRequest interface{}
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-10-03 05:19:22 +00:00
|
|
|
// Option represents Service constructor option.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
containers core.Source
|
|
|
|
|
|
|
|
sender SenderClassifier
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
next objectSvc.ServiceServer
|
2020-10-03 07:46:57 +00:00
|
|
|
|
|
|
|
*eACLCfg
|
|
|
|
}
|
|
|
|
|
|
|
|
type eACLCfg struct {
|
|
|
|
eACLOpts []eacl.Option
|
|
|
|
|
|
|
|
eACL *eacl.Validator
|
|
|
|
|
2020-11-19 08:38:50 +00:00
|
|
|
localStorage *engine.StorageEngine
|
2020-10-22 12:37:59 +00:00
|
|
|
|
|
|
|
state netmap.State
|
2020-10-03 05:19:22 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 07:39:02 +00:00
|
|
|
type accessErr struct {
|
|
|
|
requestInfo
|
|
|
|
|
|
|
|
failedCheckTyp string
|
|
|
|
}
|
|
|
|
|
2020-09-21 13:33:49 +00:00
|
|
|
var (
|
2020-10-03 07:39:02 +00:00
|
|
|
ErrMalformedRequest = errors.New("malformed request")
|
|
|
|
ErrUnknownRole = errors.New("can't classify request sender")
|
|
|
|
ErrUnknownContainer = errors.New("can't fetch container info")
|
2020-09-21 13:33:49 +00:00
|
|
|
)
|
|
|
|
|
2020-10-03 05:19:22 +00:00
|
|
|
func defaultCfg() *cfg {
|
2020-10-03 07:46:57 +00:00
|
|
|
return &cfg{
|
|
|
|
eACLCfg: new(eACLCfg),
|
|
|
|
}
|
2020-10-03 05:19:22 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 05:09:58 +00:00
|
|
|
// New is a constructor for object ACL checking service.
|
2020-10-03 05:19:22 +00:00
|
|
|
func New(opts ...Option) Service {
|
|
|
|
cfg := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](cfg)
|
|
|
|
}
|
2020-09-21 16:12:52 +00:00
|
|
|
|
2020-10-03 07:46:57 +00:00
|
|
|
cfg.eACL = eacl.NewValidator(cfg.eACLOpts...)
|
|
|
|
|
2020-10-03 05:09:58 +00:00
|
|
|
return Service{
|
2020-10-03 05:19:22 +00:00
|
|
|
cfg: cfg,
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (b Service) Get(request *object.GetRequest, stream objectSvc.GetObjectStream) error {
|
2020-09-21 16:12:52 +00:00
|
|
|
cid, err := getContainerIDFromRequest(request)
|
|
|
|
if err != nil {
|
2020-12-02 23:45:25 +00:00
|
|
|
return err
|
2020-09-21 13:33:49 +00:00
|
|
|
}
|
|
|
|
|
2021-05-26 16:51:24 +00:00
|
|
|
sTok := originalSessionToken(request.GetMetaHeader())
|
2020-12-14 13:50:45 +00:00
|
|
|
|
2020-10-02 11:39:32 +00:00
|
|
|
req := metaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
2020-12-14 13:50:45 +00:00
|
|
|
token: sTok,
|
2021-05-26 16:49:42 +00:00
|
|
|
bearer: originalBearerToken(request.GetMetaHeader()),
|
2020-12-28 15:59:42 +00:00
|
|
|
src: request,
|
2020-10-02 11:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reqInfo, err := b.findRequestInfo(req, cid, acl.OperationGet)
|
2020-09-21 16:12:52 +00:00
|
|
|
if err != nil {
|
2020-12-02 23:45:25 +00:00
|
|
|
return err
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 12:07:20 +00:00
|
|
|
reqInfo.oid = getObjectIDFromRequestBody(request.GetBody())
|
2020-12-14 13:50:45 +00:00
|
|
|
useObjectIDFromSession(&reqInfo, sTok)
|
2020-12-14 12:07:20 +00:00
|
|
|
|
2020-09-21 16:12:52 +00:00
|
|
|
if !basicACLCheck(reqInfo) {
|
2020-12-02 23:45:25 +00:00
|
|
|
return basicACLErr(reqInfo)
|
2020-10-03 07:50:41 +00:00
|
|
|
} else if !eACLCheck(request, reqInfo, b.eACLCfg) {
|
2020-12-02 23:45:25 +00:00
|
|
|
return eACLErr(reqInfo)
|
2020-09-21 13:33:49 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
return b.next.Get(request, &getStreamBasicChecker{
|
|
|
|
GetObjectStream: stream,
|
|
|
|
info: reqInfo,
|
|
|
|
eACLCfg: b.eACLCfg,
|
|
|
|
})
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 10:53:08 +00:00
|
|
|
func (b Service) Put(ctx context.Context) (objectSvc.PutObjectStream, error) {
|
2020-09-21 09:51:15 +00:00
|
|
|
streamer, err := b.next.Put(ctx)
|
|
|
|
|
|
|
|
return putStreamBasicChecker{
|
2020-10-03 07:50:41 +00:00
|
|
|
source: &b,
|
|
|
|
next: streamer,
|
|
|
|
eACLCfg: b.eACLCfg,
|
2020-09-21 09:51:15 +00:00
|
|
|
}, err
|
|
|
|
}
|
|
|
|
|
2020-10-03 05:09:58 +00:00
|
|
|
func (b Service) Head(
|
2020-09-21 09:51:15 +00:00
|
|
|
ctx context.Context,
|
|
|
|
request *object.HeadRequest) (*object.HeadResponse, error) {
|
2020-09-21 16:12:52 +00:00
|
|
|
cid, err := getContainerIDFromRequest(request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-26 16:51:24 +00:00
|
|
|
sTok := originalSessionToken(request.GetMetaHeader())
|
2020-12-14 13:50:45 +00:00
|
|
|
|
2020-10-02 11:39:32 +00:00
|
|
|
req := metaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
2020-12-14 13:50:45 +00:00
|
|
|
token: sTok,
|
2021-05-26 16:49:42 +00:00
|
|
|
bearer: originalBearerToken(request.GetMetaHeader()),
|
2020-12-28 15:59:42 +00:00
|
|
|
src: request,
|
2020-10-02 11:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reqInfo, err := b.findRequestInfo(req, cid, acl.OperationHead)
|
2020-09-21 16:12:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:07:20 +00:00
|
|
|
reqInfo.oid = getObjectIDFromRequestBody(request.GetBody())
|
2020-12-14 13:50:45 +00:00
|
|
|
useObjectIDFromSession(&reqInfo, sTok)
|
2020-12-14 12:07:20 +00:00
|
|
|
|
2020-09-21 16:12:52 +00:00
|
|
|
if !basicACLCheck(reqInfo) {
|
2020-10-03 07:39:02 +00:00
|
|
|
return nil, basicACLErr(reqInfo)
|
2020-10-03 07:50:41 +00:00
|
|
|
} else if !eACLCheck(request, reqInfo, b.eACLCfg) {
|
|
|
|
return nil, eACLErr(reqInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := b.next.Head(ctx, request)
|
|
|
|
if err == nil {
|
|
|
|
if !eACLCheck(resp, reqInfo, b.eACLCfg) {
|
|
|
|
err = eACLErr(reqInfo)
|
|
|
|
}
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 07:50:41 +00:00
|
|
|
return resp, err
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func (b Service) Search(request *object.SearchRequest, stream objectSvc.SearchStream) error {
|
2021-05-31 11:03:17 +00:00
|
|
|
var id *cid.ID
|
2020-09-21 16:12:52 +00:00
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
id, err := getContainerIDFromRequest(request)
|
2020-09-21 16:12:52 +00:00
|
|
|
if err != nil {
|
2020-12-10 12:26:40 +00:00
|
|
|
return err
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 11:39:32 +00:00
|
|
|
req := metaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
2021-05-26 16:51:24 +00:00
|
|
|
token: originalSessionToken(request.GetMetaHeader()),
|
2021-05-26 16:49:42 +00:00
|
|
|
bearer: originalBearerToken(request.GetMetaHeader()),
|
2020-12-28 15:59:42 +00:00
|
|
|
src: request,
|
2020-10-02 11:39:32 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
reqInfo, err := b.findRequestInfo(req, id, acl.OperationSearch)
|
2020-09-21 16:12:52 +00:00
|
|
|
if err != nil {
|
2020-12-10 12:26:40 +00:00
|
|
|
return err
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 12:07:20 +00:00
|
|
|
reqInfo.oid = getObjectIDFromRequestBody(request.GetBody())
|
|
|
|
|
2020-09-21 16:12:52 +00:00
|
|
|
if !basicACLCheck(reqInfo) {
|
2020-12-10 12:26:40 +00:00
|
|
|
return basicACLErr(reqInfo)
|
2020-10-03 07:50:41 +00:00
|
|
|
} else if !eACLCheck(request, reqInfo, b.eACLCfg) {
|
2020-12-10 12:26:40 +00:00
|
|
|
return eACLErr(reqInfo)
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
return b.next.Search(request, &searchStreamBasicChecker{
|
|
|
|
SearchStream: stream,
|
|
|
|
info: reqInfo,
|
|
|
|
eACLCfg: b.eACLCfg,
|
|
|
|
})
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 05:09:58 +00:00
|
|
|
func (b Service) Delete(
|
2020-09-21 09:51:15 +00:00
|
|
|
ctx context.Context,
|
|
|
|
request *object.DeleteRequest) (*object.DeleteResponse, error) {
|
2020-09-21 16:12:52 +00:00
|
|
|
cid, err := getContainerIDFromRequest(request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-26 16:51:24 +00:00
|
|
|
sTok := originalSessionToken(request.GetMetaHeader())
|
2020-12-14 13:50:45 +00:00
|
|
|
|
2020-10-02 11:39:32 +00:00
|
|
|
req := metaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
2020-12-14 13:50:45 +00:00
|
|
|
token: sTok,
|
2021-05-26 16:49:42 +00:00
|
|
|
bearer: originalBearerToken(request.GetMetaHeader()),
|
2020-12-28 15:59:42 +00:00
|
|
|
src: request,
|
2020-10-02 11:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reqInfo, err := b.findRequestInfo(req, cid, acl.OperationDelete)
|
2020-09-21 16:12:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:07:20 +00:00
|
|
|
reqInfo.oid = getObjectIDFromRequestBody(request.GetBody())
|
2020-12-14 13:50:45 +00:00
|
|
|
useObjectIDFromSession(&reqInfo, sTok)
|
2020-12-14 12:07:20 +00:00
|
|
|
|
2020-09-21 16:12:52 +00:00
|
|
|
if !basicACLCheck(reqInfo) {
|
2020-10-03 07:39:02 +00:00
|
|
|
return nil, basicACLErr(reqInfo)
|
2020-10-03 07:50:41 +00:00
|
|
|
} else if !eACLCheck(request, reqInfo, b.eACLCfg) {
|
|
|
|
return nil, eACLErr(reqInfo)
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 09:51:15 +00:00
|
|
|
return b.next.Delete(ctx, request)
|
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
func (b Service) GetRange(request *object.GetRangeRequest, stream objectSvc.GetObjectRangeStream) error {
|
2020-09-21 16:12:52 +00:00
|
|
|
cid, err := getContainerIDFromRequest(request)
|
|
|
|
if err != nil {
|
2020-12-07 17:49:47 +00:00
|
|
|
return err
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-26 16:51:24 +00:00
|
|
|
sTok := originalSessionToken(request.GetMetaHeader())
|
2020-12-14 13:50:45 +00:00
|
|
|
|
2020-10-02 11:39:32 +00:00
|
|
|
req := metaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
2020-12-14 13:50:45 +00:00
|
|
|
token: sTok,
|
2021-05-26 16:49:42 +00:00
|
|
|
bearer: originalBearerToken(request.GetMetaHeader()),
|
2020-12-28 15:59:42 +00:00
|
|
|
src: request,
|
2020-10-02 11:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reqInfo, err := b.findRequestInfo(req, cid, acl.OperationRange)
|
2020-09-21 16:12:52 +00:00
|
|
|
if err != nil {
|
2020-12-07 17:49:47 +00:00
|
|
|
return err
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 12:07:20 +00:00
|
|
|
reqInfo.oid = getObjectIDFromRequestBody(request.GetBody())
|
2020-12-14 13:50:45 +00:00
|
|
|
useObjectIDFromSession(&reqInfo, sTok)
|
2020-12-14 12:07:20 +00:00
|
|
|
|
2020-09-21 16:12:52 +00:00
|
|
|
if !basicACLCheck(reqInfo) {
|
2020-12-07 17:49:47 +00:00
|
|
|
return basicACLErr(reqInfo)
|
2020-10-03 07:50:41 +00:00
|
|
|
} else if !eACLCheck(request, reqInfo, b.eACLCfg) {
|
2020-12-07 17:49:47 +00:00
|
|
|
return eACLErr(reqInfo)
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
return b.next.GetRange(request, &rangeStreamBasicChecker{
|
|
|
|
GetObjectRangeStream: stream,
|
|
|
|
info: reqInfo,
|
|
|
|
eACLCfg: b.eACLCfg,
|
|
|
|
})
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 05:09:58 +00:00
|
|
|
func (b Service) GetRangeHash(
|
2020-09-21 09:51:15 +00:00
|
|
|
ctx context.Context,
|
|
|
|
request *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
2020-09-21 16:12:52 +00:00
|
|
|
cid, err := getContainerIDFromRequest(request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-26 16:51:24 +00:00
|
|
|
sTok := originalSessionToken(request.GetMetaHeader())
|
2020-12-14 13:50:45 +00:00
|
|
|
|
2020-10-02 11:39:32 +00:00
|
|
|
req := metaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
2020-12-14 13:50:45 +00:00
|
|
|
token: sTok,
|
2021-05-26 16:49:42 +00:00
|
|
|
bearer: originalBearerToken(request.GetMetaHeader()),
|
2020-12-28 15:59:42 +00:00
|
|
|
src: request,
|
2020-10-02 11:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reqInfo, err := b.findRequestInfo(req, cid, acl.OperationRangeHash)
|
2020-09-21 16:12:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:07:20 +00:00
|
|
|
reqInfo.oid = getObjectIDFromRequestBody(request.GetBody())
|
2020-12-14 13:50:45 +00:00
|
|
|
useObjectIDFromSession(&reqInfo, sTok)
|
2020-12-14 12:07:20 +00:00
|
|
|
|
2020-09-21 16:12:52 +00:00
|
|
|
if !basicACLCheck(reqInfo) {
|
2020-10-03 07:39:02 +00:00
|
|
|
return nil, basicACLErr(reqInfo)
|
2020-10-03 07:50:41 +00:00
|
|
|
} else if !eACLCheck(request, reqInfo, b.eACLCfg) {
|
|
|
|
return nil, eACLErr(reqInfo)
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 09:51:15 +00:00
|
|
|
return b.next.GetRangeHash(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p putStreamBasicChecker) Send(request *object.PutRequest) error {
|
2020-09-21 16:12:52 +00:00
|
|
|
body := request.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
return ErrMalformedRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
part := body.GetObjectPart()
|
2020-10-02 11:39:32 +00:00
|
|
|
if part, ok := part.(*object.PutObjectPartInit); ok {
|
2020-09-21 16:12:52 +00:00
|
|
|
cid, err := getContainerIDFromRequest(request)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-02 11:39:32 +00:00
|
|
|
ownerID, err := getObjectOwnerFromMessage(request)
|
2020-09-22 16:18:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-08 12:27:54 +00:00
|
|
|
sTok := request.GetMetaHeader().GetSessionToken()
|
2020-12-14 13:50:45 +00:00
|
|
|
|
2020-10-02 11:39:32 +00:00
|
|
|
req := metaWithToken{
|
|
|
|
vheader: request.GetVerificationHeader(),
|
2020-12-14 13:50:45 +00:00
|
|
|
token: sTok,
|
2021-05-26 16:49:42 +00:00
|
|
|
bearer: originalBearerToken(request.GetMetaHeader()),
|
2020-12-28 15:59:42 +00:00
|
|
|
src: request,
|
2020-10-02 11:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reqInfo, err := p.source.findRequestInfo(req, cid, acl.OperationPut)
|
2020-09-21 16:12:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:07:20 +00:00
|
|
|
reqInfo.oid = getObjectIDFromRequestBody(part)
|
2020-12-14 13:50:45 +00:00
|
|
|
useObjectIDFromSession(&reqInfo, sTok)
|
2020-12-14 12:07:20 +00:00
|
|
|
|
2020-10-02 11:39:32 +00:00
|
|
|
if !basicACLCheck(reqInfo) || !stickyBitCheck(reqInfo, ownerID) {
|
2020-10-03 07:39:02 +00:00
|
|
|
return basicACLErr(reqInfo)
|
2020-10-03 07:50:41 +00:00
|
|
|
} else if !eACLCheck(request, reqInfo, p.eACLCfg) {
|
|
|
|
return eACLErr(reqInfo)
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-21 09:51:15 +00:00
|
|
|
return p.next.Send(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p putStreamBasicChecker) CloseAndRecv() (*object.PutResponse, error) {
|
|
|
|
return p.next.CloseAndRecv()
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (g *getStreamBasicChecker) Send(resp *object.GetResponse) error {
|
|
|
|
if _, ok := resp.GetBody().GetObjectPart().(*object.GetObjectPartInit); ok {
|
|
|
|
if !eACLCheck(resp, g.info, g.eACLCfg) {
|
|
|
|
return eACLErr(g.info)
|
2020-09-22 16:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
return g.GetObjectStream.Send(resp)
|
2020-09-22 16:18:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
func (g *rangeStreamBasicChecker) Send(resp *object.GetRangeResponse) error {
|
|
|
|
if !eACLCheck(resp, g.info, g.eACLCfg) {
|
|
|
|
return eACLErr(g.info)
|
|
|
|
}
|
|
|
|
|
|
|
|
return g.GetObjectRangeStream.Send(resp)
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func (g *searchStreamBasicChecker) Send(resp *object.SearchResponse) error {
|
|
|
|
if !eACLCheck(resp, g.info, g.eACLCfg) {
|
|
|
|
return eACLErr(g.info)
|
|
|
|
}
|
|
|
|
|
|
|
|
return g.SearchStream.Send(resp)
|
|
|
|
}
|
|
|
|
|
2020-10-03 05:09:58 +00:00
|
|
|
func (b Service) findRequestInfo(
|
2020-10-02 11:39:32 +00:00
|
|
|
req metaWithToken,
|
2021-05-31 11:03:17 +00:00
|
|
|
cid *cid.ID,
|
2020-09-21 16:12:52 +00:00
|
|
|
op acl.Operation) (info requestInfo, err error) {
|
2021-01-11 15:12:38 +00:00
|
|
|
cnr, err := b.containers.Get(cid) // fetch actual container
|
2020-11-16 09:43:52 +00:00
|
|
|
if err != nil || cnr.OwnerID() == nil {
|
2020-09-21 16:12:52 +00:00
|
|
|
return info, ErrUnknownContainer
|
|
|
|
}
|
|
|
|
|
2020-10-05 14:13:23 +00:00
|
|
|
// find request role and key
|
2020-11-18 07:53:42 +00:00
|
|
|
role, isIR, key, err := b.sender.Classify(req, cid, cnr)
|
2020-10-21 17:39:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return info, err
|
|
|
|
}
|
|
|
|
|
2020-09-21 16:12:52 +00:00
|
|
|
if role == acl.RoleUnknown {
|
|
|
|
return info, ErrUnknownRole
|
|
|
|
}
|
|
|
|
|
2020-10-02 11:40:09 +00:00
|
|
|
// find verb from token if it is present
|
|
|
|
verb := sourceVerbOfRequest(req, op)
|
|
|
|
// todo: check verb sanity, if it was generated correctly. Do we need it ?
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
info.basicACL = basicACLHelper(cnr.BasicACL())
|
2020-09-21 16:12:52 +00:00
|
|
|
info.requestRole = role
|
2020-11-18 07:53:42 +00:00
|
|
|
info.isInnerRing = isIR
|
2020-10-02 11:40:09 +00:00
|
|
|
info.operation = verb
|
2020-11-19 14:22:45 +00:00
|
|
|
info.cnrOwner = cnr.OwnerID()
|
2020-10-03 07:40:50 +00:00
|
|
|
info.cid = cid
|
|
|
|
|
|
|
|
// it is assumed that at the moment the key will be valid,
|
|
|
|
// otherwise the request would not pass validation
|
2020-10-05 14:13:23 +00:00
|
|
|
info.senderKey = key
|
2020-10-03 07:40:50 +00:00
|
|
|
|
2020-10-21 13:11:18 +00:00
|
|
|
// add bearer token if it is present in request
|
|
|
|
info.bearer = req.bearer
|
|
|
|
|
2020-12-28 15:59:42 +00:00
|
|
|
info.srcRequest = req.src
|
|
|
|
|
2020-09-21 16:12:52 +00:00
|
|
|
return info, nil
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
func getContainerIDFromRequest(req interface{}) (id *cid.ID, err error) {
|
2020-09-21 16:12:52 +00:00
|
|
|
switch v := req.(type) {
|
|
|
|
case *object.GetRequest:
|
2021-05-31 11:03:17 +00:00
|
|
|
return cid.NewFromV2(v.GetBody().GetAddress().GetContainerID()), nil
|
2020-09-21 16:12:52 +00:00
|
|
|
case *object.PutRequest:
|
|
|
|
objPart := v.GetBody().GetObjectPart()
|
|
|
|
if part, ok := objPart.(*object.PutObjectPartInit); ok {
|
2021-05-31 11:03:17 +00:00
|
|
|
return cid.NewFromV2(part.GetHeader().GetContainerID()), nil
|
2020-09-21 16:12:52 +00:00
|
|
|
}
|
2021-01-11 15:21:06 +00:00
|
|
|
|
|
|
|
return nil, errors.New("can't get cid in chunk")
|
2020-09-21 16:12:52 +00:00
|
|
|
case *object.HeadRequest:
|
2021-05-31 11:03:17 +00:00
|
|
|
return cid.NewFromV2(v.GetBody().GetAddress().GetContainerID()), nil
|
2020-09-21 16:12:52 +00:00
|
|
|
case *object.SearchRequest:
|
2021-05-31 11:03:17 +00:00
|
|
|
return cid.NewFromV2(v.GetBody().GetContainerID()), nil
|
2020-09-21 16:12:52 +00:00
|
|
|
case *object.DeleteRequest:
|
2021-05-31 11:03:17 +00:00
|
|
|
return cid.NewFromV2(v.GetBody().GetAddress().GetContainerID()), nil
|
2020-09-21 16:12:52 +00:00
|
|
|
case *object.GetRangeRequest:
|
2021-05-31 11:03:17 +00:00
|
|
|
return cid.NewFromV2(v.GetBody().GetAddress().GetContainerID()), nil
|
2020-09-21 16:12:52 +00:00
|
|
|
case *object.GetRangeHashRequest:
|
2021-05-31 11:03:17 +00:00
|
|
|
return cid.NewFromV2(v.GetBody().GetAddress().GetContainerID()), nil
|
2020-09-21 16:12:52 +00:00
|
|
|
default:
|
|
|
|
return nil, errors.New("unknown request type")
|
|
|
|
}
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 13:50:45 +00:00
|
|
|
func useObjectIDFromSession(req *requestInfo, token *session.SessionToken) {
|
|
|
|
if token == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
objCtx, ok := token.GetBody().GetContext().(*session.ObjectSessionContext)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
req.oid = objectSDK.NewIDFromV2(
|
|
|
|
objCtx.GetAddress().GetObjectID(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:07:20 +00:00
|
|
|
func getObjectIDFromRequestBody(body interface{}) *objectSDK.ID {
|
|
|
|
switch v := body.(type) {
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
case interface {
|
|
|
|
GetObjectID() *refs.ObjectID
|
|
|
|
}:
|
|
|
|
return objectSDK.NewIDFromV2(v.GetObjectID())
|
|
|
|
case interface {
|
|
|
|
GetAddress() *refs.Address
|
|
|
|
}:
|
|
|
|
return objectSDK.NewIDFromV2(v.GetAddress().GetObjectID())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 10:54:24 +00:00
|
|
|
func getObjectOwnerFromMessage(req interface{}) (id *owner.ID, err error) {
|
2020-09-22 16:18:41 +00:00
|
|
|
switch v := req.(type) {
|
|
|
|
case *object.PutRequest:
|
|
|
|
objPart := v.GetBody().GetObjectPart()
|
|
|
|
if part, ok := objPart.(*object.PutObjectPartInit); ok {
|
2020-09-28 10:54:24 +00:00
|
|
|
return owner.NewIDFromV2(part.GetHeader().GetOwnerID()), nil
|
2020-09-22 16:18:41 +00:00
|
|
|
}
|
2021-01-11 15:21:06 +00:00
|
|
|
|
|
|
|
return nil, errors.New("can't get cid in chunk")
|
2020-09-22 16:18:41 +00:00
|
|
|
case *object.GetResponse:
|
|
|
|
objPart := v.GetBody().GetObjectPart()
|
|
|
|
if part, ok := objPart.(*object.GetObjectPartInit); ok {
|
2020-09-28 10:54:24 +00:00
|
|
|
return owner.NewIDFromV2(part.GetHeader().GetOwnerID()), nil
|
2020-09-22 16:18:41 +00:00
|
|
|
}
|
2021-01-11 15:21:06 +00:00
|
|
|
|
|
|
|
return nil, errors.New("can't get cid in chunk")
|
2020-09-22 16:18:41 +00:00
|
|
|
default:
|
|
|
|
return nil, errors.New("unsupported request type")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// main check function for basic ACL
|
2020-09-21 16:12:52 +00:00
|
|
|
func basicACLCheck(info requestInfo) bool {
|
2020-09-22 16:18:41 +00:00
|
|
|
// check basic ACL permissions
|
|
|
|
var checkFn func(acl.Operation) bool
|
|
|
|
|
|
|
|
switch info.requestRole {
|
|
|
|
case acl.RoleUser:
|
2020-10-03 05:23:54 +00:00
|
|
|
checkFn = info.basicACL.UserAllowed
|
2020-09-22 16:18:41 +00:00
|
|
|
case acl.RoleSystem:
|
2020-10-03 05:23:54 +00:00
|
|
|
checkFn = info.basicACL.SystemAllowed
|
2020-11-18 07:46:26 +00:00
|
|
|
if info.isInnerRing {
|
|
|
|
checkFn = info.basicACL.InnerRingAllowed
|
|
|
|
}
|
2020-09-22 16:18:41 +00:00
|
|
|
case acl.RoleOthers:
|
2020-10-03 05:23:54 +00:00
|
|
|
checkFn = info.basicACL.OthersAllowed
|
2020-09-22 16:18:41 +00:00
|
|
|
default:
|
|
|
|
// log there
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkFn(info.operation)
|
|
|
|
}
|
|
|
|
|
2020-09-28 10:54:24 +00:00
|
|
|
func stickyBitCheck(info requestInfo, owner *owner.ID) bool {
|
2021-09-10 11:35:29 +00:00
|
|
|
// According to NeoFS specification sticky bit has no effect on system nodes
|
|
|
|
// for correct intra-container work with objects (in particular, replication).
|
|
|
|
if info.requestRole == acl.RoleSystem {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-10-03 05:23:54 +00:00
|
|
|
if !info.basicACL.Sticky() {
|
2020-09-22 16:18:41 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-11-08 10:49:20 +00:00
|
|
|
if owner == nil || len(info.senderKey) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-05-31 08:55:40 +00:00
|
|
|
requestSenderKey := unmarshalPublicKey(info.senderKey)
|
2020-11-19 14:26:04 +00:00
|
|
|
|
|
|
|
return isOwnerFromKey(owner, requestSenderKey)
|
2020-09-21 09:51:15 +00:00
|
|
|
}
|
2020-10-02 11:40:09 +00:00
|
|
|
|
2020-10-03 07:50:41 +00:00
|
|
|
func eACLCheck(msg interface{}, reqInfo requestInfo, cfg *eACLCfg) bool {
|
|
|
|
if reqInfo.basicACL.Final() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-10-21 16:08:22 +00:00
|
|
|
// if bearer token is not allowed, then ignore it
|
|
|
|
if !reqInfo.basicACL.BearerAllowed(reqInfo.operation) {
|
|
|
|
reqInfo.bearer = nil
|
|
|
|
}
|
|
|
|
|
2020-10-21 13:11:18 +00:00
|
|
|
// if bearer token is not present, isValidBearer returns true
|
2020-10-22 12:37:59 +00:00
|
|
|
if !isValidBearer(reqInfo, cfg.state) {
|
2020-10-21 13:11:18 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-12-15 09:06:04 +00:00
|
|
|
hdrSrcOpts := make([]eaclV2.Option, 0, 3)
|
2020-10-03 07:50:41 +00:00
|
|
|
|
2020-12-15 09:06:04 +00:00
|
|
|
addr := objectSDK.NewAddress()
|
|
|
|
addr.SetContainerID(reqInfo.cid)
|
|
|
|
addr.SetObjectID(reqInfo.oid)
|
|
|
|
|
|
|
|
hdrSrcOpts = append(hdrSrcOpts,
|
|
|
|
eaclV2.WithLocalObjectStorage(cfg.localStorage),
|
|
|
|
eaclV2.WithAddress(addr.ToV2()),
|
|
|
|
)
|
2020-10-03 07:50:41 +00:00
|
|
|
|
|
|
|
if req, ok := msg.(eaclV2.Request); ok {
|
|
|
|
hdrSrcOpts = append(hdrSrcOpts, eaclV2.WithServiceRequest(req))
|
|
|
|
} else {
|
2020-12-28 15:59:42 +00:00
|
|
|
hdrSrcOpts = append(hdrSrcOpts,
|
|
|
|
eaclV2.WithServiceResponse(
|
|
|
|
msg.(eaclV2.Response),
|
|
|
|
reqInfo.srcRequest.(eaclV2.Request),
|
|
|
|
),
|
|
|
|
)
|
2020-10-03 07:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
action := cfg.eACL.CalculateAction(new(eacl.ValidationUnit).
|
|
|
|
WithRole(reqInfo.requestRole).
|
|
|
|
WithOperation(reqInfo.operation).
|
|
|
|
WithContainerID(reqInfo.cid).
|
|
|
|
WithSenderKey(reqInfo.senderKey).
|
|
|
|
WithHeaderSource(
|
|
|
|
eaclV2.NewMessageHeaderSource(hdrSrcOpts...),
|
2020-10-21 13:11:18 +00:00
|
|
|
).
|
|
|
|
WithBearerToken(reqInfo.bearer),
|
2020-10-03 07:50:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return action == acl.ActionAllow
|
|
|
|
}
|
|
|
|
|
2020-10-02 11:40:09 +00:00
|
|
|
// sourceVerbOfRequest looks for verb in session token and if it is not found,
|
|
|
|
// returns reqVerb.
|
|
|
|
func sourceVerbOfRequest(req metaWithToken, reqVerb acl.Operation) acl.Operation {
|
|
|
|
if req.token != nil {
|
|
|
|
switch v := req.token.GetBody().GetContext().(type) {
|
|
|
|
case *session.ObjectSessionContext:
|
|
|
|
return tokenVerbToOperation(v.GetVerb())
|
|
|
|
default:
|
|
|
|
// do nothing, return request verb
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return reqVerb
|
|
|
|
}
|
|
|
|
|
|
|
|
func tokenVerbToOperation(verb session.ObjectSessionVerb) acl.Operation {
|
|
|
|
switch verb {
|
|
|
|
case session.ObjectVerbGet:
|
|
|
|
return acl.OperationGet
|
|
|
|
case session.ObjectVerbPut:
|
|
|
|
return acl.OperationPut
|
|
|
|
case session.ObjectVerbHead:
|
|
|
|
return acl.OperationHead
|
|
|
|
case session.ObjectVerbSearch:
|
|
|
|
return acl.OperationSearch
|
|
|
|
case session.ObjectVerbDelete:
|
|
|
|
return acl.OperationDelete
|
|
|
|
case session.ObjectVerbRange:
|
|
|
|
return acl.OperationRange
|
|
|
|
case session.ObjectVerbRangeHash:
|
|
|
|
return acl.OperationRangeHash
|
|
|
|
default:
|
|
|
|
return acl.OperationUnknown
|
|
|
|
}
|
|
|
|
}
|
2020-10-03 07:39:02 +00:00
|
|
|
|
|
|
|
func (a *accessErr) Error() string {
|
|
|
|
return fmt.Sprintf("access to operation %v is denied by %s check", a.operation, a.failedCheckTyp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func basicACLErr(info requestInfo) error {
|
|
|
|
return &accessErr{
|
|
|
|
requestInfo: info,
|
|
|
|
failedCheckTyp: "basic ACL",
|
|
|
|
}
|
|
|
|
}
|
2020-10-03 07:50:41 +00:00
|
|
|
|
|
|
|
func eACLErr(info requestInfo) error {
|
|
|
|
return &accessErr{
|
|
|
|
requestInfo: info,
|
|
|
|
failedCheckTyp: "extended ACL",
|
|
|
|
}
|
|
|
|
}
|
2020-10-21 13:11:18 +00:00
|
|
|
|
|
|
|
// isValidBearer returns true if bearer token correctly signed by authorized
|
|
|
|
// entity. This method might be define on whole ACL service because it will
|
|
|
|
// require to fetch current epoch to check lifetime.
|
2020-10-22 12:37:59 +00:00
|
|
|
func isValidBearer(reqInfo requestInfo, st netmap.State) bool {
|
2020-10-21 13:11:18 +00:00
|
|
|
token := reqInfo.bearer
|
|
|
|
|
|
|
|
// 0. Check if bearer token is present in reqInfo. It might be non nil
|
|
|
|
// empty structure.
|
|
|
|
if token == nil || (token.GetBody() == nil && token.GetSignature() == nil) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-10-22 12:45:28 +00:00
|
|
|
// 1. First check token lifetime. Simplest verification.
|
|
|
|
if !isValidLifetime(token.GetBody().GetLifetime(), st.CurrentEpoch()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Then check if bearer token is signed correctly.
|
2020-10-21 13:11:18 +00:00
|
|
|
signWrapper := v2signature.StableMarshalerWrapper{SM: token.GetBody()}
|
|
|
|
if err := signature.VerifyDataWithSource(signWrapper, func() (key, sig []byte) {
|
|
|
|
tokenSignature := token.GetSignature()
|
|
|
|
return tokenSignature.GetKey(), tokenSignature.GetSign()
|
|
|
|
}); err != nil {
|
|
|
|
return false // invalid signature
|
|
|
|
}
|
|
|
|
|
2020-10-22 12:45:28 +00:00
|
|
|
// 3. Then check if container owner signed this token.
|
2021-05-31 08:55:40 +00:00
|
|
|
tokenIssuerKey := unmarshalPublicKey(token.GetSignature().GetKey())
|
2020-11-19 14:22:45 +00:00
|
|
|
if !isOwnerFromKey(reqInfo.cnrOwner, tokenIssuerKey) {
|
2020-10-21 13:11:18 +00:00
|
|
|
// todo: in this case we can issue all owner keys from neofs.id and check once again
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-10-22 12:45:28 +00:00
|
|
|
// 4. Then check if request sender has rights to use this token.
|
2020-11-19 14:17:15 +00:00
|
|
|
tokenOwnerField := owner.NewIDFromV2(token.GetBody().GetOwnerID())
|
2020-10-21 13:11:18 +00:00
|
|
|
if tokenOwnerField != nil { // see bearer token owner field description
|
2021-05-31 08:55:40 +00:00
|
|
|
requestSenderKey := unmarshalPublicKey(reqInfo.senderKey)
|
2020-11-19 14:17:15 +00:00
|
|
|
if !isOwnerFromKey(tokenOwnerField, requestSenderKey) {
|
|
|
|
// todo: in this case we can issue all owner keys from neofs.id and check once again
|
2020-10-21 13:11:18 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2020-10-22 12:37:59 +00:00
|
|
|
|
|
|
|
func isValidLifetime(lifetime *bearer.TokenLifetime, epoch uint64) bool {
|
|
|
|
// The "exp" (expiration time) claim identifies the expiration time on
|
|
|
|
// or after which the JWT MUST NOT be accepted for processing.
|
|
|
|
// The "nbf" (not before) claim identifies the time before which the JWT
|
|
|
|
// MUST NOT be accepted for processing
|
|
|
|
// RFC 7519 sections 4.1.4, 4.1.5
|
|
|
|
return epoch >= lifetime.GetNbf() && epoch <= lifetime.GetExp()
|
|
|
|
}
|
2020-11-19 14:17:15 +00:00
|
|
|
|
2021-05-31 08:55:40 +00:00
|
|
|
func isOwnerFromKey(id *owner.ID, key *keys.PublicKey) bool {
|
2020-11-19 14:17:15 +00:00
|
|
|
if id == nil || key == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-05-31 08:55:40 +00:00
|
|
|
wallet, err := owner.NEO3WalletFromPublicKey((*ecdsa.PublicKey)(key))
|
2020-11-19 14:17:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-05-31 10:30:59 +00:00
|
|
|
return id.Equal(owner.NewIDFromNeo3Wallet(wallet))
|
2020-11-19 14:17:15 +00:00
|
|
|
}
|
2021-05-26 16:49:42 +00:00
|
|
|
|
|
|
|
// originalBearerToken goes down to original request meta header and fetches
|
|
|
|
// bearer token from there.
|
|
|
|
func originalBearerToken(header *session.RequestMetaHeader) *bearer.BearerToken {
|
|
|
|
for header.GetOrigin() != nil {
|
|
|
|
header = header.GetOrigin()
|
|
|
|
}
|
|
|
|
|
|
|
|
return header.GetBearerToken()
|
|
|
|
}
|
2021-05-26 16:51:24 +00:00
|
|
|
|
|
|
|
// originalSessionToken goes down to original request meta header and fetches
|
|
|
|
// session token from there.
|
|
|
|
func originalSessionToken(header *session.RequestMetaHeader) *session.SessionToken {
|
|
|
|
for header.GetOrigin() != nil {
|
|
|
|
header = header.GetOrigin()
|
|
|
|
}
|
|
|
|
|
|
|
|
return header.GetSessionToken()
|
|
|
|
}
|