Examples of SSLContext


Examples of javax.net.ssl.SSLContext

        }
       
        // create new SSLServerSocketFactory!!!
        boolean isDefaultConfig = DEFAULT_SERVICE_PID.equals(m_config.get("service.pid"));
        // Step 1: context
        SSLContext context = null;
        try
        {
            context = SSLContext.getInstance(ConstsIf.PROT_TLS_V1);
       
        } catch (NoSuchAlgorithmException e)
        {
            throw new ConfigurationException(
                        "",
                        "creating SSLContext: ERROR no such algorithm");
        }

       
        //Step 2: obtain a key store instance, type is fixed
        KeyStore myKeys;
        try
        {
            myKeys = KeyStore.getInstance(ConstsIf.KS_TYPE_JKS);

        } catch (KeyStoreException e1)
        {
            throw new ConfigurationException(
                        "",
                        "creating SSLContext: ERROR no such algorithm");
        }

       
        InputStream is = null;
        char[] keyPassPhrase = null;

        if (!isDefaultConfig)
        {
            //Step 3:obtain password phrase for a keystore
            try
            {
                keyPassPhrase = ((String) m_config.get(KEYSTOREPASS_KEY)).toCharArray();
           
            } catch (Exception epass) {}
   
            //Step 4:obtain input stream for a key store
            // - if the config admin set it to type byte[], assume it is a keystore itself
            // - else if it is of type string try to interpret this string as an (absolute) path
            //   to a file
            // - else assume that this is a incomplete configruation we got from the CM Admin,
            //   use the default keystore
   
            // from CM as byte[] ?
            if ((keyPassPhrase != null) && (is == null))
            {       
                try
                {
                    is = new ByteArrayInputStream((byte[]) m_config.get(KEYSTORE_KEY));
       
                } catch (Exception eb) {}
            }       
   
            //from CM as a file pointer ?
            if ((keyPassPhrase != null) && (is == null))
            {       
                try
                {
                    is = new FileInputStream((String) m_config.get(KEYSTORE_KEY));
               
                } catch (Exception ef) {}
            }
       
            if ((is == null) &&  m_log.doWarn())
            {
                m_log.warn("using default, config is invalid: " + m_config.get("service.pid"));
            }
        }
       
        // Step 3 & 4 executed now if config is bad or we just use the default config
        if (is == null)
        {      
            try
            {
                keyPassPhrase = DEFAULT_PASSPHR_VALUE.toCharArray();
                is = getClass().getResourceAsStream(DEFAULT_KEYSTORE_VALUE);
           
            } catch (Exception edef)
            {
            }
        }
       
        // Step 5: load keys into keystore
        try
        {
            myKeys.load(is, keyPassPhrase);
           
        } catch (Exception eload)
        {
            throw new ConfigurationException(
                            KEYSTORE_KEY + "," + KEYSTOREPASS_KEY,
                            "ERROR loading keys !, passphrase " + String.valueOf(keyPassPhrase));
        }
       
        //Step 6: create and initialize KeyManagerFactory
        KeyManagerFactory kmf;
        try
        {
            kmf = KeyManagerFactory.getInstance(ConstsIf.KM_TYPE_SUN);

        } catch (NoSuchAlgorithmException e4)
        {
            throw new ConfigurationException(
                        "",
                        "creating KeyManagerFactory: ERROR no such algorithm");
        }
        try
        {
            kmf.init(myKeys, keyPassPhrase);

        } catch (Exception e5)
        {
            throw new ConfigurationException(
                        "",
                        "initing kmf: " + e5.getMessage());
        }
       
        //Step 7: initialize context with the key manager factory
        try
        {
            context.init(kmf.getKeyManagers(), null, null);

        } catch (KeyManagementException e6)
        {
            throw new ConfigurationException(
                        "",
                        "initing SSLContext: " + e6.getMessage());
        }
   
        //Step 8: create SSL Server Socket Factory
        SSLServerSocketFactory ssl = null;
        try
        {
      ssl = context.getServerSocketFactory();
   
        } catch (Exception e7)
        {
            throw new ConfigurationException(
                    "",
View Full Code Here

Examples of javax.net.ssl.SSLContext

                }
            }
        };
    
        // Install the all-trusting trust manager
        SSLContext sc = SSLContext.getInstance("SSL");
        // Create empty HostnameVerifier
        HostnameVerifier hv = new HostnameVerifier() {
                    public boolean verify(String arg0, SSLSession arg1) {
                            return true;
                    }
        };
 
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(hv);
     
      XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
     
      log.debug("config User Agent "+config.getUserAgent());
View Full Code Here

Examples of javax.net.ssl.SSLContext

                }
            }
        };
    
        // Install the all-trusting trust manager
        SSLContext sc = SSLContext.getInstance("SSL");
        // Create empty HostnameVerifier
        HostnameVerifier hv = new HostnameVerifier() {
                    public boolean verify(String arg0, SSLSession arg1) {
                            return true;
                    }
        };
 
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(hv);
     
      XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
     
      log.debug("config User Agent "+config.getUserAgent());
View Full Code Here

Examples of javax.net.ssl.SSLContext

    trustManagers = trustManagerFactory.getTrustManagers();

    SecureRandom secureRandom = _secureRandomAlgorithm == null ? null : SecureRandom
        .getInstance(_secureRandomAlgorithm);

    SSLContext context = _provider == null ? SSLContext.getInstance(SipConnectors.TLS) : SSLContext
        .getInstance(SipConnectors.TLS, _provider);

    context.init(keyManagers, trustManagers, secureRandom);

    return context.getServerSocketFactory();
  }
View Full Code Here

Examples of org.apache.activemq.broker.SslContext

     * @return Newly created (Ssl)ServerSocketFactory.
     * @throws IOException
     */
    protected ServerSocketFactory createServerSocketFactory() throws IOException {
        if( SslContext.getCurrentSslContext()!=null ) {
            SslContext ctx = SslContext.getCurrentSslContext();
            try {
                return ctx.getSSLContext().getServerSocketFactory();
            } catch (Exception e) {
                throw IOExceptionSupport.create(e);
            }
        } else {
            return SSLServerSocketFactory.getDefault();
View Full Code Here

Examples of org.jboss.netty.handler.ssl.SslContext

                return pipeline;
            }

            private SslHandler buildSslHandler() throws CertificateException, SSLException {
                final SslContext sslCtx = SslContext.newServerContext(
                        tlsCertFile, tlsKeyFile, emptyToNull(configuration.getRestTlsKeyPassword()));

                return sslCtx.newHandler();
            }
        });
        bootstrap.setOption("child.tcpNoDelay", true);
        bootstrap.setOption("child.keepAlive", true);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.