Skip to content

Commit

Permalink
8232950: SUNPKCS11 Provider incorrectly check key length for PSS Sign…
Browse files Browse the repository at this point in the history
…atures.

Fixed to treat the queried key size values as bits instead of bytes

Reviewed-by: andrew
Backport-of: f14e3a60b26f0488da26abf3ae6c0521d5f616e5
  • Loading branch information
zzambers authored and gnu-andrew committed Aug 24, 2022
1 parent 41c7d2d commit e3251a2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions jdk/src/share/classes/sun/security/pkcs11/P11PSSSignature.java
Expand Up @@ -341,23 +341,23 @@ private void checkKeySize(Key key) throws InvalidKeyException {

int keySize = 0; // in bytes
if (mechInfo != null) {
// check against available native info
int minKeySize = (int) mechInfo.ulMinKeySize;
int maxKeySize = (int) mechInfo.ulMaxKeySize;
if (key instanceof P11Key) {
keySize = (((P11Key) key).length() + 7) >> 3;
} else if (key instanceof RSAKey) {
keySize = ((RSAKey) key).getModulus().bitLength() >> 3;
} else {
throw new InvalidKeyException("Unrecognized key type " + key);
}
if ((minKeySize != -1) && (keySize < minKeySize)) {
// check against available native info which are in bits
if ((mechInfo.iMinKeySize != 0) &&
(keySize < (mechInfo.iMinKeySize >> 3))) {
throw new InvalidKeyException(KEY_ALGO +
" key must be at least " + minKeySize + " bytes");
" key must be at least " + mechInfo.iMinKeySize + " bits");
}
if ((maxKeySize != -1) && (keySize > maxKeySize)) {
if ((mechInfo.iMaxKeySize != Integer.MAX_VALUE) &&
(keySize > (mechInfo.iMaxKeySize >> 3))) {
throw new InvalidKeyException(KEY_ALGO +
" key must be at most " + maxKeySize + " bytes");
" key must be at most " + mechInfo.iMaxKeySize + " bits");
}
}
if (this.sigParams != null) {
Expand Down

1 comment on commit e3251a2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.