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 #2

Open
wants to merge 5 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
67 changes: 37 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
}

25 changes: 13 additions & 12 deletions src/main/java/org/idpass/datastorage/DatastorageApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ 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];
DatastorageApplet applet = new DatastorageApplet(bArray, bOffset, bLength);

// GP-compliant JavaCard applet registration
applet.register(bArray, (short)(bOffset + 1), bArray[bOffset]);
}

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
Expand All @@ -54,19 +64,10 @@ public static void install(byte[] bArray, short bOffset, byte bLength) {

}

// GP-compliant JavaCard applet registration
DatastorageApplet applet = new DatastorageApplet(secret);
applet.register(bArray, offsetAID, lengthAID);
}

private byte secret;
private VirtualCardRepository virtualCardRepository;

public DatastorageApplet(byte secret) {
this.secret = secret;
virtualCardRepository = VirtualCardRepository.create();
}

/**
* Shareable interface standard call from JCOP
*/
Expand Down Expand Up @@ -148,4 +149,4 @@ private void processSwitchNextVirtualCard() {
: virtualCard.getId());
setOutgoingAndSendWrap(buffer, Utils.SHORT_00, length);
}
}
}