π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Only check model hash on download
laurenspriem196b98fcc9f9
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_model.dart b/mobile/apps/photos/lib/services/machine_learning/ml_model.dartindex 758d5b7f3a..ec5a0cfe58 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_model.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_model.dart@@ -48,10 +48,7 @@ abstract class MlModel {}Future<String?> downloadModelSafe() async {- if (await RemoteAssetsService.instance.hasAsset(- modelRemotePath,- expectedSha256: modelSha256,- )) {+ if (await RemoteAssetsService.instance.hasAsset(modelRemotePath)) {return await RemoteAssetsService.instance.getAssetPath(modelRemotePath,expectedSha256: modelSha256,diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_model_download_service.dart b/mobile/apps/photos/lib/services/machine_learning/ml_model_download_service.dartindex f130e54aa1..cb0eb93dbf 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_model_download_service.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_model_download_service.dart@@ -36,11 +36,9 @@ class MLModelDownloadService {Future<bool> canLoadClipTextModel() async {final hasModel = await RemoteAssetsService.instance.hasAsset(ClipTextEncoder.instance.modelRemotePath,- expectedSha256: ClipTextEncoder.instance.modelSha256,);final hasVocab = await RemoteAssetsService.instance.hasAsset(ClipTextEncoder.instance.vocabRemotePath,- expectedSha256: ClipTextEncoder.instance.vocabSha256,);if (hasModel && hasVocab) {return true;diff --git a/mobile/apps/photos/lib/services/remote_assets_service.dart b/mobile/apps/photos/lib/services/remote_assets_service.dartindex 6d517ce8b0..fce45d48f5 100644--- a/mobile/apps/photos/lib/services/remote_assets_service.dart+++ b/mobile/apps/photos/lib/services/remote_assets_service.dart@@ -37,14 +37,8 @@ class RemoteAssetsService {final path = await _getLocalPath(remotePath);final file = File(path);if (await file.exists() && !refetch) {- if (await _hasExpectedSha256(file, remotePath, expectedSha256)) {- _logger.info("Returning cached file for $remotePath");- return file;- }- _logger.warning(- "Cached remote asset hash mismatch for $remotePath, redownloading",- );- await _deleteAssetArtifacts(path);+ _logger.info("Returning cached file for $remotePath");+ return file;}final tempFile = File(_tempPath(path));@@ -97,14 +91,6 @@ class RemoteAssetsService {return file;}- final cachedHashMatches =- await _hasExpectedSha256(file, remotePath, expectedSha256);- if (!cachedHashMatches) {- _logger.warning(- "Cached remote asset hash mismatch for $remotePath, refreshing",- );- }-final existingFileSize = await file.length();await _downloadFile(remotePath, tempFile.path);await _validateDownloadedFileSha256(@@ -113,7 +99,7 @@ class RemoteAssetsService {expectedSha256,);final newFileSize = await tempFile.length();- if (!cachedHashMatches || existingFileSize != newFileSize) {+ if (existingFileSize != newFileSize) {await _replaceFile(tempFile, file);await _deleteResumeMetadata(tempFile.path);return file;@@ -130,21 +116,10 @@ class RemoteAssetsService {});}- Future<bool> hasAsset(String remotePath, {String? expectedSha256}) async {+ Future<bool> hasAsset(String remotePath) async {return _lockFor(remotePath).synchronized(() async {final path = await _getLocalPath(remotePath);- final file = File(path);- if (!await file.exists()) {- return false;- }- if (await _hasExpectedSha256(file, remotePath, expectedSha256)) {- return true;- }- _logger.warning(- "Cached remote asset hash mismatch for $remotePath, removing cache",- );- await _deleteAssetArtifacts(path);- return false;+ return File(path).exists();});}@@ -558,23 +533,6 @@ class RemoteAssetsService {}}- Future<bool> _hasExpectedSha256(- File file,- String url,- String? expectedSha256,- ) async {- if (expectedSha256 == null) {- return true;- }- try {- await _validateExpectedSha256(file, url, expectedSha256);- return true;- } catch (e, s) {- _logger.warning("Remote asset hash validation failed for $url", e, s);- return false;- }- }-Future<String> _sha256Hex(File file) async {final digest = await sha256.bind(file.openRead()).first;return digest.toString();