From 576cabb04b2a5e479159a4a025afd80256394324 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 10 Jun 2019 15:11:16 +0200 Subject: [PATCH] better SELECT response --- build.gradle | 2 +- buildSrc/build.gradle | 2 +- .../java/im/status/keycard/CashApplet.java | 19 ++++++++++++++++--- .../java/im/status/keycard/KeycardTest.java | 4 ++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index b528ae9..3ed31f5 100644 --- a/build.gradle +++ b/build.gradle @@ -57,7 +57,7 @@ dependencies { testCompile(files("../jcardsim/jcardsim-3.0.5-SNAPSHOT.jar")) testCompile('org.web3j:core:2.3.1') testCompile('org.bitcoinj:bitcoinj-core:0.14.5') - testCompile('com.github.status-im.status-keycard-java:desktop:8b73b6c') + testCompile('com.github.status-im.status-keycard-java:desktop:49ad217') testCompile('org.bouncycastle:bcprov-jdk15on:1.60') testCompile("org.junit.jupiter:junit-jupiter-api:5.1.1") testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.1") diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index d7bb944..3cf0e9d 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -4,5 +4,5 @@ repositories { } dependencies { - compile 'com.github.status-im.status-keycard-java:desktop:8b73b6c' + compile 'com.github.status-im.status-keycard-java:desktop:49ad217' } \ No newline at end of file diff --git a/src/main/java/im/status/keycard/CashApplet.java b/src/main/java/im/status/keycard/CashApplet.java index 59454e7..a293671 100644 --- a/src/main/java/im/status/keycard/CashApplet.java +++ b/src/main/java/im/status/keycard/CashApplet.java @@ -84,10 +84,23 @@ public class CashApplet extends Applet { private void selectApplet(APDU apdu) { byte[] apduBuffer = apdu.getBuffer(); - apduBuffer[0] = KeycardApplet.TLV_PUB_KEY; - apduBuffer[1] = (byte) publicKey.getW(apduBuffer, (short) 2); + short off = 0; - apdu.setOutgoingAndSend((short) 0, (short)(apduBuffer[1] + 2)); + apduBuffer[off++] = KeycardApplet.TLV_APPLICATION_INFO_TEMPLATE; + short lenoff = off++; + + apduBuffer[off++] = KeycardApplet.TLV_PUB_KEY; + short keyLength = publicKey.getW(apduBuffer, (short) (off + 1)); + apduBuffer[off++] = (byte) keyLength; + off += keyLength; + + apduBuffer[off++] = KeycardApplet.TLV_INT; + apduBuffer[off++] = 2; + Util.setShort(apduBuffer, off, KeycardApplet.APPLICATION_VERSION); + off += 2; + + apduBuffer[lenoff] = (byte)(off - lenoff - 1); + apdu.setOutgoingAndSend((short) 0, off); } private void sign(APDU apdu) { diff --git a/src/test/java/im/status/keycard/KeycardTest.java b/src/test/java/im/status/keycard/KeycardTest.java index 55de2cd..be2542c 100644 --- a/src/test/java/im/status/keycard/KeycardTest.java +++ b/src/test/java/im/status/keycard/KeycardTest.java @@ -1446,8 +1446,8 @@ public class KeycardTest { APDUResponse response = cashCmdSet.select(); assertEquals(0x9000, response.getSw()); - ApplicationInfo info = new ApplicationInfo(response.getData()); - assertFalse(info.isInitializedCard()); + CashApplicationInfo info = new CashApplicationInfo(response.getData()); + assertTrue(info.getAppVersion() > 0); byte[] data = "some data to be hashed".getBytes(); byte[] hash = sha256(data);