Skip to content

8271199: Mutual TLS handshake fails signing client certificate with custom sensitive PKCS11 key #4887

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

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/java.base/share/classes/sun/security/rsa/RSAPSSSignature.java
Original file line number Diff line number Diff line change
@@ -232,6 +232,26 @@ private RSAKey isValid(RSAKey rsaKey) throws InvalidKeyException {
("Unrecognized digest algo: " + digestAlgo);
}
}

// validate key attributes
try {
if (rsaKey.getModulus().signum() == 0 ||
(rsaKey instanceof RSAPrivateKey rsaPrKey &&
(rsaPrKey.getPrivateExponent().signum() == 0 ||
(rsaPrKey instanceof RSAPrivateCrtKey crtKey &&
(crtKey.getPrimeP().signum() == 0 ||
crtKey.getPrimeQ().signum() == 0 ||
crtKey.getPrimeExponentP().signum() == 0 ||
crtKey.getPrimeExponentQ().signum() == 0 ||
crtKey.getCrtCoefficient().signum() == 0 ||
crtKey.getPublicExponent().signum() == 0 )))) ||
(rsaKey instanceof RSAPublicKey rsaPubKey &&
Copy link
Member

Choose a reason for hiding this comment

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

Mixing the public key and private key together in one method may be not straightforward enough to logics like this update. What do you think it we have two isvalid() method, one for private key and one for public key?

rsaPubKey.getPublicExponent().signum() == 0)) {
throw new InvalidKeyException("Invalid key attributes");
Copy link
Member

Choose a reason for hiding this comment

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

The exception description may be confusing to users. I'm not sure if the checking could be simplified and make this exception message better matching the problems.

}
Copy link
Member

Choose a reason for hiding this comment

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

What's the motivation to check the signum?

} catch(Exception ex) {
throw new InvalidKeyException("Invalid key attributes", ex);
}
return rsaKey;
}