From 6b67d35113bb5034c0a6071cbc5cfb8fb91f7248 Mon Sep 17 00:00:00 2001 From: Adrian Castillo Date: Mon, 17 Feb 2025 12:18:04 +0100 Subject: [PATCH 1/6] Gradle cleanup --- .gitignore | 1 + README.md | 27 +++++++++---- build.gradle | 100 ++++++++++++++++++++-------------------------- gradle.properties | 2 - 4 files changed, 64 insertions(+), 66 deletions(-) delete mode 100644 gradle.properties diff --git a/.gitignore b/.gitignore index 6a30819..35c6d01 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.gradle /.idea +/.vscode /build /venv __pycache__ diff --git a/README.md b/README.md index b893383..7df13b0 100644 --- a/README.md +++ b/README.md @@ -25,15 +25,28 @@ detailed requirements. You might be interested in [reading about the security model](docs/security_model.md). ## Environment Setup and Building the application -1. **Download JavacardKit**: Obtain a copy of [JavacardKit version 3.0.4](https://www.oracle.com/java/technologies/javacard-sdk-downloads.html) (or jckit_303 if you prefer). -2. **Set Environment Variable**: Configure the `JC_HOME` environment variable to point to your JavacardKit directory. - ```bash - export JC_HOME= - ``` -3. **Run Gradle Build**: Execute the following command to build the JavaCard application, which will produce a `.cap` file for installation. +1. **Download Java Card Deveploment Kit**: Obtain a copy of Oracle's [Java Card Development Kit](https://www.oracle.com/java/technologies/javacard-downloads.html). As of February 2025, the latest version was 24.1. Unzip it to a folder at the same level as your copy of FIDO2Applet and rename the folder to `jckit`. + +2. **Download Java Card Simulator**: Obtain a copy of [JCardSim](https://github.com/licel/jcardsim/packages/1650016). You can just download the `jcardsim-3.0.5.jar` file and place it at the same level as your copy of FIDO2Applet. You end with something like this: + ```bash + . + ├── FIDO2Applet + ├── jckit + │ ├── ... + ├── jcardsim-3.0.5.jar + ``` + +3. **Verify you have a compatible Java Development Kit**: Gradle needs to use a JDK compatible with the Java Card Development Kit. As of February 2025, version 24.1 is compatible with JDK 8 to 17. If you are using Visual Studio Code, you can set the `java.import.gradle.java.home` setting in your workspace `settings.json` file to point to the JDK you want to use. For example: + ```json + { + "java.import.gradle.java.home": "/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home" + } + ``` + +4. **Run Gradle Build**: When you run a regular build task in Gradle, it will produce a `.cap` file for installation in the `/build/classes/javacard` directory. You can use the following command to build the application: ```bash - ./gradlew buildJavaCard + ./gradlew build ``` diff --git a/build.gradle b/build.gradle index 5983cbb..1701a18 100644 --- a/build.gradle +++ b/build.gradle @@ -1,20 +1,5 @@ -buildscript { - repositories { - mavenCentral() - maven { url "https://javacard.pro/maven" } - } -} - - plugins { id("java") - id("com.klinec.gradle.javacard") version "1.8.0" apply false -} - -var jcHomeSet = System.getenv("JC_HOME") != null -if (!jcHomeSet) { - project.logger.warn("JC_HOME environment variable not set - doing a testing/fake build with jCardSim!") - project.logger.warn("YOU WILL NOT BE ABLE TO BUILD A JAVACARD APPLET THIS WAY") } group = "us.q3q" @@ -24,52 +9,53 @@ repositories { mavenCentral() } -dependencies { - if (jcHomeSet) { - testImplementation(group: 'com.klinec', name: 'jcardsim', version: '3.0.5.11') { - // Javacard will be provided by the user at runtime through the JC_HOME env var - exclude(group: 'oracle.javacard', module: 'api_classic') - } - } else { - // Perform a full-test build, since there's no javacard SDK - implementation(group: 'com.klinec', name: 'jcardsim', version: '3.0.5.11') - } - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.1' +// Create a new configuration for JCDK compilation +configurations { + jcdk +} - testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1' +dependencies { + // JCDK dependencies for CAP generation + jcdk files('../jckit/lib/api_classic-3.0.5.jar') + + // Main and test dependencies use JCardSim + implementation files('../jcardsim-3.0.5.jar') + testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } test { useJUnitPlatform() } -tasks.register('testJar', Jar) { - archiveBaseName = project.name + '-tests' - duplicatesStrategy = 'include' - from sourceSets.test.output + sourceSets.test.allSource - from { - sourceSets.test.runtimeClasspath.filter { - it.toString().indexOf("jcardsim-") != -1 - }.collect { - zipTree(it) - } - } -} - -if (jcHomeSet) { - apply plugin: "com.klinec.gradle.javacard" - javacard { - config { - cap { - packageName 'us.q3q.fido2' - version '0.4' - aid PackageID - output 'FIDO2.cap' - applet { - className 'us.q3q.fido2.FIDO2Applet' - aid ApplicationID - } - } - } - } -} +// Special task for compiling with JCDK API +task classesCap(type: JavaCompile) { + source = sourceSets.main.java + classpath = configurations.jcdk + destinationDirectory = file("${buildDir}/classes/jcdk") + sourceCompatibility = 1.7 + targetCompatibility = 1.7 +} + +// Add package configuration +def packageConfig = [ + AID: "0xA0:0x00:0x00:0x06:0x47:0x2F:0x00:0xFE", + name: "us.q3q.fido2", + AppletAID: "0xA0:0x00:0x00:0x06:0x47:0x2F:0x00:0x01", + version: "1.0" +] + +task(buildCap, type: JavaExec) { + mainClass = "com.sun.javacard.converter.Main" + classpath = files("${projectDir}/../jckit/lib/tools.jar") + args "-classdir", "${buildDir}/classes/jcdk", + "-applet", "${packageConfig.AppletAID}", + "${packageConfig.name}.FIDO2Applet", + "-target", "3.0.5", + "${packageConfig.name}", + "${packageConfig.AID}", + "${packageConfig.version}" +} + +buildCap.dependsOn classesCap +build.dependsOn buildCap \ No newline at end of file diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index de29a70..0000000 --- a/gradle.properties +++ /dev/null @@ -1,2 +0,0 @@ -PackageID=A000000647 -ApplicationID=A0000006472F0001 \ No newline at end of file From 6968a4547940c02e3803a1676829ef69849b18ff Mon Sep 17 00:00:00 2001 From: Adrian Castillo Date: Tue, 18 Feb 2025 11:24:23 +0100 Subject: [PATCH 2/6] Update python requirements --- build.gradle | 13 +++++++++++++ requirements.txt | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 1701a18..0ddfb50 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,19 @@ test { useJUnitPlatform() } +tasks.register('testJar', Jar) { + archiveBaseName = project.name + '-tests' + duplicatesStrategy = 'include' + from sourceSets.test.output + sourceSets.test.allSource + from { + sourceSets.test.runtimeClasspath.filter { + it.toString().indexOf("jcardsim-") != -1 + }.collect { + zipTree(it) + } + } +} + // Special task for compiling with JCDK API task classesCap(type: JavaCompile) { source = sourceSets.main.java diff --git a/requirements.txt b/requirements.txt index 1fc253e..2c73f98 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -fido2[pcsc]==1.1.2 -JPype1==1.5.0 +fido2[pcsc]==1.2.0 +JPype1==1.5.2 parameterized==0.9.0 uhid==0.0.1 From 265f81b92390909a1904dad6ecb1599dccf58008 Mon Sep 17 00:00:00 2001 From: Adrian Castillo Date: Sat, 22 Feb 2025 23:24:59 +0100 Subject: [PATCH 3/6] Use JC_HOME pointing to Java Card Development Kit --- .gitignore | 1 + README.md | 13 +++---------- build.gradle | 9 ++++----- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 35c6d01..1246dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ /.vscode /build /venv +.env __pycache__ /bin \ No newline at end of file diff --git a/README.md b/README.md index 7df13b0..f173d0d 100644 --- a/README.md +++ b/README.md @@ -26,18 +26,11 @@ You might be interested in [reading about the security model](docs/security_mode ## Environment Setup and Building the application -1. **Download Java Card Deveploment Kit**: Obtain a copy of Oracle's [Java Card Development Kit](https://www.oracle.com/java/technologies/javacard-downloads.html). As of February 2025, the latest version was 24.1. Unzip it to a folder at the same level as your copy of FIDO2Applet and rename the folder to `jckit`. +1. **Download Java Card Deveploment Kit**: Obtain a copy of Oracle's [Java Card Development Kit](https://www.oracle.com/java/technologies/javacard-downloads.html). As of February 2025, the latest version was 24.1. Unzip it and define a `JC_HOME` environment variable pointing it. -2. **Download Java Card Simulator**: Obtain a copy of [JCardSim](https://github.com/licel/jcardsim/packages/1650016). You can just download the `jcardsim-3.0.5.jar` file and place it at the same level as your copy of FIDO2Applet. You end with something like this: - ```bash - . - ├── FIDO2Applet - ├── jckit - │ ├── ... - ├── jcardsim-3.0.5.jar - ``` +2. **Download Java Card Simulator**: Obtain a copy of [JCardSim](https://github.com/licel/jcardsim/packages/1650016). You can just download the `jcardsim-3.0.5.jar` file and place it in the folder where you've extracted the Java Card Development Kit. -3. **Verify you have a compatible Java Development Kit**: Gradle needs to use a JDK compatible with the Java Card Development Kit. As of February 2025, version 24.1 is compatible with JDK 8 to 17. If you are using Visual Studio Code, you can set the `java.import.gradle.java.home` setting in your workspace `settings.json` file to point to the JDK you want to use. For example: +3. **Verify you have a compatible Java Development Kit**: Gradle needs to use a JDK compatible with the Java Card Development Kit. As of February 2025, version 24.1 is compatible with JDK 8 to 17. Make sure your `JAVA_HOME` environment variable points to that JDK. If you are using Visual Studio Code, you can set the `java.import.gradle.java.home` setting in your workspace `settings.json` file to point to the JDK you want to use. For example: ```json { "java.import.gradle.java.home": "/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home" diff --git a/build.gradle b/build.gradle index 0ddfb50..44d363e 100644 --- a/build.gradle +++ b/build.gradle @@ -16,10 +16,10 @@ configurations { dependencies { // JCDK dependencies for CAP generation - jcdk files('../jckit/lib/api_classic-3.0.5.jar') + jcdk files("${System.getenv('JC_HOME')}/lib/api_classic-3.0.5.jar") - // Main and test dependencies use JCardSim - implementation files('../jcardsim-3.0.5.jar') + // Test dependencies use JCardSim + implementation files("${System.getenv('JC_HOME')}/jcardsim-3.0.5.jar") testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } @@ -50,7 +50,6 @@ task classesCap(type: JavaCompile) { targetCompatibility = 1.7 } -// Add package configuration def packageConfig = [ AID: "0xA0:0x00:0x00:0x06:0x47:0x2F:0x00:0xFE", name: "us.q3q.fido2", @@ -60,7 +59,7 @@ def packageConfig = [ task(buildCap, type: JavaExec) { mainClass = "com.sun.javacard.converter.Main" - classpath = files("${projectDir}/../jckit/lib/tools.jar") + classpath = files("${System.getenv('JC_HOME')}/lib/tools.jar") args "-classdir", "${buildDir}/classes/jcdk", "-applet", "${packageConfig.AppletAID}", "${packageConfig.name}.FIDO2Applet", From ebf79d585f4932f1d4c4cb6d28e11e3dd435b0f7 Mon Sep 17 00:00:00 2001 From: Adrian Castillo Date: Sat, 22 Feb 2025 23:33:59 +0100 Subject: [PATCH 4/6] Target Java Card 3.0.4 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 44d363e..ed69d45 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ task(buildCap, type: JavaExec) { args "-classdir", "${buildDir}/classes/jcdk", "-applet", "${packageConfig.AppletAID}", "${packageConfig.name}.FIDO2Applet", - "-target", "3.0.5", + "-target", "3.0.4", "${packageConfig.name}", "${packageConfig.AID}", "${packageConfig.version}" From a6bee7365149835a5fde66d90540fde698dc6996 Mon Sep 17 00:00:00 2001 From: Adrian Castillo Date: Wed, 26 Feb 2025 16:41:03 +0100 Subject: [PATCH 5/6] Keep using fido2 1.1.3 for testing --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2c73f98..6b7ca3f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -fido2[pcsc]==1.2.0 +fido2[pcsc]==1.1.3 JPype1==1.5.2 parameterized==0.9.0 uhid==0.0.1 From a039f71721124a7dedbe268ffdff26fc10f85197 Mon Sep 17 00:00:00 2001 From: Adrian Castillo Date: Mon, 3 Mar 2025 12:52:15 +0100 Subject: [PATCH 6/6] Use JCardSim from Maven Central and use properties for building --- README.md | 6 ++---- build.gradle | 26 +++++++++----------------- gradle.properties | 5 +++++ settings.gradle | 1 - 4 files changed, 16 insertions(+), 22 deletions(-) create mode 100644 gradle.properties diff --git a/README.md b/README.md index f173d0d..b814e62 100644 --- a/README.md +++ b/README.md @@ -28,16 +28,14 @@ You might be interested in [reading about the security model](docs/security_mode 1. **Download Java Card Deveploment Kit**: Obtain a copy of Oracle's [Java Card Development Kit](https://www.oracle.com/java/technologies/javacard-downloads.html). As of February 2025, the latest version was 24.1. Unzip it and define a `JC_HOME` environment variable pointing it. -2. **Download Java Card Simulator**: Obtain a copy of [JCardSim](https://github.com/licel/jcardsim/packages/1650016). You can just download the `jcardsim-3.0.5.jar` file and place it in the folder where you've extracted the Java Card Development Kit. - -3. **Verify you have a compatible Java Development Kit**: Gradle needs to use a JDK compatible with the Java Card Development Kit. As of February 2025, version 24.1 is compatible with JDK 8 to 17. Make sure your `JAVA_HOME` environment variable points to that JDK. If you are using Visual Studio Code, you can set the `java.import.gradle.java.home` setting in your workspace `settings.json` file to point to the JDK you want to use. For example: +2. **Verify you have a compatible Java Development Kit**: Gradle needs to use a JDK compatible with the Java Card Development Kit. As of February 2025, version 24.1 is compatible with JDK 8 to 17. Make sure your `JAVA_HOME` environment variable points to that JDK. If you are using Visual Studio Code, you can set the `java.import.gradle.java.home` setting in your workspace `settings.json` file to point to the JDK you want to use. For example: ```json { "java.import.gradle.java.home": "/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home" } ``` -4. **Run Gradle Build**: When you run a regular build task in Gradle, it will produce a `.cap` file for installation in the `/build/classes/javacard` directory. You can use the following command to build the application: +3. **Run Gradle Build**: When you run a regular build task in Gradle, it will produce a `.cap` file for installation in the `/build/classes/javacard` directory. You can use the following command to build the application: ```bash ./gradlew build ``` diff --git a/build.gradle b/build.gradle index ed69d45..bb8c56f 100644 --- a/build.gradle +++ b/build.gradle @@ -9,17 +9,16 @@ repositories { mavenCentral() } -// Create a new configuration for JCDK compilation configurations { jcdk } dependencies { // JCDK dependencies for CAP generation - jcdk files("${System.getenv('JC_HOME')}/lib/api_classic-3.0.5.jar") + jcdk files("${System.getenv('JC_HOME')}/lib/api_classic-${JavaCardVersion}.jar") // Test dependencies use JCardSim - implementation files("${System.getenv('JC_HOME')}/jcardsim-3.0.5.jar") + implementation 'com.klinec:jcardsim:3.0.6.0' testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } @@ -50,24 +49,17 @@ task classesCap(type: JavaCompile) { targetCompatibility = 1.7 } -def packageConfig = [ - AID: "0xA0:0x00:0x00:0x06:0x47:0x2F:0x00:0xFE", - name: "us.q3q.fido2", - AppletAID: "0xA0:0x00:0x00:0x06:0x47:0x2F:0x00:0x01", - version: "1.0" -] - task(buildCap, type: JavaExec) { mainClass = "com.sun.javacard.converter.Main" classpath = files("${System.getenv('JC_HOME')}/lib/tools.jar") args "-classdir", "${buildDir}/classes/jcdk", - "-applet", "${packageConfig.AppletAID}", - "${packageConfig.name}.FIDO2Applet", - "-target", "3.0.4", - "${packageConfig.name}", - "${packageConfig.AID}", - "${packageConfig.version}" + "-applet", "${AppletAID}", + "${PackageName}.FIDO2Applet", + "-target", "${JavaCardVersion}", + "${PackageName}", + "${PackageAID}", + "${PackageVersion}" } buildCap.dependsOn classesCap -build.dependsOn buildCap \ No newline at end of file +build.dependsOn buildCap diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..603b4d7 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,5 @@ +PackageAID=0xA0:0x00:0x00:0x06:0x47:0x2F:0x00:0xFE +PackageName=us.q3q.fido2 +PackageVersion=1.0 +AppletAID=0xA0:0x00:0x00:0x06:0x47:0x2F:0x00:0x01 +JavaCardVersion=3.0.4 diff --git a/settings.gradle b/settings.gradle index ec89f1d..dde8319 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1 @@ rootProject.name = "fido2applet" -