Examples of SSLContext


Examples of javax.net.ssl.SSLContext

    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
    tmf.init(keystore);      
    TrustManager[] trustManagers = tmf.getTrustManagers();

    SSLContext ctx = SSLContext.getInstance(sslContext);
    SecureRandom securerandom = SecureRandom.getInstance("SHA1PRNG");
    //    SecureRandom securerandom = null;
    ctx.init(kmf.getKeyManagers(),trustManagers,securerandom);

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

Examples of javax.net.ssl.SSLContext

        if (!isSslEnabled()) {
          return null;
        }
       
        // Use the SSLContext to create an SSLServerSocketFactory.
        SSLContext context = null;

        if (ANONYMOUS.equals(authenticationMode)) {
            context = SocketUtil.getAnonSSLContext();
        } else {
            context = SocketUtil.getSSLContext(keyStoreFileName,
                                    keyStorePassword,
                                    trustStoreFileName,
                                    trustStorePassword,
                                    keyManagerFactoryAlgorithm,
                                    keyStoreType,
                                    sslProtocol);
        }

        SSLEngine result = context.createSSLEngine();
        result.setUseClientMode(false);
        if (ANONYMOUS.equals(authenticationMode)) {
            if (!(Arrays.asList(result.getSupportedCipherSuites()).contains(SocketUtil.ANON_CIPHER_SUITE))) {
              throw new GeneralSecurityException(RuntimePlugin.Util.getString("SSLConfiguration.no_anonymous")); //$NON-NLS-1$
            }
View Full Code Here

Examples of javax.net.ssl.SSLContext

        String truststore = props.getProperty(TRUSTSTORE_FILENAME, keystore);
        String truststorePassword = props.getProperty(TRUSTSTORE_PASSWORD, keystorePassword);
       
        boolean anon = PropertiesUtils.getBooleanProperty(props, ALLOW_ANON, true);
       
        SSLContext result = null;
        // 1) keystore != null = 2 way SSL (can define a separate truststore too)
        // 2) truststore != null = 1 way SSL (here we can define custom properties for truststore; useful when
        //    client like a appserver have to define multiple certs without importing
        //    all the certificates into one single certificate
        // 3) else = javax properties; this is default way to define the SSL anywhere.
View Full Code Here

Examples of javax.net.ssl.SSLContext

                trustManagers = tmf.getTrustManagers();
            }
        }

        // Configure the SSL
        SSLContext sslc = SSLContext.getInstance(protocol);
        sslc.init(keyManagers, trustManagers, null);
        return sslc;
    }
View Full Code Here

Examples of javax.net.ssl.SSLContext

    this.sslSocketFactory = sslSocketFactory;
  }

  public void makeSSLSocketFactory() throws Exception {
    if(getSslContext()==null && getSslSocketFactory()==null) {
      SSLContext context = SSLContext.getInstance("SSLv3");
      if(getTrustManager()==null && isUseDummyTrustManager()) {
        setTrustManager(new TrustManager[]{DummyTrustManager.getInstance()});
      }
     
      KeyManager km[] = null;
      if(getClientAuthKeystoreInputStream()!=null) {
        KeyStore keyStore = KeyStore.getInstance("JKS");
        keyStore.load(getClientAuthKeystoreInputStream(), getClientAuthKeystorePassword());
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(keyStore, getClientAuthKeyPassword());
        km = kmf.getKeyManagers();
      } else {
        km = new KeyManager[0];
      }

      context.init(km, getTrustManager(), new SecureRandom());
      setSslContext(context);
    }
   
    if(getSslSocketFactory()==null) {
      SSLSocketFactory factory = getSslContext().getSocketFactory();
View Full Code Here

Examples of javax.net.ssl.SSLContext

                    java.security.cert.X509Certificate[] certs, String authType) {
                }
              }
            };
       
          SSLContext sc = SSLContext.getInstance("SSL");
       
          sc.init(null, trustAllCerts, RandomUtils.SECURE_RANDOM );
       
          SSLSocketFactory factory = sc.getSocketFactory();

          try{
            socket_out = factory.createSocket();
           
            socket_out.connect( new InetSocketAddress( delegate_to_host, delegate_to_port ), CONNECT_TIMEOUT );
View Full Code Here

Examples of javax.net.ssl.SSLContext

    private void secureClientDataConnection() throws NoSuchAlgorithmException,
            KeyManagementException {

        // FTPSClient does not support implicit data connections, so we hack it ourselves
        FTPSClient sclient = (FTPSClient) client;
        SSLContext context = SSLContext.getInstance("TLS");

        // these are the same key and trust managers that we initialize the client with
        context.init(new KeyManager[] { clientKeyManager },
                new TrustManager[] { clientTrustManager }, null);
        sclient.setSocketFactory(new FTPSSocketFactory(context));
        SSLServerSocketFactory ssf = context.getServerSocketFactory();
        sclient.setServerSocketFactory(ssf);

        // FTPClient should not use SSL secured sockets for the data connection
    }
View Full Code Here

Examples of javax.net.ssl.SSLContext

                keyManagers[i] = new AliasKeyManager(keyManagers[i], keyAlias);
            }
        }

        // create and initialize the SSLContext
        SSLContext ctx = SSLContext.getInstance(sslProtocol);
        ctx.init(keyManagers, trustManagerFactory.getTrustManagers(), null);
        //Create the socket factory
        return ctx;
    }
View Full Code Here

Examples of javax.net.ssl.SSLContext

  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

Examples of javax.net.ssl.SSLContext

        //TODO for performance reasons we should cache the KeymanagerFactory and TrustManagerFactory
        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);
            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()});
               
            }
            if ((keyStorePassword == null) && (keyStoreLocation != null)) {
                LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_KEYSTORE_NULL_PASSWORD",
                             new Object[]{keyStoreLocation});
            }
           
            // ************************* Load Trusted CA file *************************
           
            TrustManager[] trustStoreManagers = null;
            KeyStore trustedCertStore = KeyStore.getInstance(trustStoreType);
           
            trustedCertStore.load(new FileInputStream(trustStoreLocation), null);
            TrustManagerFactory tmf  =
                TrustManagerFactory.getInstance(trustStoreKeyManagerFactoryAlgorithm);
            try {
                tmf.init(trustedCertStore);
                trustStoreManagers = tmf.getTrustManagers();
                LogUtils.log(LOG, Level.INFO, "LOADED_TRUST_STORE", new Object[]{trustStoreLocation});
            } catch (Exception e) {
                LogUtils.log(LOG, Level.WARNING, "FAILED_TO_LOAD_TRUST_STORE",
                             new Object[]{trustStoreLocation, e.getMessage()});
            }
            sslctx.init(keystoreManagers, trustStoreManagers, null);
           
            httpsConnection.setSSLSocketFactory(new SSLSocketFactoryWrapper(sslctx.getSocketFactory(),
                                                                            cipherSuites));
           
           
           
        } catch (Exception e) {
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.