Package javax.net.ssl

Examples of javax.net.ssl.KeyManagerFactory


    }

    final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(algorithm);
    trustManagerFactory.init((KeyStore) null);

    final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
    keyManagerFactory.init(keyStore, keyStorePassword);

    final SSLContext sslContext = SSLContext.getInstance(PROTOCOL);
    sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);

    return sslContext;
  }
View Full Code Here


            return null;
        }

        char[] pass = (StringUtils.hasText(keyStorePass) ? keyStorePass.trim().toCharArray() : null);
    KeyStore keyStore = loadKeyStore(keyStoreLocation, pass);
        KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmFactory.init(keyStore, pass);
        return kmFactory.getKeyManagers();
    }
View Full Code Here

      {
         return null;
      }
      else
      {
         KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
         KeyStore ks = SSLSupport.loadKeystore(keystorePath, keystorePassword);
         kmf.init(ks, keystorePassword.toCharArray());

         return kmf.getKeyManagers();
      }
   }
View Full Code Here

   
    public static SSLContext newSSLContext(final KeyStore ks, final String password,
            final String ksAlgorithm) throws InvalidSSLConfig {
           try {
               // Get a KeyManager and initialize it
               final KeyManagerFactory kmf = KeyManagerFactory.getInstance(ksAlgorithm);
               kmf.init(ks, password.toCharArray());

               // Get a TrustManagerFactory with the DEFAULT KEYSTORE, so we have all
               // the certificates in cacerts trusted
               final TrustManagerFactory tmf = TrustManagerFactory.getInstance(ksAlgorithm);
               tmf.init((KeyStore)null);

               // Get the SSLContext to help create SSLSocketFactory
               final SSLContext sslContext = SSLContext.getInstance("TLS");
               sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
               return sslContext;
           } catch (final GeneralSecurityException e) {
               throw new InvalidSSLConfig(e);
           }
       }
View Full Code Here

  }

  private static void createSSLContext() throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException {
    if(enable) {
      // A KeyManagerFactory is used to create key managers
      KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
      // Initialize the KeyManagerFactory to work with our keystore
      kmf.init(keystore, keyPass.toCharArray());
      // An SSLContext is an environment for implementing JSSE
      // It is used to create a ServerSocketFactory
      SSLContext sslc = SSLContext.getInstance("TLSv1");
      // Initialize the SSLContext to work with our key managers
      // FIXME: should we pass yarrow in here?
      sslc.init(kmf.getKeyManagers(), null, null);
      ssf = sslc.getServerSocketFactory();
    }
  }
View Full Code Here

        setKeystore(serverKeystore, pw);
    }
   
    public synchronized void setKeystore(KeyStore serverKeystore, char[] pw) throws SecurityException {
        try {
            KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
            kmf.init(serverKeystore, pw);
            keyManager = (X509KeyManager)kmf.getKeyManagers()[0];
        } catch (Exception ex) {
            throw new SecurityException("Cannnot create keymanager", ex);
        }       
    }
View Full Code Here

        if (_keystore!=null)
            keystoreInputStream=Resource.newResource(_keystore).getInputStream();
        KeyStore keyStore=KeyStore.getInstance(_keystoreType);
        keyStore.load(keystoreInputStream,_password==null?null:_password.toString().toCharArray());

        KeyManagerFactory keyManagerFactory=KeyManagerFactory.getInstance(_sslKeyManagerFactoryAlgorithm);
        keyManagerFactory.init(keyStore,_keyPassword==null?null:_keyPassword.toString().toCharArray());
        keyManagers=keyManagerFactory.getKeyManagers();


        TrustManager[] trustManagers=null;
        InputStream truststoreInputStream = null;
        if (_truststore!=null)
View Full Code Here

            keystoreInputStream= Resource.newResource(_keyStoreLocation).getInputStream();
            KeyStore keyStore=KeyStore.getInstance(_keyStoreType);
            keyStore.load(keystoreInputStream,_keyStorePassword==null?null:_keyStorePassword.toString().toCharArray());

            KeyManagerFactory keyManagerFactory=KeyManagerFactory.getInstance(_keyManagerAlgorithm);
            keyManagerFactory.init(keyStore,_keyManagerPassword==null?null:_keyManagerPassword.toString().toCharArray());
            keyManagers=keyManagerFactory.getKeyManagers();

            TrustManager[] trustManagers=null;
            InputStream truststoreInputStream = null;

                truststoreInputStream = Resource.newResource(_trustStoreLocation).getInputStream();
View Full Code Here

                }
            }
        }

        // Set up key manager factory to use our key store
        KeyManagerFactory kmf = KeyManagerFactory
                .getInstance(KEY_MANAGER_FACTORY_ALGORITHM);
        kmf.init(ks, BOGUS_PW);

        // Initialize the SSLContext to work with our key managers.
        SSLContext sslContext = SSLContext.getInstance(PROTOCOL);
        sslContext.init(kmf.getKeyManagers(),
                BogusTrustManagerFactory.X509_MANAGERS, null);

        return sslContext;
    }
View Full Code Here

            final TrustStrategy trustStrategy)
                throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
        if (algorithm == null) {
            algorithm = TLS;
        }
        KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
                KeyManagerFactory.getDefaultAlgorithm());
        kmfactory.init(keystore, keystorePassword != null ? keystorePassword.toCharArray(): null);
        KeyManager[] keymanagers =  kmfactory.getKeyManagers();
        TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
                TrustManagerFactory.getDefaultAlgorithm());
        tmfactory.init(truststore);
        TrustManager[] trustmanagers = tmfactory.getTrustManagers();
        if (trustmanagers != null && trustStrategy != null) {
View Full Code Here

TOP

Related Classes of javax.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.