简体   繁体   English

为什么Javacard阻止单个Javacard程序在AID .cap文件中上传不同的内容?

[英]Why Javacard prevent uploading different in AID .cap files of a single javacard program?

This is a simple javacard program (It do nothing!) : 这是一个简单的javacard程序(什么也不做!):

package testAID;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;

public class TestAID extends Applet {

    private TestAID() {
    }

    public static void install(byte bArray[], short bOffset, byte bLength)
            throws ISOException {
        new TestAID().register();
    }

    public void process(APDU arg0) throws ISOException {
        // TODO Auto-generated method stub
    }

}

I convert it to three .cap file with different AIDs as follow : 我将其转换为具有不同AID的三个.cap文件,如下所示:

  1. File A: PkgAID= 0000000000 & AppAID= 000000000011 档案A:PkgAID = 0000000000 &AppAID = 000000000011
  2. File B: PkgAID= 0000000000 & AppAID= 000000000022 文件B:PkgAID = 0000000000 &AppAID = 000000000022
  3. File C: PkgAID= 000000000011 & AppAID= 00000000001111 文件C:PkgAID = 000000000011 &AppAID = 00000000001111

As you see above, File A and File B are different only in AppAID . 如上所示, 文件A文件B仅在AppAID中有所不同。 and AppAID of File C is equal to AppAID of File A . 文件CAppAID等于文件AAppAID。

Now I want to upload this files on my NXP JCOP v2.4.2 r3 smart card. 现在,我想将此文件上传到我的NXP JCOP v2.4.2 r3智能卡上。 First of all, let see the contents: 首先,让我们看一下内容:

GP: gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,
 CVM (PIN) management

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)  

GP: 

OK, There is only the SD. 好的,只有SD。

Step1: Installing File A : 步骤1:安装档案A

GP: gp -install e:\TestAID\FileA.cap

GP: gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,
 CVM (PIN) management

AID: 000000000011 (|......|)
     App SELECTABLE: (none)

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)

AID: 0000000000 (|.....|)
     ExM LOADED: (none)
     000000000011 (|......|)

Successfully Completed. 成功完成。

Step 2: Installing File B : 步骤2:安装档案B

GP: gp -install e:\TestAID\FileB.cap
openkms.gp.GPException: STRICT WARNING: Package with AID 0000000000 is already p
resent on card
        at openkms.gp.GlobalPlatform.printStrictWarning(GlobalPlatform.java:159)

        at openkms.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:572)
        at openkms.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:565)
        at openkms.gp.GPTool.main(GPTool.java:330)

GP: gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,
 CVM (PIN) management

AID: 000000000011 (|......|)
     App SELECTABLE: (none)

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)

AID: 0000000000 (|.....|)
     ExM LOADED: (none)
     000000000011 (|......|)

Failed in installing. 安装失败。 gp -list command returns the same previous results. gp -list命令返回相同的先前结果。

Step 3: Installing File C : 步骤3:安装档案C

GP: gp -install e:\TestAID\FileC.cap
openkms.gp.GPException: STRICT WARNING: Package with AID 000000000011 is already
 present on card
        at openkms.gp.GlobalPlatform.printStrictWarning(GlobalPlatform.java:159)

        at openkms.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:572)
        at openkms.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:565)
        at openkms.gp.GPTool.main(GPTool.java:330)

GP: gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,
 CVM (PIN) management

AID: 000000000011 (|......|)
     App SELECTABLE: (none)

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)

AID: 0000000000 (|.....|)
     ExM LOADED: (none)
     000000000011 (|......|)

Failed in installing again and gp -list command returns the same previous results. 再次安装失败,并且gp -list命令返回相同的先前结果。

Questions: 问题:

1-What is the origin of first error? 1-第一个错误的起因是什么? Is it illegal to upload two .cap file that are different in AID and have an equal PkgAID in two step? 在两个步骤中上传两个AID不同且具有相同PkgAID的.cap文件是否非法?

2-What is the origin of second error? 2-第二次错误的起因是什么? It returns that 它返回

Package with AID 000000000011 is already present on card 卡上已经存在具有AID 000000000011的软件包

But there is not! 但是没有! It is an applet AID, not Package AID. 它是一个applet AID,而不是Package AID。

3-Are the gp prevented to install this applets or the origin of error is JCRE? 3-gp是否阻止安装此小程序,或者错误的根源是JCRE?


