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