summaryrefslogtreecommitdiff
path: root/smcc/src/main/java/at/gv/egiz/smcc/reader
diff options
context:
space:
mode:
Diffstat (limited to 'smcc/src/main/java/at/gv/egiz/smcc/reader')
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/reader/CardReader.java32
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/reader/DefaultCardReader.java16
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/reader/PinpadCardReader.java167
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/reader/ReaderFactory.java32
4 files changed, 123 insertions, 124 deletions
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/reader/CardReader.java b/smcc/src/main/java/at/gv/egiz/smcc/reader/CardReader.java
index a1246dd6..6c5e939b 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/reader/CardReader.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/reader/CardReader.java
@@ -23,7 +23,7 @@ import javax.smartcardio.ResponseAPDU;
import at.gv.egiz.smcc.CancelledException;
import at.gv.egiz.smcc.ChangeReferenceDataAPDUSpec;
import at.gv.egiz.smcc.NewReferenceDataAPDUSpec;
-import at.gv.egiz.smcc.PINSpec;
+import at.gv.egiz.smcc.PinInfo;
import at.gv.egiz.smcc.ResetRetryCounterAPDUSpec;
import at.gv.egiz.smcc.SignatureCardException;
import at.gv.egiz.smcc.VerifyAPDUSpec;
@@ -38,7 +38,7 @@ import javax.smartcardio.Card;
public interface CardReader {
- String[] FEATURES = new String[]{"NO_FEATURE",
+ static final String[] FEATURES = new String[]{"NO_FEATURE",
"FEATURE_VERIFY_PIN_START",
"FEATURE_VERIFY_PIN_FINISH",
"FEATURE_MODIFY_PIN_START",
@@ -57,16 +57,16 @@ public interface CardReader {
"FEATURE_GET_KEY",
"FEATURE_IFD_DISPLAY_PROPERTIES"};
- Byte FEATURE_VERIFY_PIN_START = new Byte((byte) 0x01);
- Byte FEATURE_VERIFY_PIN_FINISH = new Byte((byte) 0x02);
- Byte FEATURE_MODIFY_PIN_START = new Byte((byte) 0x03);
- Byte FEATURE_MODIFY_PIN_FINISH = new Byte((byte) 0x04);
- Byte FEATURE_GET_KEY_PRESSED = new Byte((byte) 0x05);
- Byte FEATURE_VERIFY_PIN_DIRECT = new Byte((byte) 0x06);
- Byte FEATURE_MODIFY_PIN_DIRECT = new Byte((byte) 0x07);
- Byte FEATURE_MCT_READER_DIRECT = new Byte((byte) 0x08);
- Byte FEATURE_MCT_UNIVERSAL = new Byte((byte) 0x09);
- Byte FEATURE_IFD_PIN_PROPERTIES = new Byte((byte) 0x0a);
+ static final Byte FEATURE_VERIFY_PIN_START = new Byte((byte) 0x01);
+ static final Byte FEATURE_VERIFY_PIN_FINISH = new Byte((byte) 0x02);
+ static final Byte FEATURE_MODIFY_PIN_START = new Byte((byte) 0x03);
+ static final Byte FEATURE_MODIFY_PIN_FINISH = new Byte((byte) 0x04);
+ static final Byte FEATURE_GET_KEY_PRESSED = new Byte((byte) 0x05);
+ static final Byte FEATURE_VERIFY_PIN_DIRECT = new Byte((byte) 0x06);
+ static final Byte FEATURE_MODIFY_PIN_DIRECT = new Byte((byte) 0x07);
+ static final Byte FEATURE_MCT_READER_DIRECT = new Byte((byte) 0x08);
+ static final Byte FEATURE_MCT_UNIVERSAL = new Byte((byte) 0x09);
+ static final Byte FEATURE_IFD_PIN_PROPERTIES = new Byte((byte) 0x0a);
//TODO continue list
@@ -75,18 +75,18 @@ public interface CardReader {
boolean hasFeature(Byte feature);
ResponseAPDU verify(CardChannel channel, VerifyAPDUSpec apduSpec,
- PINGUI pinGUI, PINSpec pinSpec, int retries)
+ PINGUI pinGUI, PinInfo pinInfo, int retries)
throws CancelledException, InterruptedException, CardException, SignatureCardException;
ResponseAPDU modify(CardChannel channel, ChangeReferenceDataAPDUSpec apduSpec,
- ModifyPINGUI pinGUI, PINSpec pinSpec, int retries)
+ ModifyPINGUI pinGUI, PinInfo pinInfo, int retries)
throws CancelledException, InterruptedException, CardException, SignatureCardException;
ResponseAPDU modify(CardChannel channel, NewReferenceDataAPDUSpec apduSpec,
- ModifyPINGUI pinGUI, PINSpec pinSpec)
+ ModifyPINGUI pinGUI, PinInfo pinInfo)
throws CancelledException, InterruptedException, CardException, SignatureCardException;
ResponseAPDU modify(CardChannel channel, ResetRetryCounterAPDUSpec apduSpec,
- ModifyPINGUI pinGUI, PINSpec pinSpec, int retries)
+ ModifyPINGUI pinGUI, PinInfo pinInfo, int retries)
throws CancelledException, InterruptedException, CardException, SignatureCardException;
}
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 03a794fe..cc25a63c 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
@@ -23,12 +23,12 @@ import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.ResponseAPDU;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.gv.egiz.smcc.ChangeReferenceDataAPDUSpec;
import at.gv.egiz.smcc.NewReferenceDataAPDUSpec;
-import at.gv.egiz.smcc.PINSpec;
+import at.gv.egiz.smcc.PinInfo;
import at.gv.egiz.smcc.ResetRetryCounterAPDUSpec;
import at.gv.egiz.smcc.SignatureCardException;
import at.gv.egiz.smcc.VerifyAPDUSpec;
@@ -42,7 +42,7 @@ import at.gv.egiz.smcc.util.ISO7816Utils;
*/
public class DefaultCardReader implements CardReader {
- protected final static Log log = LogFactory.getLog(DefaultCardReader.class);
+ private final Logger log = LoggerFactory.getLogger(DefaultCardReader.class);
protected CardTerminal ct;
protected String name;
@@ -57,7 +57,7 @@ public class DefaultCardReader implements CardReader {
@Override
public ResponseAPDU verify(CardChannel channel, VerifyAPDUSpec apduSpec,
- PINGUI pinGUI, PINSpec pinSpec, int retries)
+ PINGUI pinGUI, PinInfo pinSpec, int retries)
throws SignatureCardException, CardException, InterruptedException {
log.debug("VERIFY");
@@ -66,7 +66,7 @@ public class DefaultCardReader implements CardReader {
@Override
public ResponseAPDU modify(CardChannel channel, ChangeReferenceDataAPDUSpec apduSpec,
- ModifyPINGUI pinGUI, PINSpec pinSpec, int retries)
+ ModifyPINGUI pinGUI, PinInfo pinSpec, int retries)
throws SignatureCardException, CardException, InterruptedException {
log.debug("MODIFY (CHANGE_REFERENCE_DATA)");
char[] oldPIN = pinGUI.provideCurrentPIN(pinSpec, retries);
@@ -76,7 +76,7 @@ public class DefaultCardReader implements CardReader {
@Override
public ResponseAPDU modify(CardChannel channel, NewReferenceDataAPDUSpec apduSpec,
- ModifyPINGUI pinGUI, PINSpec pinSpec)
+ ModifyPINGUI pinGUI, PinInfo pinSpec)
throws SignatureCardException, CardException, InterruptedException {
log.debug("MODIFY (NEW_REFERENCE_DATA)");
char[] newPIN = pinGUI.provideNewPIN(pinSpec);
@@ -85,7 +85,7 @@ public class DefaultCardReader implements CardReader {
@Override
public ResponseAPDU modify(CardChannel channel, ResetRetryCounterAPDUSpec apduSpec,
- ModifyPINGUI pinGUI, PINSpec pinSpec, int retries)
+ ModifyPINGUI pinGUI, PinInfo pinSpec, int retries)
throws InterruptedException, CardException, SignatureCardException {
log.debug("MODIFY (RESET_RETRY_COUNTER)");
//TODO
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 c2537af8..3584af53 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
@@ -26,8 +26,8 @@ import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.ResponseAPDU;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.gv.egiz.smcc.CancelledException;
import at.gv.egiz.smcc.ChangeReferenceDataAPDUSpec;
@@ -35,7 +35,7 @@ import at.gv.egiz.smcc.NewReferenceDataAPDUSpec;
import at.gv.egiz.smcc.PINConfirmationException;
import at.gv.egiz.smcc.PINFormatException;
import at.gv.egiz.smcc.PINOperationAbortedException;
-import at.gv.egiz.smcc.PINSpec;
+import at.gv.egiz.smcc.PinInfo;
import at.gv.egiz.smcc.ResetRetryCounterAPDUSpec;
import at.gv.egiz.smcc.SignatureCardException;
import at.gv.egiz.smcc.TimeoutException;
@@ -52,13 +52,13 @@ public class PinpadCardReader extends DefaultCardReader {
public static final int PIN_ENTRY_POLLING_INTERVAL = 10;
- protected final static Log log = LogFactory.getLog(PinpadCardReader.class);
+ private final Logger log = LoggerFactory.getLogger(PinpadCardReader.class);
protected byte bEntryValidationCondition = 0x02; // validation key pressed
protected byte bTimeOut = 0x3c; // 60sec (= max on ReinerSCT)
protected byte bTimeOut2 = 0x00; // default (attention with SCM)
- protected byte wPINMaxExtraDigitH = 0x00; // min pin length zero digits
- protected byte wPINMaxExtraDigitL = 0x0c; // max pin length 12 digits
+ protected byte wPINMaxExtraDigitMin = 0x00; // min pin length zero digits
+ protected byte wPINMaxExtraDigitMax = 0x0c; // max pin length 12 digits
/**
* supported features and respective control codes
@@ -99,21 +99,21 @@ public class PinpadCardReader extends DefaultCardReader {
//Snow Leopard: Reiner-SCT cyberJack pinpad(a) 00 00
//display: REINER SCT CyberJack 00 00
if(name.startsWith("gemplus gempc pinpad") || name.startsWith("gemalto gempc pinpad")) {
- log.debug("setting custom wPINMaxExtraDigitH (0x04) for " + name);
- wPINMaxExtraDigitH = 0x04;
- log.debug("setting custom wPINMaxExtraDigitL (0x08) for " + name);
- wPINMaxExtraDigitL = 0x08;
+ log.trace("Setting custom wPINMaxExtraDigitH (0x04) for {}.", name);
+ wPINMaxExtraDigitMin = 0x04;
+ log.trace("Setting custom wPINMaxExtraDigitL (0x08) for {}.", name);
+ wPINMaxExtraDigitMax = 0x08;
} else if (name.startsWith("omnikey cardman 3621")) {
- log.debug("setting custom wPINMaxExtraDigitH (0x01) for " + name);
- wPINMaxExtraDigitH = 0x01;
+ log.trace("Setting custom wPINMaxExtraDigitH (0x01) for {}.", name);
+ wPINMaxExtraDigitMin = 0x01;
} else if (name.startsWith("scm spr 532") || name.startsWith("scm microsystems inc. sprx32 usb smart card reader")) {
- log.debug("setting custom bTimeOut (0x3c) for " + name);
+ log.trace("Setting custom bTimeOut (0x3c) for {}.", name);
bTimeOut = 0x3c;
- log.debug("setting custom bTimeOut2 (0x0f) for " + name);
+ log.trace("Setting custom bTimeOut2 (0x0f) for {}.", name);
bTimeOut2 = 0x0f;
} else if (name.startsWith("cherry smartboard xx44")) {
- log.debug("setting custom wPINMaxExtraDigitH (0x01) for " + name);
- wPINMaxExtraDigitH = 0x01;
+ log.trace("Setting custom wPINMaxExtraDigitH (0x01) for {}.", name);
+ wPINMaxExtraDigitMin = 0x01;
}
}
@@ -127,17 +127,17 @@ public class PinpadCardReader extends DefaultCardReader {
private void VERIFY_PIN_START(Card icc, byte[] PIN_VERIFY) throws CardException {
int ioctl = features.get(FEATURE_VERIFY_PIN_START);
if (log.isTraceEnabled()) {
- log.trace("VERIFY_PIN_START (" + Integer.toHexString(ioctl) +
- ") " + SMCCHelper.toString(PIN_VERIFY));
+ log.trace("VERIFY_PIN_START ({}) {}", Integer.toHexString(ioctl),
+ SMCCHelper.toString(PIN_VERIFY));
}
byte[] resp = icc.transmitControlCommand(ioctl, PIN_VERIFY);
if (resp != null && resp.length > 0) {
if (resp[0] == (byte) 0x57) {
- log.error("Invalid parameter in PIN_VERIFY structure");
+ log.error("Invalid parameter in PIN_VERIFY structure.");
throw new CardException("ERROR_INVALID_PARAMETER");
} else {
- log.error("unexpected response to VERIFY_PIN_START: " +
- SMCCHelper.toString(resp));
+ log.error("Unexpected response to VERIFY_PIN_START: {}.", SMCCHelper
+ .toString(resp));
throw new CardException("unexpected response to VERIFY_PIN_START: " +
SMCCHelper.toString(resp));
}
@@ -153,7 +153,7 @@ public class PinpadCardReader extends DefaultCardReader {
// }
return resp[0];
}
- log.error("unexpected response to GET_KEY_PRESSED: " +
+ log.error("Unexpected response to GET_KEY_PRESSED: {}.",
SMCCHelper.toString(resp));
throw new CardException("unexpected response to GET_KEY_PRESSED: " +
SMCCHelper.toString(resp));
@@ -162,16 +162,16 @@ public class PinpadCardReader extends DefaultCardReader {
private byte[] VERIFY_PIN_FINISH(Card icc) throws CardException {
int ioctl = features.get(FEATURE_VERIFY_PIN_FINISH);
if (log.isTraceEnabled()) {
- log.trace("VERIFY_PIN_FINISH (" + Integer.toHexString(ioctl) + ")");
+ log.trace("VERIFY_PIN_FINISH ({})", Integer.toHexString(ioctl));
}
byte[] resp = icc.transmitControlCommand(ioctl, new byte[0]);
if (resp != null && resp.length == 2) {
if (log.isTraceEnabled()) {
- log.trace("response " + SMCCHelper.toString(resp));
+ log.trace("response {}", SMCCHelper.toString(resp));
}
return resp;
}
- log.error("unexpected response to VERIFY_PIN_FINISH: " +
+ log.error("Unexpected response to VERIFY_PIN_FINISH: {}.",
SMCCHelper.toString(resp));
throw new CardException("unexpected response to VERIFY_PIN_FINISH: " +
SMCCHelper.toString(resp));
@@ -186,10 +186,10 @@ public class PinpadCardReader extends DefaultCardReader {
byte[] resp = icc.transmitControlCommand(ioctl, PIN_MODIFY);
if (resp != null && resp.length > 0) {
if (resp[0] == (byte) 0x57) {
- log.error("Invalid parameter in PIN_MODIFY structure");
+ log.error("Invalid parameter in PIN_MODIFY structure.");
throw new CardException("ERROR_INVALID_PARAMETER");
} else {
- log.error("unexpected response to MODIFY_PIN_START: " +
+ log.error("Unexpected response to MODIFY_PIN_START: {}.",
SMCCHelper.toString(resp));
throw new CardException("unexpected response to MODIFY_PIN_START: " +
SMCCHelper.toString(resp));
@@ -200,16 +200,16 @@ public class PinpadCardReader extends DefaultCardReader {
private byte[] MODIFY_PIN_FINISH(Card icc) throws CardException {
int ioctl = features.get(FEATURE_MODIFY_PIN_FINISH);
if (log.isTraceEnabled()) {
- log.trace("MODIFY_PIN_FINISH (" + Integer.toHexString(ioctl) + ")");
+ log.trace("MODIFY_PIN_FINISH ({})", Integer.toHexString(ioctl));
}
byte[] resp = icc.transmitControlCommand(ioctl, new byte[0]);
if (resp != null && resp.length == 2) {
if (log.isTraceEnabled()) {
- log.trace("response " + SMCCHelper.toString(resp));
+ log.trace("response {}", SMCCHelper.toString(resp));
}
return resp;
}
- log.error("unexpected response to MODIFY_PIN_FINISH: " +
+ log.error("Unexpected response to MODIFY_PIN_FINISH: {}",
SMCCHelper.toString(resp));
throw new CardException("unexpected response to MODIFY_PIN_FINISH: " +
SMCCHelper.toString(resp));
@@ -218,12 +218,12 @@ public class PinpadCardReader extends DefaultCardReader {
private byte[] VERIFY_PIN_DIRECT(Card icc, byte[] PIN_VERIFY) throws CardException {
int ioctl = features.get(FEATURE_VERIFY_PIN_DIRECT);
if (log.isTraceEnabled()) {
- log.trace("VERIFY_PIN_DIRECT (" + Integer.toHexString(ioctl) +
- ") " + SMCCHelper.toString(PIN_VERIFY));
+ log.trace("VERIFY_PIN_DIRECT ({}) {}", Integer.toHexString(ioctl),
+ SMCCHelper.toString(PIN_VERIFY));
}
byte[] resp = icc.transmitControlCommand(ioctl, PIN_VERIFY);
if (log.isTraceEnabled()) {
- log.trace("response " + SMCCHelper.toString(resp));
+ log.trace("response {}", SMCCHelper.toString(resp));
}
return resp;
}
@@ -233,7 +233,7 @@ public class PinpadCardReader extends DefaultCardReader {
// pinGUI.enterPIN(pinSpec, retries);
- log.debug("VERIFY_PIN_START [" + FEATURES[FEATURE_VERIFY_PIN_START] + "]");
+ log.debug("VERIFY_PIN_START [{}]", FEATURES[FEATURE_VERIFY_PIN_START]);
VERIFY_PIN_START(icc, PIN_VERIFY);
byte resp;
@@ -248,29 +248,29 @@ public class PinpadCardReader extends DefaultCardReader {
}
}
} else if (resp == (byte) 0x0d) {
- log.debug("GET_KEY_PRESSED: 0x0d (user confirmed)");
+ log.trace("GET_KEY_PRESSED: 0x0d (user confirmed)");
break;
} else if (resp == (byte) 0x2b) {
log.trace("GET_KEY_PRESSED: 0x2b (user entered valid key 0-9)");
pinGUI.validKeyPressed();
} else if (resp == (byte) 0x1b) {
- log.debug("GET_KEY_PRESSED: 0x1b (user cancelled VERIFY_PIN via cancel button)");
+ log.trace("GET_KEY_PRESSED: 0x1b (user cancelled VERIFY_PIN via cancel button)");
break; // returns 0x6401
} else if (resp == (byte) 0x08) {
- log.debug("GET_KEY_PRESSED: 0x08 (user pressed correction/backspace button)");
+ log.trace("GET_KEY_PRESSED: 0x08 (user pressed correction/backspace button)");
pinGUI.correctionButtonPressed();
} else if (resp == (byte) 0x0e) {
- log.debug("GET_KEY_PRESSED: 0x0e (timeout occured)");
+ log.trace("GET_KEY_PRESSED: 0x0e (timeout occured)");
break; // return 0x6400
} else if (resp == (byte) 0x40) {
- log.debug("GET_KEY_PRESSED: 0x40 (PIN_Operation_Aborted)");
+ log.trace("GET_KEY_PRESSED: 0x40 (PIN_Operation_Aborted)");
throw new PINOperationAbortedException("PIN_Operation_Aborted (0x40)");
} else if (resp == (byte) 0x0a) {
- log.debug("GET_KEY_PRESSED: 0x0a (all keys cleared");
+ log.trace("GET_KEY_PRESSED: 0x0a (all keys cleared");
pinGUI.allKeysCleared();
} else {
- log.error("unexpected response to GET_KEY_PRESSED: " +
- Integer.toHexString(resp));
+ log.error("Unexpected response to GET_KEY_PRESSED: {}.", Integer
+ .toHexString(resp));
throw new CardException("unexpected response to GET_KEY_PRESSED: " +
Integer.toHexString(resp));
}
@@ -283,7 +283,7 @@ public class PinpadCardReader extends DefaultCardReader {
* does not display the first pin dialog (enterCurrentPIN or enterNewPIN, depends on bConfirmPIN),
* since this is easier to do in calling modify()
*/
- private byte[] modifyPin(Card icc, byte[] PIN_MODIFY, ModifyPINGUI pinGUI, PINSpec pINSpec)
+ private byte[] modifyPin(Card icc, byte[] PIN_MODIFY, ModifyPINGUI pinGUI, PinInfo pINSpec)
throws PINOperationAbortedException, CardException {
byte pinConfirmations = (byte) 0x00; //b0: new pin not entered (0) / entered (1)
@@ -298,7 +298,7 @@ public class PinpadCardReader extends DefaultCardReader {
// pinGUI.enterCurrentPIN(pINSpec, retries);
// }
- log.debug("MODIFY_PIN_START [" + FEATURES[FEATURE_MODIFY_PIN_START] + "]");
+ log.debug("MODIFY_PIN_START [{}]", FEATURES[FEATURE_MODIFY_PIN_START]);
MODIFY_PIN_START(icc, PIN_MODIFY);
byte resp;
@@ -309,13 +309,13 @@ public class PinpadCardReader extends DefaultCardReader {
try {
wait(PIN_ENTRY_POLLING_INTERVAL);
} catch (InterruptedException ex) {
- log.error("interrupted in MODIFY_PIN");
+ log.error("Interrupted in MODIFY_PIN");
}
}
} else if (resp == (byte) 0x0d) {
if (log.isTraceEnabled()) {
- log.trace("requested pin confirmations: 0b" + Integer.toBinaryString(bConfirmPIN & 0xff));
- log.trace("performed pin confirmations: 0b" + Integer.toBinaryString(pinConfirmations & 0xff));
+ log.trace("requested pin confirmations: 0b{}", Integer.toBinaryString(bConfirmPIN & 0xff));
+ log.trace("performed pin confirmations: 0b{}", Integer.toBinaryString(pinConfirmations & 0xff));
}
log.debug("GET_KEY_PRESSED: 0x0d (user confirmed)");
if (pinConfirmations == bConfirmPIN) {
@@ -337,23 +337,23 @@ public class PinpadCardReader extends DefaultCardReader {
log.trace("GET_KEY_PRESSED: 0x2b (user entered valid key 0-9)");
pinGUI.validKeyPressed();
} else if (resp == (byte) 0x1b) {
- log.debug("GET_KEY_PRESSED: 0x1b (user cancelled VERIFY_PIN via cancel button)");
+ log.trace("GET_KEY_PRESSED: 0x1b (user cancelled VERIFY_PIN via cancel button)");
break; // returns 0x6401
} else if (resp == (byte) 0x08) {
- log.debug("GET_KEY_PRESSED: 0x08 (user pressed correction/backspace button)");
+ log.trace("GET_KEY_PRESSED: 0x08 (user pressed correction/backspace button)");
pinGUI.correctionButtonPressed();
} else if (resp == (byte) 0x0e) {
- log.debug("GET_KEY_PRESSED: 0x0e (timeout occured)");
+ log.trace("GET_KEY_PRESSED: 0x0e (timeout occured)");
break; // return 0x6400
} else if (resp == (byte) 0x40) {
- log.debug("GET_KEY_PRESSED: 0x40 (PIN_Operation_Aborted)");
+ log.trace("GET_KEY_PRESSED: 0x40 (PIN_Operation_Aborted)");
throw new PINOperationAbortedException("PIN_Operation_Aborted (0x40)");
} else if (resp == (byte) 0x0a) {
- log.debug("GET_KEY_PRESSED: 0x0a (all keys cleared");
+ log.trace("GET_KEY_PRESSED: 0x0a (all keys cleared");
pinGUI.allKeysCleared();
} else {
- log.error("unexpected response to GET_KEY_PRESSED: " +
- Integer.toHexString(resp));
+ log.error("Unexpected response to GET_KEY_PRESSED: {}.", Integer
+ .toHexString(resp));
throw new CardException("unexpected response to GET_KEY_PRESSED: " +
Integer.toHexString(resp));
}
@@ -367,17 +367,17 @@ public class PinpadCardReader extends DefaultCardReader {
private byte[] MODIFY_PIN_DIRECT(Card icc, byte[] PIN_MODIFY) throws CardException {
int ioctl = features.get(FEATURE_MODIFY_PIN_DIRECT);
if (log.isTraceEnabled()) {
- log.trace("MODIFY_PIN_DIRECT (" + Integer.toHexString(ioctl) +
- ") " + SMCCHelper.toString(PIN_MODIFY));
+ log.trace("MODIFY_PIN_DIRECT ({}) {}", Integer.toHexString(ioctl),
+ SMCCHelper.toString(PIN_MODIFY));
}
byte[] resp = icc.transmitControlCommand(ioctl, PIN_MODIFY);
if (log.isTraceEnabled()) {
- log.trace("response " + SMCCHelper.toString(resp));
+ log.trace("response {}", SMCCHelper.toString(resp));
}
return resp;
}
- protected byte[] createPINModifyStructure(NewReferenceDataAPDUSpec apduSpec, PINSpec pinSpec) {
+ protected byte[] createPINModifyStructure(NewReferenceDataAPDUSpec apduSpec, PinInfo pinSpec) {
ByteArrayOutputStream s = new ByteArrayOutputStream();
// bTimeOut
@@ -399,16 +399,17 @@ public class PinpadCardReader extends DefaultCardReader {
s.write(0x00);
// bInsertionOffsetNew
s.write(apduSpec.getPinInsertionOffsetNew());
- // wPINMaxExtraDigit
- s.write(Math.min(pinSpec.getMaxLength(), wPINMaxExtraDigitL));
- s.write(Math.max(pinSpec.getMinLength(), wPINMaxExtraDigitH));
+ // wPINMaxExtraDigit (little endian)
+ s.write(Math.min(pinSpec.getMaxLength(), wPINMaxExtraDigitMax));
+ s.write(Math.max(pinSpec.getMinLength(), wPINMaxExtraDigitMin));
// bConfirmPIN
s.write(0x01);
// bEntryValidationCondition
s.write(bEntryValidationCondition);
// bNumberMessage
s.write(0x02);
- // wLangId English (United States), see http://www.usb.org/developers/docs/USB_LANGIDs.pdf
+ // wLangId (little endian)
+ // English (United States), see http://www.usb.org/developers/docs/USB_LANGIDs.pdf
s.write(0x09);
s.write(0x04);
// bMsgIndex1
@@ -440,7 +441,7 @@ public class PinpadCardReader extends DefaultCardReader {
}
- protected byte[] createPINModifyStructure(ChangeReferenceDataAPDUSpec apduSpec, PINSpec pinSpec) {
+ protected byte[] createPINModifyStructure(ChangeReferenceDataAPDUSpec apduSpec, PinInfo pinSpec) {
//TODO bInsertionOffsetOld (0x00), bConfirmPIN (0x01), bNumberMessage (0x02), bMsgIndex1/2/3
ByteArrayOutputStream s = new ByteArrayOutputStream();
@@ -464,8 +465,8 @@ public class PinpadCardReader extends DefaultCardReader {
// bInsertionOffsetNew
s.write(apduSpec.getPinInsertionOffsetNew());
// wPINMaxExtraDigit
- s.write(Math.min(pinSpec.getMaxLength(), wPINMaxExtraDigitL));
- s.write(Math.max(pinSpec.getMinLength(), wPINMaxExtraDigitH));
+ s.write(Math.min(pinSpec.getMaxLength(), wPINMaxExtraDigitMax));
+ s.write(Math.max(pinSpec.getMinLength(), wPINMaxExtraDigitMin));
// bConfirmPIN
s.write(0x03);
// bEntryValidationCondition
@@ -504,7 +505,7 @@ public class PinpadCardReader extends DefaultCardReader {
}
- protected byte[] createPINVerifyStructure(VerifyAPDUSpec apduSpec, PINSpec pinSpec) {
+ protected byte[] createPINVerifyStructure(VerifyAPDUSpec apduSpec, PinInfo pinSpec) {
ByteArrayOutputStream s = new ByteArrayOutputStream();
// bTimeOut
@@ -522,14 +523,14 @@ public class PinpadCardReader extends DefaultCardReader {
// bmPINLengthFormat
s.write(// system unit = bit
(0xF & apduSpec.getPinLengthPos()));
- // wPINMaxExtraDigit
- s.write(Math.min(pinSpec.getMaxLength(), wPINMaxExtraDigitL)); // max PIN length
- s.write(Math.max(pinSpec.getMinLength(), wPINMaxExtraDigitH)); // min PIN length
+ // wPINMaxExtraDigit (little endian)
+ s.write(Math.min(pinSpec.getMaxLength(), wPINMaxExtraDigitMax)); // max PIN length
+ s.write(Math.max(pinSpec.getMinLength(), wPINMaxExtraDigitMin)); // min PIN length
// bEntryValidationCondition
s.write(bEntryValidationCondition);
// bNumberMessage
s.write(0x01);
- // wLangId
+ // wLangId (little endian)
s.write(0x09);
s.write(0x04);
// bMsgIndex
@@ -558,7 +559,7 @@ public class PinpadCardReader extends DefaultCardReader {
@Override
public ResponseAPDU verify(CardChannel channel, VerifyAPDUSpec apduSpec,
- PINGUI pinGUI, PINSpec pinSpec, int retries)
+ PINGUI pinGUI, PinInfo pinSpec, int retries)
throws SignatureCardException, CardException, InterruptedException {
ResponseAPDU resp = null;
@@ -571,10 +572,10 @@ public class PinpadCardReader extends DefaultCardReader {
resp = new ResponseAPDU(verifyPin(icc, s, pinGUI));
} else if (VERIFY_DIRECT) {
pinGUI.enterPINDirect(pinSpec, retries);
- log.debug("VERIFY_PIN_DIRECT [" + FEATURES[FEATURE_VERIFY_PIN_DIRECT] + "]");
+ log.debug("VERIFY_PIN_DIRECT [{}]", FEATURES[FEATURE_VERIFY_PIN_DIRECT]);
resp = new ResponseAPDU(VERIFY_PIN_DIRECT(icc, s));
} else {
- log.warn("falling back to default pin-entry");
+ log.warn("Falling back to default pin-entry.");
return super.verify(channel, apduSpec, pinGUI, pinSpec, retries);
}
@@ -586,9 +587,9 @@ public class PinpadCardReader extends DefaultCardReader {
log.debug("SPE operation was cancelled by the 'Cancel' button.");
throw new CancelledException();
case 0x6403:
- log.debug("User entered too short or too long PIN "
- + "regarding MIN/MAX PIN length.");
- throw new PINFormatException();
+ log.debug("User entered too short or too long PIN "
+ + "regarding MIN/MAX PIN length.");
+ throw new PINFormatException();
case 0x6480:
log.debug("SPE operation was aborted by the 'Cancel' operation "
+ "at the host system.");
@@ -601,7 +602,7 @@ public class PinpadCardReader extends DefaultCardReader {
@Override
public ResponseAPDU modify(CardChannel channel, ChangeReferenceDataAPDUSpec apduSpec,
- ModifyPINGUI pinGUI, PINSpec pinSpec, int retries)
+ ModifyPINGUI pinGUI, PinInfo pinSpec, int retries)
throws SignatureCardException, CardException, InterruptedException {
ResponseAPDU resp = null;
@@ -614,10 +615,10 @@ public class PinpadCardReader extends DefaultCardReader {
resp = new ResponseAPDU(modifyPin(icc, s, pinGUI, pinSpec));
} else if (MODIFY_DIRECT) {
pinGUI.modifyPINDirect(pinSpec, retries);
- log.debug("MODIFY_PIN_DIRECT [" + FEATURES[FEATURE_MODIFY_PIN_DIRECT] + "]");
+ log.debug("MODIFY_PIN_DIRECT [{}]", FEATURES[FEATURE_MODIFY_PIN_DIRECT]);
resp = new ResponseAPDU(MODIFY_PIN_DIRECT(icc, s));
} else {
- log.warn("falling back to default pin-entry");
+ log.warn("Falling back to default pin-entry.");
return super.modify(channel, apduSpec, pinGUI, pinSpec, retries);
}
@@ -648,7 +649,7 @@ public class PinpadCardReader extends DefaultCardReader {
@Override
public ResponseAPDU modify(CardChannel channel, NewReferenceDataAPDUSpec apduSpec,
- ModifyPINGUI pinGUI, PINSpec pinSpec)
+ ModifyPINGUI pinGUI, PinInfo pinSpec)
throws SignatureCardException, CardException, InterruptedException {
ResponseAPDU resp = null;
@@ -661,10 +662,10 @@ public class PinpadCardReader extends DefaultCardReader {
resp = new ResponseAPDU(modifyPin(icc, s, pinGUI, pinSpec));
} else if (MODIFY_DIRECT) {
pinGUI.modifyPINDirect(pinSpec, -1);
- log.debug("MODIFY_PIN_DIRECT [" + FEATURES[FEATURE_MODIFY_PIN_DIRECT] + "]");
+ log.debug("MODIFY_PIN_DIRECT [{}]", FEATURES[FEATURE_MODIFY_PIN_DIRECT]);
resp = new ResponseAPDU(MODIFY_PIN_DIRECT(icc, s));
} else {
- log.warn("falling back to default pin-entry");
+ log.warn("Falling back to default pin-entry.");
return super.modify(channel, apduSpec, pinGUI, pinSpec);
}
@@ -695,7 +696,7 @@ public class PinpadCardReader extends DefaultCardReader {
@Override
public ResponseAPDU modify(CardChannel channel, ResetRetryCounterAPDUSpec apduSpec,
- ModifyPINGUI pinGUI, PINSpec pinSpec, int retries)
+ ModifyPINGUI pinGUI, PinInfo pinSpec, int retries)
throws InterruptedException, CardException, SignatureCardException {
//TODO
return modify(channel, (ChangeReferenceDataAPDUSpec) apduSpec, pinGUI, pinSpec, retries);
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/reader/ReaderFactory.java b/smcc/src/main/java/at/gv/egiz/smcc/reader/ReaderFactory.java
index bf1730e9..0d0a8d8a 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/reader/ReaderFactory.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/reader/ReaderFactory.java
@@ -25,8 +25,8 @@ import java.util.Map;
import javax.smartcardio.Card;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
@@ -34,7 +34,7 @@ import org.apache.commons.logging.LogFactory;
*/
public class ReaderFactory {
- protected final static Log log = LogFactory.getLog(ReaderFactory.class);
+ private final Logger log = LoggerFactory.getLogger(ReaderFactory.class);
protected static SMCCConfiguration configuration;
@@ -50,8 +50,9 @@ public class ReaderFactory {
public static CardReader getReader(Card icc, CardTerminal ct) {
+ Logger log = LoggerFactory.getLogger(ReaderFactory.class);
String name = ct.getName();
- log.info("creating reader " + name);
+ log.info("Creating reader : {}.", name);
Map<Byte, Integer> features;
if (configuration != null && configuration.isDisablePinpad()) {
@@ -70,33 +71,31 @@ public class ReaderFactory {
return reader;
}
- private static int CTL_CODE(int code) {
+ private static int SCARD_CTL_CODE(int code) {
String os_name = System.getProperty("os.name").toLowerCase();
if (os_name.indexOf("windows") > -1) {
- // cf. WinIOCTL.h
return (0x31 << 16 | (code) << 2);
}
- // cf. reader.h
return 0x42000000 + (code);
}
- static int IOCTL_GET_FEATURE_REQUEST = CTL_CODE(3400);
+ static int IOCTL_GET_FEATURE_REQUEST = SCARD_CTL_CODE(3400);
private static Map<Byte, Integer> queryFeatures(Card icc) {
+ Logger log = LoggerFactory.getLogger(ReaderFactory.class);
Map<Byte, Integer> features = new HashMap<Byte, Integer>();
-
if (icc == null) {
- log.warn("invalid card handle, cannot query ifd features");
+ log.warn("Invalid card handle, cannot query ifd features.");
} else {
try {
if (log.isTraceEnabled()) {
- log.trace("GET_FEATURE_REQUEST " + Integer.toHexString(IOCTL_GET_FEATURE_REQUEST));
+ log.trace("GET_FEATURE_REQUEST {}", Integer.toHexString(IOCTL_GET_FEATURE_REQUEST));
}
byte[] resp = icc.transmitControlCommand(IOCTL_GET_FEATURE_REQUEST,
new byte[0]);
if (log.isTraceEnabled()) {
- log.trace("Response TLV " + SMCCHelper.toString(resp));
+ log.trace("Response TLV {}", SMCCHelper.toString(resp));
}
// tag
// length in bytes (always 4)
@@ -108,15 +107,14 @@ public class ReaderFactory {
((0xff & resp[i + 4]) << 8) |
(0xff & resp[i + 5]);
if (log.isInfoEnabled()) {
- log.info("IFD supports " + CardReader.FEATURES[feature.intValue()] +
- ": " + Integer.toHexString(ioctl.intValue()));
+ log.info("IFD supports {}: {}", CardReader.FEATURES[feature
+ .intValue()], Integer.toHexString(ioctl.intValue()));
}
features.put(feature, ioctl);
}
} catch (CardException ex) {
- log.debug("Failed to query IFD features: " + ex.getMessage());
- log.trace(ex);
- log.info("IFD does not support secure pin entry");
+ log.debug("Failed to query IFD features: {}", ex.getMessage(), ex);
+ log.info("IFD does not support secure pin entry.");
}
}
return features;