diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/security/SecurityUtils.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/security/SecurityUtils.kt index 8426396e37..7e8b453821 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/security/SecurityUtils.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/security/SecurityUtils.kt @@ -13,6 +13,7 @@ import com.flowcrypt.email.database.FlowCryptRoomDatabase import com.flowcrypt.email.database.entity.AccountEntity import com.flowcrypt.email.extensions.org.bouncycastle.openpgp.toPgpKeyDetails import com.flowcrypt.email.security.model.PgpKeyDetails +import com.flowcrypt.email.security.pgp.PgpDecrypt import com.flowcrypt.email.security.pgp.PgpKey import com.flowcrypt.email.security.pgp.PgpPwd import com.flowcrypt.email.util.exception.DifferentPassPhrasesException @@ -161,5 +162,13 @@ class SecurityUtils { fun generateRandomUUID(): String { return String(Hex.encodeHex(DigestUtils.sha1(UUID.randomUUID().toString()))) } + + /** + * Check if the file extension fits the encrypted pattern. + * If yes - it can mean the file is encrypted + */ + fun isEncryptedData(fileName: String?): Boolean { + return PgpDecrypt.DETECT_SEPARATE_ENCRYPTED_ATTACHMENTS_PATTERN.find(fileName ?: "") != null + } } } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentDownloadManagerService.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentDownloadManagerService.kt index 358ceef11d..b4dfd8e2d2 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentDownloadManagerService.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentDownloadManagerService.kt @@ -37,6 +37,7 @@ import com.flowcrypt.email.database.entity.AccountEntity import com.flowcrypt.email.extensions.kotlin.toHex import com.flowcrypt.email.jetpack.viewmodel.AccountViewModel import com.flowcrypt.email.security.KeysStorageImpl +import com.flowcrypt.email.security.SecurityUtils import com.flowcrypt.email.security.pgp.PgpDecrypt import com.flowcrypt.email.util.FileAndDirectoryUtils import com.flowcrypt.email.util.GeneralUtil @@ -653,8 +654,7 @@ class AttachmentDownloadManagerService : Service() { throw NullPointerException("Error. The file is missing") } - val regex = PgpDecrypt.DETECT_SEPARATE_ENCRYPTED_ATTACHMENTS_PATTERN - if (regex.find(att.name ?: "") == null) { + if (!SecurityUtils.isEncryptedData(att.name)) { return file } diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentNotificationManager.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentNotificationManager.kt index 4e07dc6763..1f48c70d99 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentNotificationManager.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/service/attachment/AttachmentNotificationManager.kt @@ -130,22 +130,22 @@ class AttachmentNotificationManager(context: Context) : CustomNotificationManage fun errorHappened(context: Context, attInfo: AttachmentInfo, e: Exception) { val builder = genDefBuilder(context, attInfo) - val bitText = StringBuilder() + val bigText = StringBuilder() val contentText = StringBuilder() when { TextUtils.isEmpty(e.message) -> { contentText.append(context.getString(R.string.error_occurred_please_try_again)) - bitText.append(e.javaClass.simpleName) + bigText.append(e.javaClass.simpleName) } e.cause != null -> { contentText.append(e.cause?.message ?: "") - bitText.append(e.javaClass.simpleName + ": " + e.message) + bigText.append(e.javaClass.simpleName + ": " + e.message) } else -> { contentText.append(e.message) - bitText.append(e.javaClass.simpleName + ": " + e.message) + bigText.append(e.javaClass.simpleName + ": " + e.message) } } @@ -159,7 +159,7 @@ class AttachmentNotificationManager(context: Context) : CustomNotificationManage R.plurals.please_provide_passphrase_for_following_keys, 1 ) + "\n" + GeneralUtil.doSectionsInText(" ", it, 4) + "\n\n" - bitText.insert(0, additionalText) + bigText.insert(0, additionalText) } } } @@ -175,8 +175,8 @@ class AttachmentNotificationManager(context: Context) : CustomNotificationManage .setGroup(GROUP_NAME_ATTACHMENTS) .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN) - if (bitText.isNotEmpty()) { - builder.setStyle(NotificationCompat.BigTextStyle().bigText(bitText)) + if (bigText.isNotEmpty()) { + builder.setStyle(NotificationCompat.BigTextStyle().bigText(bigText)) } notificationManagerCompat.notify(attInfo.id, attInfo.uid.toInt(), builder.build()) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt index e567907768..ec6c65bb90 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/MessageDetailsFragment.kt @@ -72,6 +72,7 @@ import com.flowcrypt.email.jetpack.viewmodel.factory.MsgDetailsViewModelFactory import com.flowcrypt.email.model.MessageEncryptionType import com.flowcrypt.email.model.MessageType import com.flowcrypt.email.model.PgpContact +import com.flowcrypt.email.security.SecurityUtils import com.flowcrypt.email.service.attachment.AttachmentDownloadManagerService import com.flowcrypt.email.ui.activity.CreateMessageActivity import com.flowcrypt.email.ui.activity.ImportPrivateKeyActivity @@ -129,6 +130,21 @@ class MessageDetailsFragment : BaseFragment(), ProgressBehaviour, View.OnClickLi override fun onDownloadClick(attachmentInfo: AttachmentInfo) { lastClickedAtt = attachmentInfo lastClickedAtt?.orderNumber = GeneralUtil.genAttOrderId(requireContext()) + + if (SecurityUtils.isEncryptedData(attachmentInfo.name)) { + for (block in msgInfo?.msgBlocks ?: emptyList()) { + if (block.type == MsgBlock.Type.DECRYPT_ERROR) { + val decryptErrorMsgBlock = block as? DecryptErrorMsgBlock ?: continue + val decryptErrorDetails = decryptErrorMsgBlock.error?.details ?: continue + if (decryptErrorDetails.type == DecryptErrorDetails.Type.NEED_PASSPHRASE) { + val fingerprints = decryptErrorMsgBlock.error.longIds?.needPassphrase ?: continue + showNeedPassphraseDialog(fingerprints) + return + } + } + } + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q || ContextCompat.checkSelfPermission( requireContext(),