private static X509Certificate toX509Certificate(Object pemObject) throws IOException, GeneralSecurityException {
        if (pemObject instanceof X509Certificate) return (X509Certificate) pemObject;
        if (pemObject instanceof X509CertificateHolder) {
            return new JcaX509CertificateConverter()
                    .setProvider(bcProvider)
                    .getCertificate((X509CertificateHolder) pemObject);
        }
        throw new IOException("Invalid type of PEM object: " + pemObject);
    }
BouncyCastle integration for creating a {@link SSLContext} instance from PEM encoded material

@author bjorncs
vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/SslContextBuilder.java