diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-12-14 20:34:49 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-12-14 20:34:49 +0100 |
commit | 1939d2cade379c23bdca08aacaf22c8bff317016 (patch) | |
tree | 7fd9b53eca70fef9fa255c2f3d98f8c06e84b7af /src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java | |
parent | f496fc8fedaef0eb7655e7032d9e19c570095559 (diff) |
postpone prekey removal and republish to after mam
Diffstat (limited to 'src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java b/src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java index 0f7823d2d..6b8468af2 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/SQLiteAxolotlStore.java @@ -16,6 +16,7 @@ import org.whispersystems.libsignal.state.SignedPreKeyRecord; import org.whispersystems.libsignal.util.KeyHelper; import java.security.cert.X509Certificate; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -55,6 +56,8 @@ public class SQLiteAxolotlStore implements SignalProtocolStore { private int localRegistrationId; private int currentPreKeyId = 0; + private final HashSet<Integer> preKeysMarkedForRemoval = new HashSet<>(); + private final LruCache<String, FingerprintStatus> trustCache = new LruCache<String, FingerprintStatus>(NUM_TRUSTS_TO_CACHE) { @Override @@ -180,7 +183,7 @@ public class SQLiteAxolotlStore implements SignalProtocolStore { * <p/> * Store a remote client's identity key as trusted. * - * @param address The address of the remote client. + * @param address The address of the remote client. * @param identityKey The remote client's identity key. * @return true on success */ @@ -215,7 +218,6 @@ public class SQLiteAxolotlStore implements SignalProtocolStore { * store. Only if it mismatches an entry in the local store is it considered * 'untrusted.' * - * @param name The name of the remote client. * @param identityKey The identity key to verify. * @return true if trusted, false if untrusted. */ @@ -284,6 +286,7 @@ public class SQLiteAxolotlStore implements SignalProtocolStore { new SignalProtocolAddress(name, 0)); } + public List<String> getKnownAddresses() { return mXmppConnectionService.databaseBackend.getKnownSignalAddresses(account); } @@ -386,7 +389,23 @@ public class SQLiteAxolotlStore implements SignalProtocolStore { */ @Override public void removePreKey(int preKeyId) { - mXmppConnectionService.databaseBackend.deletePreKey(account, preKeyId); + Log.d(Config.LOGTAG, "mark prekey for removal " + preKeyId); + synchronized (preKeysMarkedForRemoval) { + preKeysMarkedForRemoval.add(preKeyId); + } + } + + + public boolean flushPreKeys() { + Log.d(Config.LOGTAG, "flushing pre keys"); + int count = 0; + synchronized (preKeysMarkedForRemoval) { + for (Integer preKeyId : preKeysMarkedForRemoval) { + count += mXmppConnectionService.databaseBackend.deletePreKey(account, preKeyId); + } + preKeysMarkedForRemoval.clear(); + } + return count > 0; } // -------------------------------------- @@ -456,4 +475,4 @@ public class SQLiteAxolotlStore implements SignalProtocolStore { public void preVerifyFingerprint(Account account, String name, String fingerprint) { mXmppConnectionService.databaseBackend.storePreVerification(account, name, fingerprint, FingerprintStatus.createInactiveVerified()); } -} +}
\ No newline at end of file |