use of java.security.cert.X509CRL in project cxf by apache.
the class LdapCertificateRepo method getCRLsFromLdap.
private List<X509CRL> getCRLsFromLdap(String tmpRootDN, String tmpFilter, String tmpAttrName) {
try {
List<X509CRL> crls = new ArrayList<>();
NamingEnumeration<SearchResult> answer = ldapSearch.searchSubTree(tmpRootDN, tmpFilter);
while (answer.hasMore()) {
SearchResult sr = answer.next();
Attributes attrs = sr.getAttributes();
Attribute attribute = attrs.get(tmpAttrName);
if (attribute != null) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509CRL crl = (X509CRL) cf.generateCRL(new ByteArrayInputStream((byte[]) attribute.get()));
crls.add(crl);
}
}
return crls;
} catch (CertificateException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (NamingException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (CRLException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of java.security.cert.X509CRL in project Openfire by igniterealtime.
the class ClientTrustManager method loadCRL.
private void loadCRL() {
File crlFile = new File(JiveGlobals.getProperty("xmpp.client.certificate.crl", "resources" + File.separator + "security" + File.separator + "crl.pem"));
if (!crlFile.isFile()) {
Log.debug("ClientTrustmanager: crl file not found " + crlFile.toString());
useCRLs = false;
return;
}
long modified = crlFile.lastModified();
if (modified > crlLastUpdated) {
crlLastUpdated = modified;
Log.debug("ClientTrustManager: Updating CRLs");
useCRLs = false;
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509CRL crl;
FileInputStream crlStream = new FileInputStream(crlFile);
BufferedInputStream crlBuffer = new BufferedInputStream(crlStream);
//remove existing CRLs
crls.clear();
while (crlBuffer.available() > 0) {
crl = (X509CRL) cf.generateCRL(crlBuffer);
Log.debug("ClientTrustManager: adding CRL for " + crl.getIssuerDN());
crls.add(crl);
}
useCRLs = true;
} catch (FileNotFoundException e) {
// Its ok if the file wasnt found- maybe we dont have any CRL's
Log.debug("ClientTrustManager: CRL file not found: " + crlFile.toString());
} catch (IOException e) {
//Thrown bot the input streams
Log.error("ClientTrustManager: IOException while parsing CRLs", e);
} catch (CertificateException e) {
//Thrown by CertificateFactory.getInstance(...)
Log.error("ClientTrustManager: ", e);
} catch (CRLException e) {
Log.error("ClientTrustManager: CRLException while parsing CRLs", e);
}
}
}
use of java.security.cert.X509CRL in project gitblit by gitblit.
the class X509Utils method isRevoked.
/**
* Returns true if the certificate has been revoked.
*
* @param cert
* @param caRevocationList
* @return true if the certificate is revoked
*/
public static boolean isRevoked(X509Certificate cert, File caRevocationList) {
if (!caRevocationList.exists()) {
return false;
}
InputStream inStream = null;
try {
inStream = new FileInputStream(caRevocationList);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509CRL crl = (X509CRL) cf.generateCRL(inStream);
return crl.isRevoked(cert);
} catch (Exception e) {
logger.error(MessageFormat.format("Failed to check revocation status for certificate {0,number,0} [{1}] in {2}", cert.getSerialNumber(), cert.getSubjectDN().getName(), caRevocationList));
} finally {
if (inStream != null) {
try {
inStream.close();
} catch (Exception e) {
}
}
}
return false;
}
use of java.security.cert.X509CRL in project robovm by robovm.
the class X509CRLStoreSelector method match.
public boolean match(Object obj) {
if (!(obj instanceof X509CRL)) {
return false;
}
X509CRL crl = (X509CRL) obj;
DERInteger dci = null;
try {
byte[] bytes = crl.getExtensionValue(X509Extensions.DeltaCRLIndicator.getId());
if (bytes != null) {
dci = DERInteger.getInstance(X509ExtensionUtil.fromExtensionValue(bytes));
}
} catch (Exception e) {
return false;
}
if (isDeltaCRLIndicatorEnabled()) {
if (dci == null) {
return false;
}
}
if (isCompleteCRLEnabled()) {
if (dci != null) {
return false;
}
}
if (dci != null) {
if (maxBaseCRLNumber != null) {
if (dci.getPositiveValue().compareTo(maxBaseCRLNumber) == 1) {
return false;
}
}
}
if (issuingDistributionPointEnabled) {
byte[] idp = crl.getExtensionValue(X509Extensions.IssuingDistributionPoint.getId());
if (issuingDistributionPoint == null) {
if (idp != null) {
return false;
}
} else {
if (!Arrays.areEqual(idp, issuingDistributionPoint)) {
return false;
}
}
}
return super.match((X509CRL) obj);
}
use of java.security.cert.X509CRL in project robovm by robovm.
the class X509CRLTest method isRevoked.
private void isRevoked(CertificateFactory f) throws Exception {
X509Certificate rsaCert = getCertificate(f, CERT_RSA);
X509Certificate dsaCert = getCertificate(f, CERT_DSA);
X509CRL crlRsa = getCRL(f, CRL_RSA);
X509CRL crlRsaDsa = getCRL(f, CRL_RSA_DSA);
assertTrue(crlRsa.isRevoked(rsaCert));
assertFalse(crlRsa.isRevoked(dsaCert));
assertTrue(crlRsaDsa.isRevoked(rsaCert));
assertTrue(crlRsaDsa.isRevoked(dsaCert));
try {
assertFalse(crlRsa.isRevoked(null));
if ("BC".equals(f.getProvider().getName())) {
fail("BouncyCastle throws on null input");
}
} catch (NullPointerException e) {
if (!"BC".equals(f.getProvider().getName())) {
fail("Should not throw on null input");
}
}
}
Aggregations