diff options
Diffstat (limited to 'src/main/java/de')
9 files changed, 33 insertions, 25 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/ServiceDiscoveryResult.java b/src/main/java/de/pixart/messenger/entities/ServiceDiscoveryResult.java index b0c3ebb77..dda221fdc 100644 --- a/src/main/java/de/pixart/messenger/entities/ServiceDiscoveryResult.java +++ b/src/main/java/de/pixart/messenger/entities/ServiceDiscoveryResult.java @@ -16,6 +16,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.forms.Data; import de.pixart.messenger.xmpp.forms.Field; @@ -133,7 +134,7 @@ public class ServiceDiscoveryResult { if (element.getAttribute("var") != null) { features.add(element.getAttribute("var")); } - } else if (element.getName().equals("x") && "jabber:x:data".equals(element.getAttribute("xmlns"))) { + } else if (element.getName().equals("x") && element.getAttribute("xmlns").equals(Namespace.DATA)) { forms.add(Data.parse(element)); } } diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java index 658230e3f..8a1d37a3f 100644 --- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java @@ -11,7 +11,9 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import javax.net.ssl.HttpsURLConnection; @@ -32,12 +34,17 @@ import de.pixart.messenger.xmpp.stanzas.IqPacket; public class HttpUploadConnection implements Transferable { + private static final List<String> WHITE_LISTED_HEADERS = Arrays.asList( + "Authorization", + "Cookie", + "Expires" + ); + private HttpConnectionManager mHttpConnectionManager; private XmppConnectionService mXmppConnectionService; private boolean canceled = false; private boolean delayed = false; - private Account account; private DownloadableFile file; private Message message; private String mime; @@ -95,7 +102,7 @@ public class HttpUploadConnection implements Transferable { public void init(Message message, boolean delay) { this.message = message; - this.account = message.getConversation().getAccount(); + final Account account = message.getConversation().getAccount(); this.file = mXmppConnectionService.getFileBackend().getFile(message, false); if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { this.mime = "application/pgp-encrypted"; @@ -123,7 +130,7 @@ public class HttpUploadConnection implements Transferable { this.mFileInputStream = pair.first; Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD); IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime); - mXmppConnectionService.sendIqPacket(account, request, (account, packet) -> { + mXmppConnectionService.sendIqPacket(account, request, (a, packet) -> { if (packet.getType() == IqPacket.TYPE.RESULT) { Element slot = packet.findChild("slot", Namespace.HTTP_UPLOAD); if (slot != null) { @@ -138,10 +145,10 @@ public class HttpUploadConnection implements Transferable { this.mPutHeaders = new HashMap<>(); for (Element child : put.getChildren()) { if ("header".equals(child.getName())) { - String name = child.getAttribute("name"); - String value = child.getContent(); - if (name != null && value != null && !name.trim().contains("\n") && !value.trim().contains("\n")) { - this.mPutHeaders.put(name.trim(), value.trim()); + final String name = child.getAttribute("name"); + final String value = child.getContent(); + if (WHITE_LISTED_HEADERS.contains(name) && value != null && !value.trim().contains("\n")) { + this.mPutHeaders.put(name, value.trim()); } } } diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index 82810bc1c..f0b804306 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -440,7 +440,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece return; } status = Message.STATUS_RECEIVED; - if (conversation.findMessageWithRemoteId(remoteMsgId, counterpart) != null) { + if (remoteMsgId != null && conversation.findMessageWithRemoteId(remoteMsgId, counterpart) != null) { return; } } diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 0af1b1567..3fe5ea9f1 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -2777,7 +2777,7 @@ public class XmppConnectionService extends Service { } } } - Element form = query.findChild("x", "jabber:x:data"); + Element form = query.findChild("x", Namespace.DATA); if (form != null) { conversation.getMucOptions().updateFormData(Data.parse(form)); } @@ -2807,7 +2807,7 @@ public class XmppConnectionService extends Service { if (packet.getType() == IqPacket.TYPE.RESULT) { Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub#owner"); Element configuration = pubsub == null ? null : pubsub.findChild("configure"); - Element x = configuration == null ? null : configuration.findChild("x", "jabber:x:data"); + Element x = configuration == null ? null : configuration.findChild("x", Namespace.DATA); if (x != null) { Data data = Data.parse(x); data.submit(options); @@ -2839,7 +2839,7 @@ public class XmppConnectionService extends Service { @Override public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE.RESULT) { - Data data = Data.parse(packet.query().findChild("x", "jabber:x:data")); + Data data = Data.parse(packet.query().findChild("x", Namespace.DATA)); data.submit(options); IqPacket set = new IqPacket(IqPacket.TYPE.SET); set.setTo(conversation.getJid().toBareJid()); diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index 38a7689bf..ca435d6a5 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -586,10 +586,11 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp }); } } - if (Config.supportOmemo()) { + final AxolotlService axolotlService = contact.getAccount().getAxolotlService(); + if (Config.supportOmemo() && axolotlService != null) { boolean skippedInactive = false; boolean showsInactive = false; - for (final XmppAxolotlSession session : contact.getAccount().getAxolotlService().findSessionsForContact(contact)) { + for (final XmppAxolotlSession session : axolotlService.findSessionsForContact(contact)) { final FingerprintStatus trust = session.getTrust(); hasKeys |= !trust.isCompromised(); if (!trust.isActive()) { diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 24218be4e..c94ceb44b 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -326,7 +326,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat xmppConnectionService.deleteAccount(mAccount); } if (xmppConnectionService.getAccounts().size() == 0) { - xmppConnectionService.deleteAccount(mAccount); Intent intent = new Intent(EditAccountActivity.this, WelcomeActivity.class); WelcomeActivity.addInviteUri(intent, getIntent()); startActivity(intent); diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java index 679fc191f..2d6b4708f 100644 --- a/src/main/java/de/pixart/messenger/utils/Namespace.java +++ b/src/main/java/de/pixart/messenger/utils/Namespace.java @@ -10,6 +10,7 @@ public final class Namespace { public static final String MAM = "urn:xmpp:mam:2"; public static final String MAM_LEGACY = "urn:xmpp:mam:0"; public static final String IDLE = "urn:xmpp:idle:1"; + public static final String DATA = "jabber:x:data"; public static final String OOB = "jabber:x:oob"; public static final String SASL = "urn:ietf:params:xml:ns:xmpp-sasl"; public static final String TLS = "urn:ietf:params:xml:ns:xmpp-tls"; diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index f7c80d841..e37719533 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -904,22 +904,20 @@ public class XmppConnection implements Runnable { } } - private void processStreamFeatures(final Tag currentTag) - throws XmlPullParserException, IOException { + private void processStreamFeatures(final Tag currentTag) throws XmlPullParserException, IOException { this.streamFeatures = tagReader.readElement(currentTag); + final boolean isSecure = features.encryptionEnabled || Config.ALLOW_NON_TLS_CONNECTIONS; if (this.streamFeatures.hasChild("starttls") && !features.encryptionEnabled) { sendStartTLS(); } else if (this.streamFeatures.hasChild("register") && account.isOptionSet(Account.OPTION_REGISTER)) { - if (features.encryptionEnabled || Config.ALLOW_NON_TLS_CONNECTIONS) { + if (isSecure) { sendRegistryRequest(); } else { throw new StateChangingException(Account.State.INCOMPATIBLE_SERVER); } } else if (!this.streamFeatures.hasChild("register") && account.isOptionSet(Account.OPTION_REGISTER)) { throw new StateChangingException(Account.State.REGISTRATION_NOT_SUPPORTED); - } else if (this.streamFeatures.hasChild("mechanisms") - && shouldAuthenticate - && (features.encryptionEnabled || Config.ALLOW_NON_TLS_CONNECTIONS)) { + } else if (this.streamFeatures.hasChild("mechanisms") && shouldAuthenticate && isSecure) { authenticate(); } else if (this.streamFeatures.hasChild("sm", "urn:xmpp:sm:" + smVersion) && streamId != null) { if (Config.EXTENDED_SM_LOGGING) { @@ -930,7 +928,7 @@ public class XmppConnection implements Runnable { this.mWaitingForSmCatchup.set(true); this.tagWriter.writeStanzaAsync(resume); } else if (needsBinding) { - if (this.streamFeatures.hasChild("bind")) { + if (this.streamFeatures.hasChild("bind") && isSecure) { sendBindRequest(); } else { throw new StateChangingException(Account.State.INCOMPATIBLE_SERVER); @@ -1007,8 +1005,8 @@ public class XmppConnection implements Runnable { register.query().addChild(password); register.setFrom(account.getJid().toBareJid()); sendUnmodifiedIqPacket(register, registrationResponseListener); - } else if (query.hasChild("x", "jabber:x:data")) { - final Data data = Data.parse(query.findChild("x", "jabber:x:data")); + } else if (query.hasChild("x", Namespace.DATA)) { + final Data data = Data.parse(query.findChild("x", Namespace.DATA)); final Element blob = query.findChild("data", "urn:xmpp:bob"); final String id = packet.getId(); InputStream is; diff --git a/src/main/java/de/pixart/messenger/xmpp/forms/Data.java b/src/main/java/de/pixart/messenger/xmpp/forms/Data.java index ed426f397..ba70a5d1a 100644 --- a/src/main/java/de/pixart/messenger/xmpp/forms/Data.java +++ b/src/main/java/de/pixart/messenger/xmpp/forms/Data.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import de.pixart.messenger.utils.Namespace; import de.pixart.messenger.xml.Element; public class Data extends Element { @@ -15,7 +16,7 @@ public class Data extends Element { public Data() { super("x"); - this.setAttribute("xmlns", "jabber:x:data"); + this.setAttribute("xmlns", Namespace.DATA); } public List<Field> getFields() { |