Skip to content

Commit

Permalink
Fix for unexpected Ausweis SDK responses.
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Sorotokin <[email protected]>
  • Loading branch information
sorotokin committed Nov 22, 2024
1 parent cd1c59d commit afd8b84
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
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

0 comments on commit afd8b84

Please sign in to comment.