-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
private RSAPublicKey publicKey; | ||
private KeyPair keyPair; | ||
private boolean isCrtKey; | ||
|
||
// The list of elements that can be updated for an asymmetric key | ||
|
||
|
@@ -80,8 +81,11 @@ public void updateElement(byte element, byte[] buffer, short offset, short lengt | |
case ELEMENT_RSA_N: | ||
if (length != getKeyLength()) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH); | ||
if (publicKey == null || privateKey == null) allocate(); | ||
if (isCrtKey) { | ||
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); | ||
} | ||
publicKey.setModulus(buffer, offset, length); | ||
privateKey.setModulus(buffer, offset, length); | ||
((RSAPrivateKey) privateKey).setModulus(buffer, offset, length); | ||
break; | ||
|
||
// RSA Public Exponent | ||
|
@@ -95,7 +99,10 @@ public void updateElement(byte element, byte[] buffer, short offset, short lengt | |
case ELEMENT_RSA_D: | ||
if (length != getKeyLength()) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH); | ||
if (privateKey == null) allocate(); | ||
privateKey.setExponent(buffer, offset, length); | ||
if (isCrtKey) { | ||
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); | ||
} | ||
((RSAPrivateKey) privateKey).setExponent(buffer, offset, length); | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (isCrtKey) { | ||
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); | ||
} | ||
((RSAPrivateKey) privateKey).setExponent(buffer, offset, length); | ||
} | ||
|
||
/** | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (isCrtKey) { | ||
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); | ||
} | ||
((RSAPrivateKey) privateKey).setModulus(buffer, offset, length); | ||
publicKey.setModulus(buffer, offset, length); | ||
} | ||
|
||
|
@@ -194,23 +209,39 @@ public short getModulus(byte[] buffer, short offset) { | |
|
||
private void allocate() { | ||
|
||
isCrtKey = false; | ||
|
||
// Generate the appropriate key(s) | ||
switch (header[HEADER_MECHANISM]) { | ||
|
||
case PIV.ID_ALG_RSA_1024: | ||
keyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_1024); | ||
try { | ||
keyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_1024); | ||
} catch (CryptoException e) { | ||
if (e.getReason() == CryptoException.NO_SUCH_ALGORITHM) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent whitespace. |
||
keyPair = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_1024); | ||
isCrtKey = true; | ||
} | ||
} | ||
break; | ||
|
||
case PIV.ID_ALG_RSA_2048: | ||
keyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048); | ||
try { | ||
keyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_2048); | ||
} catch (CryptoException e) { | ||
if (e.getReason() == CryptoException.NO_SUCH_ALGORITHM) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent whitespace. |
||
keyPair = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048); | ||
isCrtKey = true; | ||
} | ||
} | ||
break; | ||
|
||
default: | ||
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); | ||
break; | ||
} | ||
|
||
privateKey = (RSAPrivateKey)keyPair.getPrivate(); | ||
privateKey = keyPair.getPrivate(); | ||
publicKey = (RSAPublicKey)keyPair.getPublic(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
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 bePrivateKey
?