changeset 14131:5f94741b3fc7

8251117: Cannot check P11Key size in P11Cipher and P11AEADCipher Reviewed-by: valeriep Contributed-by: zzambers@redhat.com
author mbalao
date Tue, 04 Aug 2020 17:19:21 -0300
parents d6cec711198e
children 7aaaf8998988
files src/share/classes/sun/security/pkcs11/P11AEADCipher.java src/share/classes/sun/security/pkcs11/P11Cipher.java
diffstat 2 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/security/pkcs11/P11AEADCipher.java	Wed Dec 13 01:29:58 2017 +0800
+++ b/src/share/classes/sun/security/pkcs11/P11AEADCipher.java	Tue Aug 04 17:19:21 2020 -0300
@@ -279,7 +279,9 @@
         SecureRandom sr)
         throws InvalidKeyException, InvalidAlgorithmParameterException {
         reset(true);
-        if (fixedKeySize != -1 && key.getEncoded().length != fixedKeySize) {
+        if (fixedKeySize != -1 &&
+                ((key instanceof P11Key) ? ((P11Key) key).length() >> 3 :
+                            key.getEncoded().length) != fixedKeySize) {
             throw new InvalidKeyException("Key size is invalid");
         }
         P11Key newKey = P11SecretKeyFactory.convertKey(token, key, ALGO);
--- a/src/share/classes/sun/security/pkcs11/P11Cipher.java	Wed Dec 13 01:29:58 2017 +0800
+++ b/src/share/classes/sun/security/pkcs11/P11Cipher.java	Tue Aug 04 17:19:21 2020 -0300
@@ -345,7 +345,9 @@
             SecureRandom random)
             throws InvalidKeyException, InvalidAlgorithmParameterException {
         reset(true);
-        if (fixedKeySize != -1 && key.getEncoded().length != fixedKeySize) {
+        if (fixedKeySize != -1 &&
+                ((key instanceof P11Key) ? ((P11Key) key).length() >> 3 :
+                            key.getEncoded().length) != fixedKeySize) {
             throw new InvalidKeyException("Key size is invalid");
         }
         switch (opmode) {