diff options
author | tkellner <tkellner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2013-04-10 15:15:12 +0000 |
---|---|---|
committer | tkellner <tkellner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2013-04-10 15:15:12 +0000 |
commit | eca63e98023ea8b2dd51100ad9d5e5cbc75fd0b1 (patch) | |
tree | 46a85c66b4a2d439447eb66799f3811c249d75b2 /smcc/src/main/java/at | |
parent | 4f8ceef828caa55526fe0dec3bae1c35ff8f5e3f (diff) | |
download | mocca-eca63e98023ea8b2dd51100ad9d5e5cbc75fd0b1.tar.gz mocca-eca63e98023ea8b2dd51100ad9d5e5cbc75fd0b1.tar.bz2 mocca-eca63e98023ea8b2dd51100ad9d5e5cbc75fd0b1.zip |
Solve Win8 issues by dropping exclusive access during pin entry
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1169 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'smcc/src/main/java/at')
3 files changed, 69 insertions, 2 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 fef60e2b..d3cb9a81 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,6 +43,7 @@ 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; /** * @@ -69,7 +70,11 @@ public class DefaultCardReader implements CardReader { throws SignatureCardException, CardException, InterruptedException { log.debug("VERIFY"); - return channel.transmit(ISO7816Utils.createVerifyAPDU(apduSpec, pinGUI.providePIN(pinSpec, retries))); + Card card = channel.getCard(); + boolean regain = dropExclusive(card); + char[] pin = pinGUI.providePIN(pinSpec, retries); + regainExclusive(card, regain); + return channel.transmit(ISO7816Utils.createVerifyAPDU(apduSpec, pin)); } @Override @@ -77,8 +82,11 @@ public class DefaultCardReader implements CardReader { ModifyPINGUI pinGUI, PinInfo pinSpec, int retries) throws SignatureCardException, CardException, InterruptedException { 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)); } @@ -87,7 +95,10 @@ public class DefaultCardReader implements CardReader { ModifyPINGUI pinGUI, PinInfo pinSpec) throws SignatureCardException, CardException, InterruptedException { 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)); } @@ -111,4 +122,23 @@ public class DefaultCardReader implements CardReader { return false; } + private boolean dropExclusive(Card card) throws CardException { + if (SMCCHelper.isWindows8()) { + log.debug("Win8 - giving up exclusive acess"); + try { + card.endExclusive(); + } catch (IllegalStateException e) { + log.debug("Didn't have exclusive access"); + return false; + } + } + return true; + } + + private void regainExclusive(Card card, boolean doRegainExclusive) throws CardException { + if (SMCCHelper.isWindows8() && doRegainExclusive) { + log.debug("Win8 - trying to regain exclusive acess"); + card.beginExclusive(); + } + } } 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 d7fdc17f..f02344eb 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,11 +596,14 @@ 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)); } 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)); @@ -608,6 +611,7 @@ public class PinpadCardReader extends DefaultCardReader { log.warn("Falling back to default pin-entry."); return super.verify(channel, apduSpec, pinGUI, pinSpec, retries); } + regainExclusive(icc, regain); switch (resp.getSW()) { case 0x6400: @@ -639,11 +643,14 @@ 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)); } 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)); @@ -651,6 +658,7 @@ public class PinpadCardReader extends DefaultCardReader { log.warn("Falling back to default pin-entry."); return super.modify(channel, apduSpec, pinGUI, pinSpec, retries); } + regainExclusive(icc, regain); switch (resp.getSW()) { case 0x6400: @@ -686,11 +694,14 @@ 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)); } 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)); @@ -698,6 +709,7 @@ public class PinpadCardReader extends DefaultCardReader { log.warn("Falling back to default pin-entry."); return super.modify(channel, apduSpec, pinGUI, pinSpec); } + regainExclusive(icc, regain); switch (resp.getSW()) { case 0x6400: @@ -731,4 +743,24 @@ public class PinpadCardReader extends DefaultCardReader { //TODO return modify(channel, (ChangeReferenceDataAPDUSpec) apduSpec, pinGUI, pinSpec, retries); } + + private boolean dropExclusive(Card card) throws CardException { + if (SMCCHelper.isWindows8()) { + log.debug("Win8 - giving up exclusive acess"); + try { + card.endExclusive(); + } catch (IllegalStateException e) { + log.debug("Didn't have exclusive access"); + return false; + } + } + return true; + } + + private void regainExclusive(Card card, boolean doRegainExclusive) throws CardException { + if (SMCCHelper.isWindows8() && doRegainExclusive) { + log.debug("Win8 - trying to regain exclusive acess"); + card.beginExclusive(); + } + } } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/util/SMCCHelper.java b/smcc/src/main/java/at/gv/egiz/smcc/util/SMCCHelper.java index 3c8ff830..54c831cc 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/util/SMCCHelper.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/util/SMCCHelper.java @@ -196,4 +196,9 @@ public class SMCCHelper { public static void setUseSWCard(boolean useSWCard) { SMCCHelper.useSWCard = useSWCard; } + + public static boolean isWindows8() { + String osName = System.getProperty("os.name"); + return osName.contains("Windows 8"); + } } |