# HG changeset patch # User Mychaela Falconia # Date 1613448636 0 # Node ID 8562d8508cf2215597f7fcb157d0890df8b2660e # Parent a56bbd6b02778c34883289c9dae9642149b9b5de grcard2-set-{adm,super}-hex commands implemented It appears that GrcardSIM2 cards allow arbitrary 64-bit keys for ADM and SUPER ADM, not necessarily consisting of ASCII digits like the specs require for standard PIN and PUK, and pySim-prog.py in fact sets the ADM key to 4444444444444444 in hex by default, which is not an ASCII digit string. If the cards allow such keys, we need to support them too. diff -r a56bbd6b0277 -r 8562d8508cf2 simtool/dispatch.c --- a/simtool/dispatch.c Mon Feb 15 10:00:17 2021 +0000 +++ b/simtool/dispatch.c Tue Feb 16 04:10:36 2021 +0000 @@ -19,9 +19,11 @@ extern int cmd_grcard1_set_ki(); extern int cmd_grcard1_set_pin(); extern int cmd_grcard2_set_adm(); +extern int cmd_grcard2_set_adm_hex(); extern int cmd_grcard2_set_pin(); extern int cmd_grcard2_set_puk(); extern int cmd_grcard2_set_super(); +extern int cmd_grcard2_set_super_hex(); extern int cmd_iccid(); extern int cmd_imsi(); extern int cmd_opl_dump(); @@ -101,11 +103,13 @@ {"grcard1-set-pin1", 2, 2, cmd_grcard1_set_pin}, {"grcard1-set-pin2", 2, 2, cmd_grcard1_set_pin}, {"grcard2-set-adm", 1, 1, cmd_grcard2_set_adm}, + {"grcard2-set-adm-hex", 1, 1, cmd_grcard2_set_adm_hex}, {"grcard2-set-pin1", 1, 1, cmd_grcard2_set_pin}, {"grcard2-set-pin2", 1, 1, cmd_grcard2_set_pin}, {"grcard2-set-puk1", 1, 1, cmd_grcard2_set_puk}, {"grcard2-set-puk2", 1, 1, cmd_grcard2_set_puk}, {"grcard2-set-super", 1, 1, cmd_grcard2_set_super}, + {"grcard2-set-super-hex", 1, 1, cmd_grcard2_set_super_hex}, {"iccid", 0, 0, cmd_iccid}, {"imsi", 0, 0, cmd_imsi}, {"opl-dump", 0, 0, cmd_opl_dump}, diff -r a56bbd6b0277 -r 8562d8508cf2 simtool/grcard2.c --- a/simtool/grcard2.c Mon Feb 15 10:00:17 2021 +0000 +++ b/simtool/grcard2.c Tue Feb 16 04:10:36 2021 +0000 @@ -110,6 +110,31 @@ return(0); } +cmd_grcard2_set_adm_hex(argc, argv) + char **argv; +{ + u_char cmd[13]; + int rc; + + /* Grcard2 proprietary command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xD4; + cmd[2] = 0x3A; + cmd[3] = 0x05; + cmd[4] = 8; + rc = decode_hex_data_from_string(argv[1], cmd + 5, 8, 8); + if (rc < 0) + return(rc); + rc = apdu_exchange(cmd, 13); + if (rc < 0) + return(rc); + if (sim_resp_sw != 0x9000) { + fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); + return(-1); + } + return(0); +} + cmd_grcard2_set_super(argc, argv) char **argv; { @@ -134,3 +159,28 @@ } return(0); } + +cmd_grcard2_set_super_hex(argc, argv) + char **argv; +{ + u_char cmd[13]; + int rc; + + /* Grcard2 proprietary command APDU */ + cmd[0] = 0xA0; + cmd[1] = 0xD4; + cmd[2] = 0x3A; + cmd[3] = 0x0B; + cmd[4] = 8; + rc = decode_hex_data_from_string(argv[1], cmd + 5, 8, 8); + if (rc < 0) + return(rc); + rc = apdu_exchange(cmd, 13); + if (rc < 0) + return(rc); + if (sim_resp_sw != 0x9000) { + fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); + return(-1); + } + return(0); +}