Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8265500

Some impls of javax.crypto.Cipher.init() do not throw UnsupportedOperationExc for unsupported modes

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7, 8, 11, 17
    • Fix Version/s: 17
    • Component/s: security-libs
    • Labels:

      Backports

        Description

        Looks like the Cipher init methods throw InvalidAlgorithmParameterException instead of UnsupportedOperationException when an unsupported mode is encountered. The SunPKCS11 provider is the example here:

        The SunPKCS11 provider's implementation of Cipher.init() method does not seem to align with the spec. According to the spec:

        "
        UnsupportedOperationException - if opmode is WRAP_MODE or UNWRAP_MODE but the mode is not implemented by the underlying CipherSpi.
        "

        However, the attached code throws the following exception:

        -----------------------------------------------------

        java.security.InvalidAlgorithmParameterException: Unsupported mode: 3
                at jdk.crypto.cryptoki/sun.security.pkcs11.P11Cipher.implInit(P11Cipher.java:359)
                at jdk.crypto.cryptoki/sun.security.pkcs11.P11Cipher.engineInit(P11Cipher.java:320)
                at java.base/javax.crypto.Cipher.init(Cipher.java:1431)
                at java.base/javax.crypto.Cipher.init(Cipher.java:1364)
                at KeywrapTest.main(KeywrapTest.java:20)

        -----------------------------------------------------

        It seems like an InvalidAlgorithmParameterException is thrown instead of the UnsupportedOperationException?

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                valeriep Valerie Peng
                Reporter:
                tvoniadka Thejasvi Voniadka
                Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: