diff --git a/src/test/java/pro/javacard/gp/TestDelegatedManagementHandler.java b/src/test/java/pro/javacard/gp/TestDelegatedManagementHandler.java new file mode 100644 index 00000000..78361d4c --- /dev/null +++ b/src/test/java/pro/javacard/gp/TestDelegatedManagementHandler.java @@ -0,0 +1,44 @@ +package pro.javacard.gp; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.smartcardio.CommandAPDU; + +import java.io.File; +import java.io.FileInputStream; +import java.security.PrivateKey; + +import static pro.javacard.gp.GlobalPlatform.CLA_GP; +import static pro.javacard.gp.GlobalPlatform.INS_INSTALL; + +public class TestDelegatedManagementHandler { + + private PrivateKey key; + + @Before + public void setUp() { + try (FileInputStream fin = new FileInputStream(new File("test.pem"))) { + key = GPCrypto.pem2PrivateKey(fin); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testApplyToken() { + CommandAPDU command = new CommandAPDU(CLA_GP, INS_INSTALL, 0x02, 0x00, new byte[]{0}); + DelegatedManagementHandler dmHandler = new DelegatedManagementHandler(key); + command = dmHandler.applyToken(command); + Assert.assertTrue(command.getData().length > 1); + } + + @Test + public void testApplyEmptyToken() { + CommandAPDU command = new CommandAPDU(CLA_GP, INS_INSTALL, 0x02, 0x00, new byte[]{0}); + DelegatedManagementHandler dmHandler = new DelegatedManagementHandler(null); + command = dmHandler.applyToken(command); + Assert.assertArrayEquals(command.getData(), new byte[]{0, 0}); + } +} diff --git a/src/test/resources/test.pem b/src/test/resources/test.pem new file mode 100644 index 00000000..2a3844d0 --- /dev/null +++ b/src/test/resources/test.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXgIBAAKBgQCweHHNANr7knZY8c+vfdurFmFzAsLHQfnpr57HF6d7DvUddQiC +Edl2iJWRKKZRDA0jJt5M6rk6Fn8juWujI3zwDSy9vOKygiqpNzeRRUz57JObzgUY +AldoZCajs9wQssszvF229jDCgv9Z02IQqiwPP4W9Gy+Dx8tap0FwcA7STQIDAQAB +AoGAT8zniVDNtd2xbt9Kj41WfLOONbgV5I1NOgOUxWtI7TkCVuPJiSgRMqzpFc9Q +Bm5wsmitNhMe18m8jKcYqZkusY3K3CXYD7uNhpizAb9VQ/UepWV3+SoE2PXyQhIy +UIIQ22rGCjSSye87/zMU+eF4WHdgSttuwXZKMf82SxpcTHECQQDrPQY53YcKltpW +nD0yfcq0JxWEJyP/SrNnl/6pdFlIqdzT963cCA94wi/oi8X4ZXTwGmU0Ir0kesG9 +fHIIdInvAkEAwAueWfhNeFx4i7tWZyBJFGXMtKg8WQiaoiPO2Gd8XGasdpHf0ucq +gVwIX+8pS6dZu9+PFdrOIHeazShP+kiTgwJBAM3uUjD9+WYPwXvosros3PLw9CkI +ir7Gil+587osnKy75xG41X61n7W7aW1OTzSwvLokoUwOzT3OKSTUeI9mVgkCQQCh +aKJ8587k/INsndWu81m4xR7aMBQYmLyuzf3JsKC7YKhPN6exMQ1ukBWR3AcPSOaI +mws9yRs5+oynJdyidWFVAkEAr+AGRuKKN4GD/rC/KtSDx7RhESkkONY/pIuQgVoH +hpF9NrULJNQvE5tL4d4SyaAF+E8DXv9FrXzFDoEOsXthoQ== +-----END RSA PRIVATE KEY----- \ No newline at end of file