From f76aadb245e2f11daaaf04f55e6ef2bdc461f90d Mon Sep 17 00:00:00 2001 From: Adam Velebil Date: Mon, 8 Apr 2024 15:15:44 +0200 Subject: [PATCH] fix UI progress when loading passkeys --- .../yubico/authenticator/fido/FidoManager.kt | 32 +++++++++++-------- .../authenticator/fido/FidoViewModel.kt | 6 ++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/android/app/src/main/kotlin/com/yubico/authenticator/fido/FidoManager.kt b/android/app/src/main/kotlin/com/yubico/authenticator/fido/FidoManager.kt index 839dae01..e6ad6a26 100644 --- a/android/app/src/main/kotlin/com/yubico/authenticator/fido/FidoManager.kt +++ b/android/app/src/main/kotlin/com/yubico/authenticator/fido/FidoManager.kt @@ -175,7 +175,7 @@ class FidoManager( deviceManager.removeDeviceListener(this) fidoChannel.setMethodCallHandler(null) fidoViewModel.clearSessionState() - fidoViewModel.updateCredentials(emptyList()) + fidoViewModel.updateCredentials(null) coroutineScope.cancel() } @@ -287,19 +287,11 @@ class FidoManager( val pinPermissionsBE = getPinPermissionsBE(fidoSession) val permissions = pinPermissionsCM or pinPermissionsBE - if (permissions != 0) { - val token = clientPin.getPinToken(pin, permissions, null) - val credentials = getCredentials(fidoSession, clientPin, token) - logger.debug("Creds: {}", credentials) - fidoViewModel.updateCredentials(credentials) - - if (pinPermissionsBE != 0) { - val fingerprints = getFingerprints(fidoSession, clientPin, token) - logger.debug("Fingerprints: {}", fingerprints) - fidoViewModel.updateFingerprints(fingerprints) - } + val token = if (permissions != 0) { + clientPin.getPinToken(pin, permissions, null) } else { clientPin.getPinToken(pin, permissions, "yubico-authenticator.example.com") + null } pinStore.setPin(pin) @@ -313,6 +305,19 @@ class FidoManager( pinRetries ) ) + + token?.let { + val credentials = getCredentials(fidoSession, clientPin, token) + logger.debug("Creds: {}", credentials) + fidoViewModel.updateCredentials(credentials) + + if (pinPermissionsBE != 0) { + val fingerprints = getFingerprints(fidoSession, clientPin, token) + logger.debug("Fingerprints: {}", fingerprints) + fidoViewModel.updateFingerprints(fingerprints) + } + } + return JSONObject(mapOf("success" to true)).toString() } @@ -330,7 +335,7 @@ class FidoManager( ctapException.ctapError == CtapException.ERR_PIN_POLICY_VIOLATION ) { pinStore.setPin(null) - fidoViewModel.updateCredentials(emptyList()) + fidoViewModel.updateCredentials(null) pinRetries = clientPin.pinRetries.count fidoViewModel.setSessionState( @@ -423,6 +428,7 @@ class FidoManager( pinUvAuthToken: ByteArray ): List = try { + fidoViewModel.updateCredentials(null) val credMan = CredentialManagement(fidoSession, clientPin.pinUvAuth, pinUvAuthToken) val rpIds = credMan.enumerateRps() diff --git a/android/app/src/main/kotlin/com/yubico/authenticator/fido/FidoViewModel.kt b/android/app/src/main/kotlin/com/yubico/authenticator/fido/FidoViewModel.kt index 56f12207..46e3f28c 100644 --- a/android/app/src/main/kotlin/com/yubico/authenticator/fido/FidoViewModel.kt +++ b/android/app/src/main/kotlin/com/yubico/authenticator/fido/FidoViewModel.kt @@ -38,10 +38,10 @@ class FidoViewModel : ViewModel() { _sessionState.postValue(ViewModelData.Empty) } - private val _credentials = MutableLiveData>() - val credentials: LiveData> = _credentials + private val _credentials = MutableLiveData?>() + val credentials: LiveData?> = _credentials - fun updateCredentials(credentials: List) { + fun updateCredentials(credentials: List?) { _credentials.postValue(credentials) }