Reputation: 23
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
Upvotes: 0
Views: 1019
Reputation: 42575
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);
}
Upvotes: 1