Skip to content

Commit bb9ef04

Browse files
fix(android): key user not authenticated (#224)
Co-authored-by: Alejandro <alejandro.maggi@recargapay.com>
1 parent ba3dcbc commit bb9ef04

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

android/src/main/java/br/com/classapp/RNSensitiveInfo/RNSensitiveInfoModule.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.concurrent.Executors;
3939

4040
import javax.crypto.Cipher;
41+
import javax.crypto.IllegalBlockSizeException;
4142
import javax.crypto.KeyGenerator;
4243
import javax.crypto.SecretKey;
4344
import javax.crypto.SecretKeyFactory;
@@ -425,6 +426,18 @@ public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult re
425426
pm.reject(keyResetError);
426427
}
427428
pm.reject(e);
429+
} catch (IllegalBlockSizeException e){
430+
if(e.getCause() != null && e.getCause().getMessage().contains("Key user not authenticated")) {
431+
try {
432+
mKeyStore.deleteEntry(KEY_ALIAS_AES);
433+
prepareKey();
434+
pm.reject(AppConstants.KM_ERROR_KEY_USER_NOT_AUTHENTICATED, e.getCause().getMessage());
435+
} catch (Exception keyResetError) {
436+
pm.reject(keyResetError);
437+
}
438+
} else {
439+
pm.reject(e);
440+
}
428441
} catch (SecurityException e) {
429442
pm.reject(e);
430443
} catch (Exception e) {
@@ -530,6 +543,18 @@ public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult re
530543
pm.reject(keyResetError);
531544
}
532545
pm.reject(e);
546+
} catch (IllegalBlockSizeException e){
547+
if(e.getCause() != null && e.getCause().getMessage().contains("Key user not authenticated")) {
548+
try {
549+
mKeyStore.deleteEntry(KEY_ALIAS_AES);
550+
prepareKey();
551+
pm.reject(AppConstants.KM_ERROR_KEY_USER_NOT_AUTHENTICATED, e.getCause().getMessage());
552+
} catch (Exception keyResetError) {
553+
pm.reject(keyResetError);
554+
}
555+
} else {
556+
pm.reject(e);
557+
}
533558
} catch (SecurityException e) {
534559
pm.reject(e);
535560
} catch (Exception e) {

android/src/main/java/br/com/classapp/RNSensitiveInfo/utils/AppConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public interface AppConstants {
55
String DIALOG_FRAGMENT_TAG = "authFragment";
66

77
// error codes
8+
String KM_ERROR_KEY_USER_NOT_AUTHENTICATED = "KM_ERROR_KEY_USER_NOT_AUTHENTICATED";
89
String E_AUTHENTICATION_CANCELLED = "E_AUTHENTICATION_CANCELLED";
910
String E_INIT_FAILURE = "E_INIT_FAILURE";
1011
}

0 commit comments

Comments
 (0)