summaryrefslogtreecommitdiff
path: root/smcc/src/test/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'smcc/src/test/java/at')
-rw-r--r--smcc/src/test/java/at/gv/egiz/smcc/CardTest.java67
-rw-r--r--smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardTest.java57
2 files changed, 123 insertions, 1 deletions
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 298e26a5..f72820e1 100644
--- a/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java
+++ b/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java
@@ -76,6 +76,73 @@ public abstract class CardTest {
}
+ public class TestWrongPINProvider implements PINProvider {
+
+ int provided = 0;
+ int numWrongTries = 0;
+
+ char[] pin;
+
+ public TestWrongPINProvider(char[] pin, int numWrongTries) {
+ super();
+ this.pin = pin;
+ this.numWrongTries = numWrongTries;
+ }
+
+ @Override
+ public char[] providePIN(PINSpec spec, int retries)
+ throws CancelledException, InterruptedException {
+ if (provided >= numWrongTries) {
+ throw new CancelledException("Number of wrong tries reached: " + provided);
+ } else {
+ provided++;
+ return pin;
+ }
+ }
+
+ public int getProvided() {
+ return provided;
+ }
+ }
+
+ public class TestWrongChangePINProvider implements ChangePINProvider {
+
+ int provided = 0;
+ int numWrongTries = 0;
+
+ char[] pin;
+ char[] oldPin;
+
+ /** emulate ChangePinProvider */
+ public TestWrongChangePINProvider(char[] oldPin, char[] newPin, int numWrongTries) {
+ super();
+ this.pin = newPin;
+ this.oldPin = oldPin;
+ this.numWrongTries = numWrongTries;
+ }
+
+ @Override
+ public char[] providePIN(PINSpec spec, int retries)
+ throws CancelledException, InterruptedException {
+ return pin;
+ }
+
+ public int getProvided() {
+ return provided;
+ }
+
+ @Override
+ public char[] provideOldPIN(PINSpec spec, int retries)
+ throws CancelledException, InterruptedException {
+ if (provided >= numWrongTries) {
+ throw new CancelledException("Number of wrong tries reached: " + provided);
+ } else {
+ provided++;
+ return oldPin;
+ }
+ }
+ }
+
public CardTest() {
super();
}
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 0fb4f62d..bf56ef47 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
@@ -45,6 +45,7 @@ import at.gv.egiz.smcc.SignatureCardException;
import at.gv.egiz.smcc.SignatureCardFactory;
import at.gv.egiz.smcc.CardTest.TestChangePINProvider;
import at.gv.egiz.smcc.CardTest.TestPINProvider;
+import at.gv.egiz.smcc.PINProvider;
import at.gv.egiz.smcc.SignatureCard.KeyboxName;
import at.gv.egiz.smcc.acos.A03ApplDEC;
import at.gv.egiz.smcc.acos.A04ApplDEC;
@@ -52,6 +53,7 @@ import at.gv.egiz.smcc.acos.A04ApplSIG;
import at.gv.egiz.smcc.acos.ACOSAppl;
import at.gv.egiz.smcc.acos.ACOSApplDEC;
import at.gv.egiz.smcc.acos.ACOSApplSIG;
+import org.junit.Ignore;
public class STARCOSCardTest extends CardTest {
@@ -288,10 +290,63 @@ public class STARCOSCardTest extends CardTest {
signatureCard.verifyPIN(pinSpec, new TestPINProvider(newPin));
pin = newPin;
}
-
}
+ }
+
+ @Test
+ public void testVerifyWrongPin() throws CardNotSupportedException,
+ LockedException, NotActivatedException, CancelledException,
+ PINFormatException, SignatureCardException, InterruptedException {
+
+ char[] defaultPin = "123456".toCharArray();
+
+ PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard();
+ CardEmul card = (CardEmul) signatureCard.getCard();
+ STARCOSCardChannelEmul channel = (STARCOSCardChannelEmul) card.getBasicChannel();
+ channel.setPin(STARCOSCardChannelEmul.KID_PIN_Glob, defaultPin);
+ STARCOSApplSichereSignatur appl = (STARCOSApplSichereSignatur) card.getApplication(STARCOSApplSichereSignatur.AID_SichereSignatur);
+ appl.setPin(STARCOSApplSichereSignatur.KID_PIN_SS, defaultPin);
+
+ for (PINSpec pinSpec : signatureCard.getPINSpecs()) {
+ char[] wrongPin = "999999".toCharArray();
+ int numWrongTries = 2;
+ TestWrongPINProvider wrongPinProvider = new TestWrongPINProvider(wrongPin, numWrongTries);
+ try {
+ signatureCard.verifyPIN(pinSpec, wrongPinProvider);
+ } catch (CancelledException ex) {
+ } finally {
+ assertTrue(wrongPinProvider.getProvided() == numWrongTries);
+ }
+ }
}
+ @Test
+ public void testChangeWrongPin() throws CardNotSupportedException,
+ LockedException, NotActivatedException, CancelledException,
+ PINFormatException, SignatureCardException, InterruptedException {
+ char[] defaultPin = "123456".toCharArray();
+
+ PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard();
+ CardEmul card = (CardEmul) signatureCard.getCard();
+ STARCOSCardChannelEmul channel = (STARCOSCardChannelEmul) card.getBasicChannel();
+ channel.setPin(STARCOSCardChannelEmul.KID_PIN_Glob, defaultPin);
+ STARCOSApplSichereSignatur appl = (STARCOSApplSichereSignatur) card.getApplication(STARCOSApplSichereSignatur.AID_SichereSignatur);
+ appl.setPin(STARCOSApplSichereSignatur.KID_PIN_SS, defaultPin);
+
+ for (PINSpec pinSpec : signatureCard.getPINSpecs()) {
+ char[] wrongPin = "999999".toCharArray();
+ int numWrongTries = 2;
+ TestWrongChangePINProvider wrongPinProvider =
+ new TestWrongChangePINProvider(wrongPin, defaultPin, numWrongTries);
+
+ try {
+ signatureCard.changePIN(pinSpec, wrongPinProvider);
+ } catch (CancelledException ex) {
+ } finally {
+ assertTrue(wrongPinProvider.getProvided() == numWrongTries);
+ }
+ }
+ }
}