Report decryption failures to Sentry (#1308)

This commit is contained in:
Vishnu Mohandas 2023-08-11 12:00:13 +05:30 committed by GitHub
commit a43f7d2bbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 13 deletions

View file

@ -51,16 +51,20 @@ Future<io.File?> downloadAndDecrypt(
final decryptedFilePath = Configuration.instance.getTempDirectory() +
file.generatedID.toString() +
".decrypted";
final decryptedFile = io.File(decryptedFilePath);
await CryptoUtil.decryptFile(
encryptedFilePath,
decryptedFilePath,
CryptoUtil.base642bin(file.fileDecryptionHeader!),
getFileKey(file),
);
try {
await CryptoUtil.decryptFile(
encryptedFilePath,
decryptedFilePath,
CryptoUtil.base642bin(file.fileDecryptionHeader!),
getFileKey(file),
);
} catch (e, s) {
_logger.severe("Failed to decrypt file", e, s);
return null;
}
_logger.info("File decrypted: " + file.uploadedFileID.toString());
await encryptedFile.delete();
return decryptedFile;
return io.File(decryptedFilePath);
});
}

View file

@ -158,11 +158,18 @@ Future<void> _downloadAndDecryptThumbnail(FileDownloadItem item) async {
return;
}
final thumbnailDecryptionKey = await getFileKeyUsingBgWorker(file);
var data = await CryptoUtil.decryptChaCha(
encryptedThumbnail,
thumbnailDecryptionKey,
CryptoUtil.base642bin(file.thumbnailDecryptionHeader!),
);
Uint8List data;
try {
data = await CryptoUtil.decryptChaCha(
encryptedThumbnail,
thumbnailDecryptionKey,
CryptoUtil.base642bin(file.thumbnailDecryptionHeader!),
);
} catch (e, s) {
_logger.severe("Failed to decrypt thumbnail", e, s);
item.completer.completeError(e);
return;
}
final thumbnailSize = data.length;
if (thumbnailSize > thumbnailDataLimit) {
data = await compressThumbnail(data);