首页 > 解决方案 > Java Card OwnerPin - APDU 命令

问题描述

我开始学习java卡,我正在阅读一个钱包的示例代码,里面有一个OwnerPin

以下是与 pin 及其验证相关的代码部分:

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();

}

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

0x80 0xB8 0x00 0x00 0xd 0xb 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x00 0x00 0x00 0x7F;

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

标签: javacardapdu

解决方案


显示的代码不足以实际说明给定 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

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

从您的代码中,我们看不到该process方法中 APDU 的入口点,但它可能是这样工作的:给定的数据是一个 LV 编码列表(长度/值),因此您首先解析长度字节以获得帮助,保存长度iLen并递增bOffset到下一个 LV 对。最后,小程序数据的值和长度被获取并输入到pin.update.

在给定的 APDU 中,PIN 确实丢失了,尝试解析内容和长度以获取帮助和信息,您将看到小程序数据字节丢失。


推荐阅读