From 7ab01fd391a1d3b0a3b63e698ed2bf4f45d2a773 Mon Sep 17 00:00:00 2001 From: dexter Date: Fri, 3 Jan 2020 18:27:41 +0800 Subject: [PATCH 1/5] Applet adjustment for jcardsim to work --- build.gradle | 67 ++++++++++--------- .../idpass/datastorage/DatastorageApplet.java | 29 ++++++++ 2 files changed, 66 insertions(+), 30 deletions(-) diff --git a/build.gradle b/build.gradle index 43049ff..9c1bf6a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,44 +1,51 @@ group 'card-applets' apply plugin: 'javacard' -// Common settings, definitions -final def rootPath = rootDir.absolutePath -final def libs = rootPath + '/libs' -final def libs_gp211 = rootPath + '/libs/globalplatform-2_1_1' -final def libsSdk = rootPath + '/libs-sdks' -final def JC304 = libsSdk + '/jc304_kit' +compileJava { + dependsOn 'buildJavaCard' +} +buildJavaCard { + dependsOn ':tools:buildJavaCard' +} -convertJavacard { - dependsOn ':tools:convertJavacard' +jar { + manifest { + attributes ("Uri":_getGitHash(projectDir)) + attributes ("Commit-hash":_getUri(projectDir)) + } + baseName 'idpass_datastorage' } javacard { - sdkVersion = "3.0.4" - - cap { - packageName = 'org.idpass.datastorage' - version = '0.1' - aid = '0xF7:0x69:0x64:0x70:0x61:0x73:0x73:0x03' - - applet { - className = 'DatastorageApplet' - aid = '0xf7:0x69:0x64:0x70:0x61:0x73:0x73:0x03:0x01:0x00:0x01' - } - - dependencies { - compile fileTree(dir: libs_gp211, include: '*.jar') - javacardExport files([ - libs_gp211, - rootDir.absolutePath + '/build/javacard/' - ]) - compile files(rootDir.absolutePath + '/build/classes/java/main/') - compile project(':tools') + config { + jckit _JC_SELECTED + // Using custom repo with jcardsim + addSurrogateJcardSimRepo false + addImplicitJcardSim false + addImplicitJcardSimJunit false + + cap { + packageName = 'org.idpass.datastorage' + version = '0.1' + aid = '0xF7:0x69:0x64:0x70:0x61:0x73:0x73:0x03' + output 'datastorage.cap' + + applet { + className = 'DatastorageApplet' + aid = '0xf7:0x69:0x64:0x70:0x61:0x73:0x73:0x03:0x01:0x00:0x01' + } + + dependencies { + remote 'local:gp211:2.1.1' + remote 'local:tools:0.0.1' + } } } } compileJava { - sourceCompatibility = 1.6 - targetCompatibility = 1.6 + sourceCompatibility = _sourceCompatibility + targetCompatibility = _targetCompatibility } + diff --git a/src/main/java/org/idpass/datastorage/DatastorageApplet.java b/src/main/java/org/idpass/datastorage/DatastorageApplet.java index d3958b2..cabb9d7 100644 --- a/src/main/java/org/idpass/datastorage/DatastorageApplet.java +++ b/src/main/java/org/idpass/datastorage/DatastorageApplet.java @@ -62,6 +62,35 @@ public static void install(byte[] bArray, short bOffset, byte bLength) { private byte secret; private VirtualCardRepository virtualCardRepository; + protected DatastorageApplet(byte[] bArray, short bOffset, byte bLength) { + byte lengthAID = bArray[bOffset]; + short offsetAID = (short) (bOffset + 1); + short offset = bOffset; + offset += (bArray[offset]); // skip aid + offset++; + offset += (bArray[offset]); // skip privileges + offset++; + + // default params + + byte secret = DEFAULT_SECRET; + + // read params + short lengthIn = bArray[offset]; + if (lengthIn != 0) { + + if (1 <= lengthIn) { + // param 1 - not mandatory + secret = bArray[(short) (offset + 1)]; + } + + } + + this.secret = secret; + virtualCardRepository = VirtualCardRepository.create(); + register(bArray, offsetAID, lengthAID); + } + public DatastorageApplet(byte secret) { this.secret = secret; virtualCardRepository = VirtualCardRepository.create(); From 9f186617b2474da5849ee4c09ea1d309e704e6fe Mon Sep 17 00:00:00 2001 From: dexter Date: Mon, 6 Jan 2020 16:05:14 +0800 Subject: [PATCH 2/5] Call Applet::register() outside constructor --- src/main/java/org/idpass/datastorage/DatastorageApplet.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/idpass/datastorage/DatastorageApplet.java b/src/main/java/org/idpass/datastorage/DatastorageApplet.java index cabb9d7..63209eb 100644 --- a/src/main/java/org/idpass/datastorage/DatastorageApplet.java +++ b/src/main/java/org/idpass/datastorage/DatastorageApplet.java @@ -86,9 +86,11 @@ protected DatastorageApplet(byte[] bArray, short bOffset, byte bLength) { } + this.aid_offset = offsetAID ; + this.aid_len = lengthAID; + this.secret = secret; virtualCardRepository = VirtualCardRepository.create(); - register(bArray, offsetAID, lengthAID); } public DatastorageApplet(byte secret) { @@ -177,4 +179,4 @@ private void processSwitchNextVirtualCard() { : virtualCard.getId()); setOutgoingAndSendWrap(buffer, Utils.SHORT_00, length); } -} \ No newline at end of file +} From 5652acf12591f32ff845e728c6b29dde32608d4c Mon Sep 17 00:00:00 2001 From: dexter Date: Mon, 6 Jan 2020 19:30:42 +0800 Subject: [PATCH 3/5] Save 3 bytes in applet --- .../java/org/idpass/datastorage/DatastorageApplet.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/idpass/datastorage/DatastorageApplet.java b/src/main/java/org/idpass/datastorage/DatastorageApplet.java index 63209eb..67a9e74 100644 --- a/src/main/java/org/idpass/datastorage/DatastorageApplet.java +++ b/src/main/java/org/idpass/datastorage/DatastorageApplet.java @@ -62,7 +62,7 @@ public static void install(byte[] bArray, short bOffset, byte bLength) { private byte secret; private VirtualCardRepository virtualCardRepository; - protected DatastorageApplet(byte[] bArray, short bOffset, byte bLength) { + protected DatastorageApplet(byte[] bArray, short bOffset, byte bLength, byte[] retval) { byte lengthAID = bArray[bOffset]; short offsetAID = (short) (bOffset + 1); short offset = bOffset; @@ -86,8 +86,9 @@ protected DatastorageApplet(byte[] bArray, short bOffset, byte bLength) { } - this.aid_offset = offsetAID ; - this.aid_len = lengthAID; + Util.setShort(retval,(short)0x0000,offsetAID); + retval[2] = lengthAID; + retval[3] = 0x00; this.secret = secret; virtualCardRepository = VirtualCardRepository.create(); From 2d04ad073d856c351075207b322c376293c53924 Mon Sep 17 00:00:00 2001 From: dexter Date: Sat, 11 Jan 2020 06:20:57 +0800 Subject: [PATCH 4/5] Streamline constructor to save bytes --- .../idpass/datastorage/DatastorageApplet.java | 32 +++---------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/idpass/datastorage/DatastorageApplet.java b/src/main/java/org/idpass/datastorage/DatastorageApplet.java index 67a9e74..de26fcf 100644 --- a/src/main/java/org/idpass/datastorage/DatastorageApplet.java +++ b/src/main/java/org/idpass/datastorage/DatastorageApplet.java @@ -31,31 +31,13 @@ public class DatastorageApplet extends IdpassApplet implements SIOAuthListener { private static final short NO_ACTIVE_VIRTUAL_CARDS = (short) 0xFFFF; public static void install(byte[] bArray, short bOffset, byte bLength) { - byte lengthAID = bArray[bOffset]; - short offsetAID = (short) (bOffset + 1); - short offset = bOffset; - offset += (bArray[offset]); // skip aid - offset++; - offset += (bArray[offset]); // skip privileges - offset++; - - // default params - - byte secret = DEFAULT_SECRET; - - // read params - short lengthIn = bArray[offset]; - if (lengthIn != 0) { - - if (1 <= lengthIn) { - // param 1 - not mandatory - secret = bArray[(short) (offset + 1)]; - } + byte[] retval = new byte[3]; + DatastorageApplet applet = new DatastorageApplet(bArray, bOffset, bLength, retval); - } + short offsetAID = Util.makeShort(retval[0], retval[1]); + byte lengthAID = retval[2]; // GP-compliant JavaCard applet registration - DatastorageApplet applet = new DatastorageApplet(secret); applet.register(bArray, offsetAID, lengthAID); } @@ -88,17 +70,11 @@ protected DatastorageApplet(byte[] bArray, short bOffset, byte bLength, byte[] r Util.setShort(retval,(short)0x0000,offsetAID); retval[2] = lengthAID; - retval[3] = 0x00; this.secret = secret; virtualCardRepository = VirtualCardRepository.create(); } - public DatastorageApplet(byte secret) { - this.secret = secret; - virtualCardRepository = VirtualCardRepository.create(); - } - /** * Shareable interface standard call from JCOP */ From 5dc7f9cfa488240927b4e7d282a275e8cac71ced Mon Sep 17 00:00:00 2001 From: dexter Date: Thu, 6 Feb 2020 23:54:03 +0800 Subject: [PATCH 5/5] Fix install params --- .../org/idpass/datastorage/DatastorageApplet.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/idpass/datastorage/DatastorageApplet.java b/src/main/java/org/idpass/datastorage/DatastorageApplet.java index de26fcf..72876ff 100644 --- a/src/main/java/org/idpass/datastorage/DatastorageApplet.java +++ b/src/main/java/org/idpass/datastorage/DatastorageApplet.java @@ -31,20 +31,16 @@ public class DatastorageApplet extends IdpassApplet implements SIOAuthListener { private static final short NO_ACTIVE_VIRTUAL_CARDS = (short) 0xFFFF; public static void install(byte[] bArray, short bOffset, byte bLength) { - byte[] retval = new byte[3]; - DatastorageApplet applet = new DatastorageApplet(bArray, bOffset, bLength, retval); - - short offsetAID = Util.makeShort(retval[0], retval[1]); - byte lengthAID = retval[2]; + DatastorageApplet applet = new DatastorageApplet(bArray, bOffset, bLength); // GP-compliant JavaCard applet registration - applet.register(bArray, offsetAID, lengthAID); + applet.register(bArray, (short)(bOffset + 1), bArray[bOffset]); } private byte secret; private VirtualCardRepository virtualCardRepository; - protected DatastorageApplet(byte[] bArray, short bOffset, byte bLength, byte[] retval) { + protected DatastorageApplet(byte[] bArray, short bOffset, byte bLength) { byte lengthAID = bArray[bOffset]; short offsetAID = (short) (bOffset + 1); short offset = bOffset; @@ -68,9 +64,6 @@ protected DatastorageApplet(byte[] bArray, short bOffset, byte bLength, byte[] r } - Util.setShort(retval,(short)0x0000,offsetAID); - retval[2] = lengthAID; - this.secret = secret; virtualCardRepository = VirtualCardRepository.create(); }