]> nmode's Git Repositories - signal-cli/commitdiff
Start preKeyIds with a random number
authorAsamK <asamk@gmx.de>
Thu, 23 Dec 2021 17:26:09 +0000 (18:26 +0100)
committerAsamK <asamk@gmx.de>
Thu, 23 Dec 2021 17:26:09 +0000 (18:26 +0100)
Fixes #842

lib/src/main/java/org/asamk/signal/manager/storage/SignalAccount.java

index 52655dfc04a8d791e5df7620b1220bf81642d5d5..67fc252958208b1a9a5558a7beb156347b592b8a 100644 (file)
@@ -61,6 +61,7 @@ import java.nio.channels.Channels;
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
+import java.security.SecureRandom;
 import java.util.Base64;
 import java.util.Date;
 import java.util.HashSet;
@@ -244,8 +245,8 @@ public class SignalAccount implements Closeable {
     }
 
     private void clearAllPreKeys() {
-        this.preKeyIdOffset = 0;
-        this.nextSignedPreKeyId = 0;
+        this.preKeyIdOffset = new SecureRandom().nextInt(Medium.MAX_VALUE);
+        this.nextSignedPreKeyId = new SecureRandom().nextInt(Medium.MAX_VALUE);
         this.preKeyStore.removeAllPreKeys();
         this.signedPreKeyStore.removeAllSignedPreKeys();
         save();
@@ -1020,6 +1021,7 @@ public class SignalAccount implements Closeable {
         this.lastReceiveTimestamp = 0;
         save();
 
+        clearAllPreKeys();
         getSessionStore().archiveAllSessions();
         senderKeyStore.deleteAll();
         final var recipientId = getRecipientStore().resolveRecipientTrusted(getSelfAddress());