0

I'm working on a project to manage strong authentication using a Java card, there is a server app that creates user IDs and PIN codes, it then loads the pin code on the smart card and it's signature, and here is the problem, when i try to load the signature on the card( which is a 64 bytes RSA SHA1 signature) i get the following exception thrown on card :

checkFieldStore -> Security exception
throw_error(SECURITY_EXCEPTION)

i guess this has something to do with the way i'm handling the byte array memory allocation, here is my code :

RSAPrivateKey  rsa_PrivateKey;
RSAPublicKey rsa_PublicKey;
KeyPair rsa_KeyPair;
Cipher cipherRSA;
Signature sig;
short expo;
short PIN;
byte[] pinSig = new byte[64];


public short verify (byte[] pin){

    sig = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);
    sig.init(rsa_PublicKey, Signature.MODE_VERIFY);
    if( sig.verify(pin, (short)0, (short)pin.length, pinSig, (short)0, (short)pinSig.length)){
        return 1;
    }else{
        return 0;
    }
}

public void setpinSig( byte[] sig){


    pinSig = sig;
}

public void setPIN(short pin){

    PIN = pin;

}



public short isPIN(short pin){

    if ( pin != PIN )return 0;

    return 1;

}

The exception is thrown when i call the setpinSig method.

BTW: i tried setting a pin without a signature and checking it's validity successfuly

1
  • Please take a better look at the Java language and the Java Card platform itself. There is a lot of rather fundamental errors in that code, mostly related how object lifetimes and object assignment works. This book, while old, should get you started. Commented May 4, 2014 at 11:56

1 Answer 1

1

In case the pinSig value is always 64 bytes long you should use the following implementation:

public void setpinSig( byte[] sig){
    javacard.framework.Util.arrayCopy(sig, (short) 0, 
        pinSig, (short) 0, (short) 64);
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, and go easy on me, too many university projects in a very tight schedule, that's why i couldn't go through the documentation entirely

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.