Skip to content

NPE occurs when certificate does not contain common name (CN). #10

@mrJames1985

Description

@mrJames1985

When a certificate does not contain a CN a NPE occurs in the build method of the KeystoreBuilder class.

java.lang.NullPointerException: null
at org.apache.commons.ssl.KeyStoreBuilder.build(KeyStoreBuilder.java:195) ~[not-going-to-be-commons-ssl-0.3.20.jar:0.3.20]
at org.apache.commons.ssl.KeyMaterial.(KeyMaterial.java:179) ~[not-going-to-be-commons-ssl-0.3.20.jar:0.3.20]

Happens when getting the CN of the certificate and not checking if it is null or not.

while (keysIt.hasNext() && chainsIt.hasNext()) {
                Key key = (Key) keysIt.next();
                Certificate[] c = (Certificate[]) chainsIt.next();
                X509Certificate theOne = buildChain(key, c);
                String alias = "alias_" + i++;
                // The theOne is not null, then our chain was probably altered.
                // Need to trim out the newly introduced null entries at the end of
                // our chain.
                if (theOne != null) {
                    c = Certificates.trimChain(c);
                    alias = Certificates.getCN(theOne);
                    alias = alias.replace(' ', '_');
                }
                ks.setKeyEntry(alias, key, keyPassword, c);
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions