Example usage for javax.net.ssl KeyManagerFactory getAlgorithm

List of usage examples for javax.net.ssl KeyManagerFactory getAlgorithm

Introduction

In this page you can find the example usage for javax.net.ssl KeyManagerFactory getAlgorithm.

Prototype

public final String getAlgorithm() 

Source Link

Document

Returns the algorithm name of this KeyManagerFactory object.

Usage

From source file:android.core.SSLSocketTest.java

/**
 * Regression test for 963650: javax.net.ssl.KeyManager has no implemented
 * (documented?) algorithms./*from w  w w .  ja  v a 2s .c  o  m*/
 */
public void testDefaultAlgorithms() throws Exception {
    SSLContext ctx = SSLContext.getInstance("TLS");
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
    KeyStore ks = KeyStore.getInstance("BKS");

    assertEquals("X509", kmf.getAlgorithm());
    assertEquals("X509", KeyManagerFactory.getDefaultAlgorithm());

    assertEquals("BKS", ks.getType());
    assertEquals("BKS", KeyStore.getDefaultType());
}

From source file:net.timewalker.ffmq4.listeners.tcp.io.TcpListener.java

private SSLContext createSSLContext() throws JMSException {
    try {//from  w  w w. j  av  a  2  s  .co m
        String sslProtocol = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_PROTOCOL, "SSLv3");
        String keyManagerAlgorithm = settings
                .getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYMANAGER_ALGORITHM, "SunX509");
        String keyStoreType = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYSTORE_TYPE,
                "JKS");
        String keyStorePath = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYSTORE_PATH,
                "../conf/server-keystore.jks");
        String keyStorePass = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYSTORE_PASWORD,
                "ffmqpass");
        String keyPass = settings.getStringProperty(FFMQCoreSettings.TRANSPORT_TCP_SSL_KEYSTORE_KEY_PASSWORD,
                "ffmqpass");

        SSLContext sslContext = SSLContext.getInstance(sslProtocol);
        log.debug("Created an SSL context : protocol=[" + sslContext.getProtocol() + "] provider=["
                + sslContext.getProvider() + "]");

        // Load available keys
        KeyManager[] keyManagers;
        File keyStoreFile = new File(keyStorePath);
        if (!keyStoreFile.canRead())
            throw new FFMQException("Cannot read keystore file : " + keyStoreFile.getAbsolutePath(),
                    "FS_ERROR");

        KeyStore ks = KeyStore.getInstance(keyStoreType);
        log.debug("Created keystore : type=[" + ks.getType() + "] provider=[" + ks.getProvider() + "]");
        char ksPass[] = keyStorePass.toCharArray();
        char ctPass[] = keyPass.toCharArray();
        log.debug("Loading keystore from " + keyStoreFile.getAbsolutePath());
        InputStream kis = new FileInputStream(keyStoreFile);
        ks.load(kis, ksPass);
        kis.close();

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(keyManagerAlgorithm);
        log.debug("Created KeyManagerFactory : algorithm=[" + kmf.getAlgorithm() + "] provider=["
                + kmf.getProvider() + "]");
        log.debug("Initializing KeyManagerFactory with keystore ...");
        kmf.init(ks, ctPass);

        keyManagers = kmf.getKeyManagers();

        sslContext.init(keyManagers, null, null);

        return sslContext;
    } catch (JMSException e) {
        throw e;
    } catch (Exception e) {
        throw new FFMQException("Cannot create SSL context", "NETWORK_ERROR", e);
    }
}

From source file:test.integ.be.fedict.commons.eid.client.SSLTest.java

@Test
public void testKeyManagerFactory() throws Exception {
    Security.addProvider(new BeIDProvider());
    final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("BeID");
    assertNotNull(keyManagerFactory);//from w w  w  .j a va 2 s  .  com

    final String algo = keyManagerFactory.getAlgorithm();
    LOG.debug("key manager factory algo: " + algo);
    assertEquals("BeID", algo);

    final KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
    assertNotNull(keyManagers);
}