From c87ffe9bfa539b1f91613723b51d3afe9f506246 Mon Sep 17 00:00:00 2001 From: Elizabeth Cray Date: Mon, 10 Mar 2025 13:56:43 -0400 Subject: [PATCH] Begin porting example to JC221 --- .gitignore | 2 + pom.xml | 42 ++++++++++++++++++++ src/main/java/org/hacdc/crystal/Crystal.java | 14 +++++++ 3 files changed, 58 insertions(+) create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore index e87ca6f..fd5de9f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ tools/ *.cap *.class *.jar +target/ +.vscode/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4405e86 --- /dev/null +++ b/pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + org.hacdc.crystal + crystal + 1.0-ALPHA + crystal + https://wiki.hacdc.org + + + + org.bouncycastle + bcprov-jdk18on + 1.80 + + + + + + + maven-antrun-plugin + 3.1.0 + + + generate-sources + + + + + + + + + run + + + + + + + diff --git a/src/main/java/org/hacdc/crystal/Crystal.java b/src/main/java/org/hacdc/crystal/Crystal.java index 462e1a0..e8fb9e7 100644 --- a/src/main/java/org/hacdc/crystal/Crystal.java +++ b/src/main/java/org/hacdc/crystal/Crystal.java @@ -30,6 +30,20 @@ public class Crystal extends Applet { 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; } }