As I was thought it the GP tool that limited me in installing, I tried JCManager also. 当我以为GP工具限制了我的安装时,我也尝试了JCManager The result are different! 结果是不同的!

First of all I delete everything except SD: 首先,我删除除SD之外的所有内容:

GP: gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,
 CVM (PIN) management

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)

GP:

The I repeat the same steps using JCManager : 我使用JCManager重复相同的步骤:

Step 1: Installing File A : 步骤1:安装文件A

....[Authenitication Procedure]...

Authenticated
************
UplaodCAP
*************
Get AID from header.cap file
FOR LOAD DATA: EF 04 C6 02 F4
AID:00 00 00 00 00
Applet AID:00 00 00 00 00 11
Try to delete if existing...
-> 84 E4 00 00 18 6D C3 FF 8F 54 97 BD 96 CC 57 91 5E 9F 2A 67 B9 8E 98 BA 6B 99 27 27 FB
<- 6A 88
-> 84 E4 00 00 10 43 CC 7D DB 96 C3 29 FD 31 A1 96 7E DE D8 4F 29
<- 6A 88
Loading cap file. Please wait...
Install for Load
-> 84 E6 02 00 18 52 4F 5C 69 37 7A 85 E4 57 D8 86 C8 EC 44 28 51 06 38 6C 14 BA 52 1B 1B
<- 00 90 00
Load CAP
-> 84 E8 00 00 D8 9A 2C 89 B4 2D F8 81 15 A9 CD 27 A0 61 9B ED 5A 4C B5 77 F6 EF 3C 54 9F ED BB E0 BC 9E 2D 41 A8 7E DA DA 64 7F 72 97 BF D6 55 3B E0 7C 50 86 90 42 BC 16 06 B3 5C 89 26 BF 3E 79 75 F8 A4 2D 5E 60 39 D2 B3 9C 69 C8 E7 06 02 AA 24 09 70 F6 52 7A 9E 1E F9 A7 2E 3E AD AF A0 41 EE 39 92 0D 7A 4B AA CC 2F 69 E7 2A A5 85 45 A1 80 DA 35 C7 5B A6 D5 CC 22 B5 32 D7 D2 91 1E C6 ED 9C 67 D9 33 18 B9 DA 00 06 DE 89 DC 24 A6 6D 32 9A BC 93 E4 4D 4A 73 E5 2E D0 A5 4B EF 22 21 C3 B5 61 47 7A FC 8A 55 E0 70 39 C9 8D AD D1 A7 E1 B3 7F 7E F3 E6 3A 13 EC 7B 3B 20 85 7C 3D B1 A1 4B FA EE B9 02 7D 94 BE 7C 3D 88 E1 9A 4A 32 55 23 6E 83 2B 2E 9C A8 1E A5 6B E6 C1
<- 00 90 00
-> 84 E8 80 01 38 BE 83 33 E7 A7 7E 99 59 B7 C9 A2 05 2E A3 35 0E 92 A4 47 CB C4 C5 73 F0 AD A1 1B 23 04 EC EE D1 A6 83 B4 B5 85 91 C4 C5 9C 3F 3A D9 A8 8B 0F 32 F2 1C 48 A7 FC C0 4E 28
<- 00 90 00
-> 84 E6 0C 00 28 0B 9A 13 70 1F 55 53 72 F9 B0 C4 20 62 B3 43 6D 11 C2 7D 68 8B 68 54 51 BC 0D 31 CB 13 42 CC DD D4 02 02 D2 7A 46 56 7A
<- 00 90 00
Applet loaded & registered

Result : 结果:

GP: gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,
 CVM (PIN) management

AID: 000000000011 (|......|)
     App SELECTABLE: (none)

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)

AID: 0000000000 (|.....|)
     ExM LOADED: (none)
     000000000011 (|......|)

GP:

As you see above, it completed successfully like the GP 如上所见,它像GP一样成功完成了

Step 2: Installing File B : 步骤2:安装档案B

