diff --git a/.gitignore b/.gitignore index 6a30819..1246dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /.gradle /.idea +/.vscode /build /venv +.env __pycache__ /bin \ No newline at end of file diff --git a/README.md b/README.md index b893383..b814e62 100644 --- a/README.md +++ b/README.md @@ -25,15 +25,19 @@ 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 and define a `JC_HOME` environment variable pointing it. + +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" + } + ``` + +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 buildJavaCard + ./gradlew build ``` diff --git a/build.gradle b/build.gradle index 5983cbb..bb8c56f 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,19 +9,18 @@ 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' +configurations { + jcdk +} - testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1' +dependencies { + // JCDK dependencies for CAP generation + jcdk files("${System.getenv('JC_HOME')}/lib/api_classic-${JavaCardVersion}.jar") + + // Test dependencies use JCardSim + implementation 'com.klinec:jcardsim:3.0.6.0' + testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } test { @@ -56,20 +40,26 @@ tasks.register('testJar', Jar) { } } -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 +} + +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", "${AppletAID}", + "${PackageName}.FIDO2Applet", + "-target", "${JavaCardVersion}", + "${PackageName}", + "${PackageAID}", + "${PackageVersion}" } + +buildCap.dependsOn classesCap +build.dependsOn buildCap diff --git a/gradle.properties b/gradle.properties index de29a70..603b4d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,5 @@ -PackageID=A000000647 -ApplicationID=A0000006472F0001 \ No newline at end of file +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/requirements.txt b/requirements.txt index 1fc253e..6b7ca3f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -fido2[pcsc]==1.1.2 -JPype1==1.5.0 +fido2[pcsc]==1.1.3 +JPype1==1.5.2 parameterized==0.9.0 uhid==0.0.1 diff --git a/settings.gradle b/settings.gradle index ec89f1d..dde8319 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1 @@ rootProject.name = "fido2applet" -