use of org.bouncycastle.util.io.pem.PemReader in project zeppelin by apache.
the class PEMImporter method readCertificateChain.
private static List<X509Certificate> readCertificateChain(File certificateChainFile) throws IOException, GeneralSecurityException {
final List<X509Certificate> certs = new ArrayList<>();
try (final PemReader pemReader = new PemReader(Files.newBufferedReader(certificateChainFile.toPath()))) {
final PemObject pemObject = pemReader.readPemObject();
final CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
final ByteArrayInputStream bais = new ByteArrayInputStream(pemObject.getContent());
for (final Certificate cert : certificateFactory.generateCertificates(bais)) {
if (cert instanceof X509Certificate) {
certs.add((X509Certificate) cert);
}
}
if (certs.isEmpty()) {
throw new IllegalStateException("Unable to decode certificate chain");
}
}
return certs;
}
use of org.bouncycastle.util.io.pem.PemReader in project cloudstack by apache.
the class CertUtils method pemToPrivateKey.
public static PrivateKey pemToPrivateKey(final String pem) throws InvalidKeySpecException, IOException {
final PemReader pr = new PemReader(new StringReader(pem));
final PemObject pemObject = pr.readPemObject();
final KeyFactory keyFactory = getKeyFactory();
return keyFactory.generatePrivate(new PKCS8EncodedKeySpec(pemObject.getContent()));
}
use of org.bouncycastle.util.io.pem.PemReader in project cloudstack by apache.
the class CertificateHelper method parseChain.
public static List<Certificate> parseChain(final String chain) throws IOException, CertificateException {
Preconditions.checkNotNull(chain);
final List<Certificate> certs = new ArrayList<Certificate>();
try (final PemReader pemReader = new PemReader(new StringReader(chain))) {
final PemObject pemObject = pemReader.readPemObject();
final CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
final ByteArrayInputStream bais = new ByteArrayInputStream(pemObject.getContent());
for (final Certificate cert : certificateFactory.generateCertificates(bais)) {
if (cert instanceof X509Certificate) {
certs.add(cert);
}
}
if (certs.isEmpty()) {
throw new IllegalStateException("Unable to decode certificate chain");
}
}
return certs;
}
use of org.bouncycastle.util.io.pem.PemReader in project azure-iot-sdk-java by Azure.
the class IotHubSSLContextTest method parsePublicKeyCertificateExceptionsWrappedInCertificateException.
// Tests_SRS_IOTHUBSSLCONTEXT_34_034: [If any exception is encountered while attempting to create the public key certificate instance, this function shall throw a CertificateException.]
@Test(expected = CertificateException.class)
public void parsePublicKeyCertificateExceptionsWrappedInCertificateException() throws CertificateException, IOException {
// arrange
new NonStrictExpectations() {
{
new PemReader(new StringReader(expectedPublicKeyCertificateString));
result = new IOException();
}
};
// act
X509Certificate actualPublicKeyCertificate = Deencapsulation.invoke(IotHubSSLContext.class, "parsePublicKeyCertificate", new Class[] { String.class }, expectedPublicKeyCertificateString);
// assert
assertEquals(mockedX509Certificate, actualPublicKeyCertificate);
}
use of org.bouncycastle.util.io.pem.PemReader in project platformlayer by platformlayer.
the class SimpleCertificateAuthority method parseCsr.
private static PKCS10CertificationRequest parseCsr(String csr) throws IOException {
PemReader reader = new PemReader(new StringReader(csr));
PemObject pemObject = reader.readPemObject();
reader.close();
PKCS10CertificationRequest csrHolder = new PKCS10CertificationRequest(pemObject.getContent());
return csrHolder;
}
Aggregations