use of org.bouncycastle.openssl.X509TrustedCertificateBlock in project keystore-explorer by kaikramer.
the class X509CertUtil method loadAsPEM.
private static List<X509Certificate> loadAsPEM(byte[] bytes, CertificateFactory cf) {
PEMParser pemParser = new PEMParser(new StringReader(new String(bytes)));
JcaX509CertificateConverter jcaX509CertConverter = new JcaX509CertificateConverter();
List<X509Certificate> certs = new ArrayList<>();
try {
Object pemObject = pemParser.readObject();
while (pemObject != null) {
// check for all possible certificate classes
if (pemObject instanceof X509CertificateHolder) {
certs.add(jcaX509CertConverter.getCertificate((X509CertificateHolder) pemObject));
} else if (pemObject instanceof X509TrustedCertificateBlock) {
X509TrustedCertificateBlock trustedCertBlock = (X509TrustedCertificateBlock) pemObject;
certs.add(jcaX509CertConverter.getCertificate(trustedCertBlock.getCertificateHolder()));
} else if (pemObject instanceof ContentInfo) {
ContentInfo contentInfo = (ContentInfo) pemObject;
Collection<? extends Certificate> certsFromPkcs7 = cf.generateCertificates(new ByteArrayInputStream(contentInfo.getEncoded()));
if (!certsFromPkcs7.isEmpty()) {
List<X509Certificate> x509Certificates = convertCertificates(certsFromPkcs7);
certs.addAll(x509Certificates);
}
}
pemObject = pemParser.readObject();
}
return certs;
} catch (IOException | CertificateException | CryptoException e) {
return certs;
}
}
Aggregations