Search in sources :

Example 66 with CertificateException

use of java.security.cert.CertificateException 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 67 with CertificateException

use of java.security.cert.CertificateException 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 68 with CertificateException

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

the class CertificateFactorySpiTest method testEngineGenerateCertPathLjava_io_InputStream02.

/**
     * Test for <code>engineGenerateCertPath(InputStream)</code> method.
     * Assertion: Generates a <code>CertPath</code> object and initializes it
     * with the data read from the <code>InputStream</code>
     */
public void testEngineGenerateCertPathLjava_io_InputStream02() {
    CertificateFactorySpi certFactorySpi = new extCertificateFactorySpi();
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
    DataInputStream dis = new DataInputStream(bais);
    try {
        certFactorySpi.engineGenerateCertPath(dis);
        fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException e) {
    // expected
    } catch (CertificateException e) {
        fail("Unexpected CertificateException " + e.getMessage());
    }
}
Also used : CertificateFactorySpi(java.security.cert.CertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) DataInputStream(java.io.DataInputStream)

Example 69 with CertificateException

use of java.security.cert.CertificateException 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 70 with CertificateException

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

CertificateException (java.security.cert.CertificateException)456 IOException (java.io.IOException)221 X509Certificate (java.security.cert.X509Certificate)215 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)141 KeyStoreException (java.security.KeyStoreException)123 CertificateFactory (java.security.cert.CertificateFactory)103 ByteArrayInputStream (java.io.ByteArrayInputStream)97 Certificate (java.security.cert.Certificate)75 KeyStore (java.security.KeyStore)58 InputStream (java.io.InputStream)55 UnrecoverableKeyException (java.security.UnrecoverableKeyException)53 ArrayList (java.util.ArrayList)49 InvalidKeyException (java.security.InvalidKeyException)44 X509TrustManager (javax.net.ssl.X509TrustManager)41 SSLContext (javax.net.ssl.SSLContext)36 FileInputStream (java.io.FileInputStream)34 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)34 RemoteException (android.os.RemoteException)33 FileNotFoundException (java.io.FileNotFoundException)30 KeyManagementException (java.security.KeyManagementException)30