Package javax.net.ssl

Examples of javax.net.ssl.SSLSocketFactory


     * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
     */
    public Socket createSocket(Socket socket, String host, int port,
                               boolean autoClose)
        throws IOException, UnknownHostException {
        SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
        SSLSocket sslSocket = (SSLSocket) sf.createSocket(socket, host,
                                                          port, autoClose);
        verifyHostname(sslSocket);

        return sslSocket;
    }
View Full Code Here


  }

  @Override
  protected Socket newSocket() throws Exception
  {
    SSLSocketFactory sslsocketfactory = null;
    if (authReqd)
    {
      sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
    }
    else
    {
      TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()
      {
        public java.security.cert.X509Certificate[] getAcceptedIssuers()
        {
          return null;
        }

        public void checkClientTrusted(
          java.security.cert.X509Certificate[] certs, String authType )
        {
          // ignore
        }

        public void checkServerTrusted(
          java.security.cert.X509Certificate[] certs, String authType )
        {
          // ignore
        }
      } };
      SSLContext sslc = SSLContext.getInstance( "SSLv3" );
      sslc.init( null, trustAllCerts, null );
      sslsocketfactory = sslc.getSocketFactory();
    }
    return sslsocketfactory.createSocket( host, port );
  }
View Full Code Here

      throws IOException,
             UnknownHostException,
             ConnectTimeoutException {
   
    SSLContext context;
    SSLSocketFactory factory = null;
    SSLSocket socket = null;
    try {
      KeyManagerFactory kmf;
      KeyStore ks;
      char[] passphrase = keyPass.toCharArray();

      context = SSLContext.getInstance(protocol);
      kmf = KeyManagerFactory.getInstance(kmfFactory);
      ks = KeyStore.getInstance(keyStoreType);
      ks.load(new FileInputStream(keyStore), passphrase);

      TrustManager tm = (this.tm != null) ? this.tm : new X509TrustManager() {
        public void checkClientTrusted(X509Certificate[] arg0, String arg1)
          throws CertificateException {}
        public void checkServerTrusted(X509Certificate[] arg0, String arg1)
          throws CertificateException {}
        public X509Certificate[] getAcceptedIssuers() {
          return null;
        }
      };
     
      kmf.init(ks, passphrase);
      context.init(kmf.getKeyManagers(), new TrustManager[] {tm}, null);
     
      factory = context.getSocketFactory();

      socket = (SSLSocket) factory.createSocket(host, port);
      return socket;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
View Full Code Here

  }

  @Override
  protected Socket newSocket() throws Exception
  {
    SSLSocketFactory sslsocketfactory = null;
    if (authReqd)
    {
      sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
    }
    else
    {
      TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()
      {
        public java.security.cert.X509Certificate[] getAcceptedIssuers()
        {
          return null;
        }

        public void checkClientTrusted(
          java.security.cert.X509Certificate[] certs, String authType )
        {
          // ignore
        }

        public void checkServerTrusted(
          java.security.cert.X509Certificate[] certs, String authType )
        {
          // ignore
        }
      } };
      SSLContext sslc = SSLContext.getInstance( "SSLv3" );
      sslc.init( null, trustAllCerts, null );
      sslsocketfactory = sslc.getSocketFactory();
    }
    return sslsocketfactory.createSocket( host, port );
  }
View Full Code Here

        if (DEBUG || DEBUGLINK) {
            logger.log(Level.INFO, "Creating SSL Socket...");
        }

        try {
            SSLSocketFactory factory = null;

            if (trust) {
                factory = getTrustedSocketFactory();
            } else {
                factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            }

            SSLSocket s = (SSLSocket) factory.createSocket(host, port);

            return s;
        } catch (Exception e) {
            if (!(e instanceof IOException)) {
                IOException ex = new IOException(e.getMessage());
View Full Code Here

        if (DEBUG || DEBUGLINK) {
            logger.log(Level.INFO, "Creating SSL Socket with rxBufSize...");
        }

        try {
            SSLSocketFactory factory = null;

            if (trust) {
                factory = getTrustedSocketFactory();
            } else {
                factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            }

            SSLSocket s = (SSLSocket) factory.createSocket();
            try {
            s.setReceiveBufferSize(rxBufSize);
            } catch (SocketException e) {
            logger.log(Level.WARNING, "HTTPS socket["+host+":"+port+
                   "]setReceiveBufferSize("+rxBufSize+"): "+e.toString(), e);
View Full Code Here

        TrustManager[] tm = new TrustManager[1];
        tm[0] = new DefaultTrustManager();

        ctx.init(null, tm, null);

        SSLSocketFactory factory = ctx.getSocketFactory();

        return factory;
    }
View Full Code Here

    public int hashCode()  {
        return toString().hashCode();
    }

    private SSLSocket makeSSLSocket(String host, int port) throws Exception {
        SSLSocketFactory sslFactory;

        if (isBrokerHostTrusted) {
            sslFactory = getTrustSocketFactory();

            if ( debug ) {
                System.err.println("Broker is trusted ...");
            }
        } else {
            sslFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
        }

        //This is here for QA to verify that SSL is used ...
        if ( debug ) {
            System.err.println ("Create connection using SSL protocol ...");
            System.err.println ("Broker Host: " + host);
            System.err.println ("Broker Port: " + port);
        }

        SSLSocket sslSocket = (SSLSocket) sslFactory.createSocket (host, port);

        //tcp no delay flag
        boolean tcpNoDelay = true;
        String prop = System.getProperty("imqTcpNoDelay", "true");
        if ( prop.equals("false") ) {
View Full Code Here

        return sslSocket;
    }


    private SSLSocketFactory getTrustSocketFactory() throws Exception {
        SSLSocketFactory factory = null;

        SSLContext ctx;
        ctx = SSLContext.getInstance("TLS");
        TrustManager[] tm = new TrustManager [1];
        tm[0] = new DefaultTrustManager();
View Full Code Here

     * @return the socket
     */
    public static Socket createSocket(InetAddress address, int port) throws IOException {
        Socket socket = null;
        setKeystore();
        SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getDefault();
        SSLSocket secureSocket = (SSLSocket) f.createSocket();
        secureSocket.connect(new InetSocketAddress(address, port), SysProperties.SOCKET_CONNECT_TIMEOUT);
        if (SysProperties.ENABLE_ANONYMOUS_SSL) {
            String[] list = secureSocket.getEnabledCipherSuites();
            list = addAnonymous(list);
            secureSocket.setEnabledCipherSuites(list);
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.