JDK-8267837 : JDK 7u/8u PKCS12KeyStore.parseAlgParameters exception
  • Type: Bug
  • Component: security-libs
  • Sub-Component: java.security
  • Affected Version: 7u311,8u301
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2021-05-27
  • Updated: 2021-06-02
  • Resolved: 2021-06-02
Related Reports
Relates :  
Relates :  
In JDK-8267599, reverted only macAlgorithm. So still issue is reproducible. We should revert certProtectionAlgorithm also at least, I would suggest to revert keyProtectionAlgorithm along with it.

Steps to reproduce the issue:
Generate keystore with latest java - keytool -keystore testkeystore.p12 -genkeypair -keyalg EC  -alias testcert -dname CN=testcert -storepass password -storetype pkcs12

Run the attached program with old JDK(say April 2021 CPU)

Exception in thread "main" java.io.IOException: parseAlgParameters failed: ObjectIdentifier() -- data isn't an object ID (tag = 48)
	at sun.security.pkcs12.PKCS12KeyStore.parseAlgParameters(PKCS12KeyStore.java:819)
	at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:2027)
	at java.security.KeyStore.load(KeyStore.java:1445)
	at PKCS12.main(PKCS12.java:14)
Caused by: java.io.IOException: ObjectIdentifier() -- data isn't an object ID (tag = 48)
	at sun.security.util.ObjectIdentifier.<init>(ObjectIdentifier.java:285)
	at sun.security.util.DerInputStream.getOID(DerInputStream.java:321)
	at com.sun.crypto.provider.PBES2Parameters.engineInit(PBES2Parameters.java:267)
	at java.security.AlgorithmParameters.init(AlgorithmParameters.java:293)
	at sun.security.pkcs12.PKCS12KeyStore.parseAlgParameters(PKCS12KeyStore.java:815)
	... 3 more
The issue demonstrates an interoperability issue where older 7u/8u JDKs can't parse the new algorithms DER encoded stream due to bug JDK-8202837 that's now fixed but it means 8u301/7u311 is required to parse the new PKCS12 keystore. Will document this in JDK-8242069 release note. This concerns the PKCS12 keystore which is not the default keystore in JDK 7/8

An another note: Similar interop issue is there between JDK11.0.12(July CPU) and JDK8u291 (April CPU) with default configuration

An another Note: If I use JKS keystore instance(old JKD- JDK8u291 b10) to load a pkcs12 keystore(generated with new JDK - JDK8u301 b07), then getting different exception. To reproduce the issue compile and run the attached JKS.java. Stack trace : Exception in thread "main" java.io.IOException: Invalid keystore format at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:663) at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:56) at sun.security.provider.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:224) at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(JavaKeyStore.java:70) at java.security.KeyStore.load(KeyStore.java:1445) at JKS.main(JKS.java:14)

thanks - I can reproduce with JDK 8u. JDK 11u seems ok. Investigating.

JDK8u301 b07 versus JDK8u291 b10 JDK7u311 b07 versus JDK7u301 b09 I haven't tested with JDK11, as build is not yet available.

what exact JDK version are you using to generate the keytstore ? We know that JDK 16 and later will use the newer HmacPBESHA256 alg

current 11u/8u/7u default values: keystore.pkcs12.certProtectionAlgorithm = PBEWithHmacSHA256AndAES_256 keystore.pkcs12.keyProtectionAlgorithm = PBEWithHmacSHA256AndAES_256 keystore.pkcs12.macAlgorithm = HmacPBESHA1 PBEWithHmacSHA256AndAES_256 available since JDK-6383200 why would we revert that part ? I can't reproduce the original issue reported in JDK-8267599 (post fixing it)