Search in sources :

Example 1 with MySSLContextSpi

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

the class MySslContext method test_createSSLEngine.

/**
     * @throws KeyManagementException
     * javax.net.ssl.SSLContext#createSSLEngine()
     */
public void test_createSSLEngine() throws KeyManagementException {
    if (!DEFSupported)
        fail(NotSupportMsg);
    SSLContextSpi spi = new MySSLContextSpi();
    SSLContext sslContext = new MySslContext(spi, defaultProvider, defaultProtocol);
    sslContext.init(null, null, new SecureRandom());
    SSLEngine sslEngine = sslContext.createSSLEngine();
    assertNotNull("SSL engine is null", sslEngine);
}
Also used : MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) SSLContextSpi(javax.net.ssl.SSLContextSpi) SSLEngine(javax.net.ssl.SSLEngine) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext)

Example 2 with MySSLContextSpi

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

the class MySslContext method test_createSSLEngineLjava_lang_StringI.

/**
     * @throws KeyManagementException
     * javax.net.ssl.SSLContext#createSSLEngine(java.lang.String, int)
     */
public void test_createSSLEngineLjava_lang_StringI() throws KeyManagementException {
    if (!DEFSupported)
        fail(NotSupportMsg);
    SSLContextSpi spi = new MySSLContextSpi();
    SSLContext sslContext = new MySslContext(spi, defaultProvider, defaultProtocol);
    sslContext.init(null, null, new SecureRandom());
    SSLEngine sslEngine = sslContext.createSSLEngine("www.fortify.net", 80);
    assertNotNull("SSL engine is null", sslEngine);
}
Also used : MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) SSLContextSpi(javax.net.ssl.SSLContextSpi) SSLEngine(javax.net.ssl.SSLEngine) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext)

Example 3 with MySSLContextSpi

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

the class MySslContext method test_init$Ljavax_net_ssl_KeyManager$Ljavax_net_ssl_TrustManagerLjava_security_SecureRandom.

/**
      * @throws NoSuchAlgorithmException
     * @throws KeyStoreException
     * @throws FileNotFoundException
     * @throws KeyManagementException
     * javax.net.ssl.SSLContext#
      *     init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[],
      *     java.security.SecureRandom)
      */
public void test_init$Ljavax_net_ssl_KeyManager$Ljavax_net_ssl_TrustManagerLjava_security_SecureRandom() throws Exception {
    if (!DEFSupported)
        fail(NotSupportMsg);
    SSLContextSpi spi = new MySSLContextSpi();
    SSLContext sslContext = new MySslContext(spi, defaultProvider, defaultProtocol);
    try {
        sslContext.createSSLEngine();
        fail("Expected RuntimeException was not thrown");
    } catch (RuntimeException rte) {
    // expected
    }
    try {
        sslContext.init(null, null, null);
        fail("KeyManagementException wasn't thrown");
    } catch (KeyManagementException kme) {
    //expected
    }
    try {
        String tAlg = TrustManagerFactory.getDefaultAlgorithm();
        String kAlg = KeyManagerFactory.getDefaultAlgorithm();
        if (tAlg == null)
            fail("TrustManagerFactory default algorithm is not defined");
        if (kAlg == null)
            fail("KeyManagerFactory default algorithm is not defined");
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(kAlg);
        kmf.init(null, new char[11]);
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tAlg);
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        tmf.init(ks);
        TrustManager[] tms = tmf.getTrustManagers();
        sslContext.init(kmf.getKeyManagers(), tms, new SecureRandom());
    } catch (Exception e) {
        System.out.println("EE = " + e);
    }
}
Also used : SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) KeyManagementException(java.security.KeyManagementException) KeyManagementException(java.security.KeyManagementException) KeyStoreException(java.security.KeyStoreException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchProviderException(java.security.NoSuchProviderException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) TrustManager(javax.net.ssl.TrustManager) MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) SSLContextSpi(javax.net.ssl.SSLContextSpi) TrustManagerFactory(javax.net.ssl.TrustManagerFactory)

Example 4 with MySSLContextSpi

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

the class MySslContext method test_getProtocol.

/**
     * @throws NoSuchAlgorithmException
     * @throws NoSuchProviderException
     * javax.net.ssl.SSLContext#getProtocol()
     */
public void test_getProtocol() throws NoSuchAlgorithmException, NoSuchProviderException {
    if (!DEFSupported)
        fail(NotSupportMsg);
    SSLContextSpi spi = new MySSLContextSpi();
    SSLContext sslContext = new MySslContext(spi, defaultProvider, defaultProtocol);
    assertEquals("Incorrect protocol", defaultProtocol, sslContext.getProtocol());
    sslContext = new MySslContext(spi, defaultProvider, null);
    assertNull("Incorrect protocol", sslContext.getProtocol());
    sslContext = SSLContext.getInstance(defaultProtocol);
    assertEquals("Incorrect protocol", defaultProtocol, sslContext.getProtocol());
    sslContext = SSLContext.getInstance(defaultProtocol, defaultProvider);
    assertEquals("Incorrect protocol", defaultProtocol, sslContext.getProtocol());
    sslContext = SSLContext.getInstance(defaultProtocol, defaultProviderName);
    assertEquals("Incorrect protocol", defaultProtocol, sslContext.getProtocol());
}
Also used : MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) SSLContextSpi(javax.net.ssl.SSLContextSpi) SSLContext(javax.net.ssl.SSLContext)

Example 5 with MySSLContextSpi

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

the class MySslContext method test_getProvider.

/**
     * @throws NoSuchAlgorithmException
     * @throws NoSuchProviderException
     * javax.net.ssl.SSLContext#getProvider()
     */
public void test_getProvider() throws NoSuchAlgorithmException, NoSuchProviderException {
    if (!DEFSupported)
        fail(NotSupportMsg);
    SSLContextSpi spi = new MySSLContextSpi();
    SSLContext sslContext = new MySslContext(spi, defaultProvider, defaultProtocol);
    assertEquals("Incorrect provider", defaultProvider, sslContext.getProvider());
    sslContext = SSLContext.getInstance(defaultProtocol, defaultProvider);
    assertEquals("Incorrect provider", defaultProvider, sslContext.getProvider());
    sslContext = SSLContext.getInstance(defaultProtocol, defaultProviderName);
    assertEquals("Incorrect provider", defaultProvider, sslContext.getProvider());
}
Also used : MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) MySSLContextSpi(org.apache.harmony.xnet.tests.support.MySSLContextSpi) SSLContextSpi(javax.net.ssl.SSLContextSpi) SSLContext(javax.net.ssl.SSLContext)

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