Better error handling for generic IOException

This commit is contained in:
Dominik Schürmann
2017-10-25 15:46:46 +02:00
committed by Vincent Breitmoser
parent 0920d97572
commit ed4e21957c
2 changed files with 115 additions and 117 deletions

View File

@@ -233,6 +233,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
} }
private void handleSecurityTokenError(SecurityTokenConnection stConnection, IOException e) { private void handleSecurityTokenError(SecurityTokenConnection stConnection, IOException e) {
Log.d(Constants.TAG, "Exception in handleSecurityTokenError", e);
if (e instanceof TagLostException) { if (e instanceof TagLostException) {
onSecurityTokenError(getString(R.string.security_token_error_tag_lost)); onSecurityTokenError(getString(R.string.security_token_error_tag_lost));
@@ -254,12 +255,8 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
return; return;
} }
short status;
if (e instanceof CardException) { if (e instanceof CardException) {
status = ((CardException) e).getResponseCode(); short status = ((CardException) e).getResponseCode();
} else {
status = -1;
}
// Wrong PIN, a status of 63CX indicates X attempts remaining. // Wrong PIN, a status of 63CX indicates X attempts remaining.
// NOTE: Used in ykneo-openpgp version < 1.0.10, changed to 0x6982 in 1.0.11 // NOTE: Used in ykneo-openpgp version < 1.0.10, changed to 0x6982 in 1.0.11
@@ -279,13 +276,8 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
return; return;
} }
Log.d(Constants.TAG, "security token exception", e);
// Otherwise, all status codes are fixed values. // Otherwise, all status codes are fixed values.
switch (status) { switch (status) {
// These error conditions are likely to be experienced by an end user.
/* OpenPGP Card Spec: Security status not satisfied, PW wrong, /* OpenPGP Card Spec: Security status not satisfied, PW wrong,
PW not checked (command not allowed), Secure messaging incorrect (checksum and/or cryptogram) */ PW not checked (command not allowed), Secure messaging incorrect (checksum and/or cryptogram) */
// NOTE: Used in ykneo-openpgp >= 1.0.11 for wrong PIN // NOTE: Used in ykneo-openpgp >= 1.0.11 for wrong PIN
@@ -353,8 +345,6 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
} else { } else {
promptFidesmoAppInstall(); promptFidesmoAppInstall();
} }
} else { // Other (possibly) compatible hardware
onSecurityTokenError(getString(R.string.security_token_error_pgp_app_not_installed));
} }
break; break;
} }
@@ -387,7 +377,14 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity
break; break;
} }
} }
}
// fallback for generic IOException
if (e.getMessage() != null) {
onSecurityTokenError(getString(R.string.security_token_error, e.getMessage()));
} else {
onSecurityTokenError(getString(R.string.security_token_error_generic));
}
} }
/** /**

View File

@@ -1580,6 +1580,7 @@
<string name="security_token_error_header">"Security Token reported invalid %s byte."</string> <string name="security_token_error_header">"Security Token reported invalid %s byte."</string>
<string name="security_token_error_tag_lost">"Security Token has been taken off too early. Keep the Security Token at the back until the operation finishes."</string> <string name="security_token_error_tag_lost">"Security Token has been taken off too early. Keep the Security Token at the back until the operation finishes."</string>
<string name="security_token_error_iso_dep_not_supported">"Security Token does not support the required communication standard (ISO-DEP, ISO 14443-4)"</string> <string name="security_token_error_iso_dep_not_supported">"Security Token does not support the required communication standard (ISO-DEP, ISO 14443-4)"</string>
<string name="security_token_error_generic">"Generic Error: Most probably, the Security Token has been taken off too early."</string>
<string name="security_token_not_supported">"This Security Token is not supported by OpenKeychain."</string> <string name="security_token_not_supported">"This Security Token is not supported by OpenKeychain."</string>
<string name="security_token_error_try_again">"Try again"</string> <string name="security_token_error_try_again">"Try again"</string>
<string name="btn_delete_original">Delete original file</string> <string name="btn_delete_original">Delete original file</string>