Page 1 of 1

My program returns 6F 00:No precise diagnosis, why?

Posted: Tue Dec 08, 2015 6:04 am
by Erisaron
I downloaded a part of java card program from the web. But I have a question when debugging this program in JCIDE.

Here is the code.

Code: Select all

package fileSigner;

import javacard.framework.*;
import javacard.security.KeyPair;
import javacard.security.RSAPrivateKey;
import javacard.security.RSAPublicKey;
import javacard.security.Signature;

public class FileSigning extends Applet {

    //Proprietary Status Words
    private static final short SIGN_VERIFIED_SW = (short) 0x6701;
    private static final short SIGN_NOT_VERIFIED_SW = (short) 0x6702;

    //Proprietary Instructions
    private static final byte SIGN_INS = (byte) 0x00;
    private static final byte VERIFY_INS = (byte) 0x02;
    private static final byte RET_PUB_KEY_INS = (byte) 0x04;

    //Required Objects
    private static RSAPrivateKey privateKey;
    private static RSAPublicKey publicKey;
    private static KeyPair keyPair;
    private static Signature signature;

    public static void install(byte[] bArray, short bOffset, byte bLength) {
        new FileSigning();
    }

    protected FileSigning() {
        register();
        keyPair = new KeyPair(KeyPair.ALG_RSA, (short) 1024);
        keyPair.genKeyPair();
        publicKey = (RSAPublicKey) keyPair.getPublic();
        privateKey = (RSAPrivateKey) keyPair.getPrivate();
        signature = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);
    }

    public void process(APDU apdu) {
        if (selectingApplet()) {
            return;
        }

        byte[] buffer = apdu.getBuffer();

        switch (buffer[ISO7816.OFFSET_INS]) {
            case SIGN_INS:
                signature.init(publicKey, Signature.MODE_SIGN);
                byte[] dataSignature = JCSystem.makeTransientByteArray((short) 128, JCSystem.CLEAR_ON_RESET);
                short signLen = signature.sign(buffer, ISO7816.OFFSET_CDATA, (byte) ISO7816.OFFSET_LC, dataSignature, (byte) 0);
                Util.arrayCopyNonAtomic(dataSignature, (short) 0, buffer, (short) 0, signLen);
                apdu.setOutgoingAndSend((short) 0, signLen);
                break;

            case VERIFY_INS:
                signature.init(privateKey, Signature.MODE_VERIFY);
                boolean isVerified = signature.verify(buffer, (short)ISO7816.OFFSET_CDATA, (short)0x80, buffer, (short)(ISO7816.OFFSET_CDATA + 0X80), (short)0X04);
                if (isVerified) {
                    ISOException.throwIt(SIGN_VERIFIED_SW);
                } else {
                    ISOException.throwIt(SIGN_NOT_VERIFIED_SW);
                }
                break;

            case RET_PUB_KEY_INS:
                break;

            default:
                ISOException.throwIt((short) ISO7816.SW_INS_NOT_SUPPORTED);
        }
    }
}


As the screenshot showed, I can select the applet successfully, but when I send data to sign a 2 bytes data. It returns 6F 00.
Can anyone tell me the reason? I also can't understand this program well, so if anyone can explain the detailed information/APDU to me, I will be much appreciated.


Re: My program returns 6F 00:No precise diagnosis, why?

Posted: Tue Dec 08, 2015 10:38 pm
by UNKNwYSHSA
It seems you are debugging with JCIDE, you can debug step by step, and locate which line the exception raised.