make error message for 'not encrypted for this device'

This commit is contained in:
Daniel Gultsch 2018-04-04 18:21:22 +02:00
parent 3b39d81c2e
commit bda95bc571
8 changed files with 774 additions and 751 deletions

View File

@ -1372,16 +1372,23 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
return session; return session;
} }
public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceivingPayloadMessage(XmppAxolotlMessage message, boolean postponePreKeyMessageHandling) { public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceivingPayloadMessage(XmppAxolotlMessage message, boolean postponePreKeyMessageHandling) throws NotEncryptedForThisDeviceException {
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = null; XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = null;
XmppAxolotlSession session = getReceivingSession(message); XmppAxolotlSession session = getReceivingSession(message);
int ownDeviceId = getOwnDeviceId();
try { try {
plaintextMessage = message.decrypt(session, getOwnDeviceId()); plaintextMessage = message.decrypt(session, ownDeviceId);
Integer preKeyId = session.getPreKeyIdAndReset(); Integer preKeyId = session.getPreKeyIdAndReset();
if (preKeyId != null) { if (preKeyId != null) {
postPreKeyMessageHandling(session, preKeyId, postponePreKeyMessageHandling); postPreKeyMessageHandling(session, preKeyId, postponePreKeyMessageHandling);
} }
} catch (NotEncryptedForThisDeviceException e) {
if (account.getJid().asBareJid().equals(message.getFrom().asBareJid()) && message.getSenderDeviceId() == ownDeviceId) {
Log.w(Config.LOGTAG, getLogprefix(account) + "Reflected omemo message received");
} else {
throw e;
}
} catch (CryptoFailedException e) { } catch (CryptoFailedException e) {
Log.w(Config.LOGTAG, getLogprefix(account) + "Failed to decrypt message from " + message.getFrom() + ": " + e.getMessage()); Log.w(Config.LOGTAG, getLogprefix(account) + "Failed to decrypt message from " + message.getFrom() + ": " + e.getMessage());
} }

View File

@ -42,6 +42,7 @@ public class Message extends AbstractEntity {
public static final int ENCRYPTION_DECRYPTED = 3; public static final int ENCRYPTION_DECRYPTED = 3;
public static final int ENCRYPTION_DECRYPTION_FAILED = 4; public static final int ENCRYPTION_DECRYPTION_FAILED = 4;
public static final int ENCRYPTION_AXOLOTL = 5; public static final int ENCRYPTION_AXOLOTL = 5;
public static final int ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE = 6;
public static final int TYPE_TEXT = 0; public static final int TYPE_TEXT = 0;
public static final int TYPE_IMAGE = 1; public static final int TYPE_IMAGE = 1;
@ -869,6 +870,9 @@ public class Message extends AbstractEntity {
if (encryption == ENCRYPTION_DECRYPTED || encryption == ENCRYPTION_DECRYPTION_FAILED) { if (encryption == ENCRYPTION_DECRYPTED || encryption == ENCRYPTION_DECRYPTION_FAILED) {
return ENCRYPTION_PGP; return ENCRYPTION_PGP;
} }
if (encryption == ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE) {
return ENCRYPTION_AXOLOTL;
}
return encryption; return encryption;
} }
} }

View File