....[Authenitication Procedure]...
Authenticated
************
UplaodCAP
*************
Get AID from header.cap file
FOR LOAD DATA: EF 04 C6 02 F4
AID:00 00 00 00 00
Applet AID:00 00 00 00 00 22
Try to delete if existing...
-> 84 E4 00 00 18 29 1D 33 74 43 25 B0 AE 43 BE C4 9F 57 6A 43 3F 12 9B 23 09 F2 61 D1 95
<- 6A 88
-> 84 E4 00 00 10 6F 88 E7 64 AB 0F 04 0E EA F6 D4 80 C0 40 9D 00
<- 69 85
Loading cap file. Please wait...
Install for Load
-> 84 E6 02 00 18 1C CF 09 73 5D 1F FC 06 8F 3A DA 4D 3F 9E 1E 64 72 14 56 1D 25 44 A3 10
<- 69 85
Load CAP
-> 84 E8 00 00 D8 7A 2B 5B 1B 05 C3 D4 E3 DF 4D 1A DE 47 DD FA F9 3A A4 91 28 9F 3D 8D A4 D1 89 87 24 95 65 5A 60 C4 CD ED 41 81 99 D3 71 20 C5 CC 65 7E DB 79 21 FB 56 0D 93 2B 4F 12 28 A3 26 D0 88 16 14 26 96 AA CE C3 97 0A FE 1E 81 8C 84 AE 56 9E 68 01 26 78 AE 8E 88 99 11 67 C0 E7 CA A2 44 72 7A 77 1F 08 7C 74 07 45 5B 38 E4 9B 45 58 6F 61 7A 79 BC AD 58 71 4F D6 D6 0E 15 B8 16 CA 7F 37 5F B0 5C A4 AB 1F 0D 3C 25 81 E4 E0 21 6F B7 E5 AA 17 97 C3 4E 2A 82 87 DB A8 5E 84 C7 70 20 FF C9 CB 21 BA 36 73 15 3F 48 50 D7 C4 16 A4 BA A1 D6 7A 67 3A 9A 15 8C 63 7A 3A 22 97 D4 71 05 3B 3C 2D 3D 60 61 48 1F 3F 40 0C 04 4A 25 E7 FB 2F E6 CB 6E 0E 2A 5E 9A D0 64 7E 98
<- 69 85
-> 84 E6 0C 00 28 D7 ED 13 DB 14 E1 7B 46 1E 25 77 27 BB 12 D5 B5 3A 2D 53 C3 7C 81 9D 50 6F 96 45 DD 12 B8 FB 8B 48 1C 39 5F 53 4B 1E 88
<- 6A 88
Could not load applet. See debug for more info

Result : 结果:

GP: gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,
 CVM (PIN) management

AID: 000000000011 (|......|)
     App SELECTABLE: (none)

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)

AID: 0000000000 (|.....|)
     ExM LOADED: (none)
     000000000011 (|......|)

GP:

It is also just like the step 2 of GP . 这也就像GP的步骤2一样。

But take a look at step 3 : 但是,请看一下步骤3:

Step 3: Installing File C : 步骤3:安装档案C

Authenticated
************
UplaodCAP
*************
Get AID from header.cap file
FOR LOAD DATA: EF 04 C6 02 F6
AID:00 00 00 00 00 11
Applet AID:00 00 00 00 00 11 11
Try to delete if existing...
-> 84 E4 00 00 18 21 3A 7F DF 3A D3 00 31 B9 42 AD 6C 9A D0 0E EF D7 7F CD 16 54 E2 B8 9E
<- 6A 88
-> 84 E4 00 00 18 F6 B6 22 BB 64 BE B7 1D CF 71 E2 15 6E 18 E3 A7 20 51 B1 6A 29 1E BF 6C
<- 00 90 00
Loading cap file. Please wait...
Install for Load
-> 84 E6 02 00 18 C0 68 EE 33 BE E0 34 72 2C 8A 36 51 44 39 A1 A7 AC DF E2 11 BE B6 D4 3F
<- 69 85
Load CAP
-> 84 E8 00 00 D8 5B 5F 71 2E C2 B6 9A 11 90 33 F8 58 8D 5E 88 02 98 55 55 F0 B2 42 74 BA 40 ED 61 31 35 33 1D 5A 07 37 F5 D0 AF 5C A8 45 39 EE 4B B6 FF 32 D8 68 EC 81 24 6B 91 CE 12 34 0F FF B3 B0 C2 F3 E8 24 5B 2C 3D B4 91 8F 3F 06 15 DF C8 F3 4D 04 FD 09 D4 EA 67 4C 0C E7 70 11 24 28 0F 74 46 C8 A4 85 8F 5A 36 8E 03 26 FC 60 7C AE 28 2F 28 4F 9F 58 C1 59 29 A8 CF 9D 9F B8 AA 75 9D B2 B6 65 C1 63 1E 31 80 F8 38 1B FF 82 6D B9 78 44 B9 C7 35 67 03 6D 08 67 D4 B3 B5 48 3E 6C AD 41 C0 07 E6 54 CD DF 93 BC 1E 76 52 E1 4B 60 14 55 81 63 FD CA E4 6D 4F 5E ED 02 FA 67 0E 78 F0 57 B9 51 78 8D 1B BD 7D 8D DC EF 9C E0 93 F2 77 9F 80 0D 1E FD 4F 84 72 36 8D 76 2A B1
<- 69 85
-> 84 E6 0C 00 28 4B 38 10 41 D2 77 D3 B5 25 BD EB BD 55 A9 F0 1D 18 CD 76 CD 68 19 FC E2 52 3B 5B 38 11 1D 71 6F DF 53 7C 26 24 CF 48 08
<- 6A 88
Could not load applet. See debug for more info

