Misleading NullPointerException when reading an encrypted PEM key and none supplied
See original GitHub issueDescribe the bug
When an encrypted PEM private key is used without supplying a password, a null pointer exception is being returned.
There is not way for the library user (an probably my end users too) to know the reason of this failure is that a password is required.
To Reproduce
X509ExtendedKeyManager[] x509ExtendedKeyManager = {PemUtils.loadIdentityMaterial(
"certs.crt",
"encrypted.private.key",
null)};
SSLContext context = SSLContext.getInstance("TLS");
context.init(kmf.getKeyManagers(), null, null);
Results in :
java.lang.NullPointerException: null
at java.base/java.util.Objects.requireNonNull(Objects.java:221)
at nl.altindag.ssl.util.PemUtils.lambda$static$1(PemUtils.java:92)
at nl.altindag.ssl.util.PemUtils.parsePrivateKey(PemUtils.java:416)
at nl.altindag.ssl.util.PemUtils.parseIdentityMaterial(PemUtils.java:329)
at nl.altindag.ssl.util.PemUtils.loadIdentityMaterial(PemUtils.java:301)
at nl.altindag.ssl.util.PemUtils.loadIdentityMaterial(PemUtils.java:227)
Expected behavior
I expect a dedicated exception with an easy to understand message…
Environmental Data:
- Java 11 (OpenJDK 11.0.11)
- Maven 3.6.3
- Ubuntu
Additional context
I could end up using this library in a contribution to Apache James to not just support keystores but also PEM files.
The ease of use is appealing though I need users to understand by themselves their mistakes before reaching the community (including I) and says stuff like “your soft is not working there is a NPE” without understanding the mistake is theirs…
BTW I could fire a patch if my above proposal is deemed acceptable.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
I did write https://github.com/Hakky54/sslcontext-kickstart/pull/114
NPE is IMO understandable to a developer doing debug while testing this newly written code, likely not to an admin blindly configuring this…
This yet have to pass review, today goal is to have a proof of concept :-p