简体   繁体   中英

Install parameters JavaCard

I am trying to give the PIN for my smartcard with the -instParam option in GPShell. I found some examples but I do not have a clue how to initialize the OwnerPIN object with the given PIN. AFAIK there is a LV coded structure given to the install method of my applet, but how do I parse that. I tried the BERTLV object but I get a "Conditions not satisfied" error when installing the applet then. What I have:

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

With the getInstallParams() method, I can retrieve the bytes. For my PIN it is 2 byte value, but I have no clue what to do with that bytes.

Any hints?

I am using this template over and over and it just works (as long as you have at most 127 bytes of parameters):

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);
    // ....
}

Note the &(short)0x00FF part which handles bytes with negative values correctly.

Note that the above code does not check the bLength parameter of install() which is wrong and should be fixed :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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