Archive sessions and generate new registration id on re-register

Fixes #6703
// FREEBIE
This commit is contained in:
Moxie Marlinspike
2017-07-05 13:12:59 -07:00
parent 39b95ca4ed
commit 2c4c0f1349
9 changed files with 39 additions and 52 deletions

View File

@@ -91,26 +91,6 @@ public class PreKeyUtil {
}
}
public static PreKeyRecord generateLastResortKey(Context context) {
PreKeyStore preKeyStore = new TextSecurePreKeyStore(context);
if (preKeyStore.containsPreKey(Medium.MAX_VALUE)) {
try {
return preKeyStore.loadPreKey(Medium.MAX_VALUE);
} catch (InvalidKeyIdException e) {
Log.w("PreKeyUtil", e);
preKeyStore.removePreKey(Medium.MAX_VALUE);
}
}
ECKeyPair keyPair = Curve.generateKeyPair();
PreKeyRecord record = new PreKeyRecord(Medium.MAX_VALUE, keyPair);
preKeyStore.storePreKey(Medium.MAX_VALUE, record);
return record;
}
private static synchronized void setNextPreKeyId(Context context, int id) {
try {
File nextFile = new File(getPreKeysDirectory(context), PreKeyIndex.FILE_NAME);

View File

@@ -41,6 +41,9 @@ public class SessionUtil {
}
}
}
}
public static void archiveAllSessions(Context context) {
new TextSecureSessionStore(context).archiveAllSessions();
}
}

View File

@@ -175,6 +175,24 @@ public class TextSecureSessionStore implements SessionStore {
}
}
public void archiveAllSessions() {
synchronized (FILE_LOCK) {
File directory = getSessionDirectory();
for (File session : directory.listFiles()) {
if (session.isFile()) {
SignalProtocolAddress address = getAddressName(session);
if (address != null) {
SessionRecord sessionRecord = loadSession(address);
sessionRecord.archiveCurrentState();
storeSession(address, sessionRecord);
}
}
}
}
}
private File getSessionFile(SignalProtocolAddress address) {
return new File(getSessionDirectory(), getSessionName(address));
}