π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refactor
Neeraj Gupta03ad58fe3957
diff --git a/mobile/apps/photos/lib/module/upload/service/multipart.dart b/mobile/apps/photos/lib/module/upload/service/multipart.dartindex 7ca979bf0a..3740072c40 100644--- a/mobile/apps/photos/lib/module/upload/service/multipart.dart+++ b/mobile/apps/photos/lib/module/upload/service/multipart.dart@@ -1,8 +1,5 @@-import "dart:convert";import "dart:io";-import "package:convert/convert.dart";-import "package:crypto/crypto.dart";import "package:dio/dio.dart";import "package:ente_crypto/ente_crypto.dart";import "package:ente_feature_flag/ente_feature_flag.dart";@@ -15,6 +12,7 @@ import "package:photos/module/upload/model/multipart.dart";import "package:photos/module/upload/model/xml.dart";import "package:photos/service_locator.dart";import "package:photos/services/collections_service.dart";+import "package:photos/utils/file_util.dart";class MultiPartUploader {final Dio _enteDio;@@ -303,13 +301,13 @@ class MultiPartUploader {if (e.response?.statusCode == 400 &&e.response?.data.toString().contains('BadDigest') == true ||e.response?.data.toString().contains('InvalidDigest') == true) {- final comput = await computePartMd5(- encryptedFile,- i * partSize,- isLastPart ? null : (i + 1) * partSize,+ final recomputedMD5 = await computeMd5(+ encryptedFile.path,+ start: i * partSize,+ end: isLastPart ? null : (i + 1) * partSize,);throw BadMD5DigestError(- "Failed for part ${i + 1} ${e.response?.data}, sent: ${partMd5s?[i]}, computed: $comput, \n all part MD5s: $partMd5s",+ "Failed for part ${i + 1} ${e.response?.data}, sent: ${partMd5s?[i]}, computed: $recomputedMD5",);}rethrow;@@ -324,14 +322,6 @@ class MultiPartUploader {return etags;}- Future<String> computePartMd5(File file, int start, int? end) async {- final output = AccumulatorSink<Digest>();- final input = md5.startChunkedConversion(output);- await file.openRead(start, end).forEach(input.add);- input.close();- return base64Encode(output.events.single.bytes);- }-Future<void> _completeMultipartUpload(String objectKey,Map<int, String> partEtags,diff --git a/mobile/apps/photos/lib/utils/file_uploader.dart b/mobile/apps/photos/lib/utils/file_uploader.dartindex 797089fd02..6d5f5ebe99 100644--- a/mobile/apps/photos/lib/utils/file_uploader.dart+++ b/mobile/apps/photos/lib/utils/file_uploader.dart@@ -944,7 +944,7 @@ class FileUploader {await FilesDB.instance.updateUploadedFileAcrossCollections(remoteFile);} else {final encryptedFileKeyData = CryptoUtil.encryptSync(- fileAttributes.key!,+ fileAttributes.key,CollectionsService.instance.getCollectionKey(collectionID),);final encryptedKey =@@ -1025,7 +1025,6 @@ class FileUploader {}if ((isMultipartUpload || hasExistingMultiPart) &&isPutOrMultiPartError(e)) {-await UploadLocksDB.instance.deleteMultipartTrack(lockKey);}rethrow;@@ -1616,7 +1615,15 @@ class FileUploader {return uploadURL.objectKey;} on DioException catch (e) {- if (e.message?.startsWith("HttpException: Content size") ?? false) {+ if (e.response?.statusCode == 400 &&+ e.response?.data.toString().contains('BadDigest') == true ||+ e.response?.data.toString().contains('InvalidDigest') == true) {+ final String recomputedMd5 = await computeMd5(file.path);+ throw BadMD5DigestError(+ "Failed ${e.response?.data}, sent: $contentMd5, computed: $recomputedMd5",+ );+ } else if (e.message?.startsWith("HttpException: Content size") ??+ false) {rethrow;} else if (attempt < kMaximumUploadAttempts) {_logger.info(diff --git a/mobile/apps/photos/lib/utils/file_util.dart b/mobile/apps/photos/lib/utils/file_util.dartindex 406ece5233..42b40120aa 100644--- a/mobile/apps/photos/lib/utils/file_util.dart+++ b/mobile/apps/photos/lib/utils/file_util.dart@@ -1,7 +1,9 @@import 'dart:async';+import 'dart:convert';import 'dart:io';import 'package:archive/archive.dart';+import 'package:convert/convert.dart';import "package:crypto/crypto.dart";import "package:dio/dio.dart";import 'package:flutter/foundation.dart';@@ -389,3 +391,19 @@ Future<String> computeSha1(String filePath) async {final hash = await sha1.bind(input).first;return hash.toString();}++/// Computes the MD5 hash of a file or a portion of it.+///+/// [filePath] - Path to the file+/// [start] - Optional starting byte position for partial hash computation+/// [end] - Optional ending byte position for partial hash computation+///+/// Returns base64-encoded MD5 hash suitable for HTTP Content-MD5 header.+Future<String> computeMd5(String filePath, {int? start, int? end}) async {+ final file = File(filePath);+ final output = AccumulatorSink<Digest>();+ final input = md5.startChunkedConversion(output);+ await file.openRead(start, end).forEach(input.add);+ input.close();+ return base64Encode(output.events.single.bytes);+}diff --git a/mobile/apps/photos/plugins/ente_crypto/lib/src/models/chacha_encryption_result.dart b/mobile/apps/photos/plugins/ente_crypto/lib/src/models/chacha_encryption_result.dartdeleted file mode 100644index e69de29bb2..0000000000