Skip to content

Gradle cleanup #39

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

Open
wants to merge 6 commits into
base: main
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/.gradle
/.idea
/.vscode
/build
/venv
.env
__pycache__
/bin
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<path_to_your_jckit_directory>
```

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
```


Expand Down
76 changes: 33 additions & 43 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 {
Expand All @@ -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
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
PackageID=A000000647
ApplicationID=A0000006472F0001
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
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
rootProject.name = "fido2applet"