Package javax.net.ssl

Examples of javax.net.ssl.SSLSocketFactory


   */
  public HttpConnection createHttpsConnection(String host, int port)
    throws IOException
  {
    HttpConnection connection = null;
    SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
    SSLSocket socket = null;

    if (! useProxy) {
     
      socket = (SSLSocket)factory.createSocket(host,port);

    } else {
     
      Socket tunnel = new Socket(proxyHost, proxyPort);
      doTunnelHandshake(tunnel, host, port);
     
      /*
       * Ok, let's overlay the tunnel socket with SSL.
       */
      socket = (SSLSocket)factory.createSocket(tunnel, host, port, true);
     
      /*
       * send http request
       *
       * See SSLSocketClient.java for more information about why
View Full Code Here


                        throw new FtpException(
                                "Data connection SSL not configured");
                    }

                    // get socket factory
                    SSLSocketFactory socFactory = ssl.getSocketFactory();

                    // create socket
                    SSLSocket ssoc = (SSLSocket) socFactory.createSocket();
                    ssoc.setUseClientMode(false);

                    // initialize socket
                    if (ssl.getEnabledCipherSuites() != null) {
                        ssoc.setEnabledCipherSuites(ssl.getEnabledCipherSuites());
                    }
                    dataSoc = ssoc;
                } else {
                    LOG.debug("Opening active data connection");
                    dataSoc = new Socket();
                }

                dataSoc.setReuseAddress(true);

                InetAddress localAddr = resolveAddress(dataConfig
                        .getActiveLocalAddress());

                // if no local address has been configured, make sure we use the same as the client connects from
                if(localAddr == null) {
                    localAddr = ((InetSocketAddress)session.getLocalAddress()).getAddress();
                }      

                SocketAddress localSocketAddress = new InetSocketAddress(localAddr, dataConfig.getActiveLocalPort());
               
                LOG.debug("Binding active data connection to {}", localSocketAddress);
                dataSoc.bind(localSocketAddress);

                dataSoc.connect(new InetSocketAddress(address, port));
            } else {

                if (secure) {
                    LOG.debug("Opening secure passive data connection");
                    // this is where we wrap the unsecured socket as a SSLSocket. This is
                    // due to the JVM bug described in FTPSERVER-241.

                    // get server socket factory
                    SslConfiguration ssl = getSslConfiguration();
                   
                    // we've already checked this, but let's do it again
                    if (ssl == null) {
                        throw new FtpException(
                                "Data connection SSL not configured");
                    }

                    SSLSocketFactory ssocketFactory = ssl.getSocketFactory();

                    Socket serverSocket = servSoc.accept();

                    SSLSocket sslSocket = (SSLSocket) ssocketFactory
                            .createSocket(serverSocket, serverSocket
                                    .getInetAddress().getHostAddress(),
                                    serverSocket.getPort(), true);
                    sslSocket.setUseClientMode(false);
View Full Code Here

        Socket createSocket(InetSocketAddress addr) throws Exception {
            return new Socket(addr.getAddress(), addr.getPort());
        }

        Socket createSSLSocket(InetSocketAddress addr) throws Exception {
            SSLSocketFactory sslsocketfactory = (SSLSocketFactory)SSLSocketFactory.getDefault();
            return sslsocketfactory.createSocket(addr.getAddress(), addr.getPort());
        }
View Full Code Here

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

       
          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 );
         
          }catch( SSLException ssl_excep ){
                       
            factory = SESecurityManager.installServerCertificates( "AZ-sniffer:" + delegate_to_host + ":" + port, delegate_to_host, delegate_to_port );
           
            socket_out = factory.createSocket();
           
            socket_out.connect( new InetSocketAddress( delegate_to_host, delegate_to_port ), 30*1000 );         
          }
        }else{
         
View Full Code Here

   */
  public void connect() throws IOException {
    if (level != 0) // otherwise disconnected or connect
      throw new SocketException("Socket closed or already open ("+ level +")");
    IOException exception = null;
    SSLSocketFactory sf = null;
    SSLSocket s = null;
    for (int i = 0; i < ports.length && s == null; i++) {
      try {
        if (sf == null)
          sf = getSocketFactory();
        s = (SSLSocket)sf.createSocket(host, ports[i]);
        s.startHandshake();
        exception = null;
      } catch (IOException exc) {
        if (s != null)
          s.close();
View Full Code Here

      addTrustManager(new SSLDefaultTrustManager());
    try {
      Security.addProvider(new Provider());
      SSLContext context = SSLContext.getInstance("SSL");
      context.init(null, getTrustManagers(), null);
      SSLSocketFactory socketFactory = context.getSocketFactory();
      return socketFactory;
    } catch (Exception exc) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      exc.printStackTrace(pw);
View Full Code Here

               proxyPort = "3128";
            trFact.setProxy(proxyHost, Integer.parseInt(proxyPort));
         }
         if (isSSL) {
            SocketUrl socketUrl = new SocketUrl(glob, xmlRpcUrl.getHostname(), xmlRpcUrl.getPort());
            SSLSocketFactory ssf = socketUrl.createSocketFactorySSL(address);
            if (ssf != null)
               trFact.setSSLSocketFactory(ssf);
            else
               log.warning("The SSL Socket Factory was null but SSL is required");
         }
View Full Code Here

   * @return a SSLSocket
   * @throws IOException when creating the socket failed
   */
  public SSLSocket createSSLSocket(Socket socket) throws IOException
  {
    SSLSocketFactory sf = ((SSLSocketFactory) SSLSocketFactory.getDefault());
    InetSocketAddress remoteAddress = (InetSocketAddress) socket.getRemoteSocketAddress();
    SSLSocket s = (SSLSocket) (sf.createSocket(socket, remoteAddress.getHostName(), socket.getPort(), true));

    // we are a server
    s.setUseClientMode(false);

    // allow all supported cipher suites
View Full Code Here

                            createJettySslClientConfigurer(sslClientPolicy,
                                                           "https://dummyurl",
                                                           handler);

        jettySslClientConfigurer.configure();
        SSLSocketFactory sSLSocketFactory =
                jettySslClientConfigurer.getHttpsConnection().getSSLSocketFactory();
       
        assertTrue("sSLSocketFactory not correct, sSLSocketFactory = " + sSLSocketFactory,
                   sSLSocketFactory instanceof SSLSocketFactoryWrapper);
        assertTrue("Keystore loaded success message not present",
View Full Code Here

TOP

Related Classes of javax.net.ssl.SSLSocketFactory

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.