question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Misleading NullPointerException when reading an encrypted PEM key and none supplied

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
chibenwacommented, Aug 29, 2021
1reaction
chibenwacommented, Aug 29, 2021

NPE is IMO understandable to a developer doing debug while testing this newly written code, likely not to an admin blindly configuring this…

By the way nice to hear that you are planning to use this within an enterprise solution such as Apache James!

This yet have to pass review, today goal is to have a proof of concept :-p

Read more comments on GitHub >

github_iconTop Results From Across the Web

Read a Private Encrypted Key in Java - Stack Overflow
I used to be able to read the file and obtain the private key but now the file is protected (encrypted) with a...
Read more >
Exploring Key Stores and Public Certificates — JKS
In this post let's explore the fundamentals of a Java Key Store (JKS) and a Public Key Certificate. !!! Caution: Long Post !!!...
Read more >
Encryption: Data in Transit Client to Node | ScyllaDB Docs
If not provided, Scylla will attempt to use the system truststore to authenticate certificates. Note. If using a self-signed certificate, the “truststore” ...
Read more >
"The private key password is not correct or the keystore ... - IBM
In one real-life example the reason was that the password that Controller Web was using (configured inside 'server.xml') was incorrect. Example ...
Read more >
Release Notes - Bouncy Castle
PGP patch release - fix for regression in OpenPGP PGPEncryptedData.java ... Serialisation of the non-CRT RSA Private Key could cause a NullPointerException.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found