Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove base64 encoding of ids #2542

Merged
merged 3 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/remove-base64-encoding-of-ids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Do not encode webDAV ids to base64

We removed the encoding of the IDs and use the format <storageID>!<opaqueID> with a delimiter. The used delimiter is url safe anc belongs to the reserved keys.
butonic marked this conversation as resolved.
Show resolved Hide resolved

https://github.com/cs3org/reva/pull/2542
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocdav/ocdav_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func TestWrapResourceID(t *testing.T) {
expected := "c3RvcmFnZWlkOm9wYXF1ZWlk"
expected := "storageid" + "!" + "opaqueid"
wrapped := resourceid.OwnCloudResourceIDWrap(&providerv1beta1.ResourceId{StorageId: "storageid", OpaqueId: "opaqueid"})

if wrapped != expected {
Expand Down
11 changes: 7 additions & 4 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/xattrs"
"github.com/cs3org/reva/pkg/utils"
"github.com/cs3org/reva/pkg/utils/resourceid"
"github.com/google/uuid"
)

Expand Down Expand Up @@ -417,10 +418,12 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up
hasDescription = true
}
if image, ok := space.Opaque.Map["image"]; ok {
metadata[xattrs.SpaceImageAttr] = string(image.Value)
imageID := resourceid.OwnCloudResourceIDUnwrap(string(image.Value))
metadata[xattrs.SpaceImageAttr] = imageID.OpaqueId
}
if readme, ok := space.Opaque.Map["readme"]; ok {
metadata[xattrs.SpaceReadmeAttr] = string(readme.Value)
readmeID := resourceid.OwnCloudResourceIDUnwrap(string(readme.Value))
metadata[xattrs.SpaceReadmeAttr] = readmeID.OpaqueId
}
}

Expand Down Expand Up @@ -716,7 +719,7 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
if ok {
space.Opaque.Map["image"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(spaceImage),
Value: []byte(resourceid.OwnCloudResourceIDWrap(&provider.ResourceId{StorageId: space.Root.StorageId, OpaqueId: spaceImage})),
}
}
spaceDescription, ok := spaceAttributes[xattrs.SpaceDescriptionAttr]
Expand All @@ -730,7 +733,7 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
if ok {
space.Opaque.Map["readme"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(spaceReadme),
Value: []byte(resourceid.OwnCloudResourceIDWrap(&provider.ResourceId{StorageId: space.Root.StorageId, OpaqueId: spaceReadme})),
}
}
return space, nil
Expand Down
19 changes: 6 additions & 13 deletions pkg/utils/resourceid/owncloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package resourceid

import (
"encoding/base64"
"errors"
"strings"
"unicode/utf8"
Expand All @@ -28,7 +27,7 @@ import (
)

const (
idDelimiter string = ":"
idDelimiter string = "!"
)

// OwnCloudResourceIDUnwrap returns the wrapped resource id
Expand All @@ -42,12 +41,7 @@ func OwnCloudResourceIDUnwrap(rid string) *provider.ResourceId {
}

func unwrap(rid string) (*provider.ResourceId, error) {
decodedID, err := base64.URLEncoding.DecodeString(rid)
if err != nil {
return nil, err
}

parts := strings.SplitN(string(decodedID), idDelimiter, 2)
parts := strings.SplitN(rid, idDelimiter, 2)
if len(parts) != 2 {
return nil, errors.New("could not find two parts with given delimiter")
}
Expand All @@ -68,10 +62,9 @@ func OwnCloudResourceIDWrap(r *provider.ResourceId) string {
return wrap(r.StorageId, r.OpaqueId)
}

// The fileID must be encoded
// - XML safe, because it is going to be used in the propfind result
// - url safe, because the id might be used in a url, eg. the /dav/meta nodes
// which is why we base64 encode it
// The storageID and OpaqueID need to be separated by a delimiter
// this delimiter should be Url safe
// we use a reserved character
func wrap(sid string, oid string) string {
return base64.URLEncoding.EncodeToString([]byte(sid + idDelimiter + oid))
return sid + idDelimiter + oid
}
8 changes: 4 additions & 4 deletions pkg/utils/resourceid/owncloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func BenchmarkWrap(b *testing.B) {
}

func TestWrap(t *testing.T) {
expected := "c3RvcmFnZWlkOm9wYXF1ZWlk"
expected := "storageid" + idDelimiter + "opaqueid"
wrapped := wrap("storageid", "opaqueid")

if wrapped != expected {
Expand All @@ -40,7 +40,7 @@ func TestWrap(t *testing.T) {
}

func TestWrapResourceID(t *testing.T) {
expected := "c3RvcmFnZWlkOm9wYXF1ZWlk"
expected := "storageid" + idDelimiter + "opaqueid"
wrapped := OwnCloudResourceIDWrap(&providerv1beta1.ResourceId{StorageId: "storageid", OpaqueId: "opaqueid"})

if wrapped != expected {
Expand All @@ -50,7 +50,7 @@ func TestWrapResourceID(t *testing.T) {

func BenchmarkUnwrap(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _ = unwrap("c3RvcmFnZWlkOm9wYXF1ZWlk")
_, _ = unwrap("storageid" + idDelimiter + "opaqueid")
}
}

Expand All @@ -60,7 +60,7 @@ func TestUnwrap(t *testing.T) {
expected *providerv1beta1.ResourceId
}{
{
"c3RvcmFnZWlkOm9wYXF1ZWlk",
"storageid" + idDelimiter + "opaqueid",
&providerv1beta1.ResourceId{StorageId: "storageid", OpaqueId: "opaqueid"},
},
{
Expand Down