π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add logic to decrypt file metadata and persist
Neeraj Gupta4294747d36a9
diff --git a/pkg/collections.go b/pkg/collections.goindex 11395bc5a9..4272ed910e 100644--- a/pkg/collections.go+++ b/pkg/collections.go@@ -80,7 +80,11 @@ func (c *ClICtrl) fetchRemoteFiles(ctx context.Context) error {// on first sync, no need to sync delete markerscontinue}- fileJson := encoding.MustMarshalJSON(file)+ photoFile, err := c.mapApiFileToPhotoFile(ctx, album, file)+ if err != nil {+ return err+ }+ fileJson := encoding.MustMarshalJSON(photoFile)putErr := c.PutValue(ctx, model.RemoteFiles, []byte(strconv.FormatInt(file.ID, 10)), fileJson)if putErr != nil {return putErrdiff --git a/pkg/mappers.go b/pkg/mappers.goindex 273c557f7a..cd9b223b4b 100644--- a/pkg/mappers.go+++ b/pkg/mappers.go@@ -4,7 +4,10 @@ import ("cli-go/internal/api"enteCrypto "cli-go/internal/crypto""cli-go/pkg/model"+ "cli-go/utils/encoding""context"+ "encoding/json"+ "errors""log")@@ -59,3 +62,51 @@ func (c *ClICtrl) mapCollectionToAlbum(ctx context.Context, collection api.Colle}return &album, nil}++func (c *ClICtrl) mapApiFileToPhotoFile(ctx context.Context, album model.Album, file api.File) (*model.PhotoFile, error) {+ if file.IsDeleted {+ return nil, errors.New("file is deleted")+ }+ albumKey := album.AlbumKey.MustDecrypt(c.CliKey)+ fileKey, err := enteCrypto.SecretBoxOpen(+ encoding.DecodeBase64(file.EncryptedKey),+ encoding.DecodeBase64(file.KeyDecryptionNonce),+ albumKey)+ if err != nil {+ return nil, err+ }+ var photoFile model.PhotoFile+ photoFile.ID = file.ID+ photoFile.Key = *model.MakeEncString(fileKey, c.CliKey)+ photoFile.FileNonce = file.File.DecryptionHeader+ photoFile.ThumbnailNonce = file.Thumbnail.DecryptionHeader+ photoFile.OwnerID = file.OwnerID+ if file.Info != nil {+ photoFile.PhotoInfo = model.PhotoInfo{+ FileSize: file.Info.FileSize,+ ThumbnailSize: file.Info.ThumbnailSize,+ }+ }+ if file.Metadata.DecryptionHeader != "" {+ _, encodedJsonBytes, err := enteCrypto.DecryptChaChaBase64(file.Metadata.EncryptedData, fileKey, file.Metadata.DecryptionHeader)+ if err != nil {+ return nil, err+ }+ err = json.Unmarshal(encodedJsonBytes, &photoFile.PrivateMetadata)+ if err != nil {+ return nil, err+ }+ }+ if file.MagicMetadata != nil {+ _, encodedJsonBytes, err := enteCrypto.DecryptChaChaBase64(file.MagicMetadata.Data, fileKey, file.MagicMetadata.Header)+ if err != nil {+ return nil, err+ }+ err = json.Unmarshal(encodedJsonBytes, &photoFile.PublicMetadata)+ if err != nil {+ return nil, err+ }+ }+ return &photoFile, nil++}diff --git a/pkg/model/photo_file.go b/pkg/model/photo_file.gonew file mode 100644index 0000000000..467be6a2a5--- /dev/null+++ b/pkg/model/photo_file.go@@ -0,0 +1,18 @@+package model++type PhotoFile struct {+ ID int64 `json:"id"`+ OwnerID int64 `json:"ownerID"`+ Key EncString `json:"key"`+ LastUpdateTime int64 `json:"lastUpdateTime"`+ FileNonce string `json:"fileNonce"`+ ThumbnailNonce string `json:"thumbnailNonce"`+ PrivateMetadata map[string]interface{} `json:"privateMetadata"`+ PublicMetadata map[string]interface{} `json:"publicMetadata"`+ PhotoInfo PhotoInfo ``+}++type PhotoInfo struct {+ FileSize int64 `json:"fileSize,omitempty"`+ ThumbnailSize int64 `json:"thumbSize,omitempty"`+}