Java Card OwnerPin-APDU命令

时间:2019-09-22 06:40:56

标签: javacard apdu

我开始学习Java卡,正在阅读一个钱包的示例代码,其中有一个function numArgs() { return arguments.length; }

这是代码的一部分,与引脚及其验证有关:

OwnerPin

我在理解此代码时遇到了一些麻烦。我知道这是根据安装脚本设置引脚的部分:

OwnerPIN pin;

private myApplet(byte[] bArray, short bOffset, byte bLength) {

    // It is good programming practice to allocate
    // all the memory that an applet needs during
    // its lifetime inside the constructor
    pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);

    byte iLen = bArray[bOffset]; // aid length
    bOffset = (short) (bOffset + iLen + 1);
    byte cLen = bArray[bOffset]; // info length
    bOffset = (short) (bOffset + cLen + 1);
    byte aLen = bArray[bOffset]; // applet data length

    // The installation parameters contain the PIN
    // initialization value
    pin.update(bArray, (short) (bOffset + 1), aLen);
    register();

}

我不明白安装小程序后pin的值是多少。

1 个答案:

答案 0 :(得分:0)

显示的代码不足以实际说出给定的APDU。

尽管此代码示例:

byte iLen = bArray[bOffset]; // aid length
bOffset = (short) (bOffset + iLen + 1);
byte cLen = bArray[bOffset]; // info length
bOffset = (short) (bOffset + cLen + 1);
byte aLen = bArray[bOffset]; // applet data length

是Applet的installation方法的默认代码,因此可以由Global Platform INSTALL命令触发。但是,给定的APDU根本不是有效的全球平台。

从您的代码中,我们无法在process方法中看到APDU的入口点,但是它可能像这样工作:给定的数据是LV编码的列表(长度/值),因此您解析长度首先提供一个字节,以保存长度iLen并递增bOffset至下一个LV对。最后,将获取applet数据的值和长度并将其馈送到pin.update中。

在给定的APDU中,缺少PIN,尝试解析内容和长度以获取帮助和信息,您将看到applet数据字节丢失。

相关问题