Browse Source

Fingerprint auth fixes

master
Preyea Regmi 5 years ago
parent
commit
837616f14a
  1. 3
      app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGateway.java
  2. 4
      app/src/main/java/com/gmeremit/online/gmeremittance_native/changepasswordV2/presenter/ChangePasswordV2Presenter.java
  3. 19
      app/src/main/java/com/gmeremit/online/gmeremittance_native/loginV2/presenter/LoginV2Presenter.java
  4. 44
      app/src/main/java/com/gmeremit/online/gmeremittance_native/settings/view/FingerPrintAuthPromptDialog.java
  5. 2
      app/src/main/java/com/gmeremit/online/gmeremittance_native/settings/view/SettingsView.java
  6. 13
      app/src/main/java/com/gmeremit/online/gmeremittance_native/transactionpasspromt/presenter/TransactionPasswordPromptV2Presenter.java
  7. 2
      app/src/main/res/values/strings.xml

3
app/src/main/java/com/gmeremit/online/gmeremittance_native/base/PrivilegedGateway.java

@ -185,7 +185,6 @@ public abstract class PrivilegedGateway implements PrivilegedGatewayInterface {
@Override @Override
public void persistSecretKey(String encrypted) { public void persistSecretKey(String encrypted) {
Log.d(SecurityUtils.TAG,"To be Stored Key :"+encrypted);
GmeApplication.getStorage().edit().putString(PrefKeys.APP_SECRET_KEY,encrypted).apply(); GmeApplication.getStorage().edit().putString(PrefKeys.APP_SECRET_KEY,encrypted).apply();
} }
@ -208,7 +207,6 @@ public abstract class PrivilegedGateway implements PrivilegedGatewayInterface {
@Override @Override
public String getPersistedSecretKey() { public String getPersistedSecretKey() {
Log.d(SecurityUtils.TAG,"Stored Key :"+GmeApplication.getStorage().getString(PrefKeys.APP_SECRET_KEY,null));
return GmeApplication.getStorage().getString(PrefKeys.APP_SECRET_KEY,null); return GmeApplication.getStorage().getString(PrefKeys.APP_SECRET_KEY,null);
} }
@ -223,6 +221,7 @@ public abstract class PrivilegedGateway implements PrivilegedGatewayInterface {
editor.putString(PrefKeys.APP_USER_ID_SECRET_KEY,null); editor.putString(PrefKeys.APP_USER_ID_SECRET_KEY,null);
editor.putBoolean(PrefKeys.APP_FINGER_PRINT_ENABLED,false); editor.putBoolean(PrefKeys.APP_FINGER_PRINT_ENABLED,false);
editor.putString(PrefKeys.APP_USER_SECRET_KEY,null); editor.putString(PrefKeys.APP_USER_SECRET_KEY,null);
editor.putString(PrefKeys.APP_SECRET_KEY,null);
editor.apply(); editor.apply();
} }

4
app/src/main/java/com/gmeremit/online/gmeremittance_native/changepasswordV2/presenter/ChangePasswordV2Presenter.java

@ -1,5 +1,7 @@
package com.gmeremit.online.gmeremittance_native.changepasswordV2.presenter; package com.gmeremit.online.gmeremittance_native.changepasswordV2.presenter;
import android.os.Build;
import android.security.keystore.KeyPermanentlyInvalidatedException;
import android.util.Log; import android.util.Log;
import com.gmeremit.online.gmeremittance_native.R; import com.gmeremit.online.gmeremittance_native.R;
@ -269,8 +271,6 @@ public class ChangePasswordV2Presenter extends BasePresenter implements ChangePa
public void onError(Throwable e) { public void onError(Throwable e) {
view.showProgressBar(false,""); view.showProgressBar(false,"");
gateway.flushBiometricData(); gateway.flushBiometricData();
Log.d(SecurityUtils.TAG, "Failed : " + e.getMessage());
} }
@Override @Override

19
app/src/main/java/com/gmeremit/online/gmeremittance_native/loginV2/presenter/LoginV2Presenter.java

@ -95,14 +95,10 @@ public class LoginV2Presenter extends BasePresenter implements LoginV2PresenterI
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retryWhen(errors -> errors.flatMap( .retryWhen(errors -> errors.flatMap(
error -> { error -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && error instanceof KeyPermanentlyInvalidatedException) {
view.showFingerPrintScanner(false);
gateway.flushBiometricData();
}
else if(error instanceof FingerprintAuthenticationException)
if(error instanceof FingerprintAuthenticationException)
{ {
view.showFingerPrintScanner(false); view.showFingerPrintScanner(false);
view.showToastMessage(error.getMessage());
} }
else if (error instanceof SecurityUtils.FailedFingerPrintException || error instanceof SecurityUtils.SensorNotReadyException) { else if (error instanceof SecurityUtils.FailedFingerPrintException || error instanceof SecurityUtils.SensorNotReadyException) {
view.showToastMessage(error.getMessage()); view.showToastMessage(error.getMessage());
@ -300,8 +296,7 @@ public class LoginV2Presenter extends BasePresenter implements LoginV2PresenterI
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Log.d(SecurityUtils.TAG, "Failed : " + e.getMessage());
gateway.flushBiometricData();
} }
@Override @Override
@ -315,7 +310,6 @@ public class LoginV2Presenter extends BasePresenter implements LoginV2PresenterI
@Override @Override
public void onNext(FingerprintDecResult fingerprintDecResult) { public void onNext(FingerprintDecResult fingerprintDecResult) {
Log.d(SecurityUtils.TAG, "Success : " + fingerprintDecResult.toString()); Log.d(SecurityUtils.TAG, "Success : " + fingerprintDecResult.toString());
encUserPassword = fingerprintDecResult.getUserPwd(); encUserPassword = fingerprintDecResult.getUserPwd();
view.onLoginPerformTask(() -> loginUser(fingerprintDecResult.getUserId(), "")); view.onLoginPerformTask(() -> loginUser(fingerprintDecResult.getUserId(), ""));
@ -323,7 +317,12 @@ public class LoginV2Presenter extends BasePresenter implements LoginV2PresenterI
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Log.d(SecurityUtils.TAG, "Failed : " + e.getMessage());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && e instanceof KeyPermanentlyInvalidatedException) {
view.showFingerPrintScanner(false);
gateway.flushBiometricData();
view.showPopUpMessage(getStringfromStringId(R.string.fingerprint_changed_externally),CustomAlertDialog.AlertType.ALERT,null);
}
} }

44
app/src/main/java/com/gmeremit/online/gmeremittance_native/settings/view/FingerPrintAuthPromptDialog.java

@ -51,11 +51,11 @@ public class FingerPrintAuthPromptDialog extends android.support.v4.app.DialogFr
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_fingerprint_auth_prompt, null); View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_fingerprint_auth_prompt, null);
fingerprintScannerImgView=view.findViewById(R.id.fingerprintScannerImgView);
cancelView=view.findViewById(R.id.btnCancel);
fingerprintScannerImgView = view.findViewById(R.id.fingerprintScannerImgView);
cancelView = view.findViewById(R.id.btnCancel);
builder.setView(view); builder.setView(view);
initialize(); initialize();
Dialog dialog= builder.create();
Dialog dialog = builder.create();
try { try {
this.window = dialog.getWindow(); this.window = dialog.getWindow();
window.setBackgroundDrawableResource(R.drawable.ic_rounded_white); window.setBackgroundDrawableResource(R.drawable.ic_rounded_white);
@ -73,10 +73,9 @@ public class FingerPrintAuthPromptDialog extends android.support.v4.app.DialogFr
} }
public void setFingerprintAuthListener(boolean userAction,FingerprintAuthListener listener)
{
this.userAction=userAction;
this.listener=listener;
public void setFingerprintAuthListener(boolean userAction, FingerprintAuthListener listener) {
this.userAction = userAction;
this.listener = listener;
} }
@Override @Override
@ -85,10 +84,10 @@ public class FingerPrintAuthPromptDialog extends android.support.v4.app.DialogFr
cancelView.setOnClickListener(new View.OnClickListener() { cancelView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
dismiss();
dismiss();
} }
}); });
if (fingerPrintReaderSubs==null||fingerPrintReaderSubs.isDisposed())
if (fingerPrintReaderSubs == null || fingerPrintReaderSubs.isDisposed())
fingerPrintReaderSubs = startObservingFingerPrintScanner(); fingerPrintReaderSubs = startObservingFingerPrintScanner();
} }
@ -122,7 +121,7 @@ public class FingerPrintAuthPromptDialog extends android.support.v4.app.DialogFr
fingerPrintAVDCompat.start(); fingerPrintAVDCompat.start();
} }
}, 200 );
}, 200);
} else { } else {
new Handler().postDelayed(() -> { new Handler().postDelayed(() -> {
fingerprintScannerImgView.setImageDrawable(null); fingerprintScannerImgView.setImageDrawable(null);
@ -147,12 +146,11 @@ public class FingerPrintAuthPromptDialog extends android.support.v4.app.DialogFr
}) })
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retryWhen(errors->errors.flatMap(
error->{
if(error instanceof SecurityUtils.FailedFingerPrintException || error instanceof SecurityUtils.SensorNotReadyException)
{
.retryWhen(errors -> errors.flatMap(
error -> {
if (error instanceof SecurityUtils.FailedFingerPrintException || error instanceof SecurityUtils.SensorNotReadyException) {
showToastMessage(error.getMessage()); showToastMessage(error.getMessage());
return Observable.timer(100,TimeUnit.MILLISECONDS);
return Observable.timer(100, TimeUnit.MILLISECONDS);
} }
return Observable.error(error); return Observable.error(error);
} }
@ -161,9 +159,9 @@ public class FingerPrintAuthPromptDialog extends android.support.v4.app.DialogFr
} }
private void showToastMessage(String message) { private void showToastMessage(String message) {
Toast toast=Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT);
Toast toast = Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT);
TextView v = (TextView) toast.getView().findViewById(android.R.id.message); TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
if( v != null) v.setGravity(Gravity.CENTER);
if (v != null) v.setGravity(Gravity.CENTER);
toast.show(); toast.show();
} }
@ -173,16 +171,16 @@ public class FingerPrintAuthPromptDialog extends android.support.v4.app.DialogFr
@Override @Override
public void onNext(FingerprintAuthenticationResult fingerprintAuthenticationResult) { public void onNext(FingerprintAuthenticationResult fingerprintAuthenticationResult) {
if(listener!=null)
listener.onFingerPrintAuthenticated(userAction);
if (listener != null)
listener.onFingerPrintAuthenticated(userAction);
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && e instanceof KeyPermanentlyInvalidatedException) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && e instanceof KeyPermanentlyInvalidatedException) {
listener.onFingerPrintInvalidatedBySystem(); listener.onFingerPrintInvalidatedBySystem();
}
showToastMessage(e.getMessage());
} else
showToastMessage(e.getMessage());
} }
@Override @Override
@ -192,9 +190,9 @@ public class FingerPrintAuthPromptDialog extends android.support.v4.app.DialogFr
} }
public interface FingerprintAuthListener
{
public interface FingerprintAuthListener {
void onFingerPrintAuthenticated(boolean userAction); void onFingerPrintAuthenticated(boolean userAction);
void onFingerPrintInvalidatedBySystem(); void onFingerPrintInvalidatedBySystem();
} }
} }

