From 32d17447a258188b2d534bcb0bf65a659ba7b7d0 Mon Sep 17 00:00:00 2001 From: mcentner Date: Fri, 29 Aug 2008 12:11:34 +0000 Subject: Initial import. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/smcc/SMCCApplication.java | 46 ++++++++++++++++ smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java | 63 ++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java (limited to 'smcc/src/test/java/at/gv/egiz/smcc') diff --git a/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java b/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java new file mode 100644 index 00000000..5f4bb67e --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java @@ -0,0 +1,46 @@ +/* +* Copyright 2008 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; + +import java.util.Locale; + +import at.gv.egiz.smcc.util.SMCCHelper; + +public class SMCCApplication { + + /** + * @param args + */ + public static void main(String[] args) { + + SignatureCard sc = null; + SMCCHelper smccHelper = new SMCCHelper(); + while (smccHelper.getResultCode() != SMCCHelper.CARD_FOUND) { + System.out.println("Did not get a signature card ... "+smccHelper.getResultCode()); + smccHelper.update(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + sc = smccHelper.getSignatureCard(Locale.getDefault()); + System.out.println("Found supported siganture card: "+sc); + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java new file mode 100644 index 00000000..5448fee2 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java @@ -0,0 +1,63 @@ +/* +* Copyright 2008 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; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import at.gv.egiz.smcc.SignatureCard.KeyboxName; + +public class SWCardTest implements PINProvider { + + SWCard swCard = new SWCard(); + + public static void main(String[] args) throws Exception { + + SWCardTest swCardTest = new SWCardTest(); + swCardTest.test(); + + } + + public void test() throws SignatureCardException, NoSuchAlgorithmException { + + swCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); + swCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); + + BigInteger t = BigInteger.valueOf(System.currentTimeMillis()); + + MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); + byte[] hash = messageDigest.digest(t.toByteArray()); + + byte[] signature; + signature = swCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, this); + System.out.println(SignatureCardFactory.toString(signature)); + + signature = swCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, this); + System.out.println(SignatureCardFactory.toString(signature)); + + byte[] infobox = swCard.getInfobox("IdentityLink", this, null); + System.out.println(SignatureCardFactory.toString(infobox)); + + } + + @Override + public String providePIN(PINSpec spec, int retries) { + return "buerger"; + } + +} -- cgit v1.2.3 From c2ae3db1bc6dcb8ba3eb3461c05e293917c004ca Mon Sep 17 00:00:00 2001 From: mcentner Date: Thu, 30 Oct 2008 10:33:29 +0000 Subject: Updated SMCC to use exclusive access and to throw exceptions upon locked or not activated cards. Improved locale support in the security layer request and response processing. Fixed issue in STAL which prevented the use of RSA-SHA1 signatures. Added additional parameters to the applet test pages. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@128 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/smcc/STARCOSCardTest.java | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java (limited to 'smcc/src/test/java/at/gv/egiz/smcc') diff --git a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java new file mode 100644 index 00000000..b921a5d5 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java @@ -0,0 +1,92 @@ +/* +* Copyright 2008 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; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Locale; + +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.smcc.util.SMCCHelper; + +public class STARCOSCardTest { + + /** + * @param args + * @throws CardException + * @throws NoSuchAlgorithmException + */ + public static void main(String[] args) throws CardException, NoSuchAlgorithmException { + + SMCCHelper helper = new SMCCHelper(); + while (helper.getResultCode() != SMCCHelper.CARD_FOUND) { + System.out.println("Did not get a signature card ... " + helper.getResultCode()); + helper.update(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + SignatureCard signatureCard = helper.getSignatureCard(Locale.getDefault()); + + System.out.println("Found '" + signatureCard + "'."); + + try { +// signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); +// signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); +// signatureCard.getInfobox("IdentityLink", new CommandLinePINProvider(), null); + MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); + byte[] digest = messageDigest.digest("test".getBytes()); + signatureCard.createSignature(digest, KeyboxName.CERITIFIED_KEYPAIR, new CommandLinePINProvider()); + } catch (SignatureCardException e) { + e.printStackTrace(); + } + + } + + private static class CommandLinePINProvider implements PINProvider { + + @Override + public String providePIN(PINSpec spec, int retries) { + + InputStreamReader inputStreamReader = new InputStreamReader(System.in); + BufferedReader in = new BufferedReader(inputStreamReader); + + System.out.print("Enter " + spec.getLocalizedName() + " [" + + spec.getMinLength() + "-" + spec.getMaxLength() + "] (" + retries + + " retries):"); + + try { + return in.readLine(); + } catch (IOException e) { + return null; + } + + } + + } + +} -- cgit v1.2.3 From e4a47aa9393d74647f4f0c66b54dc4519fed492f Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 11 Nov 2008 12:16:00 +0000 Subject: Interrupt in waitForAction (applet closed) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@162 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/smcc/STARCOSCardTest.java | 2 +- smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java | 94 +++++++++++----------- 2 files changed, 48 insertions(+), 48 deletions(-) (limited to 'smcc/src/test/java/at/gv/egiz/smcc') diff --git a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java index b921a5d5..13210540 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java @@ -37,7 +37,7 @@ public class STARCOSCardTest { * @throws CardException * @throws NoSuchAlgorithmException */ - public static void main(String[] args) throws CardException, NoSuchAlgorithmException { + public static void main(String[] args) throws CardException, NoSuchAlgorithmException, InterruptedException { SMCCHelper helper = new SMCCHelper(); while (helper.getResultCode() != SMCCHelper.CARD_FOUND) { diff --git a/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java index 5448fee2..38126a67 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java @@ -14,50 +14,50 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.smcc; - -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import at.gv.egiz.smcc.SignatureCard.KeyboxName; - -public class SWCardTest implements PINProvider { - - SWCard swCard = new SWCard(); - - public static void main(String[] args) throws Exception { - - SWCardTest swCardTest = new SWCardTest(); - swCardTest.test(); - - } - - public void test() throws SignatureCardException, NoSuchAlgorithmException { - - swCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); - swCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); - - BigInteger t = BigInteger.valueOf(System.currentTimeMillis()); - - MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); - byte[] hash = messageDigest.digest(t.toByteArray()); - - byte[] signature; - signature = swCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, this); - System.out.println(SignatureCardFactory.toString(signature)); - - signature = swCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, this); - System.out.println(SignatureCardFactory.toString(signature)); - - byte[] infobox = swCard.getInfobox("IdentityLink", this, null); - System.out.println(SignatureCardFactory.toString(infobox)); - - } - - @Override - public String providePIN(PINSpec spec, int retries) { - return "buerger"; - } - -} +package at.gv.egiz.smcc; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import at.gv.egiz.smcc.SignatureCard.KeyboxName; + +public class SWCardTest implements PINProvider { + + SWCard swCard = new SWCard(); + + public static void main(String[] args) throws Exception { + + SWCardTest swCardTest = new SWCardTest(); + swCardTest.test(); + + } + + public void test() throws SignatureCardException, NoSuchAlgorithmException, InterruptedException { + + swCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); + swCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); + + BigInteger t = BigInteger.valueOf(System.currentTimeMillis()); + + MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); + byte[] hash = messageDigest.digest(t.toByteArray()); + + byte[] signature; + signature = swCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, this); + System.out.println(SignatureCardFactory.toString(signature)); + + signature = swCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, this); + System.out.println(SignatureCardFactory.toString(signature)); + + byte[] infobox = swCard.getInfobox("IdentityLink", this, null); + System.out.println(SignatureCardFactory.toString(infobox)); + + } + + @Override + public String providePIN(PINSpec spec, int retries) { + return "buerger"; + } + +} -- cgit v1.2.3 From 887f6727479f3ae3d89a08ba619f9382b450e4c1 Mon Sep 17 00:00:00 2001 From: mcentner Date: Fri, 12 Dec 2008 11:48:47 +0000 Subject: Updated SMCC to support non-blocking PIN entry. Added SV-Personendaten infobox implementation. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@248 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/smcc/STARCOSCardTest.java | 40 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'smcc/src/test/java/at/gv/egiz/smcc') diff --git a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java index 13210540..090e1181 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java @@ -19,6 +19,8 @@ package at.gv.egiz.smcc; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Locale; @@ -27,6 +29,8 @@ import javax.smartcardio.CardException; import javax.smartcardio.CommandAPDU; import javax.smartcardio.ResponseAPDU; +import sun.misc.HexDumpEncoder; + import at.gv.egiz.smcc.SignatureCard.KeyboxName; import at.gv.egiz.smcc.util.SMCCHelper; @@ -34,10 +38,9 @@ public class STARCOSCardTest { /** * @param args - * @throws CardException - * @throws NoSuchAlgorithmException + * @throws Exception */ - public static void main(String[] args) throws CardException, NoSuchAlgorithmException, InterruptedException { + public static void main(String[] args) throws Exception { SMCCHelper helper = new SMCCHelper(); while (helper.getResultCode() != SMCCHelper.CARD_FOUND) { @@ -55,18 +58,41 @@ public class STARCOSCardTest { System.out.println("Found '" + signatureCard + "'."); try { -// signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); -// signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); -// signatureCard.getInfobox("IdentityLink", new CommandLinePINProvider(), null); +// printJavaByteArray( +// signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR), System.out); +// printJavaByteArray( +// signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR), System.out); +// System.out. println(new String(signatureCard.getInfobox("IdentityLink", new CommandLinePINProvider(), null))); +// byte[] infobox = signatureCard.getInfobox("Status", new CommandLinePINProvider(), null); +// printJavaByteArray(infobox, System.out); MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); byte[] digest = messageDigest.digest("test".getBytes()); - signatureCard.createSignature(digest, KeyboxName.CERITIFIED_KEYPAIR, new CommandLinePINProvider()); + byte[] signature = signatureCard.createSignature(digest, KeyboxName.SECURE_SIGNATURE_KEYPAIR, new CommandLinePINProvider()); + printJavaByteArray(signature, System.out); } catch (SignatureCardException e) { e.printStackTrace(); } } + public static void printJavaByteArray(byte[] bytes, OutputStream os) { + + PrintWriter w = new PrintWriter(os); + + w.write("new byte[] {"); + for (int i = 0; i < bytes.length;) { + if (i % 8 == 0) { + w.write("\n "); + } + w.write("(byte) 0x" + Integer.toHexString(0x0F & (bytes[i] >> 4)) + Integer.toHexString(0x0F & bytes[i])); + if (++i < bytes.length) { + w.write(", "); + } + } + w.write("\n};"); + w.flush(); + } + private static class CommandLinePINProvider implements PINProvider { @Override -- cgit v1.2.3 From d1cb86eef5158caea65975d9cc62c8b616ea6a73 Mon Sep 17 00:00:00 2001 From: wbauer Date: Wed, 17 Dec 2008 14:24:38 +0000 Subject: Added @Ignore git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@251 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java | 11 +++++++---- smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java | 3 +++ smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'smcc/src/test/java/at/gv/egiz/smcc') diff --git a/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java b/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java index 5f4bb67e..4835865f 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java @@ -16,10 +16,13 @@ */ package at.gv.egiz.smcc; -import java.util.Locale; - -import at.gv.egiz.smcc.util.SMCCHelper; - +import java.util.Locale; + +import org.junit.Ignore; + +import at.gv.egiz.smcc.util.SMCCHelper; + +@Ignore public class SMCCApplication { /** diff --git a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java index 090e1181..7f421474 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java @@ -29,11 +29,14 @@ import javax.smartcardio.CardException; import javax.smartcardio.CommandAPDU; import javax.smartcardio.ResponseAPDU; +import org.junit.Ignore; + import sun.misc.HexDumpEncoder; import at.gv.egiz.smcc.SignatureCard.KeyboxName; import at.gv.egiz.smcc.util.SMCCHelper; +@Ignore public class STARCOSCardTest { /** diff --git a/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java index 38126a67..115edc16 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java @@ -20,8 +20,11 @@ import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import org.junit.Ignore; + import at.gv.egiz.smcc.SignatureCard.KeyboxName; +@Ignore public class SWCardTest implements PINProvider { SWCard swCard = new SWCard(); -- cgit v1.2.3 From 77a19e106e4128c21dd2d1270fdc8d930e415247 Mon Sep 17 00:00:00 2001 From: wbauer Date: Thu, 18 Dec 2008 08:58:39 +0000 Subject: Fixed BUG #366, changed applet name in BKUOnline to have no version number git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@253 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/smcc/SMCCApplication.java | 49 --------- .../test/java/at/gv/egiz/smcc/STARCOSCardTest.java | 121 --------------------- smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java | 66 ----------- 3 files changed, 236 deletions(-) delete mode 100644 smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java delete mode 100644 smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java delete mode 100644 smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java (limited to 'smcc/src/test/java/at/gv/egiz/smcc') diff --git a/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java b/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java deleted file mode 100644 index 4835865f..00000000 --- a/smcc/src/test/java/at/gv/egiz/smcc/SMCCApplication.java +++ /dev/null @@ -1,49 +0,0 @@ -/* -* Copyright 2008 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; - -import java.util.Locale; - -import org.junit.Ignore; - -import at.gv.egiz.smcc.util.SMCCHelper; - -@Ignore -public class SMCCApplication { - - /** - * @param args - */ - public static void main(String[] args) { - - SignatureCard sc = null; - SMCCHelper smccHelper = new SMCCHelper(); - while (smccHelper.getResultCode() != SMCCHelper.CARD_FOUND) { - System.out.println("Did not get a signature card ... "+smccHelper.getResultCode()); - smccHelper.update(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - sc = smccHelper.getSignatureCard(Locale.getDefault()); - System.out.println("Found supported siganture card: "+sc); - } - -} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java deleted file mode 100644 index 7f421474..00000000 --- a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* -* Copyright 2008 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; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Locale; - -import javax.smartcardio.CardException; -import javax.smartcardio.CommandAPDU; -import javax.smartcardio.ResponseAPDU; - -import org.junit.Ignore; - -import sun.misc.HexDumpEncoder; - -import at.gv.egiz.smcc.SignatureCard.KeyboxName; -import at.gv.egiz.smcc.util.SMCCHelper; - -@Ignore -public class STARCOSCardTest { - - /** - * @param args - * @throws Exception - */ - public static void main(String[] args) throws Exception { - - SMCCHelper helper = new SMCCHelper(); - while (helper.getResultCode() != SMCCHelper.CARD_FOUND) { - System.out.println("Did not get a signature card ... " + helper.getResultCode()); - helper.update(); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - SignatureCard signatureCard = helper.getSignatureCard(Locale.getDefault()); - - System.out.println("Found '" + signatureCard + "'."); - - try { -// printJavaByteArray( -// signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR), System.out); -// printJavaByteArray( -// signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR), System.out); -// System.out. println(new String(signatureCard.getInfobox("IdentityLink", new CommandLinePINProvider(), null))); -// byte[] infobox = signatureCard.getInfobox("Status", new CommandLinePINProvider(), null); -// printJavaByteArray(infobox, System.out); - MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); - byte[] digest = messageDigest.digest("test".getBytes()); - byte[] signature = signatureCard.createSignature(digest, KeyboxName.SECURE_SIGNATURE_KEYPAIR, new CommandLinePINProvider()); - printJavaByteArray(signature, System.out); - } catch (SignatureCardException e) { - e.printStackTrace(); - } - - } - - public static void printJavaByteArray(byte[] bytes, OutputStream os) { - - PrintWriter w = new PrintWriter(os); - - w.write("new byte[] {"); - for (int i = 0; i < bytes.length;) { - if (i % 8 == 0) { - w.write("\n "); - } - w.write("(byte) 0x" + Integer.toHexString(0x0F & (bytes[i] >> 4)) + Integer.toHexString(0x0F & bytes[i])); - if (++i < bytes.length) { - w.write(", "); - } - } - w.write("\n};"); - w.flush(); - } - - private static class CommandLinePINProvider implements PINProvider { - - @Override - public String providePIN(PINSpec spec, int retries) { - - InputStreamReader inputStreamReader = new InputStreamReader(System.in); - BufferedReader in = new BufferedReader(inputStreamReader); - - System.out.print("Enter " + spec.getLocalizedName() + " [" - + spec.getMinLength() + "-" + spec.getMaxLength() + "] (" + retries - + " retries):"); - - try { - return in.readLine(); - } catch (IOException e) { - return null; - } - - } - - } - -} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java deleted file mode 100644 index 115edc16..00000000 --- a/smcc/src/test/java/at/gv/egiz/smcc/SWCardTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* -* Copyright 2008 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; - -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import org.junit.Ignore; - -import at.gv.egiz.smcc.SignatureCard.KeyboxName; - -@Ignore -public class SWCardTest implements PINProvider { - - SWCard swCard = new SWCard(); - - public static void main(String[] args) throws Exception { - - SWCardTest swCardTest = new SWCardTest(); - swCardTest.test(); - - } - - public void test() throws SignatureCardException, NoSuchAlgorithmException, InterruptedException { - - swCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); - swCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); - - BigInteger t = BigInteger.valueOf(System.currentTimeMillis()); - - MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); - byte[] hash = messageDigest.digest(t.toByteArray()); - - byte[] signature; - signature = swCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, this); - System.out.println(SignatureCardFactory.toString(signature)); - - signature = swCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, this); - System.out.println(SignatureCardFactory.toString(signature)); - - byte[] infobox = swCard.getInfobox("IdentityLink", this, null); - System.out.println(SignatureCardFactory.toString(infobox)); - - } - - @Override - public String providePIN(PINSpec spec, int retries) { - return "buerger"; - } - -} -- cgit v1.2.3 From 616e06910051528674165319a1d6d161dff5859c Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 27 Mar 2009 17:33:11 +0000 Subject: 1.1-RC6 (pinpad, pinmgmt, secureviewer) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@323 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/smcc/ACOSCardTest.java | 135 +++++++++++ .../test/java/at/gv/egiz/smcc/STARCOSCardTest.java | 267 +++++++++++++++++++++ 2 files changed, 402 insertions(+) create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/ACOSCardTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java (limited to 'smcc/src/test/java/at/gv/egiz/smcc') diff --git a/smcc/src/test/java/at/gv/egiz/smcc/ACOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/ACOSCardTest.java new file mode 100644 index 00000000..5839d14a --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/ACOSCardTest.java @@ -0,0 +1,135 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.smcc; + +import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.smcc.util.SMCCHelper; +import java.util.List; +import java.util.Locale; +import javax.smartcardio.ResponseAPDU; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author clemens + */ +@Ignore +public class ACOSCardTest { + + static ACOSCard card; + static PINSpec infPin, decPin, sigPin; + + public ACOSCardTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + SMCCHelper smccHelper = new SMCCHelper(); + switch (smccHelper.getResultCode()) { + case SMCCHelper.CARD_FOUND: + SignatureCard sigCard = smccHelper.getSignatureCard(Locale.GERMAN); + if (sigCard instanceof ACOSCard) { + System.out.println("ACOS card found"); + card = (ACOSCard) sigCard; + List pinSpecs = card.getPINSpecs(); + infPin = pinSpecs.get(ACOSCard.PINSPEC_INF); + decPin = pinSpecs.get(ACOSCard.PINSPEC_DEC); + sigPin = pinSpecs.get(ACOSCard.PINSPEC_SIG); + } else { + throw new Exception("not STARCOS card: " + sigCard.toString()); + } + break; + default: + throw new Exception("no card found"); + } + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + + + /** + * Test of verifyPIN method, of class STARCOSCard. + */ + @Test + @Ignore + public void testVerifyPIN_pinpad() throws Exception { + System.out.println("verifyPIN (pinpad)"); + assertNotNull(card); + + card.verifyPIN(decPin, new PINProvider() { + + @Override + public char[] providePIN(PINSpec spec, int retries) { + return null; + } + }); + } + + /** + * Test of verifyPIN method, of class STARCOSCard. + */ + @Test + @Ignore + public void testVerifyPIN_internal() throws Exception { + System.out.println("verifyPIN (internal)"); + assertNotNull(card); + + card.reset(); + + card.getCard().beginExclusive(); + + // 0x6700 without sending an APDU prior to send CtrlCmd + System.out.println("WARNING: this command will fail if no card " + + "communication took place prior to sending the CtrlCommand"); + int retries = card.verifyPIN(decPin.getKID(), null); //"1397".toCharArray()); + + System.out.println("VERIFY PIN returned " + retries); + card.getCard().endExclusive(); + } + + /** + * Test of changePIN method, of class STARCOSCard. + */ + @Test + @Ignore + public void testChangePIN() throws Exception { + System.out.println("changePIN"); + assertNotNull(card); + + card.reset(); + int retries = card.changePIN(decPin.getKID(), null, null); + + System.out.println("CHANGE PIN returned " + retries); + } + + /** + * Test of reset method, of class STARCOSCard. + */ + @Test + public void testReset() throws Exception { + System.out.println("reset"); + assertNotNull(card); + card.reset(); + } + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java new file mode 100644 index 00000000..9be8db00 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java @@ -0,0 +1,267 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.smcc; + +import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.smcc.util.SMCCHelper; +import java.util.List; +import java.util.Locale; +import javax.smartcardio.ResponseAPDU; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author clemens + */ +@Ignore +public class STARCOSCardTest { + + static STARCOSCard card; + static PINSpec cardPin, ssPin; + + public STARCOSCardTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + SMCCHelper smccHelper = new SMCCHelper(); + switch (smccHelper.getResultCode()) { + case SMCCHelper.CARD_FOUND: + SignatureCard sigCard = smccHelper.getSignatureCard(Locale.GERMAN); + if (sigCard instanceof STARCOSCard) { + System.out.println("STARCOS card found"); + card = (STARCOSCard) sigCard; + List pinSpecs = card.getPINSpecs(); + cardPin = pinSpecs.get(STARCOSCard.PINSPEC_CARD); + ssPin = pinSpecs.get(STARCOSCard.PINSPEC_SS); + + } else { + throw new Exception("not STARCOS card: " + sigCard.toString()); + } + break; + default: + throw new Exception("no card found"); + } + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getCertificate method, of class STARCOSCard. + */ + @Test + @Ignore + public void testGetCertificate() throws Exception { + System.out.println("getCertificate"); + KeyboxName keyboxName = null; + STARCOSCard instance = new STARCOSCard(); + byte[] expResult = null; + byte[] result = instance.getCertificate(keyboxName); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getInfobox method, of class STARCOSCard. + */ + @Test + @Ignore + public void testGetInfobox() throws Exception { + System.out.println("getInfobox"); + String infobox = ""; + PINProvider provider = null; + String domainId = ""; + STARCOSCard instance = new STARCOSCard(); + byte[] expResult = null; + byte[] result = instance.getInfobox(infobox, provider, domainId); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of createSignature method, of class STARCOSCard. + */ + @Test + @Ignore + public void testCreateSignature() throws Exception { + System.out.println("createSignature"); + byte[] hash = null; + KeyboxName keyboxName = null; + PINProvider provider = null; + STARCOSCard instance = new STARCOSCard(); + byte[] expResult = null; + byte[] result = instance.createSignature(hash, keyboxName, provider); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of selectFileFID method, of class STARCOSCard. + */ + @Test + @Ignore + public void testSelectFileFID() throws Exception { + System.out.println("selectFileFID"); + byte[] fid = null; + STARCOSCard instance = new STARCOSCard(); + ResponseAPDU expResult = null; + ResponseAPDU result = instance.selectFileFID(fid); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of verifyPIN method, of class STARCOSCard. + */ + @Test + @Ignore + public void testVerifyPIN_pinpad() throws Exception { + System.out.println("verifyPIN (pinpad)"); + assertNotNull(card); + + card.verifyPIN(cardPin, new PINProvider() { + + @Override + public char[] providePIN(PINSpec spec, int retries) { + return null; + } + }); + } + + /** + * Test of verifyPIN method, of class STARCOSCard. + */ + @Test + @Ignore + public void testVerifyPIN_internal() throws Exception { + System.out.println("verifyPIN (internal)"); + assertNotNull(card); + + card.reset(); + + card.getCard().beginExclusive(); + + // 0x6700 without sending an APDU prior to send CtrlCmd + System.out.println("WARNING: this command will fail if no card " + + "communication took place prior to sending the CtrlCommand"); + int retries = card.verifyPIN(cardPin.getKID(), null); //"1397".toCharArray()); + + System.out.println("VERIFY PIN returned " + retries); + card.getCard().endExclusive(); + } + + /** + * Test of verifyPIN method, of class STARCOSCard. + */ + @Test + @Ignore + public void testVerifyPIN_byte() throws Exception { + System.out.println("verifyPIN"); + byte kid = 0; + STARCOSCard instance = new STARCOSCard(); + int expResult = 0; + int result = instance.verifyPIN(kid); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of changePIN method, of class STARCOSCard. + */ + @Test + @Ignore + public void testChangePIN() throws Exception { + System.out.println("changePIN"); + assertNotNull(card); + + card.reset(); + int retries = card.changePIN(cardPin.getKID(), null, null); + + System.out.println("CHANGE PIN returned " + retries); + } + + /** + * Test of activatePIN method, of class STARCOSCard. + */ + @Test + @Ignore + public void testActivatePIN() throws Exception { + System.out.println("activatePIN"); + assertNotNull(card); + + card.reset(); + card.activatePIN(cardPin, new PINProvider() { + + @Override + public char[] providePIN(PINSpec spec, int retries) throws CancelledException, InterruptedException { + return null; + } + }); + } + + /** + * Test of encodePINBlock method, of class STARCOSCard. + */ + @Test + @Ignore + public void testEncodePINBlock() throws Exception { + System.out.println("encodePINBlock"); + char[] pin = null; + STARCOSCard instance = new STARCOSCard(); + byte[] expResult = null; + byte[] result = instance.encodePINBlock(pin); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of reset method, of class STARCOSCard. + */ + @Test + public void testReset() throws Exception { + System.out.println("reset"); + assertNotNull(card); + card.reset(); + } + + /** + * Test of toString method, of class STARCOSCard. + */ + @Test + @Ignore + public void testToString() { + System.out.println("toString"); + STARCOSCard instance = new STARCOSCard(); + String expResult = ""; + String result = instance.toString(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + +} \ No newline at end of file -- cgit v1.2.3 From 6cb4a071eab9a3b8cf78b8ec7e407aa148f2d038 Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 1 Jul 2009 13:03:41 +0000 Subject: Major refactoring of SMCC git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@381 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/smcc/ACOSCardTest.java | 135 -------- .../test/java/at/gv/egiz/smcc/AbstractAppl.java | 56 +++ smcc/src/test/java/at/gv/egiz/smcc/CardAppl.java | 43 +++ .../test/java/at/gv/egiz/smcc/CardChannelEmul.java | 52 +++ smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java | 106 ++++++ .../java/at/gv/egiz/smcc/CardTerminalEmul.java | 64 ++++ smcc/src/test/java/at/gv/egiz/smcc/CardTest.java | 298 ++++++++++++++++ .../test/java/at/gv/egiz/smcc/CardTestSuite.java | 29 ++ smcc/src/test/java/at/gv/egiz/smcc/File.java | 38 +++ smcc/src/test/java/at/gv/egiz/smcc/PIN.java | 41 +++ .../test/java/at/gv/egiz/smcc/STARCOSCardTest.java | 267 --------------- .../egiz/smcc/TransparentFileInputStreamTest.java | 208 ++++++++++++ .../test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java | 151 +++++++++ .../test/java/at/gv/egiz/smcc/acos/A03ApplSIG.java | 77 +++++ .../at/gv/egiz/smcc/acos/A03CardChannelEmul.java | 98 ++++++ .../java/at/gv/egiz/smcc/acos/A03CardEmul.java | 36 ++ .../java/at/gv/egiz/smcc/acos/A03CardTest.java | 91 +++++ .../test/java/at/gv/egiz/smcc/acos/A04ApplDEC.java | 296 ++++++++++++++++ .../test/java/at/gv/egiz/smcc/acos/A04ApplSIG.java | 87 +++++ .../at/gv/egiz/smcc/acos/A04CardChannelEmul.java | 75 +++++ .../java/at/gv/egiz/smcc/acos/A04CardEmul.java | 37 ++ .../java/at/gv/egiz/smcc/acos/A04CardTest.java | 143 ++++++++ .../test/java/at/gv/egiz/smcc/acos/ACOSAppl.java | 79 +++++ .../java/at/gv/egiz/smcc/acos/ACOSApplDEC.java | 334 ++++++++++++++++++ .../java/at/gv/egiz/smcc/acos/ACOSApplSIG.java | 302 +++++++++++++++++ .../at/gv/egiz/smcc/acos/ACOSCardChannelEmul.java | 261 ++++++++++++++ .../java/at/gv/egiz/smcc/acos/ACOSCardEmul.java | 38 +++ .../java/at/gv/egiz/smcc/acos/ACOSCardTest.java | 243 +++++++++++++ .../at/gv/egiz/smcc/acos/ACOSCardTestSuite.java | 27 ++ .../java/at/gv/egiz/smcc/starcos/STARCOSAppl.java | 95 ++++++ .../starcos/STARCOSApplGewoehnlicheSignatur.java | 332 ++++++++++++++++++ .../gv/egiz/smcc/starcos/STARCOSApplInfobox.java | 160 +++++++++ .../smcc/starcos/STARCOSApplSichereSignatur.java | 347 +++++++++++++++++++ .../egiz/smcc/starcos/STARCOSCardChannelEmul.java | 375 +++++++++++++++++++++ .../at/gv/egiz/smcc/starcos/STARCOSCardEmul.java | 50 +++ .../at/gv/egiz/smcc/starcos/STARCOSCardTest.java | 297 ++++++++++++++++ .../at/gv/egiz/smcc/util/ISO7816UtilsTest.java | 175 ++++++++++ 37 files changed, 5141 insertions(+), 402 deletions(-) delete mode 100644 smcc/src/test/java/at/gv/egiz/smcc/ACOSCardTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/AbstractAppl.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/CardAppl.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/CardChannelEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/CardTerminalEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/CardTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/CardTestSuite.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/File.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/PIN.java delete mode 100644 smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/TransparentFileInputStreamTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplSIG.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardChannelEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A04ApplDEC.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A04ApplSIG.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardChannelEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSAppl.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplDEC.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplSIG.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardChannelEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTestSuite.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSAppl.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplGewoehnlicheSignatur.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplInfobox.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplSichereSignatur.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardChannelEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/util/ISO7816UtilsTest.java (limited to 'smcc/src/test/java/at/gv/egiz/smcc') diff --git a/smcc/src/test/java/at/gv/egiz/smcc/ACOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/ACOSCardTest.java deleted file mode 100644 index 5839d14a..00000000 --- a/smcc/src/test/java/at/gv/egiz/smcc/ACOSCardTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package at.gv.egiz.smcc; - -import at.gv.egiz.smcc.SignatureCard.KeyboxName; -import at.gv.egiz.smcc.util.SMCCHelper; -import java.util.List; -import java.util.Locale; -import javax.smartcardio.ResponseAPDU; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author clemens - */ -@Ignore -public class ACOSCardTest { - - static ACOSCard card; - static PINSpec infPin, decPin, sigPin; - - public ACOSCardTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - SMCCHelper smccHelper = new SMCCHelper(); - switch (smccHelper.getResultCode()) { - case SMCCHelper.CARD_FOUND: - SignatureCard sigCard = smccHelper.getSignatureCard(Locale.GERMAN); - if (sigCard instanceof ACOSCard) { - System.out.println("ACOS card found"); - card = (ACOSCard) sigCard; - List pinSpecs = card.getPINSpecs(); - infPin = pinSpecs.get(ACOSCard.PINSPEC_INF); - decPin = pinSpecs.get(ACOSCard.PINSPEC_DEC); - sigPin = pinSpecs.get(ACOSCard.PINSPEC_SIG); - } else { - throw new Exception("not STARCOS card: " + sigCard.toString()); - } - break; - default: - throw new Exception("no card found"); - } - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - - - /** - * Test of verifyPIN method, of class STARCOSCard. - */ - @Test - @Ignore - public void testVerifyPIN_pinpad() throws Exception { - System.out.println("verifyPIN (pinpad)"); - assertNotNull(card); - - card.verifyPIN(decPin, new PINProvider() { - - @Override - public char[] providePIN(PINSpec spec, int retries) { - return null; - } - }); - } - - /** - * Test of verifyPIN method, of class STARCOSCard. - */ - @Test - @Ignore - public void testVerifyPIN_internal() throws Exception { - System.out.println("verifyPIN (internal)"); - assertNotNull(card); - - card.reset(); - - card.getCard().beginExclusive(); - - // 0x6700 without sending an APDU prior to send CtrlCmd - System.out.println("WARNING: this command will fail if no card " + - "communication took place prior to sending the CtrlCommand"); - int retries = card.verifyPIN(decPin.getKID(), null); //"1397".toCharArray()); - - System.out.println("VERIFY PIN returned " + retries); - card.getCard().endExclusive(); - } - - /** - * Test of changePIN method, of class STARCOSCard. - */ - @Test - @Ignore - public void testChangePIN() throws Exception { - System.out.println("changePIN"); - assertNotNull(card); - - card.reset(); - int retries = card.changePIN(decPin.getKID(), null, null); - - System.out.println("CHANGE PIN returned " + retries); - } - - /** - * Test of reset method, of class STARCOSCard. - */ - @Test - public void testReset() throws Exception { - System.out.println("reset"); - assertNotNull(card); - card.reset(); - } - -} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/AbstractAppl.java b/smcc/src/test/java/at/gv/egiz/smcc/AbstractAppl.java new file mode 100644 index 00000000..137de509 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/AbstractAppl.java @@ -0,0 +1,56 @@ +/* +* Copyright 2008 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; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + + +public abstract class AbstractAppl implements CardAppl { + + public final HashMap pins = new HashMap(); + + protected List files = new ArrayList(); + + public void checkINS(CommandAPDU command, int ins) { + if (command.getINS() != ins) { + throw new IllegalArgumentException("INS has to be 0x" + Integer.toHexString(ins) + "."); + } + } + + @Override + public abstract byte[] getAID(); + + @Override + public abstract byte[] getFCI(); + + public void putFile(File file) { + files.add(file); + } + + public List getFiles() { + return files; + } + + public abstract void setPin(int kid, char[] value); + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/CardAppl.java b/smcc/src/test/java/at/gv/egiz/smcc/CardAppl.java new file mode 100644 index 00000000..76a3e567 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardAppl.java @@ -0,0 +1,43 @@ +/* +* Copyright 2008 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; + +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + + +@SuppressWarnings("restriction") +public interface CardAppl { + + public byte[] getAID(); + + public byte[] getFID(); + + public byte[] getFCI(); + + public void leaveApplContext(); + + public ResponseAPDU cmdMANAGE_SECURITY_ENVIRONMENT(CommandAPDU command, CardChannelEmul channel) throws CardException; + + public ResponseAPDU cmdPERFORM_SECURITY_OPERATION(CommandAPDU command, CardChannelEmul channel) throws CardException; + + public ResponseAPDU cmdINTERNAL_AUTHENTICATE(CommandAPDU command, CardChannelEmul channel) throws CardException; + + public void setPin(int kid, char[] value); + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/CardChannelEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/CardChannelEmul.java new file mode 100644 index 00000000..bfe4e31c --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardChannelEmul.java @@ -0,0 +1,52 @@ +/* +* Copyright 2008 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; + +import java.nio.ByteBuffer; + +import javax.smartcardio.CardChannel; +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; + +@SuppressWarnings("restriction") +public abstract class CardChannelEmul extends CardChannel { + + protected AbstractAppl currentAppl = null; + protected File currentFile = null; + + public CardChannelEmul() { + super(); + } + + @Override + public int getChannelNumber() { + return 0; + } + + @Override + public void close() throws CardException { + throw new IllegalStateException("Basic logical channel cannot be closed."); + } + + @Override + public int transmit(ByteBuffer command, ByteBuffer response) throws CardException { + byte[] responseBytes = transmit(new CommandAPDU(command)).getBytes(); + response.put(responseBytes); + return responseBytes.length; + } + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java new file mode 100644 index 00000000..6017bcce --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java @@ -0,0 +1,106 @@ +/* +* Copyright 2008 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; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.smartcardio.Card; +import javax.smartcardio.CardChannel; +import javax.smartcardio.CardException; + + +@SuppressWarnings("restriction") +public abstract class CardEmul extends Card { + + protected Thread exclThread = null; + protected CardChannel channel = newCardChannel(this); + protected List applications = new ArrayList(); + + public CardEmul() { + super(); + } + + protected abstract CardChannelEmul newCardChannel(CardEmul cardEmul); + + @Override + public void beginExclusive() throws CardException { + + if (exclThread == Thread.currentThread()) { + throw new CardException("Exclusive access already assigned to current thread."); + } else if (exclThread != null) { + throw new CardException("Exclusive access already assigned to another thread."); + } + + exclThread = Thread.currentThread(); + + } + + @Override + public void endExclusive() throws CardException { + + if (exclThread == Thread.currentThread()) { + exclThread = null; + } else if (exclThread == null) { + throw new CardException("Exclusive access has not been assigned."); + } else { + throw new CardException("Exclusive access has not been assigned to current thread."); + } + + } + + @Override + public CardChannel getBasicChannel() { + return channel; + } + + @Override + public void disconnect(boolean reset) throws CardException { + if (reset) { + channel = newCardChannel(this); + } + } + + @Override + public CardChannel openLogicalChannel() throws CardException { + throw new CardException("Logical channels not supported."); + } + + @Override + public String getProtocol() { + return "T1"; + } + + @Override + public byte[] transmitControlCommand(int arg0, byte[] arg1) + throws CardException { + throw new CardException("transmitControlCommand() not supported."); + } + + public AbstractAppl getApplication(byte[] fid) { + + for(AbstractAppl appl : applications) { + if (Arrays.equals(appl.getAID(), fid) || Arrays.equals(appl.getFID(), fid)) { + return appl; + } + } + return null; + + } + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/CardTerminalEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/CardTerminalEmul.java new file mode 100644 index 00000000..b13de62f --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardTerminalEmul.java @@ -0,0 +1,64 @@ +/* +* Copyright 2008 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; + +import javax.smartcardio.Card; +import javax.smartcardio.CardException; +import javax.smartcardio.CardTerminal; + +public class CardTerminalEmul extends CardTerminal { + + private Card card; + + public CardTerminalEmul(Card card) { + this.card = card; + } + + @Override + public Card connect(String protocol) throws CardException { + if ("*".equals(protocol) || "T=1".equals(protocol)) { + return card; + } else { + throw new CardException("Protocol '" + protocol + "' not supported."); + } + } + + @Override + public String getName() { + return "CardTerminal Emulation"; + } + + @Override + public boolean isCardPresent() throws CardException { + return true; + } + + @Override + public boolean waitForCardAbsent(long timeout) throws CardException { + try { + Thread.sleep(timeout); + } catch (InterruptedException e) { + } + return false; + } + + @Override + public boolean waitForCardPresent(long timeout) throws CardException { + return true; + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java new file mode 100644 index 00000000..298e26a5 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java @@ -0,0 +1,298 @@ +/* +* Copyright 2008 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; + +import static org.junit.Assert.*; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.List; + +import javax.smartcardio.Card; + +import org.junit.Test; + +import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.smcc.acos.A04ApplDEC; + +@SuppressWarnings("restriction") +public abstract class CardTest { + + public class TestPINProvider implements PINProvider { + + int provided = 0; + + char[] pin; + + public TestPINProvider(char[] pin) { + super(); + this.pin = pin; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + provided++; + return pin; + } + + public int getProvided() { + return provided; + } + + } + + public class TestChangePINProvider extends TestPINProvider implements + ChangePINProvider { + + char[] oldPin; + + public TestChangePINProvider(char[] oldPin, char[] pin) { + super(pin); + this.oldPin = oldPin; + } + + @Override + public char[] provideOldPIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + return oldPin; + } + + } + + public CardTest() { + super(); + } + + protected abstract SignatureCard createSignatureCard() + throws CardNotSupportedException; + + @Test + public void testGetCard() throws CardNotSupportedException { + SignatureCard signatureCard = createSignatureCard(); + Card card = signatureCard.getCard(); + assertNotNull(card); + } + + @Test + public void testGetInfoboxIdentityLink() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + final char[] pin = "0000".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + + TestPINProvider pinProvider = new TestPINProvider(pin); + + byte[] idlink = signatureCard.getInfobox("IdentityLink", + pinProvider, null); + assertNotNull(idlink); + assertTrue(Arrays.equals(idlink, A04ApplDEC.IDLINK)); + assertEquals(1, pinProvider.provided); + + } + + @Test(expected = CancelledException.class) + public void testSignSIGCancel() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + PINProvider pinProvider = new PINProvider() { + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + throw new CancelledException(); + } + }; + + signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider); + + } + + @Test(expected = CancelledException.class) + public void testSignDECCancel() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + PINProvider pinProvider = new PINProvider() { + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + throw new CancelledException(); + } + }; + + signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, + pinProvider); + + } + + @Test(expected = InterruptedException.class) + public void testSignSIGInterrrupted() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + PINProvider pinProvider = new PINProvider() { + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + throw new InterruptedException(); + } + }; + + signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider); + + } + + @Test(expected = InterruptedException.class) + public void testSignDECInterrrupted() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + PINProvider pinProvider = new PINProvider() { + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + throw new InterruptedException(); + } + }; + + signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, + pinProvider); + + } + + @Test(expected = CancelledException.class) + public void testSignSIGConcurrent() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + final SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + PINProvider pinProvider = new PINProvider() { + @Override + public char[] providePIN(PINSpec 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(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider); + + } + + @Test(expected = CancelledException.class) + public void testSignDECConcurrent() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + final SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + PINProvider pinProvider = new PINProvider() { + @Override + public char[] providePIN(PINSpec 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(hash, KeyboxName.CERITIFIED_KEYPAIR, + pinProvider); + + } + + @Test + public void testGetPinSpecs() throws CardNotSupportedException { + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard(); + + List specs = signatureCard.getPINSpecs(); + assertNotNull(specs); + assertTrue(specs.size() > 0); + + } + + @Test(expected = SignatureCardException.class) + public void testActivatePin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard(); + + PINProvider pinProvider = new PINProvider() { + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + throw new CancelledException(); + } + }; + + List specs = signatureCard.getPINSpecs(); + + signatureCard.activatePIN(specs.get(0), pinProvider); + } + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/CardTestSuite.java b/smcc/src/test/java/at/gv/egiz/smcc/CardTestSuite.java new file mode 100644 index 00000000..3c275a8d --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardTestSuite.java @@ -0,0 +1,29 @@ +/* +* Copyright 2008 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; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +import at.gv.egiz.smcc.acos.ACOSCardTestSuite; + +@RunWith(Suite.class) +@SuiteClasses( { ACOSCardTestSuite.class, at.gv.egiz.smcc.starcos.STARCOSCardTest.class }) +public class CardTestSuite { + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/File.java b/smcc/src/test/java/at/gv/egiz/smcc/File.java new file mode 100644 index 00000000..e47c5f7d --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/File.java @@ -0,0 +1,38 @@ +/* +* Copyright 2008 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; + +public class File { + public byte[] fid; + public byte[] file; + public byte[] fcx; + public int kid = -1; + + public File(byte[] fid, byte[] file, byte[] fcx) { + this.fid = fid; + this.file = file; + this.fcx = fcx; + } + + public File(byte[] fid, byte[] file, byte[] fcx, int kid) { + this.fid = fid; + this.file = file; + this.fcx = fcx; + this.kid = kid; + } + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/PIN.java b/smcc/src/test/java/at/gv/egiz/smcc/PIN.java new file mode 100644 index 00000000..ae883727 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/PIN.java @@ -0,0 +1,41 @@ +/* +* Copyright 2008 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; + +public class PIN { + + public static final int STATE_RESET = 0; + + public static final int STATE_PIN_VERIFIED = 1; + + public static final int STATE_PIN_BLOCKED = -1; + + public byte[] pin; + + public int kid; + + public int state = STATE_RESET; + + public int kfpc = 10; + + public PIN(byte[] pin, int kid, int kfpc) { + this.pin = pin; + this.kid = kid; + this.kfpc = kfpc; + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java deleted file mode 100644 index 9be8db00..00000000 --- a/smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package at.gv.egiz.smcc; - -import at.gv.egiz.smcc.SignatureCard.KeyboxName; -import at.gv.egiz.smcc.util.SMCCHelper; -import java.util.List; -import java.util.Locale; -import javax.smartcardio.ResponseAPDU; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author clemens - */ -@Ignore -public class STARCOSCardTest { - - static STARCOSCard card; - static PINSpec cardPin, ssPin; - - public STARCOSCardTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - SMCCHelper smccHelper = new SMCCHelper(); - switch (smccHelper.getResultCode()) { - case SMCCHelper.CARD_FOUND: - SignatureCard sigCard = smccHelper.getSignatureCard(Locale.GERMAN); - if (sigCard instanceof STARCOSCard) { - System.out.println("STARCOS card found"); - card = (STARCOSCard) sigCard; - List pinSpecs = card.getPINSpecs(); - cardPin = pinSpecs.get(STARCOSCard.PINSPEC_CARD); - ssPin = pinSpecs.get(STARCOSCard.PINSPEC_SS); - - } else { - throw new Exception("not STARCOS card: " + sigCard.toString()); - } - break; - default: - throw new Exception("no card found"); - } - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of getCertificate method, of class STARCOSCard. - */ - @Test - @Ignore - public void testGetCertificate() throws Exception { - System.out.println("getCertificate"); - KeyboxName keyboxName = null; - STARCOSCard instance = new STARCOSCard(); - byte[] expResult = null; - byte[] result = instance.getCertificate(keyboxName); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of getInfobox method, of class STARCOSCard. - */ - @Test - @Ignore - public void testGetInfobox() throws Exception { - System.out.println("getInfobox"); - String infobox = ""; - PINProvider provider = null; - String domainId = ""; - STARCOSCard instance = new STARCOSCard(); - byte[] expResult = null; - byte[] result = instance.getInfobox(infobox, provider, domainId); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of createSignature method, of class STARCOSCard. - */ - @Test - @Ignore - public void testCreateSignature() throws Exception { - System.out.println("createSignature"); - byte[] hash = null; - KeyboxName keyboxName = null; - PINProvider provider = null; - STARCOSCard instance = new STARCOSCard(); - byte[] expResult = null; - byte[] result = instance.createSignature(hash, keyboxName, provider); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of selectFileFID method, of class STARCOSCard. - */ - @Test - @Ignore - public void testSelectFileFID() throws Exception { - System.out.println("selectFileFID"); - byte[] fid = null; - STARCOSCard instance = new STARCOSCard(); - ResponseAPDU expResult = null; - ResponseAPDU result = instance.selectFileFID(fid); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of verifyPIN method, of class STARCOSCard. - */ - @Test - @Ignore - public void testVerifyPIN_pinpad() throws Exception { - System.out.println("verifyPIN (pinpad)"); - assertNotNull(card); - - card.verifyPIN(cardPin, new PINProvider() { - - @Override - public char[] providePIN(PINSpec spec, int retries) { - return null; - } - }); - } - - /** - * Test of verifyPIN method, of class STARCOSCard. - */ - @Test - @Ignore - public void testVerifyPIN_internal() throws Exception { - System.out.println("verifyPIN (internal)"); - assertNotNull(card); - - card.reset(); - - card.getCard().beginExclusive(); - - // 0x6700 without sending an APDU prior to send CtrlCmd - System.out.println("WARNING: this command will fail if no card " + - "communication took place prior to sending the CtrlCommand"); - int retries = card.verifyPIN(cardPin.getKID(), null); //"1397".toCharArray()); - - System.out.println("VERIFY PIN returned " + retries); - card.getCard().endExclusive(); - } - - /** - * Test of verifyPIN method, of class STARCOSCard. - */ - @Test - @Ignore - public void testVerifyPIN_byte() throws Exception { - System.out.println("verifyPIN"); - byte kid = 0; - STARCOSCard instance = new STARCOSCard(); - int expResult = 0; - int result = instance.verifyPIN(kid); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of changePIN method, of class STARCOSCard. - */ - @Test - @Ignore - public void testChangePIN() throws Exception { - System.out.println("changePIN"); - assertNotNull(card); - - card.reset(); - int retries = card.changePIN(cardPin.getKID(), null, null); - - System.out.println("CHANGE PIN returned " + retries); - } - - /** - * Test of activatePIN method, of class STARCOSCard. - */ - @Test - @Ignore - public void testActivatePIN() throws Exception { - System.out.println("activatePIN"); - assertNotNull(card); - - card.reset(); - card.activatePIN(cardPin, new PINProvider() { - - @Override - public char[] providePIN(PINSpec spec, int retries) throws CancelledException, InterruptedException { - return null; - } - }); - } - - /** - * Test of encodePINBlock method, of class STARCOSCard. - */ - @Test - @Ignore - public void testEncodePINBlock() throws Exception { - System.out.println("encodePINBlock"); - char[] pin = null; - STARCOSCard instance = new STARCOSCard(); - byte[] expResult = null; - byte[] result = instance.encodePINBlock(pin); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of reset method, of class STARCOSCard. - */ - @Test - public void testReset() throws Exception { - System.out.println("reset"); - assertNotNull(card); - card.reset(); - } - - /** - * Test of toString method, of class STARCOSCard. - */ - @Test - @Ignore - public void testToString() { - System.out.println("toString"); - STARCOSCard instance = new STARCOSCard(); - String expResult = ""; - String result = instance.toString(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - -} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/TransparentFileInputStreamTest.java b/smcc/src/test/java/at/gv/egiz/smcc/TransparentFileInputStreamTest.java new file mode 100644 index 00000000..4ae48335 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/TransparentFileInputStreamTest.java @@ -0,0 +1,208 @@ +/* +* Copyright 2008 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; + +import java.io.IOException; + +import org.junit.BeforeClass; +import org.junit.Test; + +import at.gv.egiz.smcc.util.TransparentFileInputStream; +import static org.junit.Assert.*; + +public class TransparentFileInputStreamTest { + + public class TestTransparentFileInputStream extends TransparentFileInputStream { + + private byte[] data; + + public TestTransparentFileInputStream(byte[] data) { + this.data = data; + } + + @Override + protected byte[] readBinary(int offset, int len) throws IOException { + int l = Math.min(len, data.length - offset); + byte[] b = new byte[l]; + System.arraycopy(data, offset, b, 0, l); + return b; + } + + } + + protected static byte[] file; + + protected static byte[] file_bs; + + @BeforeClass + public static void setUpClass() { + + byte b = 0x00; + file = new byte[1000]; + for (int i = 0; i < file.length; i++) { + file[i] = b++; + } + + file_bs = new byte[256]; + b = 0x00; + for (int i = 0; i < file_bs.length; i++) { + file_bs[i] = b++; + } + + } + + @Test + public void testReadSeq() throws IOException { + + TransparentFileInputStream is = new TestTransparentFileInputStream(file); + int i = 0; + int b; + while ((b = is.read()) != -1) { + assertEquals(0xFF & i++, b); + } + assertEquals(file.length, i); + + } + + @Test + public void testReadBlock() throws IOException { + + TransparentFileInputStream is = new TestTransparentFileInputStream(file); + int i = 0; + byte[] b = new byte[28]; + int l; + while ((l = is.read(b)) != -1) { + for(int j = 0; j < l; j++) { + assertEquals(0xFF & i++, 0xFF & b[j]); + } + } + assertEquals(file.length, i); + + } + + @Test + public void testReadBlockBS() throws IOException { + + TransparentFileInputStream is = new TestTransparentFileInputStream(file_bs); + int i = 0; + byte[] b = new byte[28]; + int l; + while ((l = is.read(b)) != -1) { + for(int j = 0; j < l; j++) { + assertEquals(0xFF & i++, 0xFF & b[j]); + } + } + assertEquals(file_bs.length, i); + + } + + @Test(expected = IOException.class) + public void testReset() throws IOException { + + TransparentFileInputStream is = new TestTransparentFileInputStream(file); + is.read(new byte[128]); + is.reset(); + + } + + @Test + public void testMark() throws IOException { + + TransparentFileInputStream is = new TestTransparentFileInputStream(file); + int i = 0; + is.mark(12); + byte[] b = new byte[37]; + int l; + while ((l = is.read(b)) != -1) { + for(int j = 0; j < l; j++) { + assertEquals(0xFF & i++, 0xFF & b[j]); + } + } + assertEquals(file.length, i); + + } + + @Test + public void testMarkReset() throws IOException { + + TransparentFileInputStream is = new TestTransparentFileInputStream(file); + int i = 128; + is.read(new byte[i]); + is.mark(512); + byte[] b = new byte[256]; + is.read(b); + for(int j = 0; j < b.length; j++) { + assertEquals(0xFF & i + j, 0xFF & b[j]); + } + is.reset(); + int l; + while ((l = is.read(b)) != -1) { + for(int j = 0; j < l; j++) { + assertEquals(0xFF & i++, 0xFF & b[j]); + } + } + assertEquals(file.length, i); + + } + + + @Test(expected = IOException.class) + public void testMarkResetLimit() throws IOException { + + TransparentFileInputStream is = new TestTransparentFileInputStream(file); + int i = 128; + is.read(new byte[i]); + is.mark(128); + byte[] b = new byte[256]; + is.read(b); + for(int j = 0; j < b.length; j++) { + assertEquals(0xFF & i + j, 0xFF & b[j]); + } + is.reset(); + + } + + @Test + public void testSkipSmall() throws IOException { + + TransparentFileInputStream is = new TestTransparentFileInputStream(file); + int i = 0; + i+= is.read(new byte[128]); + i+= is.skip(3); + byte[] b = new byte[256]; + int l = is.read(b); + for (int j = 0; j < l; j++) { + assertEquals(0xFF & i + j, 0xFF & b[j]); + } + + } + @Test + public void testSkipBig() throws IOException { + + TransparentFileInputStream is = new TestTransparentFileInputStream(file); + int i = 0; + i+= is.read(new byte[128]); + i+= is.skip(300); + byte[] b = new byte[256]; + int l = is.read(b); + for (int j = 0; j < l; j++) { + assertEquals(0xFF & i + j, 0xFF & b[j]); + } + + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java new file mode 100644 index 00000000..9fd96d73 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java @@ -0,0 +1,151 @@ +/* +* Copyright 2008 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.acos; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.Random; + +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.File; +import at.gv.egiz.smcc.PIN; + + +@SuppressWarnings("restriction") +public class A03ApplDEC extends ACOSApplDEC { + + public static final int KID_PIN_INF = 0x83; + + public A03ApplDEC() { + super(); + + System.arraycopy(IDLINK, 0, EF_INFOBOX, 0, IDLINK.length); + putFile(new File(FID_EF_INFOBOX, EF_INFOBOX, FCI_EF_INFOBOX, KID_PIN_INF)); + + try { + pins.put(KID_PIN_INF, new PIN("0000\0\0\0\0".getBytes("ASCII"), KID_PIN_INF, 10)); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + + @Override + public ResponseAPDU cmdMANAGE_SECURITY_ENVIRONMENT(CommandAPDU command, CardChannelEmul channel) { + + checkINS(command, 0x22); + + switch (command.getP2()) { + case 0xA4: + switch (command.getP1()) { + case 0x41: { + // INTERNAL AUTHENTICATE + byte[] dst = new byte[] { (byte) 0x84, (byte) 0x01, (byte) 0x88, (byte) 0x80, (byte) 0x01, (byte) 0x01 }; + if (Arrays.equals(dst, command.getData())) { + securityEnv = command.getData(); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + } + case 0x81: + // EXTERNAL AUTHENTICATE + } + case 0xB6: + switch (command.getP1()) { + case 0x41: + // PSO - COMPUTE DIGITAL SIGNATURE + case 0x81: + // PSO - VERIFY DGITAL SIGNATURE + } + case 0xB8: + switch (command.getP1()) { + case 0x41: + // PSO � DECIPHER + case 0x81: + // PSO � ENCIPHER + } + default: + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + } + + @Override + public ResponseAPDU cmdPERFORM_SECURITY_OPERATION(CommandAPDU command, CardChannelEmul channel) { + + checkINS(command, 0x2A); + + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x00}); + + } + + @Override + public ResponseAPDU cmdINTERNAL_AUTHENTICATE(CommandAPDU command, CardChannelEmul channel) { + + checkINS(command, 0x88); + + if (command.getP1() == 0x10 && command.getP2() == 0x00) { + + byte[] data = command.getData(); + + if (securityEnv == null) { + // Security Environment not set or wrong + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + + byte[] digestInfo = new byte[] { + (byte) 0x30, (byte) 0x21, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x05, (byte) 0x2B, (byte) 0x0E, + (byte) 0x03, (byte) 0x02, (byte) 0x1A, (byte) 0x05, (byte) 0x00, (byte) 0x04, (byte) 0x14 + }; + + if (data.length != 35 || !Arrays.equals(digestInfo, Arrays.copyOf(data, 15))) { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + + if (pins.get(KID_PIN_DEC).state != PIN.STATE_PIN_VERIFIED) { + // Security Status not satisfied + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x82}); + } + + byte[] signature = new byte[48]; + + // TODO replace by signature creation + Random random = new Random(); + random.nextBytes(signature); + + byte[] response = new byte[signature.length + 2]; + System.arraycopy(signature, 0, response, 0, signature.length); + response[signature.length] = (byte) 0x90; + response[signature.length + 1] = (byte) 0x00; + + hash = null; + pins.get(KID_PIN_DEC).state = PIN.STATE_RESET; + + return new ResponseAPDU(response); + + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplSIG.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplSIG.java new file mode 100644 index 00000000..d059ad57 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplSIG.java @@ -0,0 +1,77 @@ +/* +* Copyright 2008 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.acos; + +import java.util.Arrays; + +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardChannelEmul; + + +@SuppressWarnings("restriction") +public class A03ApplSIG extends ACOSApplSIG { + + public A03ApplSIG() { + super(); + System.arraycopy(C_CH_DS, 0, EF_C_CH_DS, 0, C_CH_DS.length); + } + + @Override + public ResponseAPDU cmdMANAGE_SECURITY_ENVIRONMENT(CommandAPDU command, CardChannelEmul channel) { + + checkINS(command, 0x22); + + switch (command.getP2()) { + case 0xA4: + switch (command.getP1()) { + case 0x41: + // INTERNAL AUTHENTICATE + case 0x81: + // EXTERNAL AUTHENTICATE + } + case 0xB6: + switch (command.getP1()) { + case 0x41: { + // PSO - COMPUTE DIGITAL SIGNATURE + byte[] dst = new byte[] { (byte) 0x84, (byte) 0x01, (byte) 0x88, (byte) 0x80, (byte) 0x01, (byte) 0x14 }; + if (Arrays.equals(dst, command.getData())) { + securityEnv = command.getData(); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + } + case 0x81: + // PSO - VERIFY DGITAL SIGNATURE + } + case 0xB8: + switch (command.getP1()) { + case 0x41: + // PSO � DECIPHER + case 0x81: + // PSO � ENCIPHER + } + default: + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardChannelEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardChannelEmul.java new file mode 100644 index 00000000..c8d5382c --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardChannelEmul.java @@ -0,0 +1,98 @@ +/* +* Copyright 2008 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.acos; + + +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardEmul; +import at.gv.egiz.smcc.PIN; + + +@SuppressWarnings("restriction") +public class A03CardChannelEmul extends ACOSCardChannelEmul { + + public A03CardChannelEmul(CardEmul cardEmul) { + super(cardEmul); + } + + @Override + public ResponseAPDU cmdREAD_BINARY(CommandAPDU command) throws CardException { + + if (command.getINS() != 0xB0) { + throw new IllegalArgumentException("INS has to be 0xB0."); + } + + if (currentFile == null) { + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x86}); + } + + if ((command.getP1() & 0x80) > 0) { + throw new CardException("Not implemented."); + } + + int offset = command.getP2() + (command.getP1() << 8); + if (offset > currentFile.file.length) { + // Wrong length + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + if (command.getNe() == 0) { + throw new CardException("Not implemented."); + } + + if (currentFile.kid != -1) { + if ((currentFile.kid & 0x80) > 0) { + PIN pin; + if (currentAppl == null + || (pin = currentAppl.pins.get(currentFile.kid)) == null + || pin.state != PIN.STATE_PIN_VERIFIED) { + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x82}); + } + } else { + // Global PINs not implemented + throw new CardException("Not implemented."); + } + } + + int len; + if (command.getNe() == 256) { + if (currentFile.file.length > 256) { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } else { + len = Math.min(command.getNe(), currentFile.file.length - offset); + } + } else { + if (command.getNe() >= currentFile.file.length - offset) { + return new ResponseAPDU(new byte[] {(byte) 0x62, (byte) 0x82}); + } else { + len = command.getNe(); + } + } + + byte[] response = new byte[len + 2]; + System.arraycopy(currentFile.file, offset, response, 0, len); + response[len] = (byte) 0x90; + response[len + 1] = (byte) 0x00; + return new ResponseAPDU(response); + + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardEmul.java new file mode 100644 index 00000000..58216b6b --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardEmul.java @@ -0,0 +1,36 @@ +/* +* Copyright 2008 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.acos; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.CardEmul; + + + +public class A03CardEmul extends ACOSCardEmul { + + public A03CardEmul(A03ApplSIG applSIG, A03ApplDEC applDEC) { + applications.add(applSIG); + applications.add(applDEC); + } + + @Override + protected CardChannelEmul newCardChannel(CardEmul cardEmul) { + return new A03CardChannelEmul(this); + } + +} 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 new file mode 100644 index 00000000..776c0370 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardTest.java @@ -0,0 +1,91 @@ +/* +* Copyright 2008 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.acos; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; + +import at.gv.egiz.smcc.ACOSCard; +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.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.SignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.SignatureCardFactory; + +public class A03CardTest extends ACOSCardTest { + + @Override + protected SignatureCard createSignatureCard() + throws CardNotSupportedException { + SignatureCardFactory factory = SignatureCardFactory.getInstance(); + CardEmul card = new A03CardEmul(new A03ApplSIG(), new A03ApplDEC()); + SignatureCard signatureCard = factory.createSignatureCard(card, + new CardTerminalEmul(card)); + assertTrue(signatureCard instanceof PINMgmtSignatureCard); + return signatureCard; + } + + @Override + protected int getVersion() { + return 1; + } + + @Test + public void testChangePin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { + + char[] defaultPin = "123456".toCharArray(); + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplSIG applSIG = (ACOSApplSIG) card.getApplication(ACOSAppl.AID_SIG); + applSIG.setPin(ACOSApplSIG.KID_PIN_SIG, defaultPin); + ACOSApplDEC applDEC = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); + applDEC.setPin(ACOSApplDEC.KID_PIN_DEC, defaultPin); + applDEC.setPin(A03ApplDEC.KID_PIN_INF, defaultPin); + + for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + + char[] pin = defaultPin; + + for (int i = pinSpec.getMinLength(); i <= pinSpec.getMaxLength(); i++) { + signatureCard.verifyPIN(pinSpec, new TestPINProvider(pin)); + char[] newPin = new char[i]; + Arrays.fill(newPin, '0'); + signatureCard + .changePIN(pinSpec, new TestChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinSpec, new TestPINProvider(newPin)); + pin = newPin; + } + + } + + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A04ApplDEC.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04ApplDEC.java new file mode 100644 index 00000000..e38a8e80 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04ApplDEC.java @@ -0,0 +1,296 @@ +/* +* Copyright 2008 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.acos; + +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Signature; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.util.Arrays; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.File; +import at.gv.egiz.smcc.PIN; + + +@SuppressWarnings("restriction") +public class A04ApplDEC extends ACOSApplDEC { + + private static final byte[] SEC_ENV_INTERNAL_AUTHENTICATE = new byte[] { (byte) 0x84, + (byte) 0x01, (byte) 0x88, (byte) 0x80, (byte) 0x01, (byte) 0x01 }; + + private static final byte[] SEC_ENV_DECIPHER = new byte[] { (byte) 0x84, + (byte) 0x01, (byte) 0x88, (byte) 0x80, (byte) 0x01, (byte) 0x02 }; + + private static final RSAPrivateKey SK_CH_EKEY; + + private static final RSAPublicKey PK_CH_EKEY; + + static { + try { + KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA"); + gen.initialize(1536); + KeyPair keyPair = gen.generateKeyPair(); + SK_CH_EKEY = (RSAPrivateKey) keyPair.getPrivate(); + PK_CH_EKEY = (RSAPublicKey) keyPair.getPublic(); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } + + public A04ApplDEC() { + this(false); + } + + public A04ApplDEC(boolean encrypt) { + + int offset = 0; + + // HEADER 'AIK' + version + byte[] header; + try { + header = "AIK".getBytes("ASCII"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + System.arraycopy(header, 0, EF_INFOBOX, offset, header.length); + offset += header.length; + EF_INFOBOX[offset++] = 1; + + // HEADER identity link + EF_INFOBOX[offset++] = (byte) 0x01; // Personenbindung + if (encrypt) { + EF_INFOBOX[offset++] = (byte) 0x01; // Modifier + + byte[] cipherText; + byte[] encKey; + try { + KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede"); + SecretKey secretKey = keyGenerator.generateKey(); + + byte[] keyBytes = secretKey.getEncoded(); + + Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); + byte[] iv = new byte[8]; + Arrays.fill(iv, (byte) 0x00); + IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); + cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivParameterSpec); + cipherText = cipher.doFinal(IDLINK); + + cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.ENCRYPT_MODE, PK_CH_EKEY); + encKey = cipher.doFinal(keyBytes); + + } catch (GeneralSecurityException e) { + throw new RuntimeException(e); + } + + int len = encKey.length + cipherText.length + 2; + + EF_INFOBOX[offset++] = (byte) (0xFF & len); + EF_INFOBOX[offset++] = (byte) (0xFF & len >> 8); + + EF_INFOBOX[offset++] = (byte) (0xFF & encKey.length); + EF_INFOBOX[offset++] = (byte) (0xFF & encKey.length >> 8); + + System.arraycopy(encKey, 0, EF_INFOBOX, offset, encKey.length); + offset += encKey.length; + + System.arraycopy(cipherText, 0, EF_INFOBOX, offset, cipherText.length); + + } else { + EF_INFOBOX[offset++] = (byte) 0x00; // Modifier + EF_INFOBOX[offset++] = (byte) (0xFF & IDLINK.length); + EF_INFOBOX[offset++] = (byte) (0xFF & IDLINK.length >> 8); + System.arraycopy(IDLINK, 0, EF_INFOBOX, offset, IDLINK.length); + offset += IDLINK.length; + } + + putFile(new File(FID_EF_INFOBOX, EF_INFOBOX, FCI_EF_INFOBOX)); + } + + @Override + public ResponseAPDU cmdMANAGE_SECURITY_ENVIRONMENT(CommandAPDU command, CardChannelEmul channel) { + + checkINS(command, 0x22); + + switch (command.getP2()) { + case 0xA4: + switch (command.getP1()) { + case 0x41: { + // INTERNAL AUTHENTICATE + if (Arrays.equals(SEC_ENV_INTERNAL_AUTHENTICATE, command.getData())) { + securityEnv = command.getData(); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x85}); + } + } + case 0x81: + // EXTERNAL AUTHENTICATE + } + case 0xB6: + switch (command.getP1()) { + case 0x41: + // PSO - COMPUTE DIGITAL SIGNATURE + case 0x81: + // PSO - VERIFY DGITAL SIGNATURE + } + case 0xB8: + switch (command.getP1()) { + case 0x41: + // PSO � DECIPHER + if (Arrays.equals(SEC_ENV_DECIPHER, command.getData())) { + securityEnv = command.getData(); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x85}); + } + case 0x81: + // PSO � ENCIPHER + } + default: + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + } + + @Override + public ResponseAPDU cmdPERFORM_SECURITY_OPERATION(CommandAPDU command, CardChannelEmul channel) throws CardException { + + checkINS(command, 0x2A); + + if (command.getP1() == 0x80 && command.getP2() == 0x86) { + + byte[] data = command.getData(); + + if (!Arrays.equals(securityEnv, SEC_ENV_DECIPHER)) { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + + if (data.length != 193) { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + if (pins.get(KID_PIN_DEC).state != PIN.STATE_PIN_VERIFIED) { + // Security Status not satisfied + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x82}); + } + + byte[] cipherText = Arrays.copyOfRange(data, 1, data.length); + + byte[] plainText; + try { + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.DECRYPT_MODE, SK_CH_EKEY); + plainText = cipher.doFinal(cipherText); + } catch (GeneralSecurityException e) { + throw new CardException(e); + } + + byte[] response = new byte[plainText.length + 2]; + System.arraycopy(plainText, 0, response, 0, plainText.length); + response[plainText.length] = (byte) 0x90; + response[plainText.length + 1] = (byte) 0x00; + + return new ResponseAPDU(response); + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x00}); + } + + } + + @Override + public ResponseAPDU cmdINTERNAL_AUTHENTICATE(CommandAPDU command, CardChannelEmul channel) throws CardException { + + checkINS(command, 0x88); + + if (command.getP1() == 0x10 && command.getP2() == 0x00) { + + byte[] data = command.getData(); + + if (!Arrays.equals(securityEnv, SEC_ENV_INTERNAL_AUTHENTICATE)) { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + + byte[] digestInfo = new byte[] { + (byte) 0x30, (byte) 0x21, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x05, (byte) 0x2B, (byte) 0x0E, + (byte) 0x03, (byte) 0x02, (byte) 0x1A, (byte) 0x05, (byte) 0x00, (byte) 0x04, (byte) 0x14 + }; + + if (data.length != 35 || !Arrays.equals(digestInfo, Arrays.copyOf(data, 15))) { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + + if (pins.get(KID_PIN_DEC).state != PIN.STATE_PIN_VERIFIED) { + // Security Status not satisfied + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x82}); + } + + byte[] digest = Arrays.copyOfRange(data, 15, 35); + + byte[] sig; + try { + Signature signature = Signature.getInstance("RSA"); + signature.initSign(SK_CH_EKEY); + signature.update(digest); + sig = signature.sign(); + } catch (GeneralSecurityException e) { + throw new CardException(e); + } + + byte[] response = new byte[sig.length + 2]; + System.arraycopy(sig, 0, response, 0, sig.length); + response[sig.length] = (byte) 0x90; + response[sig.length + 1] = (byte) 0x00; + + hash = null; + pins.get(KID_PIN_DEC).state = PIN.STATE_RESET; + + return new ResponseAPDU(response); + + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A04ApplSIG.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04ApplSIG.java new file mode 100644 index 00000000..aee6a7f7 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04ApplSIG.java @@ -0,0 +1,87 @@ +/* +* Copyright 2008 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.acos; + +import java.util.Arrays; + +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.File; + + +@SuppressWarnings("restriction") +public class A04ApplSIG extends ACOSApplSIG { + + private static byte[] FID_EF_INFO = new byte[] { (byte) 0xd0, (byte) 0x02 }; + + private static byte[] FCI_EF_INFO = new byte[] { (byte) 0x6f, (byte) 0x07, + (byte) 0x80, (byte) 0x02, (byte) 0x00, (byte) 0x08, (byte) 0x82, + (byte) 0x01, (byte) 0x01 }; + + private static byte[] EF_INFO = new byte[] { (byte) 0x02, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x90, (byte) 0x00 }; + + public A04ApplSIG() { + putFile(new File(FID_EF_INFO, EF_INFO, FCI_EF_INFO)); + } + + @Override + public ResponseAPDU cmdMANAGE_SECURITY_ENVIRONMENT(CommandAPDU command, CardChannelEmul channel) { + + checkINS(command, 0x22); + + switch (command.getP2()) { + case 0xA4: + switch (command.getP1()) { + case 0x41: + // INTERNAL AUTHENTICATE + case 0x81: + // EXTERNAL AUTHENTICATE + } + case 0xB6: + switch (command.getP1()) { + case 0x41: { + // PSO - COMPUTE DIGITAL SIGNATURE + byte[] dst = new byte[] { (byte) 0x84, (byte) 0x01, (byte) 0x88, (byte) 0x80, (byte) 0x01, (byte) 0x14 }; + if (Arrays.equals(dst, command.getData())) { + securityEnv = command.getData(); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + } + case 0x81: + // PSO - VERIFY DGITAL SIGNATURE + } + case 0xB8: + switch (command.getP1()) { + case 0x41: + // PSO � DECIPHER + case 0x81: + // PSO � ENCIPHER + } + default: + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardChannelEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardChannelEmul.java new file mode 100644 index 00000000..3eaece91 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardChannelEmul.java @@ -0,0 +1,75 @@ +/* +* Copyright 2008 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.acos; + + +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardEmul; + + +@SuppressWarnings("restriction") +public class A04CardChannelEmul extends ACOSCardChannelEmul { + + public A04CardChannelEmul(CardEmul cardEmul) { + super(cardEmul); + } + + @Override + public ResponseAPDU cmdREAD_BINARY(CommandAPDU command) throws CardException { + + if (command.getINS() != 0xB0) { + throw new IllegalArgumentException("INS has to be 0xB0."); + } + + if (currentFile == null) { + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x86}); + } + + if ((command.getP1() & 0x80) > 0) { + throw new CardException("Not implemented."); + } + + int offset = command.getP2() + (command.getP1() << 8); + if (offset > currentFile.file.length) { + // Wrong length + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + if (command.getNe() == 0) { + throw new CardException("Not implemented."); + } + + if (command.getNe() == 256 || command.getNe() <= currentFile.file.length - offset) { + int len = Math.min(command.getNe(), currentFile.file.length - offset); + byte[] response = new byte[len + 2]; + System.arraycopy(currentFile.file, offset, response, 0, len); + response[len] = (byte) 0x90; + response[len + 1] = (byte) 0x00; + return new ResponseAPDU(response); + } else if (command.getNe() >= currentFile.file.length - offset) { + return new ResponseAPDU(new byte[] {(byte) 0x62, (byte) 0x82}); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardEmul.java new file mode 100644 index 00000000..70925aa6 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardEmul.java @@ -0,0 +1,37 @@ +/* +* Copyright 2008 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.acos; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.CardEmul; + + + +public class A04CardEmul extends ACOSCardEmul { + + public A04CardEmul(A04ApplSIG applSIG, A04ApplDEC applDEC) { + applications.add(applSIG); + applications.add(applDEC); + } + + @Override + protected CardChannelEmul newCardChannel(CardEmul cardEmul) { + return new A04CardChannelEmul(this); + } + + +} 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 new file mode 100644 index 00000000..d15e80d7 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardTest.java @@ -0,0 +1,143 @@ +/* +* Copyright 2008 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.acos; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import iaik.security.provider.IAIK; + +import java.security.Security; +import java.util.Arrays; + +import org.junit.BeforeClass; +import org.junit.Test; + +import at.gv.egiz.smcc.ACOSCard; +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.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.SignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.SignatureCardFactory; +import at.gv.egiz.smcc.CardTest.TestPINProvider; + +public class A04CardTest extends ACOSCardTest { + + @Override + protected SignatureCard createSignatureCard() + throws CardNotSupportedException { + SignatureCardFactory factory = SignatureCardFactory.getInstance(); + CardEmul card = new A04CardEmul(new A04ApplSIG(), new A04ApplDEC()); + SignatureCard signatureCard = factory.createSignatureCard(card, + new CardTerminalEmul(card)); + assertTrue(signatureCard instanceof PINMgmtSignatureCard); + return signatureCard; + } + + @Override + protected int getVersion() { + return 2; + } + + @BeforeClass + public static void setupClass() { + IAIK.addAsProvider(); + } + + @Test + public void testChangePin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { + + char[] defaultPin = "123456".toCharArray(); + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplSIG applSIG = (ACOSApplSIG) card.getApplication(ACOSAppl.AID_SIG); + applSIG.setPin(ACOSApplSIG.KID_PIN_SIG, defaultPin); + ACOSApplDEC applDEC = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); + applDEC.setPin(ACOSApplDEC.KID_PIN_DEC, defaultPin); + + for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + + char[] pin = defaultPin; + + for (int i = pinSpec.getMinLength(); i <= pinSpec.getMaxLength(); i++) { + char[] newPin = new char[i]; + Arrays.fill(newPin, '0'); + signatureCard + .changePIN(pinSpec, new TestChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinSpec, new TestPINProvider(newPin)); + pin = newPin; + } + + } + + } + + @Test + public void testGetInfoboxIdentityLinkEncrypted() + throws CardNotSupportedException, SignatureCardException, + InterruptedException { + + char[] pin = "0000".toCharArray(); + + SignatureCardFactory factory = SignatureCardFactory.getInstance(); + A04ApplDEC applDEC = new A04ApplDEC(true); + applDEC.setPin(A04ApplDEC.KID_PIN_DEC, pin); + CardEmul card = new A04CardEmul(new A04ApplSIG(), applDEC); + SignatureCard signatureCard = factory.createSignatureCard(card, + new CardTerminalEmul(card)); + + TestPINProvider pinProvider = new TestPINProvider(pin); + + byte[] idlink = signatureCard.getInfobox("IdentityLink", + pinProvider, null); + assertNotNull(idlink); + assertTrue(Arrays.equals(idlink, A04ApplDEC.IDLINK)); + assertEquals(1, pinProvider.getProvided()); + + } + + @Test + public void testGetInfoboxIdentityLink() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + final char[] pin = "0000".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + + TestPINProvider pinProvider = new TestPINProvider(pin); + + byte[] idlink = signatureCard.getInfobox("IdentityLink", + pinProvider, null); + assertNotNull(idlink); + assertTrue(Arrays.equals(idlink, A04ApplDEC.IDLINK)); + assertEquals(0, pinProvider.getProvided()); + + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSAppl.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSAppl.java new file mode 100644 index 00000000..4c340d61 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSAppl.java @@ -0,0 +1,79 @@ +/* +* Copyright 2008 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.acos; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.Iterator; + +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.AbstractAppl; +import at.gv.egiz.smcc.CardAppl; +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.PIN; + +@SuppressWarnings("restriction") +public abstract class ACOSAppl extends AbstractAppl implements CardAppl { + + public static byte[] AID_SIG = new byte[] { (byte) 0xA0, (byte) 0x00, + (byte) 0x00, (byte) 0x01, (byte) 0x18, (byte) 0x45, (byte) 0x43 }; + + public static byte[] FID_SIG = new byte[] { (byte) 0xDF, (byte) 0x70 }; + + public static byte[] AID_DEC = new byte[] { (byte) 0xA0, (byte) 0x00, + (byte) 0x00, (byte) 0x01, (byte) 0x18, (byte) 0x45, (byte) 0x4E }; + + public static byte[] FID_DEC = new byte[] { (byte) 0xDF, (byte) 0x71 }; + + protected byte[] securityEnv; + + protected byte[] hash; + + @Override + public ResponseAPDU cmdINTERNAL_AUTHENTICATE(CommandAPDU command, CardChannelEmul channel) throws CardException { + return new ResponseAPDU(new byte[] {(byte) 0x6D, (byte) 0x00}); + } + + @Override + public void leaveApplContext() { + Iterator pin = pins.values().iterator(); + while (pin.hasNext()) { + pin.next().state = PIN.STATE_RESET; + } + } + + public void setPin(int kid, char[] value) { + try { + PIN pin = pins.get(kid); + if (pin != null) { + if (value == null) { + Arrays.fill(pin.pin, (byte) 0x00); + pin.state = PIN.STATE_PIN_BLOCKED; + } else { + int l = pin.pin.length; + pin.pin = Arrays.copyOf(new String(value).getBytes("ASCII"), l); + } + } + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplDEC.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplDEC.java new file mode 100644 index 00000000..08979536 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplDEC.java @@ -0,0 +1,334 @@ +/* +* Copyright 2008 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.acos; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +import at.gv.egiz.smcc.File; +import at.gv.egiz.smcc.PIN; + +public abstract class ACOSApplDEC extends ACOSAppl { + + public static final byte[] IDLINK = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x11, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x0c, + (byte) 0x26, (byte) 0x68, (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, + (byte) 0x77, (byte) 0x77, (byte) 0x77, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x7a, + (byte) 0x6d, (byte) 0x72, (byte) 0x2f, (byte) 0x70, (byte) 0x65, (byte) 0x72, (byte) 0x73, (byte) 0x62, + (byte) 0x32, (byte) 0x30, (byte) 0x34, (byte) 0x2e, (byte) 0x78, (byte) 0x73, (byte) 0x6c, (byte) 0x0c, + (byte) 0x29, (byte) 0x73, (byte) 0x7a, (byte) 0x72, (byte) 0x2e, (byte) 0x62, (byte) 0x6d, (byte) 0x69, + (byte) 0x2e, (byte) 0x67, (byte) 0x76, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2d, (byte) 0x41, + (byte) 0x73, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, + (byte) 0x49, (byte) 0x44, (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x36, (byte) 0x33, (byte) 0x35, + (byte) 0x36, (byte) 0x33, (byte) 0x36, (byte) 0x36, (byte) 0x37, (byte) 0x39, (byte) 0x39, (byte) 0x39, + (byte) 0x31, (byte) 0x39, (byte) 0x0c, (byte) 0x19, (byte) 0x32, (byte) 0x30, (byte) 0x30, (byte) 0x39, + (byte) 0x2d, (byte) 0x30, (byte) 0x33, (byte) 0x2d, (byte) 0x30, (byte) 0x36, (byte) 0x54, (byte) 0x31, + (byte) 0x36, (byte) 0x3a, (byte) 0x31, (byte) 0x39, (byte) 0x3a, (byte) 0x32, (byte) 0x36, (byte) 0x2b, + (byte) 0x30, (byte) 0x31, (byte) 0x3a, (byte) 0x30, (byte) 0x30, (byte) 0xa0, (byte) 0x42, (byte) 0x30, + (byte) 0x40, (byte) 0x0c, (byte) 0x18, (byte) 0x45, (byte) 0x68, (byte) 0x42, (byte) 0x53, (byte) 0x36, + (byte) 0x54, (byte) 0x6f, (byte) 0x31, (byte) 0x49, (byte) 0x6c, (byte) 0x54, (byte) 0x4b, (byte) 0x4f, + (byte) 0x4a, (byte) 0x45, (byte) 0x39, (byte) 0x75, (byte) 0x62, (byte) 0x74, (byte) 0x48, (byte) 0x69, + (byte) 0x51, (byte) 0x3d, (byte) 0x3d, (byte) 0x0c, (byte) 0x0a, (byte) 0x58, (byte) 0x58, (byte) 0x58, + (byte) 0xc5, (byte) 0x90, (byte) 0x7a, (byte) 0x67, (byte) 0xc3, (byte) 0xbc, (byte) 0x72, (byte) 0x0c, + (byte) 0x0c, (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0x54, (byte) 0xc3, (byte) 0xbc, (byte) 0x7a, + (byte) 0x65, (byte) 0x6b, (byte) 0xc3, (byte) 0xa7, (byte) 0x69, (byte) 0x0c, (byte) 0x0a, (byte) 0x31, + (byte) 0x39, (byte) 0x37, (byte) 0x33, (byte) 0x2d, (byte) 0x30, (byte) 0x36, (byte) 0x2d, (byte) 0x30, + (byte) 0x34, (byte) 0x30, (byte) 0x0a, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x00, + (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x82, (byte) 0x01, + (byte) 0x01, (byte) 0x00, (byte) 0x9f, (byte) 0xa5, (byte) 0x68, (byte) 0xa9, (byte) 0x14, (byte) 0x4c, + (byte) 0xa4, (byte) 0x5d, (byte) 0x9d, (byte) 0x09, (byte) 0x99, (byte) 0x2e, (byte) 0xe7, (byte) 0x45, + (byte) 0x2e, (byte) 0x42, (byte) 0x49, (byte) 0x02, (byte) 0x16, (byte) 0xd9, (byte) 0xcb, (byte) 0x90, + (byte) 0x43, (byte) 0x27, (byte) 0x03, (byte) 0x43, (byte) 0x6d, (byte) 0xb4, (byte) 0x8c, (byte) 0xdc, + (byte) 0x1c, (byte) 0x77, (byte) 0xd4, (byte) 0x2e, (byte) 0xa1, (byte) 0x40, (byte) 0xe7, (byte) 0xe0, + (byte) 0x03, (byte) 0x60, (byte) 0x15, (byte) 0xf7, (byte) 0xdb, (byte) 0x03, (byte) 0x5e, (byte) 0xca, + (byte) 0xe4, (byte) 0x35, (byte) 0xba, (byte) 0x2b, (byte) 0xfd, (byte) 0xe6, (byte) 0xb8, (byte) 0xd8, + (byte) 0xb7, (byte) 0x2a, (byte) 0x80, (byte) 0xdd, (byte) 0x38, (byte) 0xe0, (byte) 0x8a, (byte) 0x69, + (byte) 0xad, (byte) 0x67, (byte) 0x60, (byte) 0x65, (byte) 0x42, (byte) 0xc9, (byte) 0x41, (byte) 0x60, + (byte) 0x94, (byte) 0xde, (byte) 0x84, (byte) 0x54, (byte) 0xad, (byte) 0xb3, (byte) 0xf4, (byte) 0xf7, + (byte) 0x44, (byte) 0xd5, (byte) 0xf3, (byte) 0xd3, (byte) 0xb6, (byte) 0x87, (byte) 0x8a, (byte) 0x22, + (byte) 0x38, (byte) 0x00, (byte) 0xcb, (byte) 0xa4, (byte) 0x4f, (byte) 0x96, (byte) 0xc2, (byte) 0x28, + (byte) 0xc2, (byte) 0x8d, (byte) 0x91, (byte) 0x95, (byte) 0xb4, (byte) 0xea, (byte) 0x00, (byte) 0x59, + (byte) 0x2e, (byte) 0xec, (byte) 0x78, (byte) 0xd8, (byte) 0x0f, (byte) 0x26, (byte) 0x04, (byte) 0xee, + (byte) 0xed, (byte) 0x13, (byte) 0xbf, (byte) 0x81, (byte) 0x68, (byte) 0x81, (byte) 0x43, (byte) 0xbe, + (byte) 0x15, (byte) 0x0e, (byte) 0xba, (byte) 0xf9, (byte) 0x6a, (byte) 0x18, (byte) 0xeb, (byte) 0x95, + (byte) 0xad, (byte) 0xb4, (byte) 0x0f, (byte) 0x3c, (byte) 0x94, (byte) 0x63, (byte) 0x32, (byte) 0x81, + (byte) 0x90, (byte) 0xcf, (byte) 0x3f, (byte) 0x95, (byte) 0xff, (byte) 0x8d, (byte) 0x86, (byte) 0xed, + (byte) 0xe4, (byte) 0x75, (byte) 0xd5, (byte) 0x09, (byte) 0x32, (byte) 0x17, (byte) 0x38, (byte) 0xb2, + (byte) 0x68, (byte) 0x35, (byte) 0x49, (byte) 0x8c, (byte) 0xa6, (byte) 0xd0, (byte) 0x3e, (byte) 0xde, + (byte) 0x6e, (byte) 0x47, (byte) 0x68, (byte) 0xbf, (byte) 0x98, (byte) 0x33, (byte) 0xae, (byte) 0x59, + (byte) 0x9f, (byte) 0xe0, (byte) 0x19, (byte) 0x9b, (byte) 0x5b, (byte) 0x1b, (byte) 0x8f, (byte) 0x74, + (byte) 0xd2, (byte) 0x9c, (byte) 0x01, (byte) 0x1a, (byte) 0xdf, (byte) 0xaf, (byte) 0xf8, (byte) 0x96, + (byte) 0x91, (byte) 0xcb, (byte) 0xf8, (byte) 0xbf, (byte) 0x06, (byte) 0xc7, (byte) 0xd5, (byte) 0x17, + (byte) 0x95, (byte) 0xef, (byte) 0xc5, (byte) 0x97, (byte) 0x37, (byte) 0x1b, (byte) 0xb0, (byte) 0xa1, + (byte) 0x4f, (byte) 0x9f, (byte) 0x01, (byte) 0x82, (byte) 0x90, (byte) 0x4a, (byte) 0x6a, (byte) 0x04, + (byte) 0xdb, (byte) 0x31, (byte) 0x1a, (byte) 0x58, (byte) 0xeb, (byte) 0xcd, (byte) 0x68, (byte) 0xe3, + (byte) 0x68, (byte) 0x0b, (byte) 0xa0, (byte) 0x11, (byte) 0x44, (byte) 0x08, (byte) 0xa0, (byte) 0x5c, + (byte) 0xfc, (byte) 0x61, (byte) 0x15, (byte) 0x1f, (byte) 0xbb, (byte) 0x22, (byte) 0x87, (byte) 0x18, + (byte) 0xa3, (byte) 0x07, (byte) 0x9b, (byte) 0x0d, (byte) 0x13, (byte) 0x7c, (byte) 0xff, (byte) 0x30, + (byte) 0xcf, (byte) 0xf3, (byte) 0xaf, (byte) 0xe4, (byte) 0x45, (byte) 0x05, (byte) 0xa0, (byte) 0x8e, + (byte) 0x6b, (byte) 0xef, (byte) 0x70, (byte) 0xf5, (byte) 0x4b, (byte) 0x68, (byte) 0x8f, (byte) 0x61, + (byte) 0xd6, (byte) 0xf5, (byte) 0xa0, (byte) 0x17, (byte) 0x03, (byte) 0x15, (byte) 0x00, (byte) 0x8e, + (byte) 0xa8, (byte) 0xdf, (byte) 0xa9, (byte) 0x77, (byte) 0xfd, (byte) 0x9b, (byte) 0x4b, (byte) 0x91, + (byte) 0x89, (byte) 0x34, (byte) 0x84, (byte) 0xf3, (byte) 0x24, (byte) 0xb2, (byte) 0x5a, (byte) 0x39, + (byte) 0xa9, (byte) 0xf2, (byte) 0x17, (byte) 0xa1, (byte) 0x17, (byte) 0x03, (byte) 0x15, (byte) 0x00, + (byte) 0xdb, (byte) 0xa2, (byte) 0xfd, (byte) 0xa4, (byte) 0xe7, (byte) 0x65, (byte) 0x2e, (byte) 0x7e, + (byte) 0xb0, (byte) 0xc8, (byte) 0xfa, (byte) 0x4d, (byte) 0x13, (byte) 0x28, (byte) 0xdf, (byte) 0xb1, + (byte) 0x58, (byte) 0x3b, (byte) 0x9e, (byte) 0x29, (byte) 0xa2, (byte) 0x17, (byte) 0x03, (byte) 0x15, + (byte) 0x00, (byte) 0x68, (byte) 0xa0, (byte) 0x17, (byte) 0x18, (byte) 0xb7, (byte) 0xb3, (byte) 0xc3, + (byte) 0x60, (byte) 0x77, (byte) 0x82, (byte) 0x8d, (byte) 0xf1, (byte) 0x5e, (byte) 0x10, (byte) 0xc3, + (byte) 0x2d, (byte) 0x78, (byte) 0x2c, (byte) 0x11, (byte) 0x0b + }; + private static byte[] FCI = new byte[] { (byte) 0x6f, (byte) 0x1a, (byte) 0x84, + (byte) 0x07, (byte) 0xa0, (byte) 0x00, (byte) 0x00, (byte) 0x01, + (byte) 0x18, (byte) 0x4e, (byte) 0x43, (byte) 0x85, (byte) 0x0f, + (byte) 0x50, (byte) 0x0d, (byte) 0x44, (byte) 0x49, (byte) 0x47, + (byte) 0x53, (byte) 0x49, (byte) 0x47, (byte) 0x20, (byte) 0x43, + (byte) 0x43, (byte) 0x20, (byte) 0x45, (byte) 0x4e, (byte) 0x43 }; + protected static byte[] FID_EF_C_CH_EKEY = new byte[] { (byte) 0xc0, (byte) 0x01 }; + protected static byte[] FCI_EF_C_CH_EKEY = new byte[] { (byte) 0x6f, (byte) 0x07, + (byte) 0x80, (byte) 0x02, (byte) 0x07, (byte) 0xd0, (byte) 0x82, + (byte) 0x01, (byte) 0x01}; + protected static byte[] C_CH_EKEY = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x05, (byte) 0x7f, (byte) 0x30, (byte) 0x82, (byte) 0x04, (byte) 0x67, + (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x02, + (byte) 0x05, (byte) 0x51, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, + (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05, + (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0xa1, (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, + (byte) 0x54, (byte) 0x31, (byte) 0x48, (byte) 0x30, (byte) 0x46, (byte) 0x06, (byte) 0x03, (byte) 0x55, + (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x3f, (byte) 0x41, (byte) 0x2d, (byte) 0x54, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x47, (byte) 0x65, (byte) 0x73, (byte) 0x2e, + (byte) 0x20, (byte) 0x66, (byte) 0x2e, (byte) 0x20, (byte) 0x53, (byte) 0x69, (byte) 0x63, (byte) 0x68, + (byte) 0x65, (byte) 0x72, (byte) 0x68, (byte) 0x65, (byte) 0x69, (byte) 0x74, (byte) 0x73, (byte) 0x73, + (byte) 0x79, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6d, (byte) 0x65, (byte) 0x20, (byte) 0x69, + (byte) 0x6d, (byte) 0x20, (byte) 0x65, (byte) 0x6c, (byte) 0x65, (byte) 0x6b, (byte) 0x74, (byte) 0x72, + (byte) 0x2e, (byte) 0x20, (byte) 0x44, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x6e, (byte) 0x76, + (byte) 0x65, (byte) 0x72, (byte) 0x6b, (byte) 0x65, (byte) 0x68, (byte) 0x72, (byte) 0x20, (byte) 0x47, + (byte) 0x6d, (byte) 0x62, (byte) 0x48, (byte) 0x31, (byte) 0x23, (byte) 0x30, (byte) 0x21, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0b, (byte) 0x0c, (byte) 0x1a, (byte) 0x61, (byte) 0x2d, + (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, (byte) 0x65, + (byte) 0x6d, (byte) 0x69, (byte) 0x75, (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, + (byte) 0x74, (byte) 0x2d, (byte) 0x45, (byte) 0x6e, (byte) 0x63, (byte) 0x2d, (byte) 0x30, (byte) 0x32, + (byte) 0x31, (byte) 0x23, (byte) 0x30, (byte) 0x21, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, + (byte) 0x03, (byte) 0x0c, (byte) 0x1a, (byte) 0x61, (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, + (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, (byte) 0x65, (byte) 0x6d, (byte) 0x69, (byte) 0x75, + (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x45, + (byte) 0x6e, (byte) 0x63, (byte) 0x2d, (byte) 0x30, (byte) 0x32, (byte) 0x30, (byte) 0x1e, (byte) 0x17, + (byte) 0x0d, (byte) 0x30, (byte) 0x39, (byte) 0x30, (byte) 0x31, (byte) 0x31, (byte) 0x33, (byte) 0x30, + (byte) 0x39, (byte) 0x34, (byte) 0x35, (byte) 0x31, (byte) 0x32, (byte) 0x5a, (byte) 0x17, (byte) 0x0d, + (byte) 0x31, (byte) 0x32, (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x31, (byte) 0x30, (byte) 0x39, + (byte) 0x34, (byte) 0x35, (byte) 0x31, (byte) 0x32, (byte) 0x5a, (byte) 0x30, (byte) 0x70, (byte) 0x31, + (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, + (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x54, (byte) 0x31, (byte) 0x1f, (byte) 0x30, (byte) 0x1d, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c, (byte) 0x16, (byte) 0x58, + (byte) 0x58, (byte) 0x58, (byte) 0x4f, (byte) 0x74, (byte) 0x74, (byte) 0x6f, (byte) 0x20, (byte) 0x58, + (byte) 0x58, (byte) 0x58, (byte) 0x4f, (byte) 0x74, (byte) 0x74, (byte) 0x61, (byte) 0x6b, (byte) 0x72, + (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x65, (byte) 0x72, (byte) 0x31, (byte) 0x17, (byte) 0x30, + (byte) 0x15, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x04, (byte) 0x0c, (byte) 0x0e, + (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0x4f, (byte) 0x74, (byte) 0x74, (byte) 0x61, (byte) 0x6b, + (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x65, (byte) 0x72, (byte) 0x31, (byte) 0x10, + (byte) 0x30, (byte) 0x0e, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x2a, (byte) 0x0c, + (byte) 0x07, (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0x4f, (byte) 0x74, (byte) 0x74, (byte) 0x6f, + (byte) 0x31, (byte) 0x15, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, + (byte) 0x05, (byte) 0x13, (byte) 0x0c, (byte) 0x39, (byte) 0x37, (byte) 0x30, (byte) 0x30, (byte) 0x31, + (byte) 0x36, (byte) 0x38, (byte) 0x36, (byte) 0x36, (byte) 0x31, (byte) 0x37, (byte) 0x34, (byte) 0x30, + (byte) 0x81, (byte) 0xdf, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, + (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x05, + (byte) 0x00, (byte) 0x03, (byte) 0x81, (byte) 0xcd, (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0xc9, + (byte) 0x02, (byte) 0x81, (byte) 0xc1, (byte) 0x00, (byte) 0xae, (byte) 0xe6, (byte) 0x07, (byte) 0x1d, + (byte) 0xb9, (byte) 0x56, (byte) 0x0a, (byte) 0x98, (byte) 0x1a, (byte) 0xde, (byte) 0x52, (byte) 0xf2, + (byte) 0x77, (byte) 0xdc, (byte) 0x5e, (byte) 0x76, (byte) 0x7f, (byte) 0xe5, (byte) 0xc1, (byte) 0x79, + (byte) 0xb9, (byte) 0x51, (byte) 0x97, (byte) 0x08, (byte) 0x20, (byte) 0x4e, (byte) 0xa6, (byte) 0xa3, + (byte) 0xab, (byte) 0xdf, (byte) 0x49, (byte) 0x21, (byte) 0x2b, (byte) 0x65, (byte) 0x4f, (byte) 0x7c, + (byte) 0x26, (byte) 0xe8, (byte) 0xb9, (byte) 0x47, (byte) 0xdf, (byte) 0x03, (byte) 0x0f, (byte) 0xf7, + (byte) 0x4e, (byte) 0xf4, (byte) 0x47, (byte) 0x3d, (byte) 0x32, (byte) 0x61, (byte) 0x05, (byte) 0x33, + (byte) 0x0f, (byte) 0xdc, (byte) 0x97, (byte) 0x3e, (byte) 0xbf, (byte) 0x9b, (byte) 0xf2, (byte) 0xf8, + (byte) 0xb3, (byte) 0xe2, (byte) 0xc4, (byte) 0x4d, (byte) 0xe0, (byte) 0x48, (byte) 0x6a, (byte) 0x1b, + (byte) 0xd2, (byte) 0xfe, (byte) 0xfa, (byte) 0xee, (byte) 0x24, (byte) 0x08, (byte) 0xdc, (byte) 0x60, + (byte) 0x2a, (byte) 0x78, (byte) 0x6c, (byte) 0x1d, (byte) 0xd3, (byte) 0x74, (byte) 0x43, (byte) 0x1f, + (byte) 0x1f, (byte) 0x4e, (byte) 0xd2, (byte) 0x0f, (byte) 0x89, (byte) 0x3c, (byte) 0xe3, (byte) 0x1e, + (byte) 0xfa, (byte) 0x31, (byte) 0x5a, (byte) 0xc2, (byte) 0x04, (byte) 0x24, (byte) 0xd1, (byte) 0xe5, + (byte) 0x51, (byte) 0xc4, (byte) 0x94, (byte) 0x26, (byte) 0xd1, (byte) 0x32, (byte) 0x1e, (byte) 0xdf, + (byte) 0x64, (byte) 0xaa, (byte) 0xaf, (byte) 0x2c, (byte) 0x85, (byte) 0x25, (byte) 0x88, (byte) 0x8f, + (byte) 0x80, (byte) 0xe4, (byte) 0x05, (byte) 0x74, (byte) 0xd5, (byte) 0xda, (byte) 0x69, (byte) 0x88, + (byte) 0x4a, (byte) 0x0c, (byte) 0x6a, (byte) 0x85, (byte) 0x5f, (byte) 0x67, (byte) 0x51, (byte) 0x6c, + (byte) 0x5c, (byte) 0x1c, (byte) 0x41, (byte) 0x88, (byte) 0x4c, (byte) 0xad, (byte) 0x83, (byte) 0xc9, + (byte) 0x10, (byte) 0x97, (byte) 0x45, (byte) 0x00, (byte) 0x3f, (byte) 0xbd, (byte) 0x1d, (byte) 0x2f, + (byte) 0x28, (byte) 0x2e, (byte) 0x78, (byte) 0x97, (byte) 0x05, (byte) 0xa5, (byte) 0x41, (byte) 0x42, + (byte) 0x37, (byte) 0x08, (byte) 0x60, (byte) 0x0b, (byte) 0x66, (byte) 0xb1, (byte) 0xb8, (byte) 0xdd, + (byte) 0x98, (byte) 0x03, (byte) 0x03, (byte) 0x33, (byte) 0xc9, (byte) 0x15, (byte) 0xf7, (byte) 0x5b, + (byte) 0x35, (byte) 0xa5, (byte) 0xaa, (byte) 0x7a, (byte) 0x5e, (byte) 0xe9, (byte) 0xa7, (byte) 0x60, + (byte) 0xba, (byte) 0xd8, (byte) 0x0d, (byte) 0x6d, (byte) 0xb3, (byte) 0x85, (byte) 0x70, (byte) 0x0e, + (byte) 0x38, (byte) 0x6f, (byte) 0xf0, (byte) 0xfd, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x00, + (byte) 0x01, (byte) 0xa3, (byte) 0x82, (byte) 0x02, (byte) 0x32, (byte) 0x30, (byte) 0x82, (byte) 0x02, + (byte) 0x2e, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x23, + (byte) 0x04, (byte) 0x0c, (byte) 0x30, (byte) 0x0a, (byte) 0x80, (byte) 0x08, (byte) 0x4b, (byte) 0x5d, + (byte) 0x02, (byte) 0x5c, (byte) 0x6d, (byte) 0x58, (byte) 0x24, (byte) 0x67, (byte) 0x30, (byte) 0x81, + (byte) 0x84, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, + (byte) 0x07, (byte) 0x01, (byte) 0x01, (byte) 0x04, (byte) 0x78, (byte) 0x30, (byte) 0x76, (byte) 0x30, + (byte) 0x2c, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, + (byte) 0x07, (byte) 0x30, (byte) 0x01, (byte) 0x86, (byte) 0x20, (byte) 0x68, (byte) 0x74, (byte) 0x74, + (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, (byte) 0x6f, (byte) 0x63, (byte) 0x73, (byte) 0x70, + (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, + (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, + (byte) 0x2f, (byte) 0x6f, (byte) 0x63, (byte) 0x73, (byte) 0x70, (byte) 0x30, (byte) 0x46, (byte) 0x06, + (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x30, + (byte) 0x02, (byte) 0x86, (byte) 0x3a, (byte) 0x68, (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, + (byte) 0x2f, (byte) 0x2f, (byte) 0x77, (byte) 0x77, (byte) 0x77, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, + (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, + (byte) 0x2f, (byte) 0x63, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x73, (byte) 0x2f, (byte) 0x61, + (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, + (byte) 0x65, (byte) 0x6d, (byte) 0x69, (byte) 0x75, (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, + (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x45, (byte) 0x6e, (byte) 0x63, (byte) 0x2d, (byte) 0x30, + (byte) 0x32, (byte) 0x2e, (byte) 0x63, (byte) 0x72, (byte) 0x74, (byte) 0x30, (byte) 0x81, (byte) 0x93, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x20, (byte) 0x04, (byte) 0x81, (byte) 0x8b, + (byte) 0x30, (byte) 0x81, (byte) 0x88, (byte) 0x30, (byte) 0x81, (byte) 0x85, (byte) 0x06, (byte) 0x06, + (byte) 0x2a, (byte) 0x28, (byte) 0x00, (byte) 0x11, (byte) 0x01, (byte) 0x03, (byte) 0x30, (byte) 0x7b, + (byte) 0x30, (byte) 0x3d, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, + (byte) 0x05, (byte) 0x07, (byte) 0x02, (byte) 0x01, (byte) 0x16, (byte) 0x31, (byte) 0x68, (byte) 0x74, + (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, (byte) 0x77, (byte) 0x77, (byte) 0x77, + (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, + (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x64, (byte) 0x6f, (byte) 0x63, (byte) 0x73, + (byte) 0x2f, (byte) 0x63, (byte) 0x70, (byte) 0x2f, (byte) 0x61, (byte) 0x2d, (byte) 0x73, (byte) 0x69, + (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x70, (byte) 0x72, (byte) 0x65, (byte) 0x6d, (byte) 0x69, + (byte) 0x75, (byte) 0x6d, (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x30, + (byte) 0x3a, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, + (byte) 0x07, (byte) 0x02, (byte) 0x02, (byte) 0x30, (byte) 0x2e, (byte) 0x1a, (byte) 0x2c, (byte) 0x44, + (byte) 0x69, (byte) 0x65, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x20, (byte) 0x5a, (byte) 0x65, + (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x6b, (byte) 0x61, (byte) 0x74, + (byte) 0x20, (byte) 0x64, (byte) 0x69, (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x20, (byte) 0x6e, + (byte) 0x75, (byte) 0x72, (byte) 0x20, (byte) 0x7a, (byte) 0x75, (byte) 0x20, (byte) 0x54, (byte) 0x65, + (byte) 0x73, (byte) 0x74, (byte) 0x7a, (byte) 0x77, (byte) 0x65, (byte) 0x63, (byte) 0x6b, (byte) 0x65, + (byte) 0x6e, (byte) 0x20, (byte) 0x21, (byte) 0x30, (byte) 0x81, (byte) 0xa4, (byte) 0x06, (byte) 0x03, + (byte) 0x55, (byte) 0x1d, (byte) 0x1f, (byte) 0x04, (byte) 0x81, (byte) 0x9c, (byte) 0x30, (byte) 0x81, + (byte) 0x99, (byte) 0x30, (byte) 0x81, (byte) 0x96, (byte) 0xa0, (byte) 0x81, (byte) 0x93, (byte) 0xa0, + (byte) 0x81, (byte) 0x90, (byte) 0x86, (byte) 0x81, (byte) 0x8d, (byte) 0x6c, (byte) 0x64, (byte) 0x61, + (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, (byte) 0x6c, (byte) 0x64, (byte) 0x61, (byte) 0x70, + (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, + (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, + (byte) 0x2f, (byte) 0x6f, (byte) 0x75, (byte) 0x3d, (byte) 0x61, (byte) 0x2d, (byte) 0x73, (byte) 0x69, + (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, (byte) 0x65, (byte) 0x6d, (byte) 0x69, + (byte) 0x75, (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, + (byte) 0x45, (byte) 0x6e, (byte) 0x63, (byte) 0x2d, (byte) 0x30, (byte) 0x32, (byte) 0x2c, (byte) 0x6f, + (byte) 0x3d, (byte) 0x41, (byte) 0x2d, (byte) 0x54, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, + (byte) 0x2c, (byte) 0x63, (byte) 0x3d, (byte) 0x41, (byte) 0x54, (byte) 0x3f, (byte) 0x63, (byte) 0x65, + (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x63, (byte) 0x61, (byte) 0x74, + (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x76, (byte) 0x6f, (byte) 0x63, (byte) 0x61, (byte) 0x74, + (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x6c, (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x3f, + (byte) 0x62, (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x3f, (byte) 0x6f, (byte) 0x62, (byte) 0x6a, + (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x63, (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, + (byte) 0x3d, (byte) 0x65, (byte) 0x69, (byte) 0x64, (byte) 0x43, (byte) 0x65, (byte) 0x72, (byte) 0x74, + (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x63, (byte) 0x61, (byte) 0x74, (byte) 0x69, (byte) 0x6f, + (byte) 0x6e, (byte) 0x41, (byte) 0x75, (byte) 0x74, (byte) 0x68, (byte) 0x6f, (byte) 0x72, (byte) 0x69, + (byte) 0x74, (byte) 0x79, (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, + (byte) 0x0e, (byte) 0x04, (byte) 0x0a, (byte) 0x04, (byte) 0x08, (byte) 0x4a, (byte) 0x24, (byte) 0x43, + (byte) 0xc0, (byte) 0x85, (byte) 0x2a, (byte) 0xb4, (byte) 0x51, (byte) 0x30, (byte) 0x0e, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0f, (byte) 0x01, (byte) 0x01, (byte) 0xff, (byte) 0x04, + (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0xb0, (byte) 0x30, (byte) 0x25, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x11, (byte) 0x04, (byte) 0x1e, (byte) 0x30, (byte) 0x1c, + (byte) 0x81, (byte) 0x1a, (byte) 0x74, (byte) 0x68, (byte) 0x6f, (byte) 0x6d, (byte) 0x61, (byte) 0x73, + (byte) 0x2e, (byte) 0x72, (byte) 0x6f, (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x6c, (byte) 0x65, + (byte) 0x72, (byte) 0x40, (byte) 0x65, (byte) 0x67, (byte) 0x69, (byte) 0x7a, (byte) 0x2e, (byte) 0x67, + (byte) 0x76, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, + (byte) 0x55, (byte) 0x1d, (byte) 0x13, (byte) 0x04, (byte) 0x02, (byte) 0x30, (byte) 0x00, (byte) 0x30, + (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, + (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x82, + (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x4a, (byte) 0x36, (byte) 0x02, (byte) 0xb3, (byte) 0xab, + (byte) 0x02, (byte) 0xe9, (byte) 0xe1, (byte) 0xaf, (byte) 0x3f, (byte) 0xd5, (byte) 0xcd, (byte) 0x3d, + (byte) 0x51, (byte) 0x08, (byte) 0xb8, (byte) 0x73, (byte) 0x23, (byte) 0x68, (byte) 0x0c, (byte) 0x22, + (byte) 0x32, (byte) 0xcd, (byte) 0xbe, (byte) 0xc8, (byte) 0x77, (byte) 0xbc, (byte) 0x47, (byte) 0x37, + (byte) 0xdd, (byte) 0x89, (byte) 0x7c, (byte) 0x22, (byte) 0x24, (byte) 0x2f, (byte) 0x23, (byte) 0xea, + (byte) 0x3e, (byte) 0xc2, (byte) 0xf4, (byte) 0x59, (byte) 0x78, (byte) 0xa6, (byte) 0xbe, (byte) 0xcd, + (byte) 0x71, (byte) 0xaa, (byte) 0xb5, (byte) 0xbc, (byte) 0xe3, (byte) 0xbc, (byte) 0x3f, (byte) 0xf1, + (byte) 0xfa, (byte) 0x1a, (byte) 0x43, (byte) 0x2b, (byte) 0x91, (byte) 0x35, (byte) 0x67, (byte) 0xa5, + (byte) 0x62, (byte) 0x9d, (byte) 0x55, (byte) 0x85, (byte) 0xe0, (byte) 0x3f, (byte) 0xed, (byte) 0x00, + (byte) 0x67, (byte) 0x80, (byte) 0x6a, (byte) 0xfb, (byte) 0x46, (byte) 0x8a, (byte) 0xed, (byte) 0x48, + (byte) 0x03, (byte) 0xe7, (byte) 0x9d, (byte) 0x5c, (byte) 0xac, (byte) 0xdf, (byte) 0xec, (byte) 0x2d, + (byte) 0x53, (byte) 0x8b, (byte) 0x01, (byte) 0xdb, (byte) 0x14, (byte) 0x91, (byte) 0x21, (byte) 0xaf, + (byte) 0xa7, (byte) 0x91, (byte) 0x69, (byte) 0x7e, (byte) 0x97, (byte) 0x68, (byte) 0xcc, (byte) 0x2a, + (byte) 0x06, (byte) 0x1a, (byte) 0xbc, (byte) 0x53, (byte) 0x35, (byte) 0xde, (byte) 0xd7, (byte) 0x62, + (byte) 0x12, (byte) 0xbd, (byte) 0x54, (byte) 0xb5, (byte) 0x4c, (byte) 0x3c, (byte) 0xaf, (byte) 0x55, + (byte) 0xa4, (byte) 0x5b, (byte) 0x28, (byte) 0x61, (byte) 0x68, (byte) 0x03, (byte) 0xc6, (byte) 0x72, + (byte) 0xc0, (byte) 0xa2, (byte) 0x3f, (byte) 0x84, (byte) 0x02, (byte) 0xf8, (byte) 0x3d, (byte) 0x70, + (byte) 0x3f, (byte) 0xde, (byte) 0x9d, (byte) 0x6a, (byte) 0x71, (byte) 0x16, (byte) 0x87, (byte) 0x9d, + (byte) 0x93, (byte) 0x3d, (byte) 0x46, (byte) 0x41, (byte) 0xa9, (byte) 0x6a, (byte) 0xca, (byte) 0x87, + (byte) 0xd4, (byte) 0xd1, (byte) 0x3f, (byte) 0x1d, (byte) 0x6e, (byte) 0x6a, (byte) 0xbf, (byte) 0x02, + (byte) 0x9b, (byte) 0xfb, (byte) 0x4a, (byte) 0x47, (byte) 0xe0, (byte) 0x20, (byte) 0x4a, (byte) 0x2d, + (byte) 0x5a, (byte) 0x0c, (byte) 0x6b, (byte) 0x25, (byte) 0xd6, (byte) 0x2d, (byte) 0xd4, (byte) 0x53, + (byte) 0x08, (byte) 0x41, (byte) 0xa9, (byte) 0x16, (byte) 0xa2, (byte) 0xa0, (byte) 0xef, (byte) 0x13, + (byte) 0xa8, (byte) 0xec, (byte) 0x7e, (byte) 0x99, (byte) 0x15, (byte) 0xf9, (byte) 0x1a, (byte) 0x18, + (byte) 0x5e, (byte) 0x75, (byte) 0xc7, (byte) 0x5d, (byte) 0x40, (byte) 0xd4, (byte) 0x84, (byte) 0x4a, + (byte) 0xd2, (byte) 0xf7, (byte) 0x7c, (byte) 0x65, (byte) 0x12, (byte) 0xc7, (byte) 0xae, (byte) 0xbc, + (byte) 0x9d, (byte) 0x3e, (byte) 0xce, (byte) 0x42, (byte) 0xfe, (byte) 0xe4, (byte) 0x98, (byte) 0x10, + (byte) 0x63, (byte) 0x0d, (byte) 0xaa, (byte) 0x2d, (byte) 0x73, (byte) 0x7d, (byte) 0x46, (byte) 0x19, + (byte) 0xca, (byte) 0x78, (byte) 0x94, (byte) 0xe5, (byte) 0x11, (byte) 0x83, (byte) 0x87, (byte) 0xb2, + (byte) 0xf7, (byte) 0x59, (byte) 0x90, (byte) 0x47, (byte) 0x86, (byte) 0x57, (byte) 0xcf, (byte) 0xc7, + (byte) 0x7b, (byte) 0x8f, (byte) 0xac, (byte) 0x20, (byte) 0xbd, (byte) 0x46, (byte) 0xea, (byte) 0xa2, + (byte) 0x10, (byte) 0xe1, (byte) 0x72, (byte) 0x3e, (byte) 0xe3, (byte) 0x72, (byte) 0x20, (byte) 0x24, + (byte) 0xa5, (byte) 0x2f, (byte) 0xc5 + }; + protected static final int KID_PIN_DEC = 0x81; + + protected static byte[] FID_EF_INFOBOX = new byte[] { (byte) 0xc0, (byte) 0x02 }; + protected static byte[] FCI_EF_INFOBOX = new byte[] { (byte) 0x6f, (byte) 0x07, + (byte) 0x80, (byte) 0x02, (byte) 0x05, (byte) 0xdc, (byte) 0x82, + (byte) 0x01, (byte) 0x01}; + + protected byte[] EF_INFOBOX = new byte[1500]; + + protected byte[] EF_C_CH_EKEY = new byte[2000]; + + public ACOSApplDEC() { + System.arraycopy(C_CH_EKEY, 0, EF_C_CH_EKEY, 0, C_CH_EKEY.length); + putFile(new File(FID_EF_C_CH_EKEY, EF_C_CH_EKEY, FCI_EF_C_CH_EKEY)); + try { + pins.put(KID_PIN_DEC, new PIN("1234\0\0\0\0".getBytes("ASCII"), KID_PIN_DEC, 10)); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + + @Override + public byte[] getAID() { + return AID_DEC; + } + + @Override + public byte[] getFID() { + return FID_DEC; + } + + @Override + public byte[] getFCI() { + return FCI; + } + + public void clearInfobox() { + Arrays.fill(EF_INFOBOX, (byte) 0x00); + } + + public void setInfoboxHeader(byte b) { + EF_INFOBOX[0] = b; + } + + public void clearCert() { + Arrays.fill(EF_C_CH_EKEY, (byte) 0x00); + } + + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplSIG.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplSIG.java new file mode 100644 index 00000000..e476b434 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplSIG.java @@ -0,0 +1,302 @@ +/* +* Copyright 2008 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.acos; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.Random; + +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.File; +import at.gv.egiz.smcc.PIN; + +@SuppressWarnings("restriction") +public abstract class ACOSApplSIG extends ACOSAppl { + + private static byte[] FCI = new byte[] { (byte) 0x6f, (byte) 0x1a, + (byte) 0x84, (byte) 0x07, (byte) 0xa0, (byte) 0x00, (byte) 0x00, + (byte) 0x01, (byte) 0x18, (byte) 0x45, (byte) 0x43, (byte) 0x85, + (byte) 0x0f, (byte) 0x50, (byte) 0x0d, (byte) 0x44, (byte) 0x49, + (byte) 0x47, (byte) 0x53, (byte) 0x49, (byte) 0x47, (byte) 0x20, + (byte) 0x43, (byte) 0x43, (byte) 0x20, (byte) 0x45, (byte) 0x43, + (byte) 0x43 }; + protected static byte[] FID_EF_C_CH_DS = new byte[] { (byte) 0xc0, (byte) 0x02 }; + protected static byte[] FCI_EF_C_CH_DS = new byte[] { (byte) 0x6f, (byte) 0x07, + (byte) 0x80, (byte) 0x02, (byte) 0x07, (byte) 0xd0, (byte) 0x82, + (byte) 0x01, (byte) 0x01 }; + protected static byte[] C_CH_DS = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x05, (byte) 0x2b, (byte) 0x30, (byte) 0x82, (byte) 0x04, (byte) 0x13, + (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x02, + (byte) 0x05, (byte) 0x52, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, + (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05, + (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0xa1, (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, + (byte) 0x54, (byte) 0x31, (byte) 0x48, (byte) 0x30, (byte) 0x46, (byte) 0x06, (byte) 0x03, (byte) 0x55, + (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x3f, (byte) 0x41, (byte) 0x2d, (byte) 0x54, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x47, (byte) 0x65, (byte) 0x73, (byte) 0x2e, + (byte) 0x20, (byte) 0x66, (byte) 0x2e, (byte) 0x20, (byte) 0x53, (byte) 0x69, (byte) 0x63, (byte) 0x68, + (byte) 0x65, (byte) 0x72, (byte) 0x68, (byte) 0x65, (byte) 0x69, (byte) 0x74, (byte) 0x73, (byte) 0x73, + (byte) 0x79, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6d, (byte) 0x65, (byte) 0x20, (byte) 0x69, + (byte) 0x6d, (byte) 0x20, (byte) 0x65, (byte) 0x6c, (byte) 0x65, (byte) 0x6b, (byte) 0x74, (byte) 0x72, + (byte) 0x2e, (byte) 0x20, (byte) 0x44, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x6e, (byte) 0x76, + (byte) 0x65, (byte) 0x72, (byte) 0x6b, (byte) 0x65, (byte) 0x68, (byte) 0x72, (byte) 0x20, (byte) 0x47, + (byte) 0x6d, (byte) 0x62, (byte) 0x48, (byte) 0x31, (byte) 0x23, (byte) 0x30, (byte) 0x21, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0b, (byte) 0x0c, (byte) 0x1a, (byte) 0x61, (byte) 0x2d, + (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, (byte) 0x65, + (byte) 0x6d, (byte) 0x69, (byte) 0x75, (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, + (byte) 0x74, (byte) 0x2d, (byte) 0x53, (byte) 0x69, (byte) 0x67, (byte) 0x2d, (byte) 0x30, (byte) 0x32, + (byte) 0x31, (byte) 0x23, (byte) 0x30, (byte) 0x21, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, + (byte) 0x03, (byte) 0x0c, (byte) 0x1a, (byte) 0x61, (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, + (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, (byte) 0x65, (byte) 0x6d, (byte) 0x69, (byte) 0x75, + (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x53, + (byte) 0x69, (byte) 0x67, (byte) 0x2d, (byte) 0x30, (byte) 0x32, (byte) 0x30, (byte) 0x1e, (byte) 0x17, + (byte) 0x0d, (byte) 0x30, (byte) 0x39, (byte) 0x30, (byte) 0x31, (byte) 0x31, (byte) 0x33, (byte) 0x30, + (byte) 0x39, (byte) 0x34, (byte) 0x35, (byte) 0x31, (byte) 0x32, (byte) 0x5a, (byte) 0x17, (byte) 0x0d, + (byte) 0x31, (byte) 0x32, (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x31, (byte) 0x30, (byte) 0x39, + (byte) 0x34, (byte) 0x35, (byte) 0x31, (byte) 0x32, (byte) 0x5a, (byte) 0x30, (byte) 0x70, (byte) 0x31, + (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, + (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x54, (byte) 0x31, (byte) 0x1f, (byte) 0x30, (byte) 0x1d, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c, (byte) 0x16, (byte) 0x58, + (byte) 0x58, (byte) 0x58, (byte) 0x4f, (byte) 0x74, (byte) 0x74, (byte) 0x6f, (byte) 0x20, (byte) 0x58, + (byte) 0x58, (byte) 0x58, (byte) 0x4f, (byte) 0x74, (byte) 0x74, (byte) 0x61, (byte) 0x6b, (byte) 0x72, + (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x65, (byte) 0x72, (byte) 0x31, (byte) 0x17, (byte) 0x30, + (byte) 0x15, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x04, (byte) 0x0c, (byte) 0x0e, + (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0x4f, (byte) 0x74, (byte) 0x74, (byte) 0x61, (byte) 0x6b, + (byte) 0x72, (byte) 0x69, (byte) 0x6e, (byte) 0x67, (byte) 0x65, (byte) 0x72, (byte) 0x31, (byte) 0x10, + (byte) 0x30, (byte) 0x0e, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x2a, (byte) 0x0c, + (byte) 0x07, (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0x4f, (byte) 0x74, (byte) 0x74, (byte) 0x6f, + (byte) 0x31, (byte) 0x15, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, + (byte) 0x05, (byte) 0x13, (byte) 0x0c, (byte) 0x39, (byte) 0x37, (byte) 0x30, (byte) 0x30, (byte) 0x31, + (byte) 0x36, (byte) 0x38, (byte) 0x36, (byte) 0x36, (byte) 0x31, (byte) 0x37, (byte) 0x34, (byte) 0x30, + (byte) 0x59, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x07, (byte) 0x2a, (byte) 0x86, (byte) 0x48, + (byte) 0xce, (byte) 0x3d, (byte) 0x02, (byte) 0x01, (byte) 0x06, (byte) 0x08, (byte) 0x2a, (byte) 0x86, + (byte) 0x48, (byte) 0xce, (byte) 0x3d, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x42, + (byte) 0x00, (byte) 0x04, (byte) 0x6b, (byte) 0xde, (byte) 0x5f, (byte) 0x5e, (byte) 0xd5, (byte) 0x2b, + (byte) 0xbe, (byte) 0x1e, (byte) 0xb9, (byte) 0x82, (byte) 0x19, (byte) 0x75, (byte) 0xf4, (byte) 0x3b, + (byte) 0xc1, (byte) 0x34, (byte) 0xe9, (byte) 0xdb, (byte) 0x0b, (byte) 0x25, (byte) 0x31, (byte) 0x33, + (byte) 0xfa, (byte) 0x8b, (byte) 0x72, (byte) 0xd4, (byte) 0x9f, (byte) 0x21, (byte) 0xf5, (byte) 0x62, + (byte) 0xb9, (byte) 0xf6, (byte) 0x50, (byte) 0xdb, (byte) 0xcc, (byte) 0xbf, (byte) 0x43, (byte) 0xb9, + (byte) 0x5e, (byte) 0x75, (byte) 0x2a, (byte) 0x37, (byte) 0xbe, (byte) 0x32, (byte) 0xa6, (byte) 0x83, + (byte) 0xb1, (byte) 0x5c, (byte) 0xc3, (byte) 0x9d, (byte) 0xf0, (byte) 0xab, (byte) 0xe6, (byte) 0x8f, + (byte) 0xe4, (byte) 0x97, (byte) 0x83, (byte) 0x57, (byte) 0x89, (byte) 0xe0, (byte) 0x13, (byte) 0xe3, + (byte) 0x13, (byte) 0xa8, (byte) 0xa3, (byte) 0x82, (byte) 0x02, (byte) 0x65, (byte) 0x30, (byte) 0x82, + (byte) 0x02, (byte) 0x61, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, + (byte) 0x23, (byte) 0x04, (byte) 0x0c, (byte) 0x30, (byte) 0x0a, (byte) 0x80, (byte) 0x08, (byte) 0x46, + (byte) 0x06, (byte) 0x9f, (byte) 0x8e, (byte) 0x41, (byte) 0x8e, (byte) 0x15, (byte) 0xbd, (byte) 0x30, + (byte) 0x27, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, + (byte) 0x07, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0xff, (byte) 0x04, (byte) 0x18, + (byte) 0x30, (byte) 0x16, (byte) 0x30, (byte) 0x08, (byte) 0x06, (byte) 0x06, (byte) 0x04, (byte) 0x00, + (byte) 0x8e, (byte) 0x46, (byte) 0x01, (byte) 0x01, (byte) 0x30, (byte) 0x0a, (byte) 0x06, (byte) 0x08, + (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x0b, (byte) 0x01, + (byte) 0x30, (byte) 0x81, (byte) 0x84, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, + (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x01, (byte) 0x01, (byte) 0x04, (byte) 0x78, (byte) 0x30, + (byte) 0x76, (byte) 0x30, (byte) 0x2c, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, + (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x30, (byte) 0x01, (byte) 0x86, (byte) 0x20, (byte) 0x68, + (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, (byte) 0x6f, (byte) 0x63, + (byte) 0x73, (byte) 0x70, (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2e, + (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, + (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x6f, (byte) 0x63, (byte) 0x73, (byte) 0x70, (byte) 0x30, + (byte) 0x46, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, + (byte) 0x07, (byte) 0x30, (byte) 0x02, (byte) 0x86, (byte) 0x3a, (byte) 0x68, (byte) 0x74, (byte) 0x74, + (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, (byte) 0x77, (byte) 0x77, (byte) 0x77, (byte) 0x2e, + (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, + (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x63, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x73, + (byte) 0x2f, (byte) 0x61, (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, + (byte) 0x50, (byte) 0x72, (byte) 0x65, (byte) 0x6d, (byte) 0x69, (byte) 0x75, (byte) 0x6d, (byte) 0x2d, + (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x53, (byte) 0x69, (byte) 0x67, + (byte) 0x2d, (byte) 0x30, (byte) 0x32, (byte) 0x2e, (byte) 0x63, (byte) 0x72, (byte) 0x74, (byte) 0x30, + (byte) 0x81, (byte) 0x9d, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x20, (byte) 0x04, + (byte) 0x81, (byte) 0x95, (byte) 0x30, (byte) 0x81, (byte) 0x92, (byte) 0x30, (byte) 0x81, (byte) 0x85, + (byte) 0x06, (byte) 0x06, (byte) 0x2a, (byte) 0x28, (byte) 0x00, (byte) 0x11, (byte) 0x01, (byte) 0x03, + (byte) 0x30, (byte) 0x7b, (byte) 0x30, (byte) 0x3d, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, + (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x02, (byte) 0x01, (byte) 0x16, (byte) 0x31, + (byte) 0x68, (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, (byte) 0x77, + (byte) 0x77, (byte) 0x77, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, (byte) 0x75, + (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x64, (byte) 0x6f, + (byte) 0x63, (byte) 0x73, (byte) 0x2f, (byte) 0x63, (byte) 0x70, (byte) 0x2f, (byte) 0x61, (byte) 0x2d, + (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x70, (byte) 0x72, (byte) 0x65, + (byte) 0x6d, (byte) 0x69, (byte) 0x75, (byte) 0x6d, (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, + (byte) 0x74, (byte) 0x30, (byte) 0x3a, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, + (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x02, (byte) 0x02, (byte) 0x30, (byte) 0x2e, (byte) 0x1a, + (byte) 0x2c, (byte) 0x44, (byte) 0x69, (byte) 0x65, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x20, + (byte) 0x5a, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x6b, + (byte) 0x61, (byte) 0x74, (byte) 0x20, (byte) 0x64, (byte) 0x69, (byte) 0x65, (byte) 0x6e, (byte) 0x74, + (byte) 0x20, (byte) 0x6e, (byte) 0x75, (byte) 0x72, (byte) 0x20, (byte) 0x7a, (byte) 0x75, (byte) 0x20, + (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x7a, (byte) 0x77, (byte) 0x65, (byte) 0x63, + (byte) 0x6b, (byte) 0x65, (byte) 0x6e, (byte) 0x20, (byte) 0x21, (byte) 0x30, (byte) 0x08, (byte) 0x06, + (byte) 0x06, (byte) 0x04, (byte) 0x00, (byte) 0x8b, (byte) 0x30, (byte) 0x01, (byte) 0x01, (byte) 0x30, + (byte) 0x81, (byte) 0xa4, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x1f, (byte) 0x04, + (byte) 0x81, (byte) 0x9c, (byte) 0x30, (byte) 0x81, (byte) 0x99, (byte) 0x30, (byte) 0x81, (byte) 0x96, + (byte) 0xa0, (byte) 0x81, (byte) 0x93, (byte) 0xa0, (byte) 0x81, (byte) 0x90, (byte) 0x86, (byte) 0x81, + (byte) 0x8d, (byte) 0x6c, (byte) 0x64, (byte) 0x61, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, + (byte) 0x6c, (byte) 0x64, (byte) 0x61, (byte) 0x70, (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, + (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, + (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x6f, (byte) 0x75, (byte) 0x3d, + (byte) 0x61, (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x50, + (byte) 0x72, (byte) 0x65, (byte) 0x6d, (byte) 0x69, (byte) 0x75, (byte) 0x6d, (byte) 0x2d, (byte) 0x54, + (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x53, (byte) 0x69, (byte) 0x67, (byte) 0x2d, + (byte) 0x30, (byte) 0x32, (byte) 0x2c, (byte) 0x6f, (byte) 0x3d, (byte) 0x41, (byte) 0x2d, (byte) 0x54, + (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2c, (byte) 0x63, (byte) 0x3d, (byte) 0x41, + (byte) 0x54, (byte) 0x3f, (byte) 0x63, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, + (byte) 0x69, (byte) 0x63, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x76, + (byte) 0x6f, (byte) 0x63, (byte) 0x61, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x6c, + (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x3f, (byte) 0x62, (byte) 0x61, (byte) 0x73, (byte) 0x65, + (byte) 0x3f, (byte) 0x6f, (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x63, + (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x3d, (byte) 0x65, (byte) 0x69, (byte) 0x64, + (byte) 0x43, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x63, + (byte) 0x61, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x41, (byte) 0x75, (byte) 0x74, + (byte) 0x68, (byte) 0x6f, (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79, (byte) 0x30, (byte) 0x11, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0e, (byte) 0x04, (byte) 0x0a, (byte) 0x04, + (byte) 0x08, (byte) 0x46, (byte) 0x08, (byte) 0xda, (byte) 0x9e, (byte) 0x68, (byte) 0xf8, (byte) 0xe5, + (byte) 0x81, (byte) 0x30, (byte) 0x0e, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0f, + (byte) 0x01, (byte) 0x01, (byte) 0xff, (byte) 0x04, (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x06, + (byte) 0xc0, (byte) 0x30, (byte) 0x25, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x11, + (byte) 0x04, (byte) 0x1e, (byte) 0x30, (byte) 0x1c, (byte) 0x81, (byte) 0x1a, (byte) 0x74, (byte) 0x68, + (byte) 0x6f, (byte) 0x6d, (byte) 0x61, (byte) 0x73, (byte) 0x2e, (byte) 0x72, (byte) 0x6f, (byte) 0x65, + (byte) 0x73, (byte) 0x73, (byte) 0x6c, (byte) 0x65, (byte) 0x72, (byte) 0x40, (byte) 0x65, (byte) 0x67, + (byte) 0x69, (byte) 0x7a, (byte) 0x2e, (byte) 0x67, (byte) 0x76, (byte) 0x2e, (byte) 0x61, (byte) 0x74, + (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x13, (byte) 0x04, + (byte) 0x02, (byte) 0x30, (byte) 0x00, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, + (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, + (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x82, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0xd8, + (byte) 0xec, (byte) 0xe5, (byte) 0x5c, (byte) 0x17, (byte) 0x42, (byte) 0xe8, (byte) 0x2f, (byte) 0x04, + (byte) 0x1f, (byte) 0xe2, (byte) 0x04, (byte) 0x57, (byte) 0x07, (byte) 0x30, (byte) 0xdc, (byte) 0x4f, + (byte) 0x61, (byte) 0x7d, (byte) 0xd8, (byte) 0x89, (byte) 0x36, (byte) 0x31, (byte) 0x26, (byte) 0x45, + (byte) 0x55, (byte) 0x64, (byte) 0xd3, (byte) 0x55, (byte) 0x1b, (byte) 0x83, (byte) 0x51, (byte) 0xa0, + (byte) 0x39, (byte) 0x1b, (byte) 0x6a, (byte) 0x7e, (byte) 0xfa, (byte) 0x7e, (byte) 0x2c, (byte) 0xd0, + (byte) 0xd3, (byte) 0x86, (byte) 0x7b, (byte) 0x8d, (byte) 0x29, (byte) 0x8f, (byte) 0xa3, (byte) 0x83, + (byte) 0xd2, (byte) 0x72, (byte) 0xce, (byte) 0x43, (byte) 0xcf, (byte) 0xc1, (byte) 0x27, (byte) 0xf1, + (byte) 0x4d, (byte) 0x11, (byte) 0xe2, (byte) 0x67, (byte) 0xbe, (byte) 0x6e, (byte) 0x34, (byte) 0x7d, + (byte) 0x04, (byte) 0x1f, (byte) 0xba, (byte) 0x55, (byte) 0x34, (byte) 0xea, (byte) 0xc2, (byte) 0xcf, + (byte) 0x0f, (byte) 0x64, (byte) 0x7b, (byte) 0x84, (byte) 0xe0, (byte) 0x55, (byte) 0x05, (byte) 0x82, + (byte) 0xdd, (byte) 0x9d, (byte) 0xd7, (byte) 0xeb, (byte) 0x91, (byte) 0x78, (byte) 0x69, (byte) 0x49, + (byte) 0x58, (byte) 0x70, (byte) 0xff, (byte) 0x83, (byte) 0x70, (byte) 0xa0, (byte) 0xb3, (byte) 0xb7, + (byte) 0x3d, (byte) 0x0f, (byte) 0x8e, (byte) 0xe9, (byte) 0x1b, (byte) 0x21, (byte) 0xef, (byte) 0x31, + (byte) 0x0b, (byte) 0xe3, (byte) 0xac, (byte) 0xc6, (byte) 0x0f, (byte) 0x57, (byte) 0x4f, (byte) 0xd8, + (byte) 0xd6, (byte) 0xb2, (byte) 0xd0, (byte) 0xca, (byte) 0xd9, (byte) 0x6f, (byte) 0x3f, (byte) 0x6e, + (byte) 0x83, (byte) 0x8c, (byte) 0xff, (byte) 0x47, (byte) 0xca, (byte) 0xbc, (byte) 0x81, (byte) 0x60, + (byte) 0x5f, (byte) 0xe2, (byte) 0xdd, (byte) 0xbd, (byte) 0x89, (byte) 0xb2, (byte) 0x52, (byte) 0xac, + (byte) 0xc3, (byte) 0x8b, (byte) 0x44, (byte) 0x99, (byte) 0x70, (byte) 0xe7, (byte) 0x2c, (byte) 0x52, + (byte) 0x21, (byte) 0xaa, (byte) 0xa2, (byte) 0x0f, (byte) 0x38, (byte) 0xc6, (byte) 0x98, (byte) 0x4d, + (byte) 0x48, (byte) 0xda, (byte) 0x65, (byte) 0x41, (byte) 0xa4, (byte) 0xad, (byte) 0x41, (byte) 0x7c, + (byte) 0x99, (byte) 0x14, (byte) 0xe5, (byte) 0xcb, (byte) 0x51, (byte) 0xd7, (byte) 0xab, (byte) 0x76, + (byte) 0xb1, (byte) 0x20, (byte) 0xce, (byte) 0x32, (byte) 0x1b, (byte) 0x11, (byte) 0x5c, (byte) 0xef, + (byte) 0x8b, (byte) 0x4f, (byte) 0xf3, (byte) 0x46, (byte) 0x5b, (byte) 0x11, (byte) 0xd7, (byte) 0x91, + (byte) 0xb6, (byte) 0x41, (byte) 0xd3, (byte) 0x23, (byte) 0xb6, (byte) 0x03, (byte) 0xa8, (byte) 0x98, + (byte) 0x40, (byte) 0x76, (byte) 0x13, (byte) 0x5d, (byte) 0x4c, (byte) 0xb2, (byte) 0xe9, (byte) 0xfe, + (byte) 0x90, (byte) 0x27, (byte) 0x04, (byte) 0xfc, (byte) 0x10, (byte) 0x45, (byte) 0x8b, (byte) 0x10, + (byte) 0xc3, (byte) 0xb2, (byte) 0x4b, (byte) 0x3c, (byte) 0xd2, (byte) 0x5b, (byte) 0x0f, (byte) 0xe8, + (byte) 0xfb, (byte) 0xb9, (byte) 0x45, (byte) 0xaf, (byte) 0x05, (byte) 0xc4, (byte) 0xba, (byte) 0xc7, + (byte) 0xfc, (byte) 0xa5, (byte) 0x7d, (byte) 0xdb, (byte) 0x4f, (byte) 0xa9, (byte) 0x76, (byte) 0xe2, + (byte) 0xfa, (byte) 0xc7, (byte) 0xe0, (byte) 0xad, (byte) 0x70, (byte) 0xaa, (byte) 0x40, (byte) 0x15, + (byte) 0x64, (byte) 0x01, (byte) 0xba, (byte) 0xc6, (byte) 0xc3, (byte) 0x83, (byte) 0x65, (byte) 0x95, + (byte) 0x3c, (byte) 0x05, (byte) 0x53, (byte) 0x88, (byte) 0xe7, (byte) 0x19, (byte) 0x98 + }; + + protected static final int KID_PIN_SIG = 0x81; + + protected byte[] EF_C_CH_DS = new byte[2000]; + + public ACOSApplSIG() { + // Files + System.arraycopy(C_CH_DS, 0, EF_C_CH_DS, 0, C_CH_DS.length); + putFile(new File(FID_EF_C_CH_DS, EF_C_CH_DS, FCI_EF_C_CH_DS)); + + // PINs + try { + pins.put(KID_PIN_SIG, new PIN(Arrays.copyOf("123456".getBytes("ASCII"), 8), KID_PIN_SIG, 3)); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + + @Override + public byte[] getAID() { + return AID_SIG; + } + + @Override + public byte[] getFID() { + return FID_SIG; + } + + @Override + public byte[] getFCI() { + return FCI; + } + + @Override + public ResponseAPDU cmdPERFORM_SECURITY_OPERATION(CommandAPDU command, CardChannelEmul channel) { + + checkINS(command, 0x2A); + + if (command.getP1() == 0x90 && command.getP2() == 0x81) { + + // PUT HASH + hash = command.getData(); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + + } else if (command.getP1() == 0x9E && command.getP2() == 0x9A) { + + // COMPUTE DIGITAL SIGNATURE + if (securityEnv == null) { + // No security environment + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + if (hash == null) { + // Command sequence not correct + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x03}); + } + if (hash.length != 20) { + // Invalid hash length + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x80}); + } + if (pins.get(KID_PIN_SIG).state != PIN.STATE_PIN_VERIFIED) { + // Security Status not satisfied + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x82}); + } + + byte[] signature = new byte[48]; + + // TODO replace by signature creation + Random random = new Random(); + random.nextBytes(signature); + + byte[] response = new byte[signature.length + 2]; + System.arraycopy(signature, 0, response, 0, signature.length); + response[signature.length] = (byte) 0x90; + response[signature.length + 1] = (byte) 0x00; + + hash = null; + pins.get(KID_PIN_SIG).state = PIN.STATE_RESET; + + return new ResponseAPDU(response); + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x00}); + } + + } + + public void clearCert() { + Arrays.fill(EF_C_CH_DS, (byte) 0x00); + } + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardChannelEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardChannelEmul.java new file mode 100644 index 00000000..25923686 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardChannelEmul.java @@ -0,0 +1,261 @@ +/* +* Copyright 2008 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.acos; + +import java.util.Arrays; + +import javax.smartcardio.Card; +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.AbstractAppl; +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.CardEmul; +import at.gv.egiz.smcc.File; +import at.gv.egiz.smcc.PIN; + +@SuppressWarnings("restriction") +public abstract class ACOSCardChannelEmul extends CardChannelEmul { + + /** + * + */ + protected CardEmul cardEmul; + + public ACOSCardChannelEmul(CardEmul cardEmul) { + this.cardEmul = cardEmul; + } + + @Override + public Card getCard() { + return cardEmul; + } + + protected ResponseAPDU cmdSELECT(CommandAPDU command) throws CardException { + + byte[] fid = command.getData(); + + AbstractAppl appl = cardEmul.getApplication(fid); + if (appl != null) { + if (currentAppl != null && currentAppl != appl) { + currentAppl.leaveApplContext(); + currentFile = null; + } + currentAppl = appl; + + byte[] fci = currentAppl.getFCI(); + byte[] response = new byte[fci.length + 2]; + System.arraycopy(fci, 0, response, 0, fci.length); + response[fci.length] = (byte) 0x90; + response[fci.length + 1] = (byte) 0x00; + return new ResponseAPDU(response); + } + + if (command.getP1() == 0x00) { + // SELECT with FID + if (currentAppl instanceof AbstractAppl) { + + for (File file : ((AbstractAppl) currentAppl).getFiles()) { + + if (Arrays.equals(fid, file.fid)) { + currentFile = file; + byte[] response = new byte[file.fcx.length + 2]; + System.arraycopy(file.fcx, 0, response, 0, file.fcx.length); + response[file.fcx.length] = (byte) 0x90; + response[file.fcx.length + 1] = (byte) 0x00; + return new ResponseAPDU(response); + } + + } + + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x82}); + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x82}); + } + } + + // Not found + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x82}); + + } + + public abstract ResponseAPDU cmdREAD_BINARY(CommandAPDU command) throws CardException; + + + @Override + public ResponseAPDU transmit(CommandAPDU command) throws CardException { + + if (command.getCLA() == 0x00) { + + switch (command.getINS()) { + + // SELECT + case 0xA4: + return cmdSELECT(command); + + // READ BINARY + case 0xB0: + return cmdREAD_BINARY(command); + + // VERIFY + case 0x20: + if ((command.getP2() & 0x80) > 0) { + return cmdVERIFY(command); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + // MANAGE SECURITY ENVIRONMENT + case 0x22: { + if (currentAppl != null) { + return currentAppl.cmdMANAGE_SECURITY_ENVIRONMENT(command, this); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + } + + // CHANGE REFERENCE DATA + case 0x24: { + return cmdCHANGE_REFERENCE_DATA(command); + } + + // PERFORM SECURITY OPERATION + case 0x2A: { + if (currentAppl != null) { + return currentAppl.cmdPERFORM_SECURITY_OPERATION(command, this); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + } + + // INTERNAL AUTHENTICATE + case 0x88: { + if (currentAppl != null) { + return currentAppl.cmdINTERNAL_AUTHENTICATE(command, this); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + } + + default: + return new ResponseAPDU(new byte[] { (byte) 0x6D, (byte) 0x00}); + } + + } else { + return new ResponseAPDU(new byte[] { (byte) 0x6E, (byte) 0x00}); + } + + } + + protected ResponseAPDU verifyPin(int kid, byte[] reference) { + + PIN pin; + if (currentAppl != null) { + pin = currentAppl.pins.get(kid); + } else { + pin = null; + } + + if (pin != null) { + + if (reference.length != 8) { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + if (Arrays.equals(reference, pin.pin)) { + switch (pin.state) { + case PIN.STATE_PIN_BLOCKED: + return new ResponseAPDU(new byte[] { (byte) 0x69, (byte) 0x83 }); + + case PIN.STATE_RESET: + pin.state = PIN.STATE_PIN_VERIFIED; + + default: + pin.kfpc = 10; + return new ResponseAPDU(new byte[] { (byte) 0x90, (byte) 0x00 }); + } + } else { + switch (pin.state) { + case PIN.STATE_PIN_BLOCKED: + return new ResponseAPDU(new byte[] { (byte) 0x69, (byte) 0x83 }); + + default: + if (--pin.kfpc > 0) { + return new ResponseAPDU(new byte[] { (byte) 0x63, (byte) (pin.kfpc | 0xC0)}); + } else { + pin.state = PIN.STATE_PIN_BLOCKED; + return new ResponseAPDU(new byte[] { (byte) 0x69, (byte) 0x83 }); + } + } + + } + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x00}); + } + + } + + public ResponseAPDU cmdVERIFY(CommandAPDU command) throws CardException { + + if (command.getINS() != 0x20) { + throw new IllegalArgumentException("INS has to be 0x20."); + } + + if (command.getP1() != 00) { + return new ResponseAPDU(new byte[] {(byte) 0x6B, (byte) 0x00}); + } + + return verifyPin(command.getP2(), command.getData()); + + } + + public ResponseAPDU cmdCHANGE_REFERENCE_DATA(CommandAPDU command) { + + if (command.getINS() != 0x24) { + throw new IllegalArgumentException("INS has to be 0x24."); + } + + if (command.getP1() == 0x00) { + + byte[] data = command.getData(); + if (data.length != 16) { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + ResponseAPDU response = verifyPin(command.getP2(), Arrays.copyOf(data, 8)); + if (response.getSW() == 0x9000) { + PIN pin; + if (currentAppl != null) { + pin = currentAppl.pins.get(command.getP2()); + } else { + pin = null; + } + pin.pin = Arrays.copyOfRange(data, 8, 16); + } + + return response; + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + } + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardEmul.java new file mode 100644 index 00000000..b9f70a5d --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardEmul.java @@ -0,0 +1,38 @@ +/* +* Copyright 2008 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.acos; + + +import javax.smartcardio.ATR; + +import at.gv.egiz.smcc.CardEmul; + +@SuppressWarnings("restriction") +public abstract class ACOSCardEmul extends CardEmul { + + protected static ATR ATR = new ATR(new byte[] { + (byte) 0x3b, (byte) 0xbf, (byte) 0x11, (byte) 0x00, (byte) 0x81, (byte) 0x31, (byte) 0xfe, (byte) 0x45, + (byte) 0x45, (byte) 0x50, (byte) 0x41, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xf1 + }); + + @Override + public ATR getATR() { + return ATR; + } + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java new file mode 100644 index 00000000..90bb039e --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java @@ -0,0 +1,243 @@ +/* +* Copyright 2008 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.acos; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +import org.junit.Test; + +import at.gv.egiz.smcc.ACOSCard; +import at.gv.egiz.smcc.CardEmul; +import at.gv.egiz.smcc.CardNotSupportedException; +import at.gv.egiz.smcc.CardTest; +import at.gv.egiz.smcc.LockedException; +import at.gv.egiz.smcc.NotActivatedException; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.SignatureCard.KeyboxName; + +public abstract class ACOSCardTest extends CardTest { + + public ACOSCardTest() { + super(); + } + + protected abstract int getVersion(); + + @Test + public void testGetInfoboxIdentityLinkEmpty() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + char[] pin = "0000".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplDEC appl = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); + appl.clearInfobox(); + + byte[] idlink = signatureCard.getInfobox("IdentityLink", + new TestPINProvider(pin), null); + assertNull(idlink); + + } + + @Test(expected = SignatureCardException.class) + public void testGetInfoboxIdentityInvalid() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + char[] pin = "0000".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplDEC appl = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); + appl.setInfoboxHeader((byte) 0xFF); + + signatureCard.getInfobox("IdentityLink", new TestPINProvider(pin), null); + + } + + @Test + public void testGetCerts() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + SignatureCard signatureCard = createSignatureCard(); + + byte[] cert; + + cert = signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); + assertNotNull(cert); + assertTrue(Arrays.equals(cert, A04ApplSIG.C_CH_DS)); + + cert = signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); + assertNotNull(cert); + assertTrue(Arrays.equals(cert, A04ApplDEC.C_CH_EKEY)); + + } + + @Test(expected = NotActivatedException.class) + public void testGetSIGCertEmpty() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplSIG appl = (ACOSApplSIG) card.getApplication(ACOSAppl.AID_SIG); + appl.clearCert(); + + signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); + + } + + @Test(expected = NotActivatedException.class) + public void testGetDECCertEmpty() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplDEC appl = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); + appl.clearCert(); + + signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); + + } + + @Test + public void testSignSIG() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + char[] pin = "123456".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplSIG appl = (ACOSApplSIG) card.getApplication(ACOSAppl.AID_SIG); + appl.setPin(ACOSApplSIG.KID_PIN_SIG, pin); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + byte[] signature = signatureCard.createSignature(hash, + KeyboxName.SECURE_SIGNATURE_KEYPAIR, new TestPINProvider(pin)); + + assertNotNull(signature); + + } + + @Test + public void testSignDEC() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + char[] pin = "1234".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplDEC appl = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); + appl.setPin(ACOSApplDEC.KID_PIN_DEC, pin); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + byte[] signature = signatureCard.createSignature(hash, + KeyboxName.CERITIFIED_KEYPAIR, new TestPINProvider(pin)); + + assertNotNull(signature); + + } + + @Test(expected = LockedException.class) + public void testSignSIGInvalidPin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); + + signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider); + + } + + @Test(expected = LockedException.class) + public void testSignDECInvalidPin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + TestPINProvider pinProvider = new TestPINProvider("0000".toCharArray()); + + signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, + pinProvider); + + } + + @Test(expected = LockedException.class) + public void testSignSIGBlockedPin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplSIG appl = (ACOSApplSIG) card.getApplication(ACOSAppl.AID_SIG); + appl.setPin(ACOSApplSIG.KID_PIN_SIG, null); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); + + signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider); + + } + + @Test(expected = LockedException.class) + public void testSignDECBlockedPin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + ACOSApplDEC appl = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); + appl.setPin(ACOSApplDEC.KID_PIN_DEC, null); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + TestPINProvider pinProvider = new TestPINProvider("0000".toCharArray()); + + signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, + pinProvider); + + } + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTestSuite.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTestSuite.java new file mode 100644 index 00000000..101f7edc --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTestSuite.java @@ -0,0 +1,27 @@ +/* +* Copyright 2008 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.acos; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses( { A03CardTest.class, A04CardTest.class }) +public class ACOSCardTestSuite { + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSAppl.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSAppl.java new file mode 100644 index 00000000..2ca63eea --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSAppl.java @@ -0,0 +1,95 @@ +/* +* Copyright 2008 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.starcos; + +import java.io.UnsupportedEncodingException; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Iterator; + +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.AbstractAppl; +import at.gv.egiz.smcc.CardAppl; +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.PIN; + +@SuppressWarnings("restriction") +public abstract class STARCOSAppl extends AbstractAppl implements CardAppl { + + public static byte[] AID_SichereSignatur = new byte[] { (byte) 0xD0, (byte) 0x40, + (byte) 0x00, (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x12, (byte) 0x01 }; + + public static byte[] FID_SichereSignatur = new byte[] { (byte) 0x3F, (byte) 0x04 }; + + public static byte[] AID_Infobox = new byte[] { (byte) 0xD0, (byte) 0x40, + (byte) 0x00, (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x18, (byte) 0x01 }; + + public static byte[] FID_Infobox = new byte[] { (byte) 0x3F, (byte) 0x06 }; + + public static byte[] AID_GewoehnlicheSignatur = new byte[] { (byte) 0xD0, (byte) 0x40, + (byte) 0x00, (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x13, (byte) 0x01 }; + + public static byte[] FID_GewoehnlicheSignatur = new byte[] { (byte) 0x3F, (byte) 0x05 }; + + protected STARCOSCardChannelEmul channel; + + protected byte[] securityEnv; + + protected byte[] hash; + + public STARCOSAppl(STARCOSCardChannelEmul channel) { + this.channel = channel; + } + + @Override + public ResponseAPDU cmdINTERNAL_AUTHENTICATE(CommandAPDU command, CardChannelEmul channel) { + return new ResponseAPDU(new byte[] {(byte) 0x6D, (byte) 0x00}); + } + + @Override + public void leaveApplContext() { + Iterator pin = pins.values().iterator(); + while (pin.hasNext()) { + pin.next().state = PIN.STATE_RESET; + } + } + + public void setPin(int kid, char[] value) { + PIN pin = pins.get(kid); + if (pin != null) { + if (value == null) { + pin.pin = null; + } else { + byte[] b = new byte[8]; + b[0] = (byte) (0x20 | value.length); + for(int i = 1, j = 0; i < b.length; i++) { + int h = ((j < value.length) + ? Character.digit(value[j++], 10) + : 0x0F); + int l = ((j < value.length) + ? Character.digit(value[j++], 10) + : 0x0F); + b[i] = (byte) ((h << 4) | l); + } + pin.pin = b; + } + } + } + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplGewoehnlicheSignatur.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplGewoehnlicheSignatur.java new file mode 100644 index 00000000..cec305da --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplGewoehnlicheSignatur.java @@ -0,0 +1,332 @@ +/* +* Copyright 2008 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.starcos; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.Random; + +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.File; +import at.gv.egiz.smcc.PIN; + +@SuppressWarnings("restriction") +public class STARCOSApplGewoehnlicheSignatur extends STARCOSAppl { + + private static byte[] FCI = new byte[] { (byte) 0x6f, (byte) 0x14, + (byte) 0x84, (byte) 0x08, (byte) 0xd0, (byte) 0x40, (byte) 0x00, + (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x13, (byte) 0x01, + (byte) 0xa5, (byte) 0x08, (byte) 0x53, (byte) 0x02, (byte) 0x01, + (byte) 0x10, (byte) 0x54, (byte) 0x02, (byte) 0x01, (byte) 0x00 }; + + protected static byte[] FID_EF_C_X509_CH_AUT = new byte[] { (byte) 0x2f, + (byte) 0x01 }; + + protected static byte[] FCI_EF_C_X509_CH_AUT = new byte[] { (byte) 0x62, + (byte) 0x16, (byte) 0x80, (byte) 0x02, (byte) 0x04, (byte) 0x9c, + (byte) 0x82, (byte) 0x01, (byte) 0x01, (byte) 0x83, (byte) 0x02, + (byte) 0x2f, (byte) 0x01, (byte) 0x88, (byte) 0x01, (byte) 0x08, + (byte) 0x8a, (byte) 0x01, (byte) 0x05, (byte) 0xa1, (byte) 0x03, + (byte) 0x8b, (byte) 0x01, (byte) 0x08 }; + + protected static byte[] C_X509_CH_AUT = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x04, (byte) 0x98, (byte) 0x30, (byte) 0x82, (byte) 0x03, (byte) 0x80, + (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x02, + (byte) 0x06, (byte) 0x5f, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, + (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05, + (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0x95, (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, + (byte) 0x54, (byte) 0x31, (byte) 0x48, (byte) 0x30, (byte) 0x46, (byte) 0x06, (byte) 0x03, (byte) 0x55, + (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x3f, (byte) 0x41, (byte) 0x2d, (byte) 0x54, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x47, (byte) 0x65, (byte) 0x73, (byte) 0x2e, + (byte) 0x20, (byte) 0x66, (byte) 0x2e, (byte) 0x20, (byte) 0x53, (byte) 0x69, (byte) 0x63, (byte) 0x68, + (byte) 0x65, (byte) 0x72, (byte) 0x68, (byte) 0x65, (byte) 0x69, (byte) 0x74, (byte) 0x73, (byte) 0x73, + (byte) 0x79, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6d, (byte) 0x65, (byte) 0x20, (byte) 0x69, + (byte) 0x6d, (byte) 0x20, (byte) 0x65, (byte) 0x6c, (byte) 0x65, (byte) 0x6b, (byte) 0x74, (byte) 0x72, + (byte) 0x2e, (byte) 0x20, (byte) 0x44, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x6e, (byte) 0x76, + (byte) 0x65, (byte) 0x72, (byte) 0x6b, (byte) 0x65, (byte) 0x68, (byte) 0x72, (byte) 0x20, (byte) 0x47, + (byte) 0x6d, (byte) 0x62, (byte) 0x48, (byte) 0x31, (byte) 0x1d, (byte) 0x30, (byte) 0x1b, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0b, (byte) 0x0c, (byte) 0x14, (byte) 0x61, (byte) 0x2d, + (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x74, (byte) 0x6f, (byte) 0x6b, + (byte) 0x65, (byte) 0x6e, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, + (byte) 0x30, (byte) 0x33, (byte) 0x31, (byte) 0x1d, (byte) 0x30, (byte) 0x1b, (byte) 0x06, (byte) 0x03, + (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c, (byte) 0x14, (byte) 0x61, (byte) 0x2d, (byte) 0x73, + (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x74, (byte) 0x6f, (byte) 0x6b, (byte) 0x65, + (byte) 0x6e, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x30, + (byte) 0x33, (byte) 0x30, (byte) 0x1e, (byte) 0x17, (byte) 0x0d, (byte) 0x30, (byte) 0x39, (byte) 0x30, + (byte) 0x33, (byte) 0x30, (byte) 0x36, (byte) 0x31, (byte) 0x35, (byte) 0x32, (byte) 0x32, (byte) 0x33, + (byte) 0x38, (byte) 0x5a, (byte) 0x17, (byte) 0x0d, (byte) 0x31, (byte) 0x32, (byte) 0x30, (byte) 0x33, + (byte) 0x30, (byte) 0x36, (byte) 0x31, (byte) 0x35, (byte) 0x32, (byte) 0x32, (byte) 0x33, (byte) 0x38, + (byte) 0x5a, (byte) 0x30, (byte) 0x72, (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x54, + (byte) 0x31, (byte) 0x20, (byte) 0x30, (byte) 0x1e, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, + (byte) 0x03, (byte) 0x0c, (byte) 0x17, (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0xc5, (byte) 0x90, + (byte) 0x7a, (byte) 0x67, (byte) 0xc3, (byte) 0xbc, (byte) 0x72, (byte) 0x20, (byte) 0x58, (byte) 0x58, + (byte) 0x58, (byte) 0x54, (byte) 0xc3, (byte) 0xbc, (byte) 0x7a, (byte) 0x65, (byte) 0x6b, (byte) 0xc3, + (byte) 0xa7, (byte) 0x69, (byte) 0x31, (byte) 0x15, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, + (byte) 0x55, (byte) 0x04, (byte) 0x04, (byte) 0x0c, (byte) 0x0c, (byte) 0x58, (byte) 0x58, (byte) 0x58, + (byte) 0x54, (byte) 0xc3, (byte) 0xbc, (byte) 0x7a, (byte) 0x65, (byte) 0x6b, (byte) 0xc3, (byte) 0xa7, + (byte) 0x69, (byte) 0x31, (byte) 0x13, (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03, (byte) 0x55, + (byte) 0x04, (byte) 0x2a, (byte) 0x0c, (byte) 0x0a, (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0xc5, + (byte) 0x90, (byte) 0x7a, (byte) 0x67, (byte) 0xc3, (byte) 0xbc, (byte) 0x72, (byte) 0x31, (byte) 0x15, + (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x05, (byte) 0x13, + (byte) 0x0c, (byte) 0x37, (byte) 0x30, (byte) 0x34, (byte) 0x38, (byte) 0x37, (byte) 0x31, (byte) 0x30, + (byte) 0x35, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x38, (byte) 0x30, (byte) 0x49, (byte) 0x30, + (byte) 0x13, (byte) 0x06, (byte) 0x07, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x3d, + (byte) 0x02, (byte) 0x01, (byte) 0x06, (byte) 0x08, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, + (byte) 0x3d, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x32, (byte) 0x00, (byte) 0x04, + (byte) 0x02, (byte) 0x55, (byte) 0x51, (byte) 0xf9, (byte) 0x2a, (byte) 0xea, (byte) 0x6f, (byte) 0xd3, + (byte) 0xf5, (byte) 0xda, (byte) 0xa9, (byte) 0x7a, (byte) 0x22, (byte) 0xfc, (byte) 0xb4, (byte) 0x38, + (byte) 0xe9, (byte) 0x5c, (byte) 0xdc, (byte) 0x6b, (byte) 0x86, (byte) 0xa6, (byte) 0x77, (byte) 0xa7, + (byte) 0x90, (byte) 0xf3, (byte) 0x36, (byte) 0xe0, (byte) 0xc4, (byte) 0xde, (byte) 0x72, (byte) 0xf2, + (byte) 0x1a, (byte) 0x07, (byte) 0xfa, (byte) 0xd0, (byte) 0xc8, (byte) 0x1c, (byte) 0xa0, (byte) 0xc8, + (byte) 0x8b, (byte) 0x5d, (byte) 0xde, (byte) 0x9e, (byte) 0xf8, (byte) 0x3b, (byte) 0x7c, (byte) 0x8c, + (byte) 0xa3, (byte) 0x82, (byte) 0x01, (byte) 0xec, (byte) 0x30, (byte) 0x82, (byte) 0x01, (byte) 0xe8, + (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x23, (byte) 0x04, + (byte) 0x0c, (byte) 0x30, (byte) 0x0a, (byte) 0x80, (byte) 0x08, (byte) 0x47, (byte) 0x7e, (byte) 0x5b, + (byte) 0xdb, (byte) 0x37, (byte) 0x33, (byte) 0xb1, (byte) 0xfa, (byte) 0x30, (byte) 0x7e, (byte) 0x06, + (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x01, + (byte) 0x01, (byte) 0x04, (byte) 0x72, (byte) 0x30, (byte) 0x70, (byte) 0x30, (byte) 0x2c, (byte) 0x06, + (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x30, + (byte) 0x01, (byte) 0x86, (byte) 0x20, (byte) 0x68, (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, + (byte) 0x2f, (byte) 0x2f, (byte) 0x6f, (byte) 0x63, (byte) 0x73, (byte) 0x70, (byte) 0x2d, (byte) 0x74, + (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x6f, + (byte) 0x63, (byte) 0x73, (byte) 0x70, (byte) 0x30, (byte) 0x40, (byte) 0x06, (byte) 0x08, (byte) 0x2b, + (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x30, (byte) 0x02, (byte) 0x86, + (byte) 0x34, (byte) 0x68, (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, + (byte) 0x77, (byte) 0x77, (byte) 0x77, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x63, + (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x73, (byte) 0x2f, (byte) 0x61, (byte) 0x2d, (byte) 0x73, + (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x74, (byte) 0x6f, (byte) 0x6b, (byte) 0x65, + (byte) 0x6e, (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x30, + (byte) 0x33, (byte) 0x2e, (byte) 0x63, (byte) 0x72, (byte) 0x74, (byte) 0x30, (byte) 0x81, (byte) 0x86, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x20, (byte) 0x04, (byte) 0x7f, (byte) 0x30, + (byte) 0x7d, (byte) 0x30, (byte) 0x7b, (byte) 0x06, (byte) 0x06, (byte) 0x2a, (byte) 0x28, (byte) 0x00, + (byte) 0x11, (byte) 0x01, (byte) 0x03, (byte) 0x30, (byte) 0x71, (byte) 0x30, (byte) 0x35, (byte) 0x06, + (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x02, + (byte) 0x01, (byte) 0x16, (byte) 0x29, (byte) 0x68, (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, + (byte) 0x2f, (byte) 0x2f, (byte) 0x77, (byte) 0x77, (byte) 0x77, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, + (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, + (byte) 0x2f, (byte) 0x64, (byte) 0x6f, (byte) 0x63, (byte) 0x73, (byte) 0x2f, (byte) 0x63, (byte) 0x70, + (byte) 0x2f, (byte) 0x61, (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, + (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x30, (byte) 0x38, (byte) 0x06, (byte) 0x08, + (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x02, (byte) 0x02, + (byte) 0x30, (byte) 0x2c, (byte) 0x1a, (byte) 0x2a, (byte) 0x44, (byte) 0x69, (byte) 0x65, (byte) 0x73, + (byte) 0x65, (byte) 0x73, (byte) 0x20, (byte) 0x5a, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, + (byte) 0x66, (byte) 0x69, (byte) 0x6b, (byte) 0x61, (byte) 0x74, (byte) 0x20, (byte) 0x64, (byte) 0x69, + (byte) 0x65, (byte) 0x6e, (byte) 0x74, (byte) 0x20, (byte) 0x6e, (byte) 0x75, (byte) 0x72, (byte) 0x20, + (byte) 0x7a, (byte) 0x75, (byte) 0x20, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x7a, + (byte) 0x77, (byte) 0x65, (byte) 0x63, (byte) 0x6b, (byte) 0x65, (byte) 0x6e, (byte) 0x30, (byte) 0x81, + (byte) 0x99, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x1f, (byte) 0x04, (byte) 0x81, + (byte) 0x91, (byte) 0x30, (byte) 0x81, (byte) 0x8e, (byte) 0x30, (byte) 0x81, (byte) 0x8b, (byte) 0xa0, + (byte) 0x81, (byte) 0x88, (byte) 0xa0, (byte) 0x81, (byte) 0x85, (byte) 0x86, (byte) 0x81, (byte) 0x82, + (byte) 0x6c, (byte) 0x64, (byte) 0x61, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, (byte) 0x6c, + (byte) 0x64, (byte) 0x61, (byte) 0x70, (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, + (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, + (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x6f, (byte) 0x75, (byte) 0x3d, (byte) 0x61, + (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x74, (byte) 0x6f, + (byte) 0x6b, (byte) 0x65, (byte) 0x6e, (byte) 0x2d, (byte) 0x30, (byte) 0x33, (byte) 0x2c, (byte) 0x6f, + (byte) 0x3d, (byte) 0x41, (byte) 0x2d, (byte) 0x54, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, + (byte) 0x2c, (byte) 0x63, (byte) 0x3d, (byte) 0x41, (byte) 0x54, (byte) 0x3f, (byte) 0x63, (byte) 0x65, + (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x63, (byte) 0x61, (byte) 0x74, + (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x76, (byte) 0x6f, (byte) 0x63, (byte) 0x61, (byte) 0x74, + (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x6c, (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x3f, + (byte) 0x62, (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x3f, (byte) 0x6f, (byte) 0x62, (byte) 0x6a, + (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x63, (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73, + (byte) 0x3d, (byte) 0x65, (byte) 0x69, (byte) 0x64, (byte) 0x43, (byte) 0x65, (byte) 0x72, (byte) 0x74, + (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x63, (byte) 0x61, (byte) 0x74, (byte) 0x69, (byte) 0x6f, + (byte) 0x6e, (byte) 0x41, (byte) 0x75, (byte) 0x74, (byte) 0x68, (byte) 0x6f, (byte) 0x72, (byte) 0x69, + (byte) 0x74, (byte) 0x79, (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, + (byte) 0x0e, (byte) 0x04, (byte) 0x0a, (byte) 0x04, (byte) 0x08, (byte) 0x4a, (byte) 0x43, (byte) 0x51, + (byte) 0x30, (byte) 0x45, (byte) 0xfc, (byte) 0x2a, (byte) 0x00, (byte) 0x30, (byte) 0x0e, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0f, (byte) 0x01, (byte) 0x01, (byte) 0xff, (byte) 0x04, + (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0xb0, (byte) 0x30, (byte) 0x09, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x13, (byte) 0x04, (byte) 0x02, (byte) 0x30, (byte) 0x00, + (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, + (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x00, (byte) 0x03, + (byte) 0x82, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x31, (byte) 0xdc, (byte) 0xf3, (byte) 0x43, + (byte) 0x79, (byte) 0xdd, (byte) 0xa9, (byte) 0x2a, (byte) 0xdc, (byte) 0x21, (byte) 0xf9, (byte) 0xd9, + (byte) 0x8f, (byte) 0x9a, (byte) 0x4e, (byte) 0x01, (byte) 0x40, (byte) 0x9a, (byte) 0xf1, (byte) 0x14, + (byte) 0x8d, (byte) 0x3a, (byte) 0x5e, (byte) 0x88, (byte) 0x36, (byte) 0x45, (byte) 0x1f, (byte) 0x16, + (byte) 0x3e, (byte) 0xeb, (byte) 0xa2, (byte) 0xef, (byte) 0xbf, (byte) 0x55, (byte) 0xbd, (byte) 0x5e, + (byte) 0x0e, (byte) 0x19, (byte) 0xc7, (byte) 0x0c, (byte) 0xbd, (byte) 0xed, (byte) 0xdf, (byte) 0xb8, + (byte) 0x75, (byte) 0x4e, (byte) 0x6a, (byte) 0x3a, (byte) 0x9a, (byte) 0x10, (byte) 0xfa, (byte) 0x49, + (byte) 0xc1, (byte) 0xd2, (byte) 0x35, (byte) 0xc5, (byte) 0x9a, (byte) 0xd7, (byte) 0xf4, (byte) 0xf0, + (byte) 0xcd, (byte) 0x13, (byte) 0xd1, (byte) 0x24, (byte) 0x06, (byte) 0xf8, (byte) 0x1f, (byte) 0xea, + (byte) 0xd6, (byte) 0x7a, (byte) 0xcb, (byte) 0x4f, (byte) 0xb5, (byte) 0x3e, (byte) 0x6c, (byte) 0xb2, + (byte) 0xfc, (byte) 0xe3, (byte) 0xaa, (byte) 0x2b, (byte) 0x20, (byte) 0x91, (byte) 0xf5, (byte) 0x5b, + (byte) 0xf1, (byte) 0x94, (byte) 0x0e, (byte) 0x06, (byte) 0x0a, (byte) 0xfd, (byte) 0x25, (byte) 0x71, + (byte) 0x11, (byte) 0xfc, (byte) 0x84, (byte) 0x46, (byte) 0xef, (byte) 0x5b, (byte) 0x0b, (byte) 0xa4, + (byte) 0x4a, (byte) 0x5d, (byte) 0x42, (byte) 0x99, (byte) 0xc8, (byte) 0x4e, (byte) 0x51, (byte) 0xd8, + (byte) 0x63, (byte) 0xd1, (byte) 0xbd, (byte) 0x00, (byte) 0xa3, (byte) 0xdd, (byte) 0x8f, (byte) 0x12, + (byte) 0x42, (byte) 0xbe, (byte) 0xca, (byte) 0x15, (byte) 0x37, (byte) 0x4c, (byte) 0xd2, (byte) 0xc9, + (byte) 0xa7, (byte) 0x37, (byte) 0xb2, (byte) 0x76, (byte) 0xb7, (byte) 0x34, (byte) 0x92, (byte) 0x98, + (byte) 0x60, (byte) 0xe7, (byte) 0x3d, (byte) 0x55, (byte) 0xa2, (byte) 0x6c, (byte) 0xb6, (byte) 0x66, + (byte) 0x67, (byte) 0xe1, (byte) 0xe4, (byte) 0x8f, (byte) 0xe3, (byte) 0xa5, (byte) 0xb8, (byte) 0xb5, + (byte) 0xc8, (byte) 0x8f, (byte) 0x9e, (byte) 0xe3, (byte) 0xf1, (byte) 0xaa, (byte) 0x8e, (byte) 0xe6, + (byte) 0xe2, (byte) 0x47, (byte) 0x49, (byte) 0x3d, (byte) 0xbe, (byte) 0x8c, (byte) 0xdd, (byte) 0xce, + (byte) 0x8d, (byte) 0x52, (byte) 0xac, (byte) 0xb9, (byte) 0x83, (byte) 0xe9, (byte) 0x9d, (byte) 0x98, + (byte) 0x7b, (byte) 0xda, (byte) 0x2b, (byte) 0xbc, (byte) 0x83, (byte) 0xcb, (byte) 0x74, (byte) 0x64, + (byte) 0x17, (byte) 0x4c, (byte) 0x33, (byte) 0xbb, (byte) 0x88, (byte) 0xc2, (byte) 0xdd, (byte) 0x08, + (byte) 0x69, (byte) 0xd8, (byte) 0xa2, (byte) 0xac, (byte) 0x95, (byte) 0x71, (byte) 0xd3, (byte) 0xf8, + (byte) 0xc9, (byte) 0xd1, (byte) 0xd6, (byte) 0x0e, (byte) 0xc3, (byte) 0x67, (byte) 0xa1, (byte) 0xdb, + (byte) 0xca, (byte) 0x58, (byte) 0xaa, (byte) 0x4b, (byte) 0xec, (byte) 0x37, (byte) 0x46, (byte) 0x73, + (byte) 0xc3, (byte) 0xa3, (byte) 0x7b, (byte) 0x1e, (byte) 0xdd, (byte) 0xf9, (byte) 0xb3, (byte) 0xbb, + (byte) 0xe0, (byte) 0x16, (byte) 0x39, (byte) 0xaf, (byte) 0xa0, (byte) 0x19, (byte) 0x9e, (byte) 0x89, + (byte) 0x37, (byte) 0x1e, (byte) 0x6e, (byte) 0x41, (byte) 0x59, (byte) 0xe1, (byte) 0x86, (byte) 0xea, + (byte) 0x0b, (byte) 0x39, (byte) 0x03, (byte) 0x89, (byte) 0xd2, (byte) 0xba, (byte) 0xd5, (byte) 0x0c, + (byte) 0x84, (byte) 0x09, (byte) 0xdd, (byte) 0xc7, (byte) 0x00, (byte) 0x2c, (byte) 0x2e, (byte) 0x1a, + (byte) 0x69, (byte) 0xeb, (byte) 0xdf, (byte) 0xb1 + }; + + + protected byte[] EF_C_X509_CH_AUT = new byte[2000]; + + public STARCOSApplGewoehnlicheSignatur(STARCOSCardChannelEmul channel) { + super(channel); + // Files + System.arraycopy(C_X509_CH_AUT, 0, EF_C_X509_CH_AUT, 0, C_X509_CH_AUT.length); + putFile(new File(FID_EF_C_X509_CH_AUT, EF_C_X509_CH_AUT, FCI_EF_C_X509_CH_AUT)); + } + + @Override + public byte[] getAID() { + return AID_GewoehnlicheSignatur; + } + + @Override + public byte[] getFID() { + return FID_GewoehnlicheSignatur; + } + + @Override + public byte[] getFCI() { + return FCI; + } + + public void clearCert() { + Arrays.fill(EF_C_X509_CH_AUT, (byte) 0x00); + } + + @Override + public ResponseAPDU cmdMANAGE_SECURITY_ENVIRONMENT(CommandAPDU command, CardChannelEmul channel) throws CardException { + + checkINS(command, 0x22); + + switch (command.getP2()) { + case 0xA4: + switch (command.getP1()) { + case 0x41: + // INTERNAL AUTHENTICATE + case 0x81: + // EXTERNAL AUTHENTICATE + } + case 0xB6: + switch (command.getP1()) { + case 0x41: { + // PSO - COMPUTE DIGITAL SIGNATURE + byte[] dst = new byte[] { (byte) 0x84, (byte) 0x03, (byte) 0x80, + (byte) 0x02, (byte) 0x00, (byte) 0x89, (byte) 0x03, (byte) 0x13, (byte) 0x35, (byte) 0x10}; + if (Arrays.equals(dst, command.getData())) { + securityEnv = command.getData(); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x80}); + } + } + case 0x81: + // PSO - VERIFY DGITAL SIGNATURE + } + case 0xB8: + switch (command.getP1()) { + case 0x41: + // PSO � DECIPHER + case 0x81: + // PSO � ENCIPHER + } + default: + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + + } + + @Override + public ResponseAPDU cmdPERFORM_SECURITY_OPERATION(CommandAPDU command, CardChannelEmul channel) throws CardException { + + checkINS(command, 0x2A); + + if (command.getP1() == 0x90 && command.getP2() == 0xA0) { + + // HASH + byte[] data = command.getData(); + if (data[0] == (byte) 0x90 && data[1] == (byte) 0x14) { + hash = Arrays.copyOfRange(data, 2, data.length); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } else { + throw new CardException("HASH command only supports complete hash."); + } + + } else if (command.getP1() == 0x9E && command.getP2() == 0x9A) { + + // COMPUTE DIGITAL SIGNATURE + if (securityEnv == null) { + // No security environment + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + if (hash == null) { + // Command sequence not correct + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x03}); + } + if (hash.length != 20) { + // Invalid hash length + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x80}); + } + STARCOSCardChannelEmul c = (STARCOSCardChannelEmul) channel; + if (c.globalPins.get(STARCOSCardChannelEmul.KID_PIN_Glob).state != PIN.STATE_PIN_VERIFIED) { + // Security Status not satisfied + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x82}); + } + + byte[] signature = new byte[48]; + + // TODO replace by signature creation + Random random = new Random(); + random.nextBytes(signature); + + byte[] response = new byte[signature.length + 2]; + System.arraycopy(signature, 0, response, 0, signature.length); + response[signature.length] = (byte) 0x90; + response[signature.length + 1] = (byte) 0x00; + + hash = null; + + return new ResponseAPDU(response); + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x00}); + } + + } + + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplInfobox.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplInfobox.java new file mode 100644 index 00000000..b7835a43 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplInfobox.java @@ -0,0 +1,160 @@ +/* +* Copyright 2008 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.starcos; + +import java.util.Arrays; + +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.File; + +@SuppressWarnings("restriction") +public class STARCOSApplInfobox extends STARCOSAppl { + + public static final byte[] IDLINK = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x11, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x0c, + (byte) 0x26, (byte) 0x68, (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, + (byte) 0x77, (byte) 0x77, (byte) 0x77, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x7a, + (byte) 0x6d, (byte) 0x72, (byte) 0x2f, (byte) 0x70, (byte) 0x65, (byte) 0x72, (byte) 0x73, (byte) 0x62, + (byte) 0x32, (byte) 0x30, (byte) 0x34, (byte) 0x2e, (byte) 0x78, (byte) 0x73, (byte) 0x6c, (byte) 0x0c, + (byte) 0x29, (byte) 0x73, (byte) 0x7a, (byte) 0x72, (byte) 0x2e, (byte) 0x62, (byte) 0x6d, (byte) 0x69, + (byte) 0x2e, (byte) 0x67, (byte) 0x76, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2d, (byte) 0x41, + (byte) 0x73, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, + (byte) 0x49, (byte) 0x44, (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x36, (byte) 0x33, (byte) 0x35, + (byte) 0x36, (byte) 0x33, (byte) 0x36, (byte) 0x36, (byte) 0x37, (byte) 0x39, (byte) 0x39, (byte) 0x39, + (byte) 0x31, (byte) 0x39, (byte) 0x0c, (byte) 0x19, (byte) 0x32, (byte) 0x30, (byte) 0x30, (byte) 0x39, + (byte) 0x2d, (byte) 0x30, (byte) 0x33, (byte) 0x2d, (byte) 0x30, (byte) 0x36, (byte) 0x54, (byte) 0x31, + (byte) 0x36, (byte) 0x3a, (byte) 0x31, (byte) 0x39, (byte) 0x3a, (byte) 0x32, (byte) 0x36, (byte) 0x2b, + (byte) 0x30, (byte) 0x31, (byte) 0x3a, (byte) 0x30, (byte) 0x30, (byte) 0xa0, (byte) 0x42, (byte) 0x30, + (byte) 0x40, (byte) 0x0c, (byte) 0x18, (byte) 0x45, (byte) 0x68, (byte) 0x42, (byte) 0x53, (byte) 0x36, + (byte) 0x54, (byte) 0x6f, (byte) 0x31, (byte) 0x49, (byte) 0x6c, (byte) 0x54, (byte) 0x4b, (byte) 0x4f, + (byte) 0x4a, (byte) 0x45, (byte) 0x39, (byte) 0x75, (byte) 0x62, (byte) 0x74, (byte) 0x48, (byte) 0x69, + (byte) 0x51, (byte) 0x3d, (byte) 0x3d, (byte) 0x0c, (byte) 0x0a, (byte) 0x58, (byte) 0x58, (byte) 0x58, + (byte) 0xc5, (byte) 0x90, (byte) 0x7a, (byte) 0x67, (byte) 0xc3, (byte) 0xbc, (byte) 0x72, (byte) 0x0c, + (byte) 0x0c, (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0x54, (byte) 0xc3, (byte) 0xbc, (byte) 0x7a, + (byte) 0x65, (byte) 0x6b, (byte) 0xc3, (byte) 0xa7, (byte) 0x69, (byte) 0x0c, (byte) 0x0a, (byte) 0x31, + (byte) 0x39, (byte) 0x37, (byte) 0x33, (byte) 0x2d, (byte) 0x30, (byte) 0x36, (byte) 0x2d, (byte) 0x30, + (byte) 0x34, (byte) 0x30, (byte) 0x0a, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x00, + (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x82, (byte) 0x01, + (byte) 0x01, (byte) 0x00, (byte) 0x9f, (byte) 0xa5, (byte) 0x68, (byte) 0xa9, (byte) 0x14, (byte) 0x4c, + (byte) 0xa4, (byte) 0x5d, (byte) 0x9d, (byte) 0x09, (byte) 0x99, (byte) 0x2e, (byte) 0xe7, (byte) 0x45, + (byte) 0x2e, (byte) 0x42, (byte) 0x49, (byte) 0x02, (byte) 0x16, (byte) 0xd9, (byte) 0xcb, (byte) 0x90, + (byte) 0x43, (byte) 0x27, (byte) 0x03, (byte) 0x43, (byte) 0x6d, (byte) 0xb4, (byte) 0x8c, (byte) 0xdc, + (byte) 0x1c, (byte) 0x77, (byte) 0xd4, (byte) 0x2e, (byte) 0xa1, (byte) 0x40, (byte) 0xe7, (byte) 0xe0, + (byte) 0x03, (byte) 0x60, (byte) 0x15, (byte) 0xf7, (byte) 0xdb, (byte) 0x03, (byte) 0x5e, (byte) 0xca, + (byte) 0xe4, (byte) 0x35, (byte) 0xba, (byte) 0x2b, (byte) 0xfd, (byte) 0xe6, (byte) 0xb8, (byte) 0xd8, + (byte) 0xb7, (byte) 0x2a, (byte) 0x80, (byte) 0xdd, (byte) 0x38, (byte) 0xe0, (byte) 0x8a, (byte) 0x69, + (byte) 0xad, (byte) 0x67, (byte) 0x60, (byte) 0x65, (byte) 0x42, (byte) 0xc9, (byte) 0x41, (byte) 0x60, + (byte) 0x94, (byte) 0xde, (byte) 0x84, (byte) 0x54, (byte) 0xad, (byte) 0xb3, (byte) 0xf4, (byte) 0xf7, + (byte) 0x44, (byte) 0xd5, (byte) 0xf3, (byte) 0xd3, (byte) 0xb6, (byte) 0x87, (byte) 0x8a, (byte) 0x22, + (byte) 0x38, (byte) 0x00, (byte) 0xcb, (byte) 0xa4, (byte) 0x4f, (byte) 0x96, (byte) 0xc2, (byte) 0x28, + (byte) 0xc2, (byte) 0x8d, (byte) 0x91, (byte) 0x95, (byte) 0xb4, (byte) 0xea, (byte) 0x00, (byte) 0x59, + (byte) 0x2e, (byte) 0xec, (byte) 0x78, (byte) 0xd8, (byte) 0x0f, (byte) 0x26, (byte) 0x04, (byte) 0xee, + (byte) 0xed, (byte) 0x13, (byte) 0xbf, (byte) 0x81, (byte) 0x68, (byte) 0x81, (byte) 0x43, (byte) 0xbe, + (byte) 0x15, (byte) 0x0e, (byte) 0xba, (byte) 0xf9, (byte) 0x6a, (byte) 0x18, (byte) 0xeb, (byte) 0x95, + (byte) 0xad, (byte) 0xb4, (byte) 0x0f, (byte) 0x3c, (byte) 0x94, (byte) 0x63, (byte) 0x32, (byte) 0x81, + (byte) 0x90, (byte) 0xcf, (byte) 0x3f, (byte) 0x95, (byte) 0xff, (byte) 0x8d, (byte) 0x86, (byte) 0xed, + (byte) 0xe4, (byte) 0x75, (byte) 0xd5, (byte) 0x09, (byte) 0x32, (byte) 0x17, (byte) 0x38, (byte) 0xb2, + (byte) 0x68, (byte) 0x35, (byte) 0x49, (byte) 0x8c, (byte) 0xa6, (byte) 0xd0, (byte) 0x3e, (byte) 0xde, + (byte) 0x6e, (byte) 0x47, (byte) 0x68, (byte) 0xbf, (byte) 0x98, (byte) 0x33, (byte) 0xae, (byte) 0x59, + (byte) 0x9f, (byte) 0xe0, (byte) 0x19, (byte) 0x9b, (byte) 0x5b, (byte) 0x1b, (byte) 0x8f, (byte) 0x74, + (byte) 0xd2, (byte) 0x9c, (byte) 0x01, (byte) 0x1a, (byte) 0xdf, (byte) 0xaf, (byte) 0xf8, (byte) 0x96, + (byte) 0x91, (byte) 0xcb, (byte) 0xf8, (byte) 0xbf, (byte) 0x06, (byte) 0xc7, (byte) 0xd5, (byte) 0x17, + (byte) 0x95, (byte) 0xef, (byte) 0xc5, (byte) 0x97, (byte) 0x37, (byte) 0x1b, (byte) 0xb0, (byte) 0xa1, + (byte) 0x4f, (byte) 0x9f, (byte) 0x01, (byte) 0x82, (byte) 0x90, (byte) 0x4a, (byte) 0x6a, (byte) 0x04, + (byte) 0xdb, (byte) 0x31, (byte) 0x1a, (byte) 0x58, (byte) 0xeb, (byte) 0xcd, (byte) 0x68, (byte) 0xe3, + (byte) 0x68, (byte) 0x0b, (byte) 0xa0, (byte) 0x11, (byte) 0x44, (byte) 0x08, (byte) 0xa0, (byte) 0x5c, + (byte) 0xfc, (byte) 0x61, (byte) 0x15, (byte) 0x1f, (byte) 0xbb, (byte) 0x22, (byte) 0x87, (byte) 0x18, + (byte) 0xa3, (byte) 0x07, (byte) 0x9b, (byte) 0x0d, (byte) 0x13, (byte) 0x7c, (byte) 0xff, (byte) 0x30, + (byte) 0xcf, (byte) 0xf3, (byte) 0xaf, (byte) 0xe4, (byte) 0x45, (byte) 0x05, (byte) 0xa0, (byte) 0x8e, + (byte) 0x6b, (byte) 0xef, (byte) 0x70, (byte) 0xf5, (byte) 0x4b, (byte) 0x68, (byte) 0x8f, (byte) 0x61, + (byte) 0xd6, (byte) 0xf5, (byte) 0xa0, (byte) 0x17, (byte) 0x03, (byte) 0x15, (byte) 0x00, (byte) 0x8e, + (byte) 0xa8, (byte) 0xdf, (byte) 0xa9, (byte) 0x77, (byte) 0xfd, (byte) 0x9b, (byte) 0x4b, (byte) 0x91, + (byte) 0x89, (byte) 0x34, (byte) 0x84, (byte) 0xf3, (byte) 0x24, (byte) 0xb2, (byte) 0x5a, (byte) 0x39, + (byte) 0xa9, (byte) 0xf2, (byte) 0x17, (byte) 0xa1, (byte) 0x17, (byte) 0x03, (byte) 0x15, (byte) 0x00, + (byte) 0xdb, (byte) 0xa2, (byte) 0xfd, (byte) 0xa4, (byte) 0xe7, (byte) 0x65, (byte) 0x2e, (byte) 0x7e, + (byte) 0xb0, (byte) 0xc8, (byte) 0xfa, (byte) 0x4d, (byte) 0x13, (byte) 0x28, (byte) 0xdf, (byte) 0xb1, + (byte) 0x58, (byte) 0x3b, (byte) 0x9e, (byte) 0x29, (byte) 0xa2, (byte) 0x17, (byte) 0x03, (byte) 0x15, + (byte) 0x00, (byte) 0x68, (byte) 0xa0, (byte) 0x17, (byte) 0x18, (byte) 0xb7, (byte) 0xb3, (byte) 0xc3, + (byte) 0x60, (byte) 0x77, (byte) 0x82, (byte) 0x8d, (byte) 0xf1, (byte) 0x5e, (byte) 0x10, (byte) 0xc3, + (byte) 0x2d, (byte) 0x78, (byte) 0x2c, (byte) 0x11, (byte) 0x0b + }; + + private static byte[] FCP = new byte[] { (byte) 0x6f, (byte) 0x14, + (byte) 0x84, (byte) 0x08, (byte) 0xd0, (byte) 0x40, (byte) 0x00, + (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x18, (byte) 0x01, + (byte) 0xa5, (byte) 0x08, (byte) 0x53, (byte) 0x02, (byte) 0x01, + (byte) 0x11, (byte) 0x54, (byte) 0x02, (byte) 0x01, (byte) 0x00 }; + + protected static byte[] FID_EF_IdentityLink = new byte[] { (byte) 0xef, (byte) 0x01 }; + + protected static byte[] FCP_EF_IdentityLink = new byte[] { (byte) 0x62, + (byte) 0x16, (byte) 0x80, (byte) 0x02, (byte) 0x04, (byte) 0x00, + (byte) 0x82, (byte) 0x01, (byte) 0x01, (byte) 0x83, (byte) 0x02, + (byte) 0xef, (byte) 0x01, (byte) 0x88, (byte) 0x01, (byte) 0x08, + (byte) 0x8a, (byte) 0x01, (byte) 0x05, (byte) 0xa1, (byte) 0x03, + (byte) 0x8b, (byte) 0x01, (byte) 0x02 }; + + protected static byte[] EF_IdentityLink = new byte[1500]; + + public STARCOSApplInfobox(STARCOSCardChannelEmul channel) { + super(channel); + System.arraycopy(IDLINK, 0, EF_IdentityLink, 0, IDLINK.length); + putFile(new File(FID_EF_IdentityLink, EF_IdentityLink, FCP_EF_IdentityLink, 0x01)); + } + + @Override + public byte[] getAID() { + return AID_Infobox; + } + + @Override + public byte[] getFID() { + return FID_Infobox; + } + + @Override + public byte[] getFCI() { + return FCP; + } + + public void clearInfobox() { + Arrays.fill(EF_IdentityLink, (byte) 0x00); + } + + public void setInfoboxHeader(byte b) { + EF_IdentityLink[0] = b; + } + + @Override + public ResponseAPDU cmdMANAGE_SECURITY_ENVIRONMENT(CommandAPDU command, CardChannelEmul channel) + throws CardException { + throw new CardException("Not supported."); + } + + @Override + public ResponseAPDU cmdPERFORM_SECURITY_OPERATION(CommandAPDU command, CardChannelEmul channel) + throws CardException { + throw new CardException("Not supported."); + } + + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplSichereSignatur.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplSichereSignatur.java new file mode 100644 index 00000000..9fb5ad37 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplSichereSignatur.java @@ -0,0 +1,347 @@ +/* +* Copyright 2008 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.starcos; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.Random; + +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.File; +import at.gv.egiz.smcc.PIN; + +@SuppressWarnings("restriction") +public class STARCOSApplSichereSignatur extends STARCOSAppl { + + private static byte[] FCI = new byte[] { (byte) 0x6f, (byte) 0x16, + (byte) 0x84, (byte) 0x08, (byte) 0xd0, (byte) 0x40, (byte) 0x00, + (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x12, (byte) 0x01, + (byte) 0xa5, (byte) 0x0a, (byte) 0x53, (byte) 0x02, (byte) 0x01, + (byte) 0x10, (byte) 0x54, (byte) 0x04, (byte) 0x01, (byte) 0x00, + (byte) 0x03, (byte) 0x00 }; + + protected static byte[] FID_EF_C_X509_CH_DS = new byte[] { (byte) 0xc0, + (byte) 0x00 }; + + protected static byte[] FCI_EF_C_X509_CH_DS = new byte[] { (byte) 0x62, + (byte) 0x16, (byte) 0x80, (byte) 0x02, (byte) 0x04, (byte) 0xef, + (byte) 0x82, (byte) 0x01, (byte) 0x01, (byte) 0x83, (byte) 0x02, + (byte) 0xc0, (byte) 0x00, (byte) 0x88, (byte) 0x01, (byte) 0x08, + (byte) 0x8a, (byte) 0x01, (byte) 0x05, (byte) 0xa1, (byte) 0x03, + (byte) 0x8b, (byte) 0x01, (byte) 0x0e }; + + protected static byte[] C_X509_CH_DS = new byte[] { + (byte) 0x30, (byte) 0x82, (byte) 0x04, (byte) 0xeb, (byte) 0x30, (byte) 0x82, (byte) 0x03, (byte) 0xd3, + (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x02, + (byte) 0x06, (byte) 0x5e, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, + (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x05, + (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0xa1, (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, + (byte) 0x54, (byte) 0x31, (byte) 0x48, (byte) 0x30, (byte) 0x46, (byte) 0x06, (byte) 0x03, (byte) 0x55, + (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x3f, (byte) 0x41, (byte) 0x2d, (byte) 0x54, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x47, (byte) 0x65, (byte) 0x73, (byte) 0x2e, + (byte) 0x20, (byte) 0x66, (byte) 0x2e, (byte) 0x20, (byte) 0x53, (byte) 0x69, (byte) 0x63, (byte) 0x68, + (byte) 0x65, (byte) 0x72, (byte) 0x68, (byte) 0x65, (byte) 0x69, (byte) 0x74, (byte) 0x73, (byte) 0x73, + (byte) 0x79, (byte) 0x73, (byte) 0x74, (byte) 0x65, (byte) 0x6d, (byte) 0x65, (byte) 0x20, (byte) 0x69, + (byte) 0x6d, (byte) 0x20, (byte) 0x65, (byte) 0x6c, (byte) 0x65, (byte) 0x6b, (byte) 0x74, (byte) 0x72, + (byte) 0x2e, (byte) 0x20, (byte) 0x44, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x6e, (byte) 0x76, + (byte) 0x65, (byte) 0x72, (byte) 0x6b, (byte) 0x65, (byte) 0x68, (byte) 0x72, (byte) 0x20, (byte) 0x47, + (byte) 0x6d, (byte) 0x62, (byte) 0x48, (byte) 0x31, (byte) 0x23, (byte) 0x30, (byte) 0x21, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0b, (byte) 0x0c, (byte) 0x1a, (byte) 0x61, (byte) 0x2d, + (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, (byte) 0x65, + (byte) 0x6d, (byte) 0x69, (byte) 0x75, (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, + (byte) 0x74, (byte) 0x2d, (byte) 0x53, (byte) 0x69, (byte) 0x67, (byte) 0x2d, (byte) 0x30, (byte) 0x32, + (byte) 0x31, (byte) 0x23, (byte) 0x30, (byte) 0x21, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, + (byte) 0x03, (byte) 0x0c, (byte) 0x1a, (byte) 0x61, (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, + (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, (byte) 0x65, (byte) 0x6d, (byte) 0x69, (byte) 0x75, + (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x53, + (byte) 0x69, (byte) 0x67, (byte) 0x2d, (byte) 0x30, (byte) 0x32, (byte) 0x30, (byte) 0x1e, (byte) 0x17, + (byte) 0x0d, (byte) 0x30, (byte) 0x39, (byte) 0x30, (byte) 0x33, (byte) 0x30, (byte) 0x36, (byte) 0x31, + (byte) 0x35, (byte) 0x32, (byte) 0x32, (byte) 0x33, (byte) 0x37, (byte) 0x5a, (byte) 0x17, (byte) 0x0d, + (byte) 0x31, (byte) 0x32, (byte) 0x30, (byte) 0x33, (byte) 0x30, (byte) 0x36, (byte) 0x31, (byte) 0x35, + (byte) 0x32, (byte) 0x32, (byte) 0x33, (byte) 0x37, (byte) 0x5a, (byte) 0x30, (byte) 0x72, (byte) 0x31, + (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, + (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x54, (byte) 0x31, (byte) 0x20, (byte) 0x30, (byte) 0x1e, + (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c, (byte) 0x17, (byte) 0x58, + (byte) 0x58, (byte) 0x58, (byte) 0xc5, (byte) 0x90, (byte) 0x7a, (byte) 0x67, (byte) 0xc3, (byte) 0xbc, + (byte) 0x72, (byte) 0x20, (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0x54, (byte) 0xc3, (byte) 0xbc, + (byte) 0x7a, (byte) 0x65, (byte) 0x6b, (byte) 0xc3, (byte) 0xa7, (byte) 0x69, (byte) 0x31, (byte) 0x15, + (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x04, (byte) 0x0c, + (byte) 0x0c, (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0x54, (byte) 0xc3, (byte) 0xbc, (byte) 0x7a, + (byte) 0x65, (byte) 0x6b, (byte) 0xc3, (byte) 0xa7, (byte) 0x69, (byte) 0x31, (byte) 0x13, (byte) 0x30, + (byte) 0x11, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x2a, (byte) 0x0c, (byte) 0x0a, + (byte) 0x58, (byte) 0x58, (byte) 0x58, (byte) 0xc5, (byte) 0x90, (byte) 0x7a, (byte) 0x67, (byte) 0xc3, + (byte) 0xbc, (byte) 0x72, (byte) 0x31, (byte) 0x15, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, + (byte) 0x55, (byte) 0x04, (byte) 0x05, (byte) 0x13, (byte) 0x0c, (byte) 0x37, (byte) 0x30, (byte) 0x34, + (byte) 0x38, (byte) 0x37, (byte) 0x31, (byte) 0x30, (byte) 0x35, (byte) 0x30, (byte) 0x30, (byte) 0x30, + (byte) 0x38, (byte) 0x30, (byte) 0x49, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x07, (byte) 0x2a, + (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x3d, (byte) 0x02, (byte) 0x01, (byte) 0x06, (byte) 0x08, + (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x3d, (byte) 0x03, (byte) 0x01, (byte) 0x01, + (byte) 0x03, (byte) 0x32, (byte) 0x00, (byte) 0x04, (byte) 0xde, (byte) 0x75, (byte) 0x22, (byte) 0x4c, + (byte) 0xc4, (byte) 0xd4, (byte) 0x14, (byte) 0x16, (byte) 0x48, (byte) 0x4a, (byte) 0x65, (byte) 0x9d, + (byte) 0x5a, (byte) 0x39, (byte) 0x71, (byte) 0x11, (byte) 0x1c, (byte) 0x33, (byte) 0x7e, (byte) 0x7f, + (byte) 0xb4, (byte) 0x06, (byte) 0x33, (byte) 0x74, (byte) 0xe6, (byte) 0xf3, (byte) 0xc2, (byte) 0x56, + (byte) 0x46, (byte) 0x18, (byte) 0x39, (byte) 0xb9, (byte) 0xc4, (byte) 0x47, (byte) 0x84, (byte) 0xf5, + (byte) 0x46, (byte) 0x41, (byte) 0x60, (byte) 0x78, (byte) 0x81, (byte) 0x45, (byte) 0x4a, (byte) 0x0f, + (byte) 0x67, (byte) 0x77, (byte) 0x77, (byte) 0xb2, (byte) 0xa3, (byte) 0x82, (byte) 0x02, (byte) 0x33, + (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x2f, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, + (byte) 0x55, (byte) 0x1d, (byte) 0x23, (byte) 0x04, (byte) 0x0c, (byte) 0x30, (byte) 0x0a, (byte) 0x80, + (byte) 0x08, (byte) 0x46, (byte) 0x06, (byte) 0x9f, (byte) 0x8e, (byte) 0x41, (byte) 0x8e, (byte) 0x15, + (byte) 0xbd, (byte) 0x30, (byte) 0x27, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, + (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x01, (byte) 0xff, + (byte) 0x04, (byte) 0x18, (byte) 0x30, (byte) 0x16, (byte) 0x30, (byte) 0x08, (byte) 0x06, (byte) 0x06, + (byte) 0x04, (byte) 0x00, (byte) 0x8e, (byte) 0x46, (byte) 0x01, (byte) 0x01, (byte) 0x30, (byte) 0x0a, + (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, + (byte) 0x0b, (byte) 0x01, (byte) 0x30, (byte) 0x81, (byte) 0x84, (byte) 0x06, (byte) 0x08, (byte) 0x2b, + (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x01, (byte) 0x01, (byte) 0x04, + (byte) 0x78, (byte) 0x30, (byte) 0x76, (byte) 0x30, (byte) 0x2c, (byte) 0x06, (byte) 0x08, (byte) 0x2b, + (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x30, (byte) 0x01, (byte) 0x86, + (byte) 0x20, (byte) 0x68, (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, + (byte) 0x6f, (byte) 0x63, (byte) 0x73, (byte) 0x70, (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, + (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, + (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x6f, (byte) 0x63, (byte) 0x73, + (byte) 0x70, (byte) 0x30, (byte) 0x46, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, (byte) 0x01, + (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x30, (byte) 0x02, (byte) 0x86, (byte) 0x3a, (byte) 0x68, + (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, (byte) 0x77, (byte) 0x77, + (byte) 0x77, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, + (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x63, (byte) 0x65, (byte) 0x72, + (byte) 0x74, (byte) 0x73, (byte) 0x2f, (byte) 0x61, (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, + (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, (byte) 0x65, (byte) 0x6d, (byte) 0x69, (byte) 0x75, + (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x53, + (byte) 0x69, (byte) 0x67, (byte) 0x2d, (byte) 0x30, (byte) 0x32, (byte) 0x2e, (byte) 0x63, (byte) 0x72, + (byte) 0x74, (byte) 0x30, (byte) 0x81, (byte) 0x92, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, + (byte) 0x20, (byte) 0x04, (byte) 0x81, (byte) 0x8a, (byte) 0x30, (byte) 0x81, (byte) 0x87, (byte) 0x30, + (byte) 0x7b, (byte) 0x06, (byte) 0x06, (byte) 0x2a, (byte) 0x28, (byte) 0x00, (byte) 0x11, (byte) 0x01, + (byte) 0x03, (byte) 0x30, (byte) 0x71, (byte) 0x30, (byte) 0x35, (byte) 0x06, (byte) 0x08, (byte) 0x2b, + (byte) 0x06, (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x02, (byte) 0x01, (byte) 0x16, + (byte) 0x29, (byte) 0x68, (byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, + (byte) 0x77, (byte) 0x77, (byte) 0x77, (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x64, + (byte) 0x6f, (byte) 0x63, (byte) 0x73, (byte) 0x2f, (byte) 0x63, (byte) 0x70, (byte) 0x2f, (byte) 0x61, + (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x74, (byte) 0x65, + (byte) 0x73, (byte) 0x74, (byte) 0x30, (byte) 0x38, (byte) 0x06, (byte) 0x08, (byte) 0x2b, (byte) 0x06, + (byte) 0x01, (byte) 0x05, (byte) 0x05, (byte) 0x07, (byte) 0x02, (byte) 0x02, (byte) 0x30, (byte) 0x2c, + (byte) 0x1a, (byte) 0x2a, (byte) 0x44, (byte) 0x69, (byte) 0x65, (byte) 0x73, (byte) 0x65, (byte) 0x73, + (byte) 0x20, (byte) 0x5a, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, + (byte) 0x6b, (byte) 0x61, (byte) 0x74, (byte) 0x20, (byte) 0x64, (byte) 0x69, (byte) 0x65, (byte) 0x6e, + (byte) 0x74, (byte) 0x20, (byte) 0x6e, (byte) 0x75, (byte) 0x72, (byte) 0x20, (byte) 0x7a, (byte) 0x75, + (byte) 0x20, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x7a, (byte) 0x77, (byte) 0x65, + (byte) 0x63, (byte) 0x6b, (byte) 0x65, (byte) 0x6e, (byte) 0x30, (byte) 0x08, (byte) 0x06, (byte) 0x06, + (byte) 0x04, (byte) 0x00, (byte) 0x8b, (byte) 0x30, (byte) 0x01, (byte) 0x01, (byte) 0x30, (byte) 0x81, + (byte) 0xa4, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x1f, (byte) 0x04, (byte) 0x81, + (byte) 0x9c, (byte) 0x30, (byte) 0x81, (byte) 0x99, (byte) 0x30, (byte) 0x81, (byte) 0x96, (byte) 0xa0, + (byte) 0x81, (byte) 0x93, (byte) 0xa0, (byte) 0x81, (byte) 0x90, (byte) 0x86, (byte) 0x81, (byte) 0x8d, + (byte) 0x6c, (byte) 0x64, (byte) 0x61, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f, (byte) 0x6c, + (byte) 0x64, (byte) 0x61, (byte) 0x70, (byte) 0x2d, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, + (byte) 0x2e, (byte) 0x61, (byte) 0x2d, (byte) 0x74, (byte) 0x72, (byte) 0x75, (byte) 0x73, (byte) 0x74, + (byte) 0x2e, (byte) 0x61, (byte) 0x74, (byte) 0x2f, (byte) 0x6f, (byte) 0x75, (byte) 0x3d, (byte) 0x61, + (byte) 0x2d, (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x2d, (byte) 0x50, (byte) 0x72, + (byte) 0x65, (byte) 0x6d, (byte) 0x69, (byte) 0x75, (byte) 0x6d, (byte) 0x2d, (byte) 0x54, (byte) 0x65, + (byte) 0x73, (byte) 0x74, (byte) 0x2d, (byte) 0x53, (byte) 0x69, (byte) 0x67, (byte) 0x2d, (byte) 0x30, + (byte) 0x32, (byte) 0x2c, (byte) 0x6f, (byte) 0x3d, (byte) 0x41, (byte) 0x2d, (byte) 0x54, (byte) 0x72, + (byte) 0x75, (byte) 0x73, (byte) 0x74, (byte) 0x2c, (byte) 0x63, (byte) 0x3d, (byte) 0x41, (byte) 0x54, + (byte) 0x3f, (byte) 0x63, (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, + (byte) 0x63, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x76, (byte) 0x6f, + (byte) 0x63, (byte) 0x61, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x6c, (byte) 0x69, + (byte) 0x73, (byte) 0x74, (byte) 0x3f, (byte) 0x62, (byte) 0x61, (byte) 0x73, (byte) 0x65, (byte) 0x3f, + (byte) 0x6f, (byte) 0x62, (byte) 0x6a, (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x63, (byte) 0x6c, + (byte) 0x61, (byte) 0x73, (byte) 0x73, (byte) 0x3d, (byte) 0x65, (byte) 0x69, (byte) 0x64, (byte) 0x43, + (byte) 0x65, (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x63, (byte) 0x61, + (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x41, (byte) 0x75, (byte) 0x74, (byte) 0x68, + (byte) 0x6f, (byte) 0x72, (byte) 0x69, (byte) 0x74, (byte) 0x79, (byte) 0x30, (byte) 0x11, (byte) 0x06, + (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0e, (byte) 0x04, (byte) 0x0a, (byte) 0x04, (byte) 0x08, + (byte) 0x47, (byte) 0x64, (byte) 0x6e, (byte) 0xbb, (byte) 0x92, (byte) 0xa0, (byte) 0xf6, (byte) 0xf4, + (byte) 0x30, (byte) 0x0e, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0f, (byte) 0x01, + (byte) 0x01, (byte) 0xff, (byte) 0x04, (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x06, (byte) 0xc0, + (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x13, (byte) 0x04, + (byte) 0x02, (byte) 0x30, (byte) 0x00, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, + (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x05, + (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x82, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x06, + (byte) 0x63, (byte) 0x76, (byte) 0x0a, (byte) 0xd5, (byte) 0x54, (byte) 0xfa, (byte) 0x51, (byte) 0x2a, + (byte) 0xb0, (byte) 0x41, (byte) 0xdc, (byte) 0xa4, (byte) 0x9b, (byte) 0x52, (byte) 0x1c, (byte) 0x0e, + (byte) 0x1d, (byte) 0x65, (byte) 0x46, (byte) 0x2b, (byte) 0xa3, (byte) 0xcd, (byte) 0xd4, (byte) 0x46, + (byte) 0x36, (byte) 0x40, (byte) 0xc3, (byte) 0x49, (byte) 0xe8, (byte) 0xa4, (byte) 0xdc, (byte) 0x01, + (byte) 0xde, (byte) 0x70, (byte) 0x97, (byte) 0x31, (byte) 0xb0, (byte) 0xcd, (byte) 0xdf, (byte) 0x69, + (byte) 0xf8, (byte) 0xc3, (byte) 0x83, (byte) 0xee, (byte) 0xc6, (byte) 0xed, (byte) 0xe3, (byte) 0x18, + (byte) 0x1a, (byte) 0x80, (byte) 0xc1, (byte) 0x30, (byte) 0xa9, (byte) 0xd6, (byte) 0xb1, (byte) 0xb8, + (byte) 0xa8, (byte) 0xe0, (byte) 0x3d, (byte) 0xb1, (byte) 0x8e, (byte) 0x2c, (byte) 0xc9, (byte) 0xa6, + (byte) 0x05, (byte) 0x6e, (byte) 0x4a, (byte) 0xd2, (byte) 0xb2, (byte) 0x03, (byte) 0xa4, (byte) 0x2b, + (byte) 0xa2, (byte) 0xad, (byte) 0xad, (byte) 0xe5, (byte) 0xba, (byte) 0x0d, (byte) 0x54, (byte) 0x8d, + (byte) 0x92, (byte) 0x51, (byte) 0xda, (byte) 0x58, (byte) 0xed, (byte) 0xd3, (byte) 0x8d, (byte) 0x61, + (byte) 0xa1, (byte) 0xfc, (byte) 0x49, (byte) 0xf6, (byte) 0x80, (byte) 0xdb, (byte) 0x65, (byte) 0x92, + (byte) 0xe0, (byte) 0xd5, (byte) 0x23, (byte) 0x69, (byte) 0x0f, (byte) 0x38, (byte) 0x11, (byte) 0x61, + (byte) 0x1e, (byte) 0xcd, (byte) 0xa2, (byte) 0x8e, (byte) 0x68, (byte) 0xec, (byte) 0x70, (byte) 0xfb, + (byte) 0x55, (byte) 0x95, (byte) 0xcb, (byte) 0xb4, (byte) 0x18, (byte) 0x6b, (byte) 0x3a, (byte) 0x25, + (byte) 0x4a, (byte) 0x3e, (byte) 0x07, (byte) 0xb0, (byte) 0x18, (byte) 0x26, (byte) 0x51, (byte) 0x39, + (byte) 0x46, (byte) 0xfa, (byte) 0xe2, (byte) 0xae, (byte) 0xe6, (byte) 0x1c, (byte) 0xd2, (byte) 0xcb, + (byte) 0x28, (byte) 0xa1, (byte) 0x8b, (byte) 0x56, (byte) 0xbb, (byte) 0xe9, (byte) 0x6c, (byte) 0xf7, + (byte) 0x0b, (byte) 0x84, (byte) 0xdd, (byte) 0x7f, (byte) 0x64, (byte) 0x8b, (byte) 0x43, (byte) 0x93, + (byte) 0x62, (byte) 0x39, (byte) 0xfb, (byte) 0x91, (byte) 0xfa, (byte) 0x3a, (byte) 0x57, (byte) 0x56, + (byte) 0x4a, (byte) 0xaa, (byte) 0x99, (byte) 0x1e, (byte) 0x9b, (byte) 0xcc, (byte) 0xa4, (byte) 0xc0, + (byte) 0x18, (byte) 0x46, (byte) 0xae, (byte) 0x15, (byte) 0x24, (byte) 0xf5, (byte) 0xf3, (byte) 0xe6, + (byte) 0x36, (byte) 0x55, (byte) 0x29, (byte) 0xa8, (byte) 0xa9, (byte) 0xaf, (byte) 0x7b, (byte) 0x44, + (byte) 0x19, (byte) 0xda, (byte) 0x66, (byte) 0x4d, (byte) 0x11, (byte) 0x89, (byte) 0x28, (byte) 0x34, + (byte) 0x01, (byte) 0x15, (byte) 0x24, (byte) 0x93, (byte) 0x43, (byte) 0x6a, (byte) 0x8f, (byte) 0xe4, + (byte) 0x54, (byte) 0x3a, (byte) 0x3d, (byte) 0x9b, (byte) 0x2f, (byte) 0xc3, (byte) 0xdb, (byte) 0x7e, + (byte) 0x5e, (byte) 0x12, (byte) 0x00, (byte) 0xaa, (byte) 0xe7, (byte) 0xc1, (byte) 0x82, (byte) 0x1c, + (byte) 0x1d, (byte) 0x1d, (byte) 0x23, (byte) 0x1d, (byte) 0xa3, (byte) 0xcc, (byte) 0x59, (byte) 0xe4, + (byte) 0x7a, (byte) 0xf0, (byte) 0x14, (byte) 0x17, (byte) 0xfb, (byte) 0x96, (byte) 0x90, (byte) 0xc1, + (byte) 0xc0, (byte) 0xde, (byte) 0xdb, (byte) 0x91, (byte) 0xfb, (byte) 0x49, (byte) 0x39, (byte) 0x70, + (byte) 0x76, (byte) 0x2f, (byte) 0x7b, (byte) 0x22, (byte) 0xcd, (byte) 0x35, (byte) 0xcb, (byte) 0xed, + (byte) 0x8f, (byte) 0xb3, (byte) 0x66, (byte) 0xae, (byte) 0x95, (byte) 0x49, (byte) 0x75 + }; + + protected static final int KID_PIN_SS = 0x81; + + protected byte[] EF_C_X509_CH_DS = new byte[2000]; + + public STARCOSApplSichereSignatur(STARCOSCardChannelEmul channel) { + super(channel); + // Files + System.arraycopy(C_X509_CH_DS, 0, EF_C_X509_CH_DS, 0, C_X509_CH_DS.length); + putFile(new File(FID_EF_C_X509_CH_DS, EF_C_X509_CH_DS, FCI_EF_C_X509_CH_DS)); + + // PINs + pins.put(KID_PIN_SS, new PIN(new byte[] { (byte) 0x24, (byte) 0x12, + (byte) 0x34, (byte) 0x56, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF }, KID_PIN_SS, 3)); + } + + @Override + public byte[] getAID() { + return AID_SichereSignatur; + } + + @Override + public byte[] getFID() { + return FID_SichereSignatur; + } + + @Override + public byte[] getFCI() { + return FCI; + } + + @Override + public ResponseAPDU cmdPERFORM_SECURITY_OPERATION(CommandAPDU command, CardChannelEmul channel) throws CardException { + + checkINS(command, 0x2A); + + if (command.getP1() == 0x90 && command.getP2() == 0xA0) { + + // HASH + byte[] data = command.getData(); + if (data[0] == (byte) 0x90 && data[1] == (byte) 0x14) { + hash = Arrays.copyOfRange(data, 2, data.length); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } else { + throw new CardException("HASH command only supports complete hash."); + } + + } else if (command.getP1() == 0x9E && command.getP2() == 0x9A) { + + // COMPUTE DIGITAL SIGNATURE + if (securityEnv == null) { + // No security environment + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + if (hash == null) { + // Command sequence not correct + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x03}); + } + if (hash.length != 20) { + // Invalid hash length + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x80}); + } + if (pins.get(KID_PIN_SS).state != PIN.STATE_PIN_VERIFIED) { + // Security Status not satisfied + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x82}); + } + + byte[] signature = new byte[48]; + + // TODO replace by signature creation + Random random = new Random(); + random.nextBytes(signature); + + byte[] response = new byte[signature.length + 2]; + System.arraycopy(signature, 0, response, 0, signature.length); + response[signature.length] = (byte) 0x90; + response[signature.length + 1] = (byte) 0x00; + + hash = null; + pins.get(KID_PIN_SS).state = PIN.STATE_RESET; + + return new ResponseAPDU(response); + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x00}); + } + + } + + public void clearCert() { + Arrays.fill(EF_C_X509_CH_DS, (byte) 0x00); + } + + @Override + public ResponseAPDU cmdMANAGE_SECURITY_ENVIRONMENT(CommandAPDU command, CardChannelEmul channel) throws CardException { + + checkINS(command, 0x22); + + switch (command.getP2()) { + case 0xA4: + switch (command.getP1()) { + case 0x41: + // INTERNAL AUTHENTICATE + case 0x81: + // EXTERNAL AUTHENTICATE + } + case 0xB6: + switch (command.getP1()) { + case 0x41: { + // PSO - COMPUTE DIGITAL SIGNATURE + byte[] dst = new byte[] { (byte) 0x84, (byte) 0x03, (byte) 0x80, + (byte) 0x02, (byte) 0x00, (byte) 0x89, (byte) 0x03, (byte) 0x13, (byte) 0x35, (byte) 0x10}; + if (Arrays.equals(dst, command.getData())) { + securityEnv = command.getData(); + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x80}); + } + } + case 0x81: + // PSO - VERIFY DGITAL SIGNATURE + } + case 0xB8: + switch (command.getP1()) { + case 0x41: + // PSO � DECIPHER + case 0x81: + // PSO � ENCIPHER + } + default: + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x81}); + } + + } + +} \ No newline at end of file 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 new file mode 100644 index 00000000..89030894 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardChannelEmul.java @@ -0,0 +1,375 @@ +/* +* Copyright 2008 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.starcos; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.HashMap; + +import javax.smartcardio.Card; +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +import at.gv.egiz.smcc.AbstractAppl; +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.CardEmul; +import at.gv.egiz.smcc.File; +import at.gv.egiz.smcc.PIN; + +@SuppressWarnings("restriction") +public class STARCOSCardChannelEmul extends CardChannelEmul { + + public static final int KID_PIN_Glob = 0x01; + + /** + * + */ + protected CardEmul cardEmul; + + public final HashMap globalPins = new HashMap(); + + public STARCOSCardChannelEmul(CardEmul cardEmul) { + this.cardEmul = cardEmul; + globalPins.put(KID_PIN_Glob, new PIN(new byte[] { (byte) 0x24, (byte) 0x00, + (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF }, KID_PIN_Glob, 10)); + } + + @Override + public Card getCard() { + return cardEmul; + } + + protected ResponseAPDU cmdSELECT(CommandAPDU command) throws CardException { + + byte[] fid = command.getData(); + + switch (command.getP1()) { + case 0x00: // MF + if (fid.length !=0) { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x80}); + } else { + currentFile = null; + currentAppl = null; + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } + + case 0x01: // Lower-level DF + throw new CardException("Not supported."); + + case 0x02: // EF in current DF + if (currentAppl != null) { + if (command.getP2() != 0x04) { + throw new CardException("Not supported."); + } + for (File file : currentAppl.getFiles()) { + if (Arrays.equals(fid, file.fid)) { + currentFile = file; + byte[] response = new byte[file.fcx.length + 2]; + System.arraycopy(file.fcx, 0, response, 0, file.fcx.length); + response[file.fcx.length] = (byte) 0x90; + response[file.fcx.length + 1] = (byte) 0x00; + return new ResponseAPDU(response); + } + } + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x82}); + } else { + throw new CardException("Not supported."); + } + + case 0x03: // Higher-level DF + throw new CardException("Not supported."); + + case 0x04: // Selection by DF name + AbstractAppl appl = cardEmul.getApplication(fid); + if (appl != null) { + if (command.getP2() != 0x00) { + throw new CardException("Not supported."); + } + if (currentAppl != null && currentAppl != appl) { + currentAppl.leaveApplContext(); + currentFile = null; + } + currentAppl = appl; + + byte[] fci = currentAppl.getFCI(); + byte[] response = new byte[fci.length + 2]; + System.arraycopy(fci, 0, response, 0, fci.length); + response[fci.length] = (byte) 0x90; + response[fci.length + 1] = (byte) 0x00; + return new ResponseAPDU(response); + } + + default: + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x86}); + } + + } + + protected ResponseAPDU cmdREAD_BINARY(CommandAPDU command) throws CardException { + + if (command.getINS() != 0xB0) { + throw new IllegalArgumentException("INS has to be 0xB0."); + } + + if (currentFile == null) { + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x86}); + } + + if ((command.getP1() & 0x80) > 0) { + throw new CardException("Not implemented."); + } + + int offset = command.getP2() + (command.getP1() << 8); + if (offset > currentFile.file.length) { + // Wrong length + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + if (command.getNe() == 0) { + throw new CardException("Not implemented."); + } + + if (currentFile.kid != -1) { + PIN pin; + if ((currentFile.kid & 0x80) > 0) { + if (currentAppl == null + || (pin = currentAppl.pins.get(currentFile.kid)) == null + || pin.state != PIN.STATE_PIN_VERIFIED) { + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x82}); + } + } else { + if ((pin = globalPins.get(currentFile.kid)) == null + || pin.state != PIN.STATE_PIN_VERIFIED) { + return new ResponseAPDU(new byte[] {(byte) 0x69, (byte) 0x82}); + } + } + } + + if (command.getNe() == 256 || command.getNe() <= currentFile.file.length - offset) { + int len = Math.min(command.getNe(), currentFile.file.length - offset); + byte[] response = new byte[len + 2]; + System.arraycopy(currentFile.file, offset, response, 0, len); + response[len] = (byte) 0x90; + response[len + 1] = (byte) 0x00; + return new ResponseAPDU(response); + } else if (command.getNe() >= currentFile.file.length - offset) { + return new ResponseAPDU(new byte[] {(byte) 0x62, (byte) 0x82}); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + } + + + @Override + public ResponseAPDU transmit(CommandAPDU command) throws CardException { + + if (command.getCLA() == 0x00) { + + switch (command.getINS()) { + + // SELECT + case 0xA4: + return cmdSELECT(command); + + // READ BINARY + case 0xB0: + return cmdREAD_BINARY(command); + + // VERIFY + case 0x20: + return cmdVERIFY(command); + + // MANAGE SECURITY ENVIRONMENT + case 0x22: { + if (currentAppl != null) { + return currentAppl.cmdMANAGE_SECURITY_ENVIRONMENT(command, this); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + } + + // CHANGE REFERENCE DATA + case 0x24: { + return cmdCHANGE_REFERENCE_DATA(command); + } + + // PERFORM SECURITY OPERATION + case 0x2A: { + if (currentAppl != null) { + return currentAppl.cmdPERFORM_SECURITY_OPERATION(command, this); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + } + + // INTERNAL AUTHENTICATE + case 0x88: { + if (currentAppl != null) { + return currentAppl.cmdINTERNAL_AUTHENTICATE(command, this); + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6F, (byte) 0x05}); + } + } + + default: + return new ResponseAPDU(new byte[] { (byte) 0x6D, (byte) 0x00}); + } + + } else { + return new ResponseAPDU(new byte[] { (byte) 0x6E, (byte) 0x00}); + } + + } + + protected ResponseAPDU verifyPin(int kid, byte[] reference) { + + PIN pin; + if ((kid & 0x80) > 0 && currentAppl != null) { + pin = currentAppl.pins.get(kid); + } else { + pin = globalPins.get(kid); + } + + if (pin != null) { + + if (reference.length == 0) { + return new ResponseAPDU(new byte[] { (byte) 0x63, (byte) (pin.kfpc | 0xC0)}); + } + + if (reference.length != 8) { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + if (Arrays.equals(reference, pin.pin)) { + switch (pin.state) { + case PIN.STATE_PIN_BLOCKED: + return new ResponseAPDU(new byte[] { (byte) 0x69, (byte) 0x83 }); + + case PIN.STATE_RESET: + pin.state = PIN.STATE_PIN_VERIFIED; + + default: + pin.kfpc = 10; + return new ResponseAPDU(new byte[] { (byte) 0x90, (byte) 0x00 }); + } + } else { + switch (pin.state) { + case PIN.STATE_PIN_BLOCKED: + return new ResponseAPDU(new byte[] { (byte) 0x69, (byte) 0x83 }); + + default: + if (--pin.kfpc > 0) { + return new ResponseAPDU(new byte[] { (byte) 0x63, (byte) (pin.kfpc | 0xC0)}); + } else { + pin.state = PIN.STATE_PIN_BLOCKED; + return new ResponseAPDU(new byte[] { (byte) 0x69, (byte) 0x83 }); + } + } + + } + + } else { + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x00}); + } + + } + + protected ResponseAPDU cmdVERIFY(CommandAPDU command) throws CardException { + + if (command.getINS() != 0x20) { + throw new IllegalArgumentException("INS has to be 0x20."); + } + + if (command.getP1() != 00) { + return new ResponseAPDU(new byte[] {(byte) 0x6B, (byte) 0x00}); + } + + return verifyPin(command.getP2(), command.getData()); + + } + + protected ResponseAPDU cmdCHANGE_REFERENCE_DATA(CommandAPDU command) { + + if (command.getINS() != 0x24) { + throw new IllegalArgumentException("INS has to be 0x24."); + } + + byte[] data = command.getData(); + + ResponseAPDU response; + + if (command.getP1() == 0x01) { + + if (data.length != 8) { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + response = verifyPin(0xFF & command.getP2(), data); + + } else if (command.getP1() == 0x00) { + + if (data.length != 16) { + return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); + } + + response = verifyPin(0xFF & command.getP2(), Arrays.copyOf(data, 8)); + + } else { + return new ResponseAPDU(new byte[] { (byte) 0x6A, (byte) 0x81 }); + } + + if (response.getSW() == 0x9000) { + PIN pin; + if (currentAppl != null) { + pin = currentAppl.pins.get(command.getP2()); + } else { + pin = globalPins.get(command.getP2()); + } + pin.pin = Arrays.copyOfRange(data, 8, 16); + } + + return response; + + } + + public void setPin(int kid, char[] value) { + PIN pin = globalPins.get(kid); + if (pin != null) { + if (value == null) { + pin.pin = null; + } else { + byte[] b = new byte[8]; + b[0] = (byte) (0x20 | value.length); + for(int i = 1, j = 0; i < b.length; i++) { + int h = ((j < value.length) + ? Character.digit(value[j++], 10) + : 0x0F); + int l = ((j < value.length) + ? Character.digit(value[j++], 10) + : 0x0F); + b[i] = (byte) ((h << 4) | l); + } + pin.pin = b; + } + } + } + + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardEmul.java new file mode 100644 index 00000000..7b2f3fbe --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardEmul.java @@ -0,0 +1,50 @@ +/* +* Copyright 2008 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.starcos; + + +import javax.smartcardio.ATR; + +import at.gv.egiz.smcc.CardChannelEmul; +import at.gv.egiz.smcc.CardEmul; + +@SuppressWarnings("restriction") +public class STARCOSCardEmul extends CardEmul { + + protected static ATR ATR = new ATR(new byte[] { + (byte) 0x3b, (byte) 0xbd, (byte) 0x18, (byte) 0x00, (byte) 0x81, (byte) 0x31, (byte) 0xfe, (byte) 0x45, + (byte) 0x80, (byte) 0x51, (byte) 0x02, (byte) 0x67, (byte) 0x05, (byte) 0x18, (byte) 0xb1, (byte) 0x02, + (byte) 0x02, (byte) 0x02, (byte) 0x01, (byte) 0x81, (byte) 0x05, (byte) 0x31 + }); + + public STARCOSCardEmul() { + applications.add(new STARCOSApplSichereSignatur((STARCOSCardChannelEmul) channel)); + applications.add(new STARCOSApplInfobox((STARCOSCardChannelEmul) channel)); + applications.add(new STARCOSApplGewoehnlicheSignatur((STARCOSCardChannelEmul) channel)); + } + + @Override + public ATR getATR() { + return ATR; + } + + @Override + protected CardChannelEmul newCardChannel(CardEmul cardEmul) { + return new STARCOSCardChannelEmul(this); + } + +} \ No newline at end of file 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 new file mode 100644 index 00000000..0fb4f62d --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardTest.java @@ -0,0 +1,297 @@ +/* +* Copyright 2008 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.starcos; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +import javax.smartcardio.CardChannel; + +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; +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.STARCOSCard; +import at.gv.egiz.smcc.SignatureCard; +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.SignatureCard.KeyboxName; +import at.gv.egiz.smcc.acos.A03ApplDEC; +import at.gv.egiz.smcc.acos.A04ApplDEC; +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; + +public class STARCOSCardTest extends CardTest { + + @Override + protected SignatureCard createSignatureCard() + throws CardNotSupportedException { + SignatureCardFactory factory = SignatureCardFactory.getInstance(); + STARCOSCardEmul card = new STARCOSCardEmul(); + SignatureCard signatureCard = factory.createSignatureCard(card, + new CardTerminalEmul(card)); + assertTrue(signatureCard instanceof PINMgmtSignatureCard); + return signatureCard; + } + + @Test + public void testGetInfoboxIdentityLinkEmpty() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + char[] pin = "0000".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + STARCOSApplInfobox appl = (STARCOSApplInfobox) card.getApplication(STARCOSAppl.AID_Infobox); + appl.clearInfobox(); + + byte[] idlink = signatureCard.getInfobox("IdentityLink", + new TestPINProvider(pin), null); + assertNull(idlink); + + } + + @Test(expected = SignatureCardException.class) + public void testGetInfoboxIdentityInvalid() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + char[] pin = "0000".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + STARCOSApplInfobox appl = (STARCOSApplInfobox) card.getApplication(STARCOSAppl.AID_Infobox); + appl.setInfoboxHeader((byte) 0xFF); + + signatureCard.getInfobox("IdentityLink", new TestPINProvider(pin), null); + + } + + @Test + public void testGetCerts() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + SignatureCard signatureCard = createSignatureCard(); + + byte[] cert; + + cert = signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); + assertNotNull(cert); + assertTrue(Arrays.equals(cert, STARCOSApplSichereSignatur.C_X509_CH_DS)); + + cert = signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); + assertNotNull(cert); + assertTrue(Arrays.equals(cert, STARCOSApplGewoehnlicheSignatur.C_X509_CH_AUT)); + + } + + @Test(expected = NotActivatedException.class) + public void testGetDSCertEmpty() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + STARCOSApplSichereSignatur appl = (STARCOSApplSichereSignatur) card.getApplication(STARCOSApplSichereSignatur.AID_SichereSignatur); + appl.clearCert(); + + signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); + + } + + @Test(expected = NotActivatedException.class) + public void testGetAUTCertEmpty() throws SignatureCardException, + InterruptedException, CardNotSupportedException { + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + STARCOSApplGewoehnlicheSignatur appl = (STARCOSApplGewoehnlicheSignatur) card.getApplication(STARCOSApplGewoehnlicheSignatur.AID_GewoehnlicheSignatur); + appl.clearCert(); + + signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); + + } + + @Test + public void testSignSichereSignatur() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + char[] pin = "123456".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + STARCOSApplSichereSignatur appl = (STARCOSApplSichereSignatur) card.getApplication(STARCOSApplSichereSignatur.AID_SichereSignatur); + appl.setPin(STARCOSApplSichereSignatur.KID_PIN_SS, pin); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + byte[] signature = signatureCard.createSignature(hash, + KeyboxName.SECURE_SIGNATURE_KEYPAIR, new TestPINProvider(pin)); + + assertNotNull(signature); + + } + + @Test + public void testSignGewoehnlicheSignatur() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + char[] pin = "1234".toCharArray(); + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + STARCOSCardChannelEmul channel = (STARCOSCardChannelEmul) card.getBasicChannel(); + channel.setPin(STARCOSCardChannelEmul.KID_PIN_Glob, pin); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + byte[] signature = signatureCard.createSignature(hash, + KeyboxName.CERITIFIED_KEYPAIR, new TestPINProvider(pin)); + + assertNotNull(signature); + + } + + @Test(expected = LockedException.class) + public void testSignSichereSignaturInvalidPin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); + + signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider); + + } + + @Test(expected = LockedException.class) + public void testSignGewoehnlicheSignaturInvalidPin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + TestPINProvider pinProvider = new TestPINProvider("1234".toCharArray()); + + signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, + pinProvider); + + } + + @Test(expected = LockedException.class) + public void testSignSichereSignaturBlockedPin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + STARCOSApplSichereSignatur appl = (STARCOSApplSichereSignatur) card.getApplication(STARCOSApplSichereSignatur.AID_SichereSignatur); + appl.setPin(STARCOSApplSichereSignatur.KID_PIN_SS, null); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); + assertTrue(pinProvider.getProvided() <= 0); + + signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider); + + } + + @Test(expected = LockedException.class) + public void testSignGewoehnlicheSignaturBlockedPin() throws SignatureCardException, + InterruptedException, CardNotSupportedException, + NoSuchAlgorithmException, UnsupportedEncodingException { + + SignatureCard signatureCard = createSignatureCard(); + CardEmul card = (CardEmul) signatureCard.getCard(); + STARCOSCardChannelEmul channel = (STARCOSCardChannelEmul) card.getBasicChannel(); + channel.setPin(STARCOSCardChannelEmul.KID_PIN_Glob, null); + + MessageDigest md = MessageDigest.getInstance("SHA-1"); + byte[] hash = md.digest("MOCCA".getBytes("ASCII")); + + TestPINProvider pinProvider = new TestPINProvider("0000".toCharArray()); + + signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, + pinProvider); + + } + + @Test + public void testChangePin() 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[] pin = defaultPin; + + for (int i = pinSpec.getMinLength(); i <= pinSpec.getMaxLength(); i++) { + signatureCard.verifyPIN(pinSpec, new TestPINProvider(pin)); + char[] newPin = new char[i]; + Arrays.fill(newPin, '0'); + signatureCard + .changePIN(pinSpec, new TestChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinSpec, new TestPINProvider(newPin)); + pin = newPin; + } + + } + + } + + +} diff --git a/smcc/src/test/java/at/gv/egiz/smcc/util/ISO7816UtilsTest.java b/smcc/src/test/java/at/gv/egiz/smcc/util/ISO7816UtilsTest.java new file mode 100644 index 00000000..679f2c02 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/util/ISO7816UtilsTest.java @@ -0,0 +1,175 @@ +/* +* Copyright 2008 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.util; + +import java.util.Arrays; + +import javax.smartcardio.CommandAPDU; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import at.gv.egiz.smcc.VerifyAPDUSpec; +import at.gv.egiz.smcc.util.ISO7816Utils; +import static org.junit.Assert.*; + +public class ISO7816UtilsTest { + + @Test + public void testFormatPIN() { + + formatPIN(VerifyAPDUSpec.PIN_FORMAT_BINARY, + VerifyAPDUSpec.PIN_JUSTIFICATION_LEFT, 7, "1234", + new byte[] { + (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00 + }, + new byte[] { + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00 + } + ); + + formatPIN(VerifyAPDUSpec.PIN_FORMAT_BINARY, + VerifyAPDUSpec.PIN_JUSTIFICATION_RIGHT, 7, "12345", + new byte[] { + (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x04, (byte) 0x03, (byte) 0x02, (byte) 0x01 + }, + new byte[] { + (byte) 0x00, (byte) 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff + } + ); + + formatPIN(VerifyAPDUSpec.PIN_FORMAT_BCD, + VerifyAPDUSpec.PIN_JUSTIFICATION_LEFT, 7, "12345", + new byte[] { + (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 + }, + new byte[] { + (byte) 0xff, (byte) 0xff, (byte) 0xf0, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 + } + ); + + formatPIN(VerifyAPDUSpec.PIN_FORMAT_BCD, + VerifyAPDUSpec.PIN_JUSTIFICATION_RIGHT, 7, "1234567", + new byte[] { + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x07, (byte) 0x65, (byte) 0x43, (byte) 0x21 + }, + new byte[] { + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0f, (byte) 0xff, (byte) 0xff, (byte) 0xff + } + ); + + formatPIN(VerifyAPDUSpec.PIN_FORMAT_ASCII, + VerifyAPDUSpec.PIN_JUSTIFICATION_LEFT, 7, "1234", + new byte[] { + (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, (byte) 0x00, (byte) 0x00, (byte) 0x00 + }, + new byte[] { + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00 + } + ); + + formatPIN(VerifyAPDUSpec.PIN_FORMAT_ASCII, + VerifyAPDUSpec.PIN_JUSTIFICATION_RIGHT, 7, "12345", + new byte[] { + (byte) 0x00, (byte) 0x00, (byte) 0x35, (byte) 0x34, (byte) 0x33, (byte) 0x32, (byte) 0x31 + }, + new byte[] { + (byte) 0x00, (byte) 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff + } + ); + + + } + + private void formatPIN(int pinFormat, int pinJusitification, int pinLength, String pin, byte[] rfpin, byte[] rmask) { + + byte[] fpin = new byte[pinLength]; + byte[] mask = new byte[pinLength]; + + ISO7816Utils.formatPIN(pinFormat, pinJusitification, fpin, mask, pin.toCharArray()); + +// System.out.println(toString(fpin)); +// System.out.println(toString(mask)); + + assertTrue(Arrays.equals(fpin, rfpin)); + assertTrue(Arrays.equals(mask, rmask)); + + } + + @Test + public void testCreateVerifyAPDU() { + + VerifyAPDUSpec verifyAPDUSpec; + CommandAPDU apdu; + byte[] ref; + + verifyAPDUSpec = new VerifyAPDUSpec( + new byte[] { + (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x80, (byte) 0x08, + (byte) 0x20, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff }, + 1, VerifyAPDUSpec.PIN_FORMAT_BCD, 7, 4, 4); + + apdu = ISO7816Utils.createVerifyAPDU(verifyAPDUSpec, "1234".toCharArray()); + +// System.out.println(toString(apdu.getBytes())); + + ref = new byte[] { (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x80, + (byte) 0x08, (byte) 0x24, (byte) 0x12, (byte) 0x34, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }; + + assertTrue(Arrays.equals(apdu.getBytes(), ref)); + + ref = new byte[] { (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x80, + (byte) 0x08, (byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; + + verifyAPDUSpec = new VerifyAPDUSpec( + new byte[] { + (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x80, (byte) 0x08, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, + 0, VerifyAPDUSpec.PIN_FORMAT_ASCII, 8); + + apdu = ISO7816Utils.createVerifyAPDU(verifyAPDUSpec, "1234".toCharArray()); + +// System.out.println(toString(apdu.getBytes())); + + assertTrue(Arrays.equals(apdu.getBytes(), ref)); + + } + + private String toString(byte[] b) { + StringBuffer sb = new StringBuffer(); + if (b != null && b.length > 0) { + sb.append(Integer.toHexString((b[0] & 240) >> 4)); + sb.append(Integer.toHexString(b[0] & 15)); + } + for (int i = 1; i < b.length; i++) { + sb.append(':'); + sb.append(Integer.toHexString((b[i] & 240) >> 4)); + sb.append(Integer.toHexString(b[i] & 15)); + } + return sb.toString(); + } + + +} -- cgit v1.2.3 From 974087a04d2fb9b03a72b66c090afe65e5a818dc Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 6 Aug 2009 14:01:01 +0000 Subject: FIX [462] PINMgmtSignatureCard changePIN silently ignores wrong pin entry [63cX] git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@414 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smcc/src/test/java/at/gv/egiz/smcc/CardTest.java | 67 ++++++++++++++++++++++ .../at/gv/egiz/smcc/starcos/STARCOSCardTest.java | 57 +++++++++++++++++- 2 files changed, 123 insertions(+), 1 deletion(-) (limited to 'smcc/src/test/java/at/gv/egiz/smcc') 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); + } + } + } } -- cgit v1.2.3 From 497f6336cc96cd3b2b4cd760774ec4c2ed892df2 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 13 Aug 2009 09:09:06 +0000 Subject: [#436] resolve "#PIN digits" message via message resource bundle git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@418 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smcc/src/test/java/at/gv/egiz/smcc/CardTest.java | 8 +++---- .../at/gv/egiz/smcc/starcos/STARCOSCardTest.java | 26 +++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'smcc/src/test/java/at/gv/egiz/smcc') 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); } } } -- cgit v1.2.3 From 68941b57df2caeead67a5bede2ef5a635d07db32 Mon Sep 17 00:00:00 2001 From: mcentner Date: Wed, 11 Nov 2009 15:51:08 +0000 Subject: Added support for SHA-256 and partial support for e-card G3, BELPIC and Italian cards. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@540 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- smcc/src/test/java/at/gv/egiz/smcc/CardTest.java | 62 +++++++++------------- .../java/at/gv/egiz/smcc/acos/ACOSCardTest.java | 62 +++++++++------------- .../at/gv/egiz/smcc/starcos/STARCOSCardTest.java | 62 +++++++++------------- 3 files changed, 78 insertions(+), 108 deletions(-) (limited to 'smcc/src/test/java/at/gv/egiz/smcc') 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 2a55357d..b3bd07ab 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java @@ -18,6 +18,8 @@ package at.gv.egiz.smcc; import static org.junit.Assert.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -178,13 +180,10 @@ public abstract class CardTest { @Test(expected = CancelledException.class) public void testSignSIGCancel() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - PINProvider pinProvider = new PINProvider() { @Override public char[] providePIN(PINSpec spec, int retries) @@ -193,21 +192,19 @@ public abstract class CardTest { } }; - signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, pinProvider, + null); } @Test(expected = CancelledException.class) public void testSignDECCancel() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - PINProvider pinProvider = new PINProvider() { @Override public char[] providePIN(PINSpec spec, int retries) @@ -216,21 +213,19 @@ public abstract class CardTest { } }; - signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, + pinProvider, null); } @Test(expected = InterruptedException.class) public void testSignSIGInterrrupted() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - PINProvider pinProvider = new PINProvider() { @Override public char[] providePIN(PINSpec spec, int retries) @@ -239,21 +234,19 @@ public abstract class CardTest { } }; - signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider, null); } @Test(expected = InterruptedException.class) public void testSignDECInterrrupted() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - PINProvider pinProvider = new PINProvider() { @Override public char[] providePIN(PINSpec spec, int retries) @@ -262,21 +255,19 @@ public abstract class CardTest { } }; - signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, + pinProvider, null); } @Test(expected = CancelledException.class) public void testSignSIGConcurrent() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { final SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - PINProvider pinProvider = new PINProvider() { @Override public char[] providePIN(PINSpec spec, int retries) @@ -294,21 +285,19 @@ public abstract class CardTest { } }; - signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider, null); } @Test(expected = CancelledException.class) public void testSignDECConcurrent() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { final SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - PINProvider pinProvider = new PINProvider() { @Override public char[] providePIN(PINSpec spec, int retries) @@ -326,8 +315,9 @@ public abstract class CardTest { } }; - signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, + pinProvider, null); } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java index 90bb039e..56d1e4b2 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java @@ -21,6 +21,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -125,7 +127,7 @@ public abstract class ACOSCardTest extends CardTest { @Test public void testSignSIG() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { char[] pin = "123456".toCharArray(); @@ -134,11 +136,9 @@ public abstract class ACOSCardTest extends CardTest { ACOSApplSIG appl = (ACOSApplSIG) card.getApplication(ACOSAppl.AID_SIG); appl.setPin(ACOSApplSIG.KID_PIN_SIG, pin); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - - byte[] signature = signatureCard.createSignature(hash, - KeyboxName.SECURE_SIGNATURE_KEYPAIR, new TestPINProvider(pin)); + byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), + KeyboxName.SECURE_SIGNATURE_KEYPAIR, new TestPINProvider(pin), null); assertNotNull(signature); @@ -147,7 +147,7 @@ public abstract class ACOSCardTest extends CardTest { @Test public void testSignDEC() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { char[] pin = "1234".toCharArray(); @@ -156,11 +156,9 @@ public abstract class ACOSCardTest extends CardTest { ACOSApplDEC appl = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); appl.setPin(ACOSApplDEC.KID_PIN_DEC, pin); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - - byte[] signature = signatureCard.createSignature(hash, - KeyboxName.CERITIFIED_KEYPAIR, new TestPINProvider(pin)); + byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), + KeyboxName.CERITIFIED_KEYPAIR, new TestPINProvider(pin), null); assertNotNull(signature); @@ -169,74 +167,66 @@ public abstract class ACOSCardTest extends CardTest { @Test(expected = LockedException.class) public void testSignSIGInvalidPin() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); - signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider, null); } @Test(expected = LockedException.class) public void testSignDECInvalidPin() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - TestPINProvider pinProvider = new TestPINProvider("0000".toCharArray()); - signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, + pinProvider, null); } @Test(expected = LockedException.class) public void testSignSIGBlockedPin() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); CardEmul card = (CardEmul) signatureCard.getCard(); ACOSApplSIG appl = (ACOSApplSIG) card.getApplication(ACOSAppl.AID_SIG); appl.setPin(ACOSApplSIG.KID_PIN_SIG, null); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); - signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider, null); } @Test(expected = LockedException.class) public void testSignDECBlockedPin() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); CardEmul card = (CardEmul) signatureCard.getCard(); ACOSApplDEC appl = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); appl.setPin(ACOSApplDEC.KID_PIN_DEC, null); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - TestPINProvider pinProvider = new TestPINProvider("0000".toCharArray()); - signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, + pinProvider, null); } 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 89e2ca65..b7dc9a0c 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 @@ -20,6 +20,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -147,7 +149,7 @@ public class STARCOSCardTest extends CardTest { @Test public void testSignSichereSignatur() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { char[] pin = "123456".toCharArray(); @@ -156,11 +158,9 @@ public class STARCOSCardTest extends CardTest { STARCOSApplSichereSignatur appl = (STARCOSApplSichereSignatur) card.getApplication(STARCOSApplSichereSignatur.AID_SichereSignatur); appl.setPin(STARCOSApplSichereSignatur.KID_PIN_SS, pin); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - - byte[] signature = signatureCard.createSignature(hash, - KeyboxName.SECURE_SIGNATURE_KEYPAIR, new TestPINProvider(pin)); + byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), + KeyboxName.SECURE_SIGNATURE_KEYPAIR, new TestPINProvider(pin), null); assertNotNull(signature); @@ -169,7 +169,7 @@ public class STARCOSCardTest extends CardTest { @Test public void testSignGewoehnlicheSignatur() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { char[] pin = "1234".toCharArray(); @@ -178,11 +178,9 @@ public class STARCOSCardTest extends CardTest { STARCOSCardChannelEmul channel = (STARCOSCardChannelEmul) card.getBasicChannel(); channel.setPin(STARCOSCardChannelEmul.KID_PIN_Glob, pin); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - - byte[] signature = signatureCard.createSignature(hash, - KeyboxName.CERITIFIED_KEYPAIR, new TestPINProvider(pin)); + byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), + KeyboxName.CERITIFIED_KEYPAIR, new TestPINProvider(pin), null); assertNotNull(signature); @@ -191,75 +189,67 @@ public class STARCOSCardTest extends CardTest { @Test(expected = LockedException.class) public void testSignSichereSignaturInvalidPin() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); - signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider, null); } @Test(expected = LockedException.class) public void testSignGewoehnlicheSignaturInvalidPin() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - TestPINProvider pinProvider = new TestPINProvider("1234".toCharArray()); - signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, + pinProvider, null); } @Test(expected = LockedException.class) public void testSignSichereSignaturBlockedPin() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); CardEmul card = (CardEmul) signatureCard.getCard(); STARCOSApplSichereSignatur appl = (STARCOSApplSichereSignatur) card.getApplication(STARCOSApplSichereSignatur.AID_SichereSignatur); appl.setPin(STARCOSApplSichereSignatur.KID_PIN_SS, null); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); assertTrue(pinProvider.getProvided() <= 0); - signatureCard.createSignature(hash, KeyboxName.SECURE_SIGNATURE_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, + pinProvider, null); } @Test(expected = LockedException.class) public void testSignGewoehnlicheSignaturBlockedPin() throws SignatureCardException, InterruptedException, CardNotSupportedException, - NoSuchAlgorithmException, UnsupportedEncodingException { + NoSuchAlgorithmException, IOException { SignatureCard signatureCard = createSignatureCard(); CardEmul card = (CardEmul) signatureCard.getCard(); STARCOSCardChannelEmul channel = (STARCOSCardChannelEmul) card.getBasicChannel(); channel.setPin(STARCOSCardChannelEmul.KID_PIN_Glob, null); - MessageDigest md = MessageDigest.getInstance("SHA-1"); - byte[] hash = md.digest("MOCCA".getBytes("ASCII")); - TestPINProvider pinProvider = new TestPINProvider("0000".toCharArray()); - signatureCard.createSignature(hash, KeyboxName.CERITIFIED_KEYPAIR, - pinProvider); + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" + .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, + pinProvider, null); } -- cgit v1.2.3 From 3da4655d011dfc2f04f9e4ac28b38aee42d01bc0 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 5 Jan 2010 10:06:47 +0000 Subject: Features [#437] Handle pinpad [64:03] response apdu correctly [#445] pin entry feedback for VERIFY_PIN_START/FINISH [#471] Provide SecureViewer Link before Pinpad PinEntry timeout starts Bugs [#479] PIN Managment Applet allows unmatching new pin and pin confirmation [#480] PIN Management displays blocked PINs as ACTIVE [#486] Not possible to select 3 times in series the same item from signedReferencesList for display in secureViewer [#506] change pin dialog (gui) issues [#508] e-card G3 PIN activation (with TransportPIN) not supported [#509] closing secure viewer window (WINDOW_CLOSING) leaves "signature data is displayed in viewer" dialog in applet git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@565 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/smcc/AbstractAppl.java | 1 + smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java | 14 +- smcc/src/test/java/at/gv/egiz/smcc/CardTest.java | 171 +++------------------ smcc/src/test/java/at/gv/egiz/smcc/PIN.java | 10 +- .../test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java | 2 +- .../java/at/gv/egiz/smcc/acos/A03CardEmul.java | 7 +- .../java/at/gv/egiz/smcc/acos/A03CardTest.java | 9 +- .../java/at/gv/egiz/smcc/acos/A04CardEmul.java | 7 +- .../java/at/gv/egiz/smcc/acos/A04CardTest.java | 12 +- .../java/at/gv/egiz/smcc/acos/ACOSApplDEC.java | 2 +- .../java/at/gv/egiz/smcc/acos/ACOSApplSIG.java | 2 +- .../java/at/gv/egiz/smcc/acos/ACOSCardTest.java | 21 ++- .../egiz/smcc/pin/gui/CancelChangePINProvider.java | 39 +++++ .../at/gv/egiz/smcc/pin/gui/CancelPINProvider.java | 29 ++++ .../at/gv/egiz/smcc/pin/gui/ChangePINProvider.java | 49 ++++++ .../at/gv/egiz/smcc/pin/gui/DummyChangePINGUI.java | 68 ++++++++ .../java/at/gv/egiz/smcc/pin/gui/DummyPINGUI.java | 48 ++++++ .../gv/egiz/smcc/pin/gui/InterruptPINProvider.java | 34 ++++ .../smcc/pin/gui/InvalidChangePINProvider.java | 56 +++++++ .../gv/egiz/smcc/pin/gui/InvalidPINProvider.java | 48 ++++++ .../gv/egiz/smcc/pin/gui/SMCCTestPINProvider.java | 43 ++++++ .../java/at/gv/egiz/smcc/starcos/STARCOSAppl.java | 23 --- .../starcos/STARCOSApplGewoehnlicheSignatur.java | 27 +++- .../gv/egiz/smcc/starcos/STARCOSApplInfobox.java | 5 + .../smcc/starcos/STARCOSApplSichereSignatur.java | 36 ++++- .../egiz/smcc/starcos/STARCOSCardChannelEmul.java | 105 ++++++++++--- .../at/gv/egiz/smcc/starcos/STARCOSCardEmul.java | 24 +-- .../at/gv/egiz/smcc/starcos/STARCOSCardTest.java | 132 ++++++++-------- .../smcc/starcos/STARCOSG3CardChannelEmul.java | 46 ++++++ .../at/gv/egiz/smcc/starcos/STARCOSG3CardEmul.java | 57 +++++++ .../at/gv/egiz/smcc/starcos/STARCOSG3CardTest.java | 119 ++++++++++++++ 31 files changed, 918 insertions(+), 328 deletions(-) create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelChangePINProvider.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelPINProvider.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/pin/gui/ChangePINProvider.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyChangePINGUI.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyPINGUI.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InterruptPINProvider.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidChangePINProvider.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidPINProvider.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/pin/gui/SMCCTestPINProvider.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardChannelEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardEmul.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardTest.java (limited to 'smcc/src/test/java/at/gv/egiz/smcc') diff --git a/smcc/src/test/java/at/gv/egiz/smcc/AbstractAppl.java b/smcc/src/test/java/at/gv/egiz/smcc/AbstractAppl.java index 137de509..affb06ff 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/AbstractAppl.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/AbstractAppl.java @@ -51,6 +51,7 @@ public abstract class AbstractAppl implements CardAppl { return files; } + @Override public abstract void setPin(int kid, char[] value); } \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java index 6017bcce..3dfc8510 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardEmul.java @@ -28,15 +28,15 @@ import javax.smartcardio.CardException; @SuppressWarnings("restriction") public abstract class CardEmul extends Card { - protected Thread exclThread = null; - protected CardChannel channel = newCardChannel(this); + protected Thread exclThread; // = null; + protected CardChannel channel; // = newCardChannel(this); protected List applications = new ArrayList(); public CardEmul() { super(); } - protected abstract CardChannelEmul newCardChannel(CardEmul cardEmul); +// protected abstract CardChannelEmul newCardChannel(CardEmul cardEmul); @Override public void beginExclusive() throws CardException { @@ -71,9 +71,9 @@ public abstract class CardEmul extends Card { @Override public void disconnect(boolean reset) throws CardException { - if (reset) { - channel = newCardChannel(this); - } +// if (reset) { +// channel = newCardChannel(this); +// } } @Override @@ -93,7 +93,7 @@ public abstract class CardEmul extends Card { } public AbstractAppl getApplication(byte[] fid) { - + for(AbstractAppl appl : applications) { if (Arrays.equals(appl.getAID(), fid) || Arrays.equals(appl.getFID(), fid)) { return appl; 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 b3bd07ab..44e48836 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/CardTest.java @@ -16,12 +16,14 @@ */ package at.gv.egiz.smcc; +import at.gv.egiz.smcc.pin.gui.CancelPINProvider; +import at.gv.egiz.smcc.pin.gui.InterruptPINProvider; +import at.gv.egiz.smcc.pin.gui.CancelChangePINProvider; import static org.junit.Assert.*; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.List; @@ -32,119 +34,15 @@ import org.junit.Test; import at.gv.egiz.smcc.SignatureCard.KeyboxName; import at.gv.egiz.smcc.acos.A04ApplDEC; +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 { - public class TestPINProvider implements PINProvider { - - int provided = 0; - - char[] pin; - - public TestPINProvider(char[] pin) { - super(); - this.pin = pin; - } - - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - provided++; - return pin; - } - - public int getProvided() { - return provided; - } - - } - - public class TestChangePINProvider extends TestPINProvider implements - ChangePINProvider { - - char[] oldPin; - - public TestChangePINProvider(char[] oldPin, char[] pin) { - super(pin); - this.oldPin = oldPin; - } - - @Override - public char[] provideOldPIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - return oldPin; - } - - } - - public class TestInvalidPINProvider implements PINProvider { - - int provided = 0; - int numWrongTries = 0; - - char[] pin; - - public TestInvalidPINProvider(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 TestInvalidChangePINProvider implements ChangePINProvider { - - int provided = 0; - int numWrongTries = 0; - - char[] pin; - char[] oldPin; - - /** emulate ChangePinProvider */ - public TestInvalidChangePINProvider(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(); } @@ -167,7 +65,7 @@ public abstract class CardTest { SignatureCard signatureCard = createSignatureCard(); - TestPINProvider pinProvider = new TestPINProvider(pin); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider(pin); byte[] idlink = signatureCard.getInfobox("IdentityLink", pinProvider, null); @@ -184,13 +82,7 @@ public abstract class CardTest { SignatureCard signatureCard = createSignatureCard(); - PINProvider pinProvider = new PINProvider() { - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - throw new CancelledException(); - } - }; + PINGUI pinProvider = new CancelPINProvider(); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, pinProvider, @@ -205,13 +97,7 @@ public abstract class CardTest { SignatureCard signatureCard = createSignatureCard(); - PINProvider pinProvider = new PINProvider() { - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - throw new CancelledException(); - } - }; + PINGUI pinProvider = new CancelPINProvider(); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, @@ -226,13 +112,7 @@ public abstract class CardTest { SignatureCard signatureCard = createSignatureCard(); - PINProvider pinProvider = new PINProvider() { - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - throw new InterruptedException(); - } - }; + PINGUI pinProvider = new InterruptPINProvider(); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, @@ -247,13 +127,7 @@ public abstract class CardTest { SignatureCard signatureCard = createSignatureCard(); - PINProvider pinProvider = new PINProvider() { - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - throw new InterruptedException(); - } - }; + PINGUI pinProvider = new InterruptPINProvider(); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, @@ -268,11 +142,11 @@ public abstract class CardTest { final SignatureCard signatureCard = createSignatureCard(); - PINProvider pinProvider = new PINProvider() { + PINGUI pinProvider = new DummyPINGUI() { @Override public char[] providePIN(PINSpec spec, int retries) throws CancelledException, InterruptedException { - + try { signatureCard.getCertificate(KeyboxName.SECURE_SIGNATURE_KEYPAIR); assertTrue(false); @@ -281,10 +155,10 @@ public abstract class CardTest { // expected throw new CancelledException(); } - + } }; - + signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, pinProvider, null); @@ -298,7 +172,7 @@ public abstract class CardTest { final SignatureCard signatureCard = createSignatureCard(); - PINProvider pinProvider = new PINProvider() { + PINGUI pinProvider = new DummyPINGUI() { @Override public char[] providePIN(PINSpec spec, int retries) throws CancelledException, InterruptedException { @@ -311,7 +185,6 @@ public abstract class CardTest { // expected throw new CancelledException(); } - } }; @@ -339,13 +212,7 @@ public abstract class CardTest { PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard(); - PINProvider pinProvider = new PINProvider() { - @Override - public char[] providePIN(PINSpec spec, int retries) - throws CancelledException, InterruptedException { - throw new CancelledException(); - } - }; + ModifyPINGUI pinProvider = new CancelChangePINProvider(); List specs = signatureCard.getPINSpecs(); diff --git a/smcc/src/test/java/at/gv/egiz/smcc/PIN.java b/smcc/src/test/java/at/gv/egiz/smcc/PIN.java index ae883727..2cda0c2f 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/PIN.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/PIN.java @@ -23,19 +23,23 @@ public class PIN { public static final int STATE_PIN_VERIFIED = 1; public static final int STATE_PIN_BLOCKED = -1; + + public static final int STATE_PIN_NOTACTIVE = 2; public byte[] pin; public int kid; - public int state = STATE_RESET; + public int state; // = STATE_RESET; - public int kfpc = 10; + public int kfpc; // = 10; - public PIN(byte[] pin, int kid, int kfpc) { + //TODO also provde default constructor without state param + public PIN(byte[] pin, int kid, int kfpc, int state) { this.pin = pin; this.kid = kid; this.kfpc = kfpc; + this.state = state; } } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java index 9fd96d73..f4ac5c35 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03ApplDEC.java @@ -40,7 +40,7 @@ public class A03ApplDEC extends ACOSApplDEC { putFile(new File(FID_EF_INFOBOX, EF_INFOBOX, FCI_EF_INFOBOX, KID_PIN_INF)); try { - pins.put(KID_PIN_INF, new PIN("0000\0\0\0\0".getBytes("ASCII"), KID_PIN_INF, 10)); + pins.put(KID_PIN_INF, new PIN("0000\0\0\0\0".getBytes("ASCII"), KID_PIN_INF, 10, PIN.STATE_RESET)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardEmul.java index 58216b6b..7394bae7 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardEmul.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A03CardEmul.java @@ -24,13 +24,8 @@ import at.gv.egiz.smcc.CardEmul; public class A03CardEmul extends ACOSCardEmul { public A03CardEmul(A03ApplSIG applSIG, A03ApplDEC applDEC) { + channel = new A03CardChannelEmul(this); applications.add(applSIG); applications.add(applDEC); } - - @Override - protected CardChannelEmul newCardChannel(CardEmul cardEmul) { - return new A03CardChannelEmul(this); - } - } 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 776c0370..3a8ac41c 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 @@ -22,15 +22,16 @@ import java.util.Arrays; import org.junit.Test; -import at.gv.egiz.smcc.ACOSCard; 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.pin.gui.ChangePINProvider; 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.pin.gui.SMCCTestPINProvider; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; @@ -74,12 +75,12 @@ public class A03CardTest extends ACOSCardTest { char[] pin = defaultPin; for (int i = pinSpec.getMinLength(); i <= pinSpec.getMaxLength(); i++) { - signatureCard.verifyPIN(pinSpec, new TestPINProvider(pin)); + signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); char[] newPin = new char[i]; Arrays.fill(newPin, '0'); signatureCard - .changePIN(pinSpec, new TestChangePINProvider(pin, newPin)); - signatureCard.verifyPIN(pinSpec, new TestPINProvider(newPin)); + .changePIN(pinSpec, new ChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(newPin)); pin = newPin; } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardEmul.java index 70925aa6..dd44d05b 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardEmul.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/A04CardEmul.java @@ -24,14 +24,9 @@ import at.gv.egiz.smcc.CardEmul; public class A04CardEmul extends ACOSCardEmul { public A04CardEmul(A04ApplSIG applSIG, A04ApplDEC applDEC) { + channel = new A04CardChannelEmul(this); applications.add(applSIG); applications.add(applDEC); } - - @Override - protected CardChannelEmul newCardChannel(CardEmul cardEmul) { - return new A04CardChannelEmul(this); - } - } 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 d15e80d7..1cbea1b3 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 @@ -28,7 +28,6 @@ import java.util.Arrays; import org.junit.BeforeClass; import org.junit.Test; -import at.gv.egiz.smcc.ACOSCard; import at.gv.egiz.smcc.CancelledException; import at.gv.egiz.smcc.CardEmul; import at.gv.egiz.smcc.CardNotSupportedException; @@ -41,7 +40,8 @@ import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.smcc.SignatureCardFactory; -import at.gv.egiz.smcc.CardTest.TestPINProvider; +import at.gv.egiz.smcc.pin.gui.ChangePINProvider; +import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider; public class A04CardTest extends ACOSCardTest { @@ -88,8 +88,8 @@ public class A04CardTest extends ACOSCardTest { char[] newPin = new char[i]; Arrays.fill(newPin, '0'); signatureCard - .changePIN(pinSpec, new TestChangePINProvider(pin, newPin)); - signatureCard.verifyPIN(pinSpec, new TestPINProvider(newPin)); + .changePIN(pinSpec, new ChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(newPin)); pin = newPin; } @@ -111,7 +111,7 @@ public class A04CardTest extends ACOSCardTest { SignatureCard signatureCard = factory.createSignatureCard(card, new CardTerminalEmul(card)); - TestPINProvider pinProvider = new TestPINProvider(pin); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider(pin); byte[] idlink = signatureCard.getInfobox("IdentityLink", pinProvider, null); @@ -129,7 +129,7 @@ public class A04CardTest extends ACOSCardTest { SignatureCard signatureCard = createSignatureCard(); - TestPINProvider pinProvider = new TestPINProvider(pin); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider(pin); byte[] idlink = signatureCard.getInfobox("IdentityLink", pinProvider, null); diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplDEC.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplDEC.java index 08979536..09a754f3 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplDEC.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplDEC.java @@ -297,7 +297,7 @@ public abstract class ACOSApplDEC extends ACOSAppl { System.arraycopy(C_CH_EKEY, 0, EF_C_CH_EKEY, 0, C_CH_EKEY.length); putFile(new File(FID_EF_C_CH_EKEY, EF_C_CH_EKEY, FCI_EF_C_CH_EKEY)); try { - pins.put(KID_PIN_DEC, new PIN("1234\0\0\0\0".getBytes("ASCII"), KID_PIN_DEC, 10)); + pins.put(KID_PIN_DEC, new PIN("1234\0\0\0\0".getBytes("ASCII"), KID_PIN_DEC, 10, PIN.STATE_RESET)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplSIG.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplSIG.java index e476b434..6ab5903a 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplSIG.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSApplSIG.java @@ -221,7 +221,7 @@ public abstract class ACOSApplSIG extends ACOSAppl { // PINs try { - pins.put(KID_PIN_SIG, new PIN(Arrays.copyOf("123456".getBytes("ASCII"), 8), KID_PIN_SIG, 3)); + pins.put(KID_PIN_SIG, new PIN(Arrays.copyOf("123456".getBytes("ASCII"), 8), KID_PIN_SIG, 3, PIN.STATE_RESET)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java index 56d1e4b2..4f012739 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/acos/ACOSCardTest.java @@ -16,26 +16,23 @@ */ package at.gv.egiz.smcc.acos; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import org.junit.Test; -import at.gv.egiz.smcc.ACOSCard; import at.gv.egiz.smcc.CardEmul; import at.gv.egiz.smcc.CardNotSupportedException; import at.gv.egiz.smcc.CardTest; import at.gv.egiz.smcc.LockedException; import at.gv.egiz.smcc.NotActivatedException; +import at.gv.egiz.smcc.pin.gui.SMCCTestPINProvider; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.smcc.SignatureCard.KeyboxName; @@ -60,7 +57,7 @@ public abstract class ACOSCardTest extends CardTest { appl.clearInfobox(); byte[] idlink = signatureCard.getInfobox("IdentityLink", - new TestPINProvider(pin), null); + new SMCCTestPINProvider(pin), null); assertNull(idlink); } @@ -76,7 +73,7 @@ public abstract class ACOSCardTest extends CardTest { ACOSApplDEC appl = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); appl.setInfoboxHeader((byte) 0xFF); - signatureCard.getInfobox("IdentityLink", new TestPINProvider(pin), null); + signatureCard.getInfobox("IdentityLink", new SMCCTestPINProvider(pin), null); } @@ -138,7 +135,7 @@ public abstract class ACOSCardTest extends CardTest { byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), - KeyboxName.SECURE_SIGNATURE_KEYPAIR, new TestPINProvider(pin), null); + KeyboxName.SECURE_SIGNATURE_KEYPAIR, new SMCCTestPINProvider(pin), null); assertNotNull(signature); @@ -158,7 +155,7 @@ public abstract class ACOSCardTest extends CardTest { byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), - KeyboxName.CERITIFIED_KEYPAIR, new TestPINProvider(pin), null); + KeyboxName.CERITIFIED_KEYPAIR, new SMCCTestPINProvider(pin), null); assertNotNull(signature); @@ -171,7 +168,7 @@ public abstract class ACOSCardTest extends CardTest { SignatureCard signatureCard = createSignatureCard(); - TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider("000000".toCharArray()); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, @@ -186,7 +183,7 @@ public abstract class ACOSCardTest extends CardTest { SignatureCard signatureCard = createSignatureCard(); - TestPINProvider pinProvider = new TestPINProvider("0000".toCharArray()); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider("0000".toCharArray()); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, @@ -204,7 +201,7 @@ public abstract class ACOSCardTest extends CardTest { ACOSApplSIG appl = (ACOSApplSIG) card.getApplication(ACOSAppl.AID_SIG); appl.setPin(ACOSApplSIG.KID_PIN_SIG, null); - TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider("000000".toCharArray()); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, @@ -222,7 +219,7 @@ public abstract class ACOSCardTest extends CardTest { ACOSApplDEC appl = (ACOSApplDEC) card.getApplication(ACOSAppl.AID_DEC); appl.setPin(ACOSApplDEC.KID_PIN_DEC, null); - TestPINProvider pinProvider = new TestPINProvider("0000".toCharArray()); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider("0000".toCharArray()); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, 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 new file mode 100644 index 00000000..dffe7e29 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelChangePINProvider.java @@ -0,0 +1,39 @@ +/* + * Copyright 2008 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.pin.gui; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; + +public class CancelChangePINProvider extends DummyChangePINGUI implements ModifyPINGUI { + + public CancelChangePINProvider() { + } + + @Override + public char[] provideCurrentPIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + throw new CancelledException("cancelled by cancelPINProvider"); + } + + @Override + public char[] provideNewPIN(PINSpec spec) + throws CancelledException, InterruptedException { + throw new CancelledException("cancelled by cancelPINProvider"); + } + +} \ No newline at end of file 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 new file mode 100644 index 00000000..77f19345 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/CancelPINProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright 2008 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.pin.gui; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; + +public class CancelPINProvider extends DummyPINGUI implements PINGUI { + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + throw new CancelledException("cancelled by cancelPINProvider"); + } +} \ No newline at end of file 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 new file mode 100644 index 00000000..5eb8b9a1 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/ChangePINProvider.java @@ -0,0 +1,49 @@ +/* + * Copyright 2008 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.pin.gui; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; + +public class ChangePINProvider extends DummyChangePINGUI implements ModifyPINGUI { + + int provided = 0; + char[] pin; + char[] oldPin; + + public ChangePINProvider(char[] oldPin, char[] pin) { + this.pin = pin; + this.oldPin = oldPin; + } + + public int getProvided() { + return provided; + } + + @Override + public char[] provideCurrentPIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + provided++; + return oldPin; + } + + @Override + public char[] provideNewPIN(PINSpec 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 new file mode 100644 index 00000000..fff89409 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyChangePINGUI.java @@ -0,0 +1,68 @@ +/* + * Copyright 2008 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.pin.gui; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; + +public abstract class DummyChangePINGUI implements ModifyPINGUI { + + @Override + public void validKeyPressed() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void correctionButtonPressed() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void allKeysCleared() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void finish() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void finishDirect() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void modifyPINDirect(PINSpec spec, int retries) throws CancelledException, InterruptedException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void enterCurrentPIN(PINSpec spec, int retries) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void enterNewPIN(PINSpec spec) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void confirmNewPIN(PINSpec 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 new file mode 100644 index 00000000..4d99b5c1 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/DummyPINGUI.java @@ -0,0 +1,48 @@ +/* + * Copyright 2008 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.pin.gui; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; + +public abstract class DummyPINGUI implements PINGUI { + + @Override + public void enterPINDirect(PINSpec spec, int retries) throws CancelledException, InterruptedException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void enterPIN(PINSpec spec, int retries) throws CancelledException, InterruptedException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void validKeyPressed() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void correctionButtonPressed() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void allKeysCleared() { + 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/InterruptPINProvider.java b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InterruptPINProvider.java new file mode 100644 index 00000000..5706b888 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InterruptPINProvider.java @@ -0,0 +1,34 @@ +/* + * Copyright 2008 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.pin.gui; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; + +@SuppressWarnings("restriction") +public class InterruptPINProvider extends DummyPINGUI implements PINGUI { + + public InterruptPINProvider() { + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + throw new InterruptedException("interrupted by cancelPINProvider"); + } + +} \ No newline at end of file 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 new file mode 100644 index 00000000..69c9f42a --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidChangePINProvider.java @@ -0,0 +1,56 @@ +/* + * Copyright 2008 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.pin.gui; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; + +public class InvalidChangePINProvider extends DummyChangePINGUI implements ModifyPINGUI { + + int provided = 0; + int numWrongTries = 0; + char[] pin; + char[] oldPin; + + /** emulate ChangePinProvider */ + public InvalidChangePINProvider(char[] oldPin, char[] newPin, int numWrongTries) { + super(); + this.pin = newPin; + this.oldPin = oldPin; + this.numWrongTries = numWrongTries; + } + + @Override + public char[] provideCurrentPIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + if (provided >= numWrongTries) { + throw new CancelledException("Number of wrong tries reached: " + provided); + } else { + provided++; + return oldPin; + } + } + + public int getProvided() { + return provided; + } + + @Override + public char[] provideNewPIN(PINSpec 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 new file mode 100644 index 00000000..db01fd0d --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/InvalidPINProvider.java @@ -0,0 +1,48 @@ +/* + * Copyright 2008 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.pin.gui; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; + +public class InvalidPINProvider extends DummyPINGUI implements PINGUI { + + int provided = 0; + int numWrongTries = 0; + char[] pin; + + public InvalidPINProvider(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; + } +} 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 new file mode 100644 index 00000000..dffc90d7 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/pin/gui/SMCCTestPINProvider.java @@ -0,0 +1,43 @@ +/* + * Copyright 2008 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.pin.gui; + +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINSpec; + +public class SMCCTestPINProvider extends DummyPINGUI implements PINGUI { + + public int provided = 0; + char[] pin; + + public SMCCTestPINProvider(char[] pin) { + this.pin = pin; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + provided++; + return pin; + } + + public int getProvided() { + return provided; + } + + +} \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSAppl.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSAppl.java index 2ca63eea..62528e6e 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSAppl.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSAppl.java @@ -69,27 +69,4 @@ public abstract class STARCOSAppl extends AbstractAppl implements CardAppl { pin.next().state = PIN.STATE_RESET; } } - - public void setPin(int kid, char[] value) { - PIN pin = pins.get(kid); - if (pin != null) { - if (value == null) { - pin.pin = null; - } else { - byte[] b = new byte[8]; - b[0] = (byte) (0x20 | value.length); - for(int i = 1, j = 0; i < b.length; i++) { - int h = ((j < value.length) - ? Character.digit(value[j++], 10) - : 0x0F); - int l = ((j < value.length) - ? Character.digit(value[j++], 10) - : 0x0F); - b[i] = (byte) ((h << 4) | l); - } - pin.pin = b; - } - } - } - } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplGewoehnlicheSignatur.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplGewoehnlicheSignatur.java index cec305da..8741dd2d 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplGewoehnlicheSignatur.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplGewoehnlicheSignatur.java @@ -16,7 +16,6 @@ */ package at.gv.egiz.smcc.starcos; -import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Random; @@ -200,12 +199,18 @@ public class STARCOSApplGewoehnlicheSignatur extends STARCOSAppl { protected byte[] EF_C_X509_CH_AUT = new byte[2000]; - - public STARCOSApplGewoehnlicheSignatur(STARCOSCardChannelEmul channel) { + + protected byte[] dst; + + public static final byte[] DST = new byte[] { (byte) 0x84, (byte) 0x03, (byte) 0x80, (byte) 0x02, (byte) 0x00, (byte) 0x89, (byte) 0x03, (byte) 0x13, (byte) 0x35, (byte) 0x10}; + public static final byte[] DST_G3 = new byte[] { (byte) 0x84, (byte) 0x03, (byte) 0x80, (byte) 0x02, (byte) 0x00, (byte) 0x80, (byte) 0x01, (byte) 0x04 }; + + public STARCOSApplGewoehnlicheSignatur(STARCOSCardChannelEmul channel, byte[] dst) { super(channel); // Files System.arraycopy(C_X509_CH_AUT, 0, EF_C_X509_CH_AUT, 0, C_X509_CH_AUT.length); putFile(new File(FID_EF_C_X509_CH_AUT, EF_C_X509_CH_AUT, FCI_EF_C_X509_CH_AUT)); + this.dst = dst; } @Override @@ -240,12 +245,19 @@ public class STARCOSApplGewoehnlicheSignatur extends STARCOSAppl { case 0x81: // EXTERNAL AUTHENTICATE } + case 0xAA: + switch (command.getP1()) { + case 0x41: + if (Arrays.equals(new byte[] {(byte) 0x80, (byte) 0x01, (byte) 0x10}, command.getData())) { + return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); + } + default: + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x80}); + } case 0xB6: switch (command.getP1()) { case 0x41: { // PSO - COMPUTE DIGITAL SIGNATURE - byte[] dst = new byte[] { (byte) 0x84, (byte) 0x03, (byte) 0x80, - (byte) 0x02, (byte) 0x00, (byte) 0x89, (byte) 0x03, (byte) 0x13, (byte) 0x35, (byte) 0x10}; if (Arrays.equals(dst, command.getData())) { securityEnv = command.getData(); return new ResponseAPDU(new byte[] {(byte) 0x90, (byte) 0x00}); @@ -328,5 +340,10 @@ public class STARCOSApplGewoehnlicheSignatur extends STARCOSAppl { } + @Override + public void setPin(int kid, char[] value) { + throw new UnsupportedOperationException("Not supported yet."); + } + } \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplInfobox.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplInfobox.java index b7835a43..c470351a 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplInfobox.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplInfobox.java @@ -156,5 +156,10 @@ public class STARCOSApplInfobox extends STARCOSAppl { throw new CardException("Not supported."); } + @Override + public void setPin(int kid, char[] value) { + throw new UnsupportedOperationException("Not supported yet."); + } + } \ No newline at end of file diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplSichereSignatur.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplSichereSignatur.java index 9fb5ad37..4036ca41 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplSichereSignatur.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSApplSichereSignatur.java @@ -213,16 +213,14 @@ public class STARCOSApplSichereSignatur extends STARCOSAppl { protected byte[] EF_C_X509_CH_DS = new byte[2000]; - public STARCOSApplSichereSignatur(STARCOSCardChannelEmul channel) { + public STARCOSApplSichereSignatur(STARCOSCardChannelEmul channel, byte[] SS_pin, int pinState) { super(channel); // Files System.arraycopy(C_X509_CH_DS, 0, EF_C_X509_CH_DS, 0, C_X509_CH_DS.length); putFile(new File(FID_EF_C_X509_CH_DS, EF_C_X509_CH_DS, FCI_EF_C_X509_CH_DS)); // PINs - pins.put(KID_PIN_SS, new PIN(new byte[] { (byte) 0x24, (byte) 0x12, - (byte) 0x34, (byte) 0x56, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF }, KID_PIN_SS, 3)); + pins.put(KID_PIN_SS, new PIN(SS_pin, KID_PIN_SS, 3, pinState)); } @Override @@ -344,4 +342,34 @@ public class STARCOSApplSichereSignatur extends STARCOSAppl { } + /** + * set and activate pin + * @param value if null, pin will be set to NOTACTIVE + */ + @Override + public void setPin(int kid, char[] value) { + PIN pin = pins.get(kid); + if (pin != null) { + if (value == null) { +// pin.pin = null; + //TransportPIN +// pin.pin = new byte[] { (byte) 0x26, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; + pin.state = PIN.STATE_PIN_NOTACTIVE; + } else { + byte[] b = new byte[8]; + b[0] = (byte) (0x20 | value.length); + for(int i = 1, j = 0; i < b.length; i++) { + int h = ((j < value.length) + ? Character.digit(value[j++], 10) + : 0x0F); + int l = ((j < value.length) + ? Character.digit(value[j++], 10) + : 0x0F); + b[i] = (byte) ((h << 4) | l); + } + pin.pin = b; + pin.state = PIN.STATE_RESET; + } + } + } } \ No newline at end of file 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 89030894..2e0c54eb 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 @@ -16,7 +16,6 @@ */ package at.gv.egiz.smcc.starcos; -import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.HashMap; @@ -30,6 +29,8 @@ import at.gv.egiz.smcc.CardChannelEmul; import at.gv.egiz.smcc.CardEmul; import at.gv.egiz.smcc.File; import at.gv.egiz.smcc.PIN; +import java.util.ArrayList; +import java.util.List; @SuppressWarnings("restriction") public class STARCOSCardChannelEmul extends CardChannelEmul { @@ -40,14 +41,13 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { * */ protected CardEmul cardEmul; - + + public final List globalFiles = new ArrayList(); public final HashMap globalPins = new HashMap(); - public STARCOSCardChannelEmul(CardEmul cardEmul) { + public STARCOSCardChannelEmul(CardEmul cardEmul, byte[] Glob_PIN, int PIN_STATE) { this.cardEmul = cardEmul; - globalPins.put(KID_PIN_Glob, new PIN(new byte[] { (byte) 0x24, (byte) 0x00, - (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF }, KID_PIN_Glob, 10)); + globalPins.put(KID_PIN_Glob, new PIN(Glob_PIN, KID_PIN_Glob, 10, PIN_STATE)); } @Override @@ -88,6 +88,21 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { } } return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x82}); + } else if (globalFiles != null) { + if (command.getP2() != 0x04) { + throw new CardException("Not supported."); + } + for (File file : globalFiles) { + if (Arrays.equals(fid, file.fid)) { + currentFile = file; + byte[] response = new byte[file.fcx.length + 2]; + System.arraycopy(file.fcx, 0, response, 0, file.fcx.length); + response[file.fcx.length] = (byte) 0x90; + response[file.fcx.length + 1] = (byte) 0x00; + return new ResponseAPDU(response); + } + } + return new ResponseAPDU(new byte[] {(byte) 0x6A, (byte) 0x82}); } else { throw new CardException("Not supported."); } @@ -121,6 +136,23 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { } + protected ResponseAPDU cmdREAD_RECORD(CommandAPDU command) throws CardException { + if (command.getINS() != 0xB2) { + throw new IllegalArgumentException("INS has to be 0xB2"); + } + if (currentFile == null) { + return new ResponseAPDU(new byte[]{ (byte) 0x69, (byte) 0x86 }); + } + if (command.getP1() != 0x01 || command.getP2() != 0x04) { + throw new CardException("Not implemented."); + } + byte[] response = new byte[currentFile.file.length + 2]; + System.arraycopy(currentFile.file, 0, response, 0, currentFile.file.length); + response[currentFile.file.length] = (byte) 0x90; + response[currentFile.file.length + 1] = (byte) 0x00; + return new ResponseAPDU(response); + } + protected ResponseAPDU cmdREAD_BINARY(CommandAPDU command) throws CardException { if (command.getINS() != 0xB0) { @@ -192,6 +224,10 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { case 0xB0: return cmdREAD_BINARY(command); + // READ RECORD + case 0xB2: + return cmdREAD_RECORD(command); + // VERIFY case 0x20: return cmdVERIFY(command); @@ -248,9 +284,15 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { } if (pin != null) { - - if (reference.length == 0) { - return new ResponseAPDU(new byte[] { (byte) 0x63, (byte) (pin.kfpc | 0xC0)}); + + if (reference == null || reference.length == 0) { + if (pin.state == PIN.STATE_PIN_NOTACTIVE) { + return new ResponseAPDU(new byte[] { (byte) 0x69, (byte) 0x84 }); + } else if (pin.state == PIN.STATE_PIN_BLOCKED) { + return new ResponseAPDU(new byte[] { (byte) 0x63, (byte) 0xc0 }); + } else { + return new ResponseAPDU(new byte[] { (byte) 0x63, (byte) (pin.kfpc | 0xC0)}); + } } if (reference.length != 8) { @@ -264,7 +306,7 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { case PIN.STATE_RESET: pin.state = PIN.STATE_PIN_VERIFIED; - + default: pin.kfpc = 10; return new ResponseAPDU(new byte[] { (byte) 0x90, (byte) 0x00 }); @@ -321,7 +363,20 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { return new ResponseAPDU(new byte[] {(byte) 0x67, (byte) 0x00}); } - response = verifyPin(0xFF & command.getP2(), data); + PIN pin; + if (currentAppl != null) { + pin = currentAppl.pins.get(command.getP2()); + } else { + pin = globalPins.get(command.getP2()); + } + if (pin.state == PIN.STATE_PIN_NOTACTIVE) { + pin.pin = data; + pin.state = PIN.STATE_RESET; + response = new ResponseAPDU(new byte[] { (byte) 0x90, (byte) 0x00 }); + } else { + // P1 == 0x01 not allowed on active pin (?) + response = new ResponseAPDU(new byte[] { (byte) 0x6A, (byte) 0x86}); + } } else if (command.getP1() == 0x00) { @@ -330,21 +385,22 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { } response = verifyPin(0xFF & command.getP2(), Arrays.copyOf(data, 8)); - + + if (response.getSW() == 0x9000) { + PIN pin; + if (currentAppl != null) { + pin = currentAppl.pins.get(command.getP2()); + } else { + pin = globalPins.get(command.getP2()); + } + pin.pin = Arrays.copyOfRange(data, 8, 16); + pin.state = PIN.STATE_PIN_VERIFIED; + } + } else { return new ResponseAPDU(new byte[] { (byte) 0x6A, (byte) 0x81 }); } - if (response.getSW() == 0x9000) { - PIN pin; - if (currentAppl != null) { - pin = currentAppl.pins.get(command.getP2()); - } else { - pin = globalPins.get(command.getP2()); - } - pin.pin = Arrays.copyOfRange(data, 8, 16); - } - return response; } @@ -353,7 +409,10 @@ public class STARCOSCardChannelEmul extends CardChannelEmul { PIN pin = globalPins.get(kid); if (pin != null) { if (value == null) { - pin.pin = null; +// pin.pin = null; + //TransportPIN +// pin.pin = new byte[] { (byte) 0x24, (byte) 0x12, (byte) 0x34, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; + pin.state = PIN.STATE_PIN_NOTACTIVE; } else { byte[] b = new byte[8]; b[0] = (byte) (0x20 | value.length); diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardEmul.java index 7b2f3fbe..5963fb63 100644 --- a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardEmul.java +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSCardEmul.java @@ -21,30 +21,34 @@ import javax.smartcardio.ATR; import at.gv.egiz.smcc.CardChannelEmul; import at.gv.egiz.smcc.CardEmul; +import at.gv.egiz.smcc.PIN; @SuppressWarnings("restriction") public class STARCOSCardEmul extends CardEmul { - + + public static byte[] DEFAULT_SS_PIN = new byte[] { (byte) 0x26, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; + public static byte[] DEFAULT_Glob_PIN = new byte[] { (byte) 0x24, (byte) 0x00, (byte) 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; + protected static ATR ATR = new ATR(new byte[] { (byte) 0x3b, (byte) 0xbd, (byte) 0x18, (byte) 0x00, (byte) 0x81, (byte) 0x31, (byte) 0xfe, (byte) 0x45, (byte) 0x80, (byte) 0x51, (byte) 0x02, (byte) 0x67, (byte) 0x05, (byte) 0x18, (byte) 0xb1, (byte) 0x02, (byte) 0x02, (byte) 0x02, (byte) 0x01, (byte) 0x81, (byte) 0x05, (byte) 0x31 }); - + public STARCOSCardEmul() { - applications.add(new STARCOSApplSichereSignatur((STARCOSCardChannelEmul) channel)); + this(DEFAULT_SS_PIN, DEFAULT_Glob_PIN, PIN.STATE_RESET); + } + + public STARCOSCardEmul(byte[] SS_PIN, byte[] Glob_PIN, int PIN_STATE) { + channel = new STARCOSCardChannelEmul(this, Glob_PIN, PIN_STATE); + applications.add(new STARCOSApplSichereSignatur((STARCOSCardChannelEmul) channel, SS_PIN, PIN_STATE)); applications.add(new STARCOSApplInfobox((STARCOSCardChannelEmul) channel)); - applications.add(new STARCOSApplGewoehnlicheSignatur((STARCOSCardChannelEmul) channel)); + applications.add(new STARCOSApplGewoehnlicheSignatur((STARCOSCardChannelEmul) channel, + STARCOSApplGewoehnlicheSignatur.DST)); } @Override public ATR getATR() { return ATR; } - - @Override - protected CardChannelEmul newCardChannel(CardEmul cardEmul) { - return new STARCOSCardChannelEmul(this); - } - } \ No newline at end of file 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 b7dc9a0c..154884d4 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 @@ -22,12 +22,9 @@ import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; -import javax.smartcardio.CardChannel; import org.junit.Test; @@ -36,25 +33,20 @@ import at.gv.egiz.smcc.CardEmul; import at.gv.egiz.smcc.CardNotSupportedException; import at.gv.egiz.smcc.CardTerminalEmul; import at.gv.egiz.smcc.CardTest; +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.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.PINSpec; -import at.gv.egiz.smcc.STARCOSCard; import at.gv.egiz.smcc.SignatureCard; 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.pin.gui.SMCCTestPINProvider; import at.gv.egiz.smcc.SignatureCard.KeyboxName; -import at.gv.egiz.smcc.acos.A03ApplDEC; -import at.gv.egiz.smcc.acos.A04ApplDEC; -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 { @@ -69,7 +61,17 @@ public class STARCOSCardTest extends CardTest { assertTrue(signatureCard instanceof PINMgmtSignatureCard); return signatureCard; } - + + protected SignatureCard createSignatureCard(byte[] SS_PIN, byte[] Glob_PIN, int pinState) + throws CardNotSupportedException { + SignatureCardFactory factory = SignatureCardFactory.getInstance(); + STARCOSCardEmul card = new STARCOSCardEmul(SS_PIN, Glob_PIN, pinState); + SignatureCard signatureCard = factory.createSignatureCard(card, + new CardTerminalEmul(card)); + assertTrue(signatureCard instanceof PINMgmtSignatureCard); + return signatureCard; + } + @Test public void testGetInfoboxIdentityLinkEmpty() throws SignatureCardException, InterruptedException, CardNotSupportedException { @@ -82,7 +84,7 @@ public class STARCOSCardTest extends CardTest { appl.clearInfobox(); byte[] idlink = signatureCard.getInfobox("IdentityLink", - new TestPINProvider(pin), null); + new SMCCTestPINProvider(pin), null); assertNull(idlink); } @@ -98,10 +100,10 @@ public class STARCOSCardTest extends CardTest { STARCOSApplInfobox appl = (STARCOSApplInfobox) card.getApplication(STARCOSAppl.AID_Infobox); appl.setInfoboxHeader((byte) 0xFF); - signatureCard.getInfobox("IdentityLink", new TestPINProvider(pin), null); + signatureCard.getInfobox("IdentityLink", new SMCCTestPINProvider(pin), null); } - + @Test public void testGetCerts() throws SignatureCardException, InterruptedException, CardNotSupportedException { @@ -145,7 +147,7 @@ public class STARCOSCardTest extends CardTest { signatureCard.getCertificate(KeyboxName.CERITIFIED_KEYPAIR); } - + @Test public void testSignSichereSignatur() throws SignatureCardException, InterruptedException, CardNotSupportedException, @@ -160,7 +162,7 @@ public class STARCOSCardTest extends CardTest { byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), - KeyboxName.SECURE_SIGNATURE_KEYPAIR, new TestPINProvider(pin), null); + KeyboxName.SECURE_SIGNATURE_KEYPAIR, new SMCCTestPINProvider(pin), null); assertNotNull(signature); @@ -180,12 +182,12 @@ public class STARCOSCardTest extends CardTest { byte[] signature = signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), - KeyboxName.CERITIFIED_KEYPAIR, new TestPINProvider(pin), null); + KeyboxName.CERITIFIED_KEYPAIR, new SMCCTestPINProvider(pin), null); assertNotNull(signature); } - + @Test(expected = LockedException.class) public void testSignSichereSignaturInvalidPin() throws SignatureCardException, InterruptedException, CardNotSupportedException, @@ -193,7 +195,7 @@ public class STARCOSCardTest extends CardTest { SignatureCard signatureCard = createSignatureCard(); - TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider("000000".toCharArray()); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.SECURE_SIGNATURE_KEYPAIR, @@ -208,7 +210,7 @@ public class STARCOSCardTest extends CardTest { SignatureCard signatureCard = createSignatureCard(); - TestPINProvider pinProvider = new TestPINProvider("1234".toCharArray()); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider("1234".toCharArray()); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, @@ -221,12 +223,9 @@ public class STARCOSCardTest extends CardTest { InterruptedException, CardNotSupportedException, NoSuchAlgorithmException, IOException { - SignatureCard signatureCard = createSignatureCard(); - CardEmul card = (CardEmul) signatureCard.getCard(); - STARCOSApplSichereSignatur appl = (STARCOSApplSichereSignatur) card.getApplication(STARCOSApplSichereSignatur.AID_SichereSignatur); - appl.setPin(STARCOSApplSichereSignatur.KID_PIN_SS, null); + SignatureCard signatureCard = createSignatureCard(null, null, PIN.STATE_PIN_BLOCKED); - TestPINProvider pinProvider = new TestPINProvider("000000".toCharArray()); + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider("000000".toCharArray()); assertTrue(pinProvider.getProvided() <= 0); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" @@ -240,68 +239,79 @@ public class STARCOSCardTest extends CardTest { InterruptedException, CardNotSupportedException, NoSuchAlgorithmException, IOException { - SignatureCard signatureCard = createSignatureCard(); - CardEmul card = (CardEmul) signatureCard.getCard(); - STARCOSCardChannelEmul channel = (STARCOSCardChannelEmul) card.getBasicChannel(); - channel.setPin(STARCOSCardChannelEmul.KID_PIN_Glob, null); - - TestPINProvider pinProvider = new TestPINProvider("0000".toCharArray()); + SignatureCard signatureCard = createSignatureCard(null, null, PIN.STATE_PIN_BLOCKED); + + SMCCTestPINProvider pinProvider = new SMCCTestPINProvider("0000".toCharArray()); signatureCard.createSignature(new ByteArrayInputStream("MOCCA" .getBytes("ASCII")), KeyboxName.CERITIFIED_KEYPAIR, pinProvider, null); } - + @Test public void testChangePin() 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); + // set all initial pins to DEFAULT_SS_PIN (123456) + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard( + STARCOSCardEmul.DEFAULT_SS_PIN, STARCOSCardEmul.DEFAULT_SS_PIN, PIN.STATE_RESET); for (PINSpec pinSpec : signatureCard.getPINSpecs()) { - char[] pin = defaultPin; + char[] pin = "123456".toCharArray(); for (int i = pinSpec.getMinLength(); i <= pinSpec.getMaxLength(); i++) { - signatureCard.verifyPIN(pinSpec, new TestPINProvider(pin)); + signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); char[] newPin = new char[i]; Arrays.fill(newPin, '0'); signatureCard - .changePIN(pinSpec, new TestChangePINProvider(pin, newPin)); - signatureCard.verifyPIN(pinSpec, new TestPINProvider(newPin)); + .changePIN(pinSpec, new ChangePINProvider(pin, newPin)); + signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(newPin)); pin = newPin; } } } @Test - public void testVerifyInvalidPin() throws CardNotSupportedException, + @Override + public void testActivatePin() throws CardNotSupportedException, LockedException, NotActivatedException, CancelledException, PINFormatException, SignatureCardException, InterruptedException { - char[] defaultPin = "123456".toCharArray(); + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard( + null, null, PIN.STATE_PIN_NOTACTIVE); + + for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + + char[] pin = "1234567890".substring(0, pinSpec.getMinLength()).toCharArray(); + + boolean notActive = false; + try { + signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + } catch (NotActivatedException ex) { + notActive = true; + } + assertTrue(notActive); + + signatureCard.activatePIN(pinSpec, new ChangePINProvider(null, pin)); + signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + } + } + + @Test + public void testVerifyInvalidPin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { 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[] invalidPin = "999999".toCharArray(); int numInvalidTries = 2; - TestInvalidPINProvider invalidPinProvider = new TestInvalidPINProvider(invalidPin, numInvalidTries); + InvalidPINProvider invalidPinProvider = new InvalidPINProvider(invalidPin, numInvalidTries); try { signatureCard.verifyPIN(pinSpec, invalidPinProvider); } catch (CancelledException ex) { @@ -315,21 +325,15 @@ public class STARCOSCardTest extends CardTest { public void testChangeInvalidPin() 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[] invalidPin = "999999".toCharArray(); int numInvalidTries = 2; - TestInvalidChangePINProvider invalidPinProvider = - new TestInvalidChangePINProvider(invalidPin, defaultPin, numInvalidTries); + InvalidChangePINProvider invalidPinProvider = + new InvalidChangePINProvider(invalidPin, invalidPin, numInvalidTries); try { signatureCard.changePIN(pinSpec, invalidPinProvider); diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardChannelEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardChannelEmul.java new file mode 100644 index 00000000..dc6836ae --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardChannelEmul.java @@ -0,0 +1,46 @@ +/* + * Copyright 2008 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.starcos; + +import at.gv.egiz.smcc.CardEmul; +import at.gv.egiz.smcc.File; +import at.gv.egiz.smcc.PIN; + +/** + * + * @author clemens + */ +public class STARCOSG3CardChannelEmul extends STARCOSCardChannelEmul { + + public STARCOSG3CardChannelEmul(CardEmul cardEmul, byte[] Glob_PIN, int PIN_STATE) { + super(cardEmul, Glob_PIN, PIN_STATE); + + // G3 version file + byte[] versionFileFID = new byte[]{(byte) 0x00, (byte) 0x32}; + byte[] versionFile = new byte[]{ + (byte) 0xa5, (byte) 0x0e, (byte) 0x53, (byte) 0x02, (byte) 0x01, (byte) 0x20, (byte) 0x54, (byte) 0x08, + (byte) 0x01, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x04, (byte) 0x01, (byte) 0x70, (byte) 0x01}; + byte[] versionFileFCX = new byte[]{ + (byte) 0x62, (byte) 0x1a, (byte) 0x80, (byte) 0x02, (byte) 0x00, (byte) 0x14, (byte) 0x82, (byte) 0x05, + (byte) 0x44, (byte) 0x41, (byte) 0x00, (byte) 0x14, (byte) 0x01, (byte) 0x83, (byte) 0x02, (byte) 0x00, + (byte) 0x32, (byte) 0x88, (byte) 0x01, (byte) 0xd8, (byte) 0x8a, (byte) 0x01, (byte) 0x05, (byte) 0xa1, + (byte) 0x03, (byte) 0x8b, (byte) 0x01, (byte) 0x03}; + + globalFiles.add(new File(versionFileFID, versionFile, versionFileFCX)); + + } + } diff --git a/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardEmul.java b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardEmul.java new file mode 100644 index 00000000..7583b3ad --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardEmul.java @@ -0,0 +1,57 @@ +/* + * Copyright 2008 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.starcos; + +import at.gv.egiz.smcc.CardEmul; +import javax.smartcardio.ATR; + +import at.gv.egiz.smcc.PIN; + +@SuppressWarnings("restriction") +public class STARCOSG3CardEmul extends CardEmul { + + public static byte[] TRANSPORT_SS_PIN = new byte[] { (byte) 0x26, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; + public static byte[] TRANSPORT_Glob_PIN = new byte[] { (byte) 0x24, (byte) 0x12, (byte) 0x34, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; + + public static byte[] DEFAULT_SS_PIN = TRANSPORT_SS_PIN; + public static byte[] DEFAULT_Glob_PIN = new byte[] { (byte) 0x24, (byte) 0x00, (byte) 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; + + protected static ATR ATR = new ATR(new byte[] { + (byte) 0x3b, (byte) 0xbd, (byte) 0x18, (byte) 0x00, (byte) 0x81, (byte) 0x31, (byte) 0xfe, (byte) 0x45, + (byte) 0x80, (byte) 0x51, (byte) 0x02, (byte) 0x67, (byte) 0x05, (byte) 0x18, (byte) 0xb1, (byte) 0x02, + (byte) 0x02, (byte) 0x02, (byte) 0x01, (byte) 0x81, (byte) 0x05, (byte) 0x31 + }); + + public STARCOSG3CardEmul(byte[] SS_PIN, byte[] Glob_PIN, int PIN_STATE){ + channel = new STARCOSG3CardChannelEmul(this, Glob_PIN, PIN_STATE); + applications.add(new STARCOSApplSichereSignatur((STARCOSCardChannelEmul) channel, + SS_PIN, PIN_STATE)); + applications.add(new STARCOSApplInfobox((STARCOSCardChannelEmul) channel)); + applications.add(new STARCOSApplGewoehnlicheSignatur((STARCOSCardChannelEmul) channel, + STARCOSApplGewoehnlicheSignatur.DST_G3)); + } + + + public STARCOSG3CardEmul() { + this(DEFAULT_SS_PIN, DEFAULT_Glob_PIN, PIN.STATE_RESET); + } + + @Override + public ATR getATR() { + return ATR; + } +} 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 new file mode 100644 index 00000000..06744c82 --- /dev/null +++ b/smcc/src/test/java/at/gv/egiz/smcc/starcos/STARCOSG3CardTest.java @@ -0,0 +1,119 @@ +/* +* Copyright 2008 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.starcos; + +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.CardEmul; +import at.gv.egiz.smcc.CardNotSupportedException; +import at.gv.egiz.smcc.CardTerminalEmul; +import at.gv.egiz.smcc.CardTest; +import at.gv.egiz.smcc.pin.gui.ChangePINProvider; +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.PINSpec; +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 { + + @Override + protected SignatureCard createSignatureCard() + throws CardNotSupportedException { + SignatureCardFactory factory = SignatureCardFactory.getInstance(); + STARCOSG3CardEmul card = new STARCOSG3CardEmul(); + SignatureCard signatureCard = factory.createSignatureCard(card, + new CardTerminalEmul(card)); + assertTrue(signatureCard instanceof PINMgmtSignatureCard); + return signatureCard; + } + + protected SignatureCard createSignatureCard(byte[] SS_PIN, byte[] Glob_PIN, int pinState) + throws CardNotSupportedException { + SignatureCardFactory factory = SignatureCardFactory.getInstance(); + STARCOSG3CardEmul card = new STARCOSG3CardEmul(SS_PIN, Glob_PIN, pinState); + SignatureCard signatureCard = factory.createSignatureCard(card, + new CardTerminalEmul(card)); + assertTrue(signatureCard instanceof PINMgmtSignatureCard); + return signatureCard; + } + + @Test + public void testChangePin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard( + STARCOSG3CardEmul.DEFAULT_SS_PIN, STARCOSG3CardEmul.DEFAULT_SS_PIN, PIN.STATE_RESET); + + for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + + char[] pin = "123456".toCharArray(); + + for (int i = pinSpec.getMinLength(); i <= pinSpec.getMaxLength(); i++) { + signatureCard.verifyPIN(pinSpec, 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)); + pin = newPin; + } + } + } + + @Test + @Override + public void testActivatePin() throws CardNotSupportedException, + LockedException, NotActivatedException, CancelledException, + PINFormatException, SignatureCardException, InterruptedException { + + PINMgmtSignatureCard signatureCard = (PINMgmtSignatureCard) createSignatureCard( + STARCOSG3CardEmul.TRANSPORT_SS_PIN, STARCOSG3CardEmul.TRANSPORT_SS_PIN, PIN.STATE_PIN_NOTACTIVE); + + for (PINSpec pinSpec : signatureCard.getPINSpecs()) { + + char[] pin = "123456789".substring(0, pinSpec.getMinLength()).toCharArray(); + char[] transportPIN = "123456".toCharArray(); + + boolean notActive = false; + try { + signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + } catch (NotActivatedException ex) { + notActive = true; + } + assertTrue(notActive); + + signatureCard.activatePIN(pinSpec, new ChangePINProvider(transportPIN, pin)); + signatureCard.verifyPIN(pinSpec, new SMCCTestPINProvider(pin)); + } + } + + +} -- cgit v1.2.3