Skip to content

Commit

Permalink
[cli] Improve logging for decryption error (#1242)
Browse files Browse the repository at this point in the history
## Description
Related to #1237
## Tests
  • Loading branch information
ua741 authored Mar 29, 2024
1 parent 54d9364 commit bc45db5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cli/internal/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func DecryptChaChaBase64(data string, key []byte, nonce string) (string, []byte,
// Decode data from base64
dataBytes, err := base64.StdEncoding.DecodeString(data)
if err != nil {
return "", nil, fmt.Errorf("invalid data: %v", err)
// safe to log the encrypted data
return "", nil, fmt.Errorf("invalid base64 data %s: %v", data, err)
}
// Decode nonce from base64
nonceBytes, err := base64.StdEncoding.DecodeString(nonce)
Expand Down
2 changes: 1 addition & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"strings"
)

var AppVersion = "0.1.12"
var AppVersion = "0.1.13"

func main() {
cliDBPath, err := GetCLIConfigPath()
Expand Down
17 changes: 9 additions & 8 deletions cli/pkg/mapper/photo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/ente-io/cli/internal/api"
eCrypto "github.com/ente-io/cli/internal/crypto"
"github.com/ente-io/cli/pkg/model"
Expand Down Expand Up @@ -41,7 +42,7 @@ func MapCollectionToAlbum(ctx context.Context, collection api.Collection, holder
if collection.MagicMetadata != nil {
_, encodedJsonBytes, err := eCrypto.DecryptChaChaBase64(collection.MagicMetadata.Data, collectionKey, collection.MagicMetadata.Header)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to decrypt magic metadata for collection %d: %w", collection.ID, err)
}
err = json.Unmarshal(encodedJsonBytes, &album.PrivateMeta)
if err != nil {
Expand All @@ -51,21 +52,21 @@ func MapCollectionToAlbum(ctx context.Context, collection api.Collection, holder
if collection.PublicMagicMetadata != nil {
_, encodedJsonBytes, err := eCrypto.DecryptChaChaBase64(collection.PublicMagicMetadata.Data, collectionKey, collection.PublicMagicMetadata.Header)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to decrypt public magic metadata for collection %d: %w", collection.ID, err)
}
err = json.Unmarshal(encodedJsonBytes, &album.PublicMeta)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to unmarshal public magic metadata for collection %d: %w", collection.ID, err)
}
}
if album.IsShared && collection.SharedMagicMetadata != nil {
_, encodedJsonBytes, err := eCrypto.DecryptChaChaBase64(collection.SharedMagicMetadata.Data, collectionKey, collection.SharedMagicMetadata.Header)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to decrypt shared magic metadata for collection %d: %w", collection.ID, err)
}
err = json.Unmarshal(encodedJsonBytes, &album.SharedMeta)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to unmarshal shared magic metadata for collection %d: %w", collection.ID, err)
}
}
return &album, nil
Expand Down Expand Up @@ -99,7 +100,7 @@ func MapApiFileToPhotoFile(ctx context.Context, album model.RemoteAlbum, file ap
if file.Metadata.DecryptionHeader != "" {
_, encodedJsonBytes, err := eCrypto.DecryptChaChaBase64(file.Metadata.EncryptedData, fileKey, file.Metadata.DecryptionHeader)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to decrypt metadata for file %d: %w", file.ID, err)
}
err = json.Unmarshal(encodedJsonBytes, &photoFile.Metadata)
if err != nil {
Expand All @@ -109,7 +110,7 @@ func MapApiFileToPhotoFile(ctx context.Context, album model.RemoteAlbum, file ap
if file.MagicMetadata != nil {
_, encodedJsonBytes, err := eCrypto.DecryptChaChaBase64(file.MagicMetadata.Data, fileKey, file.MagicMetadata.Header)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to decrypt magic metadata for file %d: %w", file.ID, err)
}
err = json.Unmarshal(encodedJsonBytes, &photoFile.PrivateMetadata)
if err != nil {
Expand All @@ -119,7 +120,7 @@ func MapApiFileToPhotoFile(ctx context.Context, album model.RemoteAlbum, file ap
if file.PubicMagicMetadata != nil {
_, encodedJsonBytes, err := eCrypto.DecryptChaChaBase64(file.PubicMagicMetadata.Data, fileKey, file.PubicMagicMetadata.Header)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to decrypt public magic metadata for file %d: %w", file.ID, err)
}
err = json.Unmarshal(encodedJsonBytes, &photoFile.PublicMetadata)
if err != nil {
Expand Down

0 comments on commit bc45db5

Please sign in to comment.