8251117: Cannot check P11Key size in P11Cipher and P11AEADCipher

Tue, 04 Aug 2020 17:19:21 -0300

author
mbalao
date
Tue, 04 Aug 2020 17:19:21 -0300
changeset 14182
5f94741b3fc7
parent 14181
d6cec711198e
child 14183
7aaaf8998988

8251117: Cannot check P11Key size in P11Cipher and P11AEADCipher
Reviewed-by: valeriep
Contributed-by: zzambers@redhat.com

src/share/classes/sun/security/pkcs11/P11AEADCipher.java file | annotate | diff | comparison | revisions
src/share/classes/sun/security/pkcs11/P11Cipher.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/sun/security/pkcs11/P11AEADCipher.java	Wed Dec 13 01:29:58 2017 +0800
     1.2 +++ b/src/share/classes/sun/security/pkcs11/P11AEADCipher.java	Tue Aug 04 17:19:21 2020 -0300
     1.3 @@ -279,7 +279,9 @@
     1.4          SecureRandom sr)
     1.5          throws InvalidKeyException, InvalidAlgorithmParameterException {
     1.6          reset(true);
     1.7 -        if (fixedKeySize != -1 && key.getEncoded().length != fixedKeySize) {
     1.8 +        if (fixedKeySize != -1 &&
     1.9 +                ((key instanceof P11Key) ? ((P11Key) key).length() >> 3 :
    1.10 +                            key.getEncoded().length) != fixedKeySize) {
    1.11              throw new InvalidKeyException("Key size is invalid");
    1.12          }
    1.13          P11Key newKey = P11SecretKeyFactory.convertKey(token, key, ALGO);
     2.1 --- a/src/share/classes/sun/security/pkcs11/P11Cipher.java	Wed Dec 13 01:29:58 2017 +0800
     2.2 +++ b/src/share/classes/sun/security/pkcs11/P11Cipher.java	Tue Aug 04 17:19:21 2020 -0300
     2.3 @@ -345,7 +345,9 @@
     2.4              SecureRandom random)
     2.5              throws InvalidKeyException, InvalidAlgorithmParameterException {
     2.6          reset(true);
     2.7 -        if (fixedKeySize != -1 && key.getEncoded().length != fixedKeySize) {
     2.8 +        if (fixedKeySize != -1 &&
     2.9 +                ((key instanceof P11Key) ? ((P11Key) key).length() >> 3 :
    2.10 +                            key.getEncoded().length) != fixedKeySize) {
    2.11              throw new InvalidKeyException("Key size is invalid");
    2.12          }
    2.13          switch (opmode) {

mercurial