Search in sources :

Example 46 with TrustManagerFactory

use of javax.net.ssl.TrustManagerFactory in project robovm by robovm.

the class myTrustManagerFactory method test_ConstructorLjavax_net_ssl_TrustManagerFactorySpiLjava_security_ProviderLjava_lang_String.

public void test_ConstructorLjavax_net_ssl_TrustManagerFactorySpiLjava_security_ProviderLjava_lang_String() throws NoSuchAlgorithmException {
    TrustManagerFactorySpi spi = new MyTrustManagerFactorySpi();
    TrustManagerFactory tmF = new myTrustManagerFactory(spi, getDefaultProvider(), getDefaultAlgorithm());
    assertTrue("Not CertStore object", tmF instanceof TrustManagerFactory);
    assertEquals("Incorrect algorithm", tmF.getAlgorithm(), getDefaultAlgorithm());
    assertEquals("Incorrect provider", tmF.getProvider(), getDefaultProvider());
    assertNull("Incorrect result", tmF.getTrustManagers());
    tmF = new myTrustManagerFactory(null, null, null);
    assertTrue("Not CertStore object", tmF instanceof TrustManagerFactory);
    assertNull("Provider must be null", tmF.getProvider());
    assertNull("Algorithm must be null", tmF.getAlgorithm());
    try {
        tmF.getTrustManagers();
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
    }
}
Also used : MyTrustManagerFactorySpi(org.apache.harmony.xnet.tests.support.MyTrustManagerFactorySpi) TrustManagerFactorySpi(javax.net.ssl.TrustManagerFactorySpi) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) MyTrustManagerFactorySpi(org.apache.harmony.xnet.tests.support.MyTrustManagerFactorySpi)

Example 47 with TrustManagerFactory

use of javax.net.ssl.TrustManagerFactory in project robovm by robovm.

the class myTrustManagerFactory method test_getInstanceLjava_lang_StringLjava_lang_String04.

/**
     * Test for <code>getInstance(String algorithm, String provider)</code>
     * method
     * Assertion: returns instance of TrustManagerFactory
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String04() throws Exception {
    for (String validValue : getValidValues()) {
        TrustManagerFactory trustMF = TrustManagerFactory.getInstance(validValue, getDefaultProviderName());
        assertTrue("Not TrustManagerFactory object", trustMF instanceof TrustManagerFactory);
        assertEquals("Invalid algorithm", trustMF.getAlgorithm(), validValue);
        assertEquals("Invalid provider", trustMF.getProvider(), getDefaultProvider());
    }
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory)

Example 48 with TrustManagerFactory

use of javax.net.ssl.TrustManagerFactory in project robovm by robovm.

the class myTrustManagerFactory method test_getTrustManagers.

/**
     * Test for <code>geTrustManagers()</code>
     * @throws KeyStoreException
     * @throws IOException
     * @throws CertificateException
     * @throws NoSuchAlgorithmException
     */
public void test_getTrustManagers() {
    try {
        TrustManagerFactory trustMF = TrustManagerFactory.getInstance(getDefaultAlgorithm());
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(null, null);
        trustMF.init(ks);
        TrustManager[] tm = trustMF.getTrustManagers();
        assertNotNull("Result has not be null", tm);
        assertTrue("Length of result TrustManager array should not be 0", (tm.length > 0));
    } catch (Exception ex) {
        fail("Unexpected exception " + ex.toString());
    }
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) TrustManager(javax.net.ssl.TrustManager)

Example 49 with TrustManagerFactory

use of javax.net.ssl.TrustManagerFactory in project robovm by robovm.

the class TrustManagerFactory2Test method testLjava_lang_StringLjava_security_Provider.

/**
     * Test for <code>getInstance(String algorithm, Provider provider)</code>
     * method
     * Assertions:
     * throws NullPointerException when algorithm is null;
     * throws NoSuchAlgorithmException when algorithm is not correct;
     * throws IllegalArgumentException when provider is null;
     * returns TrustManagerFactory object
     */
public void testLjava_lang_StringLjava_security_Provider() throws Exception {
    try {
        TrustManagerFactory.getInstance(null, mProv);
        fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
    } catch (NoSuchAlgorithmException e) {
    } catch (NullPointerException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            TrustManagerFactory.getInstance(invalidValues[i], mProv);
            fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
        } catch (NoSuchAlgorithmException e) {
        }
    }
    Provider prov = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            TrustManagerFactory.getInstance(validValues[i], prov);
            fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(invalidValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
    }
    TrustManagerFactory tmf;
    for (int i = 0; i < validValues.length; i++) {
        tmf = TrustManagerFactory.getInstance(validValues[i], mProv);
        assertTrue("Not instanceof TrustManagerFactory object", tmf instanceof TrustManagerFactory);
        assertEquals("Incorrect algorithm", tmf.getAlgorithm(), validValues[i]);
        assertEquals("Incorrect provider", tmf.getProvider(), mProv);
        checkResult(tmf);
    }
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Provider(java.security.Provider)

Example 50 with TrustManagerFactory

use of javax.net.ssl.TrustManagerFactory in project robovm by robovm.

the class TrustManagerFactory2Test method test_getInstanceLjava_lang_String.

/**
     * Test for <code>getInstance(String algorithm)</code> method
     * Assertions:
     * throws NullPointerException when algorithm is null;
     * throws NoSuchAlgorithmException when algorithm is not correct;
     * returns TrustManagerFactory object
     */
public void test_getInstanceLjava_lang_String() throws Exception {
    try {
        TrustManagerFactory.getInstance(null);
        fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
    } catch (NoSuchAlgorithmException e) {
    } catch (NullPointerException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            TrustManagerFactory.getInstance(invalidValues[i]);
            fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
        } catch (NoSuchAlgorithmException e) {
        }
    }
    TrustManagerFactory tmf;
    for (int i = 0; i < validValues.length; i++) {
        tmf = TrustManagerFactory.getInstance(validValues[i]);
        assertTrue("Not instanceof TrustManagerFactory object", tmf instanceof TrustManagerFactory);
        assertEquals("Incorrect algorithm", tmf.getAlgorithm(), validValues[i]);
        assertEquals("Incorrect provider", tmf.getProvider(), mProv);
        checkResult(tmf);
    }
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

TrustManagerFactory (javax.net.ssl.TrustManagerFactory)504 KeyStore (java.security.KeyStore)318 SSLContext (javax.net.ssl.SSLContext)247 TrustManager (javax.net.ssl.TrustManager)186 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)180 IOException (java.io.IOException)129 FileInputStream (java.io.FileInputStream)123 X509TrustManager (javax.net.ssl.X509TrustManager)123 InputStream (java.io.InputStream)113 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)113 KeyStoreException (java.security.KeyStoreException)98 CertificateException (java.security.cert.CertificateException)87 KeyManagementException (java.security.KeyManagementException)64 X509Certificate (java.security.cert.X509Certificate)60 SecureRandom (java.security.SecureRandom)53 KeyManager (javax.net.ssl.KeyManager)48 CertificateFactory (java.security.cert.CertificateFactory)37 GeneralSecurityException (java.security.GeneralSecurityException)36 File (java.io.File)35 Certificate (java.security.cert.Certificate)34