├── .gitattributes ├── settings.gradle ├── test ├── libs │ └── test.exp └── src │ └── main │ └── java │ └── fr │ └── bmartel │ └── javacard │ ├── HelloWorld.java │ └── HelloWorld2.java ├── .gitmodules ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── old.gradle ├── gradle-javacard ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── gradle-plugins │ │ │ │ └── javacard.properties │ │ └── groovy │ │ │ └── com │ │ │ └── klinec │ │ │ └── gradle │ │ │ └── javacard │ │ │ ├── extension │ │ │ ├── TestDependencies.groovy │ │ │ ├── Test.groovy │ │ │ ├── Script.groovy │ │ │ ├── Task.groovy │ │ │ ├── Import.groovy │ │ │ ├── Applet.groovy │ │ │ ├── Key.groovy │ │ │ ├── Dependencies.groovy │ │ │ ├── Scripts.groovy │ │ │ ├── JavaCard.groovy │ │ │ ├── Cap.groovy │ │ │ └── Config.groovy │ │ │ ├── gp │ │ │ └── GpExec.groovy │ │ │ ├── util │ │ │ ├── SdkUtils.groovy │ │ │ └── Utility.groovy │ │ │ ├── JavaCardBuildTask.groovy │ │ │ └── JavaCardPlugin.groovy │ └── test │ │ └── groovy │ │ └── com │ │ └── klinec │ │ └── gradle │ │ └── javacard │ │ ├── JavaCardGpExecTest.groovy │ │ ├── JavaCardListTest.groovy │ │ ├── JavaCardKeyTest.groovy │ │ ├── JavaCardInstallTaskTest.groovy │ │ ├── utils │ │ └── TestUtils.groovy │ │ ├── UtilityTest.groovy │ │ ├── JavaCardScriptTest.groovy │ │ ├── common │ │ └── CommonTest.groovy │ │ ├── JavaCardBuildTaskTest.groovy │ │ ├── JavaCardPluginTest.groovy │ │ └── StaticConfig.groovy └── build.gradle ├── .travis.yml ├── .gitignore ├── LICENSE.md ├── CHANGELOG.md ├── gradlew.bat ├── gradlew └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | test/src/* linguist-vendored 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':gradle-javacard' 2 | 3 | -------------------------------------------------------------------------------- /test/libs/test.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ph4r05/javacard-gradle-plugin/HEAD/test/libs/test.exp -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "sdks"] 2 | path = sdks 3 | url = git://github.com/martinpaljak/oracle_javacard_sdks.git 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ph4r05/javacard-gradle-plugin/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle-javacard/src/main/resources/META-INF/gradle-plugins/javacard.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.klinec.gradle.javacard.JavaCardPlugin 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | language: java 3 | script: 4 | - git submodule update --init --recursive 5 | - ./gradlew build jacocoTestReport 6 | jdk: oraclejdk8 7 | after_success: 8 | - ./gradlew jacocoRootReport coveralls 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Aug 11 02:05:15 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip 7 | -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/extension/TestDependencies.groovy: -------------------------------------------------------------------------------- 1 | package com.klinec.gradle.javacard.extension 2 | 3 | class TestDependencies { 4 | 5 | /** 6 | * list of dependencies to compile. 7 | */ 8 | List dependencies = [] 9 | 10 | void compile(Object dependency) { 11 | dependencies.add(dependency) 12 | } 13 | 14 | void implementation(Object dependency) { 15 | dependencies.add(dependency) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Intellij project files 26 | *.iml 27 | *.ipr 28 | *.iws 29 | .idea/ 30 | 31 | #Gradle 32 | .gradletasknamecache 33 | .gradle/ 34 | build/ 35 | bin/ 36 | 37 | doc/ 38 | out/ 39 | -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/extension/Test.groovy: -------------------------------------------------------------------------------- 1 | package com.klinec.gradle.javacard.extension 2 | 3 | import org.gradle.api.Action 4 | import org.gradle.api.model.ObjectFactory 5 | import org.gradle.util.ClosureBackedAction 6 | 7 | import javax.inject.Inject 8 | 9 | abstract class Test { 10 | 11 | TestDependencies dependencies 12 | 13 | void dependencies(Closure closure) { 14 | dependencies(ClosureBackedAction.of(closure)) 15 | } 16 | 17 | void dependencies(Action action) { 18 | def dependency = objectFactory.newInstance(TestDependencies) 19 | action.execute(dependency) 20 | dependencies = dependency 21 | dependency 22 | } 23 | 24 | @Inject 25 | abstract ObjectFactory getObjectFactory() 26 | } 27 | -------------------------------------------------------------------------------- /gradle-javacard/src/test/groovy/com/klinec/gradle/javacard/JavaCardGpExecTest.groovy: -------------------------------------------------------------------------------- 1 | package com.klinec.gradle.javacard 2 | 3 | 4 | import com.klinec.gradle.javacard.common.CommonTest 5 | import com.klinec.gradle.javacard.gp.GpExec 6 | import org.gradle.api.tasks.JavaExec 7 | import org.junit.Test 8 | 9 | import static org.junit.Assert.assertEquals 10 | import static org.junit.Assert.assertTrue 11 | 12 | class JavaCardGpExecTest extends CommonTest { 13 | 14 | @Test 15 | void gpExecTest() { 16 | JavaExec listTask = project.tasks.create(name: 'testTask', type: GpExec) 17 | 18 | assertTrue(listTask ? true : false) 19 | assertTrue(listTask instanceof JavaExec) 20 | assertTrue(listTask instanceof GpExec) 21 | assertEquals(listTask.main, 'pro.javacard.gp.GPTool') 22 | } 23 | } -------------------------------------------------------------------------------- /test/src/main/java/fr/bmartel/javacard/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package fr.bmartel.javacard; 2 | 3 | import javacard.framework.*; 4 | 5 | public class HelloWorld extends Applet { 6 | 7 | private final static byte[] hello = {0x48, 0x65, 0x6c, 0x6c, 0x6f}; 8 | 9 | public static void install(byte[] buffer, short offset, byte length) { 10 | (new HelloWorld()).register(); 11 | } 12 | 13 | public void process(APDU apdu) { 14 | byte[] buf = apdu.getBuffer(); 15 | 16 | switch (buf[ISO7816.OFFSET_INS]) { 17 | case 0x40: 18 | Util.arrayCopy(hello, (byte) 0, buf, ISO7816.OFFSET_CDATA, (byte) 5); 19 | apdu.setOutgoingAndSend( 20 | ISO7816.OFFSET_CDATA, (byte) 5); 21 | break; 22 | case ISO7816.INS_SELECT: 23 | apdu.setOutgoingAndSend( 24 | ISO7816.OFFSET_CDATA, (byte) 5); 25 | break; 26 | default: 27 | ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/src/main/java/fr/bmartel/javacard/HelloWorld2.java: -------------------------------------------------------------------------------- 1 | package fr.bmartel.javacard; 2 | 3 | import javacard.framework.*; 4 | 5 | public class HelloWorld2 extends Applet { 6 | 7 | private final static byte[] hello = {0x48, 0x65, 0x6c, 0x6c, 0x6f}; 8 | 9 | public static void install(byte[] buffer, short offset, byte length) { 10 | (new HelloWorld2()).register(); 11 | } 12 | 13 | public void process(APDU apdu) { 14 | byte[] buf = apdu.getBuffer(); 15 | 16 | switch (buf[ISO7816.OFFSET_INS]) { 17 | case 0x40: 18 | Util.arrayCopy(hello, (byte) 0, buf, ISO7816.OFFSET_CDATA, (byte) 5); 19 | apdu.setOutgoingAndSend( 20 | ISO7816.OFFSET_CDATA, (byte) 5); 21 | break; 22 | case ISO7816.INS_SELECT: 23 | apdu.setOutgoingAndSend( 24 | ISO7816.OFFSET_CDATA, (byte) 5); 25 | break; 26 | default: 27 | ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017-2018 Bertrand Martel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /gradle-javacard/src/test/groovy/com/klinec/gradle/javacard/JavaCardListTest.groovy: -------------------------------------------------------------------------------- 1 | package com.klinec.gradle.javacard 2 | 3 | import com.klinec.gradle.javacard.common.CommonTest 4 | import org.gradle.api.tasks.JavaExec 5 | import org.junit.Test 6 | 7 | import static org.junit.Assert.assertEquals 8 | import static org.junit.Assert.assertTrue 9 | 10 | class JavaCardListTest extends CommonTest { 11 | 12 | @Test 13 | void listAppletTest() { 14 | runBuildTask(StaticConfig.VALID_CONFIG) 15 | 16 | JavaExec listTask = project.getTasks().findByName('listJavaCard') 17 | 18 | assertTrue(listTask ? true : false) 19 | assertTrue(listTask instanceof JavaExec) 20 | assertEquals(listTask.group, 'global platform') 21 | assertEquals(listTask.args, ['-l', 22 | '--key-enc', '404142434445464748494A4B4C4D4E4F', 23 | '--key-mac', '404142434445464748494A4B4C4D4E4F', 24 | '--key-dek', '404142434445464748494A4B4C4D4E4F']) 25 | assertEquals(listTask.main, 'pro.javacard.gp.GPTool') 26 | 27 | //listTask.exec() 28 | } 29 | } -------------------------------------------------------------------------------- /gradle-javacard/src/test/groovy/com/klinec/gradle/javacard/JavaCardKeyTest.groovy: -------------------------------------------------------------------------------- 1 | package com.klinec.gradle.javacard 2 | 3 | import com.klinec.gradle.javacard.common.CommonTest 4 | import org.gradle.api.tasks.JavaExec 5 | import org.junit.Test 6 | 7 | import static org.junit.Assert.assertEquals 8 | import static org.junit.Assert.assertTrue 9 | 10 | class JavaCardKeyTest extends CommonTest { 11 | 12 | @Test 13 | void buildInstallMixedKey() { 14 | runBuildTask(StaticConfig.VALID_CONFIG_MIXED_KEY) 15 | JavaExec installTask = project.getTasks().getByName("installJavaCard") 16 | assertTrue(installTask ? true : false) 17 | assertTrue(installTask instanceof JavaExec) 18 | assertEquals('global platform', installTask.group) 19 | assertEquals(['--install', project.buildDir.absolutePath + File.separator + "javacard" + File.separator + "applet.cap", 20 | '--key-enc', '414142434445464748494A4B4C4D4E4F', 21 | '--key-mac', '404142434445464748494A4B4C4D4E4F', 22 | '--key-dek', '424142434445464748494A4B4C4D4E4F' 23 | ], installTask.args) 24 | assertEquals(installTask.main, 'pro.javacard.gp.GPTool') 25 | //installTask.exec() 26 | } 27 | } -------------------------------------------------------------------------------- /gradle-javacard/src/test/groovy/com/klinec/gradle/javacard/JavaCardInstallTaskTest.groovy: -------------------------------------------------------------------------------- 1 | package com.klinec.gradle.javacard 2 | 3 | import com.klinec.gradle.javacard.common.CommonTest 4 | import org.gradle.api.Task 5 | import org.gradle.api.tasks.JavaExec 6 | import org.junit.Test 7 | 8 | import static org.junit.Assert.assertEquals 9 | import static org.junit.Assert.assertTrue 10 | import static org.junit.Assert.assertThat 11 | import static org.hamcrest.Matchers.* 12 | 13 | class JavaCardInstallTaskTest extends CommonTest { 14 | 15 | @Test 16 | void validBuildInstall() { 17 | runBuildTask(StaticConfig.VALID_CONFIG) 18 | JavaExec installTask = project.getTasks().getByName("installJavaCard") 19 | Task buildTask = project.getTasks().getByName("buildJavaCard") 20 | assertTrue(installTask ? true : false) 21 | assertTrue(installTask instanceof JavaExec) 22 | assertThat(installTask.dependsOn, hasItem(buildTask)) 23 | assertEquals(installTask.group, 'global platform') 24 | assertEquals(installTask.args, ['--install', project.buildDir.absolutePath + File.separator + "javacard" + File.separator + "applet.cap", 25 | '--key-enc', '404142434445464748494A4B4C4D4E4F', 26 | '--key-mac', '404142434445464748494A4B4C4D4E4F', 27 | '--key-dek', '404142434445464748494A4B4C4D4E4F' 28 | ]) 29 | assertEquals(installTask.main, 'pro.javacard.gp.GPTool') 30 | //installTask.exec() 31 | } 32 | } -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/gp/GpExec.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | *

4 | * Copyright (c) 2017-2018 Bertrand Martel 5 | *

6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | *

13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.klinec.gradle.javacard.gp 26 | 27 | import org.gradle.api.tasks.JavaExec 28 | /** 29 | * Task type that inherits JavaExec. 30 | * 31 | * @author Bertrand Martel 32 | */ 33 | class GpExec extends JavaExec { 34 | 35 | static String GP_CLASSNAME = 'pro.javacard.gp.GPTool' 36 | 37 | GpExec() { 38 | super() 39 | configure { 40 | main = GP_CLASSNAME 41 | classpath = project.configurations.gptool 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/extension/Script.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | *

4 | * Copyright (c) 2017 Bertrand Martel 5 | *

6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | *

13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.klinec.gradle.javacard.extension 26 | 27 | /** 28 | * a single script reference to send an apdu. 29 | * 30 | * @author Bertrand Martel 31 | */ 32 | class Script { 33 | 34 | /** 35 | * script name. 36 | */ 37 | String name 38 | 39 | /** 40 | * apdu to send. 41 | */ 42 | String apdu 43 | 44 | void name(String name) { 45 | this.name = name 46 | } 47 | 48 | void apdu(String apdu) { 49 | this.apdu = apdu 50 | } 51 | } -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/extension/Task.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | *

4 | * Copyright (c) 2017 Bertrand Martel 5 | *

6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | *

13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.klinec.gradle.javacard.extension 26 | 27 | /** 28 | * define the created gradle task that will hold the scripts 29 | * 30 | * @author Bertrand Martel 31 | */ 32 | class Task { 33 | 34 | /** 35 | * task name. 36 | */ 37 | String name 38 | 39 | /** 40 | * list of tasks. 41 | */ 42 | List scripts = [] 43 | 44 | void name(String name) { 45 | this.name = name 46 | } 47 | 48 | void scripts(String... list) { 49 | for (String item : list) { 50 | this.scripts.add(item) 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /gradle-javacard/src/test/groovy/com/klinec/gradle/javacard/utils/TestUtils.groovy: -------------------------------------------------------------------------------- 1 | package com.klinec.gradle.javacard.utils 2 | 3 | import com.klinec.gradle.javacard.util.Utility 4 | 5 | class TestUtils { 6 | 7 | public static File getFile(ext) { 8 | return new File(ext) 9 | } 10 | 11 | public static String getFileName(filePath, ext) { 12 | return Utility.removeExtension(filePath) + "." + ext 13 | } 14 | 15 | public static boolean isInt(String v){ 16 | try { 17 | Integer.parseInt(v) 18 | return true 19 | } catch (Exception ignored){ 20 | return false 21 | } 22 | } 23 | 24 | public static int compareVersionElem(String v1, String v2){ 25 | if (isInt(v1) && isInt(v2)){ 26 | return Integer.parseInt(v1) - Integer.parseInt(v2) 27 | } else { 28 | return v1.numberAwareCompareTo(v2) 29 | } 30 | } 31 | 32 | public static int compareJdk(String version1, String version2) { 33 | def arr1 = version1.split("\\.") as String[] 34 | def arr2 = version2.split("\\.") as String[] 35 | if (arr1[0] == '1') arr1 = arr1[(1..-1)] 36 | if (arr2[0] == '1') arr2 = arr2[(1..-1)] 37 | int i=0 38 | 39 | while(i 4 | * Copyright (c) 2017 Bertrand Martel 5 | *

6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | *

13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.klinec.gradle.javacard 26 | 27 | import com.klinec.gradle.javacard.util.Utility 28 | import org.junit.Test 29 | 30 | import static org.junit.Assert.assertEquals 31 | 32 | /** 33 | * Test utility functions. 34 | * 35 | * @author Bertrand Martel 36 | */ 37 | class UtilityTest { 38 | 39 | @Test 40 | void removeExtensionTest() { 41 | assertEquals("test", Utility.removeExtension("test.txt")) 42 | assertEquals("/some/path/file", Utility.removeExtension("/some/path/file.cap")) 43 | assertEquals("test_test", Utility.removeExtension("test_test.exp")) 44 | assertEquals("somefile.txt", Utility.removeExtension("somefile.txt.txt")) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/extension/Import.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | *

4 | * Copyright (c) 2017 Bertrand Martel 5 | *

6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | *

13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.klinec.gradle.javacard.extension 26 | 27 | /** 28 | * Cap extension object (the same as defined in https://github.com/martinpaljak/ant-javacard#syntax 29 | * 30 | * @author Bertrand Martel 31 | */ 32 | class Import { 33 | 34 | /** 35 | * path to the folder keeping .exp files. Required 36 | */ 37 | String exps 38 | 39 | /** 40 | * path to the JAR file for compilation. Optional - only required if using sources mode and not necessary with classes mode if java code is already compiled 41 | */ 42 | String jar 43 | 44 | void exps(String exps) { 45 | this.exps = exps 46 | } 47 | 48 | void jar(String jar) { 49 | this.jar = jar 50 | } 51 | } -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/extension/Applet.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | *

4 | * Copyright (c) 2017 Bertrand Martel 5 | *

6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | *

13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.klinec.gradle.javacard.extension 26 | 27 | /** 28 | * Cap extension object (the same as defined in https://github.com/martinpaljak/ant-javacard#syntax 29 | * 30 | * @author Bertrand Martel 31 | */ 32 | class Applet { 33 | 34 | /** 35 | * class of the Applet where install() method is defined. Required. 36 | */ 37 | String className 38 | 39 | /** 40 | * AID (hex) of the applet. Recommended - or set to package aid+i where i is index of the applet definition in the build.xml instruction 41 | */ 42 | String aid 43 | 44 | void className(String className) { 45 | this.className = className 46 | } 47 | 48 | void aid(String aid) { 49 | this.aid = aid 50 | } 51 | } -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/util/SdkUtils.groovy: -------------------------------------------------------------------------------- 1 | package com.klinec.gradle.javacard.util 2 | 3 | import org.slf4j.Logger 4 | 5 | import java.nio.file.Paths 6 | 7 | import pro.javacard.JavaCardSDK 8 | 9 | /** 10 | * Javacard SDK utils taken from ant-javacard(https://github.com/martinpaljak/ant-javacard) by Martin Paljak 11 | */ 12 | class SdkUtils { 13 | 14 | static class JavaCardKit { 15 | JavaCardSDK.Version version = JavaCardSDK.Version.NONE 16 | String path = null 17 | JavaCardSDK sdk = null 18 | } 19 | 20 | /** 21 | * Get api classpath depending on SDK version 22 | * 23 | * @param extensionKit path to JavaCard SDK 24 | * @return api jar classpath 25 | */ 26 | static getApiPath(extensionKit, Logger logger) { 27 | def jckit = SdkUtils.detectSDK(extensionKit, logger) 28 | def jars = jckit.sdk.getApiJars() 29 | return jars.isEmpty() ? null : jars.get(0) 30 | } 31 | 32 | /** 33 | * Given a path, return a meta-info object about possible JavaCard SDK in that path. 34 | * 35 | * @param path raw string as present in build.xml or environment, or null 36 | * 37 | * @return a {@link JavaCardKit} instance 38 | */ 39 | static JavaCardKit detectSDK(String path, Logger logger) { 40 | JavaCardKit detected = new JavaCardKit() 41 | if (path == null || path.trim() == "") { 42 | return detected 43 | } 44 | 45 | // Expand user 46 | String real_path = path.replaceFirst("^~", System.getProperty("user.home")) 47 | 48 | // Check if path is OK 49 | if (!new File(real_path).exists()) { 50 | logger.info("JavaCard SDK folder " + path + " does not exist!") 51 | return detected 52 | } 53 | 54 | detected.sdk = JavaCardSDK.detectSDK(real_path) 55 | detected.version = detected.sdk?.version 56 | detected.path = real_path 57 | 58 | // Identify jckit type 59 | if (!detected.sdk) { 60 | logger.info("Could not detect a JavaCard SDK in " + Paths.get(path).toAbsolutePath()) 61 | } 62 | return detected 63 | } 64 | } -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/extension/Key.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | *

4 | * Copyright (c) 2017 Bertrand Martel 5 | *

6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | *

13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.klinec.gradle.javacard.extension 26 | 27 | /** 28 | * Key extension. 29 | * 30 | * @author Bertrand Martel 31 | */ 32 | class Key { 33 | 34 | /** 35 | * key Master 36 | */ 37 | String keyMaster 38 | 39 | /** 40 | * key DEK 41 | */ 42 | String keyDek 43 | 44 | /** 45 | * key ENC 46 | */ 47 | String keyEnc 48 | 49 | /** 50 | * key MAC 51 | */ 52 | String keyMac 53 | 54 | /** 55 | * key KEK 56 | */ 57 | String keyKek 58 | 59 | void enc(String key) { 60 | this.keyEnc = key 61 | } 62 | 63 | void mac(String key) { 64 | this.keyMac = key 65 | } 66 | 67 | void kek(String key) { 68 | this.keyKek = key 69 | } 70 | 71 | void master(String key){ 72 | this.keyMaster = key 73 | } 74 | 75 | void dek(String key){ 76 | this.keyDek = key 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /gradle-javacard/src/test/groovy/com/klinec/gradle/javacard/JavaCardScriptTest.groovy: -------------------------------------------------------------------------------- 1 | package com.klinec.gradle.javacard 2 | 3 | import com.klinec.gradle.javacard.common.CommonTest 4 | import org.gradle.api.Task 5 | import org.gradle.api.tasks.JavaExec 6 | import org.junit.Test 7 | 8 | import static org.junit.Assert.assertEquals 9 | import static org.junit.Assert.assertTrue 10 | 11 | class JavaCardScriptTest extends CommonTest { 12 | 13 | @Test 14 | void validScript() { 15 | runBuildTask(StaticConfig.VALID_SCRIPT_CONFIG) 16 | 17 | Task task1 = project.getTasks().findByName('task1') 18 | Task task2 = project.getTasks().findByName('task2') 19 | Task task3 = project.getTasks().findByName('task3') 20 | 21 | assertTrue(task1 ? true : false) 22 | assertTrue(task2 ? true : false) 23 | assertTrue(task3 ? true : false) 24 | 25 | assertTrue(task1 instanceof JavaExec) 26 | assertTrue(task2 instanceof JavaExec) 27 | assertTrue(task3 instanceof JavaExec) 28 | 29 | assertEquals(task1.group, 'global platform') 30 | assertEquals(task2.group, 'global platform') 31 | assertEquals(task3.group, 'global platform') 32 | 33 | assertEquals(task1.args, ['-a', '010203', '-a', '040506']) 34 | assertEquals(task2.args, ['-a', '010203']) 35 | assertEquals(task3.args, ['-a', '040506']) 36 | 37 | assertEquals(task1.main, 'pro.javacard.gp.GPTool') 38 | assertEquals(task2.main, 'pro.javacard.gp.GPTool') 39 | assertEquals(task3.main, 'pro.javacard.gp.GPTool') 40 | 41 | //task1.exec() 42 | } 43 | 44 | @Test 45 | void runnableScript() { 46 | runBuildTask(StaticConfig.RUNNABLE_SCRIPT_CONFIG) 47 | 48 | JavaExec installTask = project.getTasks().getByName("installJavaCard") 49 | JavaExec task1 = project.getTasks().getByName('task1') 50 | 51 | assertTrue(task1 ? true : false) 52 | assertTrue(task1 instanceof JavaExec) 53 | assertEquals(task1.group, 'global platform') 54 | assertEquals(task1.args, ['-a', '00A404000A0102030405060708090100', '-a', '0040000000']) 55 | assertEquals(task1.main, 'pro.javacard.gp.GPTool') 56 | 57 | //installTask.exec() 58 | //task1.exec() 59 | } 60 | } -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/extension/Dependencies.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | *

4 | * Copyright (c) 2017 Bertrand Martel 5 | *

6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | *

13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.klinec.gradle.javacard.extension 26 | 27 | import org.gradle.api.Action 28 | import org.gradle.api.model.ObjectFactory 29 | import org.gradle.util.ClosureBackedAction 30 | 31 | import javax.inject.Inject 32 | 33 | /** 34 | * Cap extension object (the same as defined in https://github.com/martinpaljak/ant-javacard#syntax 35 | * 36 | * @author Bertrand Martel 37 | */ 38 | abstract class Dependencies { 39 | 40 | /** 41 | * list of local exp/jar dependencies 42 | */ 43 | List local = [] 44 | 45 | /** 46 | * list of remote exp/jar dependencies 47 | */ 48 | List remote = [] 49 | 50 | void remote(String remote) { 51 | this.remote.add(remote) 52 | } 53 | 54 | Import local(Closure closure) { 55 | local(ClosureBackedAction.of(closure)) 56 | } 57 | 58 | Import local(Action action) { 59 | def someLocal = objectFactory.newInstance(Import) 60 | action.execute(someLocal) 61 | local.add(someLocal) 62 | return someLocal 63 | } 64 | 65 | @Inject 66 | abstract ObjectFactory getObjectFactory() 67 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.5.4](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.5.4) (2018-03-03) 4 | [Full Changelog](https://github.com/bertrandmartel/javacard-gradle-plugin/compare/1.5.3...1.5.4) 5 | 6 | **Merged pull requests:** 7 | 8 | - finding sources automatically by default - from the existing source sets [\#3](https://github.com/bertrandmartel/javacard-gradle-plugin/pull/3) ([ph4r05](https://github.com/ph4r05)) 9 | - More flexible JcardSim configuration [\#2](https://github.com/bertrandmartel/javacard-gradle-plugin/pull/2) ([ph4r05](https://github.com/ph4r05)) 10 | 11 | ## [1.5.3](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.5.3) (2017-10-10) 12 | [Full Changelog](https://github.com/bertrandmartel/javacard-gradle-plugin/compare/1.5.2...1.5.3) 13 | 14 | **Closed issues:** 15 | 16 | - Depend on another module [\#1](https://github.com/bertrandmartel/javacard-gradle-plugin/issues/1) 17 | 18 | ## [1.5.2](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.5.2) (2017-09-23) 19 | [Full Changelog](https://github.com/bertrandmartel/javacard-gradle-plugin/compare/1.5.0...1.5.2) 20 | 21 | ## [1.5.0](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.5.0) (2017-09-02) 22 | [Full Changelog](https://github.com/bertrandmartel/javacard-gradle-plugin/compare/1.4.1...1.5.0) 23 | 24 | ## [1.4.1](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.4.1) (2017-08-31) 25 | [Full Changelog](https://github.com/bertrandmartel/javacard-gradle-plugin/compare/1.4.0...1.4.1) 26 | 27 | ## [1.4.0](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.4.0) (2017-08-30) 28 | [Full Changelog](https://github.com/bertrandmartel/javacard-gradle-plugin/compare/1.3.0...1.4.0) 29 | 30 | ## [1.3.0](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.3.0) (2017-08-21) 31 | [Full Changelog](https://github.com/bertrandmartel/javacard-gradle-plugin/compare/1.2.3...1.3.0) 32 | 33 | ## [1.2.3](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.2.3) (2017-08-19) 34 | [Full Changelog](https://github.com/bertrandmartel/javacard-gradle-plugin/compare/1.2.0...1.2.3) 35 | 36 | ## [1.2.0](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.2.0) (2017-08-18) 37 | [Full Changelog](https://github.com/bertrandmartel/javacard-gradle-plugin/compare/1.1.1...1.2.0) 38 | 39 | ## [1.1.1](https://github.com/bertrandmartel/javacard-gradle-plugin/tree/1.1.1) (2017-08-13) 40 | 41 | 42 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /gradle-javacard/src/main/groovy/com/klinec/gradle/javacard/extension/Scripts.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | *

4 | * Copyright (c) 2017 Bertrand Martel 5 | *

6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | *

13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | *

16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package com.klinec.gradle.javacard.extension 26 | 27 | import org.gradle.api.Action 28 | import org.gradle.api.model.ObjectFactory 29 | import org.gradle.util.ClosureBackedAction 30 | 31 | import javax.inject.Inject 32 | 33 | /** 34 | * scripts used to configure apdu batch request from a gradle task. 35 | * 36 | * @author Bertrand Martel 37 | */ 38 | abstract class Scripts { 39 | 40 | /** 41 | * list of scripts. 42 | */ 43 | List