diff options
Diffstat (limited to 'smcc/src/test/java/at/gv/egiz/smcc/test/ecard')
8 files changed, 496 insertions, 0 deletions
diff --git a/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG2Test.java b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG2Test.java new file mode 100644 index 00000000..904c8c06 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG2Test.java @@ -0,0 +1,85 @@ +/* + * Copyright 2009 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.smcc.test.ecard; + +import static org.junit.Assert.assertArrayEquals; + +import java.util.Arrays; + +import org.junit.Test; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.CardNotSupportedException; +import at.gv.egiz.smcc.LockedException; +import at.gv.egiz.smcc.NotActivatedException; +import at.gv.egiz.smcc.PIN; +import at.gv.egiz.smcc.PINFormatException; +import at.gv.egiz.smcc.PINMgmtSignatureCard; +import at.gv.egiz.smcc.PinInfo; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.pin.gui.ChangePINProvider; +import at.gv.egiz.smcc.pin.gui.PINGUI; +import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider; + + +public class ECardG2Test extends ECardTest { + + @Test + public void testChangeCardPin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { + + byte[] referenceData = { (byte) 0x26, (byte) 0x12, (byte) 0x34, + (byte) 0x56, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }; + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) this.signatureCard; + PIN signaturPIN = (PIN) applicationContext.getBean("signaturPIN"); + signaturPIN.setPin(referenceData); + PIN kartenPIN = (PIN) applicationContext.getBean("kartenPIN"); + kartenPIN.setPin(referenceData); + + for (PinInfo pinInfo : signatureCard.getPinInfos()) { + + char[] pin = "123456".toCharArray(); + + for (int i = pinInfo.getMinLength(); i <= pinInfo.getMaxLength(); i++) { + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(pin)); + char[] newPin = new char[i]; + Arrays.fill(newPin, '0'); + signatureCard + .changePIN(pinInfo, new ChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(newPin)); + pin = newPin; + } + } + } + + @Test + public void testGetInfoboxIdentityLink() throws SignatureCardException, InterruptedException { + + PINGUI pinProvider = new SMCCTestPINProvider("1234".toCharArray()); + + byte[] idlinkRef = (byte[]) applicationContext.getBean("identityLink", byte[].class); + + byte[] idlink = signatureCard.getInfobox("IdentityLink", pinProvider, null); + + assertArrayEquals(idlinkRef, idlink); + + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3ActivateTest.java b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3ActivateTest.java new file mode 100644 index 00000000..6270e3b8 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3ActivateTest.java @@ -0,0 +1,64 @@ +/* +* Copyright 2009 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package at.gv.egiz.smcc.test.ecard; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.CardNotSupportedException; +import at.gv.egiz.smcc.LockedException; +import at.gv.egiz.smcc.NotActivatedException; +import at.gv.egiz.smcc.PINFormatException; +import at.gv.egiz.smcc.PINMgmtSignatureCard; +import at.gv.egiz.smcc.PinInfo; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.pin.gui.ChangePINProvider; +import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider; +import at.gv.egiz.smcc.test.AbstractCardTestBase; + +public class ECardG3ActivateTest extends AbstractCardTestBase { + + @Test + public void testActivatePin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) this.signatureCard; + + for (PinInfo pinInfo : signatureCard.getPinInfos()) { + + char[] pin = "123456789".substring(0, pinInfo.getMinLength()).toCharArray(); + char[] transportPIN = "123456".toCharArray(); + + boolean notActive = false; + try { + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(pin)); + } catch (NotActivatedException ex) { + notActive = true; + } + assertTrue(notActive); + + signatureCard.activatePIN(pinInfo, new ChangePINProvider(transportPIN, pin)); + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(pin)); + } + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3InfoboxContainerEncryptedTest.java b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3InfoboxContainerEncryptedTest.java new file mode 100644 index 00000000..2f240729 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3InfoboxContainerEncryptedTest.java @@ -0,0 +1,44 @@ +/* +* Copyright 2009 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package at.gv.egiz.smcc.test.ecard; + +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; + +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.pin.gui.PINGUI; +import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider; +import at.gv.egiz.smcc.test.AbstractCardTestBase; + +public class ECardG3InfoboxContainerEncryptedTest extends AbstractCardTestBase { + + @Test + public void testGetInfoboxIdentityLink() throws SignatureCardException, InterruptedException { + + PINGUI pinProvider = new SMCCTestPINProvider("1234".toCharArray()); + + byte[] idlinkRef = (byte[]) applicationContext.getBean("identityLink", byte[].class); + + byte[] idlink = signatureCard.getInfobox("IdentityLink", pinProvider, null); + + assertArrayEquals(idlinkRef, idlink); + + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3InfoboxContainerTest.java b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3InfoboxContainerTest.java new file mode 100644 index 00000000..112556a6 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3InfoboxContainerTest.java @@ -0,0 +1,55 @@ +/* +* Copyright 2009 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package at.gv.egiz.smcc.test.ecard; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PinInfo; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.pin.gui.DummyPINGUI; +import at.gv.egiz.smcc.pin.gui.PINGUI; +import at.gv.egiz.smcc.test.AbstractCardTestBase; + +public class ECardG3InfoboxContainerTest extends AbstractCardTestBase { + + @Test + public void testGetInfoboxIdentityLink() throws SignatureCardException, InterruptedException { + + PINGUI pinProvider = new DummyPINGUI() { + @Override + public char[] providePIN(PinInfo pinSpec, int retries) + throws CancelledException, InterruptedException { + // must not require a PIN! + fail(); + return null; + } + }; + + byte[] idlinkRef = (byte[]) applicationContext.getBean("identityLink", byte[].class); + + byte[] idlink = signatureCard.getInfobox("IdentityLink", pinProvider, null); + + assertArrayEquals(idlinkRef, idlink); + + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3InvalidTest.java b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3InvalidTest.java new file mode 100644 index 00000000..f5a78448 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3InvalidTest.java @@ -0,0 +1,24 @@ +/* +* Copyright 2009 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package at.gv.egiz.smcc.test.ecard; + +import at.gv.egiz.smcc.test.AbstractInvalidCardTest; + +public class ECardG3InvalidTest extends AbstractInvalidCardTest { + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3NotActivatedTest.java b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3NotActivatedTest.java new file mode 100644 index 00000000..5dfcfb21 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3NotActivatedTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2009 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.smcc.test.ecard; + +import org.junit.Test; + +import at.gv.egiz.smcc.NotActivatedException; +import at.gv.egiz.smcc.PINMgmtSignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.test.AbstractNotActivatedCardTest; + +public class ECardG3NotActivatedTest extends AbstractNotActivatedCardTest { + + @Test(expected = NotActivatedException.class) + public void getPINInfos() throws SignatureCardException { + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) this.signatureCard; + signatureCard.getPinInfos(); + + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3Test.java b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3Test.java new file mode 100644 index 00000000..d8528b62 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardG3Test.java @@ -0,0 +1,132 @@ +/* + * Copyright 2009 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.smcc.test.ecard; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.CardNotSupportedException; +import at.gv.egiz.smcc.LockedException; +import at.gv.egiz.smcc.NotActivatedException; +import at.gv.egiz.smcc.PIN; +import at.gv.egiz.smcc.PINFormatException; +import at.gv.egiz.smcc.PINMgmtSignatureCard; +import at.gv.egiz.smcc.PinInfo; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.pin.gui.ChangePINProvider; +import at.gv.egiz.smcc.pin.gui.InvalidChangePINProvider; +import at.gv.egiz.smcc.pin.gui.InvalidPINProvider; +import at.gv.egiz.smcc.pin.gui.PINGUI; +import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider; + + +public class ECardG3Test extends ECardTest { + + @Test + public void testGetInfoboxIdentityLink() throws SignatureCardException, InterruptedException { + + PINGUI pinProvider = new SMCCTestPINProvider("1234".toCharArray()); + + byte[] idlinkRef = (byte[]) applicationContext.getBean("identityLink", byte[].class); + + byte[] idlink = signatureCard.getInfobox("IdentityLink", pinProvider, null); + + assertArrayEquals(idlinkRef, idlink); + + } + + @Test + public void testChangePin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { + + byte[] referenceData = { (byte) 0x26, (byte) 0x12, (byte) 0x34, + (byte) 0x56, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }; + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) this.signatureCard; + PIN signaturPIN = (PIN) applicationContext.getBean("signaturPIN"); + signaturPIN.setPin(referenceData); + PIN kartenPIN = (PIN) applicationContext.getBean("kartenPIN"); + kartenPIN.setPin(referenceData); + + for (PinInfo pinInfo : signatureCard.getPinInfos()) { + + char[] pin = "123456".toCharArray(); + + for (int i = pinInfo.getMinLength(); i <= pinInfo.getMaxLength(); i++) { + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(pin)); + char[] newPin = new char[i]; + Arrays.fill(newPin, '0'); + signatureCard + .changePIN(pinInfo, new ChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(newPin)); + pin = newPin; + } + } + } + + @Test + public void testVerifyInvalidPin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) this.signatureCard; + + for (PinInfo pinInfo : signatureCard.getPinInfos()) { + + char[] invalidPin = "999999".toCharArray(); + int numInvalidTries = 2; + InvalidPINProvider invalidPinProvider = new InvalidPINProvider(invalidPin, numInvalidTries); + try { + signatureCard.verifyPIN(pinInfo, invalidPinProvider); + } catch (CancelledException ex) { + } finally { + assertTrue(invalidPinProvider.getProvided() == numInvalidTries); + } + } + } + + @Test + public void testChangeInvalidPin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) this.signatureCard; + + for (PinInfo pinInfo : signatureCard.getPinInfos()) { + + char[] invalidPin = "999999".toCharArray(); + int numInvalidTries = 2; + InvalidChangePINProvider invalidPinProvider = + new InvalidChangePINProvider(invalidPin, invalidPin, numInvalidTries); + + try { + signatureCard.changePIN(pinInfo, invalidPinProvider); + } catch (CancelledException ex) { + } finally { + assertTrue(invalidPinProvider.getProvided() == numInvalidTries); + } + } + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardTest.java new file mode 100644 index 00000000..e95a1615 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/test/ecard/ECardTest.java @@ -0,0 +1,54 @@ +/* +* Copyright 2009 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package at.gv.egiz.smcc.test.ecard; + +import static org.junit.Assert.assertTrue; + +import java.io.UnsupportedEncodingException; +import java.security.NoSuchAlgorithmException; + +import org.junit.Test; + +import at.gv.egiz.smcc.CardNotSupportedException; +import at.gv.egiz.smcc.PINMgmtSignatureCard; +import at.gv.egiz.smcc.PinInfo; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.pin.gui.CancelChangePINProvider; +import at.gv.egiz.smcc.pin.gui.ModifyPINGUI; +import at.gv.egiz.smcc.test.AbstractCardTest; + +public abstract class ECardTest extends AbstractCardTest { + + @Test + public abstract void testGetInfoboxIdentityLink() throws SignatureCardException, InterruptedException; + + @Test(expected = SignatureCardException.class) + public void testActivatePin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + assertTrue(signatureCard instanceof PINMgmtSignatureCard); + + ModifyPINGUI pinProvider = new CancelChangePINProvider(); + + PinInfo[] specs = ((PINMgmtSignatureCard) signatureCard).getPinInfos(); + + ((PINMgmtSignatureCard) signatureCard).activatePIN(specs[0], pinProvider); + } + +} |