Package javax.net.ssl

Examples of javax.net.ssl.KeyManagerFactory


        KeyStore ks = getKeystore(keystoreType, keystoreProvider, keystorePass);
        if (keyAlias != null && !ks.isKeyEntry(keyAlias)) {
            throw new IOException(sm.getString("jsse.alias_no_key_entry", keyAlias));
        }

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
        kmf.init(ks, keystorePass.toCharArray());

        kms = kmf.getKeyManagers();
        if (keyAlias != null) {
            if (JSSESocketFactory.defaultKeystoreType.equals(keystoreType)) {
                keyAlias = keyAlias.toLowerCase();
            }
            for(int i=0; i<kms.length; i++) {
View Full Code Here


    private int clientSessionTimeout = -1;
    private int serverSessionCacheSize = -1;
    private int serverSessionTimeout = -1;

    public SSLContext newInstance() throws Exception {
        KeyManagerFactory kmf = this.keyManagerFactory;
        TrustManagerFactory tmf = this.trustManagerFactory;

        if (kmf == null) {
            String algorithm = keyManagerFactoryAlgorithm;
            if (algorithm == null && keyManagerFactoryAlgorithmUseDefault) {
                algorithm = KeyManagerFactory.getDefaultAlgorithm();
            }
            if (algorithm != null) {
                if (keyManagerFactoryProvider == null) {
                    kmf = KeyManagerFactory.getInstance(algorithm);
                } else {
                    kmf = KeyManagerFactory.getInstance(algorithm,
                            keyManagerFactoryProvider);
                }
            }
        }

        if (tmf == null) {
            String algorithm = trustManagerFactoryAlgorithm;
            if (algorithm == null && trustManagerFactoryAlgorithmUseDefault) {
                algorithm = TrustManagerFactory.getDefaultAlgorithm();
            }
            if (algorithm != null) {
                if (trustManagerFactoryProvider == null) {
                    tmf = TrustManagerFactory.getInstance(algorithm);
                } else {
                    tmf = TrustManagerFactory.getInstance(algorithm,
                            trustManagerFactoryProvider);
                }
            }
        }

        KeyManager[] keyManagers = null;
        if (kmf != null) {
            kmf.init(keyManagerFactoryKeyStore,
                    keyManagerFactoryKeyStorePassword);
            keyManagers = kmf.getKeyManagers();
        }
        TrustManager[] trustManagers = null;
        if (tmf != null) {
            if (trustManagerFactoryParameters != null) {
                tmf.init(trustManagerFactoryParameters);
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)
          truststoreInputStream = Resource.newResource(_truststore).getInputStream();
View Full Code Here

        String trustManagerAlgorithm = properties.getProperty("trustManagerAlgorithm", TrustManagerFactory.getDefaultAlgorithm());
        String protocol = properties.getProperty("protocol", "TLS");

        KeyManager[] keyManagers = null;
        if (keyStore != null) {
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(keyManagerAlgorithm);
            char[] passPhrase = keyStorePassword != null ? keyStorePassword.toCharArray() : null;
            loadKeyStore(ks, passPhrase, keyStore);
            kmf.init(ks, passPhrase);
            keyManagers = kmf.getKeyManagers();
        }

        TrustManager[] trustManagers = null;
        if (trustStore != null) {
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(trustManagerAlgorithm);
View Full Code Here

  private static SSLContext createSSLContext(TSSLTransportParameters params) throws TTransportException {
    SSLContext ctx;
    try {
      ctx = SSLContext.getInstance(params.protocol);
      TrustManagerFactory tmf = null;
      KeyManagerFactory kmf = null;

      if (params.isTrustStoreSet) {
        tmf = TrustManagerFactory.getInstance(params.trustManagerType);
        KeyStore ts = KeyStore.getInstance(params.trustStoreType);
        ts.load(new FileInputStream(params.trustStore), params.trustPass.toCharArray());
        tmf.init(ts);
      }

      if (params.isKeyStoreSet) {
        kmf = KeyManagerFactory.getInstance(params.keyManagerType);
        KeyStore ks = KeyStore.getInstance(params.keyStoreType);
        ks.load(new FileInputStream(params.keyStore), params.keyPass.toCharArray());
        kmf.init(ks, params.keyPass.toCharArray());
      }

      if (params.isKeyStoreSet && params.isTrustStoreSet) {
        ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
      }
      else if (params.isKeyStoreSet) {
        ctx.init(kmf.getKeyManagers(), null, null);
      }
      else {
        ctx.init(null, tmf.getTrustManagers(), null);
      }
View Full Code Here

               // can not continue as supplied alias does not exist as key entry
               throw new IOException("Can not find key entry for key store (" + ksPathURL + ") with given alias (" + alias + ")");
            }
         }

         KeyManagerFactory keyMgrFactory = null;
         String alg = getKeyStoreAlgorithm();

         if(getProvider() != null)
         {
            keyMgrFactory = KeyManagerFactory.getInstance(alg, getProvider());
         }
         else if(getProviderName() != null)
         {
            keyMgrFactory = KeyManagerFactory.getInstance(alg, getProviderName());
         }
         else
         {
            keyMgrFactory = KeyManagerFactory.getInstance(alg);
         }

         // get they key password, if it isn't defined, use the key store password
         String keyPasswd = getKeyPassword();
         if (keyPasswd == null || keyPasswd.length() == 0)
         {
            keyPasswd = ksPasswd;
         }

         char[] keyPasswdCharArray = keyPasswd == null ? null : keyPasswd.toCharArray();
         keyMgrFactory.init(keyStore, keyPasswdCharArray);
         keyManagers = keyMgrFactory.getKeyManagers();

         // if alias provided, use helper impl to hard wire alias name to be used
         if(alias != null)
         {
            //TODO: -TME Need careful review of if this is really needed or not.
View Full Code Here

      stream = new FileInputStream(trustStorePath);
      server_truststore.load(stream, trustPassphrase);
      stream.close();
     
      // initialize a KeyManagerFactory with the KeyStore
      KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
      kmf.init(server_keystore, keyPassphrase);     
      // KeyManagers from the KeyManagerFactory
      KeyManager[] keyManagers = kmf.getKeyManagers();

      // initialize a TrustManagerFactory with the TrustStore
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
      tmf.init(server_truststore);
      // TrustManagers from the TrustManagerFactory
View Full Code Here

                try {
                    fis = new FileInputStream(keyStoreFile);
                    KeyStore theKeyStore = KeyStore.getInstance("JKS");
                    theKeyStore.load(fis, keyStorePassword);

                    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
                    keyManagerFactory.init(theKeyStore, keyStorePassword);
                    keyManagers = keyManagerFactory.getKeyManagers();
                } catch (IOException e) {
                    throw new CliInitializationException(e);
                } catch (GeneralSecurityException e) {
                    throw new CliInitializationException(e);
                } finally {
View Full Code Here

   protected KeyManager[] getKeyManagers(String keystoreType, String algorithm,
      String keyAlias)
      throws Exception
   {
      verifySecurityDomain();
      KeyManagerFactory kmf = securityDomain.getKeyManagerFactory();
      KeyManager[] keyMgrs = null;
      if( kmf != null )
      {
         keyMgrs = kmf.getKeyManagers();
         /* from tomcat JSSESocketFactory.java */
         if (keyAlias != null)
         {
            if ("JKS".equals(keystoreType))
            {
View Full Code Here

      stream = new FileInputStream(trustStorePath);
      server_truststore.load(stream, trustPassphrase);
      stream.close();
     
      // initialize a KeyManagerFactory with the KeyStore
      KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
      kmf.init(server_keystore, keyPassphrase);     
      // KeyManagers from the KeyManagerFactory
      KeyManager[] keyManagers = kmf.getKeyManagers();

      // initialize a TrustManagerFactory with the TrustStore
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
      tmf.init(server_truststore);
      // TrustManagers from the TrustManagerFactory
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.