Search in sources :

Example 6 with MySSLContextSpi

use of org.apache.harmony.xnet.tests.support.MySSLContextSpi in project robovm by robovm.

the class MySslContext method test_ConstructorLjavax_net_ssl_SSLContextSpiLjava_security_ProviderLjava_lang_String.

/**
     * Test for <code>SSLContext</code> constructor Assertion: returns
     * SSLContext object
     */
public void test_ConstructorLjavax_net_ssl_SSLContextSpiLjava_security_ProviderLjava_lang_String() throws NoSuchAlgorithmException, KeyManagementException {
    if (!DEFSupported) {
        fail(NotSupportMsg);
        return;
    }
    SSLContextSpi spi = new MySSLContextSpi();
    SSLContext sslContext = new MySslContext(spi, defaultProvider, defaultProtocol);
    assertEquals("Incorrect protocol", defaultProtocol, sslContext.getProtocol());
    assertEquals("Incorrect provider", defaultProvider, sslContext.getProvider());
    TrustManager[] tm = null;
    KeyManager[] km = null;
    sslContext.init(km, tm, new SecureRandom());
    assertNotNull("No SSLEngine created", sslContext.createSSLEngine());
    assertNotNull("No SSLEngine created", sslContext.createSSLEngine("host", 8888));
    try {
        sslContext.init(km, tm, null);
        fail("KeyManagementException should be thrown for null " + "SecureRandom");
    } catch (KeyManagementException e) {
    }
    sslContext = new MySslContext(null, null, null);
    assertNull("Incorrect protocol", sslContext.getProtocol());
    assertNull("Incorrect provider", sslContext.getProvider());
    try {
        sslContext.createSSLEngine();
        fail("NullPointerException should be thrown");
    } catch (NullPointerException e) {
    }
    try {
        sslContext.getSocketFactory();
        fail("NullPointerException should be thrown");
    } catch (NullPointerException e) {
    }
}
Also used : MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) SSLContextSpi(javax.net.ssl.SSLContextSpi) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) KeyManager(javax.net.ssl.KeyManager) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager)

Aggregations

SSLContext (javax.net.ssl.SSLContext)6 SSLContextSpi (javax.net.ssl.SSLContextSpi)6 MySSLContextSpi (org.apache.harmony.xnet.tests.support.MySSLContextSpi)6 SecureRandom (java.security.SecureRandom)4 KeyManagementException (java.security.KeyManagementException)2 SSLEngine (javax.net.ssl.SSLEngine)2 TrustManager (javax.net.ssl.TrustManager)2 FileNotFoundException (java.io.FileNotFoundException)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 KeyManager (javax.net.ssl.KeyManager)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1