TestApplet: include object deletion test

This commit is contained in:
Arnaud Fontaine 2021-12-20 15:02:15 +01:00
parent 1720a3494b
commit c2d7070f2d
3 changed files with 25 additions and 4 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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()