Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Creating a derived RSAPublicKey

JCIDE related questions and answers.

Moderators: product, kuafu

kosullivan
Posts: 34
Joined: Mon Jun 29, 2015 9:03 pm
Points :616
Contact:

Creating a derived RSAPublicKey

Post by kosullivan » Mon Mar 20, 2017 3:15 am

Hi folks,

I'm trying to create a class that implements RSAPublicKey, so that I can pass it through to Cipher.init(). I'm doing this because I want to override the behavior of getModulus() slightly.

Since RSAPublicKey is an interface, not a class, I cant extend it, so I created a class that implemented it.
e.g. public class DynamicRSAPublicKey implements RSAPublicKey { ... }

To make sure that I could get it working, I first created an instance of this class that did absolutely nothing to change the behavior. It is just a simple wrapper class and the code is here: http://pastebin.com/iVcMt5fU

I then create a really basic RSA encryption test, but I'm getting a CryptoException when I call Cipher.init (passing it an instance of DynamicRSAPublicKey). My test code works perfectly if I just pass an actual RSAPublicKey through.

The reason code is CryptoException.ILLEGAL_VALUE, so my theory is that the init() method is internally doing a check along the lines of 'if (!key instanceof <SomeClass>) CryptoException.throwIt(CryptoException.ILLEGAL_VALUE)'.

My problem is, because ultimately I'm using KeyBuilder.buildKey to create the interal RSAPublicKey, I have absolutely no idea what the actual class is that I should be deriving from?

Is there any way around this that anyone can think of?

Cheers,
kos

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: Creating a derived RSAPublicKey

Post by UNKNwYSHSA » Mon Mar 20, 2017 5:53 am

I had test card A40CR and J3D081, they throw CryptoException (ILLEGE_USE) same as you mentioned.
You have to use the key generated by the method KeyBuilder.buildKey().
sense and simplicity

kosullivan
Posts: 34
Joined: Mon Jun 29, 2015 9:03 pm
Points :616
Contact:

Re: Creating a derived RSAPublicKey

Post by kosullivan » Mon Mar 20, 2017 6:59 am

Thanks for checking on your end.

It's an unfortunate thing because ultimately if I am creating a class that implements the interface faithfully, why should it fail this in a runtime check?
There appears to be a hierarchy of classes that are completely inaccessible, because you only ever see them exposed via interfaces. Maybe there is a security justification for this but I can't see it in the JVM/JCRE documents for Javacard.

Cheers

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: Creating a derived RSAPublicKey

Post by UNKNwYSHSA » Wed Mar 22, 2017 2:21 am

I found that, document for javacard.security.KeyBuilder:
public static Key buildKey(byte keyType,
short keyLength,
boolean keyEncryption)
throws CryptoExceptionCreates uninitialized cryptographic keys for signature and cipher algorithms. Only instances created by this method may be the key objects used to initialize instances of Signature, Cipher and KeyPair. Note that the object returned must be cast to their appropriate key type interface.
sense and simplicity

kosullivan
Posts: 34
Joined: Mon Jun 29, 2015 9:03 pm
Points :616
Contact:

Re: Creating a derived RSAPublicKey

Post by kosullivan » Wed Mar 22, 2017 2:45 am

Yes I saw this. I think what it really comes to is that this is Javacard, not Java. The underlying types are hidden (probably for good security reasons) and so it just can't be done. Thanks for looking further.

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: Creating a derived RSAPublicKey

Post by UNKNwYSHSA » Wed Mar 22, 2017 2:56 am

;)
sense and simplicity

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 24 guests

JavaCard OS : Disclaimer