2
app/src/main/java/com/gmeremit/online/gmeremittance_native/settings/view/SettingsView.java

@ -67,7 +67,7 @@ public class SettingsView extends BaseActivity implements CompoundButton.OnCheck
private boolean isBiometricDataAvailable() { private boolean isBiometricDataAvailable() {
SharedPreferences sp = GmeApplication.getStorage(); SharedPreferences sp = GmeApplication.getStorage();
return sp.getString(PrefKeys.APP_USER_ID_SECRET_KEY, null) != null && sp.getString(PrefKeys.APP_USER_SECRET_KEY, null) != null;
return sp.getString(PrefKeys.APP_USER_ID_SECRET_KEY, null) != null && sp.getString(PrefKeys.APP_USER_SECRET_KEY, null) != null&&sp.getString(PrefKeys.APP_SECRET_KEY,null)!=null;
} }
@OnClick({R.id.view_change_password, R.id.iv_back, R.id.view_language, R.id.view_fingerprint}) @OnClick({R.id.view_change_password, R.id.iv_back, R.id.view_language, R.id.view_fingerprint})

13
app/src/main/java/com/gmeremit/online/gmeremittance_native/transactionpasspromt/presenter/TransactionPasswordPromptV2Presenter.java

@ -147,11 +147,7 @@ public class TransactionPasswordPromptV2Presenter extends BasePresenter implemen
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retryWhen(errors -> errors.flatMap( .retryWhen(errors -> errors.flatMap(
error -> { error -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && error instanceof KeyPermanentlyInvalidatedException) {
view.addFingerprintIcon(false);
gateway.flushBiometricData();
} else if (error instanceof FingerprintAuthenticationException) {
if (error instanceof FingerprintAuthenticationException) {
view.addFingerprintIcon(false); view.addFingerprintIcon(false);
} else if (error instanceof SecurityUtils.FailedFingerPrintException || error instanceof SecurityUtils.SensorNotReadyException) { } else if (error instanceof SecurityUtils.FailedFingerPrintException || error instanceof SecurityUtils.SensorNotReadyException) {
view.showToastMessage(error.getMessage()); view.showToastMessage(error.getMessage());
@ -263,6 +259,13 @@ public class TransactionPasswordPromptV2Presenter extends BasePresenter implemen
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && e instanceof KeyPermanentlyInvalidatedException)
{
view.addFingerprintIcon(false);
gateway.flushBiometricData();
view.showPopUpMessage(getStringfromStringId(R.string.fingerprint_changed_externally),CustomAlertDialog.AlertType.ALERT,null);
}
Log.d(SecurityUtils.TAG, "Failed : " + e.getMessage()); Log.d(SecurityUtils.TAG, "Failed : " + e.getMessage());
} }

2
app/src/main/res/values/strings.xml

@ -469,7 +469,7 @@
<string name="enter_bank_ac_no">Enter your bank account number</string> <string name="enter_bank_ac_no">Enter your bank account number</string>
<string name="select_language">Select language</string> <string name="select_language">Select language</string>
<string name="touch_fingerprint_text">Please place your finger on the fingerprint sensor to continue.</string> <string name="touch_fingerprint_text">Please place your finger on the fingerprint sensor to continue.</string>
<string name="fingerprint_changed_externally">Your fingerprint has been expired. Please login again to continue.</string>
<string name="fingerprint_changed_externally">It seems you added a new fingerprint or removed the existing one. Please login again to validate your fingerprint.</string>
<string name="loading_text">Loading...</string> <string name="loading_text">Loading...</string>

Loading…
Cancel
Save