use of org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateFactory in project pdfbox by apache.
the class CrlHelper method performCrlRequestAndCheck.
/**
* Performs the CRL-Request and checks if the given certificate has been revoked.
*
* @param crlUrl to get the CRL from
* @param cert to be checked if it is inside the CRL
* @return CRL-Response; might be very big depending on the issuer.
* @throws CRLException if an Error occurred getting the CRL, or parsing it.
* @throws RevokedCertificateException
*/
public static byte[] performCrlRequestAndCheck(String crlUrl, X509Certificate cert) throws CRLException, RevokedCertificateException {
try {
URL url = new URL(crlUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
if (con.getResponseCode() != 200) {
throw new IOException("Unsuccessful CRL request. Status: " + con.getResponseCode() + " Url: " + crlUrl);
}
CertificateFactory certFac = new CertificateFactory();
X509CRL crl = (X509CRL) certFac.engineGenerateCRL(con.getInputStream());
if (crl.isRevoked(cert)) {
throw new RevokedCertificateException("The Certificate was found on the CRL and is revoked!");
}
return crl.getEncoded();
} catch (IOException e) {
throw new CRLException(e);
}
}
use of org.bouncycastle.jcajce.provider.asymmetric.x509.CertificateFactory in project ddf by codice.
the class PkiTools method pemToCertificate.
/**
* Given a PEM encoded X509 certificate, return an object representation of the certificate
*
* @param certString PEM encoded X509 certificate
* @return instance of X509 certificate
*/
public static X509Certificate pemToCertificate(String certString) {
CertificateFactory cf = new CertificateFactory();
ByteArrayInputStream in = new ByteArrayInputStream(PkiTools.pemToDer(certString));
X509Certificate cert;
try {
cert = (X509Certificate) cf.engineGenerateCertificate(in);
} catch (CertificateException e) {
throw new CertificateGeneratorException("Cannot convert this PEM object to X509 certificate", e);
}
if (cert == null) {
throw new CertificateGeneratorException("Cannot convert this PEM object to X509 certificate");
}
return cert;
}
Aggregations