add explicit error message for outdated backup files

This commit is contained in:
Daniel Gultsch 2023-09-20 17:00:04 +02:00
parent b4c3334d7e
commit 8ba90f266e
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
3 changed files with 18 additions and 8 deletions

View file

@ -30,6 +30,7 @@ import eu.siacs.conversations.databinding.DialogEnterPasswordBinding;
import eu.siacs.conversations.services.ImportBackupService;
import eu.siacs.conversations.ui.adapter.BackupFileAdapter;
import eu.siacs.conversations.ui.util.SettingsUtils;
import eu.siacs.conversations.utils.BackupFileHeader;
import eu.siacs.conversations.utils.ThemeHelper;
public class ImportBackupActivity extends ActionBarActivity implements ServiceConnection, ImportBackupService.OnBackupFilesLoaded, BackupFileAdapter.OnItemClickedListener, ImportBackupService.OnBackupProcessed {
@ -131,6 +132,8 @@ public class ImportBackupActivity extends ActionBarActivity implements ServiceCo
try {
final ImportBackupService.BackupFile backupFile = ImportBackupService.BackupFile.read(this, uri);
showEnterPasswordDialog(backupFile, finishOnCancel);
} catch (final BackupFileHeader.OutdatedBackupFileVersion e) {
Snackbar.make(binding.coordinator, R.string.outdated_backup_file_format, Snackbar.LENGTH_LONG).show();
} catch (final IOException | IllegalArgumentException e) {
Log.d(Config.LOGTAG, "unable to open backup file " + uri, e);
Snackbar.make(binding.coordinator, R.string.not_a_backup_file, Snackbar.LENGTH_LONG).show();

View file

@ -50,17 +50,19 @@ public class BackupFileHeader {
public static BackupFileHeader read(DataInputStream inputStream) throws IOException {
final int version = inputStream.readInt();
final String app = inputStream.readUTF();
final String jid = inputStream.readUTF();
long timestamp = inputStream.readLong();
final byte[] iv = new byte[12];
inputStream.readFully(iv);
final byte[] salt = new byte[16];
inputStream.readFully(salt);
if (version < VERSION) {
throw new OutdatedBackupFileVersion();
}
if (version != VERSION) {
throw new IllegalArgumentException("Backup File version was " + version + " but app only supports version " + VERSION);
}
String app = inputStream.readUTF();
String jid = inputStream.readUTF();
long timestamp = inputStream.readLong();
byte[] iv = new byte[12];
inputStream.readFully(iv);
byte[] salt = new byte[16];
inputStream.readFully(salt);
return new BackupFileHeader(app, Jid.of(jid), timestamp, iv, salt);
}
@ -84,4 +86,8 @@ public class BackupFileHeader {
public long getTimestamp() {
return timestamp;
}
public static class OutdatedBackupFileVersion extends RuntimeException {
}
}

View file

@ -894,6 +894,7 @@
<string name="event">Event</string>
<string name="open_backup">Open backup</string>
<string name="not_a_backup_file">The file you selected is not a Conversations backup file</string>
<string name="outdated_backup_file_format">You are trying to import an outdated backup file format</string>
<string name="account_already_setup">This account has already been setup</string>
<string name="please_enter_password">Please enter the password for this account</string>
<string name="unable_to_perform_this_action">Could not perform this action</string>