Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for unexpected Ausweis SDK responses. #794

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class AusweisModel(
data class Auth(val progress: Int): Status()
data object NetworkError: Status()
data object GenericError: Status()
data object PinError: Status()

private lateinit var sdk: IAusweisApp2Sdk
private lateinit var sessionId: String
Expand Down Expand Up @@ -122,7 +123,11 @@ class AusweisModel(
fun startWorkflow(simulatedCard: Boolean) {
useSimulatedCard = simulatedCard
job = coroutineScope.launch {
runAusweisSdk()
try {
runAusweisSdk()
} catch (err: UnexpectedStateException) {
Logger.e(TAG, "Error communicating with the card", err)
}
}
}

Expand All @@ -140,7 +145,7 @@ class AusweisModel(

fun tryAgain() {
status.value = null
navController.navigate(AusweisModel.Route.INITIAL.route)
navController.navigate(Route.INITIAL.route)
initialize()
}

Expand Down Expand Up @@ -279,7 +284,13 @@ class AusweisModel(
} else if (type == "READER") {
// TODO: process READER
} else {
throw IllegalStateException("Unexpected message type: $type")
if (type == "ENTER_CAN" || type == "ENTER_PUK") {
status.value = PinError
} else {
status.value = GenericError
}
navController.navigate(Route.ERROR.route)
throw UnexpectedStateException(type ?: "<null>")
}
}
}
Expand All @@ -306,4 +317,7 @@ class AusweisModel(
private fun disableCardScanning(nfcAdapter: NfcAdapter?) {
nfcAdapter?.disableReaderMode(context.getActivity())
}

class UnexpectedStateException(type: String):
IllegalStateException("Unexpected message type: $type")
}
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,8 @@ fun AusweisView(
text = stringResource(
if (status.value == AusweisModel.NetworkError) {
R.string.eid_network_error
} else if (status.value == AusweisModel.PinError) {
R.string.eid_pin_error
} else {
R.string.eid_generic_error
}),
Expand Down
1 change: 1 addition & 0 deletions wallet/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@
<string name="eid_nfc_scanning">Scanning eID using NFC</string>
<string name="eid_enter_pin">Enter your PIN</string>
<string name="eid_network_error">Error establishing network connection</string>
<string name="eid_pin_error">Incorrect PIN entered too many times. The card is locked. Use Ausweis App to unlock the card.</string>
<string name="eid_generic_error">Error scanning or processing the card</string>
<string name="eid_try_again">Try again</string>

Expand Down