|
|
@ -1,26 +1,18 @@ |
|
|
|
package com.gmeremit.online.gmeremittance_native.security; |
|
|
|
|
|
|
|
import android.content.DialogInterface; |
|
|
|
import android.content.SharedPreferences; |
|
|
|
import android.os.Build; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.security.keystore.KeyPermanentlyInvalidatedException; |
|
|
|
import android.util.Log; |
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
import androidx.core.content.ContextCompat; |
|
|
|
|
|
|
|
import com.github.pwittchen.rxbiometric.library.RxBiometric; |
|
|
|
import com.github.pwittchen.rxbiometric.library.validation.RxPreconditions; |
|
|
|
import com.gmeremit.online.gmeremittance_native.GmeApplication; |
|
|
|
import com.gmeremit.online.gmeremittance_native.R; |
|
|
|
import com.gmeremit.online.gmeremittance_native.base.PrefKeys; |
|
|
|
import com.gmeremit.online.gmeremittance_native.base.PrivilegedGateway; |
|
|
|
import com.gmeremit.online.gmeremittance_native.customwidgets.CustomAlertDialog; |
|
|
|
import com.gmeremit.online.gmeremittance_native.security.auth.GMEUserPasswordPromptBottomSheetDialog; |
|
|
|
import com.gmeremit.online.gmeremittance_native.security.auth.GMEUserProfileChangeOTPRequestBottomSheetDialog; |
|
|
|
import com.gmeremit.online.gmeremittance_native.security.utils.SecurityUtils; |
|
|
|
import com.gmeremit.online.gmeremittance_native.transactionpasspromt.view.TransactionBiometricPromptDialog; |
|
|
|
import com.mtramin.rxfingerprint.RxFingerprint; |
|
|
|
import com.mtramin.rxfingerprint.data.BiometricExceptions; |
|
|
|
import com.mtramin.rxfingerprint.data.FingerprintDecryptionResult; |
|
|
|
|
|
|
@ -28,7 +20,6 @@ import io.reactivex.Observable; |
|
|
|
import io.reactivex.Observer; |
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers; |
|
|
|
import io.reactivex.disposables.Disposable; |
|
|
|
import io.reactivex.internal.operators.completable.CompletableError; |
|
|
|
import io.reactivex.schedulers.Schedulers; |
|
|
|
|
|
|
|
import static com.gmeremit.online.gmeremittance_native.utils.https.HTTPConstants.INVALID_REQUEST; |
|
|
@ -45,8 +36,8 @@ public class GMEAuthManager { |
|
|
|
|
|
|
|
private AppCompatActivity context; |
|
|
|
private GMEAuthListener listener; |
|
|
|
private String paymentSourceType; |
|
|
|
private GMEAuthType explicitlyRequestedAuthType; |
|
|
|
private GMEAuthType gmeAuthType; |
|
|
|
private GMEScreenBasedAuthType explicitlyRequestedAuthType; |
|
|
|
private Bundle param; |
|
|
|
private GMEAuthManagerGateway gmeAuthManagerGateway; |
|
|
|
|
|
|
@ -58,7 +49,7 @@ public class GMEAuthManager { |
|
|
|
|
|
|
|
private void resetParamToDefault() { |
|
|
|
listener = null; |
|
|
|
paymentSourceType = null; |
|
|
|
gmeAuthType = null; |
|
|
|
explicitlyRequestedAuthType = null; |
|
|
|
} |
|
|
|
|
|
|
@ -74,15 +65,36 @@ public class GMEAuthManager { |
|
|
|
|
|
|
|
|
|
|
|
public GMEAuthManager fromPaymentSource(String paymentSourceType) { |
|
|
|
this.paymentSourceType = paymentSourceType; |
|
|
|
if ("wallet".equalsIgnoreCase(paymentSourceType)) |
|
|
|
if (checkIfUserHasEnabledBiometric()) |
|
|
|
this.gmeAuthType = GMEAuthType.BIOMETRIC; |
|
|
|
else |
|
|
|
this.gmeAuthType = GMEAuthType.PASSWORD; |
|
|
|
else if ("autodebit".equalsIgnoreCase(paymentSourceType)) |
|
|
|
this.gmeAuthType = GMEAuthType.OTP; |
|
|
|
|
|
|
|
this.explicitlyRequestedAuthType = null; |
|
|
|
|
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
public GMEAuthManager requestExplicitly(GMEAuthType gmeAuthType) { |
|
|
|
public GMEAuthManager requestAuthPerScreenExplicitly(GMEScreenBasedAuthType gmeAuthType) { |
|
|
|
this.explicitlyRequestedAuthType = gmeAuthType; |
|
|
|
this.paymentSourceType = null; |
|
|
|
this.gmeAuthType = null; |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
public GMEAuthManager requestBiometricAuth() { |
|
|
|
this.gmeAuthType = GMEAuthType.BIOMETRIC; |
|
|
|
this.explicitlyRequestedAuthType = null; |
|
|
|
|
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
public GMEAuthManager requestPasswordAuth() { |
|
|
|
this.gmeAuthType = GMEAuthType.PASSWORD; |
|
|
|
this.explicitlyRequestedAuthType = null; |
|
|
|
|
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
@ -94,27 +106,45 @@ public class GMEAuthManager { |
|
|
|
public void prompt() { |
|
|
|
if (explicitlyRequestedAuthType != null) { |
|
|
|
startAuthFromRequestedAuthType(); |
|
|
|
} else { |
|
|
|
} else if (gmeAuthType != null) { |
|
|
|
startAuthFromPaymentSourceType(); |
|
|
|
} |
|
|
|
} else |
|
|
|
returnInvalidRequest(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void startAuthFromPaymentSourceType() { |
|
|
|
if ("wallet".equalsIgnoreCase(paymentSourceType)) |
|
|
|
if (checkIfUserHasEnabledBiometric()) |
|
|
|
showBiometricAuthPrompt(); |
|
|
|
else |
|
|
|
|
|
|
|
switch (gmeAuthType) { |
|
|
|
case OTP: |
|
|
|
showOTPTxnPrompt(); |
|
|
|
break; |
|
|
|
|
|
|
|
case PASSWORD: |
|
|
|
showUserPasswordPrompt(); |
|
|
|
else if ("autodebit".equalsIgnoreCase(paymentSourceType)) |
|
|
|
showOTPTxnPrompt(); |
|
|
|
else |
|
|
|
returnInvalidRequest(); |
|
|
|
break; |
|
|
|
|
|
|
|
case BIOMETRIC: |
|
|
|
showBiometricAuthPrompt(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isBiometricDataAvailable() { |
|
|
|
return gmeAuthManagerGateway.isBiometricDataAvailable(); |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isBiometricEnabledOnTheApp() { |
|
|
|
return gmeAuthManagerGateway.isBiometricEnabledOnTheApp(); |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isBiometricSupportedByDevice() { |
|
|
|
return RxFingerprint.isAvailable(context); |
|
|
|
} |
|
|
|
|
|
|
|
private void returnInvalidRequest() { |
|
|
|
if (listener != null) |
|
|
|
listener.onGMEAuthFailed("Payment source not recognized.\n" + INVALID_REQUEST); |
|
|
|
listener.onGMEAuthFailed("Unknown auth requested.\n" + INVALID_REQUEST); |
|
|
|
} |
|
|
|
|
|
|
|
private void returnSecret(String secret) { |
|
|
@ -127,9 +157,6 @@ public class GMEAuthManager { |
|
|
|
} |
|
|
|
|
|
|
|
private void showBiometricAuthPrompt() { |
|
|
|
// TransactionBiometricPromptDialog promptDialog = new TransactionBiometricPromptDialog(); |
|
|
|
// promptDialog.show(context.getSupportFragmentManager(), promptDialog.getClass().getSimpleName()); |
|
|
|
|
|
|
|
|
|
|
|
biometricAuthenticateAndReturnUserCredentialOnSuccess() |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
@ -237,19 +264,16 @@ public class GMEAuthManager { |
|
|
|
showOTPTxnPrompt(); |
|
|
|
break; |
|
|
|
|
|
|
|
case OTP_PROFILE_REQUEST: |
|
|
|
case OTP_REQUEST_PROFILE: |
|
|
|
showOTPProfilePrompt(true); |
|
|
|
break; |
|
|
|
|
|
|
|
case OTP_PROFILE_SUBMIT: |
|
|
|
case OTP_SUBMIT_PROFILE: |
|
|
|
showOTPProfilePrompt(false); |
|
|
|
break; |
|
|
|
|
|
|
|
case BIOMETRIC: |
|
|
|
showBiometricAuthPrompt(); |
|
|
|
break; |
|
|
|
|
|
|
|
case USER_PASSWORD: |
|
|
|
case PASSWORD_USER_PROFILE: |
|
|
|
showUserPasswordPrompt(); |
|
|
|
break; |
|
|
|
|
|
|
@ -260,10 +284,6 @@ public class GMEAuthManager { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class GMEAuthManagerGateway extends PrivilegedGateway { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public static class UserCredentialDecryptionResultDTO { |
|
|
|
String userId; |
|
|
|
String userPwd; |
|
|
@ -299,7 +319,11 @@ public class GMEAuthManager { |
|
|
|
void onGMEAuthCancelled(); |
|
|
|
} |
|
|
|
|
|
|
|
public enum GMEScreenBasedAuthType { |
|
|
|
PASSWORD_USER_PROFILE, OTP_REQUEST_PROFILE, OTP_SUBMIT_PROFILE, OTP_TXN |
|
|
|
} |
|
|
|
|
|
|
|
public enum GMEAuthType { |
|
|
|
USER_PASSWORD, BIOMETRIC, OTP_PROFILE_REQUEST, OTP_PROFILE_SUBMIT, OTP_TXN |
|
|
|
BIOMETRIC, PASSWORD, OTP |
|
|
|
} |
|
|
|
} |