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

  • 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](http://www.oracle.com/technetwork/java/javacard/javacard-142511.html), while old, should get you started. – Maarten Bodewes May 04 '14 at 11:56

1 Answers1

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);
}
Robert
  • 39,162
  • 17
  • 99
  • 152
  • 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 – Abdou Abderrahmane May 05 '14 at 11:18