Result : 结果:

GP: gp -list
AID: A000000151000000 (|....Q...|)
     ISD OP_READY: Security Domain, Card lock, Card terminate, Default selected,
 CVM (PIN) management

AID: A0000001515350 (|....QSP|)
     ExM LOADED: (none)
     A000000151535041 (|....QSPA|)

AID: 0000000000 (|.....|)
     ExM LOADED: (none)
     000000000011 (|......|)

GP:

Did you see? 你看到吗? JCManager deleted on of the Installed applets, but It can't upload File C! JCManager已删除“已安装”小程序中的一个,但无法上载文件C!

In this case, I tried to install File C with GP, but I received a new error, not repetitive PkgAID or ... : 在这种情况下,我尝试使用GP安装File C ,但是收到一个新错误,而不是重复的PkgAID或...:

GP: gp -install e:\TestAID\FileC.cap
openkms.gp.GPException: Install for Load failed SW: 6985
        at openkms.gp.GlobalPlatform.check(GlobalPlatform.java:924)
        at openkms.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:600)
        at openkms.gp.GlobalPlatform.loadCapFile(GlobalPlatform.java:565)
        at openkms.gp.GPTool.main(GPTool.java:330)

GP:

Can anyone shed any light on this issue? 任何人都可以阐明这个问题吗?

What is the meaning of Status words that JCManager returns on case of errors? 如果发生错误,JCManager返回的状态字是什么意思?

Again,I asked more than one question in a single post, But I think these questions are chained to each other, and I couldn't break them to three or four posts! 再一次,我在一个帖子中问了一个以上的问题,但是我认为这些问题是相互关联的,我无法将它们分解为三到四个帖子!

1-What is the origin of first error? 1-第一个错误的起因是什么? Is it illegal to upload two .cap file that are different in AID and have an equal PkgAID in two step? 在两个步骤中上传两个AID不同且具有相同PkgAID的.cap文件是否非法?

Yes. 是。 You have uploaded that package. 您已经上传了该软件包。 Therefore, it is forbidden to upload the same package again. 因此,禁止再次上传相同的软件包。 Here, you have two options: 在这里,您有两个选择:

  1. Directly instantiate the AppAID=000000000022 直接实例化AppAID = 000000000022
  2. Delete the package, then install it again (assuming you want to install updated package) 删除软件包,然后重新安装(假设您要安装更新的软件包)

2-What is the origin of second error? 2-第二次错误的起因是什么? It returns that Package with AID 000000000011 is already present on card. 它返回卡上已经存在具有AID 000000000011的程序包。 But there is not! 但是没有! It is an applet AID, not Package AID. 它是一个applet AID,而不是Package AID。

Quoting from JavaCard222VMspec.pdf section 4.2. 引用JavaCard222VMspec.pdf第4.2节。 and highlighted the answer in bold 并以粗体突出显示答案

