From c2d7070f2d78869b19da1c55d0d32982995ac2e1 Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine Date: Mon, 20 Dec 2021 15:02:15 +0100 Subject: [PATCH] TestApplet: include object deletion test --- test_applet/src/fr/anssi/smartpgp/Data.java | 2 ++ .../src/fr/anssi/smartpgp/TestApplet.java | 11 +++++++++++ test_applet/test.py | 16 ++++++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/test_applet/src/fr/anssi/smartpgp/Data.java b/test_applet/src/fr/anssi/smartpgp/Data.java index 246d3cf..fd29002 100644 --- a/test_applet/src/fr/anssi/smartpgp/Data.java +++ b/test_applet/src/fr/anssi/smartpgp/Data.java @@ -8,6 +8,7 @@ public final class Data { public static final byte INS_TEST_RSA_CRT = (byte)0x02; public static final byte INS_TEST_EC = (byte)0x03; public static final byte INS_TEST_PIN = (byte)0x04; + public static final byte INS_TEST_DELETION = (byte)0x05; public static final short SW_FAILED_TO_BUILD_PRIV_KEY = (short)0x6500; public static final short SW_FAILED_TO_BUILD_PUB_KEY = (short)0x6501; @@ -15,6 +16,7 @@ public final class Data { public static final short SW_PUB_KEY_NOT_INITIALIZED = (short)0x6503; public static final short SW_PIN_INVALID = (short)0x6504; public static final short SW_PIN_EMPTY = (short)0x6505; + public static final short SW_DELETION_NOT_SUPPORTED = (short)0x6506; public static final short BUFFER_RED_LENGTH = (short)0x200; public static final short BUFFER_BLACK_LENGTH = (short)0x200; diff --git a/test_applet/src/fr/anssi/smartpgp/TestApplet.java b/test_applet/src/fr/anssi/smartpgp/TestApplet.java index 7f13375..1a8fb18 100644 --- a/test_applet/src/fr/anssi/smartpgp/TestApplet.java +++ b/test_applet/src/fr/anssi/smartpgp/TestApplet.java @@ -341,6 +341,13 @@ public final class TestApplet extends Applet { } } + private final void processDeletion() { + if(!JCSystem.isObjectDeletionSupported()) { + ISOException.throwIt(Data.SW_DELETION_NOT_SUPPORTED); + } + JCSystem.requestObjectDeletion(); + } + public final void process(final APDU apdu) { final byte[] apdubuf = apdu.getBuffer(); @@ -376,6 +383,10 @@ public final class TestApplet extends Applet { } break; + case Data.INS_TEST_DELETION: + processDeletion(); + break; + default: ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); return; diff --git a/test_applet/test.py b/test_applet/test.py index 08fda4d..14a8d90 100755 --- a/test_applet/test.py +++ b/test_applet/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import smartcard @@ -87,6 +87,9 @@ TEST_PIN = [0x00, 0x04, 0x06, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36]; +TEST_DELETION = [0x00, 0x05, + 0x00, 0x00]; + def assemble_with_len(prefix,data): return prefix + [len(data)] + data @@ -103,14 +106,14 @@ def encode_len(data): def send_apdu(con, text, apdu): apdu = [int(c) for c in apdu] - #print ' '.join('{:02X}'.format(c) for c in apdu) + #print(' '.join('{:02X}'.format(c) for c in apdu)) (data, sw1, sw2) = con.transmit(apdu) if sw1 == 0x90 and sw2 == 0x00: if text is not None: - print "[+] %s... ok" % text + print("[+] %s... ok" % text) else: if text is not None: - print "[-] %s... KO 0x%02X%02X" % (text, sw1, sw2) + print("[-] %s... KO 0x%02X%02X" % (text, sw1, sw2)) return (data, sw1, sw2) class InvalidCard(Exception): @@ -182,6 +185,10 @@ def test_pin(con): select_applet(con, False) (data, _, _) = send_apdu(con, "Test PIN", TEST_PIN); +def test_deletion(con): + select_applet(con, False) + (data, _, _) = send_apdu(con, "Test OBJECT DELETIOn", TEST_DELETION); + def main(): reader_list = smartcard.System.readers() r = reader_list[0] @@ -192,6 +199,7 @@ def main(): test_rsa(con) test_ec(con) test_pin(con) + test_deletion(con) if __name__=='__main__': main()