Skip to content

Commit

Permalink
fix: android cancel auth send promise
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht committed Aug 23, 2024
1 parent 6b7cda5 commit a376365
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class SecureEnvironment {
SecureEnvironmentBiometrics(
context,
{ sig: ByteArray -> promise.resolve(sig) },
{ code: Number, msg: String -> promise.reject(CodedException("code: $code, msg: $msg")) },
message
).authenticate(signature)
} else {
Expand All @@ -117,3 +118,5 @@ class SecureEnvironment {
}
}
}

// code: <CODE>, msg: <MSG>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.security.Signature
class SecureEnvironmentBiometrics(
private val appContext: AppContext,
private val signedCb: (sig: ByteArray) -> Unit,
private val errorCb: (code: Number, message: String) -> Unit,
private val toBeSigned: ByteArray,
private val activity: FragmentActivity = appContext.currentActivity as FragmentActivity,
private val promptInfo: PromptInfo = PromptInfo.Builder()
Expand All @@ -25,30 +26,22 @@ class SecureEnvironmentBiometrics(
sig.update(toBeSigned)
val signature = sig.sign()
signedCb(signature)
} ?: throw SecureEnvironmentExceptions.NoSignatureOnCryptoObject()
} ?: errorCb(2323, "No CryptoObjectFound")
}

override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
errorCb(errorCode, errString.toString())
}

private fun authenticateWithPrompt(signature: Signature) {
val prompt = BiometricPrompt(activity, this)
prompt.authenticate(promptInfo, BiometricPrompt.CryptoObject(signature))
}

private fun waitResult() {
if (Thread.currentThread() === Looper.getMainLooper().thread) {
throw SecureEnvironmentExceptions.NotExecutedFromMainThread()
}

try {
synchronized(this) { (this as Object).wait() }
} catch (ignored: InterruptedException) {
/* shutdown sequence */
}
}


fun authenticate(signature: Signature) {
if (Thread.currentThread() != Looper.getMainLooper().thread) {
activity.runOnUiThread { this@SecureEnvironmentBiometrics.authenticate(signature) }
waitResult()
return
}

Expand Down
4 changes: 4 additions & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { StyleSheet, View } from "react-native";

export default function App() {
const testBiometrics = async () => {
try{
const id = new Date().toString();
generateKeypair(id, true);
const publicKey = getPublicBytesForKeyId(id);
Expand All @@ -30,6 +31,9 @@ export default function App() {
});

console.log(isValid);
}catch(e) {
console.error('ERRRRRR', e)
}
};

const testNoBiometrics = async () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@animo-id/expo-secure-environment",
"version": "0.1.0-alpha.2",
"version": "0.1.0-alpha.3",
"description": "Expo Secure Environment",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down

0 comments on commit a376365

Please sign in to comment.