0

我正在研究一个小型票务原型。我想要做的是 - 如果选择了顶级 ADF,我想返回所有包含 DF 的 AID,并且乍一看它工作得很好。

我创建 ADF 和 1 或 2 个 DF。选择 ADF 后,这些 DF 的 AID 会很好地返回,我可以添加 EF(或 DF),...

现在,当我重新启动整个过程时(顺便说一句,我正在使用 JCOP。)我仍然可以选择 ADF,但不再返回来自 DF 的 AID,实际上我得到了 6F00“无精确诊断”。

对于我的数据结构 - 首先您会看到 ADF 的最小构造函数,它没有父对象

public DirectoryFile(byte[] aid) {
  super(aid);
  this.aid = aid;
  numApp = 1;
  created = true;
}

第二个结构是相同的,但对于具有 parentDirectoryFile 和基本文件数组(arrayFiles)的“通常” DirectoryFile:

public DirectoryFile(byte[] aid, DirectoryFile parent) {
    super(aid, parent);
    for (byte i = 0; i < numberFiles; i++) {
      arrayFiles[i].setActive(false);
    }   
}

都继承自同一个 File.class

public File (byte aid[]) {
    Util.arrayCopy(aid, (short) 0, this.aid, (short) 0, (short) 6); 
}

public File (byte[] aid, DirectoryFile parentFile) {
    this.parentFile = parentFile;
    Util.arrayCopy(aid, (short) 0, this.aid, (short) 0, (short) 6); 
}

这应该是一个非常基本的文件系统,只要卡连接到终端它就可以工作,但是在重新启动程序后信息似乎丢失了,尽管我根本没有使用瞬态数组。

返回代码始终是“6F00 - 没有精确诊断”,这会导致未引用的字节 [] 或类似的东西,除了 DF 对象之外,我找不到任何其他对象,这些对象在创建新对象时会被实例化。

编辑:刚刚发现这可能是一个更“普遍”的问题,这就是我做错的事情。

现在,如果我使用像http://umer555.wordpress.com/2012/05/17/java-card-hello-world-applet/这样的“Hello World”并像我在这里一样添加一些 INS:

  public class HalloWeltApplet extends Applet {
    private static byte[] helloWorld = new byte[11];
    private static final byte HW_CLA = (byte)0x80;
    private static final byte HW_INS = (byte)0x00;
    private static final byte HW_INS1 = (byte)0x01;
    private static final byte HW_INS2 = (byte)0x02;


    public static void install(byte[] bArray, short bOffset, byte bLength) {
      new HalloWeltApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
    }

   public void process(APDU apdu) {
     if (selectingApplet()) {
       return;
     }

     byte[] buffer = apdu.getBuffer();
     byte CLA = (byte) (buffer[ISO7816.OFFSET_CLA] & 0xFF);
     byte INS = (byte) (buffer[ISO7816.OFFSET_INS] & 0xFF);

     if(CLA != HW_CLA) {
       ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
     }

     switch(INS) {
       case HW_INS:
         getHelloWorld(apdu);
         break;
       case HW_INS1:
         getHelloWorld1(apdu);
         break;
       case HW_INS2:
         getHelloWorld2(apdu);
         break;
       default:
         ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
      }

   }

   private void getHelloWorld( APDU apdu) {
     byte[] buffer = apdu.getBuffer();
     short length = (short) helloWorld.length;
     byte[] test =  {(byte)'H',(byte)'e',(byte)'l',(byte)'l',(byte)'o',(byte)' ',(byte)'W',(byte)'o',(byte)'r',(byte)'l',(byte)'d',};

     Util.arrayCopy(test, (short) 0, helloWorld, (short) 0, (short) test.length);

   }  
   private void getHelloWorld1( APDU apdu) {
     byte[] buffer = apdu.getBuffer();
     short length = (short) helloWorld.length;
     byte[] test =  {(byte)'H',(byte)'i',(byte)' ',(byte)'W',(byte)'o',(byte)'r',(byte)'l',(byte)'d'};

     Util.arrayCopy(test, (short) 0, helloWorld, (short) 0, (short) test.length);

   }
   private void getHelloWorld2( APDU apdu) {
     byte[] buffer = apdu.getBuffer();
     apdu.setOutgoing();
     apdu.setOutgoingLength((short) helloWorld.length);
     apdu.sendBytesLong(helloWorld, (short) 0, (short) helloWorld.length);
   }
 }

所以在我看来,这应该将“Hello World”或“Hi World”保存到helloWorldINS2 中,我可以显示哪个被保存了。但是每当我重新启动程序时,helloWorld都会因为启动而为空,对吧?毕竟这可能是我的问题吗?如果是这样,如何解决?

4

1 回答 1

1

问题大概出在这里:

super(aid);
this.aid = aid;

首先,您正确复制数据,然后File用您在DirectoryFile构造函数中使用的字段覆盖该字段。如果这是一个临时缓冲区或更糟的是 JCRE 拥有的 APDU 缓冲区,那么您的代码将失败,因为不应通过持久引用使用 JCRE 拥有的对象。

请注意,AID 是应用程序标识符。它们识别应用程序,例如您的 Java Card applet。通常,文件和非应用程序 DF(尤其是子 DF)不使用 AID 标识或选择,而是使用文件标识符或(相关)短文件标识符。有关详细信息,请参阅 ISO/IEC 7816-4(我猜的任何版本)。

请注意,重置在 JCOP 模拟器中起作用,但是当您重新启动该过程时,所有信息都会丢失;数据不会保存到磁盘,必须重新加载小程序。

于 2014-05-28T21:24:35.853 回答