licel / jcardsim

https://jcardsim.org
222 stars 123 forks source link

Issue while using it for PIV applet #175

Open snlgaba opened 3 years ago

snlgaba commented 3 years ago

Hi,

First of all, thanks for the great work.

I am trying to use this simulator to run PIV Applet: https://github.com/arekinath/PivApplet

It currently fails when trying to perform auth operations.

Exception i get is: javacard.security.CryptoException at javacard.security.CryptoException.throwIt(Unknown Source) at com.licel.jcardsim.crypto.AsymmetricCipherImpl.update(AsymmetricCipherImpl.java:115) at com.licel.jcardsim.crypto.AsymmetricCipherImpl.doFinal(AsymmetricCipherImpl.java:92)

This is because the buffer size here: https://github.com/licel/jcardsim/blob/master/src/main/java/com/licel/jcardsim/crypto/AsymmetricCipherImpl.java#L77 is 255 bytes for RSA 2048 key.

However, in the doFinal input size is 256 and it fails at:

https://github.com/licel/jcardsim/blob/master/src/main/java/com/licel/jcardsim/crypto/AsymmetricCipherImpl.java#L120

If I change the buffer size to getInputBlockSize() + 1 to make it 256, everything works.

Can you please help me understand why we are limiting the buffer size to engine.getInputBlockSize()? Is it possible to make the buffer size bigger and let RSAEngine fail if the input is bigger than expected for that Cipher.

koh-osug commented 2 years ago

I have merged in several pull requests in my version which might address this. See https://github.com/koh-osug/jcardsim/blob/master/src/main/java/com/licel/jcardsim/crypto/AsymmetricCipherImpl.java#L77 The latest released jars are addressing this.