Search in sources :

Example 81 with CertificateFactory

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

the class CertificateFactory4Test method test_getInstanceLjava_lang_StringLjava_lang_String.

/**
     * java.security.cert.CertificateFactory#getInstance(java.lang.String,
     *        java.lang.String)
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
    // Test for method java.security.cert.CertificateFactory
    // java.security.cert.CertificateFactory.getInstance(java.lang.String,
    // java.lang.String)
    Provider[] providers = Security.getProviders("CertificateFactory.X.509");
    if (providers != null) {
        for (int i = 0; i < providers.length; i++) {
            CertificateFactory fact = CertificateFactory.getInstance("X.509", providers[i].getName());
            assertNotNull("factory is null", fact);
        }
    // end for
    } else {
        fail("No providers support CertificateFactory.X.509");
    }
    // exception case
    try {
        CertificateFactory.getInstance("X.509", "IHaventBeenConfigured");
        fail("Should have thrown NoSuchProviderException");
    } catch (NoSuchProviderException e) {
    // Expected
    }
}
Also used : NoSuchProviderException(java.security.NoSuchProviderException) CertificateFactory(java.security.cert.CertificateFactory) Provider(java.security.Provider)

Example 82 with CertificateFactory

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

the class CertificateFactory4Test method test_generateCRLsLjava_io_InputStream.

/**
     * java.security.cert.CertificateFactory#generateCRLs(java.io.InputStream)
     */
public void test_generateCRLsLjava_io_InputStream() throws Exception {
    CertificateFactory fact = CertificateFactory.getInstance("X.509");
    for (int i = 0; i < CRLCOLLECTION_URLS.length; i++) {
        URL certUrl = new URL(BASE_URL + CRLCOLLECTION_URLS[i]);
        try {
            InputStream is = certUrl.openStream();
            Collection<? extends CRL> crls = fact.generateCRLs(is);
            assertTrue("The CRLs in \"" + certUrl.toExternalForm() + "\" were not parsed correctly", crls != null && crls.size() > 0);
        } catch (IOException e) {
        // the certificate could not be found, skip it
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) URL(java.net.URL)

Example 83 with CertificateFactory

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

the class CertificateFactory4Test method test_generateCertificatesLjava_io_InputStream.

/**
     * java.security.cert.CertificateFactory#generateCertificates(java.io.InputStream)
     */
public void test_generateCertificatesLjava_io_InputStream() throws Exception {
    CertificateFactory fact = CertificateFactory.getInstance("X.509");
    for (int i = 0; i < CERTIFICATE_URLS.length; i++) {
        URL certUrl = new URL(BASE_URL + CERTIFICATE_URLS[i]);
        try {
            InputStream is = certUrl.openStream();
            Collection<? extends Certificate> certs = fact.generateCertificates(is);
            assertNotNull("The certificates in \"" + certUrl.toExternalForm() + "\" were not parsed correctly", certs);
        } catch (IOException e) {
        // the certificate could not be found, skip it
        } catch (CertificateException e) {
            fail("An exception was thrown while parsing \"" + certUrl.toExternalForm() + "\": " + e.getMessage());
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) URL(java.net.URL)

Example 84 with CertificateFactory

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

the class myCertificateFactory method testCertificateFactory01.

/**
     * Test for <code>getInstance(String type)</code> method
     * Assertion: returns CertificateFactory if type is X.509
     */
public void testCertificateFactory01() throws CertificateException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    for (int i = 0; i < validValues.length; i++) {
        CertificateFactory certF = CertificateFactory.getInstance(validValues[i]);
        assertEquals("Incorrect type: ", validValues[i], certF.getType());
    }
}
Also used : CertificateFactory(java.security.cert.CertificateFactory)

Example 85 with CertificateFactory

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

the class myCertificateFactory method testCertificateFactory12.

/**
     * Test for <code>generateCertPath(InputStream inStream)</code>
     * <code>generateCertPath(InputStream inStream, String encoding)</code>
     * methods
     * Assertion: throws CertificateException when inStream is null or
     * when isStream contains invalid datas
     */
public void testCertificateFactory12() {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    InputStream is1 = null;
    InputStream is2 = new ByteArrayInputStream(new byte[10]);
    for (int i = 0; i < certFs.length; i++) {
        try {
            certFs[i].generateCertPath(is1);
            fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null");
        } catch (CertificateException e) {
        } catch (NullPointerException e) {
        }
        try {
            certFs[i].generateCertPath(is2);
            fail("generateCertificate must thrown CertificateException when input stream contains invalid datas");
        } catch (CertificateException e) {
        }
        Iterator<String> it = certFs[i].getCertPathEncodings();
        while (it.hasNext()) {
            String enc = it.next();
            try {
                certFs[i].generateCertPath(is1, enc);
                fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null and encodings ".concat(enc));
            } catch (CertificateException e) {
            } catch (NullPointerException e) {
            }
            try {
                certFs[i].generateCertPath(is2, enc);
                fail("generateCertificate must thrown CertificateException when input stream contains invalid datas  and encodings ".concat(enc));
            } catch (CertificateException e) {
            }
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CertificateException(java.security.cert.CertificateException) 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