Search in sources :

Example 11 with CRLException

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

the class CertificateFactory method engineGenerateCRL.

/**
     * Generates a certificate revocation list (CRL) object and initializes
     * it with the data read from the input stream inStream.
     */
public CRL engineGenerateCRL(InputStream inStream) throws CRLException {
    if (currentCrlStream == null) {
        currentCrlStream = inStream;
        sCrlData = null;
        sCrlDataObjectCount = 0;
    } else if (// reset if input stream has changed
    currentCrlStream != inStream) {
        currentCrlStream = inStream;
        sCrlData = null;
        sCrlDataObjectCount = 0;
    }
    try {
        if (sCrlData != null) {
            if (sCrlDataObjectCount != sCrlData.size()) {
                return getCRL();
            } else {
                sCrlData = null;
                sCrlDataObjectCount = 0;
                return null;
            }
        }
        PushbackInputStream pis = new PushbackInputStream(inStream);
        int tag = pis.read();
        if (tag == -1) {
            return null;
        }
        pis.unread(tag);
        if (// assume ascii PEM encoded.
        tag != 0x30) {
            return readPEMCRL(pis);
        } else {
            // lazy evaluate to help processing of large CRLs
            return readDERCRL(new ASN1InputStream(pis, true));
        }
    } catch (CRLException e) {
        throw e;
    } catch (Exception e) {
        throw new CRLException(e.toString());
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) PushbackInputStream(java.io.PushbackInputStream) CRLException(java.security.cert.CRLException) CertificateParsingException(java.security.cert.CertificateParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CRLException(java.security.cert.CRLException)

Example 12 with CRLException

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

the class CertificateFactory2Test method checkResult.

private void checkResult(CertificateFactory certFactory, boolean mode) throws CertificateException, CRLException {
    MyCertificateFactorySpi.putMode(mode);
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
    DataInputStream dis = new DataInputStream(bais);
    try {
        certFactory.generateCertPath(bais);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactory.generateCertPath(dis);
        if (!mode) {
            fail("CertificateException must be thrown because encodings list is empty");
        }
    } catch (CertificateException e) {
        if (mode) {
            fail("Unexpected CertificateFactoryException was thrown");
        }
    }
    try {
        certFactory.generateCertPath(bais, "aa");
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactory.generateCertPath(dis, "");
        if (mode) {
            fail("IllegalArgumentException must be thrown");
        }
    } catch (IllegalArgumentException e) {
        if (!mode) {
            fail("Unexpected IllegalArgumentException was thrown");
        }
    }
    certFactory.generateCertPath(dis, "ss");
    try {
        certFactory.generateCertificate(bais);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactory.generateCertificates(null);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    Certificate cert = certFactory.generateCertificate(dis);
    assertNull("Result must be null", cert);
    Collection<? extends Certificate> col = certFactory.generateCertificates(dis);
    assertNull("Result must be null", col);
    try {
        certFactory.generateCRL(bais);
        fail("CRLException must be thrown");
    } catch (CRLException e) {
    }
    try {
        certFactory.generateCRLs(null);
        fail("CRLException must be thrown");
    } catch (CRLException e) {
    }
    CRL crl = certFactory.generateCRL(dis);
    assertNull("Result must be null", crl);
    Collection<? extends CRL> colc = certFactory.generateCRLs(dis);
    assertNull("Result must be null", colc);
    List<Certificate> list = null;
    CertPath cp;
    try {
        cp = certFactory.generateCertPath(list);
        if (mode) {
            fail("NullPointerException must be thrown");
        } else {
            assertNull("Must be null", cp);
        }
    } catch (NullPointerException e) {
        if (!mode) {
            fail("Unexpected NullPointerException was thrown");
        }
    }
    Iterator<String> it = certFactory.getCertPathEncodings();
    if (mode) {
        assertTrue(it.hasNext());
    } else {
        assertFalse(it.hasNext());
    }
}
Also used : CertificateException(java.security.cert.CertificateException) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CRL(java.security.cert.CRL) CertPath(java.security.cert.CertPath) CRLException(java.security.cert.CRLException) Certificate(java.security.cert.Certificate)

Example 13 with CRLException

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

the class CertificateFactorySpiTest method testCertificateFactorySpi02.

/**
     * Test for <code>CertificateFactorySpi</code> constructor
     * Assertion: constructs CertificateFactorySpi
     */
public void testCertificateFactorySpi02() throws CertificateException, CRLException {
    CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi();
    MyCertificateFactorySpi.putMode(true);
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
    DataInputStream dis = new DataInputStream(bais);
    try {
        certFactorySpi.engineGenerateCertPath(bais);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    certFactorySpi.engineGenerateCertPath(dis);
    try {
        certFactorySpi.engineGenerateCertPath(bais, "aa");
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactorySpi.engineGenerateCertPath(dis, "");
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    certFactorySpi.engineGenerateCertPath(dis, "ss");
    try {
        certFactorySpi.engineGenerateCertificate(bais);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactorySpi.engineGenerateCertificates(null);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    Certificate cert = certFactorySpi.engineGenerateCertificate(dis);
    assertNull("Result must be null", cert);
    Collection<? extends Certificate> col = certFactorySpi.engineGenerateCertificates(dis);
    assertNull("Result must be null", col);
    try {
        certFactorySpi.engineGenerateCRL(bais);
        fail("CRLException must be thrown");
    } catch (CRLException e) {
    }
    try {
        certFactorySpi.engineGenerateCRLs(null);
        fail("CRLException must be thrown");
    } catch (CRLException e) {
    }
    CRL crl = certFactorySpi.engineGenerateCRL(dis);
    assertNull("Result must be null", crl);
    Collection<? extends CRL> colcrl = certFactorySpi.engineGenerateCRLs(dis);
    assertNull("Result must be null", colcrl);
    List<Certificate> list = null;
    try {
        certFactorySpi.engineGenerateCertPath(list);
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
    }
    Iterator<String> enc = certFactorySpi.engineGetCertPathEncodings();
    assertTrue("Incorrect Iterator", enc.hasNext());
}
Also used : CertificateFactorySpi(java.security.cert.CertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) CertificateException(java.security.cert.CertificateException) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) CRL(java.security.cert.CRL) CRLException(java.security.cert.CRLException) Certificate(java.security.cert.Certificate)

Example 14 with CRLException

use of java.security.cert.CRLException in project j2objc by google.

the class X509CRLEntryImpl method parse.

private void parse(DerValue derVal) throws CRLException, IOException {
    if (derVal.tag != DerValue.tag_Sequence) {
        throw new CRLException("Invalid encoded RevokedCertificate, " + "starting sequence tag missing.");
    }
    if (derVal.data.available() == 0)
        throw new CRLException("No data encoded for RevokedCertificates");
    revokedCert = derVal.toByteArray();
    // serial number
    DerInputStream in = derVal.toDerInputStream();
    DerValue val = in.getDerValue();
    this.serialNumber = new SerialNumber(val);
    // revocationDate
    int nextByte = derVal.data.peekByte();
    if ((byte) nextByte == DerValue.tag_UtcTime) {
        this.revocationDate = derVal.data.getUTCTime();
    } else if ((byte) nextByte == DerValue.tag_GeneralizedTime) {
        this.revocationDate = derVal.data.getGeneralizedTime();
    } else
        throw new CRLException("Invalid encoding for revocation date");
    if (derVal.data.available() == 0)
        // no extensions
        return;
    // crlEntryExtensions
    this.extensions = new CRLExtensions(derVal.toDerInputStream());
}
Also used : CRLException(java.security.cert.CRLException)

Example 15 with CRLException

use of java.security.cert.CRLException in project j2objc by google.

the class X509CRLEntryImpl method encode.

/**
     * Encodes the revoked certificate to an output stream.
     *
     * @param outStrm an output stream to which the encoded revoked
     * certificate is written.
     * @exception CRLException on encoding errors.
     */
public void encode(DerOutputStream outStrm) throws CRLException {
    try {
        if (revokedCert == null) {
            DerOutputStream tmp = new DerOutputStream();
            // sequence { serialNumber, revocationDate, extensions }
            serialNumber.encode(tmp);
            if (revocationDate.getTime() < YR_2050) {
                tmp.putUTCTime(revocationDate);
            } else {
                tmp.putGeneralizedTime(revocationDate);
            }
            if (extensions != null)
                extensions.encode(tmp, isExplicit);
            DerOutputStream seq = new DerOutputStream();
            seq.write(DerValue.tag_Sequence, tmp);
            revokedCert = seq.toByteArray();
        }
        outStrm.write(revokedCert);
    } catch (IOException e) {
        throw new CRLException("Encoding error: " + e.toString());
    }
}
Also used : IOException(java.io.IOException) 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