diff options
Diffstat (limited to 'smcc')
7 files changed, 55 insertions, 30 deletions
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java b/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java index 99aadebd..414d4678 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java @@ -104,13 +104,13 @@ public class ACOSCard extends AbstractSignatureCard implements PINMgmtSignatureC }; private static final PINSpec DEC_PIN_SPEC = new PINSpec(0, 8, "[0-9]", - "at/gv/egiz/smcc/ACOSCard", "dec.pin.name", KID_PIN_DEC, AID_DEC); + "at/gv/egiz/smcc/ACOSCard", "dec.pin", KID_PIN_DEC, AID_DEC); private static final PINSpec SIG_PIN_SPEC = new PINSpec(0, 8, "[0-9]", - "at/gv/egiz/smcc/ACOSCard", "sig.pin.name", KID_PIN_SIG, AID_SIG); + "at/gv/egiz/smcc/ACOSCard", "sig.pin", KID_PIN_SIG, AID_SIG); private static final PINSpec INF_PIN_SPEC = new PINSpec(0, 8, "[0-9]", - "at/gv/egiz/smcc/ACOSCard", "inf.pin.name", KID_PIN_INF, AID_DEC); + "at/gv/egiz/smcc/ACOSCard", "inf.pin", KID_PIN_INF, AID_DEC); /** * The version of the card's digital signature application. diff --git a/smcc/src/main/java/at/gv/egiz/smcc/PINSpec.java b/smcc/src/main/java/at/gv/egiz/smcc/PINSpec.java index b8ffafab..1812049c 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/PINSpec.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/PINSpec.java @@ -33,7 +33,10 @@ public class PINSpec { String resourceBundleName_; - String name_; + String nameKey_; + + /** the localized, i.e. configurable length */ + String lengthKey_; byte kid_; @@ -49,13 +52,14 @@ public class PINSpec { * @param kid the keyId for this pin */ public PINSpec(int minLenght, int maxLength, String rexepPattern, - String resourceBundleName, String name, byte kid, byte[] contextAID) { + String resourceBundleName, String resourceKey, byte kid, byte[] contextAID) { minLength_ = minLenght; maxLength_ = maxLength; rexepPattern_ = rexepPattern; resourceBundleName_ = resourceBundleName; - name_ = name; + nameKey_ = resourceKey + ".name"; + lengthKey_ = resourceKey + ".length"; kid_ = kid; context_aid_ = contextAID; } @@ -66,7 +70,8 @@ public class PINSpec { minLength_ = minLenght; maxLength_ = maxLength; rexepPattern_ = rexepPattern; - name_ = name; + nameKey_ = name + ".name"; + lengthKey_ = name + ".length"; kid_ = kid; context_aid_ = contextAID; } @@ -75,9 +80,9 @@ public class PINSpec { if (resourceBundleName_ != null) { ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceBundleName_); - return resourceBundle.getString(name_); + return resourceBundle.getString(nameKey_); } else { - return name_; + return nameKey_; } } @@ -86,13 +91,28 @@ public class PINSpec { if (resourceBundleName_ != null) { ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceBundleName_, locale); - return resourceBundle.getString(name_); + return resourceBundle.getString(nameKey_); } else { - return name_; + return nameKey_; } } + public String getLocalizedLength() { + + if (resourceBundleName_ != null) { + ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceBundleName_); + return resourceBundle.getString(lengthKey_); + } else { + if (maxLength_ > minLength_) { + return minLength_ + "-" + maxLength_; + } else { + return String.valueOf(minLength_); + } + } + + } + public int getMaxLength() { return maxLength_; } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java b/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java index 921819ee..2e6dd5d6 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java @@ -150,11 +150,11 @@ public class STARCOSCard extends AbstractSignatureCard implements PINMgmtSignatu private static final PINSpec CARD_PIN_SPEC = new PINSpec(4, 12, "[0-9]", - "at/gv/egiz/smcc/STARCOSCard", "card.pin.name", KID_PIN_CARD, null); + "at/gv/egiz/smcc/STARCOSCard", "card.pin", KID_PIN_CARD, null); private static final PINSpec SS_PIN_SPEC = new PINSpec(6, 12, "[0-9]", - "at/gv/egiz/smcc/STARCOSCard", "sig.pin.name", KID_PIN_SS, AID_DF_SS); + "at/gv/egiz/smcc/STARCOSCard", "sig.pin", KID_PIN_SS, AID_DF_SS); /** * Creates an new instance. diff --git a/smcc/src/main/resources/at/gv/egiz/smcc/ACOSCard.properties b/smcc/src/main/resources/at/gv/egiz/smcc/ACOSCard.properties index d2bbe4f9..2e032d1b 100644 --- a/smcc/src/main/resources/at/gv/egiz/smcc/ACOSCard.properties +++ b/smcc/src/main/resources/at/gv/egiz/smcc/ACOSCard.properties @@ -17,5 +17,8 @@ # and open the template in the editor. dec.pin.name=Geheimhaltungs-PIN +dec.pin.length=4 sig.pin.name=Signatur-PIN +sig.pin.length=6 inf.pin.name=Infobox-PIN +inf.pin.length=4 diff --git a/smcc/src/main/resources/at/gv/egiz/smcc/STARCOSCard.properties b/smcc/src/main/resources/at/gv/egiz/smcc/STARCOSCard.properties index 6fa5f0fa..ae91f265 100644 --- a/smcc/src/main/resources/at/gv/egiz/smcc/STARCOSCard.properties +++ b/smcc/src/main/resources/at/gv/egiz/smcc/STARCOSCard.properties @@ -17,4 +17,6 @@ # and open the template in the editor. sig.pin.name=Signatur-PIN +sig.pin.length=6 card.pin.name=Karten-PIN +card.pin.length=4 diff --git a/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java index f72820e1..2a55357d 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java @@ -76,14 +76,14 @@ public abstract class CardTest { } - public class TestWrongPINProvider implements PINProvider { + public class TestInvalidPINProvider implements PINProvider { int provided = 0; int numWrongTries = 0; char[] pin; - public TestWrongPINProvider(char[] pin, int numWrongTries) { + public TestInvalidPINProvider(char[] pin, int numWrongTries) { super(); this.pin = pin; this.numWrongTries = numWrongTries; @@ -105,7 +105,7 @@ public abstract class CardTest { } } - public class TestWrongChangePINProvider implements ChangePINProvider { + public class TestInvalidChangePINProvider implements ChangePINProvider { int provided = 0; int numWrongTries = 0; @@ -114,7 +114,7 @@ public abstract class CardTest { char[] oldPin; /** emulate ChangePinProvider */ - public TestWrongChangePINProvider(char[] oldPin, char[] newPin, int numWrongTries) { + public TestInvalidChangePINProvider(char[] oldPin, char[] newPin, int numWrongTries) { super(); this.pin = newPin; this.oldPin = oldPin; diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardTest.java index bf56ef47..89e2ca65 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardTest.java @@ -294,7 +294,7 @@ public class STARCOSCardTest extends CardTest { } @Test - public void testVerifyWrongPin() throws CardNotSupportedException, + public void testVerifyInvalidPin() throws CardNotSupportedException, LockedException, NotActivatedException, CancelledException, PINFormatException, SignatureCardException, InterruptedException { @@ -309,20 +309,20 @@ public class STARCOSCardTest extends CardTest { for (PINSpec pinSpec : signatureCard.getPINSpecs()) { - char[] wrongPin = "999999".toCharArray(); - int numWrongTries = 2; - TestWrongPINProvider wrongPinProvider = new TestWrongPINProvider(wrongPin, numWrongTries); + char[] invalidPin = "999999".toCharArray(); + int numInvalidTries = 2; + TestInvalidPINProvider invalidPinProvider = new TestInvalidPINProvider(invalidPin, numInvalidTries); try { - signatureCard.verifyPIN(pinSpec, wrongPinProvider); + signatureCard.verifyPIN(pinSpec, invalidPinProvider); } catch (CancelledException ex) { } finally { - assertTrue(wrongPinProvider.getProvided() == numWrongTries); + assertTrue(invalidPinProvider.getProvided() == numInvalidTries); } } } @Test - public void testChangeWrongPin() throws CardNotSupportedException, + public void testChangeInvalidPin() throws CardNotSupportedException, LockedException, NotActivatedException, CancelledException, PINFormatException, SignatureCardException, InterruptedException { char[] defaultPin = "123456".toCharArray(); @@ -336,16 +336,16 @@ public class STARCOSCardTest extends CardTest { for (PINSpec pinSpec : signatureCard.getPINSpecs()) { - char[] wrongPin = "999999".toCharArray(); - int numWrongTries = 2; - TestWrongChangePINProvider wrongPinProvider = - new TestWrongChangePINProvider(wrongPin, defaultPin, numWrongTries); + char[] invalidPin = "999999".toCharArray(); + int numInvalidTries = 2; + TestInvalidChangePINProvider invalidPinProvider = + new TestInvalidChangePINProvider(invalidPin, defaultPin, numInvalidTries); try { - signatureCard.changePIN(pinSpec, wrongPinProvider); + signatureCard.changePIN(pinSpec, invalidPinProvider); } catch (CancelledException ex) { } finally { - assertTrue(wrongPinProvider.getProvided() == numWrongTries); + assertTrue(invalidPinProvider.getProvided() == numInvalidTries); } } } |