2

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

最后我设置010203040506070809package IDapplet AID0102030405060708090000 ,并将其上传到我的卡上。

这是我列出小程序时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>

如您所见,我的小程序已成功上传。


上传后,我将一些 APDU 发送到我的小程序:

< 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

正如您在上面看到的,我选择了我的小程序,向它发送验证命令(一次输入正确的 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

4 回答 4

3

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

gpj -deletedeps -delete 01020304050607080900

原因是您的小程序类 ( TANGen) 包含几个引用您的小程序创建的对象的静态字段:

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

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

于 2014-07-14T08:32:19.380 回答
2

关于你的问题“这个小程序和其他有什么区别?”

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

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

关于您的问题“如何生成 MAC?”

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

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

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

  • 在未修改的 APDU 上生成 MAC 在此处输入图像描述

  • 修改后的 APDU 上的 MAC 生成 在此处输入图像描述

更多详情请参考Global Platform GPC_Specification 2.2.1

如有疑问请回复。乐意效劳。

于 2014-11-30T10:43:43.303 回答
2

我同意迈克尔·罗兰的大部分回答。但是,还有另一种方法可以在不删除小程序包的情况下删除您的小程序。您可以通过实现AppletEvent.uninstall()方法来做到这一点。在小程序删除期间调用此方法。您可以使用它来删除您的静态对象:

scid = null;
workarray = null;
.
.
.

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

于 2015-01-06T02:32:48.167 回答
1

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

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

因此,您可以尝试两件事:

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

于 2014-07-09T18:51:42.230 回答