Package javax.net.ssl

Examples of javax.net.ssl.KeyManagerFactory


        FileInputStream fis = new FileInputStream(
                "src/test/resources/keymanager-test.jks");
        ks.load(fis, "".toCharArray());

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, "".toCharArray());

        km = kmf.getKeyManagers()[0];
    }
View Full Code Here


            LogUtils.log(LOG, Level.WARNING, "KEY_PASSWORD_NOT_SAME_KEYSTORE_PASSWORD");
        }
        try {
            SSLContext sslctx = SSLContext.getInstance(secureSocketProtocol);

            KeyManagerFactory kmf =
                KeyManagerFactory.getInstance(keystoreKeyManagerFactoryAlgorithm)
            KeyStore ks = KeyStore.getInstance(keyStoreType);
            FileInputStream fis = new FileInputStream(keyStoreLocation);
            DataInputStream dis = new DataInputStream(fis);
            byte[] bytes = new byte[dis.available()];
            dis.readFully(bytes);
            ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
           
            KeyManager[] keystoreManagers = null;
            if (keyStorePassword != null) {
                try {
                    ks.load(bin, keyStorePassword.toCharArray());
                    kmf.init(ks, keyStorePassword.toCharArray());
                    keystoreManagers = kmf.getKeyManagers();
                    LogUtils.log(LOG, Level.INFO, "LOADED_KEYSTORE", new Object[]{keyStoreLocation});
                } catch (Exception e) {
                    LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE",
                                 new Object[]{keyStoreLocation, e.getMessage()});
               
View Full Code Here

        if ((keyStorePassword != null) && (keyPassword != null) && (!keyStorePassword.equals(keyPassword))) {
            LogUtils.log(LOG, Level.WARNING, "KEY_PASSWORD_NOT_SAME_KEYSTORE_PASSWORD");
        }
        try {
            SSLContext sslctx = SSLContext.getInstance(secureSocketProtocol);
            KeyManagerFactory kmf =
                KeyManagerFactory.getInstance(keystoreKeyManagerFactoryAlgorithm)
            KeyStore ks = KeyStore.getInstance(keyStoreType);
            KeyManager[] keystoreManagers = null;
           
           
            byte[] sslCert = loadClientCredential(keyStoreLocation);
           
            if (sslCert != null && sslCert.length > 0 && keyStorePassword != null) {
                ByteArrayInputStream bin = new ByteArrayInputStream(sslCert);
                try {
                    ks.load(bin, keyStorePassword.toCharArray());
                    kmf.init(ks, keyStorePassword.toCharArray());
                    keystoreManagers = kmf.getKeyManagers();
                    LogUtils.log(LOG, Level.INFO, "LOADED_KEYSTORE", new Object[]{keyStoreLocation});
                } catch (Exception e) {
                    LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE",
                                                     new Object[]{keyStoreLocation, e.getMessage()});
                }
View Full Code Here

     
      char[] passphrase = PASSWORD.toCharArray();
      KeyStore ks = KeyStore.getInstance("JKS");
      ks.load(new FileInputStream(filename), passphrase);
 
      KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
      kmf.init(ks, passphrase);
     
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
      tmf.init(ks);
 
      SSLContext sslContext = SSLContext.getInstance("TLS");
      sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

      return sslContext;

    } catch (Exception e) {
      return null;
View Full Code Here

     */
    public SSLContext getSSLContext(String keyStoreName, String password)
            throws IOException {
        try {
            // Check the key manager factory
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(this.keyManagerType);
           
            File ksFile = new File(keyStoreName);
            if (!ksFile.exists() || !ksFile.isFile())
                throw new WinstoneException(SSL_RESOURCES.getString(
                        "HttpsListener.KeyStoreNotFound", ksFile.getPath()));
            InputStream in = new FileInputStream(ksFile);
            char[] passwordChars = password == null ? null : password.toCharArray();
            KeyStore ks = KeyStore.getInstance("JKS");
            ks.load(in, passwordChars);
            kmf.init(ks, passwordChars);
            Logger.log(Logger.FULL_DEBUG, SSL_RESOURCES,
                    "HttpsListener.KeyCount", ks.size() + "");
            for (Enumeration e = ks.aliases(); e.hasMoreElements();) {
                String alias = (String) e.nextElement();
                Logger.log(Logger.FULL_DEBUG, SSL_RESOURCES,
                        "HttpsListener.KeyFound", new String[] { alias,
                                ks.getCertificate(alias) + "" });
            }

            SSLContext context = SSLContext.getInstance("SSL");
            context.init(kmf.getKeyManagers(), null, null);
            Arrays.fill(passwordChars, 'x');
            return context;
        } catch (IOException err) {
            throw err;
        } catch (Throwable err) {
View Full Code Here

   {
      SSLContext sslCtx = null;
      try
      {
         sslCtx = SSLContext.getInstance("TLS");
         KeyManagerFactory keyMgr = securityDomain.getKeyManagerFactory();
         if( keyMgr == null )
            throw new IOException("KeyManagerFactory is null for security domain: "+securityDomain.getSecurityDomain());
         TrustManagerFactory trustMgr = securityDomain.getTrustManagerFactory();
         TrustManager[] trustMgrs = null;
         if( trustMgr != null )
            trustMgrs = trustMgr.getTrustManagers();
         sslCtx.init(keyMgr.getKeyManagers(), trustMgrs, null);
         return sslCtx;
      }
      catch(NoSuchAlgorithmException e)
      {
         log.error("Failed to get SSLContext for TLS algorithm", e);
View Full Code Here

         log.debug("Opening KeyStore: "+keyStoreURL);
         KeyStore keyStore = KeyStore.getInstance("JKS");
         InputStream is = keyStoreURL.openStream();
         keyStore.load(is, KEYSTORE_PASSWORD.toCharArray());
         String algorithm = KeyManagerFactory.getDefaultAlgorithm();
         KeyManagerFactory keyMgr = KeyManagerFactory.getInstance(algorithm);
         keyMgr.init(keyStore, KEYSTORE_PASSWORD.toCharArray());
         algorithm = TrustManagerFactory.getDefaultAlgorithm();
         TrustManagerFactory trustMgr = TrustManagerFactory.getInstance(algorithm);
         trustMgr.init(keyStore);
         TrustManager[] trustMgrs = trustMgr.getTrustManagers();
         sslCtx.init(keyMgr.getKeyManagers(), trustMgrs, null);
      }
      catch(Exception e)
      {
         log.error("Failed to init SSLContext", e);
         throw new IOException("Failed to get SSLContext for TLS algorithm");
View Full Code Here

        try {
            KeyStoreManager km = KeyStoreManager.getInstance(KeyStoreManager.SERVER_AUTHENTICATION_CERTIFICATES_KEY_STORE);
            if (!km.isKeyStoreEmpty()) {
                KeyStore keyStore = km.getKeyStore();
                // Get a key manager factory out of the key store
                KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
                keyManagerFactory.init(keyStore, KeyStoreManager.getInstance(KeyStoreManager.SERVER_AUTHENTICATION_CERTIFICATES_KEY_STORE).getKeyStorePassword().toCharArray());
                retVal = keyManagerFactory.getKeyManagers();
            } else
                return null;
        } catch (NoSuchAlgorithmException e) {
            log.fatal("Error getting algorithm.", e);
        } catch (CertificateException e) {
View Full Code Here

     
      char[] passphrase = PASSWORD.toCharArray();
      KeyStore ks = KeyStore.getInstance("JKS");
      ks.load(new FileInputStream(filename), passphrase);
 
      KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
      kmf.init(ks, passphrase);
     
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
      tmf.init(ks);
 
      SSLContext sslContext = SSLContext.getInstance("TLS");
      sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

      return sslContext;

    } catch (Exception e) {
      return null;
View Full Code Here

     
      char[] passphrase = PASSWORD.toCharArray();
      KeyStore ks = KeyStore.getInstance("JKS");
      ks.load(new FileInputStream(filename), passphrase);
 
      KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
      kmf.init(ks, passphrase);
     
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
      tmf.init(ks);
 
      SSLContext sslContext = SSLContext.getInstance("TLS");
      sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

      return sslContext;

    } catch (Exception e) {
      return 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.