mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-26 09:59:28 +00:00
Archive sessions and generate new registration id on re-register
Fixes #6703 // FREEBIE
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -41,6 +41,9 @@ public class SessionUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void archiveAllSessions(Context context) {
|
||||
new TextSecureSessionStore(context).archiveAllSessions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user