Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support cards which only have ALG_RSA_CRT #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fishsoupisgood
Copy link

None of the smartcards I tried (various JavaCOS, NXP, SmartCafe Expert) supported KeyPair(KeyPair.ALG_RSA, ...) only KeyPair.ALG_RSA_CRT.

This patch detects that and switches to using KeyPair.ALG_RSA_CRT.

Copy link

@darconeous darconeous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not associated with this project, but I had a look over the changes and figured I would throw in my $0.02. Take it with a grain of salt.

  1. You may want to consider gating this capability by adding a feature flag.

  2. Now that you added support for RSAPrivateCrtKey, consider implementing all of the types (ELEMENT_RSA_P, ELEMENT_RSA_Q, etc.) that RSAPrivateCrtKey seems to support:

    /*
    // RSA Prime Exponent P
    case ELEMENT_RSA_P:
    if (privateKey == null) allocate();
    break;
    // RSA Prime Exponent Q
    case ELEMENT_RSA_Q:
    if (privateKey == null) allocate();
    break;
    // RSA D mod P - 1
    case ELEMENT_RSA_DP:
    if (privateKey == null) allocate();
    break;
    // RSA D mod Q - 1
    case ELEMENT_RSA_DQ:
    if (privateKey == null) allocate();
    break;
    // RSA Inverse Q
    case ELEMENT_RSA_PQ:
    if (privateKey == null) allocate();
    break;
    */

@@ -146,7 +153,11 @@ public void updateElement(byte element, byte[] buffer, short offset, short lengt
*/
public void setPrivateExponent(byte[] buffer, short offset, short length) {
if (privateKey == null) allocate();
privateKey.setExponent(buffer, offset, length);
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the next few lines, I'm guessing this line was included in error.

@@ -35,9 +35,10 @@ of this software and associated documentation files (the "Software"), to deal
*/
public final class PIVKeyObjectPKI extends PIVKeyObject {

private RSAPrivateKey privateKey;
private Key privateKey;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of Key, should this be PrivateKey?

@@ -168,7 +179,11 @@ public void setPublicExponent(byte[] buffer, short offset, short length) {
*/
public void setModulus(byte[] buffer, short offset, short length) {
if (privateKey == null || publicKey == null) allocate();
privateKey.setModulus(buffer, offset, length);
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as that from line 156 above: I'm guessing this line was added in error.

try {
keyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_1024);
} catch (CryptoException e) {
if (e.getReason() == CryptoException.NO_SUCH_ALGORITHM) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent whitespace.

try {
keyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048);
} catch (CryptoException e) {
if (e.getReason() == CryptoException.NO_SUCH_ALGORITHM) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants