【问题标题】:Install parameters JavaCard安装参数 JavaCard
【发布时间】:2015-12-26 17:22:30
【问题描述】:

我正在尝试使用 GPSShell 中的 -instParam 选项为我的智能卡提供 PIN。我找到了一些示例,但我不知道如何使用给定的 PIN 初始化 OwnerPIN 对象。 AFAIK 我的小程序的安装方法有一个 LV 编码结构,但我该如何解析它。我尝试了 BERTLV 对象,但在安装小程序时出现“条件不满足”错误。 我有什么:

  public static void install(byte[] bArray, short bOffset, byte bLength)
            {

                new MYPinCard(bArray, bOffset, bLength);
            }
     private MYPinCard(byte[] bArray, short bOffset, byte bLength)
        {
            m_pin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);
            byte iLen = bArray[bOffset]; // aid length
            short iOffset = (short) (bOffset+iLen+1);
            iLen = bArray[iOffset]; // application privileges length
            iOffset = (short) (iOffset+iLen+1);
            iLen = bArray[iOffset]; // application specific parameters length
            iOffset++;

            try
            {
                m_pin.update(bArray, iOffset, iLen);
            }
            catch (PINException e)
            {
                ISOException.throwIt((short)0x6AAA); 
            }
            testdata = new byte[iLen];

            Util.arrayCopy(bArray, bOffset, testdata, (short)0, iLen);
            register();
        }

 private void getInstallParams(APDU apdu)
    {
        try
        {
            byte[] buffer = apdu.getBuffer();
            // inform the JCRE that the applet has data to return
            short le = apdu.setOutgoing();
            // set the actual number of the outgoing data bytes
            apdu.setOutgoingLength(((short)testdata.length));
            apdu.sendBytesLong(testdata, (short)0, (short)testdata.length);

        }
        catch (APDUException e)
        {
            ISOException.throwIt(SW_APDU_EXCEPTION);
        }
        catch (TransactionException e)
        {
            ISOException.throwIt(SW_TRANSACTION_EXCEPTION);
        }
        catch (ArrayIndexOutOfBoundsException e)
        {
            ISOException.throwIt(SW_AIOOB_EXCEPTION);
        }
        catch (NullPointerException e)
        {
            ISOException.throwIt(SW_NULLPOINTER_EXCEPTION);
        }
    }

使用 getInstallParams() 方法,我可以检索字节。对于我的 PIN,它是 2 个字节的值,但我不知道如何处理这些字节。

有什么提示吗?

【问题讨论】:

  • Util.arrayCopy(bArray, bOffset, testdata, (short)0, iLen); 部分可能使用了错误的偏移量——恕我直言,iOffset 应该在那里(如果你想存储参数值)。

标签: java javacard


【解决方案1】:

我一遍又一遍地使用这个模板,它就可以工作(只要你最多有 127 个字节的参数):

public static void install(byte[] bArray, short bOffset, byte bLength) {
    byte aidLength = bArray[bOffset];
    short controlLength = (short)(bArray[(short)(bOffset+1+aidLength)]&(short)0x00FF);
    short dataLength = (short)(bArray[(short)(bOffset+1+aidLength+1+controlLength)]&(short)0x00FF);
    new MyPinCard(bArray, (short) (bOffset+1+aidLength+1+controlLength+1), dataLength).register(bArray, (short) (bOffset + 1), aidLength);
}

private MyPinCard(byte[] bArray, short bOffset, short bLength) {
    if(bLength!=(short)(2)) {
        ISOException.throwIt(ISO7816.SW_WRONG_DATA);
    }
    // ....
    m_pin = new OwnerPIN(PIN_TRY_LIMIT, (byte)2);
    m_pin.update(bArray, bOffset, (byte)2);
    // ....
}

注意&(short)0x00FF 部分,它正确处理具有负值的字节。

请注意,上面的代码没有检查install()bLength参数,这是错误的,应该修复:)

【讨论】:

  • 嗯,这对我不起作用....我有超过 2 个字节的 PIN,但这不会改变任何东西,对吧?
  • GPSShell 会不会有什么问题?我的安装字符串是: install -file mypincard.cap -sdAID A000000018434D00 -nvCodeLimit 4096 -instParam 1234
  • ahhh,当然,我需要将参数设置为十六进制 :) 抱歉造成混淆......现在它就像一个魅力 :)
  • 我很高兴听到这个消息。我正要在卡片上测试它并给你一些更详细的样本......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-05
  • 2012-05-24
  • 2021-08-20
相关资源
最近更新 更多