Home

Awesome

JavaCard Gradle plugin

Build Status Maven Central Coverage Status Javadoc License

A Gradle plugin for building JavaCard applets.

This plugin is a wrapper on ant-javacard and Global Platform Pro, it is inspired by gradle-javacard

This is a fork of a great work bertrandmartel/javacard-gradle-plugin, we extended the work and added some improvements.

Gradle 6.4 is the minimal version supported.

Features

Usage

It may be the best to start with a simple HelloWorld project using this gradle plugin and demonstrating basic usage.

Clone this https://github.com/crocs-muni/javacard-gradle-template-edu template project with git clone --recursive, and try:

Example gradle script:

buildscript {
    repositories {
        jcenter()
        mavenCentral()

        // Repository with Globalplatform, ant-javacard, gppro, gptools, etc.
        maven { url "https://javacard.pro/maven" }
        maven { url "https://deadcode.me/mvn" }
    }
    dependencies {
        classpath 'com.klinec:gradle-javacard:1.8.0'
    }
}

apply plugin: 'com.klinec.gradle.javacard'

repositories {
    mavenCentral()
    // mavenLocal() // for local maven repository if needed

    // Repository with Globalplatform, ant-javacard, gppro, gptools, etc.
    maven { url  "https://dl.bintray.com/ph4r05/jcard" }
    maven { url "https://javacard.pro/maven" }
    maven { url "https://deadcode.me/mvn" }
}

javacard {

    config {
        
        cap {
            packageName 'fr.bmartel.javacard'
            version '0.1'
            aid '01:02:03:04:05:06:07:08:09'
            output 'applet.cap'
            applet {
                className 'fr.bmartel.javacard.HelloWorld'
                aid '01:02:03:04:05:06:07:08:09:01:02'
            }
        }
    }
          
    scripts {
        script {
            name 'select'
            apdu '00:A4:04:00:0A:01:02:03:04:05:06:07:08:09:01:00'
        }
        script {
            name 'hello'
            apdu '00:40:00:00:00'
        }
        task {
            name 'sendHello'
            scripts 'select', 'hello'
        }
    }
}

plugin is available from jcenter() or mavenCentral()

You can specify custom GPtool dependency with configuration gptool:

dependencies {
  gptool "com.github.martinpaljak:gppro:20.08.12"
  gptool "com.github.martinpaljak:gptool:20.08.12"
  gptool "com.github.martinpaljak:globalplatformpro:20.08.12"
}

Check this project for more usage examples

JavaCard SDK path

The path to JavaCard SDK can be specified through :

Tasks

task namedescription
buildJavaCardbuild JavaCard cap files
installJavaCarddelete existing aid & install all JavaCard cap files (gp --delete XXXX --install file.cap)
listJavaCardlist applets (gp -l)

It's possible to create custom tasks that will send series of custom apdu :

scripts {
    script {
        name 'select'
        apdu '00:A4:04:00:0A:01:02:03:04:05:06:07:08:09:01:00'
    }
    script {
        name 'hello'
        apdu '00:40:00:00:00'
    }
    task {
        name 'sendHello'
        scripts 'select', 'hello'
    }
}

The above will create task sendHello that will select applet ID 01:02:03:04:05:06:07:08:09:01 and send the apdu 00:40:00:00:00.
The order of the scripts's apdu in task.scripts is respected.
00:A4:04:00:0A:01:02:03:04:05:06:07:08:09:01:00 or '00A404000A0102030405060708090100' are valid apdu.

Custom Global Platform Pro task

You can build custom tasks that launch Global Platform Pro tool :

task displayHelp(type: com.klinec.gradle.javacard.gp.GpExec) {
    description = 'display Global Platform pro help'
    group = 'help'
    args '-h'
}

More complex example

apply plugin: 'javacard'

repositories {
    maven {
        url 'http://dl.bintray.com/bertrandmartel/maven'
    }
}

javacard {

    config {
        jckit '../oracle_javacard_sdks/jc222_kit'
        cap {
            packageName 'fr.bmartel.javacard'
            version '0.1'
            aid '01:02:03:04:05:06:07:08:09'
            output 'applet1.cap'
            applet {
                className 'fr.bmartel.javacard.HelloSmartcard'
                aid '01:02:03:04:05:06:07:08:09:01:02'
            }
            applet {
                className 'fr.bmartel.javacard.GoodByeSmartCard'
                aid '01:02:03:04:05:06:07:08:09:01:03'
            }
        }
        cap {
            packageName 'fr.bmartel.javacard'
            version '0.1'
            aid '01:02:03:04:05:06:07:08:0A'
            output 'applet2.cap'
            applet {
                className 'fr.bmartel.javacard.SomeOtherClass'
                aid '01:02:03:04:05:06:07:08:09:01:04'
            }
            dependencies {
                local {
                    jar '/path/to/dependency.jar'
                    exps '/path/to/expfolder'
                }
                remote 'fr.bmartel:gplatform:2.1.1'
            }
        }
    }
    
    defaultKey '40:41:42:43:44:45:46:47:48:49:4A:4B:4C:4D:4E:4F'
    // or 
    /*
    key {
        enc '40:41:42:43:44:45:46:47:48:49:4A:4B:4C:4D:4E:4F'
        kek '40:41:42:43:44:45:46:47:48:49:4A:4B:4C:4D:4E:4F' 
        mac '40:41:42:43:44:45:46:47:48:49:4A:4B:4C:4D:4E:4F' 
    }
    */

    scripts {
        script {
            name 'select'
            apdu '00:A4:04:00:0A:01:02:03:04:05:06:07:08:09:01:00'
        }
        script {
            name 'hello'
            apdu '00:40:00:00:00'
        }
        task {
            name 'sendHello'
            scripts 'select', 'hello'
        }
    }
}

Note1 : the remote dependency will automatically download the jar (the jar file must include the exp file)
Note2 : you can add as many local or remote dependency as you want

Syntax

(*) If you specify at least one dependency, jcardsim & junit won't be automatically added so you will need to add them manually if you need them for example :

test {
    dependencies {
        compile 'junit:junit:4.12'
        compile 'com.licel:jcardsim:3.0.4'
    }
}

Compatibility

This plugin has been tested on following IDE :

Recommended IDE : IntelliJ IDEA or Android Studio

License

The MIT License (MIT) Copyright (c) 2017-2018 Bertrand Martel