From a0c15da432b468a4ad7d5d5ee8ccf6266787142d Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Fri, 30 Nov 2018 09:55:49 +0300 Subject: [PATCH] add better exception handling --- .../java/im/status/wallet/WalletApplet.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/im/status/wallet/WalletApplet.java b/src/main/java/im/status/wallet/WalletApplet.java index 56a27fd..a77fb21 100644 --- a/src/main/java/im/status/wallet/WalletApplet.java +++ b/src/main/java/im/status/wallet/WalletApplet.java @@ -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. *