aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-09-19 11:35:17 +0200
committerChristian Schneppe <christian@pix-art.de>2019-09-19 11:35:17 +0200
commit2a55037993f2397a2f8bf6f6a99fdd8f26a5a348 (patch)
treeec3234a66ead4cf8fa2b9414deaa82453548e6bd /src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
parentf65fa8fb0bea4ba367a6262a6112547903729162 (diff)
do not finish or repair sessions for untrusted senders
finishing (sending a key transport message in response to pre key message) as well as reparing sessions will leak resource and availability and might in certain situations in group chat leak the Jabber ID. Therefor we disable that. Leaking resource might not be considered harmful by a lot of people however we have always doing similar things with receipts.
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
index f45668c49..c6f5ea7f9 100644
--- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
@@ -66,8 +66,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
public static final String LOGPREFIX = "AxolotlService";
- public static final int NUM_KEYS_TO_PUBLISH = 100;
- public static final int publishTriesThreshold = 3;
+ private static final int NUM_KEYS_TO_PUBLISH = 100;
+ private static final int publishTriesThreshold = 3;
private final Account account;
private final XmppConnectionService mXmppConnectionService;
@@ -1480,7 +1480,9 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
} else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": nothing to flush. Not republishing key");
}
- completeSession(session);
+ if (trustedOrPreviouslyResponded(session)) {
+ completeSession(session);
+ }
}
}
@@ -1490,23 +1492,43 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
publishBundlesIfNeeded(false, false);
}
}
- Iterator<XmppAxolotlSession> iterator = postponedSessions.iterator();
+ final Iterator<XmppAxolotlSession> iterator = postponedSessions.iterator();
while (iterator.hasNext()) {
- completeSession(iterator.next());
+ final XmppAxolotlSession session = iterator.next();
+ if (trustedOrPreviouslyResponded(session)) {
+ completeSession(iterator.next());
+ }
iterator.remove();
}
- Iterator<SignalProtocolAddress> postponedHealingAttemptsIterator = postponedHealing.iterator();
+ final Iterator<SignalProtocolAddress> postponedHealingAttemptsIterator = postponedHealing.iterator();
while (postponedHealingAttemptsIterator.hasNext()) {
notifyRequiresHealing(postponedHealingAttemptsIterator.next());
postponedHealingAttemptsIterator.remove();
}
}
+ private boolean trustedOrPreviouslyResponded(XmppAxolotlSession session) {
+ try {
+ return trustedOrPreviouslyResponded(Jid.of(session.getRemoteAddress().getName()));
+ } catch (IllegalArgumentException e) {
+ return false;
+ }
+ }
+
+ public boolean trustedOrPreviouslyResponded(Jid jid) {
+ final Contact contact = account.getRoster().getContact(jid);
+ if (contact.showInRoster() || contact.isSelf()) {
+ return true;
+ }
+ final Conversation conversation = mXmppConnectionService.find(account, jid);
+ return conversation != null && conversation.sentMessagesCount() > 0;
+ }
+
private void completeSession(XmppAxolotlSession session) {
final XmppAxolotlMessage axolotlMessage = new XmppAxolotlMessage(account.getJid().asBareJid(), getOwnDeviceId());
axolotlMessage.addDevice(session, true);
try {
- Jid jid = Jid.of(session.getRemoteAddress().getName());
+ final Jid jid = Jid.of(session.getRemoteAddress().getName());
MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateKeyTransportMessage(jid, axolotlMessage);
mXmppConnectionService.sendMessagePacket(account, packet);
} catch (IllegalArgumentException e) {
@@ -1516,9 +1538,8 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
public XmppAxolotlMessage.XmppAxolotlKeyTransportMessage processReceivingKeyTransportMessage(XmppAxolotlMessage message, final boolean postponePreKeyMessageHandling) {
- XmppAxolotlMessage.XmppAxolotlKeyTransportMessage keyTransportMessage;
-
- XmppAxolotlSession session = getReceivingSession(message);
+ final XmppAxolotlMessage.XmppAxolotlKeyTransportMessage keyTransportMessage;
+ final XmppAxolotlSession session = getReceivingSession(message);
try {
keyTransportMessage = message.getParameters(session, getOwnDeviceId());
Integer preKeyId = session.getPreKeyIdAndReset();
@@ -1527,7 +1548,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}
} catch (CryptoFailedException e) {
Log.d(Config.LOGTAG, "could not decrypt keyTransport message " + e.getMessage());
- keyTransportMessage = null;
+ return null;
}
if (session.isFresh() && keyTransportMessage != null) {
@@ -1538,7 +1559,6 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}
private void putFreshSession(XmppAxolotlSession session) {
- Log.d(Config.LOGTAG, "put fresh session");
sessions.put(session);
if (Config.X509_VERIFICATION) {
if (session.getIdentityKey() != null) {