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

2024 refresh with JC 3.2.0 support #97

Merged
merged 22 commits into from
Mar 15, 2024
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/robot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11, 17, 20 ]
java: [ 8, 11, 17, 21 ]
name: Java ${{ matrix.java }}
steps:
- name: Checkout with submodules
uses: actions/checkout@v3.5.0
uses: actions/checkout@v4.1.1
with:
submodules: true
- name: Setup java
uses: actions/setup-java@v3.11.0
uses: actions/setup-java@v4.0.0
with:
java-version: ${{ matrix.java }}
distribution: temurin
cache: maven
- name: Set SSH key
if: github.event_name != 'pull_request'
uses: webfactory/ssh-agent@v0.8.0
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
- name: Add host key
Expand All @@ -39,7 +39,7 @@ jobs:
if: matrix.java != 8
run: ./mvnw -T1C -B -U verify
- name: Run ANT tests
if: matrix.java != 20
if: matrix.java != 21
run: ant test dist
- name: Deploy package or snapshot
if: github.event_name != 'pull_request' && matrix.java == '11'
Expand Down
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2023 Martin Paljak
Copyright (c) 2015-2024 Martin Paljak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SHELL := /bin/bash
JDK := zulu
JAVA8 := /Library/Java/JavaVirtualMachines/$(JDK)-8.jdk/Contents/Home
JAVA11 := /Library/Java/JavaVirtualMachines/$(JDK)-11.jdk/Contents/Home
JAVA17 := /Library/Java/JavaVirtualMachines/$(JDK)-17.jdk/Contents/Home
JAVA21 := /Library/Java/JavaVirtualMachines/$(JDK)-21.jdk/Contents/Home

default: reportjava
./mvnw package
ant test

reportjava:
@echo using java $(shell java -version 2>&1 | grep version) from \"$(JAVA_HOME)\"

jar:
JAVA_HOME=$(JAVA8) ant clean dist

cap:
# run maven with JDK21
JAVA_HOME=$(JAVA21) ./mvnw package

8:
JAVA_HOME=$(JAVA8) ant clean test

11:
JAVA_HOME=$(JAVA11) ant clean test

17:
JAVA_HOME=$(JAVA17) ant clean test


all: cap 8 11 17
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

