Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

FIx: Return sharee-specific collection key

Neeraj Gupta3cd416d29343
diff --git a/server/pkg/controller/collections/collection.go b/server/pkg/controller/collections/collection.go
index 1f824fd721..fd81c38fbf 100644
--- a/server/pkg/controller/collections/collection.go
+++ b/server/pkg/controller/collections/collection.go
@@ -81,15 +81,14 @@ func (c *CollectionController) GetCollection(ctx *gin.Context, userID int64, cID
if err != nil {
return ente.Collection{}, stacktrace.Propagate(err, "")
}
- collection, err := c.CollectionRepo.GetWithSharingDetails(cID)
+ collection, err := c.CollectionRepo.GetWithSharingDetailsForUser(cID, userID)
if err != nil {
- role := ente.UNKNOWN
- if resp.Role != nil {
- role = *resp.Role
- }
- collection.PublicURLs = ente.FilterPublicURLsForRole(collection.PublicURLs, role)
+ return ente.Collection{}, stacktrace.Propagate(err, "")
}
- return collection, err
+ if resp.Role != nil && *resp.Role != ente.OWNER {
+ collection.PublicURLs = ente.FilterPublicURLsForRole(collection.PublicURLs, *resp.Role)
+ }
+ return collection, nil
}
func (c *CollectionController) GetFile(ctx *gin.Context, collectionID int64, fileID int64) (*ente.File, error) {
diff --git a/server/pkg/repo/collection.go b/server/pkg/repo/collection.go
index 2982a604d7..efbdaa9136 100644
--- a/server/pkg/repo/collection.go
+++ b/server/pkg/repo/collection.go
@@ -89,8 +89,9 @@ func (repo *CollectionRepository) Get(collectionID int64) (ente.Collection, erro
return c, nil
}
-// GetWithSharingDetails returns the collection along with sharees, active public URLs, and decrypted owner email.
-func (repo *CollectionRepository) GetWithSharingDetails(collectionID int64) (ente.Collection, error) {
+// GetWithSharingDetailsForUser returns the collection along with sharees, active public URLs,
+// and decrypted owner email. If the actor is a sharee, the encrypted key sealed for that actor is returned.
+func (repo *CollectionRepository) GetWithSharingDetailsForUser(collectionID int64, actorUserID int64) (ente.Collection, error) {
c, err := repo.Get(collectionID)
if err != nil {
return c, stacktrace.Propagate(err, "")
@@ -117,6 +118,18 @@ func (repo *CollectionRepository) GetWithSharingDetails(collectionID int64) (ent
}
c.Owner.Email = email
}
+ if actorUserID != c.Owner.ID {
+ var encryptedKey sql.NullString
+ err := repo.DB.QueryRow(`SELECT encrypted_key FROM collection_shares WHERE collection_id = $1 AND to_user_id = $2 AND is_deleted = $3`,
+ collectionID, actorUserID, false).Scan(&encryptedKey)
+ if err != nil {
+ return ente.Collection{}, stacktrace.Propagate(err, "failed to fetch sharee encrypted key")
+ }
+ if !encryptedKey.Valid {
+ return ente.Collection{}, stacktrace.Propagate(fmt.Errorf("share key missing for user %d collection %d", actorUserID, collectionID), "")
+ }
+ c.EncryptedKey = encryptedKey.String
+ }
return c, nil
}
func (repo *CollectionRepository) GetCollectionByType(userID int64, collectionType string) (ente.Collection, error) {