From b1c8641a63a67e3c64d948f9e8dce5c01e11e2dd Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 5 May 2010 15:29:01 +0000 Subject: Merged feature branch mocca-1.2.13-id@r724 back to trunk. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@725 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smcc/src/test/java/at/gv/egiz/smcc/CardTest.java | 16 ++- .../java/at/gv/egiz/smcc/acos/A03CardTest.java | 4 +- .../java/at/gv/egiz/smcc/acos/A04CardTest.java | 4 +- .../java/at/gv/egiz/smcc/card/CreateSignature.java | 108 +++++++++++++++++++++ .../java/at/gv/egiz/smcc/card/ReadCertiticate.java | 56 +++++++++++ .../egiz/smcc/pin/gui/CancelChangePINProvider.java | 6 +- .../at/gv/egiz/smcc/pin/gui/CancelPINProvider.java | 4 +- .../at/gv/egiz/smcc/pin/gui/ChangePINProvider.java | 6 +- .../at/gv/egiz/smcc/pin/gui/DummyChangePINGUI.java | 10 +- .../java/at/gv/egiz/smcc/pin/gui/DummyPINGUI.java | 6 +- .../gv/egiz/smcc/pin/gui/InterruptPINProvider.java | 4 +- .../smcc/pin/gui/InvalidChangePINProvider.java | 6 +- .../gv/egiz/smcc/pin/gui/InvalidPINProvider.java | 4 +- .../gv/egiz/smcc/pin/gui/SMCCTestPINProvider.java | 4 +- .../egiz/smcc/starcos/STARCOSCardChannelEmul.java | 4 +- .../at/gv/egiz/smcc/starcos/STARCOSCardTest.java | 30 +++--- .../at/gv/egiz/smcc/starcos/STARCOSG3CardTest.java | 24 +++-- 17 files changed, 228 insertions(+), 68 deletions(-) create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/card/CreateSignature.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/card/ReadCertiticate.java (limited to 'smcc/src/test/java/at/gv') 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 44e48836..17a8a03f 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java @@ -26,7 +26,6 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; import java.util.Arrays; -import java.util.List; import javax.smartcardio.Card; @@ -38,7 +37,6 @@ import at.gv.egiz.smcc.pin.gui.DummyPINGUI; import at.gv.egiz.smcc.pin.gui.ModifyPINGUI; import at.gv.egiz.smcc.pin.gui.PINGUI; import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider; -import org.junit.Ignore; @SuppressWarnings("restriction") public abstract class CardTest { @@ -144,7 +142,7 @@ public abstract class CardTest { PINGUI pinProvider = new DummyPINGUI() { @Override - public char[] providePIN(PINSpec spec, int retries) + public char[] providePIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { try { @@ -174,7 +172,7 @@ public abstract class CardTest { PINGUI pinProvider = new DummyPINGUI() { @Override - public char[] providePIN(PINSpec spec, int retries) + public char[] providePIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { try { @@ -195,13 +193,13 @@ public abstract class CardTest { } @Test - public void testGetPinSpecs() throws CardNotSupportedException { + public void testGetPinSpecs() throws CardNotSupportedException, SignatureCardException { PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard(); - List specs = signatureCard.getPINSpecs(); + PinInfo[] specs = signatureCard.getPinInfos(); assertNotNull(specs); - assertTrue(specs.size() > 0); + assertTrue(specs.length > 0); } @@ -214,9 +212,9 @@ public abstract class CardTest { ModifyPINGUI pinProvider = new CancelChangePINProvider(); - List specs = signatureCard.getPINSpecs(); + PinInfo[] specs = signatureCard.getPinInfos(); - signatureCard.activatePIN(specs.get(0), pinProvider); + signatureCard.activatePIN(specs[0], pinProvider); } } \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardTest.java index 3a8ac41c..4a94c623 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardTest.java @@ -32,7 +32,7 @@ import at.gv.egiz.smcc.NotActivatedException; import at.gv.egiz.smcc.PINFormatException; import at.gv.egiz.smcc.PINMgmtSignatureCard; import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.smcc.SignatureCardFactory; @@ -70,7 +70,7 @@ public class A03CardTest extends ACOSCardTest { applDEC.setPin(ACOSApplDEC.KID_PIN_DEC, defaultPin); applDEC.setPin(A03ApplDEC.KID_PIN_INF, defaultPin); - for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + for (PinInfo pinSpec : signatureCard.getPinInfos()) { char[] pin = defaultPin; diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardTest.java index 1cbea1b3..a7a5eef4 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardTest.java @@ -36,7 +36,7 @@ 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.PINSpec; +import at.gv.egiz.smcc.PinInfo; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.smcc.SignatureCardFactory; @@ -80,7 +80,7 @@ public class A04CardTest extends ACOSCardTest { ACOSApplDEC applDEC = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); applDEC.setPin(ACOSApplDEC.KID_PIN_DEC, defaultPin); - for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + for (PinInfo pinSpec : signatureCard.getPinInfos()) { char[] pin = defaultPin; diff --git a/smcc/src/test/java/at/gv/egiz/smcc/card/CreateSignature.java b/smcc/src/test/java/at/gv/egiz/smcc/card/CreateSignature.java new file mode 100644 index 00000000..956bcc99 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/card/CreateSignature.java @@ -0,0 +1,108 @@ +/* +* 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.card; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.math.BigInteger; +import java.nio.charset.Charset; +import java.util.Formatter; +import java.util.Locale; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PinInfo; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.smcc.pin.gui.PINGUI; +import at.gv.egiz.smcc.util.SMCCHelper; + +public class CreateSignature { + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + + SMCCHelper helper = new SMCCHelper(); + + SignatureCard signatureCard = helper.getSignatureCard(Locale.getDefault()); + + if (signatureCard == null) { + return; + } + + InputStream data = new ByteArrayInputStream("just a test".getBytes(Charset.forName("UTF-8"))); + byte[] signature = createSignature(signatureCard, KeyboxName.SECURE_SIGNATURE_KEYPAIR, data); + Formatter printf = new Formatter(System.out); + printf.format("Signature: %1$x", new BigInteger(signature)); + + } + + public static byte[] createSignature(SignatureCard signatureCard, KeyboxName keyboxName, InputStream data) throws SignatureCardException, InterruptedException, IOException { + return signatureCard.createSignature(data, keyboxName, new ConsolePINGUI(), "http://www.w3.org/2000/09/xmldsig#rsa-sha1"); + } + + public static class ConsolePINGUI implements PINGUI { + + @Override + public void allKeysCleared() { + } + + @Override + public void correctionButtonPressed() { + } + + @Override + public void enterPIN(PinInfo spec, int retries) throws CancelledException, + InterruptedException { + } + + @Override + public void enterPINDirect(PinInfo spec, int retries) + throws CancelledException, InterruptedException { + } + + @Override + public void validKeyPressed() { + } + + @Override + public char[] providePIN(PinInfo pinSpec, int retries) + throws CancelledException, InterruptedException { + System.out.print("Enter " + pinSpec.getLocalizedName() + ": "); + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String pin; + try { + pin = in.readLine(); + } catch (IOException e) { + throw new CancelledException(e); + } + if (pin == null || pin.length() == 0) { + throw new CancelledException(); + } + return pin.toCharArray(); + } + + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/card/ReadCertiticate.java b/smcc/src/test/java/at/gv/egiz/smcc/card/ReadCertiticate.java new file mode 100644 index 00000000..38a4042a --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/card/ReadCertiticate.java @@ -0,0 +1,56 @@ +/* +* 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.card; + +import java.io.ByteArrayInputStream; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.Locale; + +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.smcc.util.SMCCHelper; + +public class ReadCertiticate { + + public static void main(String[] args) throws Exception { + + SMCCHelper helper = new SMCCHelper(); + + SignatureCard signatureCard = helper.getSignatureCard(Locale.getDefault()); + + if (signatureCard == null) { + return; + } + + X509Certificate cert = readCertificate(signatureCard, KeyboxName.SECURE_SIGNATURE_KEYPAIR); + System.out.println(cert.toString()); + + } + + public static X509Certificate readCertificate(SignatureCard signatureCard, + KeyboxName keyboxName) throws SignatureCardException, + InterruptedException, CertificateException { + byte[] certificate = signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); + CertificateFactory certificateFactory = CertificateFactory.getInstance("X509"); + return (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(certificate)); + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelChangePINProvider.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelChangePINProvider.java index dffe7e29..1c720a14 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelChangePINProvider.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelChangePINProvider.java @@ -17,7 +17,7 @@ package at.gv.egiz.smcc.pin.gui; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; public class CancelChangePINProvider extends DummyChangePINGUI implements ModifyPINGUI { @@ -25,13 +25,13 @@ public class CancelChangePINProvider extends DummyChangePINGUI implements Modify } @Override - public char[] provideCurrentPIN(PINSpec spec, int retries) + public char[] provideCurrentPIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { throw new CancelledException("cancelled by cancelPINProvider"); } @Override - public char[] provideNewPIN(PINSpec spec) + public char[] provideNewPIN(PinInfo spec) throws CancelledException, InterruptedException { throw new CancelledException("cancelled by cancelPINProvider"); } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelPINProvider.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelPINProvider.java index 77f19345..7da3ec5c 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelPINProvider.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelPINProvider.java @@ -17,12 +17,12 @@ package at.gv.egiz.smcc.pin.gui; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; public class CancelPINProvider extends DummyPINGUI implements PINGUI { @Override - public char[] providePIN(PINSpec spec, int retries) + public char[] providePIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { throw new CancelledException("cancelled by cancelPINProvider"); } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/ChangePINProvider.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/ChangePINProvider.java index 5eb8b9a1..50bc0784 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/ChangePINProvider.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/ChangePINProvider.java @@ -17,7 +17,7 @@ package at.gv.egiz.smcc.pin.gui; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; public class ChangePINProvider extends DummyChangePINGUI implements ModifyPINGUI { @@ -35,14 +35,14 @@ public class ChangePINProvider extends DummyChangePINGUI implements ModifyPINGUI } @Override - public char[] provideCurrentPIN(PINSpec spec, int retries) + public char[] provideCurrentPIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { provided++; return oldPin; } @Override - public char[] provideNewPIN(PINSpec spec) { + public char[] provideNewPIN(PinInfo spec) { return pin; } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyChangePINGUI.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyChangePINGUI.java index fff89409..e6192417 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyChangePINGUI.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyChangePINGUI.java @@ -17,7 +17,7 @@ package at.gv.egiz.smcc.pin.gui; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; public abstract class DummyChangePINGUI implements ModifyPINGUI { @@ -47,22 +47,22 @@ public abstract class DummyChangePINGUI implements ModifyPINGUI { } @Override - public void modifyPINDirect(PINSpec spec, int retries) throws CancelledException, InterruptedException { + public void modifyPINDirect(PinInfo spec, int retries) throws CancelledException, InterruptedException { throw new UnsupportedOperationException("Not supported yet."); } @Override - public void enterCurrentPIN(PINSpec spec, int retries) { + public void enterCurrentPIN(PinInfo spec, int retries) { throw new UnsupportedOperationException("Not supported yet."); } @Override - public void enterNewPIN(PINSpec spec) { + public void enterNewPIN(PinInfo spec) { throw new UnsupportedOperationException("Not supported yet."); } @Override - public void confirmNewPIN(PINSpec spec) { + public void confirmNewPIN(PinInfo spec) { throw new UnsupportedOperationException("Not supported yet."); } } \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyPINGUI.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyPINGUI.java index 4d99b5c1..27d268c5 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyPINGUI.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyPINGUI.java @@ -17,17 +17,17 @@ package at.gv.egiz.smcc.pin.gui; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; public abstract class DummyPINGUI implements PINGUI { @Override - public void enterPINDirect(PINSpec spec, int retries) throws CancelledException, InterruptedException { + public void enterPINDirect(PinInfo spec, int retries) throws CancelledException, InterruptedException { throw new UnsupportedOperationException("Not supported yet."); } @Override - public void enterPIN(PINSpec spec, int retries) throws CancelledException, InterruptedException { + public void enterPIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { throw new UnsupportedOperationException("Not supported yet."); } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InterruptPINProvider.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InterruptPINProvider.java index 5706b888..814ced11 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InterruptPINProvider.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InterruptPINProvider.java @@ -17,7 +17,7 @@ package at.gv.egiz.smcc.pin.gui; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; @SuppressWarnings("restriction") public class InterruptPINProvider extends DummyPINGUI implements PINGUI { @@ -26,7 +26,7 @@ public class InterruptPINProvider extends DummyPINGUI implements PINGUI { } @Override - public char[] providePIN(PINSpec spec, int retries) + public char[] providePIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { throw new InterruptedException("interrupted by cancelPINProvider"); } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidChangePINProvider.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidChangePINProvider.java index 69c9f42a..53732d82 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidChangePINProvider.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidChangePINProvider.java @@ -17,7 +17,7 @@ package at.gv.egiz.smcc.pin.gui; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; public class InvalidChangePINProvider extends DummyChangePINGUI implements ModifyPINGUI { @@ -35,7 +35,7 @@ public class InvalidChangePINProvider extends DummyChangePINGUI implements Modif } @Override - public char[] provideCurrentPIN(PINSpec spec, int retries) + public char[] provideCurrentPIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { if (provided >= numWrongTries) { throw new CancelledException("Number of wrong tries reached: " + provided); @@ -50,7 +50,7 @@ public class InvalidChangePINProvider extends DummyChangePINGUI implements Modif } @Override - public char[] provideNewPIN(PINSpec spec) { + public char[] provideNewPIN(PinInfo spec) { return pin; } } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidPINProvider.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidPINProvider.java index db01fd0d..695ec964 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidPINProvider.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidPINProvider.java @@ -17,7 +17,7 @@ package at.gv.egiz.smcc.pin.gui; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; public class InvalidPINProvider extends DummyPINGUI implements PINGUI { @@ -32,7 +32,7 @@ public class InvalidPINProvider extends DummyPINGUI implements PINGUI { } @Override - public char[] providePIN(PINSpec spec, int retries) + public char[] providePIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { if (provided >= numWrongTries) { throw new CancelledException("Number of wrong tries reached: " + provided); diff --git a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/SMCCTestPINProvider.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/SMCCTestPINProvider.java index dffc90d7..e6fd67d5 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/SMCCTestPINProvider.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/SMCCTestPINProvider.java @@ -17,7 +17,7 @@ package at.gv.egiz.smcc.pin.gui; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PinInfo; public class SMCCTestPINProvider extends DummyPINGUI implements PINGUI { @@ -29,7 +29,7 @@ public class SMCCTestPINProvider extends DummyPINGUI implements PINGUI { } @Override - public char[] providePIN(PINSpec spec, int retries) + public char[] providePIN(PinInfo spec, int retries) throws CancelledException, InterruptedException { provided++; return pin; diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardChannelEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardChannelEmul.java index 2e0c54eb..f37f12dd 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardChannelEmul.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardChannelEmul.java @@ -364,7 +364,7 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { } PIN pin; - if (currentAppl != null) { + if ((command.getP2() & 0x80) > 0 && currentAppl != null) { pin = currentAppl.pins.get(command.getP2()); } else { pin = globalPins.get(command.getP2()); @@ -388,7 +388,7 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { if (response.getSW() == 0x9000) { PIN pin; - if (currentAppl != null) { + if ((command.getP2() & 0x80) > 0 && currentAppl != null) { pin = currentAppl.pins.get(command.getP2()); } else { pin = globalPins.get(command.getP2()); 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 154884d4..82e48d64 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 @@ -41,7 +41,7 @@ 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.PINSpec; +import at.gv.egiz.smcc.PinInfo; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.smcc.SignatureCardFactory; @@ -258,17 +258,17 @@ public class STARCOSCardTest extends CardTest { PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard( STARCOSCardEmul.DEFAULT_SS_PIN, STARCOSCardEmul.DEFAULT_SS_PIN, PIN.STATE_RESET); - for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + for (PinInfo pinInfo : signatureCard.getPinInfos()) { char[] pin = "123456".toCharArray(); - for (int i = pinSpec.getMinLength(); i <= pinSpec.getMaxLength(); i++) { - signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + 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(pinSpec, new ChangePINProvider(pin, newPin)); - signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(newPin)); + .changePIN(pinInfo, new ChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(newPin)); pin = newPin; } } @@ -283,20 +283,20 @@ public class STARCOSCardTest extends CardTest { PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard( null, null, PIN.STATE_PIN_NOTACTIVE); - for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + for (PinInfo pinInfo : signatureCard.getPinInfos()) { - char[] pin = "1234567890".substring(0, pinSpec.getMinLength()).toCharArray(); + char[] pin = "1234567890".substring(0, pinInfo.getMinLength()).toCharArray(); boolean notActive = false; try { - signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(pin)); } catch (NotActivatedException ex) { notActive = true; } assertTrue(notActive); - signatureCard.activatePIN(pinSpec, new ChangePINProvider(null, pin)); - signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + signatureCard.activatePIN(pinInfo, new ChangePINProvider(null, pin)); + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(pin)); } } @@ -307,13 +307,13 @@ public class STARCOSCardTest extends CardTest { PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard(); - for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + for (PinInfo pinInfo : signatureCard.getPinInfos()) { char[] invalidPin = "999999".toCharArray(); int numInvalidTries = 2; InvalidPINProvider invalidPinProvider = new InvalidPINProvider(invalidPin, numInvalidTries); try { - signatureCard.verifyPIN(pinSpec, invalidPinProvider); + signatureCard.verifyPIN(pinInfo, invalidPinProvider); } catch (CancelledException ex) { } finally { assertTrue(invalidPinProvider.getProvided() == numInvalidTries); @@ -328,7 +328,7 @@ public class STARCOSCardTest extends CardTest { PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard(); - for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + for (PinInfo pinInfo : signatureCard.getPinInfos()) { char[] invalidPin = "999999".toCharArray(); int numInvalidTries = 2; @@ -336,7 +336,7 @@ public class STARCOSCardTest extends CardTest { new InvalidChangePINProvider(invalidPin, invalidPin, numInvalidTries); try { - signatureCard.changePIN(pinSpec, invalidPinProvider); + signatureCard.changePIN(pinInfo, invalidPinProvider); } catch (CancelledException ex) { } finally { assertTrue(invalidPinProvider.getProvided() == numInvalidTries); diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardTest.java index 06744c82..1d8507b2 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardTest.java @@ -24,7 +24,6 @@ import java.util.Arrays; import org.junit.Test; import at.gv.egiz.smcc.CancelledException; -import at.gv.egiz.smcc.CardEmul; import at.gv.egiz.smcc.CardNotSupportedException; import at.gv.egiz.smcc.CardTerminalEmul; import at.gv.egiz.smcc.CardTest; @@ -34,12 +33,11 @@ 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.PINSpec; +import at.gv.egiz.smcc.PinInfo; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.smcc.SignatureCardFactory; import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider; -import org.junit.Ignore; public class STARCOSG3CardTest extends CardTest { @@ -72,17 +70,17 @@ public class STARCOSG3CardTest extends CardTest { PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard( STARCOSG3CardEmul.DEFAULT_SS_PIN, STARCOSG3CardEmul.DEFAULT_SS_PIN, PIN.STATE_RESET); - for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + for (PinInfo pinInfo : signatureCard.getPinInfos()) { char[] pin = "123456".toCharArray(); - for (int i = pinSpec.getMinLength(); i <= pinSpec.getMaxLength(); i++) { - signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + 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(pinSpec, new ChangePINProvider(pin, newPin)); - signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(newPin)); + .changePIN(pinInfo, new ChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(newPin)); pin = newPin; } } @@ -97,21 +95,21 @@ public class STARCOSG3CardTest extends CardTest { PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard( STARCOSG3CardEmul.TRANSPORT_SS_PIN, STARCOSG3CardEmul.TRANSPORT_SS_PIN, PIN.STATE_PIN_NOTACTIVE); - for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + for (PinInfo pinInfo : signatureCard.getPinInfos()) { - char[] pin = "123456789".substring(0, pinSpec.getMinLength()).toCharArray(); + char[] pin = "123456789".substring(0, pinInfo.getMinLength()).toCharArray(); char[] transportPIN = "123456".toCharArray(); boolean notActive = false; try { - signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(pin)); } catch (NotActivatedException ex) { notActive = true; } assertTrue(notActive); - signatureCard.activatePIN(pinSpec, new ChangePINProvider(transportPIN, pin)); - signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + signatureCard.activatePIN(pinInfo, new ChangePINProvider(transportPIN, pin)); + signatureCard.verifyPIN(pinInfo, new SMCCTestPINProvider(pin)); } } -- cgit v1.2.3