Show warning before changing the encryption

This commit is contained in:
Jakob Nixdorf 2018-02-27 11:29:50 +01:00
parent 5c687f63e1
commit 002f5f1e07
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
2 changed files with 43 additions and 13 deletions

View file

@ -246,6 +246,28 @@ public class SettingsActivity extends BaseActivity
useAndroidSync.setChecked(false);
}
public void encryptionChangeWithDialog(final EncryptionType encryptionType) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.settings_dialog_title_warning)
.setMessage(R.string.settings_dialog_msg_encryption_change)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (encryptionType == EncryptionType.PASSWORD)
((SettingsActivity) getActivity()).tryEncryptionChangeWithAuth(encryptionType);
else if (encryptionType == EncryptionType.KEYSTORE)
((SettingsActivity) getActivity()).tryEncryptionChange(encryptionType, null);
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.create()
.show();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -273,22 +295,25 @@ public class SettingsActivity extends BaseActivity
public boolean onPreferenceChange(final Preference preference, Object o) {
String newEncryption = (String) o;
EncryptionType encryptionType = EncryptionType.valueOf(newEncryption.toUpperCase());
EncryptionType oldEncryptionType = settings.getEncryption();
AuthMethod authMethod = settings.getAuthMethod();
if (encryptionType == EncryptionType.PASSWORD) {
if (authMethod != AuthMethod.PASSWORD && authMethod != AuthMethod.PIN) {
UIHelper.showGenericDialog(getActivity(), R.string.settings_dialog_title_error, R.string.settings_dialog_msg_encryption_invalid_with_auth);
return false;
} else {
if (settings.getAuthCredentials().isEmpty()) {
UIHelper.showGenericDialog(getActivity(), R.string.settings_dialog_title_error, R.string.settings_dialog_msg_encryption_invalid_without_credentials);
return false;
}
}
if (encryptionType != oldEncryptionType) {
if (encryptionType == EncryptionType.PASSWORD) {
if (authMethod != AuthMethod.PASSWORD && authMethod != AuthMethod.PIN) {
UIHelper.showGenericDialog(getActivity(), R.string.settings_dialog_title_error, R.string.settings_dialog_msg_encryption_invalid_with_auth);
return false;
} else {
if (settings.getAuthCredentials().isEmpty()) {
UIHelper.showGenericDialog(getActivity(), R.string.settings_dialog_title_error, R.string.settings_dialog_msg_encryption_invalid_without_credentials);
return false;
}
}
((SettingsActivity) getActivity()).tryEncryptionChangeWithAuth(encryptionType);
} else if (encryptionType == EncryptionType.KEYSTORE) {
((SettingsActivity) getActivity()).tryEncryptionChange(encryptionType, null);
encryptionChangeWithDialog(EncryptionType.PASSWORD);
} else if (encryptionType == EncryptionType.KEYSTORE) {
encryptionChangeWithDialog(EncryptionType.KEYSTORE);
}
}
return false;

View file

@ -92,10 +92,15 @@
<string name="settings_toast_auth_upgrade_failed">Failed to silently upgrade your password / PIN
to the new encryption, please manually reset it in the Settings!</string>
<string name="settings_dialog_title_warning">Warning</string>
<string name="settings_dialog_title_error">Error</string>
<string name="settings_dialog_title_clear_keystore">Clear the KeyStore?</string>
<string name="settings_dialog_title_android_sync">Android sync</string>
<string name="settings_dialog_msg_encryption_change">andOTP will now try to change the database
encryption. In case of a failure an internal backup will be restored and the encryption
remains unchanged.\n\n<b>However, it\'s always a good idea to have a backup in case
something unexpected happens!</b></string>
<string name="settings_dialog_msg_auth_invalid_with_encryption">You can only use Password or PIN as
long as the database encryption is set to \"Password / PIN\"!</string>
<string name="settings_dialog_msg_encryption_invalid_with_auth">You first need to set the