Search in sources :

Example 11 with KeyManager

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

the class ProtectionParameterImpl method test_initLjava_security_KeyStore$C.

/**
     * Test for <code>init(KeyStore keyStore, char[] password)</code> and
     * <code>getKeyManagers()</code>
     * Assertion: returns not empty KeyManager array
     */
public void test_initLjava_security_KeyStore$C() throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
    if (!DEFSupported) {
        fail(NotSupportedMsg);
        return;
    }
    KeyManagerFactory[] keyMF = createKMFac();
    assertNotNull("KeyManagerFactory object were not created", keyMF);
    KeyStore ksNull = null;
    KeyManager[] km;
    for (int i = 0; i < keyMF.length; i++) {
        keyMF[i].init(ksNull, new char[10]);
        km = keyMF[i].getKeyManagers();
        assertNotNull("Result should not be null", km);
        assertTrue("Length of result KeyManager array should not be 0", (km.length > 0));
    }
    KeyStore ks;
    try {
        ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(null, null);
    } catch (KeyStoreException e) {
        fail(e.toString() + "default KeyStore type is not supported");
        return;
    } catch (Exception e) {
        fail("Unexpected: " + e.toString());
        return;
    }
    for (int i = 0; i < keyMF.length; i++) {
        try {
            keyMF[i].init(ks, new char[10]);
        } catch (KeyStoreException e) {
        }
        km = keyMF[i].getKeyManagers();
        assertNotNull("Result has not be null", km);
        assertTrue("Length of result KeyManager array should not be 0", (km.length > 0));
    }
}
Also used : KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) KeyManager(javax.net.ssl.KeyManager) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchProviderException(java.security.NoSuchProviderException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 12 with KeyManager

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

the class SSLServerSocketTest method test_creationStressTest.

public void test_creationStressTest() throws Exception {
    KeyManager[] keyManagers = getKeyManagers();
    // Test the default codepath, which uses /dev/urandom.
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyManagers, null, null);
    for (int i = 0; i < 2048; ++i) {
        sslContext.getServerSocketFactory().createServerSocket().close();
    }
    // Test the other codepath, which copies a seed from a byte[].
    sslContext.init(keyManagers, null, new SecureRandom());
    for (int i = 0; i < 2048; ++i) {
        sslContext.getServerSocketFactory().createServerSocket().close();
    }
}
Also used : SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) KeyManager(javax.net.ssl.KeyManager)

Example 13 with KeyManager

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

the class SSLParametersImpl method createDefaultKeyManager.

private static X509KeyManager createDefaultKeyManager() throws KeyManagementException {
    try {
        String algorithm = KeyManagerFactory.getDefaultAlgorithm();
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
        kmf.init(null, null);
        KeyManager[] kms = kmf.getKeyManagers();
        return findX509KeyManager(kms);
    } catch (NoSuchAlgorithmException e) {
        throw new KeyManagementException(e);
    } catch (KeyStoreException e) {
        throw new KeyManagementException(e);
    } catch (UnrecoverableKeyException e) {
        throw new KeyManagementException(e);
    }
}
Also used : UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager) KeyManagementException(java.security.KeyManagementException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 14 with KeyManager

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

the class KeyManagerFactoryTest method test_KeyManagerFactory_getKeyManagers.

private void test_KeyManagerFactory_getKeyManagers(KeyManagerFactory kmf, boolean empty) throws Exception {
    KeyManager[] keyManagers = kmf.getKeyManagers();
    assertNotNull(keyManagers);
    assertTrue(keyManagers.length > 0);
    for (KeyManager keyManager : keyManagers) {
        assertNotNull(keyManager);
        if (keyManager instanceof X509KeyManager) {
            test_X509KeyManager((X509KeyManager) keyManager, empty, kmf.getAlgorithm());
        }
    }
}
Also used : X509KeyManager(javax.net.ssl.X509KeyManager) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager) X509ExtendedKeyManager(javax.net.ssl.X509ExtendedKeyManager)

Example 15 with KeyManager

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

the class HttpsURLConnectionTest method getContext.

/**
     * Builds and returns the context used for secure socket creation.
     */
private static SSLContext getContext() throws Exception {
    String type = KeyStore.getDefaultType();
    String keyStore = getKeyStoreFileName();
    File keyStoreFile = new File(keyStore);
    FileInputStream fis = new FileInputStream(keyStoreFile);
    KeyStore ks = KeyStore.getInstance(type);
    ks.load(fis, KS_PASSWORD.toCharArray());
    fis.close();
    if (DO_LOG && false) {
        TestKeyStore.dump("HttpsURLConnection.getContext", ks, KS_PASSWORD.toCharArray());
    }
    String kmfAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(kmfAlgorithm);
    kmf.init(ks, KS_PASSWORD.toCharArray());
    KeyManager[] keyManagers = kmf.getKeyManagers();
    String tmfAlgorthm = TrustManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorthm);
    tmf.init(ks);
    TrustManager[] trustManagers = tmf.getTrustManagers();
    if (DO_LOG) {
        trustManagers = TestTrustManager.wrap(trustManagers);
    }
    SSLContext ctx = SSLContext.getInstance("TLSv1");
    ctx.init(keyManagers, trustManagers, null);
    return ctx;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLContext(javax.net.ssl.SSLContext) File(java.io.File) TestKeyStore(libcore.java.security.TestKeyStore) KeyStore(java.security.KeyStore) KeyManager(javax.net.ssl.KeyManager) FileInputStream(java.io.FileInputStream) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) TrustManager(javax.net.ssl.TrustManager) TestTrustManager(libcore.javax.net.ssl.TestTrustManager)

Aggregations

KeyManager (javax.net.ssl.KeyManager)210 SSLContext (javax.net.ssl.SSLContext)127 TrustManager (javax.net.ssl.TrustManager)127 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)103 KeyStore (java.security.KeyStore)95 IOException (java.io.IOException)59 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)59 SecureRandom (java.security.SecureRandom)54 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)54 KeyManagementException (java.security.KeyManagementException)46 X509TrustManager (javax.net.ssl.X509TrustManager)45 KeyStoreException (java.security.KeyStoreException)42 X509KeyManager (javax.net.ssl.X509KeyManager)40 InputStream (java.io.InputStream)33 UnrecoverableKeyException (java.security.UnrecoverableKeyException)32 FileInputStream (java.io.FileInputStream)31 CertificateException (java.security.cert.CertificateException)30 GeneralSecurityException (java.security.GeneralSecurityException)24 X509Certificate (java.security.cert.X509Certificate)23 File (java.io.File)15