summaryrefslogtreecommitdiff
path: root/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-03-06 14:53:37 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-03-06 14:53:37 +0000
commite177419331b8849497d25d3eb1866c5dc715bc88 (patch)
tree15d5d1c7dbaa9692eb03ebae9c91a8aff17d2aa7 /smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java
parenta8690cc956924e1d83b0c45d21995ee2e10fbba2 (diff)
downloadmocca-e177419331b8849497d25d3eb1866c5dc715bc88.tar.gz
mocca-e177419331b8849497d25d3eb1866c5dc715bc88.tar.bz2
mocca-e177419331b8849497d25d3eb1866c5dc715bc88.zip
1.1-rc4
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@312 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java')
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java57
1 files changed, 23 insertions, 34 deletions
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java b/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java
index 63301bd1..39952bb9 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java
@@ -37,6 +37,8 @@ import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.smartcardio.ATR;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
@@ -117,8 +119,8 @@ public abstract class AbstractSignatureCard implements SignatureCard {
protected abstract ResponseAPDU selectFileFID(byte[] fid) throws CardException,
SignatureCardException;
- // made public
-// protected abstract int verifyPIN(String pin, byte kid) throws CardException, SignatureCardException;
+ protected abstract int verifyPIN(String pin, byte kid)
+ throws LockedException, NotActivatedException, SignatureCardException;
protected byte[] readRecord(int recordNumber) throws SignatureCardException, CardException {
@@ -321,7 +323,7 @@ public abstract class AbstractSignatureCard implements SignatureCard {
throw new VerificationFailedException(retries);
}
}
-
+
return readBinaryTLV(maxLength, (byte) 0x30);
@@ -443,53 +445,40 @@ public abstract class AbstractSignatureCard implements SignatureCard {
return pinSpecs;
}
- public void changePIN(byte kid, byte[] contextAID, String oldPIN, String newPIN) throws SignatureCardException, VerificationFailedException {
+ @Override
+ public int verifyPIN(PINSpec pinSpec, String pin) throws LockedException, NotActivatedException, SignatureCardException {
+
Card icc = getCard();
try {
icc.beginExclusive();
CardChannel channel = icc.getBasicChannel();
- if (contextAID != null) {
+ if (pinSpec.getContextAID() != null) {
ResponseAPDU responseAPDU = transmit(channel,
- new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, contextAID));
+ new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, pinSpec.getContextAID()));
if (responseAPDU.getSW() != 0x9000) {
icc.endExclusive();
- String msg = "Failed to change PIN " + SMCCHelper.toString(new byte[]{kid}) +
- ": Failed to select AID " + SMCCHelper.toString(contextAID) +
+ String msg = "Failed to verify PIN " +
+ SMCCHelper.toString(new byte[]{pinSpec.getKID()}) +
+ ": Failed to verify AID " +
+ SMCCHelper.toString(pinSpec.getContextAID()) +
": " + SMCCHelper.toString(responseAPDU.getBytes());
log.error(msg);
throw new SignatureCardException(msg);
}
}
+ return verifyPIN(pin, pinSpec.getKID());
- byte[] cmd = new byte[16];
- System.arraycopy(encodePINBlock(oldPIN), 0, cmd, 0, 8);
- System.arraycopy(encodePINBlock(newPIN), 0, cmd, 8, 8);
-
- ResponseAPDU responseAPDU = transmit(channel,
- new CommandAPDU(0x00, 0x24, 0x00, kid, cmd), false);
-
- icc.endExclusive();
-
- if (responseAPDU.getSW1() == 0x63 && responseAPDU.getSW2() >> 4 == 0xc) {
- int retries = responseAPDU.getSW2() & 0x0f;
- log.error("Failed VERIFY PIN, " + retries + " tries left");
- throw new VerificationFailedException(retries);
- }
- if (responseAPDU.getSW() != 0x9000) {
- String msg = "Failed to change PIN "
- + SMCCHelper.toString(new byte[]{kid}) + ": "
- + SMCCHelper.toString(responseAPDU.getBytes());
- log.error(msg);
- throw new SignatureCardException(msg);
+ } catch (CardException ex) {
+ log.error("failed to verify pinspec: " + ex.getMessage(), ex);
+ throw new SignatureCardException(ex);
+ } finally {
+ try {
+ icc.endExclusive();
+ } catch (CardException ex) {
+ log.trace("failed to end exclusive card access: " + ex.getMessage());
}
- } catch (CardException ex) {
- log.error("Failed to change PIN: " + ex.getMessage());
- throw new SignatureCardException(ex.getMessage(), ex);
}
}
-
- abstract byte[] encodePINBlock(String pin);
-
}