handle pre key messages in dtls verification

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/Config.java                        | 1 
src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java | 9 
2 files changed, 8 insertions(+), 2 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/Config.java 🔗

@@ -102,6 +102,7 @@ public final class Config {
     public static final boolean REMOVE_BROKEN_DEVICES = false;
     public static final boolean OMEMO_PADDING = false;
     public static final boolean PUT_AUTH_TAG_INTO_KEY = true;
+    public static final boolean AUTOMATICALLY_COMPLETE_SESSIONS = true;
 
     public static final boolean USE_BOOKMARKS2 = false;
 

src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java 🔗

@@ -1264,6 +1264,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
                     new RtpContentMap.DescriptionTransport(descriptionTransport.description, decryptedTransport.payload)
             );
         }
+        processPostponed();
         return new OmemoVerifiedPayload<>(
                 omemoVerification,
                 new RtpContentMap(omemoVerifiedRtpContentMap.group, descriptionTransportBuilder.build())
@@ -1283,6 +1284,10 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
                 final XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(encrypted, from.asBareJid());
                 final XmppAxolotlSession session = getReceivingSession(xmppAxolotlMessage);
                 final XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintext = xmppAxolotlMessage.decrypt(session, getOwnDeviceId());
+                final Integer preKeyId = session.getPreKeyIdAndReset();
+                if (preKeyId != null) {
+                    postponedSessions.add(session);
+                }
                 fingerprint.setContent(plaintext.getPlaintext());
                 omemoVerification.setDeviceId(session.getRemoteAddress().getDeviceId());
                 omemoVerification.setSessionFingerprint(plaintext.getFingerprint());
@@ -1414,7 +1419,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
             } else {
                 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": nothing to flush. Not republishing key");
             }
-            if (trustedOrPreviouslyResponded(session)) {
+            if (trustedOrPreviouslyResponded(session) && Config.AUTOMATICALLY_COMPLETE_SESSIONS) {
                 completeSession(session);
             }
         }
@@ -1429,7 +1434,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
         final Iterator<XmppAxolotlSession> iterator = postponedSessions.iterator();
         while (iterator.hasNext()) {
             final XmppAxolotlSession session = iterator.next();
-            if (trustedOrPreviouslyResponded(session)) {
+            if (trustedOrPreviouslyResponded(session) && Config.AUTOMATICALLY_COMPLETE_SESSIONS) {
                 completeSession(session);
             }
             iterator.remove();