无法删除小程序

时间:2014-07-06 09:59:44

标签: smartcard javacard apdu globalplatform

我创建了here代码的 .cap 文件。 它是一个简单的一次性密码生成器。

最后我将010203040506070809设置为包ID ,将0102030405060708090000设置为 applet AID ,然后将其上传到我的卡片中。

当我列出小程序时,这是 GPJ 的输出:

C:\Users\ghasemi\Desktop\gpj-20120310>gpj -list

C:\Users\ghasemi\Desktop\gpj-20120310>java -jar gpj.jar -list
Found terminals: [PC/SC terminal ACS CCID USB Reader 0]
Found card in terminal: ACS CCID USB Reader 0
ATR: 3B 68 00 00 00 73 C8 40 12 00 90 00
DEBUG: Command  APDU: 00 A4 04 00 07 A0 00 00 01 51 00 00
DEBUG: Response APDU: 6A 82
Failed to select Security Domain GP211 A0 00 00 01 51 00 00 , SW: 6A 82
DEBUG: Command  APDU: 00 A4 04 00 08 A0 00 00 00 18 43 4D 00
DEBUG: Response APDU: 6A 82
Failed to select Security Domain GemaltoXpressPro A0 00 00 00 18 43 4D 00 , SW:
6A 82
DEBUG: Command  APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00
DEBUG: Response APDU: 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 01 FF 90 0
0
Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00
DEBUG: Command  APDU: 80 50 00 00 08 B5 16 68 A9 92 84 7D 58
DEBUG: Response APDU: 00 00 11 60 01 00 8A 79 0A F9 FF 02 00 5B 6B 9E 48 44 A2 D
B 8A 52 C1 87 99 FC 26 72 90 00
DEBUG: Command  APDU: 84 82 00 00 10 EE 5D DB 8D 26 DA C6 B9 51 85 E1 33 A2 CE 2
4 AD
DEBUG: Response APDU: 90 00
DEBUG: Command  APDU: 84 82 00 00 08 EE 5D DB 8D 26 DA C6 B9
DEBUG: Response APDU: 90 00
DEBUG: Command  APDU: 80 F2 80 00 02 4F 00
DEBUG: Response APDU: 08 A0 00 00 00 03 00 00 00 01 9E 90 00
DEBUG: Command  APDU: 80 F2 80 00 02 4F 00
DEBUG: Response APDU: 08 A0 00 00 00 03 00 00 00 01 9E 90 00
DEBUG: Command  APDU: 80 F2 40 00 02 4F 00
DEBUG: Response APDU: 0B 01 02 03 04 05 06 07 08 09 00 00 07 00 90 00
DEBUG: Command  APDU: 80 F2 40 00 02 4F 00
DEBUG: Response APDU: 0B 01 02 03 04 05 06 07 08 09 00 00 07 00 90 00
DEBUG: Command  APDU: 80 F2 10 00 02 4F 00
DEBUG: Response APDU: 6A 81
DEBUG: Command  APDU: 80 F2 10 00 02 4F 00
DEBUG: Response APDU: 6A 81
DEBUG: Command  APDU: 80 F2 20 00 02 4F 00
DEBUG: Response APDU: 0A 01 02 03 04 05 06 07 08 09 00 01 00 90 00
DEBUG: Command  APDU: 80 F2 20 00 02 4F 00
DEBUG: Response APDU: 0A 01 02 03 04 05 06 07 08 09 00 01 00 90 00
AID: A0 00 00 00 03 00 00 00                       |........|        ISD LC: 1 P
R: 0x9E

AID: 01 02 03 04 05 06 07 08 09 00 00              |...........|     App LC: 7 P
R: 0x00

AID: 01 02 03 04 05 06 07 08 09 00                 |..........|      Exe LC: 1 P
R: 0x00

C:\Users\ghasemi\Desktop\gpj-20120310>

如您所见,我的applet已成功上传。


上传后,我将一些APDU发送到我的applet:

< 00 A4 04 00 0B 00
< 01 02 03 04 05 06 07 08 09 00 00
> 9000

< 00 20 00 02 03 00
< 22 22 22
> 9000

< 00 20 00 02 03 00
< 11 11 23
> 6C02

< 00 20 00 02 03 00
< 11 11 23
> 6C01

< 00 20 00 02 03 00
< 11 11 23
> 6C00

< 00 20 00 02 03 00
< 11 11 23
> 6D00

如上所述,我选择了我的applet,向它发送验证命令(一次使用正确的PIN,三次使用错误的引脚)。并使其锁定。


现在我要删除小程序:

