mirror of
https://github.com/oxen-io/session-android.git
synced 2025-05-06 15:38:14 +00:00
Prevent restoring newer backups into older versions of Signal.
Relates to #8184
This commit is contained in:
parent
d2a8abe769
commit
15b4517e35
@ -1335,6 +1335,7 @@
|
|||||||
<string name="preferences_chats__create_backup">Create backup</string>
|
<string name="preferences_chats__create_backup">Create backup</string>
|
||||||
<string name="RegistrationActivity_enter_backup_passphrase">Enter backup passphrase</string>
|
<string name="RegistrationActivity_enter_backup_passphrase">Enter backup passphrase</string>
|
||||||
<string name="RegistrationActivity_restore">Restore</string>
|
<string name="RegistrationActivity_restore">Restore</string>
|
||||||
|
<string name="RegistrationActivity_backup_failure_downgrade">Cannot import backups from newer versions of Signal</string>
|
||||||
<string name="RegistrationActivity_incorrect_backup_passphrase">Incorrect backup passphrase</string>
|
<string name="RegistrationActivity_incorrect_backup_passphrase">Incorrect backup passphrase</string>
|
||||||
<string name="RegistrationActivity_checking">Checking...</string>
|
<string name="RegistrationActivity_checking">Checking...</string>
|
||||||
<string name="RegistrationActivity_d_messages_so_far">%d messages so far...</string>
|
<string name="RegistrationActivity_d_messages_so_far">%d messages so far...</string>
|
||||||
|
@ -366,9 +366,9 @@ public class RegistrationActivity extends BaseActionBarActivity implements Verif
|
|||||||
restoreButton.setIndeterminateProgressMode(true);
|
restoreButton.setIndeterminateProgressMode(true);
|
||||||
restoreButton.setProgress(50);
|
restoreButton.setProgress(50);
|
||||||
|
|
||||||
new AsyncTask<Void, Void, Boolean>() {
|
new AsyncTask<Void, Void, BackupImportResult>() {
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... voids) {
|
protected BackupImportResult doInBackground(Void... voids) {
|
||||||
try {
|
try {
|
||||||
Context context = RegistrationActivity.this;
|
Context context = RegistrationActivity.this;
|
||||||
String passphrase = prompt.getText().toString();
|
String passphrase = prompt.getText().toString();
|
||||||
@ -383,23 +383,32 @@ public class RegistrationActivity extends BaseActionBarActivity implements Verif
|
|||||||
|
|
||||||
TextSecurePreferences.setBackupEnabled(context, true);
|
TextSecurePreferences.setBackupEnabled(context, true);
|
||||||
TextSecurePreferences.setBackupPassphrase(context, passphrase);
|
TextSecurePreferences.setBackupPassphrase(context, passphrase);
|
||||||
return true;
|
return BackupImportResult.SUCCESS;
|
||||||
|
} catch (FullBackupImporter.DatabaseDowngradeException e) {
|
||||||
|
Log.w(TAG, "Failed due to the backup being from a newer version of Signal.", e);
|
||||||
|
return BackupImportResult.FAILURE_VERSION_DOWNGRADE;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
return false;
|
return BackupImportResult.FAILURE_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(@NonNull Boolean result) {
|
protected void onPostExecute(@NonNull BackupImportResult result) {
|
||||||
restoreButton.setIndeterminateProgressMode(false);
|
restoreButton.setIndeterminateProgressMode(false);
|
||||||
restoreButton.setProgress(0);
|
restoreButton.setProgress(0);
|
||||||
restoreBackupProgress.setText("");
|
restoreBackupProgress.setText("");
|
||||||
|
|
||||||
if (result) {
|
switch (result) {
|
||||||
displayInitialView(true);
|
case SUCCESS:
|
||||||
} else {
|
displayInitialView(true);
|
||||||
Toast.makeText(RegistrationActivity.this, R.string.RegistrationActivity_incorrect_backup_passphrase, Toast.LENGTH_LONG).show();
|
break;
|
||||||
|
case FAILURE_VERSION_DOWNGRADE:
|
||||||
|
Toast.makeText(RegistrationActivity.this, R.string.RegistrationActivity_backup_failure_downgrade, Toast.LENGTH_LONG).show();
|
||||||
|
break;
|
||||||
|
case FAILURE_UNKNOWN:
|
||||||
|
Toast.makeText(RegistrationActivity.this, R.string.RegistrationActivity_incorrect_backup_passphrase, Toast.LENGTH_LONG).show();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
@ -1115,4 +1124,8 @@ public class RegistrationActivity extends BaseActionBarActivity implements Verif
|
|||||||
this.gcmToken = previous.gcmToken;
|
this.gcmToken = previous.gcmToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum BackupImportResult {
|
||||||
|
SUCCESS, FAILURE_VERSION_DOWNGRADE, FAILURE_UNKNOWN
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,11 @@ public class FullBackupImporter extends FullBackupBase {
|
|||||||
EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.FINISHED, count));
|
EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.FINISHED, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processVersion(@NonNull SQLiteDatabase db, DatabaseVersion version) {
|
private static void processVersion(@NonNull SQLiteDatabase db, DatabaseVersion version) throws IOException {
|
||||||
|
if (version.getVersion() > db.getVersion()) {
|
||||||
|
throw new DatabaseDowngradeException(db.getVersion(), version.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
db.setVersion(version.getVersion());
|
db.setVersion(version.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,4 +332,9 @@ public class FullBackupImporter extends FullBackupBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class DatabaseDowngradeException extends IOException {
|
||||||
|
DatabaseDowngradeException(int currentVersion, int backupVersion) {
|
||||||
|
super("Tried to import a backup with version " + backupVersion + " into a database with version " + currentVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user