Package javax.net.ssl

Examples of javax.net.ssl.SSLContext


 
  @Test
    public void testHttpClientSSL() throws Exception {
       
       
        SSLContext sslContext = SSLTestContextFactory.getSSLContext();
       
        IServer server = new HttpServer(0, new ContentEchoHandler(), sslContext, true);
        server.start();

       
View Full Code Here


 
  @Test
    public void testSSL() throws Exception {
     
     
      SSLContext sslContext = SSLTestContextFactory.getSSLContext();
     
        IServer server = new HttpServer(0, new ContentEchoHandler(), sslContext, true);
        server.start();

        INonBlockingConnection tcpCon = new NonBlockingConnection("localhost", server.getLocalPort(), sslContext, true);
View Full Code Here

 
  @Test
    public void testHttpClientSSL() throws Exception {
       
       
        SSLContext sslContext = SSLTestContextFactory.getSSLContext();
       
        IServer server = new HttpServer(0, new ContentEchoHandler(), sslContext, true);
        server.start();

       
View Full Code Here

    this.proxyPort = pproxyPort;
  }

  public SOSSSLSocketFactory() {

    SSLContext sslcontext = null;
    try {
      sslcontext = SSLContext.getInstance(securityProtocol);
    }
    catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
    if (sslcontext != null) {
      try {
        sslcontext.init(null, new TrustManager[] { new SOSTrustManager() }, new java.security.SecureRandom());
      }
      catch (KeyManagementException e) {
        e.printStackTrace();
      }
      sslFactory = sslcontext.getSocketFactory();
    }
  }
View Full Code Here

        super();
    }

    private static SSLContext createEasySSLContext() {
        try {
            SSLContext context = SSLContext.getInstance("SSL");
            context.init(
              null,
              new TrustManager[] {new EasyX509TrustManager(null)},
              null);
            return context;
        } catch (Exception e) {
View Full Code Here

        }
       
        // 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

                }
            }
        };
    
        // 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

                }
            }
        };
    
        // 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

    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

    throws IOException, GeneralSecurityException
  {
    SSLServerSocketFactory factory = null;
   
    if (_keyStore != null) {
      SSLContext sslContext = SSLContext.getInstance(_sslContext);

      KeyManagerFactory kmf
        = KeyManagerFactory.getInstance(_keyManagerFactory);
   
      kmf.init(_keyStore, _password.toCharArray());
     
      sslContext.init(kmf.getKeyManagers(), null, null);

      /*
      if (_cipherSuites != null)
        sslContext.createSSLEngine().setEnabledCipherSuites(_cipherSuites);

      if (_protocols != null)
        sslContext.createSSLEngine().setEnabledProtocols(_protocols);
      */

      factory = sslContext.getServerSocketFactory();
    }
    else {
      factory = createAnonymousFactory(host, port);
    }

View Full Code Here

TOP

Related Classes of javax.net.ssl.SSLContext

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.