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

XMLWordPrintable

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

        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?

              Assignee:
              Valerie Peng
              Reporter:
              Thejasvi Voniadka (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Created:
                Updated:
                Resolved: