bc-java icon indicating copy to clipboard operation
bc-java copied to clipboard

Loading a PKCS12 keystore with wrong password should throw recommended exception

Open dnl50 opened this issue 7 months ago • 1 comments

When loading a PKCS12 keystore using the JCA API Method java.security.Keystore#load(InputStream, char[]) using a wrong password, an IOException without a cause is thrown. The JCA API recommends throwing an IOException with a java.security.UnrecoverableKeyException as the cause to indicate a wrong password (see JCA API Docs). This is the case for both PKCS12 keystores with a MAC and without a MAC.

We are currently using Java 11 with Bouncy Castle Version 1.77, but the issue seems to exist with the latest Bouncy Castle Version ( 1.80) as well.

Code Pointers:

dnl50 avatar May 23 '25 06:05 dnl50

Thanks for the report; it seems reasonable to conform to that behaviour. getEntry, getKey are related cases that could be handled at the same time.

Latest openjdk implementation, for reference: https://github.com/openjdk/jdk/blob/48df41b6997cfe2c8aa3bc46ea25eff01f615d31/src/java.base/share/classes/sun/security/pkcs12/PKCS12KeyStore.java .

peterdettman avatar May 23 '25 12:05 peterdettman