C:\Users\ghasemi\Desktop\gpj-20120310>java -jar gpj.jar -delete 0102030405060708
090000 -deletedeps
Found terminals: [PC/SC terminal ACS CCID USB Reader 0]
Found card in terminal: ACS CCID USB Reader 0
ATR: 3B 68 00 00 00 73 C8 40 12 00 90 00
DEBUG: Command  APDU: 00 A4 04 00 07 A0 00 00 01 51 00 00
DEBUG: Response APDU: 6A 82
Failed to select Security Domain GP211 A0 00 00 01 51 00 00 , SW: 6A 82
DEBUG: Command  APDU: 00 A4 04 00 08 A0 00 00 00 18 43 4D 00
DEBUG: Response APDU: 6A 82
Failed to select Security Domain GemaltoXpressPro A0 00 00 00 18 43 4D 00 , SW:
6A 82
DEBUG: Command  APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00
DEBUG: Response APDU: 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 01 FF 90 0
0
Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00
DEBUG: Command  APDU: 80 50 00 00 08 5E 64 FF F5 A9 52 96 4D
DEBUG: Response APDU: 00 00 11 60 01 00 8A 79 0A F9 FF 02 00 5A 29 D0 38 18 61 9
9 BA 72 91 2D 89 12 55 0E 90 00
DEBUG: Command  APDU: 84 82 00 00 10 20 3E 1D 85 1C 36 2B B8 EA DC 25 E9 9F 78 8
D 2D
DEBUG: Response APDU: 90 00
DEBUG: Command  APDU: 84 82 00 00 08 20 3E 1D 85 1C 36 2B B8
DEBUG: Response APDU: 90 00
DEBUG: Command  APDU: 80 E4 00 80 0D 4F 0B 01 02 03 04 05 06 07 08 09 00 00
DEBUG: Response APDU: 6A 86
DEBUG: Command  APDU: 80 E4 00 80 0D 4F 0B 01 02 03 04 05 06 07 08 09 00 00
DEBUG: Response APDU: 6A 86
Could not delete AID: 01 02 03 04 05 06 07 08 09 00 00

C:\Users\ghasemi\Desktop\gpj-20120310>

Q1:我是否阻止了卡片或阻止了我的小程序?

Q2:为什么我无法删除它,我该怎么办?

4 个答案:

答案 0 :(得分:3)

您需要删除整个可执行文件加载文件(应用程序包)及其所有相关对象(应用程序实例):

gpj -deletedeps -delete 01020304050607080900

原因是你的applet类(TANGen)包含几个引用applet创建的对象的静态字段:

static byte[]        scid;
static byte[]        workarray;
static byte[]        seed;
static DESKey        tangenkey;
static Signature     mac;
static OwnerPIN      adminpin;
static OwnerPIN      userpin;

这些对象是在applet实例(应用程序)的上下文中创建的,但可以从整个应用程序包中访问(因此与应用程序包而不是applet实例相关联)。因此,仅删除应用程序会破坏这些引用。因此,它们会阻止您的应用程序实例被删除,您只能通过删除整个应用程序包(可执行加载文件)及其所有关联对象来删除它。

答案 1 :(得分:2)

关于你的问题&#34;这个小程序和其他小程序有什么区别? &#34;

  1. 根据Java Card 2.2,除非同时删除包和所有实例,否则将无法删除将内存分配给static object的应用程序实例。因此,在这种情况下,如果你的applet将内存分配给静态对象,然后你需要删除Executable load file(即包)及其所有related objects,而只删除applet实例。

  2. 如果您的applet没有为任何静态对象分配内存,那么只有您可以像其他applet一样删除此applet,否则您必须删除可执行加载文件及其所有相关对象。

  3. 关于你的问题&#34;如何生成MAC? &#34;

    根据全球平台规范GPC_Specification 2.2.1 ,为C-MAC生成定义了以下两种方法:

    • 未修改的APDU上的MAC生成
    • 修改后的APDU上的MAC生成

    SCP命令中使用的parameter 'i'实现选项(initialUpdate)决定是否应在未修改的APDU或修改的APDU上生成MAC。

    • 未修改的APDU上的MAC生成 enter image description here

    • 修改后的APDU上的MAC生成 enter image description here

    有关详细信息,请参阅全球平台GPC_Specification 2.2.1

    如果有疑问,请退回。很乐意提供帮助。

答案 2 :(得分:2)

我同意Michael Roland的大部分回答。但是,还有另一种方法可以在不删除applet包的情况下删除applet。您可以通过实施AppletEvent.uninstall()方法来完成此操作。在applet删除期间调用此方法。您可以使用它来删除静态对象:

scid = null;
workarray = null;
.
.
.

确保从整个项目中删除对这些对象的所有其他引用。否则,您仍然会在删除小程序时遇到问题。

答案 3 :(得分:1)

您的6A86命令的错误代码为DELETE,这意味着INCORRECT P1 P2P1=0没问题,P2=0x80看起来也不错;它告诉卡删除所有相关对象,而不仅仅是对象本身。

但是当一个applet被删除时,卡可能会拒绝这个选项,只允许它删除包。

所以你可以尝试两件事:

(i)设置P2 = 0(可能有效);和
(ii)删除整个包裹,正如Michael Roland所建议的那样(在这种情况下你需要保留P2=0x80)。