Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in KeyStoreUtil (due to new bouncycastle version) #22

Open
ThomasKamm opened this issue Jul 31, 2017 · 1 comment
Open

Bug in KeyStoreUtil (due to new bouncycastle version) #22

ThomasKamm opened this issue Jul 31, 2017 · 1 comment

Comments

@ThomasKamm
Copy link

ThomasKamm commented Jul 31, 2017

The Switch to the new bouncycastle included using org.bouncycastle.util.io.pem.PemReader as a replacement for PEMReader in KeyStoreUtils.java.
The objects returns by this reader are not Certificates or Keys themselves, leading to the instanceof checks never evaluating to true.
Therefore e.g. loadCertificateFromPEM always returns null.

The PemReader should probably be replaced with org.bouncycastle.openssl.PEMParser.

The following sample seems to solve the problem:

public static X509Certificate loadCertificateFromPEM(InputStream in, final char[] pwd) throws Exception
{
        loadBC();
        JcaX509CertificateConverter certConv = new JcaX509CertificateConverter();
        PEMParser pemParser = new PEMParser(new InputStreamReader(in));

        Object obj;
        while ((obj = pemParser.readObject()) != null)
        {
                if (obj instanceof X509CertificateHolder)
                {
                        return certConv.getCertificate((X509CertificateHolder) obj);
                }
        }

        return null;
}
@pphaal
Copy link

pphaal commented Feb 21, 2018

Thanks for pointing me in the right direction. Similar changes are required to the loadKeyManager method, see KeyStoreUtils.java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants