Compare commits

..

2 Commits

Author SHA1 Message Date
Elizabeth Cray
c87ffe9bfa Begin porting example to JC221 2025-03-10 13:56:43 -04:00
Elizabeth Cray
dd68840fff Finished template 2025-03-08 21:53:17 -05:00
7 changed files with 100 additions and 23 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ tools/
*.cap
*.class
*.jar
target/
.vscode/

View File

@ -5,9 +5,11 @@
</description>
<property environment="env"/>
<property name="EXPORT" value="build/crystal.cap" />
<property name="EXPORT" value="crystal.cap" />
<property name="RID" value="A000000648" />
<property name="AID" value="2F0002" />
<property name="JC_CLASSIC_HOME" value="${basedir}/oracle_javacard_sdks/jc221_kit"/>
<property name="JC_HOME" value="${basedir}/oracle_javacard_sdks/jc305u4_kit"/>
<target name="clean">
<delete dir="build" />
@ -15,7 +17,7 @@
<target name="check.sdk">
<condition property="jcsdk.exists">
<available file="${env.JC_HOME}" type="dir" />
<available file="${JC_HOME}" type="dir" />
</condition>
</target>
@ -45,8 +47,8 @@
<target name="build" depends="clean,check.tool,build.dir,setup" if="tool.exists">
<!-- ant-javacard task from javacard.pro -->
<taskdef name="javacard" classname="pro.javacard.ant.JavaCard" classpath="tools/ant-javacard.jar" />
<javacard jckit="${env.JC_HOME}">
<cap aid="${RID}" output="${EXPORT}" sources="src/org/hacdc/crystal" targetsdk="${env.JC_CLASSIC_HOME}">
<javacard jckit="${JC_HOME}">
<cap aid="${RID}" output="build/${EXPORT}" sources="src/main/java/org/hacdc/crystal" targetsdk="${JC_CLASSIC_HOME}">
<applet class="org.hacdc.crystal.Crystal" aid="${RID}${AID}" />
<import jar="tools/bcprov-jdk18on-1.80.jar" />
</cap>
@ -57,7 +59,7 @@
<target name="install" depends="build">
<java jar="tools/gp.jar" fork="true">
<arg value="-reinstall" />
<arg value="${EXPORT}" />
<arg value="build/${EXPORT}" />
</java>
</target>

42
pom.xml Normal file
View File

@ -0,0 +1,42 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.hacdc.crystal</groupId>
<artifactId>crystal</artifactId>
<version>1.0-ALPHA</version>
<name>crystal</name>
<url>https://wiki.hacdc.org</url>
<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.80</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<target>
<ant antfile="${basedir}/build.xml" inheritAll="false">
<target name="build"/>
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,49 @@
package org.hacdc.crystal;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
public class Crystal extends Applet {
public static void install(byte[] buffer, short offset, byte length){
// GP-compliant JavaCard applet registration
new Crystal().register();
}
public void process(APDU apdu){
// Process APDU commands
if (selectingApplet()) {
return;
}
byte[] buffer = apdu.getBuffer();
switch (buffer[ISO7816.OFFSET_INS]) {
case (byte) 0x01:
processCMD1(apdu);
break;
default:
// Unknown Instruction
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
private void processCMD1(APDU apdu) throws ISOException {
// Process command 1
short len = apdu.setIncomingAndReceive();
byte[] buffer = apdu.getBuffer();
short offset = apdu.getOffsetCdata();
byte p1 = buffer[ISO7816.OFFSET_P1]; // 00, could encode further parameters for CMD1 here
byte p2 = buffer[ISO7816.OFFSET_P2]; // 00, could encode further parameters for CMD2 here
if (p1 == 0x00 && p2 == 0x00) {
if (len != 16) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
} else {
apdu.setOutgoingAndSend(dataOffset, (short)16);
}
} else {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
return;
}
}

View File

@ -1,17 +0,0 @@
package org.hacdc.crystal;
import javacard.framework.APDU;
import javacard.framework.Applet;
public class Crystal extends Applet {
public static void install(byte[] buffer, short offset, byte length){
// GP-compliant JavaCard applet registration
new Crystal().register();
}
@Override
public void process(APDU apdu){
// Process APDU commands
}
}

View File

@ -1 +0,0 @@
.level = SEVERE