> Easy to use [Ant](https://ant.apache.org/) task for building JavaCard CAP files in a declarative way.

Have a consistent and concise build declaration for JavaCard applets, no matter which JavaCard SDK you use or target.

[![Build Status](https://github.com/martinpaljak/ant-javacard/workflows/Robot%20builder/badge.svg)](https://github.com/martinpaljak/ant-javacard/actions) [![Latest release](https://img.shields.io/github/release/martinpaljak/ant-javacard.svg)](https://github.com/martinpaljak/ant-javacard/releases/latest) [![Maven version](https://img.shields.io/maven-metadata/v?label=javacard.pro%20maven%20version&metadataUrl=https%3A%2F%2Fjavacard.pro%2Fmaven%2Fcom%2Fgithub%2Fmartinpaljak%2Fant-javacard%2Fmaven-metadata.xml)](https://gist.github.com/martinpaljak/c77d11d671260e24eef6c39123345cae) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/martinpaljak/ant-javacard/blob/master/LICENSE)

## Features
* **[Do What I Mean](http://en.wikipedia.org/wiki/DWIM)**. You will [love it](#happy-users)!
* **No dependencies**, no extra or unrelated downloads. Just **a jar file smaller than 100KB**.
* Supports **all available JavaCard SDK versions**: 2.1.2, 2.2.1, 2.2.2, 3.0.3, 3.0.4, 3.0.5 and 3.1.0
* Supports **all available JavaCard SDK versions**: 2.1.2, 2.2.1, 2.2.2, 3.0.3, 3.0.4, 3.0.5, 3.1.0 and 3.2.0
* Get one from [oracle.com](https://www.oracle.com/java/technologies/javacard-sdk-downloads.html) or use the [handy Github repository](https://github.com/martinpaljak/oracle_javacard_sdks)
* **Works on all platforms** with LTS Java 1.8+: Windows, OSX, Linux.
* **[Usable SDK-s depend on JDK version](https://github.com/martinpaljak/ant-javacard/wiki/JavaCard-SDK-and-JDK-version-compatibility)**; 1.8 recommended!
Expand All @@ -21,7 +23,6 @@

## Download & Use
* Download [`ant-javacard.jar`](https://github.com/martinpaljak/ant-javacard/releases/latest/download/ant-javacard.jar)
* Java version usable with all SDK-s is 1.8! Use SDK 3.0.5u3 and `targetsdk` to compile with Java 11 for older versions.
* Or use the download task:
```xml
<get src="https://github.com/martinpaljak/ant-javacard/releases/latest/download/ant-javacard.jar" dest="." skipexisting="true"/>
Expand Down Expand Up @@ -57,6 +58,16 @@ target:
[javacard] NB! Please use JavaCard SDK 3.0.5u3 or later for verifying!
[cap] CAP saved to /Users/martin/projects/ant-javacard/Empty_A000000617008E5CDAAE_50da91a4_2.2.2.cap
```
## Recommended setup
- Targeting JC 3.0.4 or later (modern JavaCard-s)
- Use JDK 17 (don't forget to set `$JAVA_HOME`)
- Use JavaCard SDK 3.2.0 (`jckit="sdks/jc320v24.0_kit"`) with right target (`targetsdk="3.x.y"`)
- Targeting JC 2.x.y or 3.0.1 (legacy JavaCard-s)
- Use JDK 8 (don't forget to set `$JAVA_HOME`)
- Use JavaCard SDK 3.0.5u4 (`jckit="sdks/jc305u4_kit"`) with right target (`targetsdk="sdks/jc222_kit"`)

> Note: ant-javacard will continue to support JavaCard 2 for as long as this is achievable with sane effort.

## Syntax
Sample:

Expand Down Expand Up @@ -84,6 +95,7 @@ Details:
* `aid` attribute - AID (hex) of the package. Recommended - or set to the 5 first bytes of the applet AID if left unspecified.
* `output` attribute - path where to save the generated CAP file. Optional, see below for variables.
* `export` attribtue - path (folder) where to place the JAR and generated EXP file. Optional.
* `exportmap` attribtue - if set to true, use pre-defined export file. Optional.
* `jar` attribute - path where to save the generated archive JAR file. Optional.
* `jca` attribute - path where to save the generated JavaCard Assembly (JCA) file. Optional.
* `verify` attribute - if set to false, disables verification of the resulting CAP file with offcardeverifier. Optional.
Expand All @@ -99,6 +111,7 @@ Details:

Notes:
* `jc.home` property has the highest precedence, followed by `jckit` path of `cap`, followed by path in `javacard`, followed by `JC_HOME` environment variable. SDK must be valid to be considered for use.
* All source files are expected to be UTF-8. It is a sane choice, please use it.

### Output file name variables
* `%h` - 8 character prefix of the SHA-256 Load File Data Block hash of the CAP file
Expand All @@ -108,14 +121,28 @@ Notes:
* `%a` - package AID
* `%j` - targeted JavaCard version

### Command line utility
`ant-javacard.jar` can be used to dump built .cap file metadata and to re-run off-card verifier.

- dump .cap file metadata
- `java -jar ant-javacard.jar <capfile>`
- run off-card verifier
- `java -jar ant-javacard.jar <sdk> <capfile> <expfiles>`

### Environment variables
- `JAVA_HOME` - path to the JDK to be used.
- `JC_HOME` - path to the JavaCard SDK to be used if not specified in the build file.
- `ANT_JAVACARD_TMP` - path to the temporary folder to be used for building CAP files. This is not cleaned after use.
- `DEBUG` - if set, shows debug output.

## Maven dependency
Releases are published to [`https://javacard.pro/maven/`](https://javacard.pro/maven/). To use it, add this to your `pom.xml`:
Releases are published to [`https://mvn.javacard.pro/maven/`](https://mvn.javacard.pro/maven/). To use it, add this to your `pom.xml`:

```xml
<repositories>
<repository>
<id>javacard-pro</id>
<url>https://javacard.pro/maven/</url>
<url>https://mvn.javacard.pro/maven/</url>
</repository>
</repositories>
```
Expand Down
6 changes: 3 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="dist" name="ant-javacard build">
<!-- Build and load the JavaCard task -->
<target name="jcpro" depends="clean">
<target name="jcpro">
<mkdir dir="build"/>
<javac debug="true" destdir="build" includeantruntime="true" target="8" source="8">
<src path="capfile/src/main/java"/>
Expand All @@ -19,7 +19,7 @@
<!-- Package it into a JAR -->
<target name="dist" depends="jcpro">
<jar destfile="ant-javacard.jar" level="9" basedir="build">
<!-- Some people try to execute ant-javacard.jar... -->
<!-- It is possible to execute ant-javacard.jar... -->
<manifest>
<attribute name="Main-Class" value="pro.javacard.ant.DummyMain"/>
</manifest>
Expand All @@ -29,7 +29,7 @@
<!-- lib folder and having the following in your target: -->
<!-- <taskdef name="javacard" classname="pro.javacard.ant.JavaCard" classpath="lib/ant-javacard.jar"/> -->
</target>
<!-- Build test applets -->
<!-- Build smoke test applets -->
<import file="tests-${ant.java.version}.xml"/>
<!-- Cleanup! -->
<target name="clean">
Expand Down
61 changes: 9 additions & 52 deletions capfile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,25 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<version>7.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.7</version>
<version>2.0.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<!-- compile everything to ensure module-info contains right entries -->
<release>11</release>
<compilerArgs combine.children="append">
<arg>-Werror</arg>
<arg>-Xlint:all</arg>
<arg>-Xlint:-options</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<!-- Run tests with 11 -->
<id>default-testCompile</id>
<configuration>
<!-- compile everything to ensure module-info contains right entries -->
<release>11</release>
</configuration>
</execution>
<execution>
<id>base-compile</id>
<goals>
<goal>compile</goal>
</goals>
<!-- recompile everything for 1.8 except the module-info.java -->
<configuration>
<source>8</source>
<target>8</target>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.7.3.4</version>
<configuration>
<excludeFilterFile>spotbugs.xml</excludeFilterFile>
</configuration>
</plugin>

</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion capfile/src/main/java/pro/javacard/HexUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2018 Martin Paljak
* Copyright (c) 2016-2024 Martin Paljak
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion capfile/src/main/java/pro/javacard/capfile/AID.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 Martin Paljak
* Copyright (c) 2018-2024 Martin Paljak
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading
Loading