From 48147b7fd148a949268bd62db5297766d43406da Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Sun, 23 Jul 2017 16:53:42 +0800 Subject: [PATCH] Give up PGP decryption when intent is cancelled When receiving a PGP message which is not encrypted with YOUR key, OpenKeychain shows a dialog, which tells you the private key to decrypt the message is unavailable. However, Conversations won't give up decrypting the message. So whether the subsequent messages are decryptable or not, the decryption is blocked at the current message. The commit fixes the bug in this way: Give up the current message when the decryption intent is cancelled, so that subsequent messages can be handled. --- .../crypto/PgpDecryptionService.java | 21 +++++++++++++++++++ .../ui/ConversationFragment.java | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java index 53aa3e9f4a24d79087a071bd96af32597be08339..69bd5f70ba5259e068a05ad3c25a76652f2dd376 100644 --- a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java +++ b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java @@ -69,6 +69,27 @@ public class PgpDecryptionService { this.pendingNotifications.remove(message); } + public void giveUpCurrentDecryption(){ + Message message; + synchronized (this) { + if(currentMessage != null) { + return; + } + message = messages.peekFirst(); + if (message == null) { + return; + } + discard(message); + } + synchronized (message){ + if (message.getEncryption() == Message.ENCRYPTION_PGP) { + message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED); + } + } + mXmppConnectionService.updateMessage(message); + continueDecryption(true); + } + protected synchronized void decryptNext() { if (pendingIntent == null && getOpenPgpApi() != null diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index afdabcfe82939de21d895309b4534e23fd244506..635a96274ba80a827cb65e615f5240707bdd1f59 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1658,6 +1658,11 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa int choice = data.getIntExtra("choice", ConversationActivity.ATTACHMENT_CHOICE_INVALID); activity.selectPresenceToAttachFile(choice, conversation.getNextEncryption()); } + } else if (resultCode == Activity.RESULT_CANCELED) { + if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) { + // discard the message to prevent decryption being blocked + conversation.getAccount().getPgpDecryptionService().giveUpCurrentDecryption(); + } } }