From 438e3b52394e2936f6e286e0cddaaf4d41125324 Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Wed, 20 Feb 2013 12:40:28 -0500 Subject: WIP --- .../src/test/org/dogtagpki/javacard/MainTest.java | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 base/javacard/src/test/org/dogtagpki/javacard/MainTest.java (limited to 'base/javacard/src/test/org/dogtagpki/javacard/MainTest.java') diff --git a/base/javacard/src/test/org/dogtagpki/javacard/MainTest.java b/base/javacard/src/test/org/dogtagpki/javacard/MainTest.java new file mode 100644 index 000000000..fa2875a90 --- /dev/null +++ b/base/javacard/src/test/org/dogtagpki/javacard/MainTest.java @@ -0,0 +1,77 @@ +package org.dogtagpki.javacard; + +import com.licel.jcardsim.base.Simulator; +import javacard.framework.AID; +import org.bouncycastle.util.encoders.Hex; +import org.junit.Assert; +import org.junit.Test; + +import javax.smartcardio.*; +import java.io.FileReader; +import java.util.Properties; + +/** + * @author Endi Sukma Dewata + */ +public class MainTest { + + @Test + public void testMainApplet() throws Exception { + + Properties props = new Properties(); + props.load(new FileReader("conf/jcardsim.cfg")); + + String s = (String)props.get("com.licel.jcardsim.smartcardio.applet.0.AID"); + byte[] aidBytes = Hex.decode(s); + AID appletAID = new AID(aidBytes, (short) 0, (byte) aidBytes.length); + + Simulator simulator = new Simulator(); + + simulator.installApplet(appletAID, TestApplet.class); + simulator.selectApplet(appletAID); + + // test NOP + ResponseAPDU response = simulator.transmitCommand(new CommandAPDU(0x01, 0x02, 0x00, 0x00)); + Assert.assertEquals(0x9000, response.getSW()); + + // test hello world from card + response = simulator.transmitCommand(new CommandAPDU(0x01, 0x01, 0x00, 0x00)); + Assert.assertEquals(0x9000, response.getSW()); + Assert.assertEquals("TestApplet", new String(response.getData())); + + // test echo + response = simulator.transmitCommand(new CommandAPDU(0x01, 0x01, 0x01, 0x00, ("Hello javacard world !").getBytes())); + Assert.assertEquals(0x9000, response.getSW()); + Assert.assertEquals("Hello javacard world !", new String(response.getData())); + } + + @Test + public void testProxyApplet() throws Exception { + + Properties props = new Properties(); + props.load(new FileReader("conf/jcardsim.cfg")); + + String s = (String)props.get("com.licel.jcardsim.smartcardio.applet.1.AID"); + byte[] aidBytes = Hex.decode(s); + AID appletAID = new AID(aidBytes, (short) 0, (byte) aidBytes.length); + + Simulator simulator = new Simulator(); + + simulator.installApplet(appletAID, ProxyApplet.class); + simulator.selectApplet(appletAID); + + // test NOP + ResponseAPDU response = simulator.transmitCommand(new CommandAPDU(0x01, 0x02, 0x00, 0x00)); + Assert.assertEquals(0x9000, response.getSW()); + + // test hello world from card + response = simulator.transmitCommand(new CommandAPDU(0x01, 0x01, 0x00, 0x00)); + Assert.assertEquals(0x9000, response.getSW()); + Assert.assertEquals("ProxyApplet", new String(response.getData())); + + // test echo + response = simulator.transmitCommand(new CommandAPDU(0x01, 0x01, 0x01, 0x00, ("Hello javacard world !").getBytes())); + Assert.assertEquals(0x9000, response.getSW()); + Assert.assertEquals("Hello javacard world !", new String(response.getData())); + } +} -- cgit