make error message for 'not encrypted for this device'
This commit is contained in:
parent
3b39d81c2e
commit
bda95bc571
|
@ -1372,16 +1372,23 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
|
|||
return session;
|
||||
}
|
||||
|
||||
public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceivingPayloadMessage(XmppAxolotlMessage message, boolean postponePreKeyMessageHandling) {
|
||||
public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceivingPayloadMessage(XmppAxolotlMessage message, boolean postponePreKeyMessageHandling) throws NotEncryptedForThisDeviceException {
|
||||
XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = null;
|
||||
|
||||
XmppAxolotlSession session = getReceivingSession(message);
|
||||
int ownDeviceId = getOwnDeviceId();
|
||||
try {
|
||||
plaintextMessage = message.decrypt(session, getOwnDeviceId());
|
||||
plaintextMessage = message.decrypt(session, ownDeviceId);
|
||||
Integer preKeyId = session.getPreKeyIdAndReset();
|
||||
if (preKeyId != null) {
|
||||
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) {
|
||||
Log.w(Config.LOGTAG, getLogprefix(account) + "Failed to decrypt message from " + message.getFrom() + ": " + e.getMessage());
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ public class Message extends AbstractEntity {
|
|||
public static final int ENCRYPTION_DECRYPTED = 3;
|
||||
public static final int ENCRYPTION_DECRYPTION_FAILED = 4;
|
||||
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_IMAGE = 1;
|
||||
|
@ -869,6 +870,9 @@ public class Message extends AbstractEntity {
|
|||
if (encryption == ENCRYPTION_DECRYPTED || encryption == ENCRYPTION_DECRYPTION_FAILED) {
|
||||
return ENCRYPTION_PGP;
|
||||
}
|
||||
if (encryption == ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE) {
|
||||
return ENCRYPTION_AXOLOTL;
|
||||
}
|
||||
return encryption;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.UUID;
|
|||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.R;
|
||||
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.entities.Account;
|
||||
import eu.siacs.conversations.entities.Bookmark;
|
||||
|
@ -114,7 +115,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||
return null;
|
||||
}
|
||||
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) {
|
||||
Message finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
|
||||
finishedMessage.setFingerprint(plaintextMessage.getFingerprint());
|
||||
|
@ -545,6 +551,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
|||
|
||||
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||
notify = conversation.getAccount().getPgpDecryptionService().decrypt(message, notify);
|
||||
} else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE) {
|
||||
notify = false;
|
||||
}
|
||||
|
||||
if (query == null) {
|
||||
|
|
|
@ -1054,6 +1054,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
|||
}
|
||||
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
|
||||
&& m.getType() != Message.TYPE_PRIVATE
|
||||
&& !(t instanceof TransferablePlaceholder);
|
||||
|
|
|
@ -807,16 +807,12 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
|||
}
|
||||
} else {
|
||||
displayInfoMessage(viewHolder, activity.getString(R.string.install_openkeychain), darkBackground);
|
||||
viewHolder.message_box.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
activity.showInstallPgpDialog();
|
||||
}
|
||||
});
|
||||
viewHolder.message_box.setOnClickListener(v -> activity.showInstallPgpDialog());
|
||||
}
|
||||
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||
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 {
|
||||
if (message.isGeoUri()) {
|
||||
displayLocationMessage(viewHolder, message);
|
||||
|
|
|
@ -241,6 +241,7 @@ public final class CryptoHelper {
|
|||
case Message.ENCRYPTION_OTR:
|
||||
return R.string.encryption_choice_otr;
|
||||
case Message.ENCRYPTION_AXOLOTL:
|
||||
case Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE:
|
||||
return R.string.encryption_choice_omemo;
|
||||
case Message.ENCRYPTION_NONE:
|
||||
return R.string.encryption_choice_unencrypted;
|
||||
|
|
|
@ -277,6 +277,8 @@ public class UIHelper {
|
|||
return new Pair<>(context.getString(R.string.pgp_message), true);
|
||||
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
|
||||
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) {
|
||||
if (message.getStatus() == Message.STATUS_RECEIVED) {
|
||||
return new Pair<>(context.getString(R.string.received_x_file,
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue