mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Remove thread when typing
This commit is contained in:
@@ -60,7 +60,6 @@ import com.keepassdroid.settings.PrefsUtil;
|
||||
import com.keepassdroid.utils.EmptyUtils;
|
||||
import com.keepassdroid.utils.MenuUtil;
|
||||
import com.keepassdroid.utils.UriUtil;
|
||||
import com.keepassdroid.utils.Util;
|
||||
import com.keepassdroid.view.FingerPrintDialog;
|
||||
import com.keepassdroid.view.KeyFileHelper;
|
||||
import com.kunzisoft.keepass.KeePass;
|
||||
@@ -92,6 +91,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
|
||||
private int mode;
|
||||
private static final String PREF_KEY_VALUE_PREFIX = "valueFor_"; // key is a combination of db file name and this prefix
|
||||
private static final String PREF_KEY_IV_PREFIX = "ivFor_"; // key is a combination of db file name and this prefix
|
||||
private String prefFingerprintKey;
|
||||
|
||||
private View fingerprintContainerView;
|
||||
private View fingerprintImageView;
|
||||
@@ -238,6 +238,8 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
prefFingerprintKey = getPreferenceKeyValue();
|
||||
|
||||
// If the application was shutdown make sure to clear the password field, if it
|
||||
// was saved in the instance state
|
||||
if (App.isShutdown()) {
|
||||
@@ -317,11 +319,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
|
||||
final boolean validInput = s.length() > 0;
|
||||
// encrypt or decrypt mode based on how much input or not
|
||||
setFingerPrintTextView(validInput ? R.string.store_with_fingerprint : R.string.scanning_fingerprint);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
mode = validInput ? toggleMode(Cipher.ENCRYPT_MODE) : toggleMode(Cipher.DECRYPT_MODE);
|
||||
}
|
||||
}).start();
|
||||
mode = validInput ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -363,7 +361,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
|
||||
} else if (mode == Cipher.DECRYPT_MODE) {
|
||||
|
||||
// retrieve the encrypted value from preferences
|
||||
final String encryptedValue = prefsNoBackup.getString(getPreferenceKeyValue(), null);
|
||||
final String encryptedValue = prefsNoBackup.getString(prefFingerprintKey, null);
|
||||
if (encryptedValue != null) {
|
||||
fingerPrintHelper.decryptData(encryptedValue);
|
||||
}
|
||||
@@ -476,7 +474,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
|
||||
setFingerPrintAlphaImageView(1f);
|
||||
|
||||
// fingerprint available but no stored password found yet for this DB so show info don't listen
|
||||
if (prefsNoBackup.getString(getPreferenceKeyValue(), null) == null) {
|
||||
if (prefsNoBackup.getString(prefFingerprintKey, null) == null) {
|
||||
setFingerPrintTextView(R.string.no_password_stored);
|
||||
}
|
||||
// all is set here so we can confirm to user and start listening for fingerprints
|
||||
|
||||
@@ -45,7 +45,7 @@ import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
public class FingerPrintHelper {
|
||||
|
||||
private static final String ALIAS_KEY = "example-key";
|
||||
private static final String FINGERPRINT_KEYSTORE_KEY = "example-key";
|
||||
|
||||
private FingerprintManagerCompat fingerprintManager;
|
||||
private KeyStore keyStore = null;
|
||||
@@ -146,7 +146,7 @@ public class FingerPrintHelper {
|
||||
try {
|
||||
createNewKeyIfNeeded(false); // no need to keep deleting existing keys
|
||||
keyStore.load(null);
|
||||
final SecretKey key = (SecretKey) keyStore.getKey(ALIAS_KEY, null);
|
||||
final SecretKey key = (SecretKey) keyStore.getKey(FINGERPRINT_KEYSTORE_KEY, null);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
|
||||
stopListening();
|
||||
@@ -187,7 +187,7 @@ public class FingerPrintHelper {
|
||||
try {
|
||||
createNewKeyIfNeeded(false);
|
||||
keyStore.load(null);
|
||||
final SecretKey key = (SecretKey) keyStore.getKey(ALIAS_KEY, null);
|
||||
final SecretKey key = (SecretKey) keyStore.getKey(FINGERPRINT_KEYSTORE_KEY, null);
|
||||
|
||||
// important to restore spec here that was used for decryption
|
||||
final byte[] iv = Base64.decode(ivSpecValue, Base64.DEFAULT);
|
||||
@@ -231,18 +231,18 @@ public class FingerPrintHelper {
|
||||
try {
|
||||
keyStore.load(null);
|
||||
if (allowDeleteExisting
|
||||
&& keyStore.containsAlias(ALIAS_KEY)) {
|
||||
&& keyStore.containsAlias(FINGERPRINT_KEYSTORE_KEY)) {
|
||||
|
||||
keyStore.deleteEntry(ALIAS_KEY);
|
||||
keyStore.deleteEntry(FINGERPRINT_KEYSTORE_KEY);
|
||||
}
|
||||
|
||||
// Create new key if needed
|
||||
if (!keyStore.containsAlias(ALIAS_KEY)) {
|
||||
if (!keyStore.containsAlias(FINGERPRINT_KEYSTORE_KEY)) {
|
||||
// Set the alias of the entry in Android KeyStore where the key will appear
|
||||
// and the constrains (purposes) in the constructor of the Builder
|
||||
keyGenerator.init(
|
||||
new KeyGenParameterSpec.Builder(
|
||||
ALIAS_KEY,
|
||||
FINGERPRINT_KEYSTORE_KEY,
|
||||
KeyProperties.PURPOSE_ENCRYPT |
|
||||
KeyProperties.PURPOSE_DECRYPT)
|
||||
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
|
||||
@@ -260,7 +260,7 @@ public class FingerPrintHelper {
|
||||
|
||||
private void deleteEntryKey() {
|
||||
try {
|
||||
keyStore.deleteEntry(ALIAS_KEY);
|
||||
keyStore.deleteEntry(FINGERPRINT_KEYSTORE_KEY);
|
||||
} catch (KeyStoreException e) {
|
||||
fingerPrintCallback.onFingerPrintException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user