From bf6b54a7aa7806a8017c4e45ca873d243b2b0128 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 19 Feb 2018 13:55:48 +0100 Subject: [PATCH] get rid of OTR --- build.gradle | 1 - src/main/AndroidManifest.xml | 4 - .../conversations/crypto/OtrService.java | 310 ------------ .../siacs/conversations/entities/Account.java | 37 -- .../conversations/entities/Conversation.java | 133 ------ .../conversations/entities/Transferable.java | 2 +- .../generator/AbstractGenerator.java | 3 - .../generator/MessageGenerator.java | 40 -- .../http/HttpDownloadConnection.java | 4 +- .../conversations/parser/MessageParser.java | 118 +---- .../services/XmppConnectionService.java | 139 +----- .../ui/ContactDetailsActivity.java | 28 +- .../ui/ConversationActivity.java | 57 +-- .../ui/ConversationFragment.java | 48 +- .../conversations/ui/EditAccountActivity.java | 27 -- .../conversations/ui/ShareWithActivity.java | 3 +- .../conversations/ui/VerifyOTRActivity.java | 443 ------------------ .../siacs/conversations/ui/XmppActivity.java | 14 +- .../siacs/conversations/utils/UIHelper.java | 2 - .../eu/siacs/conversations/utils/XmppUri.java | 8 +- .../eu/siacs/conversations/xmpp/jid/Jid.java | 10 - .../xmpp/jingle/JingleConnection.java | 31 +- src/main/res/layout/activity_edit_account.xml | 46 -- src/main/res/menu/conversations.xml | 3 - 24 files changed, 15 insertions(+), 1496 deletions(-) delete mode 100644 src/main/java/eu/siacs/conversations/crypto/OtrService.java delete mode 100644 src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java diff --git a/build.gradle b/build.gradle index 14bf60867..aa593378f 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,6 @@ dependencies { implementation "com.android.support:design:$supportLibVersion" freeImplementation "com.android.support:support-emoji-bundled:$supportLibVersion" implementation 'org.bouncycastle:bcmail-jdk15on:1.58' - implementation 'org.jitsi:org.otr4j:0.22' implementation 'org.gnu.inet:libidn:1.15' implementation 'com.google.zxing:core:3.3.0' implementation 'de.measite.minidns:minidns-hla:0.2.4' diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index b884804d7..d98c7a489 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -141,10 +141,6 @@ android:name=".ui.PublishProfilePictureActivity" android:label="@string/mgmt_account_publish_avatar" android:windowSoftInputMode="stateHidden" /> - getFingerprints() { ArrayList fingerprints = new ArrayList<>(); - final String otr = this.getOtrFingerprint(); - if (otr != null) { - fingerprints.add(new XmppUri.Fingerprint(XmppUri.FingerprintType.OTR,otr)); - } if (axolotlService == null) { return fingerprints; } diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 8867ff6af..1d03e7b1c 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -4,17 +4,10 @@ import android.content.ContentValues; import android.database.Cursor; import android.support.annotation.NonNull; -import net.java.otr4j.OtrException; -import net.java.otr4j.crypto.OtrCryptoException; -import net.java.otr4j.session.SessionID; -import net.java.otr4j.session.SessionImpl; -import net.java.otr4j.session.SessionStatus; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.security.interfaces.DSAPublicKey; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -77,11 +70,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl protected final ArrayList messages = new ArrayList<>(); protected Account account = null; - private transient SessionImpl otrSession; - - private transient String otrFingerprint = null; - private Smp mSmp = new Smp(); - private transient MucOptions mucOptions = null; private byte[] symmetricKey; @@ -89,7 +77,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl private boolean messagesLeftOnServer = true; private ChatState mOutgoingChatState = Config.DEFAULT_CHATSTATE; private ChatState mIncomingChatState = Config.DEFAULT_CHATSTATE; - private String mLastReceivedOtrMessageId = null; private String mFirstMamReference = null; private Message correctingMessage; public AtomicBoolean messagesLoaded = new AtomicBoolean(true); @@ -335,14 +322,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return getContact().getBlockedJid(); } - public String getLastReceivedOtrMessageId() { - return this.mLastReceivedOtrMessageId; - } - - public void setLastReceivedOtrMessageId(String id) { - this.mLastReceivedOtrMessageId = id; - } - public int countMessages() { synchronized (this.messages) { return this.messages.size(); @@ -587,110 +566,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl this.mode = mode; } - public SessionImpl startOtrSession(String presence, boolean sendStart) { - if (this.otrSession != null) { - return this.otrSession; - } else { - final SessionID sessionId = new SessionID(this.getJid().toBareJid().toString(), - presence, - "xmpp"); - this.otrSession = new SessionImpl(sessionId, getAccount().getOtrService()); - try { - if (sendStart) { - this.otrSession.startSession(); - return this.otrSession; - } - return this.otrSession; - } catch (OtrException e) { - return null; - } - } - - } - - public SessionImpl getOtrSession() { - return this.otrSession; - } - - public void resetOtrSession() { - this.otrFingerprint = null; - this.otrSession = null; - this.mSmp.hint = null; - this.mSmp.secret = null; - this.mSmp.status = Smp.STATUS_NONE; - } - - public Smp smp() { - return mSmp; - } - - public boolean startOtrIfNeeded() { - if (this.otrSession != null && this.otrSession.getSessionStatus() != SessionStatus.ENCRYPTED) { - try { - this.otrSession.startSession(); - return true; - } catch (OtrException e) { - this.resetOtrSession(); - return false; - } - } else { - return true; - } - } - - public boolean endOtrIfNeeded() { - if (this.otrSession != null) { - if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) { - try { - this.otrSession.endSession(); - this.resetOtrSession(); - return true; - } catch (OtrException e) { - this.resetOtrSession(); - return false; - } - } else { - this.resetOtrSession(); - return false; - } - } else { - return false; - } - } - - public boolean hasValidOtrSession() { - return this.otrSession != null; - } - - public synchronized String getOtrFingerprint() { - if (this.otrFingerprint == null) { - try { - if (getOtrSession() == null || getOtrSession().getSessionStatus() != SessionStatus.ENCRYPTED) { - return null; - } - DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession().getRemotePublicKey(); - this.otrFingerprint = getAccount().getOtrService().getFingerprint(remotePubKey).toLowerCase(Locale.US); - } catch (final OtrCryptoException | UnsupportedOperationException ignored) { - return null; - } - } - return this.otrFingerprint; - } - - public boolean verifyOtrFingerprint() { - final String fingerprint = getOtrFingerprint(); - if (fingerprint != null) { - getContact().addOtrFingerprint(fingerprint); - return true; - } else { - return false; - } - } - - public boolean isOtrFingerprintVerified() { - return getContact().getOtrFingerprints().contains(getOtrFingerprint()); - } - /** * short for is Private and Non-anonymous */ @@ -735,8 +610,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return Config.supportUnencrypted() ? selectedEncryption : getDefaultEncryption(); case Message.ENCRYPTION_AXOLOTL: return Config.supportOmemo() ? selectedEncryption : getDefaultEncryption(); - case Message.ENCRYPTION_OTR: - return Config.supportOtr() ? selectedEncryption : getDefaultEncryption(); case Message.ENCRYPTION_PGP: case Message.ENCRYPTION_DECRYPTED: case Message.ENCRYPTION_DECRYPTION_FAILED: @@ -753,8 +626,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } else if (Config.supportOmemo() && (axolotlService != null && axolotlService.isConversationAxolotlCapable(this) || !Config.multipleEncryptionChoices())) { return Message.ENCRYPTION_AXOLOTL; - } else if (Config.supportOtr() && mode == MODE_SINGLE) { - return Message.ENCRYPTION_OTR; } else if (Config.supportOpenPgp()) { return Message.ENCRYPTION_PGP; } else { @@ -771,10 +642,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return nextMessage == null ? "" : nextMessage; } - public boolean smpRequested() { - return smp().status == Smp.STATUS_CONTACT_REQUESTED; - } - public boolean setNextMessage(String message) { boolean changed = !getNextMessage().equals(message); this.setAttribute(ATTRIBUTE_NEXT_MESSAGE, message); diff --git a/src/main/java/eu/siacs/conversations/entities/Transferable.java b/src/main/java/eu/siacs/conversations/entities/Transferable.java index 5a47c4512..204c70240 100644 --- a/src/main/java/eu/siacs/conversations/entities/Transferable.java +++ b/src/main/java/eu/siacs/conversations/entities/Transferable.java @@ -6,7 +6,7 @@ import java.util.List; public interface Transferable { List VALID_IMAGE_EXTENSIONS = Arrays.asList("webp", "jpeg", "jpg", "png", "jpe"); - List VALID_CRYPTO_EXTENSIONS = Arrays.asList("pgp", "gpg", "otr"); + List VALID_CRYPTO_EXTENSIONS = Arrays.asList("pgp", "gpg"); List WELL_KNOWN_EXTENSIONS = Arrays.asList("pdf","m4a","mp4","3gp","aac","amr","mp3"); int STATUS_UNKNOWN = 0x200; diff --git a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java index 6db39cdec..e970008c6 100644 --- a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java @@ -118,9 +118,6 @@ public abstract class AbstractGenerator { if (!mXmppConnectionService.useTorToConnect()) { features.addAll(Arrays.asList(PRIVACY_SENSITIVE)); } - if (Config.supportOtr()) { - features.addAll(Arrays.asList(OTR)); - } if (mXmppConnectionService.broadcastLastActivity()) { features.add(Namespace.IDLE); } diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index 716953a05..3218d88a6 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -1,8 +1,5 @@ package eu.siacs.conversations.generator; -import net.java.otr4j.OtrException; -import net.java.otr4j.session.Session; - import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -24,7 +21,6 @@ import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.stanzas.MessagePacket; public class MessageGenerator extends AbstractGenerator { - public static final String OTR_FALLBACK_MESSAGE = "I would like to start a private (OTR encrypted) conversation but your client doesn’t seem to support that"; private static final String OMEMO_FALLBACK_MESSAGE = "I sent you an OMEMO encrypted message but your client doesn’t seem to support that. Find more information on https://conversations.im/omemo"; private static final String PGP_FALLBACK_MESSAGE = "I sent you a PGP encrypted message but your client doesn’t seem to support that."; @@ -112,29 +108,6 @@ public class MessageGenerator extends AbstractGenerator { packet.addChild("no-permanent-storage", "urn:xmpp:hints"); //do not copy this. this is wrong. it is *store* } - public MessagePacket generateOtrChat(Message message) { - Session otrSession = message.getConversation().getOtrSession(); - if (otrSession == null) { - return null; - } - MessagePacket packet = preparePacket(message); - addMessageHints(packet); - try { - String content; - if (message.hasFileOnRemoteHost()) { - content = message.getFileParams().url.toString(); - } else { - content = message.getBody(); - } - packet.setBody(otrSession.transformSending(content)[0]); - packet.addChild("encryption","urn:xmpp:eme:0") - .setAttribute("namespace","urn:xmpp:otr:0"); - return packet; - } catch (OtrException e) { - return null; - } - } - public MessagePacket generateChat(Message message) { MessagePacket packet = preparePacket(message); String content; @@ -254,17 +227,4 @@ public class MessageGenerator extends AbstractGenerator { packet.addChild("store", "urn:xmpp:hints"); return packet; } - - public MessagePacket generateOtrError(Jid to, String id, String errorText) { - MessagePacket packet = new MessagePacket(); - packet.setType(MessagePacket.TYPE_ERROR); - packet.setAttribute("id",id); - packet.setTo(to); - Element error = packet.addChild("error"); - error.setAttribute("code","406"); - error.setAttribute("type","modify"); - error.addChild("not-acceptable","urn:ietf:params:xml:ns:xmpp-stanzas"); - error.addChild("text").setContent("?OTR Error:" + errorText); - return packet; - } } diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index fa3df7494..173d29634 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -96,9 +96,7 @@ public class HttpDownloadConnection implements Transferable { this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference)); } - if ((this.message.getEncryption() == Message.ENCRYPTION_OTR - || this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL) - && this.file.getKey() == null) { + if (this.message.getEncryption() == Message.ENCRYPTION_AXOLOTL && this.file.getKey() == null) { this.message.setEncryption(Message.ENCRYPTION_NONE); } checkFileSize(interactive); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 3654c98e9..d2d082a84 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -1,13 +1,8 @@ package eu.siacs.conversations.parser; -import android.os.Build; -import android.text.Html; import android.util.Log; import android.util.Pair; -import net.java.otr4j.session.Session; -import net.java.otr4j.session.SessionStatus; - import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -19,7 +14,6 @@ import java.util.UUID; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; -import eu.siacs.conversations.crypto.OtrService; import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage; import eu.siacs.conversations.entities.Account; @@ -28,10 +22,8 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; -import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.entities.ReadByMarker; import eu.siacs.conversations.entities.ReceiptRequest; -import eu.siacs.conversations.entities.ServiceDiscoveryResult; import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.XmppConnectionService; @@ -46,8 +38,6 @@ import eu.siacs.conversations.xmpp.stanzas.MessagePacket; public class MessageParser extends AbstractParser implements OnMessagePacketReceived { - private static final List CLIENTS_SENDING_HTML_IN_OTR = Arrays.asList("Pidgin", "Adium", "Trillian"); - public MessageParser(XmppConnectionService service) { super(service); } @@ -80,90 +70,6 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece return false; } - private Message parseOtrChat(String body, Jid from, String id, Conversation conversation) { - String presence; - if (from.isBareJid()) { - presence = ""; - } else { - presence = from.getResourcepart(); - } - if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) { - conversation.endOtrIfNeeded(); - } - if (!conversation.hasValidOtrSession()) { - conversation.startOtrSession(presence, false); - } else { - String foreignPresence = conversation.getOtrSession().getSessionID().getUserID(); - if (!foreignPresence.equals(presence)) { - conversation.endOtrIfNeeded(); - conversation.startOtrSession(presence, false); - } - } - try { - conversation.setLastReceivedOtrMessageId(id); - Session otrSession = conversation.getOtrSession(); - body = otrSession.transformReceiving(body); - SessionStatus status = otrSession.getSessionStatus(); - if (body == null && status == SessionStatus.ENCRYPTED) { - mXmppConnectionService.onOtrSessionEstablished(conversation); - return null; - } else if (body == null && status == SessionStatus.FINISHED) { - conversation.resetOtrSession(); - mXmppConnectionService.updateConversationUi(); - return null; - } else if (body == null || (body.isEmpty())) { - return null; - } - if (body.startsWith(CryptoHelper.FILETRANSFER)) { - String key = body.substring(CryptoHelper.FILETRANSFER.length()); - conversation.setSymmetricKey(CryptoHelper.hexToBytes(key)); - return null; - } - if (clientMightSendHtml(conversation.getAccount(), from)) { - Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": received OTR message from bad behaving client. escaping HTML…"); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - body = Html.fromHtml(body, Html.FROM_HTML_MODE_LEGACY).toString(); - } else { - body = Html.fromHtml(body).toString(); - } - } - - final OtrService otrService = conversation.getAccount().getOtrService(); - Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED); - finishedMessage.setFingerprint(otrService.getFingerprint(otrSession.getRemotePublicKey())); - conversation.setLastReceivedOtrMessageId(null); - - return finishedMessage; - } catch (Exception e) { - conversation.resetOtrSession(); - return null; - } - } - - private static boolean clientMightSendHtml(Account account, Jid from) { - String resource = from.getResourcepart(); - if (resource == null) { - return false; - } - Presence presence = account.getRoster().getContact(from).getPresences().getPresences().get(resource); - ServiceDiscoveryResult disco = presence == null ? null : presence.getServiceDiscoveryResult(); - if (disco == null) { - return false; - } - return hasIdentityKnowForSendingHtml(disco.getIdentities()); - } - - private static boolean hasIdentityKnowForSendingHtml(List identities) { - for (ServiceDiscoveryResult.Identity identity : identities) { - if (identity.getName() != null) { - if (CLIENTS_SENDING_HTML_IN_OTR.contains(identity.getName())) { - return true; - } - } - } - return false; - } - private Message parseAxolotlChat(Element axolotlMessage, Jid from, Conversation conversation, int status, boolean postpone) { final AxolotlService service = conversation.getAccount().getAxolotlService(); final XmppAxolotlMessage xmppAxolotlMessage; @@ -316,11 +222,6 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece packet.getId(), Message.STATUS_SEND_FAILED, extractErrorMessage(packet)); - if (message != null) { - if (message.getEncryption() == Message.ENCRYPTION_OTR) { - message.getConversation().endOtrIfNeeded(); - } - } } return true; } @@ -467,17 +368,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } } final Message message; - if (body != null && body.startsWith("?OTR") && Config.supportOtr()) { - if (!isForwarded && !isTypeGroupChat && isProperlyAddressed && !conversationMultiMode) { - message = parseOtrChat(body, from, remoteMsgId, conversation); - if (message == null) { - return; - } - } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": ignoring OTR message from " + from + " isForwarded=" + Boolean.toString(isForwarded) + ", isProperlyAddressed=" + Boolean.valueOf(isProperlyAddressed)); - message = new Message(conversation, body, Message.ENCRYPTION_NONE, status); - } - } else if (pgpEncrypted != null && Config.supportOpenPgp()) { + if (pgpEncrypted != null && Config.supportOpenPgp()) { message = new Message(conversation, pgpEncrypted, Message.ENCRYPTION_PGP, status); } else if (axolotlEncrypted != null && Config.supportOmemo()) { Jid origin; @@ -669,13 +560,6 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece processMessageReceipts(account, packet, query); } - if (message.getStatus() == Message.STATUS_RECEIVED - && conversation.getOtrSession() != null - && !conversation.getOtrSession().getSessionID().getUserID() - .equals(message.getCounterpart().getResourcepart())) { - conversation.endOtrIfNeeded(); - } - mXmppConnectionService.databaseBackend.createMessage(message); final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager(); if (message.trusted() && message.treatAsDownloadable() && manager.getAutoAcceptFileSize() > 0) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 91fa6637c..5a1ae4097 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -34,12 +34,6 @@ import android.util.Log; import android.util.LruCache; import android.util.Pair; -import net.java.otr4j.OtrException; -import net.java.otr4j.session.Session; -import net.java.otr4j.session.SessionID; -import net.java.otr4j.session.SessionImpl; -import net.java.otr4j.session.SessionStatus; - import org.openintents.openpgp.IOpenPgpService2; import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpServiceConnection; @@ -214,18 +208,9 @@ public class XmppConnectionService extends Service { Conversation conversation = find(getConversations(), contact); if (conversation != null) { if (online) { - conversation.endOtrIfNeeded(); if (contact.getPresences().size() == 1) { sendUnsentMessages(conversation); } - } else { - //check if the resource we are haveing a conversation with is still online - if (conversation.hasValidOtrSession()) { - String otrResource = conversation.getOtrSession().getSessionID().getUserID(); - if (!(Arrays.asList(contact.getPresences().toResourceArray()).contains(otrResource))) { - conversation.endOtrIfNeeded(); - } - } } } } @@ -351,11 +336,7 @@ public class XmppConnectionService extends Service { } List conversations = getConversations(); for (Conversation conversation : conversations) { - if (conversation.getAccount() == account - && !account.pendingConferenceJoins.contains(conversation)) { - if (!conversation.startOtrIfNeeded()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": couldn't start OTR with " + conversation.getContact().getJid() + " when needed"); - } + if (conversation.getAccount() == account && !account.pendingConferenceJoins.contains(conversation)) { sendUnsentMessages(conversation); } } @@ -1209,17 +1190,6 @@ public class XmppConnectionService extends Service { boolean saveInDb = addToConversation; message.setStatus(Message.STATUS_WAITING); - if (!resend && message.getEncryption() != Message.ENCRYPTION_OTR) { - message.getConversation().endOtrIfNeeded(); - message.getConversation().findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, - new Conversation.OnMessageFound() { - @Override - public void onMessageFound(Message message) { - markMessage(message, Message.STATUS_SEND_FAILED); - } - }); - } - if (account.isOnlineAndConnected()) { switch (message.getEncryption()) { case Message.ENCRYPTION_NONE: @@ -1249,30 +1219,6 @@ public class XmppConnectionService extends Service { packet = mMessageGenerator.generatePgpChat(message); } break; - case Message.ENCRYPTION_OTR: - SessionImpl otrSession = conversation.getOtrSession(); - if (otrSession != null && otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) { - try { - message.setCounterpart(Jid.fromSessionID(otrSession.getSessionID())); - } catch (InvalidJidException e) { - break; - } - if (message.needsUploading()) { - mJingleConnectionManager.createNewConnection(message); - } else { - packet = mMessageGenerator.generateOtrChat(message); - } - } else if (otrSession == null) { - if (message.fixCounterpart()) { - conversation.startOtrSession(message.getCounterpart().getResourcepart(), true); - } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fix counterpart for OTR message to contact " + message.getCounterpart()); - break; - } - } else { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + " OTR session with " + message.getContact() + " is in wrong state: " + otrSession.getSessionStatus().toString()); - } - break; case Message.ENCRYPTION_AXOLOTL: message.setFingerprint(account.getAxolotlService().getOwnFingerprint()); if (message.needsUploading()) { @@ -1324,12 +1270,6 @@ public class XmppConnectionService extends Service { } } break; - case Message.ENCRYPTION_OTR: - if (!conversation.hasValidOtrSession() && message.getCounterpart() != null) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": create otr session without starting for " + message.getContact().getJid()); - conversation.startOtrSession(message.getCounterpart().getResourcepart(), false); - } - break; case Message.ENCRYPTION_AXOLOTL: message.setFingerprint(account.getAxolotlService().getOwnFingerprint()); break; @@ -1804,7 +1744,6 @@ public class XmppConnectionService extends Service { } leaveMuc(conversation); } else { - conversation.endOtrIfNeeded(); if (conversation.getContact().getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) { Log.d(Config.LOGTAG, "Canceling presence request from " + conversation.getJid().toString()); sendPresencePacket( @@ -1941,8 +1880,6 @@ public class XmppConnectionService extends Service { if (conversation.getAccount() == account) { if (conversation.getMode() == Conversation.MODE_MULTI) { leaveMuc(conversation); - } else if (conversation.getMode() == Conversation.MODE_SINGLE) { - conversation.endOtrIfNeeded(); } conversations.remove(conversation); } @@ -2750,12 +2687,6 @@ public class XmppConnectionService extends Service { if (conversation.getAccount() == account) { if (conversation.getMode() == Conversation.MODE_MULTI) { leaveMuc(conversation, true); - } else { - if (conversation.endOtrIfNeeded()) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() - + ": ended otr session with " - + conversation.getJid()); - } } } } @@ -2800,65 +2731,6 @@ public class XmppConnectionService extends Service { pushContactToServer(contact); } - public void onOtrSessionEstablished(Conversation conversation) { - final Account account = conversation.getAccount(); - final Session otrSession = conversation.getOtrSession(); - Log.d(Config.LOGTAG, - account.getJid().toBareJid() + " otr session established with " - + conversation.getJid() + "/" - + otrSession.getSessionID().getUserID()); - conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() { - - @Override - public void onMessageFound(Message message) { - SessionID id = otrSession.getSessionID(); - try { - message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID())); - } catch (InvalidJidException e) { - return; - } - if (message.needsUploading()) { - mJingleConnectionManager.createNewConnection(message); - } else { - MessagePacket outPacket = mMessageGenerator.generateOtrChat(message); - if (outPacket != null) { - mMessageGenerator.addDelay(outPacket, message.getTimeSent()); - message.setStatus(Message.STATUS_SEND); - databaseBackend.updateMessage(message); - sendMessagePacket(account, outPacket); - } - } - updateConversationUi(); - } - }); - } - - public boolean renewSymmetricKey(Conversation conversation) { - Account account = conversation.getAccount(); - byte[] symmetricKey = new byte[32]; - this.mRandom.nextBytes(symmetricKey); - Session otrSession = conversation.getOtrSession(); - if (otrSession != null) { - MessagePacket packet = new MessagePacket(); - packet.setType(MessagePacket.TYPE_CHAT); - packet.setFrom(account.getJid()); - MessageGenerator.addMessageHints(packet); - packet.setAttribute("to", otrSession.getSessionID().getAccountID() + "/" - + otrSession.getSessionID().getUserID()); - try { - packet.setBody(otrSession - .transformSending(CryptoHelper.FILETRANSFER - + CryptoHelper.bytesToHex(symmetricKey))[0]); - sendMessagePacket(account, packet); - conversation.setSymmetricKey(symmetricKey); - return true; - } catch (OtrException e) { - return false; - } - } - return false; - } - public void pushContactToServer(final Contact contact) { contact.resetOption(Contact.Options.DIRTY_DELETE); contact.setOption(Contact.Options.DIRTY_PUSH); @@ -3959,14 +3831,10 @@ public class XmppConnectionService extends Service { } public boolean verifyFingerprints(Contact contact, List fingerprints) { - boolean needsRosterWrite = false; boolean performedVerification = false; final AxolotlService axolotlService = contact.getAccount().getAxolotlService(); for (XmppUri.Fingerprint fp : fingerprints) { - if (fp.type == XmppUri.FingerprintType.OTR) { - performedVerification |= contact.addOtrFingerprint(fp.fingerprint); - needsRosterWrite |= performedVerification; - } else if (fp.type == XmppUri.FingerprintType.OMEMO) { + if (fp.type == XmppUri.FingerprintType.OMEMO) { String fingerprint = "05" + fp.fingerprint.replaceAll("\\s", ""); FingerprintStatus fingerprintStatus = axolotlService.getFingerprintTrust(fingerprint); if (fingerprintStatus != null) { @@ -3979,9 +3847,6 @@ public class XmppConnectionService extends Service { } } } - if (needsRosterWrite) { - syncRosterToDisk(contact.getAccount()); - } return performedVerification; } diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 5867356e7..6c74e4620 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -409,33 +409,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp binding.detailsContactKeys.removeAllViews(); boolean hasKeys = false; - LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); - if (Config.supportOtr()) { - for (final String otrFingerprint : contact.getOtrFingerprints()) { - hasKeys = true; - View view = inflater.inflate(R.layout.contact_key, binding.detailsContactKeys, false); - TextView key = (TextView) view.findViewById(R.id.key); - TextView keyType = (TextView) view.findViewById(R.id.key_type); - ImageButton removeButton = (ImageButton) view - .findViewById(R.id.button_remove); - removeButton.setVisibility(View.VISIBLE); - key.setText(CryptoHelper.prettifyFingerprint(otrFingerprint)); - if (otrFingerprint != null && otrFingerprint.equalsIgnoreCase(messageFingerprint)) { - keyType.setText(R.string.otr_fingerprint_selected_message); - keyType.setTextColor(ContextCompat.getColor(this, R.color.accent)); - } else { - keyType.setText(R.string.otr_fingerprint); - } - binding.detailsContactKeys.addView(view); - removeButton.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - confirmToDeleteFingerprint(otrFingerprint); - } - }); - } - } + final LayoutInflater inflater = getLayoutInflater(); final AxolotlService axolotlService = contact.getAccount().getAxolotlService(); if (Config.supportOmemo() && axolotlService != null) { boolean skippedInactive = false; diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 12906f687..174eac841 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -32,12 +32,8 @@ import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; -import android.widget.PopupMenu; -import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.Toast; -import net.java.otr4j.session.SessionStatus; - import org.openintents.openpgp.util.OpenPgpApi; import java.util.ArrayList; @@ -454,17 +450,12 @@ public class ConversationActivity extends XmppActivity } private static void configureEncryptionMenu(Conversation conversation, Menu menu) { - MenuItem otr = menu.findItem(R.id.encryption_choice_otr); MenuItem none = menu.findItem(R.id.encryption_choice_none); MenuItem pgp = menu.findItem(R.id.encryption_choice_pgp); MenuItem axolotl = menu.findItem(R.id.encryption_choice_axolotl); pgp.setVisible(Config.supportOpenPgp()); none.setVisible(Config.supportUnencrypted() || conversation.getMode() == Conversation.MODE_MULTI); - otr.setVisible(Config.supportOtr()); axolotl.setVisible(Config.supportOmemo()); - if (conversation.getMode() == Conversation.MODE_MULTI) { - otr.setVisible(false); - } if (!conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) { axolotl.setEnabled(false); } @@ -472,9 +463,6 @@ public class ConversationActivity extends XmppActivity case Message.ENCRYPTION_NONE: none.setChecked(true); break; - case Message.ENCRYPTION_OTR: - otr.setChecked(true); - break; case Message.ENCRYPTION_PGP: pgp.setChecked(true); break; @@ -542,7 +530,7 @@ public class ConversationActivity extends XmppActivity startActivity(getInstallApkIntent(fallbackPackageId)); } }; - if ((account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) && encryption != Message.ENCRYPTION_OTR) { + if (account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) { conversation.setNextCounterpart(null); callback.onPresenceSelected(); } else { @@ -699,7 +687,6 @@ public class ConversationActivity extends XmppActivity } else if (getSelectedConversation() != null) { switch (item.getItemId()) { case R.id.encryption_choice_axolotl: - case R.id.encryption_choice_otr: case R.id.encryption_choice_pgp: case R.id.encryption_choice_none: handleEncryptionSelection(item); @@ -808,41 +795,6 @@ public class ConversationActivity extends XmppActivity builder.create().show(); } - public void verifyOtrSessionDialog(final Conversation conversation, View view) { - if (!conversation.hasValidOtrSession() || conversation.getOtrSession().getSessionStatus() != SessionStatus.ENCRYPTED) { - Toast.makeText(this, R.string.otr_session_not_started, Toast.LENGTH_LONG).show(); - return; - } - if (view == null) { - return; - } - PopupMenu popup = new PopupMenu(this, view); - popup.inflate(R.menu.verification_choices); - popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - Intent intent = new Intent(ConversationActivity.this, VerifyOTRActivity.class); - intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT); - intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString()); - intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString()); - switch (menuItem.getItemId()) { - case R.id.scan_fingerprint: - intent.putExtra("mode", VerifyOTRActivity.MODE_SCAN_FINGERPRINT); - break; - case R.id.ask_question: - intent.putExtra("mode", VerifyOTRActivity.MODE_ASK_QUESTION); - break; - case R.id.manual_verification: - intent.putExtra("mode", VerifyOTRActivity.MODE_MANUAL_VERIFICATION); - break; - } - startActivity(intent); - return true; - } - }); - popup.show(); - } - private void handleEncryptionSelection(MenuItem item) { Conversation conversation = getSelectedConversation(); if (conversation == null) { @@ -854,10 +806,6 @@ public class ConversationActivity extends XmppActivity conversation.setNextEncryption(Message.ENCRYPTION_NONE); item.setChecked(true); break; - case R.id.encryption_choice_otr: - conversation.setNextEncryption(Message.ENCRYPTION_OTR); - item.setChecked(true); - break; case R.id.encryption_choice_pgp: if (hasPgp()) { if (conversation.getAccount().getPgpSignature() != null) { @@ -1388,8 +1336,7 @@ public class ConversationActivity extends XmppActivity } }; if (c == null || c.getMode() == Conversation.MODE_MULTI - || FileBackend.allFilesUnderSize(this, uris, getMaxHttpUploadSize(c)) - || c.getNextEncryption() == Message.ENCRYPTION_OTR) { + || FileBackend.allFilesUnderSize(this, uris, getMaxHttpUploadSize(c))) { callback.onPresenceSelected(); } else { selectPresence(c, callback); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index ac5e5d8a5..3690a9eaa 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -42,8 +42,6 @@ import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; import android.widget.Toast; -import net.java.otr4j.session.SessionStatus; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -221,13 +219,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } } }; - protected OnClickListener clickToVerify = new OnClickListener() { - @Override - public void onClick(View v) { - activity.verifyOtrSessionDialog(conversation, v); - } - }; private EditMessage.OnCommitContentListener mEditorContentListener = new EditMessage.OnCommitContentListener() { @Override public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts, String[] contentMimeTypes) { @@ -316,17 +308,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } } }; - private OnClickListener mAnswerSmpClickListener = new OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(activity, VerifyOTRActivity.class); - intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT); - intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString()); - intent.putExtra(VerifyOTRActivity.EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString()); - intent.putExtra("mode", VerifyOTRActivity.MODE_ANSWER_QUESTION); - startActivity(intent); - } - }; + protected OnClickListener clickToDecryptListener = new OnClickListener() { @Override @@ -483,9 +465,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa message.setUuid(UUID.randomUUID().toString()); } switch (message.getConversation().getNextEncryption()) { - case Message.ENCRYPTION_OTR: - sendOtrMessage(message); - break; case Message.ENCRYPTION_PGP: sendPgpMessage(message); break; @@ -600,8 +579,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { fingerprint = "pgp"; - } else if (message.getEncryption() == Message.ENCRYPTION_OTR) { - fingerprint = "otr"; } else { fingerprint = message.getFingerprint(); } @@ -1114,14 +1091,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } } else if (account.hasPendingPgpIntent(conversation)) { showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener); - } else if (mode == Conversation.MODE_SINGLE - && conversation.smpRequested()) { - showSnackbar(R.string.smp_requested, R.string.verify, this.mAnswerSmpClickListener); - } else if (mode == Conversation.MODE_SINGLE - && conversation.hasValidOtrSession() - && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) - && (!conversation.isOtrFingerprintVerified())) { - showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify); } else if (connection != null && connection.getFeatures().blocking() && conversation.countMessages() != 0 @@ -1612,21 +1581,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa messageSent(); } - protected void sendOtrMessage(final Message message) { - final ConversationActivity activity = (ConversationActivity) getActivity(); - final XmppConnectionService xmppService = activity.xmppConnectionService; - activity.selectPresence(message.getConversation(), - new OnPresenceSelected() { - - @Override - public void onPresenceSelected() { - message.setCounterpart(conversation.getNextCounterpart()); - xmppService.sendMessage(message); - messageSent(); - } - }); - } - public void appendText(String text) { if (text == null) { return; diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index fc56738df..b6de29ad7 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -96,17 +96,13 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private TextView mServerInfoHttpUpload; private TextView mServerInfoPush; private TextView mSessionEst; - private TextView mOtrFingerprint; private TextView mAxolotlFingerprint; private TextView mPgpFingerprint; private TextView mOwnFingerprintDesc; - private TextView mOtrFingerprintDesc; private TextView getmPgpFingerprintDesc; private ImageView mAvatar; - private RelativeLayout mOtrFingerprintBox; private RelativeLayout mAxolotlFingerprintBox; private RelativeLayout mPgpFingerprintBox; - private ImageButton mOtrFingerprintToClipboardButton; private ImageButton mAxolotlFingerprintToClipboardButton; private ImageButton mPgpDeleteFingerprintButton; private LinearLayout keys; @@ -567,10 +563,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mPgpFingerprint = (TextView) findViewById(R.id.pgp_fingerprint); this.getmPgpFingerprintDesc = (TextView) findViewById(R.id.pgp_fingerprint_desc); this.mPgpDeleteFingerprintButton = (ImageButton) findViewById(R.id.action_delete_pgp); - this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint); - this.mOtrFingerprintDesc = (TextView) findViewById(R.id.otr_fingerprint_desc); - this.mOtrFingerprintBox = (RelativeLayout) findViewById(R.id.otr_fingerprint_box); - this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard); this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint); this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box); this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard); @@ -980,25 +972,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } else { this.mPgpFingerprintBox.setVisibility(View.GONE); } - final String otrFingerprint = this.mAccount.getOtrFingerprint(); - if (otrFingerprint != null && Config.supportOtr()) { - if ("otr".equals(messageFingerprint)) { - this.mOtrFingerprintDesc.setTextColor(ContextCompat.getColor(this, R.color.accent)); - } - this.mOtrFingerprintBox.setVisibility(View.VISIBLE); - this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint)); - this.mOtrFingerprintToClipboardButton.setVisibility(View.VISIBLE); - this.mOtrFingerprintToClipboardButton.setOnClickListener(v -> { - if (copyTextToClipboard(CryptoHelper.prettifyFingerprint(otrFingerprint), R.string.otr_fingerprint)) { - Toast.makeText( - EditAccountActivity.this, - R.string.toast_message_otr_fingerprint, - Toast.LENGTH_SHORT).show(); - } - }); - } else { - this.mOtrFingerprintBox.setVisibility(View.GONE); - } final String ownAxolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint(); if (ownAxolotlFingerprint != null && Config.supportOmemo()) { this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE); diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java index 2ff04a54e..1c954be70 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java @@ -332,8 +332,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer if (account.httpUploadAvailable() && ((share.image && !neverCompressPictures()) || conversation.getMode() == Conversation.MODE_MULTI - || FileBackend.allFilesUnderSize(this, share.uris, max)) - && conversation.getNextEncryption() != Message.ENCRYPTION_OTR) { + || FileBackend.allFilesUnderSize(this, share.uris, max))) { callback.onPresenceSelected(); } else { selectPresence(conversation, callback); diff --git a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java b/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java deleted file mode 100644 index 00d96994e..000000000 --- a/src/main/java/eu/siacs/conversations/ui/VerifyOTRActivity.java +++ /dev/null @@ -1,443 +0,0 @@ -package eu.siacs.conversations.ui; - -import android.support.v7.app.AlertDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.support.v7.app.ActionBar; -import android.view.Menu; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import net.java.otr4j.OtrException; -import net.java.otr4j.session.Session; - -import eu.siacs.conversations.R; -import eu.siacs.conversations.entities.Account; -import eu.siacs.conversations.entities.Contact; -import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.services.XmppConnectionService; -import eu.siacs.conversations.utils.CryptoHelper; -import eu.siacs.conversations.utils.XmppUri; -import eu.siacs.conversations.utils.zxing.IntentIntegrator; -import eu.siacs.conversations.utils.zxing.IntentResult; -import eu.siacs.conversations.xmpp.jid.InvalidJidException; -import eu.siacs.conversations.xmpp.jid.Jid; - -public class VerifyOTRActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate { - - public static final String ACTION_VERIFY_CONTACT = "verify_contact"; - public static final int MODE_SCAN_FINGERPRINT = - 0x0502; - public static final int MODE_ASK_QUESTION = 0x0503; - public static final int MODE_ANSWER_QUESTION = 0x0504; - public static final int MODE_MANUAL_VERIFICATION = 0x0505; - - private LinearLayout mManualVerificationArea; - private LinearLayout mSmpVerificationArea; - private TextView mRemoteFingerprint; - private TextView mYourFingerprint; - private TextView mVerificationExplain; - private TextView mStatusMessage; - private TextView mSharedSecretHint; - private EditText mSharedSecretHintEditable; - private EditText mSharedSecretSecret; - private Button mLeftButton; - private Button mRightButton; - private Account mAccount; - private Conversation mConversation; - private int mode = MODE_MANUAL_VERIFICATION; - private XmppUri mPendingUri = null; - - private DialogInterface.OnClickListener mVerifyFingerprintListener = new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialogInterface, int click) { - mConversation.verifyOtrFingerprint(); - xmppConnectionService.syncRosterToDisk(mConversation.getAccount()); - Toast.makeText(VerifyOTRActivity.this,R.string.verified,Toast.LENGTH_SHORT).show(); - finish(); - } - }; - - private View.OnClickListener mCreateSharedSecretListener = new View.OnClickListener() { - @Override - public void onClick(final View view) { - if (isAccountOnline()) { - final String question = mSharedSecretHintEditable.getText().toString(); - final String secret = mSharedSecretSecret.getText().toString(); - if (question.trim().isEmpty()) { - mSharedSecretHintEditable.requestFocus(); - mSharedSecretHintEditable.setError(getString(R.string.shared_secret_hint_should_not_be_empty)); - } else if (secret.trim().isEmpty()) { - mSharedSecretSecret.requestFocus(); - mSharedSecretSecret.setError(getString(R.string.shared_secret_can_not_be_empty)); - } else { - mSharedSecretSecret.setError(null); - mSharedSecretHintEditable.setError(null); - initSmp(question, secret); - updateView(); - } - } - } - }; - private View.OnClickListener mCancelSharedSecretListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - if (isAccountOnline()) { - abortSmp(); - updateView(); - } - } - }; - private View.OnClickListener mRespondSharedSecretListener = new View.OnClickListener() { - - @Override - public void onClick(View view) { - if (isAccountOnline()) { - final String question = mSharedSecretHintEditable.getText().toString(); - final String secret = mSharedSecretSecret.getText().toString(); - respondSmp(question, secret); - updateView(); - } - } - }; - private View.OnClickListener mRetrySharedSecretListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - mConversation.smp().status = Conversation.Smp.STATUS_NONE; - mConversation.smp().hint = null; - mConversation.smp().secret = null; - updateView(); - } - }; - private View.OnClickListener mFinishListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - mConversation.smp().status = Conversation.Smp.STATUS_NONE; - finish(); - } - }; - - protected boolean initSmp(final String question, final String secret) { - final Session session = mConversation.getOtrSession(); - if (session!=null) { - try { - session.initSmp(question, secret); - mConversation.smp().status = Conversation.Smp.STATUS_WE_REQUESTED; - mConversation.smp().secret = secret; - mConversation.smp().hint = question; - return true; - } catch (OtrException e) { - return false; - } - } else { - return false; - } - } - - protected boolean abortSmp() { - final Session session = mConversation.getOtrSession(); - if (session!=null) { - try { - session.abortSmp(); - mConversation.smp().status = Conversation.Smp.STATUS_NONE; - mConversation.smp().hint = null; - mConversation.smp().secret = null; - return true; - } catch (OtrException e) { - return false; - } - } else { - return false; - } - } - - protected boolean respondSmp(final String question, final String secret) { - final Session session = mConversation.getOtrSession(); - if (session!=null) { - try { - session.respondSmp(question,secret); - return true; - } catch (OtrException e) { - return false; - } - } else { - return false; - } - } - - protected boolean verifyWithUri(XmppUri uri) { - Contact contact = mConversation.getContact(); - if (this.mConversation.getContact().getJid().equals(uri.getJid()) && uri.hasFingerprints()) { - xmppConnectionService.verifyFingerprints(contact,uri.getFingerprints()); - Toast.makeText(this,R.string.verified,Toast.LENGTH_SHORT).show(); - updateView(); - return true; - } else { - Toast.makeText(this,R.string.could_not_verify_fingerprint,Toast.LENGTH_SHORT).show(); - return false; - } - } - - protected boolean isAccountOnline() { - if (this.mAccount.getStatus() != Account.State.ONLINE) { - Toast.makeText(this,R.string.not_connected_try_again,Toast.LENGTH_SHORT).show(); - return false; - } else { - return true; - } - } - - protected boolean handleIntent(Intent intent) { - if (intent != null && intent.getAction().equals(ACTION_VERIFY_CONTACT)) { - this.mAccount = extractAccount(intent); - if (this.mAccount == null) { - return false; - } - try { - this.mConversation = this.xmppConnectionService.find(this.mAccount,Jid.fromString(intent.getExtras().getString("contact"))); - if (this.mConversation == null) { - return false; - } - } catch (final InvalidJidException ignored) { - return false; - } - this.mode = intent.getIntExtra("mode", MODE_MANUAL_VERIFICATION); - if (this.mode == MODE_SCAN_FINGERPRINT) { - new IntentIntegrator(this).initiateScan(); - return false; - } - return true; - } else { - return false; - } - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent intent) { - if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) { - IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); - if (scanResult != null && scanResult.getFormatName() != null) { - String data = scanResult.getContents(); - XmppUri uri = new XmppUri(data); - if (xmppConnectionServiceBound) { - verifyWithUri(uri); - finish(); - } else { - this.mPendingUri = uri; - } - } else { - finish(); - } - } - super.onActivityResult(requestCode, requestCode, intent); - } - - @Override - protected void onBackendConnected() { - if (handleIntent(getIntent())) { - updateView(); - } else if (mPendingUri!=null) { - verifyWithUri(mPendingUri); - finish(); - mPendingUri = null; - } - setIntent(null); - } - - protected void updateView() { - if (this.mConversation != null && this.mConversation.hasValidOtrSession()) { - final ActionBar actionBar = getSupportActionBar(); - this.mVerificationExplain.setText(R.string.no_otr_session_found); - invalidateOptionsMenu(); - switch(this.mode) { - case MODE_ASK_QUESTION: - if (actionBar != null ) { - actionBar.setTitle(R.string.ask_question); - } - this.updateViewAskQuestion(); - break; - case MODE_ANSWER_QUESTION: - if (actionBar != null ) { - actionBar.setTitle(R.string.smp_requested); - } - this.updateViewAnswerQuestion(); - break; - case MODE_MANUAL_VERIFICATION: - default: - if (actionBar != null ) { - actionBar.setTitle(R.string.manually_verify); - } - this.updateViewManualVerification(); - break; - } - } else { - this.mManualVerificationArea.setVisibility(View.GONE); - this.mSmpVerificationArea.setVisibility(View.GONE); - } - } - - protected void updateViewManualVerification() { - this.mVerificationExplain.setText(R.string.manual_verification_explanation); - this.mManualVerificationArea.setVisibility(View.VISIBLE); - this.mSmpVerificationArea.setVisibility(View.GONE); - this.mYourFingerprint.setText(CryptoHelper.prettifyFingerprint(this.mAccount.getOtrFingerprint())); - this.mRemoteFingerprint.setText(CryptoHelper.prettifyFingerprint(this.mConversation.getOtrFingerprint())); - if (this.mConversation.isOtrFingerprintVerified()) { - deactivateButton(this.mRightButton,R.string.verified); - activateButton(this.mLeftButton,R.string.cancel,this.mFinishListener); - } else { - activateButton(this.mLeftButton,R.string.cancel,this.mFinishListener); - activateButton(this.mRightButton,R.string.verify, new View.OnClickListener() { - @Override - public void onClick(View view) { - showManuallyVerifyDialog(); - } - }); - } - } - - protected void updateViewAskQuestion() { - this.mManualVerificationArea.setVisibility(View.GONE); - this.mSmpVerificationArea.setVisibility(View.VISIBLE); - this.mVerificationExplain.setText(R.string.smp_explain_question); - final int smpStatus = this.mConversation.smp().status; - switch (smpStatus) { - case Conversation.Smp.STATUS_WE_REQUESTED: - this.mStatusMessage.setVisibility(View.GONE); - this.mSharedSecretHintEditable.setVisibility(View.VISIBLE); - this.mSharedSecretSecret.setVisibility(View.VISIBLE); - this.mSharedSecretHintEditable.setText(this.mConversation.smp().hint); - this.mSharedSecretSecret.setText(this.mConversation.smp().secret); - this.activateButton(this.mLeftButton, R.string.cancel, this.mCancelSharedSecretListener); - this.deactivateButton(this.mRightButton, R.string.in_progress); - break; - case Conversation.Smp.STATUS_FAILED: - this.mStatusMessage.setVisibility(View.GONE); - this.mSharedSecretHintEditable.setVisibility(View.VISIBLE); - this.mSharedSecretSecret.setVisibility(View.VISIBLE); - this.mSharedSecretSecret.requestFocus(); - this.mSharedSecretSecret.setError(getString(R.string.secrets_do_not_match)); - this.deactivateButton(this.mLeftButton, R.string.cancel); - this.activateButton(this.mRightButton, R.string.try_again, this.mRetrySharedSecretListener); - break; - case Conversation.Smp.STATUS_VERIFIED: - this.mSharedSecretHintEditable.setText(""); - this.mSharedSecretHintEditable.setVisibility(View.GONE); - this.mSharedSecretSecret.setText(""); - this.mSharedSecretSecret.setVisibility(View.GONE); - this.mStatusMessage.setVisibility(View.VISIBLE); - this.deactivateButton(this.mLeftButton, R.string.cancel); - this.activateButton(this.mRightButton, R.string.finish, this.mFinishListener); - break; - default: - this.mStatusMessage.setVisibility(View.GONE); - this.mSharedSecretHintEditable.setVisibility(View.VISIBLE); - this.mSharedSecretSecret.setVisibility(View.VISIBLE); - this.activateButton(this.mLeftButton,R.string.cancel,this.mFinishListener); - this.activateButton(this.mRightButton, R.string.ask_question, this.mCreateSharedSecretListener); - break; - } - } - - protected void updateViewAnswerQuestion() { - this.mManualVerificationArea.setVisibility(View.GONE); - this.mSmpVerificationArea.setVisibility(View.VISIBLE); - this.mVerificationExplain.setText(R.string.smp_explain_answer); - this.mSharedSecretHintEditable.setVisibility(View.GONE); - this.mSharedSecretHint.setVisibility(View.VISIBLE); - this.deactivateButton(this.mLeftButton, R.string.cancel); - final int smpStatus = this.mConversation.smp().status; - switch (smpStatus) { - case Conversation.Smp.STATUS_CONTACT_REQUESTED: - this.mStatusMessage.setVisibility(View.GONE); - this.mSharedSecretHint.setText(this.mConversation.smp().hint); - this.activateButton(this.mRightButton,R.string.respond,this.mRespondSharedSecretListener); - break; - case Conversation.Smp.STATUS_VERIFIED: - this.mSharedSecretHintEditable.setText(""); - this.mSharedSecretHintEditable.setVisibility(View.GONE); - this.mSharedSecretHint.setVisibility(View.GONE); - this.mSharedSecretSecret.setText(""); - this.mSharedSecretSecret.setVisibility(View.GONE); - this.mStatusMessage.setVisibility(View.VISIBLE); - this.activateButton(this.mRightButton, R.string.finish, this.mFinishListener); - break; - case Conversation.Smp.STATUS_FAILED: - default: - this.mSharedSecretSecret.requestFocus(); - this.mSharedSecretSecret.setError(getString(R.string.secrets_do_not_match)); - this.activateButton(this.mRightButton,R.string.finish,this.mFinishListener); - break; - } - } - - protected void activateButton(Button button, int text, View.OnClickListener listener) { - button.setEnabled(true); - button.setTextColor(getPrimaryTextColor()); - button.setText(text); - button.setOnClickListener(listener); - } - - protected void deactivateButton(Button button, int text) { - button.setEnabled(false); - button.setTextColor(getSecondaryTextColor()); - button.setText(text); - button.setOnClickListener(null); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_verify_otr); - this.mRemoteFingerprint = (TextView) findViewById(R.id.remote_fingerprint); - this.mYourFingerprint = (TextView) findViewById(R.id.your_fingerprint); - this.mLeftButton = (Button) findViewById(R.id.left_button); - this.mRightButton = (Button) findViewById(R.id.right_button); - this.mVerificationExplain = (TextView) findViewById(R.id.verification_explanation); - this.mStatusMessage = (TextView) findViewById(R.id.status_message); - this.mSharedSecretSecret = (EditText) findViewById(R.id.shared_secret_secret); - this.mSharedSecretHintEditable = (EditText) findViewById(R.id.shared_secret_hint_editable); - this.mSharedSecretHint = (TextView) findViewById(R.id.shared_secret_hint); - this.mManualVerificationArea = (LinearLayout) findViewById(R.id.manual_verification_area); - this.mSmpVerificationArea = (LinearLayout) findViewById(R.id.smp_verification_area); - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - super.onCreateOptionsMenu(menu); - getMenuInflater().inflate(R.menu.verify_otr, menu); - return true; - } - - private void showManuallyVerifyDialog() { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.manually_verify); - builder.setMessage(R.string.are_you_sure_verify_fingerprint); - builder.setNegativeButton(R.string.cancel, null); - builder.setPositiveButton(R.string.verify, mVerifyFingerprintListener); - builder.create().show(); - } - - @Override - protected String getShareableUri() { - if (mAccount!=null) { - return mAccount.getShareableUri(); - } else { - return ""; - } - } - - public void onConversationUpdate() { - refreshUi(); - } - - @Override - protected void refreshUiReal() { - updateView(); - } -} diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 593189195..5b26576e6 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -48,8 +48,6 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.Toast; -import net.java.otr4j.session.SessionID; - import java.io.FileNotFoundException; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -782,17 +780,7 @@ public abstract class XmppActivity extends AppCompatActivity { public void selectPresence(final Conversation conversation, final OnPresenceSelected listener) { final Contact contact = conversation.getContact(); - if (conversation.hasValidOtrSession()) { - SessionID id = conversation.getOtrSession().getSessionID(); - Jid jid; - try { - jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID()); - } catch (InvalidJidException e) { - jid = null; - } - conversation.setNextCounterpart(jid); - listener.onPresenceSelected(); - } else if (!contact.showInRoster()) { + if (!contact.showInRoster()) { showAddToRosterDialog(conversation); } else { final Presences presences = contact.getPresences(); diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index d079256e0..b6c56ff1f 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -483,8 +483,6 @@ public class UIHelper { } else { return context.getString(R.string.send_message_to_x, conversation.getName()); } - case Message.ENCRYPTION_OTR: - return context.getString(R.string.send_otr_message); case Message.ENCRYPTION_AXOLOTL: AxolotlService axolotlService = conversation.getAccount().getAxolotlService(); if (axolotlService != null && axolotlService.trustedSessionVerified(conversation)) { diff --git a/src/main/java/eu/siacs/conversations/utils/XmppUri.java b/src/main/java/eu/siacs/conversations/utils/XmppUri.java index d66094f1f..a3f8138c6 100644 --- a/src/main/java/eu/siacs/conversations/utils/XmppUri.java +++ b/src/main/java/eu/siacs/conversations/utils/XmppUri.java @@ -132,9 +132,6 @@ public class XmppUri { if (parts.length == 2) { String key = parts[0].toLowerCase(Locale.US); String value = parts[1].toLowerCase(Locale.US); - if (OTR_URI_PARAM.equals(key)) { - fingerprints.add(new Fingerprint(FingerprintType.OTR,value)); - } if (key.startsWith(OMEMO_URI_PARAM)) { try { int id = Integer.parseInt(key.substring(OMEMO_URI_PARAM.length())); @@ -213,8 +210,7 @@ public class XmppUri { return fingerprints.size() > 0; } public enum FingerprintType { - OMEMO, - OTR + OMEMO } public static String getFingerprintUri(String base, List fingerprints, char seperator) { @@ -225,8 +221,6 @@ public class XmppUri { if (type == XmppUri.FingerprintType.OMEMO) { builder.append(XmppUri.OMEMO_URI_PARAM); builder.append(fingerprints.get(i).deviceId); - } else if (type == XmppUri.FingerprintType.OTR) { - builder.append(XmppUri.OTR_URI_PARAM); } builder.append('='); builder.append(fingerprints.get(i).fingerprint); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java b/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java index 23d4c88b0..726fcc7bd 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java @@ -2,8 +2,6 @@ package eu.siacs.conversations.xmpp.jid; import android.util.LruCache; -import net.java.otr4j.session.SessionID; - import java.net.IDN; import eu.siacs.conversations.Config; @@ -51,14 +49,6 @@ public final class Jid { return resourcepart; } - public static Jid fromSessionID(final SessionID id) throws InvalidJidException{ - if (id.getUserID().isEmpty()) { - return Jid.fromString(id.getAccountID()); - } else { - return Jid.fromString(id.getAccountID()+"/"+id.getUserID()); - } - } - public static Jid fromString(final String jid) throws InvalidJidException { return Jid.fromString(jid, false); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 7d7470bcf..b43f8073a 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -404,11 +404,7 @@ public class JingleConnection implements Transferable { } else { message.setType(Message.TYPE_FILE); } - if (filename[filename.length - 1].equals("otr")) { - message.setEncryption(Message.ENCRYPTION_OTR); - } else { - message.setEncryption(Message.ENCRYPTION_PGP); - } + message.setEncryption(Message.ENCRYPTION_PGP); } } else { message.setType(Message.TYPE_FILE); @@ -418,9 +414,7 @@ public class JingleConnection implements Transferable { if (!fileNameElement.getContent().isEmpty()) { String parts[] = fileNameElement.getContent().split("/"); suffix = parts[parts.length - 1]; - if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) { - suffix = suffix.substring(0,suffix.length() - 4); - } else if (message.getEncryption() == Message.ENCRYPTION_PGP && (suffix.endsWith(".pgp") || suffix.endsWith(".gpg"))) { + if (message.getEncryption() == Message.ENCRYPTION_PGP && (suffix.endsWith(".pgp") || suffix.endsWith(".gpg"))) { suffix = suffix.substring(0,suffix.length() - 4); } } @@ -457,15 +451,6 @@ public class JingleConnection implements Transferable { } else { Log.d(Config.LOGTAG,"could not process KeyTransportMessage"); } - } else if (message.getEncryption() == Message.ENCRYPTION_OTR) { - byte[] key = conversation.getSymmetricKey(); - if (key == null) { - this.sendCancel(); - this.fail(); - return; - } else { - this.file.setKeyAndIv(key); - } } this.file.setExpectedSize(size); message.resetFileParams(); @@ -488,17 +473,7 @@ public class JingleConnection implements Transferable { this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false); Pair pair; try { - if (message.getEncryption() == Message.ENCRYPTION_OTR) { - Conversation conversation = this.message.getConversation(); - if (!this.mXmppConnectionService.renewSymmetricKey(conversation)) { - Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not set symmetric key"); - cancel(); - } - this.file.setKeyAndIv(conversation.getSymmetricKey()); - pair = AbstractConnectionManager.createInputStream(this.file, false); - this.file.setExpectedSize(pair.second); - content.setFileOffer(this.file, true, this.ftVersion); - } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { + if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { this.file.setKey(mXmppAxolotlMessage.getInnerKey()); this.file.setIv(mXmppAxolotlMessage.getIV()); pair = AbstractConnectionManager.createInputStream(this.file, true); diff --git a/src/main/res/layout/activity_edit_account.xml b/src/main/res/layout/activity_edit_account.xml index d7b8bf0cd..9d9d0619f 100644 --- a/src/main/res/layout/activity_edit_account.xml +++ b/src/main/res/layout/activity_edit_account.xml @@ -525,52 +525,6 @@ android:visibility="visible"/> - - - - - - - - - - - - -