mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-26 23:25:20 +03:00
Fix finger auth
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
8a07e94e0e
commit
0f7b004023
3 changed files with 23 additions and 20 deletions
|
@ -116,8 +116,8 @@ public final class MainActivity extends BaseActivity implements ActionBarProvide
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
checkIfWeAreSecure();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ import android.app.KeyguardManager;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -58,7 +60,6 @@ public class LockedController extends BaseController {
|
|||
return inflater.inflate(R.layout.controller_locked, container, false);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
@Override
|
||||
protected void onViewBound(@NonNull View view) {
|
||||
super.onViewBound(view);
|
||||
|
@ -66,8 +67,13 @@ public class LockedController extends BaseController {
|
|||
if (getActionBar() != null) {
|
||||
getActionBar().hide();
|
||||
}
|
||||
}
|
||||
|
||||
showBiometricDialog();
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
@Override
|
||||
protected void onAttach(@NonNull View view) {
|
||||
super.onAttach(view);
|
||||
checkIfWeAreSecure();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
|
@ -94,7 +100,7 @@ public class LockedController extends BaseController {
|
|||
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
||||
super.onAuthenticationSucceeded(result);
|
||||
Log.d(TAG, "Fingerprint recognised successfully");
|
||||
getRouter().popCurrentController();
|
||||
new Handler(Looper.getMainLooper()).post(() -> getRouter().popCurrentController());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,7 +117,12 @@ public class LockedController extends BaseController {
|
|||
}
|
||||
);
|
||||
|
||||
biometricPrompt.authenticate(promptInfo, SecurityUtils.getCryptoObject());
|
||||
BiometricPrompt.CryptoObject cryptoObject = SecurityUtils.getCryptoObject();
|
||||
if (cryptoObject != null) {
|
||||
biometricPrompt.authenticate(promptInfo, cryptoObject);
|
||||
} else {
|
||||
biometricPrompt.authenticate(promptInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +133,8 @@ public class LockedController extends BaseController {
|
|||
if (keyguardManager != null && keyguardManager.isKeyguardSecure() && appPreferences.getIsScreenLocked()) {
|
||||
if (!SecurityUtils.checkIfWeAreAuthenticated(appPreferences.getScreenLockTimeout())) {
|
||||
showBiometricDialog();
|
||||
} else {
|
||||
getRouter().popCurrentController();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ public class SecurityUtils {
|
|||
private static final String CREDENTIALS_KEY = "KEY_CREDENTIALS";
|
||||
private static final byte[] SECRET_BYTE_ARRAY = new byte[]{1, 2, 3, 4, 5, 6};
|
||||
|
||||
private static BiometricPrompt.CryptoObject cryptoObject;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
public static boolean checkIfWeAreAuthenticated(String screenLockTimeout) {
|
||||
try {
|
||||
|
@ -58,6 +60,7 @@ public class SecurityUtils {
|
|||
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
|
||||
cipher.doFinal(SECRET_BYTE_ARRAY);
|
||||
|
||||
cryptoObject = new BiometricPrompt.CryptoObject(cipher);
|
||||
// If the user has recently authenticated, we will reach here
|
||||
return true;
|
||||
} catch (UserNotAuthenticatedException e) {
|
||||
|
@ -80,22 +83,9 @@ public class SecurityUtils {
|
|||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
public static BiometricPrompt.CryptoObject getCryptoObject() {
|
||||
Cipher cipher = null;
|
||||
try {
|
||||
cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_GCM + "/" + KeyProperties.ENCRYPTION_PADDING_NONE);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Log.w(TAG, e.getLocalizedMessage());
|
||||
} catch (NoSuchPaddingException e) {
|
||||
Log.w(TAG, e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
BiometricPrompt.CryptoObject cryptoObject = null;
|
||||
if (cipher != null) {
|
||||
cryptoObject = new BiometricPrompt.CryptoObject(cipher);
|
||||
}
|
||||
|
||||
return cryptoObject;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
public static void createKey(String validity) {
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue