Package com.sun.net.ssl

Examples of com.sun.net.ssl.KeyManagerFactory


         }
         catch (IOException x)
         {
         }

         KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(m_keyManagerAlgorithm);
         // Use the keystore password as default if not given
         keyFactory.init(keystore, m_keyManagerPassword == null ? m_keyStorePassword.toCharArray() : m_keyManagerPassword.toCharArray());

         TrustManagerFactory trustFactory = null;
         if (m_trustStoreName != null)
         {
            // User specified a trust store, retrieve it

            if (m_trustStorePassword == null)
            {
               throw new IOException("TrustStore password cannot be null");
            }

            KeyStore trustStore = KeyStore.getInstance(m_trustStoreType);
            InputStream trustStoreStream = getClass().getClassLoader().getResourceAsStream(m_trustStoreName);
            // Check for nullity
            if (trustStoreStream == null)
            {
               throw new IOException("Cannot find TrustStore " + m_trustStoreName);
            }
            trustStore.load(trustStoreStream, m_trustStorePassword.toCharArray());

            trustFactory = TrustManagerFactory.getInstance(m_trustManagerAlgorithm);
            trustFactory.init(trustStore);
         }

         SSLContext context = SSLContext.getInstance(m_sslProtocol);
         // Below call does not handle TrustManagers, needed when server must authenticate clients.
         context.init(keyFactory.getKeyManagers(), trustFactory == null ? null : trustFactory.getTrustManagers(), null);

         SSLServerSocketFactory ssf = context.getServerSocketFactory();
         SSLServerSocket serverSocket = (SSLServerSocket)ssf.createServerSocket(port, backlog, InetAddress.getByName(host));

         return serverSocket;
View Full Code Here


                is = url.openStream();
                keystore.load(is, "nopassword".toCharArray());
            } finally {
                if (is != null) is.close();
            }
            KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
                    KeyManagerFactory.getDefaultAlgorithm());
            kmfactory.init(keystore, "nopassword".toCharArray());
            KeyManager[] keymanagers = kmfactory.getKeyManagers();
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(keymanagers, null, null);
            return sslcontext;
        } catch (Exception ex) {
            // this is not the way a sane exception handling should be done
View Full Code Here

    {
        SecurityTool.setup();
   
        SSLContext context = SSLContext.getInstance(SecurityTool.getSecurityProtocol());
         
        KeyManagerFactory keyManagerFactory =
            KeyManagerFactory.getInstance(SecurityTool.getKeyManagerType());
           
        KeyStore keyStore = KeyStore.getInstance(SecurityTool.getKeyStoreType());
           
        keyStore.load(new FileInputStream(SecurityTool.getKeyStore()),
            SecurityTool.getKeyStorePassword().toCharArray());
           
        keyManagerFactory.init(keyStore, SecurityTool.getKeyStorePassword().toCharArray());
           
        context.init(keyManagerFactory.getKeyManagers(), null, null);
        SSLServerSocketFactory sslSrvFact = context.getServerSocketFactory();
        return (SSLServerSocket) sslSrvFact.createServerSocket(port);
    }
View Full Code Here

            {
                log.error("Exception occurred",ee);
            }
            try
            {
                KeyManagerFactory managerFactory =
                    KeyManagerFactory.getInstance("SunX509");
                JmeterKeyStore keys = this.getKeyStore();
                managerFactory.init(null, this.defaultpw.toCharArray());
                KeyManager[] managers = managerFactory.getKeyManagers();
                log.info(keys.getClass().toString());
                for (int i = 0; i < managers.length; i++)
                {
                    if (managers[i] instanceof X509KeyManager)
                    {
View Full Code Here

                is = url.openStream();
                keystore.load(is, "nopassword".toCharArray());
            } finally {
                if (is != null) is.close();
            }
            KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
                    KeyManagerFactory.getDefaultAlgorithm());
            kmfactory.init(keystore, "nopassword".toCharArray());
            KeyManager[] keymanagers = kmfactory.getKeyManagers();
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(keymanagers, null, null);
            return sslcontext;
        } catch (Exception ex) {
            // this is not the way a sane exception handling should be done
View Full Code Here

    {
        SecurityTool.setup();
   
        SSLContext context = SSLContext.getInstance(SecurityTool.getSecurityProtocol());
         
        KeyManagerFactory keyManagerFactory =
            KeyManagerFactory.getInstance(SecurityTool.getKeyManagerType());
           
        KeyStore keyStore = KeyStore.getInstance(SecurityTool.getKeyStoreType());
           
        keyStore.load(new FileInputStream(SecurityTool.getKeyStore()),
            SecurityTool.getKeyStorePassword().toCharArray());
           
        keyManagerFactory.init(keyStore, SecurityTool.getKeyStorePassword().toCharArray());
           
        context.init(keyManagerFactory.getKeyManagers(), null, null);
        SSLServerSocketFactory sslSrvFact = context.getServerSocketFactory();
        return (SSLServerSocket) sslSrvFact.createServerSocket(port);
    }
View Full Code Here

        try {
            ClassLoader cl = SimpleSocketFactory.class.getClassLoader();
            URL url = cl.getResource("org/apache/commons/httpclient/ssl/simpleserver.keystore");
            KeyStore keystore  = KeyStore.getInstance("jks");
            keystore.load(url.openStream(), "nopassword".toCharArray());
            KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
                    KeyManagerFactory.getDefaultAlgorithm());
            kmfactory.init(keystore, "nopassword".toCharArray());
            KeyManager[] keymanagers = kmfactory.getKeyManagers();
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(keymanagers, null, null);
            return sslcontext;
        } catch (Exception ex) {
            // this is not the way a sane exception handling should be done
View Full Code Here

            // Create an SSL context used to create an SSL socket factory
            SSLContext context = SSLContext.getInstance(protocol);

            // Create the key manager factory used to extract the server key
            KeyManagerFactory keyManagerFactory =
                KeyManagerFactory.getInstance(algorithm);
            keyManagerFactory.init(keyStore, keystorePass.toCharArray());

            // Create the trust manager factory used for checking certificates
            /*
              trustManagerFactory = TrustManagerFactory.getInstance(algorithm);
              trustManagerFactory.init(keyStore);
            */

            // Initialize the context with the key managers
            context.init(keyManagerFactory.getKeyManagers(), null,
                         new java.security.SecureRandom());

            // Create the proxy and return
            sslProxy = context.getServerSocketFactory();

View Full Code Here

              is = url.openStream();
              keystore.load(is, "nopassword".toCharArray());
            } finally {
              if (is != null) is.close();
            }
            KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
                    KeyManagerFactory.getDefaultAlgorithm());
            kmfactory.init(keystore, "nopassword".toCharArray());
            KeyManager[] keymanagers = kmfactory.getKeyManagers();
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(keymanagers, null, null);
            return sslcontext;
        } catch (Exception ex) {
          // this is not the way a sane exception handling should be done
View Full Code Here

    {
        if (keystore == null) {
            throw new IllegalArgumentException("Keystore may not be null");
        }
        LOG.debug("Initializing key manager");
        KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
            KeyManagerFactory.getDefaultAlgorithm());
        kmfactory.init(keystore, password != null ? password.toCharArray(): null);
        return kmfactory.getKeyManagers();
    }
View Full Code Here

TOP

Related Classes of com.sun.net.ssl.KeyManagerFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.