diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java
index ec2ff77b..e74f5497 100644
--- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java
+++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java
@@ -22,6 +22,8 @@
package org.shadowice.flocke.andotp.Activities;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
@@ -117,6 +119,13 @@ public class SettingsActivity extends BaseActivity
}
}
+ private void generateNewEncryptionKey() {
+ if (settings.getEncryption() == EncryptionType.KEYSTORE) {
+ encryptionKey = KeyStoreHelper.loadEncryptionKeyFromKeyStore(this, false);
+ encryptionChanged = true;
+ }
+ }
+
private void tryEncryptionChangeWithAuth(EncryptionType newEnc) {
Intent authIntent = new Intent(this, AuthenticateActivity.class);
authIntent.putExtra(Constants.EXTRA_AUTH_NEW_ENCRYPTION, newEnc.name());
@@ -271,6 +280,40 @@ public class SettingsActivity extends BaseActivity
if (sharedPref.contains(getString(R.string.settings_key_special_features)) &&
sharedPref.getBoolean(getString(R.string.settings_key_special_features), false)) {
addPreferencesFromResource(R.xml.preferences_special);
+
+ Preference clearKeyStore = findPreference(getString(R.string.settings_key_clear_keystore));
+ clearKeyStore.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+
+ builder.setTitle(R.string.settings_dialog_title_clear_keystore);
+ if (settings.getEncryption() == EncryptionType.PASSWORD)
+ builder.setMessage(R.string.settings_dialog_msg_clear_keystore_password);
+ else if (settings.getEncryption() == EncryptionType.KEYSTORE)
+ builder.setMessage(R.string.settings_dialog_msg_clear_keystore_keystore);
+
+ builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ KeyStoreHelper.wipeKeys(getActivity());
+ if (settings.getEncryption() == EncryptionType.KEYSTORE) {
+ DatabaseHelper.wipeDatabase(getActivity());
+ ((SettingsActivity) getActivity()).generateNewEncryptionKey();
+ }
+ }
+ });
+ builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ }
+ });
+
+ builder.create().show();
+
+ return false;
+ }
+ });
}
}
}
diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/DatabaseHelper.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/DatabaseHelper.java
index ba15808d..ef0d561e 100644
--- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/DatabaseHelper.java
+++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/DatabaseHelper.java
@@ -44,7 +44,9 @@ public class DatabaseHelper {
public static void wipeDatabase(Context context) {
File db = new File(context.getFilesDir() + "/" + Constants.FILENAME_DATABASE);
+ File dbBackup = new File(context.getFilesDir() + "/" + Constants.FILENAME_DATABASE_BACKUP);
db.delete();
+ dbBackup.delete();
}
private static void copyFile(File src, File dst)
diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml
index 99e8ff0d..67bdb7c2 100644
--- a/app/src/main/res/values/settings.xml
+++ b/app/src/main/res/values/settings.xml
@@ -42,6 +42,7 @@
pref_tags_toggles
pref_enable_screenshot
+ pref_clear_keystore
pref_last_used_dialog_shown
diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml
index 60cfee12..be0830d5 100644
--- a/app/src/main/res/values/strings_settings.xml
+++ b/app/src/main/res/values/strings_settings.xml
@@ -33,6 +33,7 @@
Enable special features
Enable screenshots
+ Clear KeyStore
Hide the OTP tokens by default, requiring them to be
@@ -55,9 +56,10 @@
Encrypted backups are only imported if they are
signed with a valid key
+ Uncheck to disable the special features again
Allow to take screenshots of the main screen
(disabled by default for security reasons)
- Uncheck to disable the special features again
+ Delete the encryption key from the KeyStore
This feature requires at least Android 5.0
@@ -89,6 +91,19 @@
Failed to silently upgrade your password / PIN
to the new encryption, please manually reset it in the settings!
+ Clear the KeyStore?
+
+ In some cases clearing the KeyStore
+ can help resolve problems. You should only proceed if you know what you are doing!\n\nSince
+ the Database encryption is set to Password / PIN you shouldn\'t lose any data
+ doing this (but it never hurts to have a backup anyways).\n\nAre you really sure you want
+ to clear the KeyStore?
+ In some cases clearing the KeyStore
+ can help resolve problems. You should only proceed if you know what you are doing!\n\nWarning:
+ Since the Database encryption is set to Android KeyStore you will lose all
+ your accounts. Make sure you have a backup!\n\nAre you really sure you want to clear the
+ KeyStore?
+
- None
diff --git a/app/src/main/res/xml/preferences_special.xml b/app/src/main/res/xml/preferences_special.xml
index cea59bbe..d154d67e 100644
--- a/app/src/main/res/xml/preferences_special.xml
+++ b/app/src/main/res/xml/preferences_special.xml
@@ -17,6 +17,11 @@
android:summary="@string/settings_desc_enable_screenshot"
android:defaultValue="false" />
+
+
\ No newline at end of file