Updated on 2026-08-14

This commit is contained in:
Tangem 2019-01-10 16:46:56 +03:00
parent 95021a0600
commit 30c4c0b425
15 changed files with 74 additions and 105 deletions

View file

@ -11,6 +11,7 @@ import android.security.keystore.KeyProperties;
import com.tangem.Constant;
import com.tangem.tangemcard.android.data.PINStorage;
import com.tangem.presentation.activity.PinRequestActivity;
import com.tangem.util.LOG;
import java.io.IOException;
import java.lang.ref.WeakReference;
@ -26,6 +27,8 @@ import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
public static final String TAG = StartFingerprintReaderTask.class.getSimpleName();
private WeakReference<PinRequestActivity> reference;
private KeyStore keyStore;
@ -64,16 +67,14 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
@Override
protected void onPostExecute(final Boolean success) {
PinRequestActivity pinRequestActivity = reference.get();
onCancelled();
if (!success) {
pinRequestActivity.doLog("Authentication failed!");
LOG.i(TAG, "Authentication failed!");
} else {
fingerprintHelper.startAuth(fingerprintManager, cryptoObject);
pinRequestActivity.doLog("Authenticate using fingerprint!");
LOG.i(TAG, "Authenticate using fingerprint!");
}
}
@ -85,9 +86,7 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
}
private boolean getKeyStore() {
PinRequestActivity pinRequestActivity = reference.get();
pinRequestActivity.doLog("Getting keystore...");
LOG.i(TAG, "Getting keystore...");
try {
keyStore = KeyStore.getInstance(Constant.KEYSTORE);
keyStore.load(null); // Create empty keystore
@ -101,9 +100,7 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
@TargetApi(Build.VERSION_CODES.M)
public boolean createNewKey(boolean forceCreate) {
PinRequestActivity pinRequestActivity = reference.get();
pinRequestActivity.doLog("Creating new key...");
LOG.i(TAG, "Creating new key...");
try {
if (forceCreate)
keyStore.deleteEntry(Constant.KEY_ALIAS);
@ -120,9 +117,9 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
);
generator.generateKey();
pinRequestActivity.doLog("Key created.");
LOG.i(TAG, "Key created.");
} else
pinRequestActivity.doLog("Key exists.");
LOG.i(TAG, "Key exists.");
return true;
} catch (Exception e) {
@ -133,9 +130,7 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
}
private boolean getCipher() {
PinRequestActivity pinRequestActivity = reference.get();
pinRequestActivity.doLog("Getting cipher...");
LOG.i(TAG, "Getting cipher...");
try {
cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
return true;
@ -150,7 +145,7 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
private boolean initCipher(int mode) {
PinRequestActivity pinRequestActivity = reference.get();
pinRequestActivity.doLog("Initializing cipher...");
LOG.i(TAG, "Initializing cipher...");
try {
keyStore.load(null);
SecretKey keyspec = (SecretKey) keyStore.getKey(Constant.KEY_ALIAS, null);
@ -181,9 +176,7 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
@TargetApi(Build.VERSION_CODES.M)
private boolean initCryptObject() {
PinRequestActivity pinRequestActivity = reference.get();
pinRequestActivity.doLog("Initializing crypt object...");
LOG.i(TAG, "Initializing crypt object...");
try {
cryptoObject = new FingerprintManager.CryptoObject(cipher);
return true;
@ -193,5 +186,4 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
return false;
}
}