Search in sources :

Example 76 with CertificateFactory

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

the class CertificateFactory2Test method GetInstance01.

/**
     * Test for <code>getInstance(String type)</code> method
     * Assertions:
     * throws NullPointerException when type is null
     * throws CertificateException when type is not available
     * returns CertificateFactory object
     */
public void GetInstance01(boolean mode) throws CertificateException, CRLException {
    try {
        CertificateFactory.getInstance(null);
        fail("NullPointerException or CertificateException must be thrown when type is null");
    } catch (CertificateException e) {
    } catch (NullPointerException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            CertificateFactory.getInstance(invalidValues[i]);
            fail("CertificateException must be thrown (type: ".concat(invalidValues[i]).concat(")"));
        } catch (CertificateException e) {
        }
    }
    CertificateFactory cerF;
    for (int i = 0; i < validValues.length; i++) {
        cerF = CertificateFactory.getInstance(validValues[i]);
        assertEquals("Incorrect type", cerF.getType(), validValues[i]);
        assertEquals("Incorrect provider", cerF.getProvider(), mProv);
        checkResult(cerF, mode);
    }
}
Also used : CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory)

Example 77 with CertificateFactory

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

the class CertificateFactory2Test method GetInstance03.

/**
     * Test for <code>getInstance(String type, Provider provider)</code>
     * method
     * Assertions:
     * throws NullPointerException when type is null
     * throws CertificateException when type is not available
     * throws IllegalArgumentException when provider is null;
     * returns CertificateFactory object
     */
public void GetInstance03(boolean mode) throws CertificateException, IllegalArgumentException, CRLException {
    try {
        CertificateFactory.getInstance(null, mProv);
        fail("NullPointerException or CertificateException must be thrown when type is null");
    } catch (CertificateException e) {
    } catch (NullPointerException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            CertificateFactory.getInstance(invalidValues[i], mProv);
            fail("CertificateException must be thrown (type: ".concat(invalidValues[i]).concat(")"));
        } catch (CertificateException e) {
        }
    }
    Provider prov = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            CertificateFactory.getInstance(validValues[i], prov);
            fail("IllegalArgumentException must be thrown when provider is null (type: ".concat(validValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
    }
    CertificateFactory cerF;
    for (int i = 0; i < validValues.length; i++) {
        cerF = CertificateFactory.getInstance(validValues[i], mProv);
        assertEquals("Incorrect type", cerF.getType(), validValues[i]);
        assertEquals("Incorrect provider", cerF.getProvider(), mProv);
        checkResult(cerF, mode);
    }
}
Also used : CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) Provider(java.security.Provider)

Example 78 with CertificateFactory

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

the class CertificateFactory3Test method testGenerateCertPath01.

/**
     * Test for <code>generateCertPath(List certificates)</code> method
     * Assertion: returns CertPath with 1 Certificate
     */
public void testGenerateCertPath01() throws Exception {
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    // create list of certificates with one certificate
    Certificate cert = certFs[0].generateCertificate(new ByteArrayInputStream(TestUtils.getEncodedX509Certificate()));
    List<Certificate> list = new Vector<Certificate>();
    list.add(cert);
    for (int i = 0; i < certFs.length; i++) {
        CertPath certPath = null;
        certPath = certFs[i].generateCertPath(list);
        assertEquals(cert.getType(), certPath.getType());
        List<? extends Certificate> list1 = certPath.getCertificates();
        assertFalse("Result list is empty", list1.isEmpty());
        Iterator<? extends Certificate> it = list1.iterator();
        assertEquals("Incorrect Certificate in CertPath", cert, it.next());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertPath(java.security.cert.CertPath) CertificateFactory(java.security.cert.CertificateFactory) Vector(java.util.Vector) Certificate(java.security.cert.Certificate)

Example 79 with CertificateFactory

use of java.security.cert.CertificateFactory 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 80 with CertificateFactory

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

the class CertificateFactory4Test method test_getInstanceLjava_lang_String.

/**
     * java.security.cert.CertificateFactory#getInstance(java.lang.String)
     */
public void test_getInstanceLjava_lang_String() throws Exception {
    // Test for method java.security.cert.CertificateFactory
    // java.security.cert.CertificateFactory.getInstance(java.lang.String)
    CertificateFactory fact = CertificateFactory.getInstance("X.509");
    assertTrue("factory is null", fact != null);
}
Also used : CertificateFactory(java.security.cert.CertificateFactory)

Aggregations

CertificateFactory (java.security.cert.CertificateFactory)550 X509Certificate (java.security.cert.X509Certificate)409 ByteArrayInputStream (java.io.ByteArrayInputStream)372 Certificate (java.security.cert.Certificate)272 CertificateException (java.security.cert.CertificateException)120 KeyFactory (java.security.KeyFactory)103 PrivateKey (java.security.PrivateKey)93 InputStream (java.io.InputStream)92 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)86 IOException (java.io.IOException)80 KeyStore (java.security.KeyStore)77 PrivateKeyEntry (java.security.KeyStore.PrivateKeyEntry)67 Entry (java.security.KeyStore.Entry)59 TrustedCertificateEntry (java.security.KeyStore.TrustedCertificateEntry)59 KeyStoreException (java.security.KeyStoreException)49 ArrayList (java.util.ArrayList)49 FileInputStream (java.io.FileInputStream)47 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)35 File (java.io.File)23 HashSet (java.util.HashSet)21