π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Improve logging to include meta version
Neeraj Gupta170e7340b558
diff --git a/mobile/apps/photos/lib/models/file/file.dart b/mobile/apps/photos/lib/models/file/file.dartindex 971bafdf64..c5c9381494 100644--- a/mobile/apps/photos/lib/models/file/file.dart+++ b/mobile/apps/photos/lib/models/file/file.dart@@ -62,8 +62,9 @@ class EnteFile {// in Version 1, live photo hash is stored as zip's hash.// in V2: LivePhoto hash is stored as imgHash:vidHash- static const kCurrentMetadataVersion = 2;- static const kMetadataSimplifiedEncVersion = 3;+ // in V3: Safeguard for concurrent multipart uploads+ static const kCurrentMetadataVersion = 3;+ static const kMetadataSimplifiedEncVersion = 4;static final _logger = Logger('File');diff --git a/mobile/apps/photos/lib/utils/file_download_util.dart b/mobile/apps/photos/lib/utils/file_download_util.dartindex 3fea091fce..c45dd3e530 100644--- a/mobile/apps/photos/lib/utils/file_download_util.dart+++ b/mobile/apps/photos/lib/utils/file_download_util.dart@@ -81,7 +81,11 @@ Future<File?> downloadAndDecryptPublicFile(_logger.info('$logPrefix file saved at $decryptedFilePath');} catch (e, s) {fakeProgress?.stop();- _logger.severe("Critical: $logPrefix failed to decrypt", e, s);+ _logger.severe(+ "Critical: $logPrefix failed to decrypt v:${file.metadataVersion}, viaMob:${(file.deviceFolder ?? '') != ''}",+ e,+ s,+ );return null;}return File(decryptedFilePath);@@ -184,7 +188,11 @@ Future<File?> downloadAndDecrypt(.info('$logPrefix decryption completed (genID ${file.generatedID})');} catch (e, s) {fakeProgress?.stop();- _logger.severe("Critical: $logPrefix failed to decrypt", e, s);+ _logger.severe(+ "Critical: $logPrefix failed to decrypt v:${file.metadataVersion}, viaMob:${(file.deviceFolder ?? '') != ''}",+ e,+ s,+ );return null;}await encryptedFile.delete();diff --git a/mobile/apps/photos/plugins/ente_crypto/lib/src/crypto.dart b/mobile/apps/photos/plugins/ente_crypto/lib/src/crypto.dartindex d1b62acc6a..2e06cf0b95 100644--- a/mobile/apps/photos/plugins/ente_crypto/lib/src/crypto.dart+++ b/mobile/apps/photos/plugins/ente_crypto/lib/src/crypto.dart@@ -206,32 +206,43 @@ Future<void> chachaDecryptFile(Map<String, dynamic> args) async {logger.info("Decrypting file of size " + sourceFileLength.toString());final inputFile = sourceFile.openSync(mode: FileMode.read);- final pullState = Sodium.cryptoSecretstreamXchacha20poly1305InitPull(- args["header"],- args["key"],- );+ int chunckIndex = 0;+ try {+ final pullState = Sodium.cryptoSecretstreamXchacha20poly1305InitPull(+ args["header"],+ args["key"],+ );- var bytesRead = 0;- var tag = Sodium.cryptoSecretstreamXchacha20poly1305TagMessage;- while (tag != Sodium.cryptoSecretstreamXchacha20poly1305TagFinal) {- var chunkSize = decryptionChunkSize;- if (bytesRead + chunkSize >= sourceFileLength) {- chunkSize = sourceFileLength - bytesRead;+ var bytesRead = 0;+ var tag = Sodium.cryptoSecretstreamXchacha20poly1305TagMessage;+ while (tag != Sodium.cryptoSecretstreamXchacha20poly1305TagFinal) {+ chunckIndex++;+ var chunkSize = decryptionChunkSize;+ if (bytesRead + chunkSize >= sourceFileLength) {+ chunkSize = sourceFileLength - bytesRead;+ }+ final buffer = await inputFile.read(chunkSize);+ bytesRead += chunkSize;+ final pullResult = Sodium.cryptoSecretstreamXchacha20poly1305Pull(+ pullState,+ buffer,+ null,+ );+ await destinationFile.writeAsBytes(pullResult.m, mode: FileMode.append);+ tag = pullResult.tag;}- final buffer = await inputFile.read(chunkSize);- bytesRead += chunkSize;- final pullResult =- Sodium.cryptoSecretstreamXchacha20poly1305Pull(pullState, buffer, null);- await destinationFile.writeAsBytes(pullResult.m, mode: FileMode.append);- tag = pullResult.tag;- }- inputFile.closeSync();+ inputFile.closeSync();- logger.info(- "ChaCha20 Decryption time: " +- (DateTime.now().millisecondsSinceEpoch - decryptionStartTime)- .toString(),- );+ logger.info(+ "ChaCha20 Decryption time: " ++ (DateTime.now().millisecondsSinceEpoch - decryptionStartTime)+ .toString(),+ );+ } catch (e) {+ throw Exception(+ "at chunk $chunckIndex for $sourceFileLength bytes with err $e",+ );+ }}Uint8List chachaDecryptData(Map<String, dynamic> args) {@@ -427,11 +438,13 @@ class CryptoUtil {args["destinationFilePath"] = destinationFilePath;args["header"] = header;args["key"] = key;- return _computer.compute(- chachaDecryptFile,- param: args,- taskName: "decryptFile",- );+ return _computer+ .compute(+ chachaDecryptFile,+ param: args,+ taskName: "decryptFile",+ )+ .catchError((e) => throw CryptoErr("decryptFile", e));}// Generates and returns a 256-bit key.diff --git a/mobile/apps/photos/plugins/ente_crypto/lib/src/models/errors.dart b/mobile/apps/photos/plugins/ente_crypto/lib/src/models/errors.dartindex 3d4a186456..9893b989c8 100644--- a/mobile/apps/photos/plugins/ente_crypto/lib/src/models/errors.dart+++ b/mobile/apps/photos/plugins/ente_crypto/lib/src/models/errors.dart@@ -1,3 +1,18 @@class KeyDerivationError extends Error {}class LoginKeyDerivationError extends Error {}++class CryptoErr implements Exception {+ final String message;+ final dynamic originalException;++ CryptoErr(this.message, [this.originalException]);++ @override+ String toString() {+ if (originalException != null) {+ return 'CryptoErr: $message\nCaused by: $originalException';+ }+ return 'CryptoErr: $message';+ }+}