add better exception handling

This commit is contained in:
Michele Balistreri 2018-11-30 09:55:49 +03:00
parent b7f9df6383
commit a0c15da432
1 changed files with 13 additions and 5 deletions

View File

@ -266,11 +266,11 @@ public class WalletApplet extends Applet {
break;
}
} catch(ISOException sw) {
if (shouldRespond(apdu) && (sw.getReason() != ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED)) {
secureChannel.respond(apdu, (short) 0, sw.getReason());
} else {
throw sw;
}
handleException(apdu, sw.getReason());
} catch (CryptoException ce) {
handleException(apdu, (short)(ISO7816.SW_UNKNOWN | ce.getReason()));
} catch (Exception e) {
handleException(apdu, ISO7816.SW_UNKNOWN);
}
if (shouldRespond(apdu)) {
@ -278,6 +278,14 @@ public class WalletApplet extends Applet {
}
}
private void handleException(APDU apdu, short sw) {
if (shouldRespond(apdu) && (sw != ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED)) {
secureChannel.respond(apdu, (short) 0, sw);
} else {
ISOException.throwIt(sw);
}
}
/**
* Processes the init command, this is invoked only if the applet has not yet been personalized with secrets.
*