aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/crypto/axolotl
diff options
context:
space:
mode:
authorAndreas Straub <andy@strb.org>2015-07-03 13:34:34 +0200
committerAndreas Straub <andy@strb.org>2015-07-19 21:32:27 +0200
commitbf4185ac08a42e9d16bf1e2fc0126bff467a55be (patch)
tree872f6dcf17b076e927081c4ed6afd4f868eeba0d /src/main/java/eu/siacs/conversations/crypto/axolotl
parent69600502d217334031732cef2e80ebd4461e522d (diff)
Refresh PEP on session establish
We now track preKeys used to establish incoming sessions with us. On each new established session, we remove the used prekey from PEP. We have to do this because libaxolotl-java internally clears the used preKey from its storage, so we will not be able to establish any future sessions using that key.
Diffstat (limited to 'src/main/java/eu/siacs/conversations/crypto/axolotl')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
index d79fa1bf..420c75b5 100644
--- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java
@@ -444,6 +444,7 @@ public class AxolotlService {
public static class XmppAxolotlSession {
private SessionCipher cipher;
private boolean isTrusted = false;
+ private Integer preKeyId = null;
private SQLiteAxolotlStore sqLiteAxolotlStore;
private AxolotlAddress remoteAddress;
@@ -463,6 +464,14 @@ public class AxolotlService {
return this.isTrusted;
}
+ public Integer getPreKeyId() {
+ return preKeyId;
+ }
+
+ public void resetPreKeyId() {
+ preKeyId = null;
+ }
+
public byte[] processReceiving(XmppAxolotlMessage.XmppAxolotlMessageHeader incomingHeader) {
byte[] plaintext = null;
try {
@@ -470,6 +479,9 @@ public class AxolotlService {
PreKeyWhisperMessage message = new PreKeyWhisperMessage(incomingHeader.getContents());
Log.d(Config.LOGTAG, "PreKeyWhisperMessage ID:" + message.getSignedPreKeyId() + "/" + message.getPreKeyId());
plaintext = cipher.decrypt(message);
+ if (message.getPreKeyId().isPresent()) {
+ preKeyId = message.getPreKeyId().get();
+ }
} catch (InvalidMessageException | InvalidVersionException e) {
WhisperMessage message = new WhisperMessage(incomingHeader.getContents());
plaintext = cipher.decrypt(message);
@@ -946,6 +958,12 @@ public class AxolotlService {
Log.d(Config.LOGTAG, "Got payload key from axolotl header. Decrypting message...");
plaintextMessage = message.decrypt(session, payloadKey);
}
+ Integer preKeyId = session.getPreKeyId();
+ if (preKeyId != null) {
+ publishBundlesIfNeeded();
+ session.resetPreKeyId();
+ }
+ break;
}
}