This commit is contained in:
Adam Velebil 2024-04-08 15:50:03 +02:00
commit 941a4faed2
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
2 changed files with 22 additions and 16 deletions

View File

@ -175,7 +175,7 @@ class FidoManager(
deviceManager.removeDeviceListener(this) deviceManager.removeDeviceListener(this)
fidoChannel.setMethodCallHandler(null) fidoChannel.setMethodCallHandler(null)
fidoViewModel.clearSessionState() fidoViewModel.clearSessionState()
fidoViewModel.updateCredentials(emptyList()) fidoViewModel.updateCredentials(null)
coroutineScope.cancel() coroutineScope.cancel()
} }
@ -261,19 +261,11 @@ class FidoManager(
val pinPermissionsBE = getPinPermissionsBE(fidoSession) val pinPermissionsBE = getPinPermissionsBE(fidoSession)
val permissions = pinPermissionsCM or pinPermissionsBE val permissions = pinPermissionsCM or pinPermissionsBE
if (permissions != 0) { val token = if (permissions != 0) {
val token = clientPin.getPinToken(pin, permissions, null) 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)
}
} else { } else {
clientPin.getPinToken(pin, permissions, "yubico-authenticator.example.com") clientPin.getPinToken(pin, permissions, "yubico-authenticator.example.com")
null
} }
pinStore.setPin(pin) pinStore.setPin(pin)
@ -287,6 +279,19 @@ class FidoManager(
pinRetries 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() return JSONObject(mapOf("success" to true)).toString()
} }
@ -304,7 +309,7 @@ class FidoManager(
ctapException.ctapError == CtapException.ERR_PIN_POLICY_VIOLATION ctapException.ctapError == CtapException.ERR_PIN_POLICY_VIOLATION
) { ) {
pinStore.setPin(null) pinStore.setPin(null)
fidoViewModel.updateCredentials(emptyList()) fidoViewModel.updateCredentials(null)
pinRetries = clientPin.pinRetries.count pinRetries = clientPin.pinRetries.count
fidoViewModel.setSessionState( fidoViewModel.setSessionState(
@ -397,6 +402,7 @@ class FidoManager(
pinUvAuthToken: ByteArray pinUvAuthToken: ByteArray
): List<FidoCredential> = ): List<FidoCredential> =
try { try {
fidoViewModel.updateCredentials(null)
val credMan = CredentialManagement(fidoSession, clientPin.pinUvAuth, pinUvAuthToken) val credMan = CredentialManagement(fidoSession, clientPin.pinUvAuth, pinUvAuthToken)
val rpIds = credMan.enumerateRps() val rpIds = credMan.enumerateRps()

View File

@ -38,10 +38,10 @@ class FidoViewModel : ViewModel() {
_sessionState.postValue(ViewModelData.Empty) _sessionState.postValue(ViewModelData.Empty)
} }
private val _credentials = MutableLiveData<List<FidoCredential>>() private val _credentials = MutableLiveData<List<FidoCredential>?>()
val credentials: LiveData<List<FidoCredential>> = _credentials val credentials: LiveData<List<FidoCredential>?> = _credentials
fun updateCredentials(credentials: List<FidoCredential>) { fun updateCredentials(credentials: List<FidoCredential>?) {
_credentials.postValue(credentials) _credentials.postValue(credentials)
} }