diff --git a/build.gradle b/build.gradle index 7c3ea0c..fbdcb0d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,47 +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_auth' } javacard { -// jckit JC304 - - - sdkVersion = "3.0.4" - - cap { - packageName = 'org.idpass.auth' - version = '0.1' - aid = '0xF7:0x69:0x64:0x70:0x61:0x73:0x73:0x01' - - applet { - className = 'AuthApplet' - aid = '0xF7:0x69:0x64:0x70:0x61:0x73:0x73:0x01:0x01:0x00:0x01' - } - - dependencies { - compile fileTree(dir: libs_gp211, include: '*.jar') - javacardExport files([ - libs_gp211, - rootPath + '/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.auth' + version = '0.1' + aid = '0xF7:0x69:0x64:0x70:0x61:0x73:0x73:0x01' + output 'auth.cap' + + applet { + className = 'AuthApplet' + aid = '0xF7:0x69:0x64:0x70:0x61:0x73:0x73:0x01: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/auth/AuthApplet.java b/src/main/java/org/idpass/auth/AuthApplet.java index 1383a40..d7fa84e 100644 --- a/src/main/java/org/idpass/auth/AuthApplet.java +++ b/src/main/java/org/idpass/auth/AuthApplet.java @@ -31,7 +31,7 @@ * AuthApplet * */ -public final class AuthApplet extends IdpassApplet { +public class AuthApplet extends IdpassApplet { private static final byte LENGTH_INSTALL_PARAMS = 0; @@ -72,43 +72,13 @@ public final class AuthApplet extends IdpassApplet { 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 - short personaInitCount = 1; - byte verifierType = VerifierBuilder.FINGERPRINT; - byte secret = DEFAULT_SECRET; - - // read params - short lengthIn = bArray[offset]; - if (lengthIn != 0) { - if (lengthIn < LENGTH_INSTALL_PARAMS) { - ISOException.throwIt(ISO7816.SW_WRONG_DATA); - } - - if (1 <= lengthIn) { - // param 1 - not mandatory - verifierType = bArray[(short) (offset + 1)]; - } - - if (2 <= lengthIn) { - // param 2 - not mandatory - personaInitCount = Util.makeShort(Utils.BYTE_00, bArray[(short) (offset + 2)]); - } - if (3 <= lengthIn) { - // param 3 - not mandatory - secret = bArray[(short) (offset + 3)]; - } - } + byte[] retval = new byte[3]; + AuthApplet applet = new AuthApplet(bArray, bOffset, bLength, retval); + short offsetAID = Util.makeShort(retval[0], retval[1]); + byte lengthAID = retval[2]; + // GP-compliant JavaCard applet registration - AuthApplet applet = new AuthApplet(personaInitCount, verifierType, secret); applet.register(bArray, offsetAID, lengthAID); } @@ -176,12 +146,50 @@ protected void processInternal(APDU apdu) throws ISOException { ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); } } + + protected AuthApplet(byte[] bArray, short bOffset, byte bLength, byte[] retval) { + 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 + short personaInitCount = 1; + byte verifierType = VerifierBuilder.FINGERPRINT; + byte secret = DEFAULT_SECRET; + + // read params + short lengthIn = bArray[offset]; + if (lengthIn != 0) { + if (lengthIn < LENGTH_INSTALL_PARAMS) { + ISOException.throwIt(ISO7816.SW_WRONG_DATA); + } + + if (1 <= lengthIn) { + // param 1 - not mandatory + verifierType = bArray[(short) (offset + 1)]; + } + + if (2 <= lengthIn) { + // param 2 - not mandatory + personaInitCount = Util.makeShort(Utils.BYTE_00, bArray[(short) (offset + 2)]); + } + if (3 <= lengthIn) { + // param 3 - not mandatory + secret = bArray[(short) (offset + 3)]; + } + } - private AuthApplet(short personaInitCount, byte verifierType, byte secret) { + Util.setShort(retval,(short)0x0000,offsetAID); + retval[2] = lengthAID; + personasRepository = PersonasRepository.create(personaInitCount); this.verifierType = verifierType; this.secret = secret; - this.listeners = new AID[0]; + this.listeners = new AID[0]; } private SIOAuthListener getSIOAuthListener(AID aid) {