Each applet installed on a Java Card technology enabled device must also have a unique AID. 安装在支持Java卡技术的设备上的每个小程序还必须具有唯一的AID。 This AID is constructed similarly to a package AID. 该AID的构造类似于程序包AID。 It is a concatenation of the applet provider's RID and PIX for that applet. 它是该小程序的小程序提供程序的RID和PIX的串联。 An applet AID must not have the same value as the AID of any package or the AID of any other applet. 小程序AID的值不得与任何程序包的AID或任何其他小程序的AID相同。 The RID of each applet in a package must be the same as the RID of the package. 程序包中每个小程序的RID必须与程序包的RID相同。

3-Are the gp prevented to install this applets or the origin of error is JCRE? 3-gp是否阻止安装此小程序,或者错误的根源是JCRE?

It is not error. 这不是错误。 Instead, the JCRE must be implemented that way. 相反,必须以这种方式实现JCRE。 Please refer to JavaCard222JCREspec.pdf section 11.1.5 Installer Behavior. 请参阅JavaCard222JCREspec.pdf部分11.1.5安装程序行为。 Quoting from it: 引用:

The Java Card RE shall guarantee that an applet will not be deemed successfully installed in the following cases: Java Card RE必须保证在以下情况下不会成功安装小程序:

  • The applet package as identified by the package AID is already resident on the card. 由包AID标识的applet包已经位于卡上。
  • The applet package contains an applet with the same Java Card platform name as that of another applet already resident on the card. applet软件包中包含一个与Java Card平台名称相同的Java applet平台名称。 The Java Card platform name of an applet identified by the AID item is described in Section 6.5 of the Virtual Machine Specification, Java Card Platform, Version 2.2.2. 虚拟机规范Java Card Platform版本2.2.2的6.5节中描述了由AID项标识的applet的Java Card平台名称。
  • ...etc ...等等

According to Global Platform specification there are two phases: Card Content Loading and Card Content Installing. 根据全球平台规范,分为两个阶段:卡内容加载和卡内容安装。

Loading - this phase handles packages. 加载 -此阶段处理包。 AID of newly loaded package is checked in this phase: 在此阶段检查新加载的软件包的AID:

On receipt of a load request (data contained in the INSTALL [for load] command), the OPEN shall: 收到加载请求(INSTALL [for load]命令中包含的数据)后,OPEN应:

  • Check that the AID of the Load File is not already present in the GlobalPlatform Registry as an Executable Load File or Application 检查加载文件的AID是否作为可执行加载文件或应用程序存在于GlobalPlatform注册表中

  • ... ...

Installing - this phase handles applet instances (this is the moment your applet's install() method is called). 安装 -此阶段处理applet实例(这是调用applet的install()方法的那一刻)。 AID of your applet instance is checked in this phase: 在此阶段中检查applet实例的AID:

On receipt of the install request (data contained within the INSTALL [for install] command), the OPEN shall: 收到安装请求(INSTALL [用于安装]命令中包含的数据)后,OPEN将:

  • Check that the Executable Module AID is present in the GlobalPlatform Registry, 检查GlobalPlatform注册表中是否存在可执行模块AID,

  • Check that the Instance AID (for future selection of the Application) is not already present in the GlobalPlatform Registry as an Application or Executable Load File, 检查实例AID(用于将来选择应用程序)是否没有作为应用程序或可执行加载文件在GlobalPlatform注册表中出现,

  • ... ...

I think your gp -install command tries to do both phases in one step. 我认为您的gp -install命令尝试一步完成两个阶段。 This is why you get error "Package with AID 0000000000 is already present on card" when installing File B, your tool fails in loading phase when trying to load a package which is already there. 这就是为什么在安装文件B时出现错误“卡上已经存在AID 0000000000的程序包”的原因,当您尝试加载已存在的程序包时,您的工具在加载阶段失败。

When installing File C, you get an error because of collision of File A package AID and File C applet instance AID. 安装文件C时,由于文件A包AID和文件C小程序实例AID冲突而导致错误。

I do not know your JCManager tool, but it obviously tries to delete applets and packages before loading them again. 我不知道您的JCManager工具,但显然它会尝试在再次加载小程序和程序包之前先删除它们。 Status word 6A88 means "referenced data not found" (package is not there), status word 6985 means "conditions not satisfied" (there is a package depending on the package you want to delete. You have to delete the depending package first.). 状态字6A88表示“找不到参考数据”(不存在程序包),状态字6985表示“条件不满足”(有一个程序包取决于要删除的程序包。您必须先删除从属程序包。) 。 This is why the JCManager's behaviour differs. 这就是JCManager的行为不同的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM