Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applet adjustment for jcardsim to work #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 37 additions & 33 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
}

84 changes: 46 additions & 38 deletions src/main/java/org/idpass/auth/AuthApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* AuthApplet
*
*/
public final class AuthApplet extends IdpassApplet {
public class AuthApplet extends IdpassApplet {

private static final byte LENGTH_INSTALL_PARAMS = 0;

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down