Page 1 of 1

How to catch the reason of error 6F00

Posted: Tue Aug 22, 2017 11:44 pm
by Valks
When I debugged my applet, it always returned error status word 0x6F00. Is it possible to catch the reason of this error ?

Code: Select all

        OwnerPIN mypin;

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

                backSomething = new byte[BS_LENGTH];

                mypin = new OwnerPIN(PIN_TRY_LIMIT, MAX_PIN_SIZE);

                byte pin[]={0x00,0x00,0x00,0x00};
                mypin.update (pin, (short) 0, (byte) 0x04);
               
                register();
        }

        private void verifypin(APDU apdu){

                byte[] buffer = apdu.getBuffer();
                byte byteRead = (byte) apdu.setIncomingAndReceive();
                if ( mypin.check ( buffer, ISO7816.OFFSET_CDATA, byteRead ) == false )
                        ISOException.throwIt(SW_VERIFICATION_FAILED);

        }

Re: How to catch the reason of error 6F00

Posted: Wed Aug 23, 2017 6:24 am
by BrooksIQ
Your problem may be caused by this line:

byte byteRead = (byte) apdu.setIncomingAndReceive();

Re: How to catch the reason of error 6F00

Posted: Wed Aug 23, 2017 6:48 am
by Valks
BrooksIQ wrote:Your problem may be caused by this line:

byte byteRead = (byte) apdu.setIncomingAndReceive();


Thank you so much for your pointer. Now I can check my pin successfully.But I still have another question.

I wrote a simple method to update the PIN. I can update the pin, but when I call the verify method, the response APDU tell me that I have a wrong pin. How can I fix this problem?

Code: Select all

                byte[] buffer = apdu.getBuffer();

                if ( buffer[ISO7816.OFFSET_LC] >  MAX_PIN_SIZE)
                        ISOException.throwIt(SW_PIN_EX);

                mypin.update(buffer, buffer[ISO7816.OFFSET_CDATA], buffer[ISO7816.OFFSET_LC]);

Re: How to catch the reason of error 6F00

Posted: Wed Aug 23, 2017 10:22 pm
by BrooksIQ
0x6F00 is usually returned by the card when an exception is not caught.
Could you show us your process method ?

Re: How to catch the reason of error 6F00

Posted: Wed Aug 23, 2017 10:24 pm
by BrooksIQ
You may also try to add a try/catch clause to confirm which exception is thrown.
.

Re: How to catch the reason of error 6F00

Posted: Thu Aug 24, 2017 2:59 am
by Valks
Process method

Code: Select all

public void process(APDU apdu){

                byte buffer[] = apdu.getBuffer() ;
                byte byesRead = (byte) apdu.setIncomingAndReceive();

                if ( ( buffer[ISO7816.OFFSET_CLA] == 0) &&
                        (buffer[ISO7816.OFFSET_INS] == (byte) 0xA4)) return;


                switch ( buffer[ISO7816.OFFSET_INS] ){

                case GET_INS: get_ins(apdu); break;
                case VER_PIN: verifypin(apdu); break;
                case SET_PIN: mysetpin(apdu); break;
                default: ISOException.throwIt(ISO7816.SW_WRONG_DATA);

                }
        }


>> CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 0f, 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 06, 01, 03, 00, 00, 00, Le: 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 06, 01
<< 90 00

>> CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 0a, a0, 00, 00, 00, 62, 03, 01, 0c, 06, 01, Le: 00
<< 90 00

>> CLA: b0, INS: 20, P1: 10, P2: 00, Lc: 03, 00, 00, 00, Le: 00 // Verify PIN
<< 90 00

>> CLA: b0, INS: 30, P1: 00, P2: 00, Lc: 03, 01, 02, 03, Le: 00
<< 90 00

>> CLA: b0, INS: 20, P1: 10, P2: 00, Lc: 03, 01, 02, 03, Le: 00
<< 63 00

>> CLA: b0, INS: 15, P1: 20, P2: 30, Lc: 02, 00, 00, Le: 00
<< 65 00

Re: How to catch the reason of error 6F00

Posted: Thu Aug 24, 2017 3:16 am
by BrooksIQ
mypin.update(buffer, buffer[ISO7816.OFFSET_CDATA], buffer[ISO7816.OFFSET_LC]);

The second parameter of OwnerPIN.update() is the starting offset of your pin in the given array.
In your example command, your are using the content of the APDU buffer at offset 5. This may be the problem.

Re: How to catch the reason of error 6F00

Posted: Thu Aug 24, 2017 3:50 am
by Valks
Thank you very much for your help, BrooksIQ. It saved all my day. Much appreciated.