From 0a1dc595f0e33e4a1f51e7a5d0adb26287fa77d8 Mon Sep 17 00:00:00 2001 From: Michael Farrell Date: Fri, 30 Aug 2019 21:16:03 +1000 Subject: [PATCH 1/2] Adds TerminalFactorySpi, and (incomplete) ResponseAPDU implementation. - Provide stub TerminalFactorySpi implementation - Adds incomplete ResponseAPDU implementation - Adds CommandAPDU(bytes[], int, int) implementation This seems to be good enough to let jnasmartcardio work, grabbing a list of terminals directly with `Smartcardio.JnaTerminalFactorySpi(new Object()).engineTerminals().list()`. This let me successfully communicate with a (contactless) DESFire card using an ACR122U reader. --- .../java/javax/smartcardio/CommandAPDU.java | 2 ++ .../java/javax/smartcardio/ResponseAPDU.java | 30 +++++++++++++++++++ .../javax/smartcardio/TerminalFactorySpi.java | 6 ++++ 3 files changed, 38 insertions(+) create mode 100644 framework/src/main/java/javax/smartcardio/TerminalFactorySpi.java diff --git a/framework/src/main/java/javax/smartcardio/CommandAPDU.java b/framework/src/main/java/javax/smartcardio/CommandAPDU.java index fa6ac29..70415c1 100644 --- a/framework/src/main/java/javax/smartcardio/CommandAPDU.java +++ b/framework/src/main/java/javax/smartcardio/CommandAPDU.java @@ -19,6 +19,8 @@ public class CommandAPDU { * @param apduLength */ public CommandAPDU(byte[] apdu, int apduOffset, int apduLength) { + mBytes = Arrays.copyOfRange(apdu, apduOffset, apduLength); + mNc = apduLength; } /** diff --git a/framework/src/main/java/javax/smartcardio/ResponseAPDU.java b/framework/src/main/java/javax/smartcardio/ResponseAPDU.java index a952c42..3a4c60b 100644 --- a/framework/src/main/java/javax/smartcardio/ResponseAPDU.java +++ b/framework/src/main/java/javax/smartcardio/ResponseAPDU.java @@ -1,4 +1,34 @@ package javax.smartcardio; +import java.util.Arrays; + public class ResponseAPDU { + private byte[] mBytes; + + public ResponseAPDU(byte[] apdu) { + this.mBytes = apdu; + } + + public byte[] getBytes() { + return this.mBytes; + } + + public String toString() { + return "ResponseAPDU: " + mBytes.length + " bytes"; + } + + public int hashCode() { + return Arrays.hashCode(mBytes); + } + + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof ResponseAPDU)) { + return false; + } + ResponseAPDU other = (ResponseAPDU) obj; + return Arrays.equals(mBytes, other.getBytes()); + } } diff --git a/framework/src/main/java/javax/smartcardio/TerminalFactorySpi.java b/framework/src/main/java/javax/smartcardio/TerminalFactorySpi.java new file mode 100644 index 0000000..9667c45 --- /dev/null +++ b/framework/src/main/java/javax/smartcardio/TerminalFactorySpi.java @@ -0,0 +1,6 @@ +package javax.smartcardio; + +public abstract class TerminalFactorySpi { + protected TerminalFactorySpi() { } + protected abstract CardTerminals engineTerminals(); +} From 5bfe6b91951b59b14c600ab2647331774e7adf54 Mon Sep 17 00:00:00 2001 From: Michael Farrell Date: Sat, 31 Aug 2019 11:45:02 +1000 Subject: [PATCH 2/2] Clone apdu bytes like RequestAPDU --- framework/src/main/java/javax/smartcardio/ResponseAPDU.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/main/java/javax/smartcardio/ResponseAPDU.java b/framework/src/main/java/javax/smartcardio/ResponseAPDU.java index 3a4c60b..ad880ca 100644 --- a/framework/src/main/java/javax/smartcardio/ResponseAPDU.java +++ b/framework/src/main/java/javax/smartcardio/ResponseAPDU.java @@ -6,7 +6,7 @@ public class ResponseAPDU { private byte[] mBytes; public ResponseAPDU(byte[] apdu) { - this.mBytes = apdu; + this.mBytes = apdu.clone(); } public byte[] getBytes() {