JDK-8228429 : Destroyed PBEKey behaves incorrectly
  • Type: Bug
  • Component: security-libs
  • Sub-Component: javax.crypto
  • Affected Version: 11,13
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-07-16
  • Updated: 2019-12-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
JDK-8208583 implemented the destruction of com.sun.crypto.provider.PBEKey, however this implementation is incomplete.

Destroyable.destroy() says that IllegalStateExceptions should be thrown if a method would access the destroyed data. But currently NullPointerExceptions are thrown because the destroyed state is not checked.

This also affects Java 8.

Have for example a look at javax.security.auth.kerberos.KerberosTicket to see how destroyed objects can be handled.


---------- BEGIN SOURCE ----------
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

public class PBEKeyDestructionTest {
    public static void main(String[] args) throws Exception {
        final SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE");
        final SecretKey pbeKey = factory.generateSecret(new PBEKeySpec("test".toCharArray()));
        pbeKey.destroy();
        // Expecting IllegalStateException as described by Destroyable.destroy()
        pbeKey.getEncoded();
        // Also affects other methods, e.g. hashCode()
    }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
[~coffeys] This is an issue introduced by JDK-8208583 so I am assigning it to you. I think this is worth further triage. The NPEs that can thrown by methods of PBEKey after destroying it are an issue and should be fixed. For equals and hashCode, we should probably check if the key is null. For getEncoded, ideally it should throw IllegalStateException but this will require an API change to SecretKey.getEncoded().
24-07-2019

To reproduce the issue, run the attached test case: JDK 11.0.3 - Fail JDK 13-ea+29 - Fail Output: Exception in thread "main" java.lang.NullPointerException at java.base/com.sun.crypto.provider.PBEKey.getEncoded(PBEKey.java:90) at PBEKeyDestructionTest.main(PBEKeyDestructionTest.java:11)
19-07-2019