Search in sources :

Example 96 with Certificate

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

the class CertificateFactory3Test method testGenerateCertificates.

/**
     * Test for <code>generateCertificates(InputStream inStream)</code> method
     * Assertion: returns Collection which consists of 1 Certificate
     */
public void testGenerateCertificates() throws Exception {
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    Certificate cert = certFs[0].generateCertificate(new ByteArrayInputStream(TestUtils.getEncodedX509Certificate()));
    for (int i = 0; i < certFs.length; i++) {
        Collection<? extends Certificate> col = null;
        col = certFs[i].generateCertificates(new ByteArrayInputStream(TestUtils.getEncodedX509Certificate()));
        Iterator<? extends Certificate> it = col.iterator();
        assertEquals("Incorrect Collection size", col.size(), 1);
        assertEquals("Incorrect Certificate in Collection", cert, it.next());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateFactory(java.security.cert.CertificateFactory) Certificate(java.security.cert.Certificate)

Example 97 with Certificate

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

the class CertificateFactorySpiTest method testEngineGenerateCertPathLJava_util_List01.

/**
     * Test for <code>engineGenerateCertPath(List<? extends Certificate>)</code>
     * method Assertion: generates a <code>CertPath</code> object and
     * initializes it with a <code>List</code> of <code>Certificates</code>
     */
public void testEngineGenerateCertPathLJava_util_List01() {
    CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi();
    MyCertificateFactorySpi.putMode(true);
    List<Certificate> list = new ArrayList<Certificate>();
    try {
        assertNull(certFactorySpi.engineGenerateCertPath(list));
    } catch (CertificateException e) {
        fail("Unexpected CertificateException " + e.getMessage());
    }
    try {
        certFactorySpi.engineGenerateCertPath((List<? extends Certificate>) null);
        fail("expected NullPointerException");
    } catch (NullPointerException e) {
    // ok
    } catch (CertificateException e) {
        fail("Unexpected CertificateException " + e.getMessage());
    }
}
Also used : CertificateFactorySpi(java.security.cert.CertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) ArrayList(java.util.ArrayList) CertificateException(java.security.cert.CertificateException) Certificate(java.security.cert.Certificate)

Example 98 with Certificate

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

the class myCertificateFactory method testCertificateFactory15.

/**
     * Test for <code>generateCertPath(List certificates)</code> method
     * Assertion: returns empty CertPath if certificates is empty
     */
public void testCertificateFactory15() throws CertificateException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    List<Certificate> list = new Vector<Certificate>();
    for (int i = 0; i < certFs.length; i++) {
        CertPath cp = certFs[i].generateCertPath(list);
        List<? extends Certificate> list1 = cp.getCertificates();
        assertTrue("List should be empty", list1.isEmpty());
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) CertPath(java.security.cert.CertPath) CertificateFactory(java.security.cert.CertificateFactory) Vector(java.util.Vector) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Example 99 with Certificate

use of java.security.cert.Certificate 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 100 with Certificate

use of java.security.cert.Certificate 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)

Aggregations

Certificate (java.security.cert.Certificate)723 X509Certificate (java.security.cert.X509Certificate)469 CertificateFactory (java.security.cert.CertificateFactory)272 ByteArrayInputStream (java.io.ByteArrayInputStream)237 KeyStore (java.security.KeyStore)133 PrivateKey (java.security.PrivateKey)132 IOException (java.io.IOException)106 CertificateException (java.security.cert.CertificateException)102 KeyFactory (java.security.KeyFactory)89 KeyStoreException (java.security.KeyStoreException)88 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)72 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)69 PrivateKeyEntry (java.security.KeyStore.PrivateKeyEntry)63 ArrayList (java.util.ArrayList)63 TrustedCertificateEntry (java.security.KeyStore.TrustedCertificateEntry)56 Entry (java.security.KeyStore.Entry)53 PublicKey (java.security.PublicKey)48 InputStream (java.io.InputStream)40 FileInputStream (java.io.FileInputStream)39 Key (java.security.Key)36