Search in sources :

Example 41 with CRLException

use of java.security.cert.CRLException 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);
        }
    }
}
Also used : X509CRL(java.security.cert.X509CRL) BufferedInputStream(java.io.BufferedInputStream) FileNotFoundException(java.io.FileNotFoundException) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) File(java.io.File) CertificateFactory(java.security.cert.CertificateFactory) CRLException(java.security.cert.CRLException) FileInputStream(java.io.FileInputStream)

Example 42 with CRLException

use of java.security.cert.CRLException in project robovm by robovm.

the class CMSUtils method getCRLsFromStore.

static List getCRLsFromStore(CertStore certStore) throws CertStoreException, CMSException {
    List crls = new ArrayList();
    try {
        for (Iterator it = certStore.getCRLs(null).iterator(); it.hasNext(); ) {
            X509CRL c = (X509CRL) it.next();
            crls.add(CertificateList.getInstance(ASN1Primitive.fromByteArray(c.getEncoded())));
        }
        return crls;
    } catch (IllegalArgumentException e) {
        throw new CMSException("error processing crls", e);
    } catch (IOException e) {
        throw new CMSException("error processing crls", e);
    } catch (CRLException e) {
        throw new CMSException("error encoding crls", e);
    }
}
Also used : X509CRL(java.security.cert.X509CRL) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) CertificateList(org.bouncycastle.asn1.x509.CertificateList) List(java.util.List) IOException(java.io.IOException) CRLException(java.security.cert.CRLException)

Example 43 with CRLException

use of java.security.cert.CRLException in project robovm by robovm.

the class X509CRLObject method verify.

public void verify(PublicKey key, String sigProvider) throws CRLException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
    if (!c.getSignatureAlgorithm().equals(c.getTBSCertList().getSignature())) {
        throw new CRLException("Signature algorithm on CertificateList does not match TBSCertList.");
    }
    Signature sig;
    if (sigProvider != null) {
        sig = Signature.getInstance(getSigAlgName(), sigProvider);
    } else {
        sig = Signature.getInstance(getSigAlgName());
    }
    sig.initVerify(key);
    sig.update(this.getTBSCertList());
    if (!sig.verify(this.getSignature())) {
        throw new SignatureException("CRL does not verify with supplied public key.");
    }
}
Also used : Signature(java.security.Signature) SignatureException(java.security.SignatureException) CRLException(java.security.cert.CRLException)

Example 44 with CRLException

use of java.security.cert.CRLException in project robovm by robovm.

the class CRLExceptionTest method testCRLException06.

/**
     * Test for <code>CRLException(String, Throwable)</code> constructor
     * Assertion: constructs CRLException when <code>cause</code> is null
     * <code>msg</code> is null
     */
public void testCRLException06() {
    CRLException tE = new CRLException(null, null);
    assertNull("getMessage() must return null", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CRLException(java.security.cert.CRLException)

Example 45 with CRLException

use of java.security.cert.CRLException in project robovm by robovm.

the class CRLExceptionTest method testCRLException03.

/**
     * Test for <code>CRLException(String)</code> constructor Assertion:
     * constructs CRLException when <code>msg</code> is null
     */
public void testCRLException03() {
    String msg = null;
    CRLException tE = new CRLException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CRLException(java.security.cert.CRLException)

Aggregations

CRLException (java.security.cert.CRLException)63 IOException (java.io.IOException)26 CertificateException (java.security.cert.CertificateException)21 X509CRL (java.security.cert.X509CRL)14 CRL (java.security.cert.CRL)11 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Signature (java.security.Signature)8 CertificateFactory (java.security.cert.CertificateFactory)8 SignatureException (java.security.SignatureException)6 InputStream (java.io.InputStream)5 Certificate (java.security.cert.Certificate)5 X509CRLImpl (sun.security.x509.X509CRLImpl)5 CertificateParsingException (java.security.cert.CertificateParsingException)4 ArrayList (java.util.ArrayList)4 DataInputStream (java.io.DataInputStream)3 CertificateFactorySpi (java.security.cert.CertificateFactorySpi)3 X509CRLEntry (java.security.cert.X509CRLEntry)3 X509Certificate (java.security.cert.X509Certificate)3 X500Principal (javax.security.auth.x500.X500Principal)3 MyCertificateFactorySpi (org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi)3