From 2b07916f22f7e27a67098c7ed0b8b0acdd4e37ae Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Wed, 20 Nov 2024 13:55:31 +0100 Subject: [PATCH] [full-ci] bump reva to v2.26.7 --- changelog/unreleased/bump-reva.md | 18 +++ go.mod | 3 +- go.sum | 6 +- .../grpc/services/gateway/appprovider.go | 6 +- .../grpc/services/gateway/storageprovider.go | 17 +- .../services/gateway/storageprovidercache.go | 22 ++- .../services/gateway/usershareprovider.go | 19 ++- .../http/services/appprovider/appprovider.go | 88 ++--------- .../http/services/datagateway/datagateway.go | 4 +- .../reva/v2/pkg/app/provider/wopi/wopi.go | 8 +- .../reva/v2/pkg/siteacc/manager/token.go | 10 +- .../reva/v2/pkg/storage/fs/posix/posix.go | 2 +- .../pkg/storage/fs/posix/trashbin/trashbin.go | 22 ++- .../pkg/storage/fs/posix/tree/assimilation.go | 79 ++++++++-- .../posix/tree/gpfsfilauditloggingwatcher.go | 40 +++-- .../fs/posix/tree/gpfswatchfolderwatcher.go | 23 ++- .../storage/fs/posix/tree/inotifywatcher.go | 28 +++- .../reva/v2/pkg/storage/fs/posix/tree/tree.go | 28 +++- .../utils/decomposedfs/lookup/lookup.go | 7 +- .../utils/decomposedfs/upload/store.go | 7 +- .../utils/decomposedfs/upload/upload.go | 12 +- .../reva/v2/pkg/token/manager/jwt/jwt.go | 33 ++-- vendor/github.com/golang-jwt/jwt/.gitignore | 4 - vendor/github.com/golang-jwt/jwt/LICENSE | 9 -- .../golang-jwt/jwt/MIGRATION_GUIDE.md | 22 --- vendor/github.com/golang-jwt/jwt/README.md | 113 ------------- .../golang-jwt/jwt/VERSION_HISTORY.md | 131 ---------------- vendor/github.com/golang-jwt/jwt/claims.go | 146 ----------------- vendor/github.com/golang-jwt/jwt/doc.go | 4 - vendor/github.com/golang-jwt/jwt/ecdsa.go | 142 ----------------- .../github.com/golang-jwt/jwt/ecdsa_utils.go | 69 -------- vendor/github.com/golang-jwt/jwt/ed25519.go | 81 ---------- .../golang-jwt/jwt/ed25519_utils.go | 64 -------- vendor/github.com/golang-jwt/jwt/errors.go | 59 ------- vendor/github.com/golang-jwt/jwt/hmac.go | 95 ----------- .../github.com/golang-jwt/jwt/map_claims.go | 120 -------------- vendor/github.com/golang-jwt/jwt/none.go | 52 ------ vendor/github.com/golang-jwt/jwt/parser.go | 148 ------------------ vendor/github.com/golang-jwt/jwt/rsa.go | 101 ------------ vendor/github.com/golang-jwt/jwt/rsa_pss.go | 142 ----------------- vendor/github.com/golang-jwt/jwt/rsa_utils.go | 101 ------------ .../golang-jwt/jwt/signing_method.go | 35 ----- vendor/github.com/golang-jwt/jwt/token.go | 104 ------------ vendor/modules.txt | 5 +- 44 files changed, 292 insertions(+), 1937 deletions(-) create mode 100644 changelog/unreleased/bump-reva.md delete mode 100644 vendor/github.com/golang-jwt/jwt/.gitignore delete mode 100644 vendor/github.com/golang-jwt/jwt/LICENSE delete mode 100644 vendor/github.com/golang-jwt/jwt/MIGRATION_GUIDE.md delete mode 100644 vendor/github.com/golang-jwt/jwt/README.md delete mode 100644 vendor/github.com/golang-jwt/jwt/VERSION_HISTORY.md delete mode 100644 vendor/github.com/golang-jwt/jwt/claims.go delete mode 100644 vendor/github.com/golang-jwt/jwt/doc.go delete mode 100644 vendor/github.com/golang-jwt/jwt/ecdsa.go delete mode 100644 vendor/github.com/golang-jwt/jwt/ecdsa_utils.go delete mode 100644 vendor/github.com/golang-jwt/jwt/ed25519.go delete mode 100644 vendor/github.com/golang-jwt/jwt/ed25519_utils.go delete mode 100644 vendor/github.com/golang-jwt/jwt/errors.go delete mode 100644 vendor/github.com/golang-jwt/jwt/hmac.go delete mode 100644 vendor/github.com/golang-jwt/jwt/map_claims.go delete mode 100644 vendor/github.com/golang-jwt/jwt/none.go delete mode 100644 vendor/github.com/golang-jwt/jwt/parser.go delete mode 100644 vendor/github.com/golang-jwt/jwt/rsa.go delete mode 100644 vendor/github.com/golang-jwt/jwt/rsa_pss.go delete mode 100644 vendor/github.com/golang-jwt/jwt/rsa_utils.go delete mode 100644 vendor/github.com/golang-jwt/jwt/signing_method.go delete mode 100644 vendor/github.com/golang-jwt/jwt/token.go diff --git a/changelog/unreleased/bump-reva.md b/changelog/unreleased/bump-reva.md new file mode 100644 index 00000000000..563c6e5c86c --- /dev/null +++ b/changelog/unreleased/bump-reva.md @@ -0,0 +1,18 @@ +Bugfix: Bump Reva to v2.26.7 + + * Fix [cs3org/reva#4964](https://github.com/cs3org/reva/issues/4964): Fix a wrong error code when approvider creates a new file + +Bump Reva to v2.26.6 + + * Fix [cs3org/reva#4955](https://github.com/cs3org/reva/issues/4955): Allow small clock skew in reva token validation + * Fix [cs3org/reva#4929](https://github.com/cs3org/reva/issues/4929): Fix flaky posixfs integration tests + * Fix [cs3org/reva#4953](https://github.com/cs3org/reva/issues/4953): Avoid gateway panics + * Fix [cs3org/reva#4959](https://github.com/cs3org/reva/issues/4959): Fix missing file touched event + * Fix [cs3org/reva#4933](https://github.com/cs3org/reva/issues/4933): Fix federated sharing when using an external identity provider + * Fix [cs3org/reva#4935](https://github.com/cs3org/reva/issues/4935): Enable datatx log + * Fix [cs3org/reva#4936](https://github.com/cs3org/reva/issues/4936): Do not delete mlock files + * Fix [cs3org/reva#4954](https://github.com/cs3org/reva/issues/4954): Prevent a panic when logging an error + * Fix [cs3org/reva#4956](https://github.com/cs3org/reva/issues/4956): Improve posixfs error handling and logging + * Fix [cs3org/reva#4951](https://github.com/cs3org/reva/issues/4951): Pass the initialized logger down the stack + +https://github.com/owncloud/ocis/pull/10612 diff --git a/go.mod b/go.mod index 7225c96361c..278a6d75add 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/cenkalti/backoff v2.2.1+incompatible github.com/coreos/go-oidc/v3 v3.11.0 github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1 - github.com/cs3org/reva/v2 v2.26.6-0.20241119075849-6f05da66906b + github.com/cs3org/reva/v2 v2.26.7 github.com/davidbyttow/govips/v2 v2.15.0 github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8 github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e @@ -218,7 +218,6 @@ require ( github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gofrs/flock v0.12.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/snappy v0.0.4 // indirect diff --git a/go.sum b/go.sum index d7174460bc1..23ce286f754 100644 --- a/go.sum +++ b/go.sum @@ -255,8 +255,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c= github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME= github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1 h1:RU6LT6mkD16xZs011+8foU7T3LrPvTTSWeTQ9OgfhkA= github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1/go.mod h1:DedpcqXl193qF/08Y04IO0PpxyyMu8+GrkD6kWK2MEQ= -github.com/cs3org/reva/v2 v2.26.6-0.20241119075849-6f05da66906b h1:RrfFOwT3gZCqlzulV1tq/xfdVG/wvtfe0ChbPJoviv8= -github.com/cs3org/reva/v2 v2.26.6-0.20241119075849-6f05da66906b/go.mod h1:KP0Zomt3dNIr/kU2M1mXzTIVFOtxBVS4qmBDMRCfrOQ= +github.com/cs3org/reva/v2 v2.26.7 h1:E5b1+H5ZsnmDgWWS/u3t4PtdmiMaY1bEEYVI/vE9xo8= +github.com/cs3org/reva/v2 v2.26.7/go.mod h1:xC5N2XOrCRim/W55uyMsew8RwwFZbQ4hIaKshIbyToo= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= @@ -471,8 +471,6 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= -github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= diff --git a/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/appprovider.go b/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/appprovider.go index af56ae88ea3..fa77ef157a7 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/appprovider.go +++ b/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/appprovider.go @@ -197,7 +197,11 @@ func buildOpenInAppRequest(ctx context.Context, ri *storageprovider.ResourceInfo } // build a fake user object for the token - currentuser := ctxpkg.ContextMustGetUser(ctx) + currentuser, ok := ctxpkg.ContextGetUser(ctx) + if !ok { + return nil, errors.New("user not found in context") + } + scopedUser := &userpb.User{ Id: ri.GetOwner(), // the owner of the resource is always set, right? DisplayName: "View Only user for " + currentuser.GetUsername(), diff --git a/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/storageprovider.go b/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/storageprovider.go index 978a687831b..63dddc8fa18 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/storageprovider.go +++ b/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/storageprovider.go @@ -48,7 +48,7 @@ import ( "github.com/cs3org/reva/v2/pkg/share" "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/cs3org/reva/v2/pkg/utils" - "github.com/golang-jwt/jwt" + "github.com/golang-jwt/jwt/v5" "github.com/pkg/errors" gstatus "google.golang.org/grpc/status" ) @@ -78,7 +78,7 @@ import ( // transferClaims are custom claims for a JWT token to be used between the metadata and data gateways. type transferClaims struct { - jwt.StandardClaims + jwt.RegisteredClaims Target string `json:"target"` } @@ -86,10 +86,10 @@ func (s *svc) sign(_ context.Context, target string, expiresAt int64) (string, e // Tus sends a separate request to the datagateway service for every chunk. // For large files, this can take a long time, so we extend the expiration claims := transferClaims{ - StandardClaims: jwt.StandardClaims{ - ExpiresAt: expiresAt, - Audience: "reva", - IssuedAt: time.Now().Unix(), + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(time.Unix(expiresAt, 0)), + Audience: jwt.ClaimStrings{"reva"}, + IssuedAt: jwt.NewNumericDate(time.Now()), }, Target: target, } @@ -428,7 +428,10 @@ func (s *svc) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorag } func (s *svc) GetHome(ctx context.Context, _ *provider.GetHomeRequest) (*provider.GetHomeResponse, error) { - currentUser := ctxpkg.ContextMustGetUser(ctx) + currentUser, ok := ctxpkg.ContextGetUser(ctx) + if !ok { + return nil, errors.New("user not found in context") + } srClient, err := s.getStorageRegistryClient(ctx, s.c.StorageRegistryEndpoint) if err != nil { diff --git a/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/storageprovidercache.go b/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/storageprovidercache.go index 122620bcb32..b9ce9c1b7ef 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/storageprovidercache.go +++ b/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/storageprovidercache.go @@ -28,6 +28,7 @@ import ( sdk "github.com/cs3org/reva/v2/pkg/sdk/common" "github.com/cs3org/reva/v2/pkg/storage/cache" "github.com/cs3org/reva/v2/pkg/utils" + "github.com/pkg/errors" "google.golang.org/grpc" ) @@ -44,7 +45,12 @@ func (c *cachedRegistryClient) ListStorageProviders(ctx context.Context, in *reg spaceID := sdk.DecodeOpaqueMap(in.Opaque)["space_id"] - key := c.cache.GetKey(ctxpkg.ContextMustGetUser(ctx).GetId(), spaceID) + u, ok := ctxpkg.ContextGetUser(ctx) + if !ok { + return nil, errors.New("user not found in context") + } + + key := c.cache.GetKey(u.GetId(), spaceID) if key != "" { s := ®istry.ListStorageProvidersResponse{} if err := c.cache.PullFromCache(key, s); err == nil { @@ -89,7 +95,12 @@ type cachedSpacesAPIClient struct { // CreateStorageSpace creates a storage space func (c *cachedSpacesAPIClient) CreateStorageSpace(ctx context.Context, in *provider.CreateStorageSpaceRequest, opts ...grpc.CallOption) (*provider.CreateStorageSpaceResponse, error) { if in.Type == "personal" { - key := c.createPersonalSpaceCache.GetKey(ctxpkg.ContextMustGetUser(ctx).GetId()) + u, ok := ctxpkg.ContextGetUser(ctx) + if !ok { + return nil, errors.New("user not found in context") + } + + key := c.createPersonalSpaceCache.GetKey(u.GetId()) if key != "" { s := &provider.CreateStorageSpaceResponse{} if err := c.createPersonalSpaceCache.PullFromCache(key, s); err == nil { @@ -132,7 +143,12 @@ type cachedAPIClient struct { // CreateHome caches calls to CreateHome locally - anyways they only need to be called once per user func (c *cachedAPIClient) CreateHome(ctx context.Context, in *provider.CreateHomeRequest, opts ...grpc.CallOption) (*provider.CreateHomeResponse, error) { - key := c.createPersonalSpaceCache.GetKey(ctxpkg.ContextMustGetUser(ctx).GetId()) + u, ok := ctxpkg.ContextGetUser(ctx) + if !ok { + return nil, errors.New("user not found in context") + } + + key := c.createPersonalSpaceCache.GetKey(u.GetId()) if key != "" { s := &provider.CreateHomeResponse{} if err := c.createPersonalSpaceCache.PullFromCache(key, s); err == nil { diff --git a/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/usershareprovider.go b/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/usershareprovider.go index 951d95cb1fa..2782a8b3a1c 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/usershareprovider.go +++ b/vendor/github.com/cs3org/reva/v2/internal/grpc/services/gateway/usershareprovider.go @@ -139,7 +139,11 @@ func (s *svc) updateShare(ctx context.Context, req *collaboration.UpdateShareReq } if s.c.CommitShareToStorageGrant { - creator := ctxpkg.ContextMustGetUser(ctx) + creator, ok := ctxpkg.ContextGetUser(ctx) + if !ok { + return nil, errors.New("user not found in context") + } + grant := &provider.Grant{ Grantee: res.GetShare().GetGrantee(), Permissions: res.GetShare().GetPermissions().GetPermissions(), @@ -198,11 +202,16 @@ func (s *svc) updateSpaceShare(ctx context.Context, req *collaboration.UpdateSha req.Share.Expiration = existsGrant.GetExpiration() } + u, ok := ctxpkg.ContextGetUser(ctx) + if !ok { + return nil, errors.New("user not found in context") + } + grant := &provider.Grant{ Grantee: req.GetShare().GetGrantee(), Permissions: req.GetShare().GetPermissions().GetPermissions(), Expiration: req.GetShare().GetExpiration(), - Creator: ctxpkg.ContextMustGetUser(ctx).GetId(), + Creator: u.GetId(), } if grant.GetPermissions() == nil { @@ -410,7 +419,11 @@ func (s *svc) addGrant(ctx context.Context, id *provider.ResourceId, g *provider ResourceId: id, } - creator := ctxpkg.ContextMustGetUser(ctx) + creator, ok := ctxpkg.ContextGetUser(ctx) + if !ok { + return nil, errors.New("user not found in context") + } + grantReq := &provider.AddGrantRequest{ Ref: ref, Grant: &provider.Grant{ diff --git a/vendor/github.com/cs3org/reva/v2/internal/http/services/appprovider/appprovider.go b/vendor/github.com/cs3org/reva/v2/internal/http/services/appprovider/appprovider.go index 14761c25791..c434eb6cdc5 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/http/services/appprovider/appprovider.go +++ b/vendor/github.com/cs3org/reva/v2/internal/http/services/appprovider/appprovider.go @@ -31,13 +31,9 @@ import ( gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" - "github.com/cs3org/reva/v2/internal/http/services/datagateway" - "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/net" ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/rgrpc/status" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" - "github.com/cs3org/reva/v2/pkg/rhttp" "github.com/cs3org/reva/v2/pkg/rhttp/global" "github.com/cs3org/reva/v2/pkg/sharedconf" "github.com/cs3org/reva/v2/pkg/storagespace" @@ -230,92 +226,42 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) { return } - // Create empty file via storageprovider - createReq := &provider.InitiateFileUploadRequest{ + touchFileReq := &provider.TouchFileRequest{ Ref: fileRef, - Opaque: &typespb.Opaque{ - Map: map[string]*typespb.OpaqueEntry{ - "Upload-Length": { - Decoder: "plain", - Value: []byte("0"), - }, - }, - }, } - // having a client.CreateFile() function would come in handy here... - - createRes, err := client.InitiateFileUpload(ctx, createReq) + touchRes, err := client.TouchFile(ctx, touchFileReq) if err != nil { - writeError(w, r, appErrorServerError, "error calling InitiateFileUpload", err) + writeError(w, r, appErrorServerError, "error sending a grpc touchfile request", err) return } - if createRes.Status.Code != rpc.Code_CODE_OK { - switch createRes.Status.Code { - case rpc.Code_CODE_PERMISSION_DENIED: + + if touchRes.Status.Code != rpc.Code_CODE_OK { + if touchRes.Status.Code == rpc.Code_CODE_PERMISSION_DENIED { writeError(w, r, appErrorPermissionDenied, "permission denied to create the file", nil) return - case rpc.Code_CODE_NOT_FOUND: - writeError(w, r, appErrorNotFound, "parent container does not exist", nil) - return - default: - writeError(w, r, appErrorServerError, "error calling InitiateFileUpload", nil) - return } - } - - // Do a HTTP PUT with an empty body - var ep, token string - for _, p := range createRes.Protocols { - if p.Protocol == "simple" { - ep, token = p.UploadEndpoint, p.Token - } - } - httpReq, err := rhttp.NewRequest(ctx, http.MethodPut, ep, nil) - if err != nil { - writeError(w, r, appErrorServerError, "failed to create the file", err) + writeError(w, r, appErrorServerError, "touching the file failed", nil) return } - httpReq.Header.Set(datagateway.TokenTransportHeader, token) - httpRes, err := rhttp.GetHTTPClient( - rhttp.Context(ctx), - rhttp.Insecure(s.conf.Insecure), - ).Do(httpReq) + // Stat the newly created file + statRes, err := client.Stat(ctx, statFileReq) if err != nil { - writeError(w, r, appErrorServerError, "failed to create the file", err) + writeError(w, r, appErrorServerError, "statting the created file failed", err) return } - defer httpRes.Body.Close() - if httpRes.StatusCode == http.StatusBadRequest { - // the file upload was already finished since it is a zero byte file - } else if httpRes.StatusCode != http.StatusOK { - writeError(w, r, appErrorServerError, "failed to create the file", nil) + + if statRes.Status.Code != rpc.Code_CODE_OK { + writeError(w, r, appErrorServerError, "statting the created file failed", nil) return } - var fileid string - if httpRes.Header.Get(net.HeaderOCFileID) != "" { - fileid = httpRes.Header.Get(net.HeaderOCFileID) - } else { - // Stat the newly created file - statRes, err := client.Stat(ctx, statFileReq) - if err != nil { - writeError(w, r, appErrorServerError, "statting the created file failed", err) - return - } - - if statRes.Status.Code != rpc.Code_CODE_OK { - writeError(w, r, appErrorServerError, "statting the created file failed", nil) - return - } - - if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_FILE { - writeError(w, r, appErrorInvalidParameter, "the given file id does not point to a file", nil) - return - } - fileid = storagespace.FormatResourceID(statRes.Info.Id) + if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_FILE { + writeError(w, r, appErrorInvalidParameter, "the given file id does not point to a file", nil) + return } + fileid := storagespace.FormatResourceID(statRes.Info.Id) js, err := json.Marshal( map[string]interface{}{ diff --git a/vendor/github.com/cs3org/reva/v2/internal/http/services/datagateway/datagateway.go b/vendor/github.com/cs3org/reva/v2/internal/http/services/datagateway/datagateway.go index 53ba79af817..8f8fcf46662 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/http/services/datagateway/datagateway.go +++ b/vendor/github.com/cs3org/reva/v2/internal/http/services/datagateway/datagateway.go @@ -32,7 +32,7 @@ import ( "github.com/cs3org/reva/v2/pkg/rhttp" "github.com/cs3org/reva/v2/pkg/rhttp/global" "github.com/cs3org/reva/v2/pkg/sharedconf" - "github.com/golang-jwt/jwt" + "github.com/golang-jwt/jwt/v5" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" "github.com/rs/zerolog" @@ -58,7 +58,7 @@ func init() { // transferClaims are custom claims for a JWT token to be used between the metadata and data gateways. type transferClaims struct { - jwt.StandardClaims + jwt.RegisteredClaims Target string `json:"target"` } type config struct { diff --git a/vendor/github.com/cs3org/reva/v2/pkg/app/provider/wopi/wopi.go b/vendor/github.com/cs3org/reva/v2/pkg/app/provider/wopi/wopi.go index d0356a35368..45167be1e2c 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/app/provider/wopi/wopi.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/app/provider/wopi/wopi.go @@ -47,7 +47,7 @@ import ( "github.com/cs3org/reva/v2/pkg/sharedconf" "github.com/cs3org/reva/v2/pkg/storage/utils/templates" "github.com/cs3org/reva/v2/pkg/storagespace" - "github.com/golang-jwt/jwt" + "github.com/golang-jwt/jwt/v5" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" ) @@ -379,16 +379,16 @@ func getAppURLs(c *config) (map[string]map[string]string, error) { func (p *wopiProvider) getAccessTokenTTL(ctx context.Context) (string, error) { tkn := ctxpkg.ContextMustGetToken(ctx) - token, err := jwt.ParseWithClaims(tkn, &jwt.StandardClaims{}, func(token *jwt.Token) (interface{}, error) { + token, err := jwt.ParseWithClaims(tkn, &jwt.RegisteredClaims{}, func(token *jwt.Token) (interface{}, error) { return []byte(p.conf.JWTSecret), nil }) if err != nil { return "", err } - if claims, ok := token.Claims.(*jwt.StandardClaims); ok && token.Valid { + if claims, ok := token.Claims.(*jwt.RegisteredClaims); ok && token.Valid { // milliseconds since Jan 1, 1970 UTC as required in https://wopi.readthedocs.io/projects/wopirest/en/latest/concepts.html?highlight=access_token_ttl#term-access-token-ttl - return strconv.FormatInt(claims.ExpiresAt*1000, 10), nil + return strconv.FormatInt(claims.ExpiresAt.Unix()*1000, 10), nil } return "", errtypes.InvalidCredentials("wopi: invalid token present in ctx") diff --git a/vendor/github.com/cs3org/reva/v2/pkg/siteacc/manager/token.go b/vendor/github.com/cs3org/reva/v2/pkg/siteacc/manager/token.go index d1c0309b67b..d83bdccbbe7 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/siteacc/manager/token.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/siteacc/manager/token.go @@ -21,13 +21,13 @@ package manager import ( "time" - "github.com/golang-jwt/jwt" + "github.com/golang-jwt/jwt/v5" "github.com/pkg/errors" "github.com/sethvargo/go-password/password" ) type userToken struct { - jwt.StandardClaims + jwt.RegisteredClaims User string `json:"user"` Scope string `json:"scope"` @@ -45,10 +45,10 @@ var ( func generateUserToken(user string, scope string, timeout int) (string, error) { // Create a JWT as the user token claims := userToken{ - StandardClaims: jwt.StandardClaims{ - ExpiresAt: time.Now().Add(time.Duration(timeout) * time.Second).Unix(), + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Duration(timeout) * time.Second)), Issuer: tokenIssuer, - IssuedAt: time.Now().Unix(), + IssuedAt: jwt.NewNumericDate(time.Now()), }, User: user, Scope: scope, diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/posix.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/posix.go index 340f89b1fe8..e6faca47b19 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/posix.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/posix.go @@ -84,7 +84,7 @@ func New(m map[string]interface{}, stream events.Stream, log *zerolog.Logger) (s return nil, fmt.Errorf("unknown metadata backend %s, only 'messagepack' or 'xattrs' (default) supported", o.MetadataBackend) } - trashbin, err := trashbin.New(o, lu) + trashbin, err := trashbin.New(o, lu, log) if err != nil { return nil, err } diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/trashbin/trashbin.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/trashbin/trashbin.go index f0fed08e16c..02c89c6644c 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/trashbin/trashbin.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/trashbin/trashbin.go @@ -26,6 +26,9 @@ import ( "strings" "time" + "github.com/google/uuid" + "github.com/rs/zerolog" + provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/v2/pkg/storage" @@ -34,13 +37,13 @@ import ( "github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/metadata/prefixes" "github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node" "github.com/cs3org/reva/v2/pkg/utils" - "github.com/google/uuid" ) type Trashbin struct { - fs storage.FS - o *options.Options - lu *lookup.Lookup + fs storage.FS + o *options.Options + lu *lookup.Lookup + log *zerolog.Logger } const ( @@ -49,10 +52,11 @@ const ( ) // New returns a new Trashbin -func New(o *options.Options, lu *lookup.Lookup) (*Trashbin, error) { +func New(o *options.Options, lu *lookup.Lookup, log *zerolog.Logger) (*Trashbin, error) { return &Trashbin{ - o: o, - lu: lu, + o: o, + lu: lu, + log: log, }, nil } @@ -261,7 +265,9 @@ func (tb *Trashbin) RestoreRecycleItem(ctx context.Context, ref *provider.Refere if err != nil { return err } - _ = tb.lu.CacheID(ctx, n.SpaceID, string(id), restorePath) + if err := tb.lu.CacheID(ctx, n.SpaceID, string(id), restorePath); err != nil { + tb.log.Error().Err(err).Str("spaceID", n.SpaceID).Str("id", string(id)).Str("path", restorePath).Msg("trashbin: error caching id") + } // cleanup trash info if relativePath == "." || relativePath == "/" { diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/assimilation.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/assimilation.go index 687eb5ca475..bd5e2d3440a 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/assimilation.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/assimilation.go @@ -165,6 +165,7 @@ func (t *Tree) Scan(path string, action EventAction, isDir bool) error { // cases: switch action { case ActionCreate: + t.log.Debug().Str("path", path).Bool("isDir", isDir).Msg("scanning path (ActionCreate)") if !isDir { // 1. New file (could be emitted as part of a new directory) // -> assimilate file @@ -197,6 +198,7 @@ func (t *Tree) Scan(path string, action EventAction, isDir bool) error { } case ActionUpdate: + t.log.Debug().Str("path", path).Bool("isDir", isDir).Msg("scanning path (ActionUpdate)") // 3. Updated file // -> update file unless parent directory is being rescanned if !t.scanDebouncer.InProgress(filepath.Dir(path)) { @@ -207,6 +209,7 @@ func (t *Tree) Scan(path string, action EventAction, isDir bool) error { } case ActionMove: + t.log.Debug().Str("path", path).Bool("isDir", isDir).Msg("scanning path (ActionMove)") // 4. Moved file // -> update file // 5. Moved directory @@ -218,6 +221,7 @@ func (t *Tree) Scan(path string, action EventAction, isDir bool) error { }) case ActionMoveFrom: + t.log.Debug().Str("path", path).Bool("isDir", isDir).Msg("scanning path (ActionMoveFrom)") // 6. file/directory moved out of the watched directory // -> update directory if err := t.setDirty(filepath.Dir(path), true); err != nil { @@ -227,9 +231,16 @@ func (t *Tree) Scan(path string, action EventAction, isDir bool) error { go func() { _ = t.WarmupIDCache(filepath.Dir(path), false, true) }() case ActionDelete: - _ = t.HandleFileDelete(path) + t.log.Debug().Str("path", path).Bool("isDir", isDir).Msg("handling deleted item") + // 7. Deleted file or directory // -> update parent and all children + + err := t.HandleFileDelete(path) + if err != nil { + return err + } + t.scanDebouncer.Debounce(scanItem{ Path: filepath.Dir(path), ForceRescan: true, @@ -242,8 +253,12 @@ func (t *Tree) Scan(path string, action EventAction, isDir bool) error { func (t *Tree) HandleFileDelete(path string) error { // purge metadata - _ = t.lookup.(*lookup.Lookup).IDCache.DeleteByPath(context.Background(), path) - _ = t.lookup.MetadataBackend().Purge(context.Background(), path) + if err := t.lookup.(*lookup.Lookup).IDCache.DeleteByPath(context.Background(), path); err != nil { + t.log.Error().Err(err).Str("path", path).Msg("could not delete id cache entry by path") + } + if err := t.lookup.MetadataBackend().Purge(context.Background(), path); err != nil { + t.log.Error().Err(err).Str("path", path).Msg("could not purge metadata") + } // send event owner, spaceID, nodeID, parentID, err := t.getOwnerAndIDs(filepath.Dir(path)) @@ -369,23 +384,36 @@ func (t *Tree) assimilate(item scanItem) error { if ok && len(previousParentID) > 0 && previousPath != item.Path { _, err := os.Stat(previousPath) if err == nil { - // this id clashes with an existing id -> clear metadata and re-assimilate + // this id clashes with an existing item -> clear metadata and re-assimilate + t.log.Debug().Str("path", item.Path).Msg("ID clash detected, purging metadata and re-assimilating") - _ = t.lookup.MetadataBackend().Purge(context.Background(), item.Path) + if err := t.lookup.MetadataBackend().Purge(context.Background(), item.Path); err != nil { + t.log.Error().Err(err).Str("path", item.Path).Msg("could not purge metadata") + } go func() { - _ = t.assimilate(scanItem{Path: item.Path, ForceRescan: true}) + if err := t.assimilate(scanItem{Path: item.Path, ForceRescan: true}); err != nil { + t.log.Error().Err(err).Str("path", item.Path).Msg("could not re-assimilate") + } }() } else { // this is a move - _ = t.lookup.(*lookup.Lookup).CacheID(context.Background(), spaceID, string(id), item.Path) + t.log.Debug().Str("path", item.Path).Msg("move detected") + + if err := t.lookup.(*lookup.Lookup).CacheID(context.Background(), spaceID, string(id), item.Path); err != nil { + t.log.Error().Err(err).Str("spaceID", spaceID).Str("id", string(id)).Str("path", item.Path).Msg("could not cache id") + } _, err := t.updateFile(item.Path, string(id), spaceID) if err != nil { return err } // purge original metadata. Only delete the path entry using DeletePath(reverse lookup), not the whole entry pair. - _ = t.lookup.(*lookup.Lookup).IDCache.DeletePath(context.Background(), previousPath) - _ = t.lookup.MetadataBackend().Purge(context.Background(), previousPath) + if err := t.lookup.(*lookup.Lookup).IDCache.DeletePath(context.Background(), previousPath); err != nil { + t.log.Error().Err(err).Str("path", previousPath).Msg("could not delete id cache entry by path") + } + if err := t.lookup.MetadataBackend().Purge(context.Background(), previousPath); err != nil { + t.log.Error().Err(err).Str("path", previousPath).Msg("could not purge metadata") + } fi, err := os.Stat(item.Path) if err != nil { @@ -393,7 +421,11 @@ func (t *Tree) assimilate(item scanItem) error { } if fi.IsDir() { // if it was moved and it is a directory we need to propagate the move - go func() { _ = t.WarmupIDCache(item.Path, false, true) }() + go func() { + if err := t.WarmupIDCache(item.Path, false, true); err != nil { + t.log.Error().Err(err).Str("path", item.Path).Msg("could not warmup id cache") + } + }() } parentID, err := t.lookup.MetadataBackend().Get(context.Background(), item.Path, prefixes.ParentidAttr) @@ -426,7 +458,10 @@ func (t *Tree) assimilate(item scanItem) error { } } else { // This item had already been assimilated in the past. Update the path - _ = t.lookup.(*lookup.Lookup).CacheID(context.Background(), spaceID, string(id), item.Path) + t.log.Debug().Str("path", item.Path).Msg("updating cached path") + if err := t.lookup.(*lookup.Lookup).CacheID(context.Background(), spaceID, string(id), item.Path); err != nil { + t.log.Error().Err(err).Str("spaceID", spaceID).Str("id", string(id)).Str("path", item.Path).Msg("could not cache id") + } _, err := t.updateFile(item.Path, string(id), spaceID) if err != nil { @@ -434,6 +469,7 @@ func (t *Tree) assimilate(item scanItem) error { } } } else { + t.log.Debug().Str("path", item.Path).Msg("new item detected") // assimilate new file newId := uuid.New().String() fi, err := t.updateFile(item.Path, newId, spaceID) @@ -550,12 +586,15 @@ assimilate: return nil, errors.Wrap(err, "failed to propagate") } + t.log.Debug().Str("path", path).Interface("attributes", attributes).Msg("setting attributes") err = t.lookup.MetadataBackend().SetMultiple(context.Background(), path, attributes, false) if err != nil { return nil, errors.Wrap(err, "failed to set attributes") } - _ = t.lookup.(*lookup.Lookup).CacheID(context.Background(), spaceID, id, path) + if err := t.lookup.(*lookup.Lookup).CacheID(context.Background(), spaceID, id, path); err != nil { + t.log.Error().Err(err).Str("spaceID", spaceID).Str("id", id).Str("path", path).Msg("could not cache id") + } return fi, nil } @@ -654,10 +693,14 @@ func (t *Tree) WarmupIDCache(root string, assimilate, onlyDirty bool) error { _ = t.assimilate(scanItem{Path: path, ForceRescan: true}) } } - _ = t.lookup.(*lookup.Lookup).CacheID(context.Background(), string(spaceID), string(id), path) + if err := t.lookup.(*lookup.Lookup).CacheID(context.Background(), string(spaceID), string(id), path); err != nil { + t.log.Error().Err(err).Str("spaceID", string(spaceID)).Str("id", string(id)).Str("path", path).Msg("could not cache id") + } } } else if assimilate { - _ = t.assimilate(scanItem{Path: path, ForceRescan: true}) + if err := t.assimilate(scanItem{Path: path, ForceRescan: true}); err != nil { + t.log.Error().Err(err).Str("path", path).Msg("could not assimilate item") + } } return t.setDirty(path, false) }) @@ -665,9 +708,13 @@ func (t *Tree) WarmupIDCache(root string, assimilate, onlyDirty bool) error { for dir, size := range sizes { if dir == root { // Propagate the size diff further up the tree - _ = t.propagateSizeDiff(dir, size) + if err := t.propagateSizeDiff(dir, size); err != nil { + t.log.Error().Err(err).Str("path", dir).Msg("could not propagate size diff") + } + } + if err := t.lookup.MetadataBackend().Set(context.Background(), dir, prefixes.TreesizeAttr, []byte(fmt.Sprintf("%d", size))); err != nil { + t.log.Error().Err(err).Str("path", dir).Int64("size", size).Msg("could not set tree size") } - _ = t.lookup.MetadataBackend().Set(context.Background(), dir, prefixes.TreesizeAttr, []byte(fmt.Sprintf("%d", size))) } if err != nil { diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/gpfsfilauditloggingwatcher.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/gpfsfilauditloggingwatcher.go index ead3cf398f4..681a7910c3f 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/gpfsfilauditloggingwatcher.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/gpfsfilauditloggingwatcher.go @@ -25,10 +25,13 @@ import ( "os" "strconv" "time" + + "github.com/rs/zerolog" ) type GpfsFileAuditLoggingWatcher struct { tree *Tree + log *zerolog.Logger } type lwe struct { @@ -37,9 +40,10 @@ type lwe struct { BytesWritten string } -func NewGpfsFileAuditLoggingWatcher(tree *Tree, auditLogFile string) (*GpfsFileAuditLoggingWatcher, error) { +func NewGpfsFileAuditLoggingWatcher(tree *Tree, auditLogFile string, log *zerolog.Logger) (*GpfsFileAuditLoggingWatcher, error) { w := &GpfsFileAuditLoggingWatcher{ tree: tree, + log: log, } _, err := os.Stat(auditLogFile) @@ -75,25 +79,33 @@ start: case nil: err := json.Unmarshal([]byte(line), ev) if err != nil { + w.log.Error().Err(err).Str("line", line).Msg("error unmarshalling line") continue } if isLockFile(ev.Path) || isTrash(ev.Path) || w.tree.isUpload(ev.Path) { continue } - switch ev.Event { - case "CREATE": - go func() { _ = w.tree.Scan(ev.Path, ActionCreate, false) }() - case "CLOSE": - bytesWritten, err := strconv.Atoi(ev.BytesWritten) - if err == nil && bytesWritten > 0 { - go func() { _ = w.tree.Scan(ev.Path, ActionUpdate, false) }() + go func() { + switch ev.Event { + case "CREATE": + err = w.tree.Scan(ev.Path, ActionCreate, false) + case "CLOSE": + var bytesWritten int + bytesWritten, err = strconv.Atoi(ev.BytesWritten) + if err == nil && bytesWritten > 0 { + err = w.tree.Scan(ev.Path, ActionUpdate, false) + } + case "RENAME": + err = w.tree.Scan(ev.Path, ActionMove, false) + if warmupErr := w.tree.WarmupIDCache(ev.Path, false, false); warmupErr != nil { + w.log.Error().Err(warmupErr).Str("path", ev.Path).Msg("error warming up id cache") + } } - case "RENAME": - go func() { - _ = w.tree.Scan(ev.Path, ActionMove, false) - _ = w.tree.WarmupIDCache(ev.Path, false, false) - }() - } + if err != nil { + w.log.Error().Err(err).Str("line", line).Msg("error unmarshalling line") + } + }() + case io.EOF: time.Sleep(1 * time.Second) default: diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/gpfswatchfolderwatcher.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/gpfswatchfolderwatcher.go index 5a0fb6a4bd1..5d05bcd11ca 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/gpfswatchfolderwatcher.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/gpfswatchfolderwatcher.go @@ -25,18 +25,21 @@ import ( "strconv" "strings" + "github.com/rs/zerolog" kafka "github.com/segmentio/kafka-go" ) type GpfsWatchFolderWatcher struct { tree *Tree brokers []string + log *zerolog.Logger } -func NewGpfsWatchFolderWatcher(tree *Tree, kafkaBrokers []string) (*GpfsWatchFolderWatcher, error) { +func NewGpfsWatchFolderWatcher(tree *Tree, kafkaBrokers []string, log *zerolog.Logger) (*GpfsWatchFolderWatcher, error) { return &GpfsWatchFolderWatcher{ tree: tree, brokers: kafkaBrokers, + log: log, }, nil } @@ -66,23 +69,27 @@ func (w *GpfsWatchFolderWatcher) Watch(topic string) { go func() { isDir := strings.Contains(lwev.Event, "IN_ISDIR") + var err error switch { case strings.Contains(lwev.Event, "IN_DELETE"): - _ = w.tree.Scan(lwev.Path, ActionDelete, isDir) + err = w.tree.Scan(lwev.Path, ActionDelete, isDir) case strings.Contains(lwev.Event, "IN_MOVE_FROM"): - _ = w.tree.Scan(lwev.Path, ActionMoveFrom, isDir) + err = w.tree.Scan(lwev.Path, ActionMoveFrom, isDir) case strings.Contains(lwev.Event, "IN_CREATE"): - _ = w.tree.Scan(lwev.Path, ActionCreate, isDir) + err = w.tree.Scan(lwev.Path, ActionCreate, isDir) case strings.Contains(lwev.Event, "IN_CLOSE_WRITE"): - bytesWritten, err := strconv.Atoi(lwev.BytesWritten) - if err == nil && bytesWritten > 0 { - _ = w.tree.Scan(lwev.Path, ActionUpdate, isDir) + bytesWritten, convErr := strconv.Atoi(lwev.BytesWritten) + if convErr == nil && bytesWritten > 0 { + err = w.tree.Scan(lwev.Path, ActionUpdate, isDir) } case strings.Contains(lwev.Event, "IN_MOVED_TO"): - _ = w.tree.Scan(lwev.Path, ActionMove, isDir) + err = w.tree.Scan(lwev.Path, ActionMove, isDir) + } + if err != nil { + w.log.Error().Err(err).Str("path", lwev.Path).Msg("error scanning path") } }() } diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/inotifywatcher.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/inotifywatcher.go index 54b7157e0f8..660cdbdacd9 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/inotifywatcher.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/inotifywatcher.go @@ -22,15 +22,18 @@ import ( "fmt" "github.com/pablodz/inotifywaitgo/inotifywaitgo" + "github.com/rs/zerolog" ) type InotifyWatcher struct { tree *Tree + log *zerolog.Logger } -func NewInotifyWatcher(tree *Tree) *InotifyWatcher { +func NewInotifyWatcher(tree *Tree, log *zerolog.Logger) *InotifyWatcher { return &InotifyWatcher{ tree: tree, + log: log, } } @@ -60,20 +63,29 @@ func (iw *InotifyWatcher) Watch(path string) { for { select { case event := <-events: + if isLockFile(event.Filename) || isTrash(event.Filename) || iw.tree.isUpload(event.Filename) { + continue + } for _, e := range event.Events { - if isLockFile(event.Filename) || isTrash(event.Filename) || iw.tree.isUpload(event.Filename) { - continue - } go func() { + var err error switch e { case inotifywaitgo.DELETE: - _ = iw.tree.Scan(event.Filename, ActionDelete, event.IsDir) + err = iw.tree.Scan(event.Filename, ActionDelete, event.IsDir) case inotifywaitgo.MOVED_FROM: - _ = iw.tree.Scan(event.Filename, ActionMoveFrom, event.IsDir) + err = iw.tree.Scan(event.Filename, ActionMoveFrom, event.IsDir) case inotifywaitgo.CREATE, inotifywaitgo.MOVED_TO: - _ = iw.tree.Scan(event.Filename, ActionCreate, event.IsDir) + err = iw.tree.Scan(event.Filename, ActionCreate, event.IsDir) case inotifywaitgo.CLOSE_WRITE: - _ = iw.tree.Scan(event.Filename, ActionUpdate, event.IsDir) + err = iw.tree.Scan(event.Filename, ActionUpdate, event.IsDir) + case inotifywaitgo.CLOSE: + // ignore, already handled by CLOSE_WRITE + default: + iw.log.Warn().Interface("event", event).Msg("unhandled event") + return + } + if err != nil { + iw.log.Error().Err(err).Str("path", event.Filename).Msg("error scanning file") } }() } diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/tree.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/tree.go index 7bf7e34a1b5..cbe0f392e29 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/tree.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/fs/posix/tree/tree.go @@ -121,17 +121,17 @@ func New(lu node.PathLookup, bs Blobstore, um usermapper.Mapper, trashbin *trash var err error switch o.WatchType { case "gpfswatchfolder": - t.watcher, err = NewGpfsWatchFolderWatcher(t, strings.Split(o.WatchFolderKafkaBrokers, ",")) + t.watcher, err = NewGpfsWatchFolderWatcher(t, strings.Split(o.WatchFolderKafkaBrokers, ","), log) if err != nil { return nil, err } case "gpfsfileauditlogging": - t.watcher, err = NewGpfsFileAuditLoggingWatcher(t, o.WatchPath) + t.watcher, err = NewGpfsFileAuditLoggingWatcher(t, o.WatchPath, log) if err != nil { return nil, err } default: - t.watcher = NewInotifyWatcher(t) + t.watcher = NewInotifyWatcher(t, log) watchPath = o.Root } @@ -213,7 +213,9 @@ func (t *Tree) TouchFile(ctx context.Context, n *node.Node, markprocessing bool, n.SetType(provider.ResourceType_RESOURCE_TYPE_FILE) // Set id in cache - _ = t.lookup.(*lookup.Lookup).CacheID(context.Background(), n.SpaceID, n.ID, nodePath) + if err := t.lookup.(*lookup.Lookup).CacheID(context.Background(), n.SpaceID, n.ID, nodePath); err != nil { + t.log.Error().Err(err).Str("spaceID", n.SpaceID).Str("id", n.ID).Str("path", nodePath).Msg("could not cache id") + } if err := os.MkdirAll(filepath.Dir(nodePath), 0700); err != nil { return errors.Wrap(err, "Decomposedfs: error creating node") @@ -312,7 +314,9 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node) if newNode.ID == "" { newNode.ID = oldNode.ID } - _ = t.lookup.(*lookup.Lookup).CacheID(ctx, newNode.SpaceID, newNode.ID, filepath.Join(newNode.ParentPath(), newNode.Name)) + if err := t.lookup.(*lookup.Lookup).CacheID(ctx, newNode.SpaceID, newNode.ID, filepath.Join(newNode.ParentPath(), newNode.Name)); err != nil { + t.log.Error().Err(err).Str("spaceID", newNode.SpaceID).Str("id", newNode.ID).Str("path", filepath.Join(newNode.ParentPath(), newNode.Name)).Msg("could not cache id") + } // rename the lock (if it exists) if _, err := os.Stat(oldNode.LockFilePath()); err == nil { @@ -476,7 +480,11 @@ func (t *Tree) Delete(ctx context.Context, n *node.Node) error { } // remove entry from cache immediately to avoid inconsistencies - defer func() { _ = t.idCache.Delete(path) }() + defer func() { + if err := t.idCache.Delete(path); err != nil { + log.Error().Err(err).Str("path", path).Msg("could not delete id from cache") + } + }() if appctx.DeletingSharedResourceFromContext(ctx) { src := filepath.Join(n.ParentPath(), n.Name) @@ -495,7 +503,9 @@ func (t *Tree) Delete(ctx context.Context, n *node.Node) error { } // Remove lock file if it exists - _ = os.Remove(n.LockFilePath()) + if err := os.Remove(n.LockFilePath()); err != nil { + log.Error().Err(err).Str("path", n.LockFilePath()).Msg("could not remove lock file") + } err := t.trashbin.MoveToTrash(ctx, n, path) if err != nil { @@ -748,7 +758,9 @@ func (t *Tree) createDirNode(ctx context.Context, n *node.Node) (err error) { return errors.Wrap(err, "Decomposedfs: error creating node") } - _ = idcache.Set(ctx, n.SpaceID, n.ID, path) + if err := idcache.Set(ctx, n.SpaceID, n.ID, path); err != nil { + log.Error().Err(err).Str("spaceID", n.SpaceID).Str("id", n.ID).Str("path", path).Msg("could not cache id") + } attributes := n.NodeMetadata(ctx) attributes[prefixes.IDAttr] = []byte(n.ID) diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/lookup/lookup.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/lookup/lookup.go index fc95764aaf9..2a4671cda72 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/lookup/lookup.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/lookup/lookup.go @@ -235,14 +235,17 @@ func (lu *Lookup) GenerateSpaceID(spaceType string, owner *user.User) (string, e // Path returns the path for node func (lu *Lookup) Path(ctx context.Context, n *node.Node, hasPermission node.PermissionFunc) (p string, err error) { root := n.SpaceRoot + var child *node.Node for n.ID != root.ID { p = filepath.Join(n.Name, p) + child = n if n, err = n.Parent(ctx); err != nil { appctx.GetLogger(ctx). Error().Err(err). Str("path", p). - Str("spaceid", n.SpaceID). - Str("nodeid", n.ID). + Str("spaceid", child.SpaceID). + Str("nodeid", child.ID). + Str("parentid", child.ParentID). Msg("Path()") return } diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/store.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/store.go index 1264512205d..d170fc5d872 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/store.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/store.go @@ -312,11 +312,8 @@ func (store OcisStore) updateExistingNode(ctx context.Context, session *OcisSess } unlock := func() error { - err := f.Close() - if err != nil { - return err - } - return os.Remove(store.lu.MetadataBackend().LockfilePath(targetPath)) + // NOTE: to prevent stale NFS file handles do not remove lock file! + return f.Close() } old, _ := node.ReadNode(ctx, store.lu, spaceID, n.ID, false, nil, false) diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/upload.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/upload.go index f460c526ed1..7476d10058d 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/upload.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/upload.go @@ -33,7 +33,7 @@ import ( userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" - "github.com/golang-jwt/jwt" + "github.com/golang-jwt/jwt/v5" "github.com/pkg/errors" tusd "github.com/tus/tusd/v2/pkg/handler" "go.opentelemetry.io/otel" @@ -372,17 +372,17 @@ func (session *OcisSession) Cleanup(revertNodeMetadata, cleanBin, cleanInfo bool // URL returns a url to download an upload func (session *OcisSession) URL(_ context.Context) (string, error) { type transferClaims struct { - jwt.StandardClaims + jwt.RegisteredClaims Target string `json:"target"` } u := joinurl(session.store.tknopts.DownloadEndpoint, "tus/", session.ID()) ttl := time.Duration(session.store.tknopts.TransferExpires) * time.Second claims := transferClaims{ - StandardClaims: jwt.StandardClaims{ - ExpiresAt: time.Now().Add(ttl).Unix(), - Audience: "reva", - IssuedAt: time.Now().Unix(), + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(time.Now().Add(ttl)), + Audience: jwt.ClaimStrings{"reva"}, + IssuedAt: jwt.NewNumericDate(time.Now()), }, Target: u, } diff --git a/vendor/github.com/cs3org/reva/v2/pkg/token/manager/jwt/jwt.go b/vendor/github.com/cs3org/reva/v2/pkg/token/manager/jwt/jwt.go index f331a26ee0f..4e327018e89 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/token/manager/jwt/jwt.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/token/manager/jwt/jwt.go @@ -28,20 +28,22 @@ import ( "github.com/cs3org/reva/v2/pkg/sharedconf" "github.com/cs3org/reva/v2/pkg/token" "github.com/cs3org/reva/v2/pkg/token/manager/registry" - "github.com/golang-jwt/jwt" + "github.com/golang-jwt/jwt/v5" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" ) const defaultExpiration int64 = 86400 // 1 day +const defaultLeeway int64 = 5 // 5 seconds func init() { registry.Register("jwt", New) } type config struct { - Secret string `mapstructure:"secret"` - Expires int64 `mapstructure:"expires"` + Secret string `mapstructure:"secret"` + Expires int64 `mapstructure:"expires"` + tokenTimeLeeway int64 `mapstructure:"token_leeway"` } type manager struct { @@ -50,7 +52,7 @@ type manager struct { // claims are custom claims for the JWT token. type claims struct { - jwt.StandardClaims + jwt.RegisteredClaims User *user.User `json:"user"` Scope map[string]*auth.Scope `json:"scope"` } @@ -75,6 +77,10 @@ func New(value map[string]interface{}) (token.Manager, error) { c.Expires = defaultExpiration } + if c.tokenTimeLeeway == 0 { + c.tokenTimeLeeway = defaultLeeway + } + c.Secret = sharedconf.GetJWTSecret(c.Secret) if c.Secret == "" { @@ -87,31 +93,32 @@ func New(value map[string]interface{}) (token.Manager, error) { func (m *manager) MintToken(ctx context.Context, u *user.User, scope map[string]*auth.Scope) (string, error) { ttl := time.Duration(m.conf.Expires) * time.Second - claims := claims{ - StandardClaims: jwt.StandardClaims{ - ExpiresAt: time.Now().Add(ttl).Unix(), + newClaims := claims{ + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(time.Now().Add(ttl)), Issuer: u.Id.Idp, - Audience: "reva", - IssuedAt: time.Now().Unix(), + Audience: jwt.ClaimStrings{"reva"}, + IssuedAt: jwt.NewNumericDate(time.Now()), }, User: u, Scope: scope, } - t := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), claims) + t := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), newClaims) tkn, err := t.SignedString([]byte(m.conf.Secret)) if err != nil { - return "", errors.Wrapf(err, "error signing token with claims %+v", claims) + return "", errors.Wrapf(err, "error signing token with claims %+v", newClaims) } return tkn, nil } func (m *manager) DismantleToken(ctx context.Context, tkn string) (*user.User, map[string]*auth.Scope, error) { - token, err := jwt.ParseWithClaims(tkn, &claims{}, func(token *jwt.Token) (interface{}, error) { + keyfunc := func(token *jwt.Token) (interface{}, error) { return []byte(m.conf.Secret), nil - }) + } + token, err := jwt.ParseWithClaims(tkn, &claims{}, keyfunc, jwt.WithLeeway(time.Duration(m.conf.tokenTimeLeeway)*time.Second)) if err != nil { return nil, nil, errors.Wrap(err, "error parsing token") diff --git a/vendor/github.com/golang-jwt/jwt/.gitignore b/vendor/github.com/golang-jwt/jwt/.gitignore deleted file mode 100644 index 09573e0169c..00000000000 --- a/vendor/github.com/golang-jwt/jwt/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.DS_Store -bin -.idea/ - diff --git a/vendor/github.com/golang-jwt/jwt/LICENSE b/vendor/github.com/golang-jwt/jwt/LICENSE deleted file mode 100644 index 35dbc252041..00000000000 --- a/vendor/github.com/golang-jwt/jwt/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -Copyright (c) 2012 Dave Grijalva -Copyright (c) 2021 golang-jwt maintainers - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/vendor/github.com/golang-jwt/jwt/MIGRATION_GUIDE.md b/vendor/github.com/golang-jwt/jwt/MIGRATION_GUIDE.md deleted file mode 100644 index c4efbd2a8c5..00000000000 --- a/vendor/github.com/golang-jwt/jwt/MIGRATION_GUIDE.md +++ /dev/null @@ -1,22 +0,0 @@ -## Migration Guide (v3.2.1) - -Starting from [v3.2.1](https://github.com/golang-jwt/jwt/releases/tag/v3.2.1]), the import path has changed from `github.com/dgrijalva/jwt-go` to `github.com/golang-jwt/jwt`. Future releases will be using the `github.com/golang-jwt/jwt` import path and continue the existing versioning scheme of `v3.x.x+incompatible`. Backwards-compatible patches and fixes will be done on the `v3` release branch, where as new build-breaking features will be developed in a `v4` release, possibly including a SIV-style import path. - -### go.mod replacement - -In a first step, the easiest way is to use `go mod edit` to issue a replacement. - -``` -go mod edit -replace github.com/dgrijalva/jwt-go=github.com/golang-jwt/jwt@v3.2.1+incompatible -go mod tidy -``` - -This will still keep the old import path in your code but replace it with the new package and also introduce a new indirect dependency to `github.com/golang-jwt/jwt`. Try to compile your project; it should still work. - -### Cleanup - -If your code still consistently builds, you can replace all occurences of `github.com/dgrijalva/jwt-go` with `github.com/golang-jwt/jwt`, either manually or by using tools such as `sed`. Finally, the `replace` directive in the `go.mod` file can be removed. - -## Older releases (before v3.2.0) - -The original migration guide for older releases can be found at https://github.com/dgrijalva/jwt-go/blob/master/MIGRATION_GUIDE.md. \ No newline at end of file diff --git a/vendor/github.com/golang-jwt/jwt/README.md b/vendor/github.com/golang-jwt/jwt/README.md deleted file mode 100644 index 9b653e46b01..00000000000 --- a/vendor/github.com/golang-jwt/jwt/README.md +++ /dev/null @@ -1,113 +0,0 @@ -# jwt-go - -[![build](https://github.com/golang-jwt/jwt/actions/workflows/build.yml/badge.svg)](https://github.com/golang-jwt/jwt/actions/workflows/build.yml) -[![Go Reference](https://pkg.go.dev/badge/github.com/golang-jwt/jwt.svg)](https://pkg.go.dev/github.com/golang-jwt/jwt) - -A [go](http://www.golang.org) (or 'golang' for search engine friendliness) implementation of [JSON Web Tokens](https://datatracker.ietf.org/doc/html/rfc7519). - -**IMPORT PATH CHANGE:** Starting from [v3.2.1](https://github.com/golang-jwt/jwt/releases/tag/v3.2.1), the import path has changed from `github.com/dgrijalva/jwt-go` to `github.com/golang-jwt/jwt`. After the original author of the library suggested migrating the maintenance of `jwt-go`, a dedicated team of open source maintainers decided to clone the existing library into this repository. See [dgrijalva/jwt-go#462](https://github.com/dgrijalva/jwt-go/issues/462) for a detailed discussion on this topic. - -Future releases will be using the `github.com/golang-jwt/jwt` import path and continue the existing versioning scheme of `v3.x.x+incompatible`. Backwards-compatible patches and fixes will be done on the `v3` release branch, where as new build-breaking features will be developed in a `v4` release, possibly including a SIV-style import path. - -**SECURITY NOTICE:** Some older versions of Go have a security issue in the crypto/elliptic. Recommendation is to upgrade to at least 1.15 See issue [dgrijalva/jwt-go#216](https://github.com/dgrijalva/jwt-go/issues/216) for more detail. - -**SECURITY NOTICE:** It's important that you [validate the `alg` presented is what you expect](https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/). This library attempts to make it easy to do the right thing by requiring key types match the expected alg, but you should take the extra step to verify it in your usage. See the examples provided. - -### Supported Go versions - -Our support of Go versions is aligned with Go's [version release policy](https://golang.org/doc/devel/release#policy). -So we will support a major version of Go until there are two newer major releases. -We no longer support building jwt-go with unsupported Go versions, as these contain security vulnerabilities -which will not be fixed. - -## What the heck is a JWT? - -JWT.io has [a great introduction](https://jwt.io/introduction) to JSON Web Tokens. - -In short, it's a signed JSON object that does something useful (for example, authentication). It's commonly used for `Bearer` tokens in Oauth 2. A token is made of three parts, separated by `.`'s. The first two parts are JSON objects, that have been [base64url](https://datatracker.ietf.org/doc/html/rfc4648) encoded. The last part is the signature, encoded the same way. - -The first part is called the header. It contains the necessary information for verifying the last part, the signature. For example, which encryption method was used for signing and what key was used. - -The part in the middle is the interesting bit. It's called the Claims and contains the actual stuff you care about. Refer to [RFC 7519](https://datatracker.ietf.org/doc/html/rfc7519) for information about reserved keys and the proper way to add your own. - -## What's in the box? - -This library supports the parsing and verification as well as the generation and signing of JWTs. Current supported signing algorithms are HMAC SHA, RSA, RSA-PSS, and ECDSA, though hooks are present for adding your own. - -## Examples - -See [the project documentation](https://pkg.go.dev/github.com/golang-jwt/jwt) for examples of usage: - -* [Simple example of parsing and validating a token](https://pkg.go.dev/github.com/golang-jwt/jwt#example-Parse-Hmac) -* [Simple example of building and signing a token](https://pkg.go.dev/github.com/golang-jwt/jwt#example-New-Hmac) -* [Directory of Examples](https://pkg.go.dev/github.com/golang-jwt/jwt#pkg-examples) - -## Extensions - -This library publishes all the necessary components for adding your own signing methods. Simply implement the `SigningMethod` interface and register a factory method using `RegisterSigningMethod`. - -Here's an example of an extension that integrates with multiple Google Cloud Platform signing tools (AppEngine, IAM API, Cloud KMS): https://github.com/someone1/gcp-jwt-go - -## Compliance - -This library was last reviewed to comply with [RTF 7519](https://datatracker.ietf.org/doc/html/rfc7519) dated May 2015 with a few notable differences: - -* In order to protect against accidental use of [Unsecured JWTs](https://datatracker.ietf.org/doc/html/rfc7519#section-6), tokens using `alg=none` will only be accepted if the constant `jwt.UnsafeAllowNoneSignatureType` is provided as the key. - -## Project Status & Versioning - -This library is considered production ready. Feedback and feature requests are appreciated. The API should be considered stable. There should be very few backwards-incompatible changes outside of major version updates (and only with good reason). - -This project uses [Semantic Versioning 2.0.0](http://semver.org). Accepted pull requests will land on `main`. Periodically, versions will be tagged from `main`. You can find all the releases on [the project releases page](https://github.com/golang-jwt/jwt/releases). - -While we try to make it obvious when we make breaking changes, there isn't a great mechanism for pushing announcements out to users. You may want to use this alternative package include: `gopkg.in/golang-jwt/jwt.v3`. It will do the right thing WRT semantic versioning. - -**BREAKING CHANGES:*** -* Version 3.0.0 includes _a lot_ of changes from the 2.x line, including a few that break the API. We've tried to break as few things as possible, so there should just be a few type signature changes. A full list of breaking changes is available in `VERSION_HISTORY.md`. See `MIGRATION_GUIDE.md` for more information on updating your code. - -## Usage Tips - -### Signing vs Encryption - -A token is simply a JSON object that is signed by its author. this tells you exactly two things about the data: - -* The author of the token was in the possession of the signing secret -* The data has not been modified since it was signed - -It's important to know that JWT does not provide encryption, which means anyone who has access to the token can read its contents. If you need to protect (encrypt) the data, there is a companion spec, `JWE`, that provides this functionality. JWE is currently outside the scope of this library. - -### Choosing a Signing Method - -There are several signing methods available, and you should probably take the time to learn about the various options before choosing one. The principal design decision is most likely going to be symmetric vs asymmetric. - -Symmetric signing methods, such as HSA, use only a single secret. This is probably the simplest signing method to use since any `[]byte` can be used as a valid secret. They are also slightly computationally faster to use, though this rarely is enough to matter. Symmetric signing methods work the best when both producers and consumers of tokens are trusted, or even the same system. Since the same secret is used to both sign and validate tokens, you can't easily distribute the key for validation. - -Asymmetric signing methods, such as RSA, use different keys for signing and verifying tokens. This makes it possible to produce tokens with a private key, and allow any consumer to access the public key for verification. - -### Signing Methods and Key Types - -Each signing method expects a different object type for its signing keys. See the package documentation for details. Here are the most common ones: - -* The [HMAC signing method](https://pkg.go.dev/github.com/golang-jwt/jwt#SigningMethodHMAC) (`HS256`,`HS384`,`HS512`) expect `[]byte` values for signing and validation -* The [RSA signing method](https://pkg.go.dev/github.com/golang-jwt/jwt#SigningMethodRSA) (`RS256`,`RS384`,`RS512`) expect `*rsa.PrivateKey` for signing and `*rsa.PublicKey` for validation -* The [ECDSA signing method](https://pkg.go.dev/github.com/golang-jwt/jwt#SigningMethodECDSA) (`ES256`,`ES384`,`ES512`) expect `*ecdsa.PrivateKey` for signing and `*ecdsa.PublicKey` for validation - -### JWT and OAuth - -It's worth mentioning that OAuth and JWT are not the same thing. A JWT token is simply a signed JSON object. It can be used anywhere such a thing is useful. There is some confusion, though, as JWT is the most common type of bearer token used in OAuth2 authentication. - -Without going too far down the rabbit hole, here's a description of the interaction of these technologies: - -* OAuth is a protocol for allowing an identity provider to be separate from the service a user is logging in to. For example, whenever you use Facebook to log into a different service (Yelp, Spotify, etc), you are using OAuth. -* OAuth defines several options for passing around authentication data. One popular method is called a "bearer token". A bearer token is simply a string that _should_ only be held by an authenticated user. Thus, simply presenting this token proves your identity. You can probably derive from here why a JWT might make a good bearer token. -* Because bearer tokens are used for authentication, it's important they're kept secret. This is why transactions that use bearer tokens typically happen over SSL. - -### Troubleshooting - -This library uses descriptive error messages whenever possible. If you are not getting the expected result, have a look at the errors. The most common place people get stuck is providing the correct type of key to the parser. See the above section on signing methods and key types. - -## More - -Documentation can be found [on pkg.go.dev](https://pkg.go.dev/github.com/golang-jwt/jwt). - -The command line utility included in this project (cmd/jwt) provides a straightforward example of token creation and parsing as well as a useful tool for debugging your own integration. You'll also find several implementation examples in the documentation. diff --git a/vendor/github.com/golang-jwt/jwt/VERSION_HISTORY.md b/vendor/github.com/golang-jwt/jwt/VERSION_HISTORY.md deleted file mode 100644 index 637f2ba616a..00000000000 --- a/vendor/github.com/golang-jwt/jwt/VERSION_HISTORY.md +++ /dev/null @@ -1,131 +0,0 @@ -## `jwt-go` Version History - -#### 3.2.2 - -* Starting from this release, we are adopting the policy to support the most 2 recent versions of Go currently available. By the time of this release, this is Go 1.15 and 1.16 ([#28](https://github.com/golang-jwt/jwt/pull/28)). -* Fixed a potential issue that could occur when the verification of `exp`, `iat` or `nbf` was not required and contained invalid contents, i.e. non-numeric/date. Thanks for @thaJeztah for making us aware of that and @giorgos-f3 for originally reporting it to the formtech fork ([#40](https://github.com/golang-jwt/jwt/pull/40)). -* Added support for EdDSA / ED25519 ([#36](https://github.com/golang-jwt/jwt/pull/36)). -* Optimized allocations ([#33](https://github.com/golang-jwt/jwt/pull/33)). - -#### 3.2.1 - -* **Import Path Change**: See MIGRATION_GUIDE.md for tips on updating your code - * Changed the import path from `github.com/dgrijalva/jwt-go` to `github.com/golang-jwt/jwt` -* Fixed type confusing issue between `string` and `[]string` in `VerifyAudience` ([#12](https://github.com/golang-jwt/jwt/pull/12)). This fixes CVE-2020-26160 - -#### 3.2.0 - -* Added method `ParseUnverified` to allow users to split up the tasks of parsing and validation -* HMAC signing method returns `ErrInvalidKeyType` instead of `ErrInvalidKey` where appropriate -* Added options to `request.ParseFromRequest`, which allows for an arbitrary list of modifiers to parsing behavior. Initial set include `WithClaims` and `WithParser`. Existing usage of this function will continue to work as before. -* Deprecated `ParseFromRequestWithClaims` to simplify API in the future. - -#### 3.1.0 - -* Improvements to `jwt` command line tool -* Added `SkipClaimsValidation` option to `Parser` -* Documentation updates - -#### 3.0.0 - -* **Compatibility Breaking Changes**: See MIGRATION_GUIDE.md for tips on updating your code - * Dropped support for `[]byte` keys when using RSA signing methods. This convenience feature could contribute to security vulnerabilities involving mismatched key types with signing methods. - * `ParseFromRequest` has been moved to `request` subpackage and usage has changed - * The `Claims` property on `Token` is now type `Claims` instead of `map[string]interface{}`. The default value is type `MapClaims`, which is an alias to `map[string]interface{}`. This makes it possible to use a custom type when decoding claims. -* Other Additions and Changes - * Added `Claims` interface type to allow users to decode the claims into a custom type - * Added `ParseWithClaims`, which takes a third argument of type `Claims`. Use this function instead of `Parse` if you have a custom type you'd like to decode into. - * Dramatically improved the functionality and flexibility of `ParseFromRequest`, which is now in the `request` subpackage - * Added `ParseFromRequestWithClaims` which is the `FromRequest` equivalent of `ParseWithClaims` - * Added new interface type `Extractor`, which is used for extracting JWT strings from http requests. Used with `ParseFromRequest` and `ParseFromRequestWithClaims`. - * Added several new, more specific, validation errors to error type bitmask - * Moved examples from README to executable example files - * Signing method registry is now thread safe - * Added new property to `ValidationError`, which contains the raw error returned by calls made by parse/verify (such as those returned by keyfunc or json parser) - -#### 2.7.0 - -This will likely be the last backwards compatible release before 3.0.0, excluding essential bug fixes. - -* Added new option `-show` to the `jwt` command that will just output the decoded token without verifying -* Error text for expired tokens includes how long it's been expired -* Fixed incorrect error returned from `ParseRSAPublicKeyFromPEM` -* Documentation updates - -#### 2.6.0 - -* Exposed inner error within ValidationError -* Fixed validation errors when using UseJSONNumber flag -* Added several unit tests - -#### 2.5.0 - -* Added support for signing method none. You shouldn't use this. The API tries to make this clear. -* Updated/fixed some documentation -* Added more helpful error message when trying to parse tokens that begin with `BEARER ` - -#### 2.4.0 - -* Added new type, Parser, to allow for configuration of various parsing parameters - * You can now specify a list of valid signing methods. Anything outside this set will be rejected. - * You can now opt to use the `json.Number` type instead of `float64` when parsing token JSON -* Added support for [Travis CI](https://travis-ci.org/dgrijalva/jwt-go) -* Fixed some bugs with ECDSA parsing - -#### 2.3.0 - -* Added support for ECDSA signing methods -* Added support for RSA PSS signing methods (requires go v1.4) - -#### 2.2.0 - -* Gracefully handle a `nil` `Keyfunc` being passed to `Parse`. Result will now be the parsed token and an error, instead of a panic. - -#### 2.1.0 - -Backwards compatible API change that was missed in 2.0.0. - -* The `SignedString` method on `Token` now takes `interface{}` instead of `[]byte` - -#### 2.0.0 - -There were two major reasons for breaking backwards compatibility with this update. The first was a refactor required to expand the width of the RSA and HMAC-SHA signing implementations. There will likely be no required code changes to support this change. - -The second update, while unfortunately requiring a small change in integration, is required to open up this library to other signing methods. Not all keys used for all signing methods have a single standard on-disk representation. Requiring `[]byte` as the type for all keys proved too limiting. Additionally, this implementation allows for pre-parsed tokens to be reused, which might matter in an application that parses a high volume of tokens with a small set of keys. Backwards compatibilty has been maintained for passing `[]byte` to the RSA signing methods, but they will also accept `*rsa.PublicKey` and `*rsa.PrivateKey`. - -It is likely the only integration change required here will be to change `func(t *jwt.Token) ([]byte, error)` to `func(t *jwt.Token) (interface{}, error)` when calling `Parse`. - -* **Compatibility Breaking Changes** - * `SigningMethodHS256` is now `*SigningMethodHMAC` instead of `type struct` - * `SigningMethodRS256` is now `*SigningMethodRSA` instead of `type struct` - * `KeyFunc` now returns `interface{}` instead of `[]byte` - * `SigningMethod.Sign` now takes `interface{}` instead of `[]byte` for the key - * `SigningMethod.Verify` now takes `interface{}` instead of `[]byte` for the key -* Renamed type `SigningMethodHS256` to `SigningMethodHMAC`. Specific sizes are now just instances of this type. - * Added public package global `SigningMethodHS256` - * Added public package global `SigningMethodHS384` - * Added public package global `SigningMethodHS512` -* Renamed type `SigningMethodRS256` to `SigningMethodRSA`. Specific sizes are now just instances of this type. - * Added public package global `SigningMethodRS256` - * Added public package global `SigningMethodRS384` - * Added public package global `SigningMethodRS512` -* Moved sample private key for HMAC tests from an inline value to a file on disk. Value is unchanged. -* Refactored the RSA implementation to be easier to read -* Exposed helper methods `ParseRSAPrivateKeyFromPEM` and `ParseRSAPublicKeyFromPEM` - -#### 1.0.2 - -* Fixed bug in parsing public keys from certificates -* Added more tests around the parsing of keys for RS256 -* Code refactoring in RS256 implementation. No functional changes - -#### 1.0.1 - -* Fixed panic if RS256 signing method was passed an invalid key - -#### 1.0.0 - -* First versioned release -* API stabilized -* Supports creating, signing, parsing, and validating JWT tokens -* Supports RS256 and HS256 signing methods diff --git a/vendor/github.com/golang-jwt/jwt/claims.go b/vendor/github.com/golang-jwt/jwt/claims.go deleted file mode 100644 index f1dba3cb916..00000000000 --- a/vendor/github.com/golang-jwt/jwt/claims.go +++ /dev/null @@ -1,146 +0,0 @@ -package jwt - -import ( - "crypto/subtle" - "fmt" - "time" -) - -// For a type to be a Claims object, it must just have a Valid method that determines -// if the token is invalid for any supported reason -type Claims interface { - Valid() error -} - -// Structured version of Claims Section, as referenced at -// https://tools.ietf.org/html/rfc7519#section-4.1 -// See examples for how to use this with your own claim types -type StandardClaims struct { - Audience string `json:"aud,omitempty"` - ExpiresAt int64 `json:"exp,omitempty"` - Id string `json:"jti,omitempty"` - IssuedAt int64 `json:"iat,omitempty"` - Issuer string `json:"iss,omitempty"` - NotBefore int64 `json:"nbf,omitempty"` - Subject string `json:"sub,omitempty"` -} - -// Validates time based claims "exp, iat, nbf". -// There is no accounting for clock skew. -// As well, if any of the above claims are not in the token, it will still -// be considered a valid claim. -func (c StandardClaims) Valid() error { - vErr := new(ValidationError) - now := TimeFunc().Unix() - - // The claims below are optional, by default, so if they are set to the - // default value in Go, let's not fail the verification for them. - if !c.VerifyExpiresAt(now, false) { - delta := time.Unix(now, 0).Sub(time.Unix(c.ExpiresAt, 0)) - vErr.Inner = fmt.Errorf("token is expired by %v", delta) - vErr.Errors |= ValidationErrorExpired - } - - if !c.VerifyIssuedAt(now, false) { - vErr.Inner = fmt.Errorf("Token used before issued") - vErr.Errors |= ValidationErrorIssuedAt - } - - if !c.VerifyNotBefore(now, false) { - vErr.Inner = fmt.Errorf("token is not valid yet") - vErr.Errors |= ValidationErrorNotValidYet - } - - if vErr.valid() { - return nil - } - - return vErr -} - -// Compares the aud claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyAudience(cmp string, req bool) bool { - return verifyAud([]string{c.Audience}, cmp, req) -} - -// Compares the exp claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyExpiresAt(cmp int64, req bool) bool { - return verifyExp(c.ExpiresAt, cmp, req) -} - -// Compares the iat claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyIssuedAt(cmp int64, req bool) bool { - return verifyIat(c.IssuedAt, cmp, req) -} - -// Compares the iss claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyIssuer(cmp string, req bool) bool { - return verifyIss(c.Issuer, cmp, req) -} - -// Compares the nbf claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (c *StandardClaims) VerifyNotBefore(cmp int64, req bool) bool { - return verifyNbf(c.NotBefore, cmp, req) -} - -// ----- helpers - -func verifyAud(aud []string, cmp string, required bool) bool { - if len(aud) == 0 { - return !required - } - // use a var here to keep constant time compare when looping over a number of claims - result := false - - var stringClaims string - for _, a := range aud { - if subtle.ConstantTimeCompare([]byte(a), []byte(cmp)) != 0 { - result = true - } - stringClaims = stringClaims + a - } - - // case where "" is sent in one or many aud claims - if len(stringClaims) == 0 { - return !required - } - - return result -} - -func verifyExp(exp int64, now int64, required bool) bool { - if exp == 0 { - return !required - } - return now <= exp -} - -func verifyIat(iat int64, now int64, required bool) bool { - if iat == 0 { - return !required - } - return now >= iat -} - -func verifyIss(iss string, cmp string, required bool) bool { - if iss == "" { - return !required - } - if subtle.ConstantTimeCompare([]byte(iss), []byte(cmp)) != 0 { - return true - } else { - return false - } -} - -func verifyNbf(nbf int64, now int64, required bool) bool { - if nbf == 0 { - return !required - } - return now >= nbf -} diff --git a/vendor/github.com/golang-jwt/jwt/doc.go b/vendor/github.com/golang-jwt/jwt/doc.go deleted file mode 100644 index a86dc1a3b34..00000000000 --- a/vendor/github.com/golang-jwt/jwt/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -// Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html -// -// See README.md for more info. -package jwt diff --git a/vendor/github.com/golang-jwt/jwt/ecdsa.go b/vendor/github.com/golang-jwt/jwt/ecdsa.go deleted file mode 100644 index 15e23435df6..00000000000 --- a/vendor/github.com/golang-jwt/jwt/ecdsa.go +++ /dev/null @@ -1,142 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/ecdsa" - "crypto/rand" - "errors" - "math/big" -) - -var ( - // Sadly this is missing from crypto/ecdsa compared to crypto/rsa - ErrECDSAVerification = errors.New("crypto/ecdsa: verification error") -) - -// Implements the ECDSA family of signing methods signing methods -// Expects *ecdsa.PrivateKey for signing and *ecdsa.PublicKey for verification -type SigningMethodECDSA struct { - Name string - Hash crypto.Hash - KeySize int - CurveBits int -} - -// Specific instances for EC256 and company -var ( - SigningMethodES256 *SigningMethodECDSA - SigningMethodES384 *SigningMethodECDSA - SigningMethodES512 *SigningMethodECDSA -) - -func init() { - // ES256 - SigningMethodES256 = &SigningMethodECDSA{"ES256", crypto.SHA256, 32, 256} - RegisterSigningMethod(SigningMethodES256.Alg(), func() SigningMethod { - return SigningMethodES256 - }) - - // ES384 - SigningMethodES384 = &SigningMethodECDSA{"ES384", crypto.SHA384, 48, 384} - RegisterSigningMethod(SigningMethodES384.Alg(), func() SigningMethod { - return SigningMethodES384 - }) - - // ES512 - SigningMethodES512 = &SigningMethodECDSA{"ES512", crypto.SHA512, 66, 521} - RegisterSigningMethod(SigningMethodES512.Alg(), func() SigningMethod { - return SigningMethodES512 - }) -} - -func (m *SigningMethodECDSA) Alg() string { - return m.Name -} - -// Implements the Verify method from SigningMethod -// For this verify method, key must be an ecdsa.PublicKey struct -func (m *SigningMethodECDSA) Verify(signingString, signature string, key interface{}) error { - var err error - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - // Get the key - var ecdsaKey *ecdsa.PublicKey - switch k := key.(type) { - case *ecdsa.PublicKey: - ecdsaKey = k - default: - return ErrInvalidKeyType - } - - if len(sig) != 2*m.KeySize { - return ErrECDSAVerification - } - - r := big.NewInt(0).SetBytes(sig[:m.KeySize]) - s := big.NewInt(0).SetBytes(sig[m.KeySize:]) - - // Create hasher - if !m.Hash.Available() { - return ErrHashUnavailable - } - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Verify the signature - if verifystatus := ecdsa.Verify(ecdsaKey, hasher.Sum(nil), r, s); verifystatus { - return nil - } - - return ErrECDSAVerification -} - -// Implements the Sign method from SigningMethod -// For this signing method, key must be an ecdsa.PrivateKey struct -func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string, error) { - // Get the key - var ecdsaKey *ecdsa.PrivateKey - switch k := key.(type) { - case *ecdsa.PrivateKey: - ecdsaKey = k - default: - return "", ErrInvalidKeyType - } - - // Create the hasher - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Sign the string and return r, s - if r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, hasher.Sum(nil)); err == nil { - curveBits := ecdsaKey.Curve.Params().BitSize - - if m.CurveBits != curveBits { - return "", ErrInvalidKey - } - - keyBytes := curveBits / 8 - if curveBits%8 > 0 { - keyBytes += 1 - } - - // We serialize the outputs (r and s) into big-endian byte arrays - // padded with zeros on the left to make sure the sizes work out. - // Output must be 2*keyBytes long. - out := make([]byte, 2*keyBytes) - r.FillBytes(out[0:keyBytes]) // r is assigned to the first half of output. - s.FillBytes(out[keyBytes:]) // s is assigned to the second half of output. - - return EncodeSegment(out), nil - } else { - return "", err - } -} diff --git a/vendor/github.com/golang-jwt/jwt/ecdsa_utils.go b/vendor/github.com/golang-jwt/jwt/ecdsa_utils.go deleted file mode 100644 index db9f4be7d8e..00000000000 --- a/vendor/github.com/golang-jwt/jwt/ecdsa_utils.go +++ /dev/null @@ -1,69 +0,0 @@ -package jwt - -import ( - "crypto/ecdsa" - "crypto/x509" - "encoding/pem" - "errors" -) - -var ( - ErrNotECPublicKey = errors.New("Key is not a valid ECDSA public key") - ErrNotECPrivateKey = errors.New("Key is not a valid ECDSA private key") -) - -// Parse PEM encoded Elliptic Curve Private Key Structure -func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParseECPrivateKey(block.Bytes); err != nil { - if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil { - return nil, err - } - } - - var pkey *ecdsa.PrivateKey - var ok bool - if pkey, ok = parsedKey.(*ecdsa.PrivateKey); !ok { - return nil, ErrNotECPrivateKey - } - - return pkey, nil -} - -// Parse PEM encoded PKCS1 or PKCS8 public key -func ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil { - if cert, err := x509.ParseCertificate(block.Bytes); err == nil { - parsedKey = cert.PublicKey - } else { - return nil, err - } - } - - var pkey *ecdsa.PublicKey - var ok bool - if pkey, ok = parsedKey.(*ecdsa.PublicKey); !ok { - return nil, ErrNotECPublicKey - } - - return pkey, nil -} diff --git a/vendor/github.com/golang-jwt/jwt/ed25519.go b/vendor/github.com/golang-jwt/jwt/ed25519.go deleted file mode 100644 index a2f8ddbe9bb..00000000000 --- a/vendor/github.com/golang-jwt/jwt/ed25519.go +++ /dev/null @@ -1,81 +0,0 @@ -package jwt - -import ( - "errors" - - "crypto/ed25519" -) - -var ( - ErrEd25519Verification = errors.New("ed25519: verification error") -) - -// Implements the EdDSA family -// Expects ed25519.PrivateKey for signing and ed25519.PublicKey for verification -type SigningMethodEd25519 struct{} - -// Specific instance for EdDSA -var ( - SigningMethodEdDSA *SigningMethodEd25519 -) - -func init() { - SigningMethodEdDSA = &SigningMethodEd25519{} - RegisterSigningMethod(SigningMethodEdDSA.Alg(), func() SigningMethod { - return SigningMethodEdDSA - }) -} - -func (m *SigningMethodEd25519) Alg() string { - return "EdDSA" -} - -// Implements the Verify method from SigningMethod -// For this verify method, key must be an ed25519.PublicKey -func (m *SigningMethodEd25519) Verify(signingString, signature string, key interface{}) error { - var err error - var ed25519Key ed25519.PublicKey - var ok bool - - if ed25519Key, ok = key.(ed25519.PublicKey); !ok { - return ErrInvalidKeyType - } - - if len(ed25519Key) != ed25519.PublicKeySize { - return ErrInvalidKey - } - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - // Verify the signature - if !ed25519.Verify(ed25519Key, []byte(signingString), sig) { - return ErrEd25519Verification - } - - return nil -} - -// Implements the Sign method from SigningMethod -// For this signing method, key must be an ed25519.PrivateKey -func (m *SigningMethodEd25519) Sign(signingString string, key interface{}) (string, error) { - var ed25519Key ed25519.PrivateKey - var ok bool - - if ed25519Key, ok = key.(ed25519.PrivateKey); !ok { - return "", ErrInvalidKeyType - } - - // ed25519.Sign panics if private key not equal to ed25519.PrivateKeySize - // this allows to avoid recover usage - if len(ed25519Key) != ed25519.PrivateKeySize { - return "", ErrInvalidKey - } - - // Sign the string and return the encoded result - sig := ed25519.Sign(ed25519Key, []byte(signingString)) - return EncodeSegment(sig), nil -} diff --git a/vendor/github.com/golang-jwt/jwt/ed25519_utils.go b/vendor/github.com/golang-jwt/jwt/ed25519_utils.go deleted file mode 100644 index c6357275efc..00000000000 --- a/vendor/github.com/golang-jwt/jwt/ed25519_utils.go +++ /dev/null @@ -1,64 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/ed25519" - "crypto/x509" - "encoding/pem" - "errors" -) - -var ( - ErrNotEdPrivateKey = errors.New("Key is not a valid Ed25519 private key") - ErrNotEdPublicKey = errors.New("Key is not a valid Ed25519 public key") -) - -// Parse PEM-encoded Edwards curve private key -func ParseEdPrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil { - return nil, err - } - - var pkey ed25519.PrivateKey - var ok bool - if pkey, ok = parsedKey.(ed25519.PrivateKey); !ok { - return nil, ErrNotEdPrivateKey - } - - return pkey, nil -} - -// Parse PEM-encoded Edwards curve public key -func ParseEdPublicKeyFromPEM(key []byte) (crypto.PublicKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil { - return nil, err - } - - var pkey ed25519.PublicKey - var ok bool - if pkey, ok = parsedKey.(ed25519.PublicKey); !ok { - return nil, ErrNotEdPublicKey - } - - return pkey, nil -} diff --git a/vendor/github.com/golang-jwt/jwt/errors.go b/vendor/github.com/golang-jwt/jwt/errors.go deleted file mode 100644 index 1c93024aad2..00000000000 --- a/vendor/github.com/golang-jwt/jwt/errors.go +++ /dev/null @@ -1,59 +0,0 @@ -package jwt - -import ( - "errors" -) - -// Error constants -var ( - ErrInvalidKey = errors.New("key is invalid") - ErrInvalidKeyType = errors.New("key is of invalid type") - ErrHashUnavailable = errors.New("the requested hash function is unavailable") -) - -// The errors that might occur when parsing and validating a token -const ( - ValidationErrorMalformed uint32 = 1 << iota // Token is malformed - ValidationErrorUnverifiable // Token could not be verified because of signing problems - ValidationErrorSignatureInvalid // Signature validation failed - - // Standard Claim validation errors - ValidationErrorAudience // AUD validation failed - ValidationErrorExpired // EXP validation failed - ValidationErrorIssuedAt // IAT validation failed - ValidationErrorIssuer // ISS validation failed - ValidationErrorNotValidYet // NBF validation failed - ValidationErrorId // JTI validation failed - ValidationErrorClaimsInvalid // Generic claims validation error -) - -// Helper for constructing a ValidationError with a string error message -func NewValidationError(errorText string, errorFlags uint32) *ValidationError { - return &ValidationError{ - text: errorText, - Errors: errorFlags, - } -} - -// The error from Parse if token is not valid -type ValidationError struct { - Inner error // stores the error returned by external dependencies, i.e.: KeyFunc - Errors uint32 // bitfield. see ValidationError... constants - text string // errors that do not have a valid error just have text -} - -// Validation error is an error type -func (e ValidationError) Error() string { - if e.Inner != nil { - return e.Inner.Error() - } else if e.text != "" { - return e.text - } else { - return "token is invalid" - } -} - -// No errors -func (e *ValidationError) valid() bool { - return e.Errors == 0 -} diff --git a/vendor/github.com/golang-jwt/jwt/hmac.go b/vendor/github.com/golang-jwt/jwt/hmac.go deleted file mode 100644 index addbe5d4018..00000000000 --- a/vendor/github.com/golang-jwt/jwt/hmac.go +++ /dev/null @@ -1,95 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/hmac" - "errors" -) - -// Implements the HMAC-SHA family of signing methods signing methods -// Expects key type of []byte for both signing and validation -type SigningMethodHMAC struct { - Name string - Hash crypto.Hash -} - -// Specific instances for HS256 and company -var ( - SigningMethodHS256 *SigningMethodHMAC - SigningMethodHS384 *SigningMethodHMAC - SigningMethodHS512 *SigningMethodHMAC - ErrSignatureInvalid = errors.New("signature is invalid") -) - -func init() { - // HS256 - SigningMethodHS256 = &SigningMethodHMAC{"HS256", crypto.SHA256} - RegisterSigningMethod(SigningMethodHS256.Alg(), func() SigningMethod { - return SigningMethodHS256 - }) - - // HS384 - SigningMethodHS384 = &SigningMethodHMAC{"HS384", crypto.SHA384} - RegisterSigningMethod(SigningMethodHS384.Alg(), func() SigningMethod { - return SigningMethodHS384 - }) - - // HS512 - SigningMethodHS512 = &SigningMethodHMAC{"HS512", crypto.SHA512} - RegisterSigningMethod(SigningMethodHS512.Alg(), func() SigningMethod { - return SigningMethodHS512 - }) -} - -func (m *SigningMethodHMAC) Alg() string { - return m.Name -} - -// Verify the signature of HSXXX tokens. Returns nil if the signature is valid. -func (m *SigningMethodHMAC) Verify(signingString, signature string, key interface{}) error { - // Verify the key is the right type - keyBytes, ok := key.([]byte) - if !ok { - return ErrInvalidKeyType - } - - // Decode signature, for comparison - sig, err := DecodeSegment(signature) - if err != nil { - return err - } - - // Can we use the specified hashing method? - if !m.Hash.Available() { - return ErrHashUnavailable - } - - // This signing method is symmetric, so we validate the signature - // by reproducing the signature from the signing string and key, then - // comparing that against the provided signature. - hasher := hmac.New(m.Hash.New, keyBytes) - hasher.Write([]byte(signingString)) - if !hmac.Equal(sig, hasher.Sum(nil)) { - return ErrSignatureInvalid - } - - // No validation errors. Signature is good. - return nil -} - -// Implements the Sign method from SigningMethod for this signing method. -// Key must be []byte -func (m *SigningMethodHMAC) Sign(signingString string, key interface{}) (string, error) { - if keyBytes, ok := key.([]byte); ok { - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := hmac.New(m.Hash.New, keyBytes) - hasher.Write([]byte(signingString)) - - return EncodeSegment(hasher.Sum(nil)), nil - } - - return "", ErrInvalidKeyType -} diff --git a/vendor/github.com/golang-jwt/jwt/map_claims.go b/vendor/github.com/golang-jwt/jwt/map_claims.go deleted file mode 100644 index 72c79f92e55..00000000000 --- a/vendor/github.com/golang-jwt/jwt/map_claims.go +++ /dev/null @@ -1,120 +0,0 @@ -package jwt - -import ( - "encoding/json" - "errors" - // "fmt" -) - -// Claims type that uses the map[string]interface{} for JSON decoding -// This is the default claims type if you don't supply one -type MapClaims map[string]interface{} - -// VerifyAudience Compares the aud claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyAudience(cmp string, req bool) bool { - var aud []string - switch v := m["aud"].(type) { - case string: - aud = append(aud, v) - case []string: - aud = v - case []interface{}: - for _, a := range v { - vs, ok := a.(string) - if !ok { - return false - } - aud = append(aud, vs) - } - } - return verifyAud(aud, cmp, req) -} - -// Compares the exp claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool { - exp, ok := m["exp"] - if !ok { - return !req - } - switch expType := exp.(type) { - case float64: - return verifyExp(int64(expType), cmp, req) - case json.Number: - v, _ := expType.Int64() - return verifyExp(v, cmp, req) - } - return false -} - -// Compares the iat claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool { - iat, ok := m["iat"] - if !ok { - return !req - } - switch iatType := iat.(type) { - case float64: - return verifyIat(int64(iatType), cmp, req) - case json.Number: - v, _ := iatType.Int64() - return verifyIat(v, cmp, req) - } - return false -} - -// Compares the iss claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyIssuer(cmp string, req bool) bool { - iss, _ := m["iss"].(string) - return verifyIss(iss, cmp, req) -} - -// Compares the nbf claim against cmp. -// If required is false, this method will return true if the value matches or is unset -func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool { - nbf, ok := m["nbf"] - if !ok { - return !req - } - switch nbfType := nbf.(type) { - case float64: - return verifyNbf(int64(nbfType), cmp, req) - case json.Number: - v, _ := nbfType.Int64() - return verifyNbf(v, cmp, req) - } - return false -} - -// Validates time based claims "exp, iat, nbf". -// There is no accounting for clock skew. -// As well, if any of the above claims are not in the token, it will still -// be considered a valid claim. -func (m MapClaims) Valid() error { - vErr := new(ValidationError) - now := TimeFunc().Unix() - - if !m.VerifyExpiresAt(now, false) { - vErr.Inner = errors.New("Token is expired") - vErr.Errors |= ValidationErrorExpired - } - - if !m.VerifyIssuedAt(now, false) { - vErr.Inner = errors.New("Token used before issued") - vErr.Errors |= ValidationErrorIssuedAt - } - - if !m.VerifyNotBefore(now, false) { - vErr.Inner = errors.New("Token is not valid yet") - vErr.Errors |= ValidationErrorNotValidYet - } - - if vErr.valid() { - return nil - } - - return vErr -} diff --git a/vendor/github.com/golang-jwt/jwt/none.go b/vendor/github.com/golang-jwt/jwt/none.go deleted file mode 100644 index f04d189d067..00000000000 --- a/vendor/github.com/golang-jwt/jwt/none.go +++ /dev/null @@ -1,52 +0,0 @@ -package jwt - -// Implements the none signing method. This is required by the spec -// but you probably should never use it. -var SigningMethodNone *signingMethodNone - -const UnsafeAllowNoneSignatureType unsafeNoneMagicConstant = "none signing method allowed" - -var NoneSignatureTypeDisallowedError error - -type signingMethodNone struct{} -type unsafeNoneMagicConstant string - -func init() { - SigningMethodNone = &signingMethodNone{} - NoneSignatureTypeDisallowedError = NewValidationError("'none' signature type is not allowed", ValidationErrorSignatureInvalid) - - RegisterSigningMethod(SigningMethodNone.Alg(), func() SigningMethod { - return SigningMethodNone - }) -} - -func (m *signingMethodNone) Alg() string { - return "none" -} - -// Only allow 'none' alg type if UnsafeAllowNoneSignatureType is specified as the key -func (m *signingMethodNone) Verify(signingString, signature string, key interface{}) (err error) { - // Key must be UnsafeAllowNoneSignatureType to prevent accidentally - // accepting 'none' signing method - if _, ok := key.(unsafeNoneMagicConstant); !ok { - return NoneSignatureTypeDisallowedError - } - // If signing method is none, signature must be an empty string - if signature != "" { - return NewValidationError( - "'none' signing method with non-empty signature", - ValidationErrorSignatureInvalid, - ) - } - - // Accept 'none' signing method. - return nil -} - -// Only allow 'none' signing if UnsafeAllowNoneSignatureType is specified as the key -func (m *signingMethodNone) Sign(signingString string, key interface{}) (string, error) { - if _, ok := key.(unsafeNoneMagicConstant); ok { - return "", nil - } - return "", NoneSignatureTypeDisallowedError -} diff --git a/vendor/github.com/golang-jwt/jwt/parser.go b/vendor/github.com/golang-jwt/jwt/parser.go deleted file mode 100644 index d6901d9adb5..00000000000 --- a/vendor/github.com/golang-jwt/jwt/parser.go +++ /dev/null @@ -1,148 +0,0 @@ -package jwt - -import ( - "bytes" - "encoding/json" - "fmt" - "strings" -) - -type Parser struct { - ValidMethods []string // If populated, only these methods will be considered valid - UseJSONNumber bool // Use JSON Number format in JSON decoder - SkipClaimsValidation bool // Skip claims validation during token parsing -} - -// Parse, validate, and return a token. -// keyFunc will receive the parsed token and should return the key for validating. -// If everything is kosher, err will be nil -func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { - return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc) -} - -func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) { - token, parts, err := p.ParseUnverified(tokenString, claims) - if err != nil { - return token, err - } - - // Verify signing method is in the required set - if p.ValidMethods != nil { - var signingMethodValid = false - var alg = token.Method.Alg() - for _, m := range p.ValidMethods { - if m == alg { - signingMethodValid = true - break - } - } - if !signingMethodValid { - // signing method is not in the listed set - return token, NewValidationError(fmt.Sprintf("signing method %v is invalid", alg), ValidationErrorSignatureInvalid) - } - } - - // Lookup key - var key interface{} - if keyFunc == nil { - // keyFunc was not provided. short circuiting validation - return token, NewValidationError("no Keyfunc was provided.", ValidationErrorUnverifiable) - } - if key, err = keyFunc(token); err != nil { - // keyFunc returned an error - if ve, ok := err.(*ValidationError); ok { - return token, ve - } - return token, &ValidationError{Inner: err, Errors: ValidationErrorUnverifiable} - } - - vErr := &ValidationError{} - - // Validate Claims - if !p.SkipClaimsValidation { - if err := token.Claims.Valid(); err != nil { - - // If the Claims Valid returned an error, check if it is a validation error, - // If it was another error type, create a ValidationError with a generic ClaimsInvalid flag set - if e, ok := err.(*ValidationError); !ok { - vErr = &ValidationError{Inner: err, Errors: ValidationErrorClaimsInvalid} - } else { - vErr = e - } - } - } - - // Perform validation - token.Signature = parts[2] - if err = token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil { - vErr.Inner = err - vErr.Errors |= ValidationErrorSignatureInvalid - } - - if vErr.valid() { - token.Valid = true - return token, nil - } - - return token, vErr -} - -// WARNING: Don't use this method unless you know what you're doing -// -// This method parses the token but doesn't validate the signature. It's only -// ever useful in cases where you know the signature is valid (because it has -// been checked previously in the stack) and you want to extract values from -// it. -func (p *Parser) ParseUnverified(tokenString string, claims Claims) (token *Token, parts []string, err error) { - parts = strings.Split(tokenString, ".") - if len(parts) != 3 { - return nil, parts, NewValidationError("token contains an invalid number of segments", ValidationErrorMalformed) - } - - token = &Token{Raw: tokenString} - - // parse Header - var headerBytes []byte - if headerBytes, err = DecodeSegment(parts[0]); err != nil { - if strings.HasPrefix(strings.ToLower(tokenString), "bearer ") { - return token, parts, NewValidationError("tokenstring should not contain 'bearer '", ValidationErrorMalformed) - } - return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - if err = json.Unmarshal(headerBytes, &token.Header); err != nil { - return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - - // parse Claims - var claimBytes []byte - token.Claims = claims - - if claimBytes, err = DecodeSegment(parts[1]); err != nil { - return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - dec := json.NewDecoder(bytes.NewBuffer(claimBytes)) - if p.UseJSONNumber { - dec.UseNumber() - } - // JSON Decode. Special case for map type to avoid weird pointer behavior - if c, ok := token.Claims.(MapClaims); ok { - err = dec.Decode(&c) - } else { - err = dec.Decode(&claims) - } - // Handle decode error - if err != nil { - return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed} - } - - // Lookup signature method - if method, ok := token.Header["alg"].(string); ok { - if token.Method = GetSigningMethod(method); token.Method == nil { - return token, parts, NewValidationError("signing method (alg) is unavailable.", ValidationErrorUnverifiable) - } - } else { - return token, parts, NewValidationError("signing method (alg) is unspecified.", ValidationErrorUnverifiable) - } - - return token, parts, nil -} diff --git a/vendor/github.com/golang-jwt/jwt/rsa.go b/vendor/github.com/golang-jwt/jwt/rsa.go deleted file mode 100644 index e4caf1ca4a1..00000000000 --- a/vendor/github.com/golang-jwt/jwt/rsa.go +++ /dev/null @@ -1,101 +0,0 @@ -package jwt - -import ( - "crypto" - "crypto/rand" - "crypto/rsa" -) - -// Implements the RSA family of signing methods signing methods -// Expects *rsa.PrivateKey for signing and *rsa.PublicKey for validation -type SigningMethodRSA struct { - Name string - Hash crypto.Hash -} - -// Specific instances for RS256 and company -var ( - SigningMethodRS256 *SigningMethodRSA - SigningMethodRS384 *SigningMethodRSA - SigningMethodRS512 *SigningMethodRSA -) - -func init() { - // RS256 - SigningMethodRS256 = &SigningMethodRSA{"RS256", crypto.SHA256} - RegisterSigningMethod(SigningMethodRS256.Alg(), func() SigningMethod { - return SigningMethodRS256 - }) - - // RS384 - SigningMethodRS384 = &SigningMethodRSA{"RS384", crypto.SHA384} - RegisterSigningMethod(SigningMethodRS384.Alg(), func() SigningMethod { - return SigningMethodRS384 - }) - - // RS512 - SigningMethodRS512 = &SigningMethodRSA{"RS512", crypto.SHA512} - RegisterSigningMethod(SigningMethodRS512.Alg(), func() SigningMethod { - return SigningMethodRS512 - }) -} - -func (m *SigningMethodRSA) Alg() string { - return m.Name -} - -// Implements the Verify method from SigningMethod -// For this signing method, must be an *rsa.PublicKey structure. -func (m *SigningMethodRSA) Verify(signingString, signature string, key interface{}) error { - var err error - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - var rsaKey *rsa.PublicKey - var ok bool - - if rsaKey, ok = key.(*rsa.PublicKey); !ok { - return ErrInvalidKeyType - } - - // Create hasher - if !m.Hash.Available() { - return ErrHashUnavailable - } - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Verify the signature - return rsa.VerifyPKCS1v15(rsaKey, m.Hash, hasher.Sum(nil), sig) -} - -// Implements the Sign method from SigningMethod -// For this signing method, must be an *rsa.PrivateKey structure. -func (m *SigningMethodRSA) Sign(signingString string, key interface{}) (string, error) { - var rsaKey *rsa.PrivateKey - var ok bool - - // Validate type of key - if rsaKey, ok = key.(*rsa.PrivateKey); !ok { - return "", ErrInvalidKey - } - - // Create the hasher - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Sign the string and return the encoded bytes - if sigBytes, err := rsa.SignPKCS1v15(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil)); err == nil { - return EncodeSegment(sigBytes), nil - } else { - return "", err - } -} diff --git a/vendor/github.com/golang-jwt/jwt/rsa_pss.go b/vendor/github.com/golang-jwt/jwt/rsa_pss.go deleted file mode 100644 index c0147086480..00000000000 --- a/vendor/github.com/golang-jwt/jwt/rsa_pss.go +++ /dev/null @@ -1,142 +0,0 @@ -// +build go1.4 - -package jwt - -import ( - "crypto" - "crypto/rand" - "crypto/rsa" -) - -// Implements the RSAPSS family of signing methods signing methods -type SigningMethodRSAPSS struct { - *SigningMethodRSA - Options *rsa.PSSOptions - // VerifyOptions is optional. If set overrides Options for rsa.VerifyPPS. - // Used to accept tokens signed with rsa.PSSSaltLengthAuto, what doesn't follow - // https://tools.ietf.org/html/rfc7518#section-3.5 but was used previously. - // See https://github.com/dgrijalva/jwt-go/issues/285#issuecomment-437451244 for details. - VerifyOptions *rsa.PSSOptions -} - -// Specific instances for RS/PS and company. -var ( - SigningMethodPS256 *SigningMethodRSAPSS - SigningMethodPS384 *SigningMethodRSAPSS - SigningMethodPS512 *SigningMethodRSAPSS -) - -func init() { - // PS256 - SigningMethodPS256 = &SigningMethodRSAPSS{ - SigningMethodRSA: &SigningMethodRSA{ - Name: "PS256", - Hash: crypto.SHA256, - }, - Options: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthEqualsHash, - }, - VerifyOptions: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthAuto, - }, - } - RegisterSigningMethod(SigningMethodPS256.Alg(), func() SigningMethod { - return SigningMethodPS256 - }) - - // PS384 - SigningMethodPS384 = &SigningMethodRSAPSS{ - SigningMethodRSA: &SigningMethodRSA{ - Name: "PS384", - Hash: crypto.SHA384, - }, - Options: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthEqualsHash, - }, - VerifyOptions: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthAuto, - }, - } - RegisterSigningMethod(SigningMethodPS384.Alg(), func() SigningMethod { - return SigningMethodPS384 - }) - - // PS512 - SigningMethodPS512 = &SigningMethodRSAPSS{ - SigningMethodRSA: &SigningMethodRSA{ - Name: "PS512", - Hash: crypto.SHA512, - }, - Options: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthEqualsHash, - }, - VerifyOptions: &rsa.PSSOptions{ - SaltLength: rsa.PSSSaltLengthAuto, - }, - } - RegisterSigningMethod(SigningMethodPS512.Alg(), func() SigningMethod { - return SigningMethodPS512 - }) -} - -// Implements the Verify method from SigningMethod -// For this verify method, key must be an rsa.PublicKey struct -func (m *SigningMethodRSAPSS) Verify(signingString, signature string, key interface{}) error { - var err error - - // Decode the signature - var sig []byte - if sig, err = DecodeSegment(signature); err != nil { - return err - } - - var rsaKey *rsa.PublicKey - switch k := key.(type) { - case *rsa.PublicKey: - rsaKey = k - default: - return ErrInvalidKey - } - - // Create hasher - if !m.Hash.Available() { - return ErrHashUnavailable - } - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - opts := m.Options - if m.VerifyOptions != nil { - opts = m.VerifyOptions - } - - return rsa.VerifyPSS(rsaKey, m.Hash, hasher.Sum(nil), sig, opts) -} - -// Implements the Sign method from SigningMethod -// For this signing method, key must be an rsa.PrivateKey struct -func (m *SigningMethodRSAPSS) Sign(signingString string, key interface{}) (string, error) { - var rsaKey *rsa.PrivateKey - - switch k := key.(type) { - case *rsa.PrivateKey: - rsaKey = k - default: - return "", ErrInvalidKeyType - } - - // Create the hasher - if !m.Hash.Available() { - return "", ErrHashUnavailable - } - - hasher := m.Hash.New() - hasher.Write([]byte(signingString)) - - // Sign the string and return the encoded bytes - if sigBytes, err := rsa.SignPSS(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil), m.Options); err == nil { - return EncodeSegment(sigBytes), nil - } else { - return "", err - } -} diff --git a/vendor/github.com/golang-jwt/jwt/rsa_utils.go b/vendor/github.com/golang-jwt/jwt/rsa_utils.go deleted file mode 100644 index 14c78c292a9..00000000000 --- a/vendor/github.com/golang-jwt/jwt/rsa_utils.go +++ /dev/null @@ -1,101 +0,0 @@ -package jwt - -import ( - "crypto/rsa" - "crypto/x509" - "encoding/pem" - "errors" -) - -var ( - ErrKeyMustBePEMEncoded = errors.New("Invalid Key: Key must be a PEM encoded PKCS1 or PKCS8 key") - ErrNotRSAPrivateKey = errors.New("Key is not a valid RSA private key") - ErrNotRSAPublicKey = errors.New("Key is not a valid RSA public key") -) - -// Parse PEM encoded PKCS1 or PKCS8 private key -func ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - var parsedKey interface{} - if parsedKey, err = x509.ParsePKCS1PrivateKey(block.Bytes); err != nil { - if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil { - return nil, err - } - } - - var pkey *rsa.PrivateKey - var ok bool - if pkey, ok = parsedKey.(*rsa.PrivateKey); !ok { - return nil, ErrNotRSAPrivateKey - } - - return pkey, nil -} - -// Parse PEM encoded PKCS1 or PKCS8 private key protected with password -func ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - var parsedKey interface{} - - var blockDecrypted []byte - if blockDecrypted, err = x509.DecryptPEMBlock(block, []byte(password)); err != nil { - return nil, err - } - - if parsedKey, err = x509.ParsePKCS1PrivateKey(blockDecrypted); err != nil { - if parsedKey, err = x509.ParsePKCS8PrivateKey(blockDecrypted); err != nil { - return nil, err - } - } - - var pkey *rsa.PrivateKey - var ok bool - if pkey, ok = parsedKey.(*rsa.PrivateKey); !ok { - return nil, ErrNotRSAPrivateKey - } - - return pkey, nil -} - -// Parse PEM encoded PKCS1 or PKCS8 public key -func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error) { - var err error - - // Parse PEM block - var block *pem.Block - if block, _ = pem.Decode(key); block == nil { - return nil, ErrKeyMustBePEMEncoded - } - - // Parse the key - var parsedKey interface{} - if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil { - if cert, err := x509.ParseCertificate(block.Bytes); err == nil { - parsedKey = cert.PublicKey - } else { - return nil, err - } - } - - var pkey *rsa.PublicKey - var ok bool - if pkey, ok = parsedKey.(*rsa.PublicKey); !ok { - return nil, ErrNotRSAPublicKey - } - - return pkey, nil -} diff --git a/vendor/github.com/golang-jwt/jwt/signing_method.go b/vendor/github.com/golang-jwt/jwt/signing_method.go deleted file mode 100644 index ed1f212b21e..00000000000 --- a/vendor/github.com/golang-jwt/jwt/signing_method.go +++ /dev/null @@ -1,35 +0,0 @@ -package jwt - -import ( - "sync" -) - -var signingMethods = map[string]func() SigningMethod{} -var signingMethodLock = new(sync.RWMutex) - -// Implement SigningMethod to add new methods for signing or verifying tokens. -type SigningMethod interface { - Verify(signingString, signature string, key interface{}) error // Returns nil if signature is valid - Sign(signingString string, key interface{}) (string, error) // Returns encoded signature or error - Alg() string // returns the alg identifier for this method (example: 'HS256') -} - -// Register the "alg" name and a factory function for signing method. -// This is typically done during init() in the method's implementation -func RegisterSigningMethod(alg string, f func() SigningMethod) { - signingMethodLock.Lock() - defer signingMethodLock.Unlock() - - signingMethods[alg] = f -} - -// Get a signing method from an "alg" string -func GetSigningMethod(alg string) (method SigningMethod) { - signingMethodLock.RLock() - defer signingMethodLock.RUnlock() - - if methodF, ok := signingMethods[alg]; ok { - method = methodF() - } - return -} diff --git a/vendor/github.com/golang-jwt/jwt/token.go b/vendor/github.com/golang-jwt/jwt/token.go deleted file mode 100644 index 6b30ced1200..00000000000 --- a/vendor/github.com/golang-jwt/jwt/token.go +++ /dev/null @@ -1,104 +0,0 @@ -package jwt - -import ( - "encoding/base64" - "encoding/json" - "strings" - "time" -) - -// TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time). -// You can override it to use another time value. This is useful for testing or if your -// server uses a different time zone than your tokens. -var TimeFunc = time.Now - -// Parse methods use this callback function to supply -// the key for verification. The function receives the parsed, -// but unverified Token. This allows you to use properties in the -// Header of the token (such as `kid`) to identify which key to use. -type Keyfunc func(*Token) (interface{}, error) - -// A JWT Token. Different fields will be used depending on whether you're -// creating or parsing/verifying a token. -type Token struct { - Raw string // The raw token. Populated when you Parse a token - Method SigningMethod // The signing method used or to be used - Header map[string]interface{} // The first segment of the token - Claims Claims // The second segment of the token - Signature string // The third segment of the token. Populated when you Parse a token - Valid bool // Is the token valid? Populated when you Parse/Verify a token -} - -// Create a new Token. Takes a signing method -func New(method SigningMethod) *Token { - return NewWithClaims(method, MapClaims{}) -} - -func NewWithClaims(method SigningMethod, claims Claims) *Token { - return &Token{ - Header: map[string]interface{}{ - "typ": "JWT", - "alg": method.Alg(), - }, - Claims: claims, - Method: method, - } -} - -// Get the complete, signed token -func (t *Token) SignedString(key interface{}) (string, error) { - var sig, sstr string - var err error - if sstr, err = t.SigningString(); err != nil { - return "", err - } - if sig, err = t.Method.Sign(sstr, key); err != nil { - return "", err - } - return strings.Join([]string{sstr, sig}, "."), nil -} - -// Generate the signing string. This is the -// most expensive part of the whole deal. Unless you -// need this for something special, just go straight for -// the SignedString. -func (t *Token) SigningString() (string, error) { - var err error - parts := make([]string, 2) - for i := range parts { - var jsonValue []byte - if i == 0 { - if jsonValue, err = json.Marshal(t.Header); err != nil { - return "", err - } - } else { - if jsonValue, err = json.Marshal(t.Claims); err != nil { - return "", err - } - } - - parts[i] = EncodeSegment(jsonValue) - } - return strings.Join(parts, "."), nil -} - -// Parse, validate, and return a token. -// keyFunc will receive the parsed token and should return the key for validating. -// If everything is kosher, err will be nil -func Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { - return new(Parser).Parse(tokenString, keyFunc) -} - -func ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) { - return new(Parser).ParseWithClaims(tokenString, claims, keyFunc) -} - -// Encode JWT specific base64url encoding with padding stripped -func EncodeSegment(seg []byte) string { - return base64.RawURLEncoding.EncodeToString(seg) -} - -// Decode JWT specific base64url encoding with padding stripped -func DecodeSegment(seg string) ([]byte, error) { - return base64.RawURLEncoding.DecodeString(seg) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index d7ec56cd7a7..faf27874ef3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -367,7 +367,7 @@ github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1 github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1 github.com/cs3org/go-cs3apis/cs3/tx/v1beta1 github.com/cs3org/go-cs3apis/cs3/types/v1beta1 -# github.com/cs3org/reva/v2 v2.26.6-0.20241119075849-6f05da66906b +# github.com/cs3org/reva/v2 v2.26.7 ## explicit; go 1.22.0 github.com/cs3org/reva/v2/cmd/revad/internal/grace github.com/cs3org/reva/v2/cmd/revad/runtime @@ -1061,9 +1061,6 @@ github.com/gofrs/uuid github.com/gogo/protobuf/gogoproto github.com/gogo/protobuf/proto github.com/gogo/protobuf/protoc-gen-gogo/descriptor -# github.com/golang-jwt/jwt v3.2.2+incompatible -## explicit -github.com/golang-jwt/jwt # github.com/golang-jwt/jwt/v4 v4.5.1 ## explicit; go 1.16 github.com/golang-jwt/jwt/v4