diff options
-rw-r--r-- | smcc/src/main/java/at/gv/egiz/smcc/reader/DefaultCardReader.java | 30 | ||||
-rw-r--r-- | smcc/src/main/java/at/gv/egiz/smcc/reader/PinpadCardReader.java | 72 |
2 files changed, 64 insertions, 38 deletions
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/reader/DefaultCardReader.java b/smcc/src/main/java/at/gv/egiz/smcc/reader/DefaultCardReader.java index 56680313..06d3d133 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/reader/DefaultCardReader.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/reader/DefaultCardReader.java @@ -43,7 +43,6 @@ import at.gv.egiz.smcc.VerifyAPDUSpec; import at.gv.egiz.smcc.pin.gui.ModifyPINGUI; import at.gv.egiz.smcc.pin.gui.PINGUI; import at.gv.egiz.smcc.util.ISO7816Utils; -import at.gv.egiz.smcc.util.SMCCHelper; /** * @@ -72,9 +71,12 @@ public class DefaultCardReader implements CardReader { log.debug("VERIFY"); Card card = channel.getCard(); boolean regain = dropExclusive(card); - char[] pin = pinGUI.providePIN(pinSpec, retries); - regainExclusive(card, regain); - return channel.transmit(ISO7816Utils.createVerifyAPDU(apduSpec, pin)); + try { + char[] pin = pinGUI.providePIN(pinSpec, retries); + return channel.transmit(ISO7816Utils.createVerifyAPDU(apduSpec, pin)); + } finally { + regainExclusive(card, regain); + } } @Override @@ -84,10 +86,13 @@ public class DefaultCardReader implements CardReader { log.debug("MODIFY (CHANGE_REFERENCE_DATA)"); Card card = channel.getCard(); boolean regain = dropExclusive(card); - char[] oldPIN = pinGUI.provideCurrentPIN(pinSpec, retries); - char[] newPIN = pinGUI.provideNewPIN(pinSpec); - regainExclusive(card, regain); - return channel.transmit(ISO7816Utils.createChangeReferenceDataAPDU(apduSpec, oldPIN, newPIN)); + try { + char[] oldPIN = pinGUI.provideCurrentPIN(pinSpec, retries); + char[] newPIN = pinGUI.provideNewPIN(pinSpec); + return channel.transmit(ISO7816Utils.createChangeReferenceDataAPDU(apduSpec, oldPIN, newPIN)); + } finally { + regainExclusive(card, regain); + } } @Override @@ -97,9 +102,12 @@ public class DefaultCardReader implements CardReader { log.debug("MODIFY (NEW_REFERENCE_DATA)"); Card card = channel.getCard(); boolean regain = dropExclusive(card); - char[] newPIN = pinGUI.provideNewPIN(pinSpec); - regainExclusive(card, regain); - return channel.transmit(ISO7816Utils.createNewReferenceDataAPDU(apduSpec, newPIN)); + try { + char[] newPIN = pinGUI.provideNewPIN(pinSpec); + return channel.transmit(ISO7816Utils.createNewReferenceDataAPDU(apduSpec, newPIN)); + } finally { + regainExclusive(card, regain); + } } @Override diff --git a/smcc/src/main/java/at/gv/egiz/smcc/reader/PinpadCardReader.java b/smcc/src/main/java/at/gv/egiz/smcc/reader/PinpadCardReader.java index 56d2233c..9a7206ec 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/reader/PinpadCardReader.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/reader/PinpadCardReader.java @@ -596,22 +596,28 @@ public class PinpadCardReader extends DefaultCardReader { byte[] s = createPINVerifyStructure(apduSpec, pinSpec); Card icc = channel.getCard(); - boolean regain; if (VERIFY) { - regain = dropExclusive(icc); - pinGUI.enterPIN(pinSpec, retries); - resp = new ResponseAPDU(verifyPin(icc, s, pinGUI)); + boolean regain = dropExclusive(icc); + try { + pinGUI.enterPIN(pinSpec, retries); + resp = new ResponseAPDU(verifyPin(icc, s, pinGUI)); + } finally { + regainExclusive(icc, regain); + } } else if (VERIFY_DIRECT) { - regain = dropExclusive(icc); - pinGUI.enterPINDirect(pinSpec, retries); - log.debug("VERIFY_PIN_DIRECT [{}]", FEATURES[FEATURE_VERIFY_PIN_DIRECT]); - resp = new ResponseAPDU(VERIFY_PIN_DIRECT(icc, s)); + boolean regain = dropExclusive(icc); + try { + pinGUI.enterPINDirect(pinSpec, retries); + log.debug("VERIFY_PIN_DIRECT [{}]", FEATURES[FEATURE_VERIFY_PIN_DIRECT]); + resp = new ResponseAPDU(VERIFY_PIN_DIRECT(icc, s)); + } finally { + regainExclusive(icc, regain); + } } else { log.warn("Falling back to default pin-entry."); return super.verify(channel, apduSpec, pinGUI, pinSpec, retries); } - regainExclusive(icc, regain); switch (resp.getSW()) { case 0x6400: @@ -643,22 +649,28 @@ public class PinpadCardReader extends DefaultCardReader { byte[] s = createPINModifyStructure(apduSpec, pinSpec); Card icc = channel.getCard(); - boolean regain; if (MODIFY) { - regain = dropExclusive(icc); - pinGUI.enterCurrentPIN(pinSpec, retries); - resp = new ResponseAPDU(modifyPin(icc, s, pinGUI, pinSpec)); + boolean regain = dropExclusive(icc); + try { + pinGUI.enterCurrentPIN(pinSpec, retries); + resp = new ResponseAPDU(modifyPin(icc, s, pinGUI, pinSpec)); + } finally { + regainExclusive(icc, regain); + } } else if (MODIFY_DIRECT) { - regain = dropExclusive(icc); - pinGUI.modifyPINDirect(pinSpec, retries); - log.debug("MODIFY_PIN_DIRECT [{}]", FEATURES[FEATURE_MODIFY_PIN_DIRECT]); - resp = new ResponseAPDU(MODIFY_PIN_DIRECT(icc, s)); + boolean regain = dropExclusive(icc); + try { + pinGUI.modifyPINDirect(pinSpec, retries); + log.debug("MODIFY_PIN_DIRECT [{}]", FEATURES[FEATURE_MODIFY_PIN_DIRECT]); + resp = new ResponseAPDU(MODIFY_PIN_DIRECT(icc, s)); + } finally { + regainExclusive(icc, regain); + } } else { log.warn("Falling back to default pin-entry."); return super.modify(channel, apduSpec, pinGUI, pinSpec, retries); } - regainExclusive(icc, regain); switch (resp.getSW()) { case 0x6400: @@ -694,22 +706,28 @@ public class PinpadCardReader extends DefaultCardReader { byte[] s = createPINModifyStructure(apduSpec, pinSpec); Card icc = channel.getCard(); - boolean regain; if (MODIFY) { - regain = dropExclusive(icc); - pinGUI.enterNewPIN(pinSpec); - resp = new ResponseAPDU(modifyPin(icc, s, pinGUI, pinSpec)); + boolean regain = dropExclusive(icc); + try { + pinGUI.enterNewPIN(pinSpec); + resp = new ResponseAPDU(modifyPin(icc, s, pinGUI, pinSpec)); + } finally { + regainExclusive(icc, regain); + } } else if (MODIFY_DIRECT) { - regain = dropExclusive(icc); - pinGUI.modifyPINDirect(pinSpec, -1); - log.debug("MODIFY_PIN_DIRECT [{}]", FEATURES[FEATURE_MODIFY_PIN_DIRECT]); - resp = new ResponseAPDU(MODIFY_PIN_DIRECT(icc, s)); + boolean regain = dropExclusive(icc); + try { + pinGUI.modifyPINDirect(pinSpec, -1); + log.debug("MODIFY_PIN_DIRECT [{}]", FEATURES[FEATURE_MODIFY_PIN_DIRECT]); + resp = new ResponseAPDU(MODIFY_PIN_DIRECT(icc, s)); + } finally { + regainExclusive(icc, regain); + } } else { log.warn("Falling back to default pin-entry."); return super.modify(channel, apduSpec, pinGUI, pinSpec); } - regainExclusive(icc, regain); switch (resp.getSW()) { case 0x6400: |