@ -16,6 +16,7 @@ import java.util.UUID;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.NotEncryptedForThisDeviceException;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Bookmark;
@ -114,7 +115,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
return null; return null;
} }
if (xmppAxolotlMessage.hasPayload()) { if (xmppAxolotlMessage.hasPayload()) {
final XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage, postpone); final XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage;
try {
plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage, postpone);
} catch (NotEncryptedForThisDeviceException e) {
return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE, status);
}
if (plaintextMessage != null) { if (plaintextMessage != null) {
Message finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status); Message finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
finishedMessage.setFingerprint(plaintextMessage.getFingerprint()); finishedMessage.setFingerprint(plaintextMessage.getFingerprint());
@ -545,6 +551,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (message.getEncryption() == Message.ENCRYPTION_PGP) { if (message.getEncryption() == Message.ENCRYPTION_PGP) {
notify = conversation.getAccount().getPgpDecryptionService().decrypt(message, notify); notify = conversation.getAccount().getPgpDecryptionService().decrypt(message, notify);
} else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE) {
notify = false;
} }
if (query == null) { if (query == null) {

View File

@ -1054,6 +1054,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
if (m.getType() != Message.TYPE_STATUS) { if (m.getType() != Message.TYPE_STATUS) {
if (m.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE) {
return;
}
final boolean treatAsFile = m.getType() != Message.TYPE_TEXT final boolean treatAsFile = m.getType() != Message.TYPE_TEXT
&& m.getType() != Message.TYPE_PRIVATE && m.getType() != Message.TYPE_PRIVATE
&& !(t instanceof TransferablePlaceholder); && !(t instanceof TransferablePlaceholder);

View File

@ -807,16 +807,12 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
} }
} else { } else {
displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain), darkBackground); displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain), darkBackground);
viewHolder.message_box.setOnClickListener(new OnClickListener() { viewHolder.message_box.setOnClickListener(v -> activity.showInstallPgpDialog());
@Override
public void onClick(View v) {
activity.showInstallPgpDialog();
}
});
} }
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
displayDecryptionFailed(viewHolder, darkBackground); displayDecryptionFailed(viewHolder, darkBackground);
} else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE) {
displayInfoMessage(viewHolder, activity.getString(R.string.not_encrypted_for_this_device), darkBackground);
} else { } else {
if (message.isGeoUri()) { if (message.isGeoUri()) {
displayLocationMessage(viewHolder, message); displayLocationMessage(viewHolder, message);

View File

@ -241,6 +241,7 @@ public final class CryptoHelper {
case Message.ENCRYPTION_OTR: case Message.ENCRYPTION_OTR:
return R.string.encryption_choice_otr; return R.string.encryption_choice_otr;
case Message.ENCRYPTION_AXOLOTL: case Message.ENCRYPTION_AXOLOTL:
case Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE:
return R.string.encryption_choice_omemo; return R.string.encryption_choice_omemo;
case Message.ENCRYPTION_NONE: case Message.ENCRYPTION_NONE:
return R.string.encryption_choice_unencrypted; return R.string.encryption_choice_unencrypted;

View File

@ -277,6 +277,8 @@ public class UIHelper {
return new Pair<>(context.getString(R.string.pgp_message), true); return new Pair<>(context.getString(R.string.pgp_message), true);
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
return new Pair<>(context.getString(R.string.decryption_failed), true); return new Pair<>(context.getString(R.string.decryption_failed), true);
} else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE) {
return new Pair<>(context.getString(R.string.not_encrypted_for_this_device), true);
} else if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) { } else if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
if (message.getStatus() == Message.STATUS_RECEIVED) { if (message.getStatus() == Message.STATUS_RECEIVED) {
return new Pair<>(context.getString(R.string.received_x_file, return new Pair<>(context.getString(R.string.received_x_file,

View File

@ -557,7 +557,7 @@
<string name="security_error_invalid_file_access">Security error: Invalid file access</string> <string name="security_error_invalid_file_access">Security error: Invalid file access</string>
<string name="no_application_to_share_uri">No application found to share URI</string> <string name="no_application_to_share_uri">No application found to share URI</string>
<string name="share_uri_with">Share URI with…</string> <string name="share_uri_with">Share URI with…</string>
<string translatable="false" name="welcome_header">Join the Conversation</string> <string name="welcome_header" translatable="false">Join the Conversation</string>
<string name="welcome_text">Jabber is a provider independent instant messaging network. You can use this client with what ever Jabber server you choose.\nHowever for your convenience we made it easy to create an account on conversations.im¹; a provider specially suited for the use with Conversations.</string> <string name="welcome_text">Jabber is a provider independent instant messaging network. You can use this client with what ever Jabber server you choose.\nHowever for your convenience we made it easy to create an account on conversations.im¹; a provider specially suited for the use with Conversations.</string>
<string name="magic_create_text">We will guide you through the process of creating an account on conversations.im.¹\nWhen picking conversations.im as a provider you will be able to communicate with users of other providers by giving them your full Jabber ID.</string> <string name="magic_create_text">We will guide you through the process of creating an account on conversations.im.¹\nWhen picking conversations.im as a provider you will be able to communicate with users of other providers by giving them your full Jabber ID.</string>
<string name="your_full_jid_will_be">Your full Jabber ID will be: %s</string> <string name="your_full_jid_will_be">Your full Jabber ID will be: %s</string>
@ -748,4 +748,5 @@
<string name="small">Small</string> <string name="small">Small</string>
<string name="medium">Medium</string> <string name="medium">Medium</string>
<string name="large">Large</string> <string name="large">Large</string>
<string name="not_encrypted_for_this_device">Message was not encrypted for this device.</string>
</resources> </resources>