8244565: Accept PKCS #8 with version number 1

Reviewed-by: valeriep
This commit is contained in:
Weijun Wang 2020-06-05 07:53:50 +08:00
parent 0db1be28c7
commit 507816d550
8 changed files with 222 additions and 618 deletions

View file

@ -79,6 +79,9 @@ public final class RSAPrivateCrtKeyImpl
*/
public static RSAPrivateKey newKey(byte[] encoded)
throws InvalidKeyException {
if (encoded == null || encoded.length == 0) {
throw new InvalidKeyException("Missing key encoding");
}
RSAPrivateCrtKeyImpl key = new RSAPrivateCrtKeyImpl(encoded);
// check all CRT-specific components are available, if any one
// missing, return a non-CRT key instead
@ -124,11 +127,8 @@ public final class RSAPrivateCrtKeyImpl
* Construct a key from its encoding. Called from newKey above.
*/
RSAPrivateCrtKeyImpl(byte[] encoded) throws InvalidKeyException {
if (encoded == null || encoded.length == 0) {
throw new InvalidKeyException("Missing key encoding");
}
decode(encoded);
super(encoded);
parseKeyBits();
RSAKeyFactory.checkRSAProviderKeyLengths(n.bitLength(), e);
try {
// check the validity of oid and params
@ -258,10 +258,7 @@ public final class RSAPrivateCrtKeyImpl
+ "\n modulus: " + n + "\n private exponent: " + d;
}
/**
* Parse the key. Called by PKCS8Key.
*/
protected void parseKeyBits() throws InvalidKeyException {
private void parseKeyBits() throws InvalidKeyException {
try {
DerInputStream in = new DerInputStream(key);
DerValue derValue = in.getDerValue();