summaryrefslogtreecommitdiff
path: root/smcc/src/test/java/at/gv/egiz/smcc/test/AbstractCardTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'smcc/src/test/java/at/gv/egiz/smcc/test/AbstractCardTest.java')
-rw-r--r--smcc/src/test/java/at/gv/egiz/smcc/test/AbstractCardTest.java228
1 files changed, 228 insertions, 0 deletions
diff --git a/smcc/src/test/java/at/gv/egiz/smcc/test/AbstractCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/test/AbstractCardTest.java
new file mode 100644
index 00000000..ca3efa38
--- /dev/null
+++ b/smcc/src/test/java/at/gv/egiz/smcc/test/AbstractCardTest.java
@@ -0,0 +1,228 @@
+/*
+* 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;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.NoSuchAlgorithmException;
+
+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.PINMgmtSignatureCard;
+import at.gv.egiz.smcc.PinInfo;
+import at.gv.egiz.smcc.SignatureCardException;
+import at.gv.egiz.smcc.SignatureCard.KeyboxName;
+import at.gv.egiz.smcc.pin.gui.CancelPINProvider;
+import at.gv.egiz.smcc.pin.gui.DummyPINGUI;
+import at.gv.egiz.smcc.pin.gui.InterruptPINProvider;
+import at.gv.egiz.smcc.pin.gui.PINGUI;
+import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider;
+
+public abstract class AbstractCardTest extends AbstractCardTestBase {
+
+ @Test
+ public void testGetCertificates() throws SignatureCardException, InterruptedException {
+
+ byte[] certificateSSRef = (byte[]) applicationContext.getBean("certificateSS", byte[].class);
+
+ byte[] certificateSS = signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR);
+
+ assertArrayEquals(certificateSSRef, certificateSS);
+
+ byte[] certificateGSRef = (byte[]) applicationContext.getBean("certificateGS", byte[].class);
+
+ byte[] certificateGS = signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR);
+
+ assertArrayEquals(certificateGSRef, certificateGS);
+
+ }
+
+ @Test
+ public void testSignSIG() throws UnsupportedEncodingException, SignatureCardException, InterruptedException, IOException {
+
+ char[] pin = "123456".toCharArray();
+
+ byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA"
+ .getBytes("ASCII")),
+ KeyboxName.SECURE_SIGNATURE_KEYPAIR, new SMCCTestPINProvider(pin), null);
+
+ assertNotNull(signature);
+
+ }
+
+ @Test(expected = LockedException.class)
+ public void testSignSIGWrongPIN() throws UnsupportedEncodingException, SignatureCardException, InterruptedException, IOException {
+
+ char[] pin = "00000".toCharArray();
+
+ byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA"
+ .getBytes("ASCII")),
+ KeyboxName.SECURE_SIGNATURE_KEYPAIR, new SMCCTestPINProvider(pin), null);
+
+ assertNotNull(signature);
+
+ }
+
+ @Test(expected = CancelledException.class)
+ public void testSignSIGCancel() throws SignatureCardException,
+ InterruptedException, CardNotSupportedException,
+ NoSuchAlgorithmException, IOException {
+
+ PINGUI pinProvider = new CancelPINProvider();
+
+ signatureCard.createSignature(new ByteArrayInputStream(MOCCA),
+ KeyboxName.SECURE_SIGNATURE_KEYPAIR, pinProvider, null);
+
+ }
+
+ @Test
+ public void testSignDEC() throws UnsupportedEncodingException, SignatureCardException, InterruptedException, IOException {
+
+ char[] pin = "1234".toCharArray();
+
+ byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA"
+ .getBytes("ASCII")),
+ KeyboxName.CERITIFIED_KEYPAIR, new SMCCTestPINProvider(pin), null);
+
+ assertNotNull(signature);
+
+ }
+
+ @Test(expected = LockedException.class)
+ public void testSignDECWrongPIN() throws UnsupportedEncodingException, SignatureCardException, InterruptedException, IOException {
+
+ char[] pin = "00000".toCharArray();
+
+ byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA"
+ .getBytes("ASCII")),
+ KeyboxName.CERITIFIED_KEYPAIR, new SMCCTestPINProvider(pin), null);
+
+ assertNotNull(signature);
+
+ }
+
+ @Test(expected = CancelledException.class)
+ public void testSignDECCancel() throws SignatureCardException,
+ InterruptedException, CardNotSupportedException,
+ NoSuchAlgorithmException, IOException {
+
+ PINGUI pinProvider = new CancelPINProvider();
+
+ signatureCard.createSignature(new ByteArrayInputStream(MOCCA),
+ KeyboxName.CERITIFIED_KEYPAIR, pinProvider, null);
+
+ }
+
+ @Test(expected = InterruptedException.class)
+ public void testSignSIGInterrrupted() throws SignatureCardException,
+ InterruptedException, CardNotSupportedException,
+ NoSuchAlgorithmException, IOException {
+
+ PINGUI pinProvider = new InterruptPINProvider();
+
+ signatureCard.createSignature(new ByteArrayInputStream(MOCCA),
+ KeyboxName.SECURE_SIGNATURE_KEYPAIR, pinProvider, null);
+
+ }
+
+ @Test(expected = InterruptedException.class)
+ public void testSignDECInterrrupted() throws SignatureCardException,
+ InterruptedException, CardNotSupportedException,
+ NoSuchAlgorithmException, IOException {
+
+ PINGUI pinProvider = new InterruptPINProvider();
+
+ signatureCard.createSignature(new ByteArrayInputStream(MOCCA),
+ KeyboxName.CERITIFIED_KEYPAIR, pinProvider, null);
+
+ }
+
+ @Test(expected = CancelledException.class)
+ public void testSignSIGConcurrent() throws SignatureCardException,
+ InterruptedException, CardNotSupportedException,
+ NoSuchAlgorithmException, IOException {
+
+ PINGUI pinProvider = new DummyPINGUI() {
+ @Override
+ public char[] providePIN(PinInfo spec, int retries)
+ throws CancelledException, InterruptedException {
+
+ try {
+ signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR);
+ assertTrue(false);
+ return null;
+ } catch (SignatureCardException e) {
+ // expected
+ throw new CancelledException();
+ }
+
+ }
+ };
+
+ signatureCard.createSignature(new ByteArrayInputStream(MOCCA),
+ KeyboxName.SECURE_SIGNATURE_KEYPAIR, pinProvider, null);
+
+ }
+
+ @Test(expected = CancelledException.class)
+ public void testSignDECConcurrent() throws SignatureCardException,
+ InterruptedException, CardNotSupportedException,
+ NoSuchAlgorithmException, IOException {
+
+ PINGUI pinProvider = new DummyPINGUI() {
+ @Override
+ public char[] providePIN(PinInfo spec, int retries)
+ throws CancelledException, InterruptedException {
+
+ try {
+ signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR);
+ assertTrue(false);
+ return null;
+ } catch (SignatureCardException e) {
+ // expected
+ throw new CancelledException();
+ }
+ }
+ };
+
+ signatureCard.createSignature(new ByteArrayInputStream(MOCCA),
+ KeyboxName.CERITIFIED_KEYPAIR, pinProvider, null);
+
+ }
+
+ @Test
+ public void testGetPinSpecs() throws CardNotSupportedException,
+ SignatureCardException {
+
+ assertTrue(signatureCard instanceof PINMgmtSignatureCard);
+
+ PinInfo[] specs = ((PINMgmtSignatureCard) signatureCard).getPinInfos();
+ assertNotNull(specs);
+ assertTrue(specs.length > 0);
+
+ }
+
+}