#1
  1. Java PHP Oracle Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    C-Bus OH-IO
    Posts
    204
    Rep Power
    11

    Connecting through a proxy WSAD / BorderManager / JSSE


    I am trying to get the InputStream from a URLConnection object. The connection must be established with the Internet through a proxy.

    My code stops at the following line: line = reader.readLine();

    I already asked my security guys if I could tunnel through and they change the setting on the proxy server to allow for HTTP tunelling and they said no because it is a security risk.


    Here is my environment:
    IBM WebSphere Application Developer 4.03 w/ JDK 1.3.1
    Proxy Server: Novell Border Manager
    I have jecert.jar, jnet.jar and jsse.jar in my classpath and they are located here: C:\Program Files\IBM\Application Developer\jre\lib\ext
    (I was told I need to use the SUN classes and not the IBM ones)


    From my java.security file:
    security.provider.1=sun.security.provider.Sun
    security.provider.2=com.sun.net.ssl.internal.ssl.Provider
    security.provider.3=com.ibm.crypto.provider.IBMJCA


    Here is my code:
    Code:
    package com.MattSidesinger.test;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.security.Security;
    
    import javax.net.ssl.SSLSocket;
    import javax.net.ssl.SSLSocketFactory;
    
    public class ProxyConnectionTester
    {
    
    	public static void main(String[] args)
    	{
    		try
    		{
    			// Set the system and security properties
    			System.setProperty("javax.net.ssl.trustStore", "C:\\cacerts1");
    		    	System.setProperty("javax.net.ssl.trustStorePassword", "password");
    
    		    	// Keystore location and password	
    	     		System.setProperty("javax.net.ssl.keyStore", "C:\\cacerts1");
    		    	System.setProperty("javax.net.ssl.keyStorePassword", "password");
    		    	
    			System.setProperty("proxyHost","bmserver");
    			System.setProperty("proxyPort","8080");
    			System.setProperty("proxyUserName","username");
    			System.setProperty("proxyPassword","password");
    			System.setProperty("proxySet","true");
    			System.setProperty("http.proxyHost","bmserver");
    			System.setProperty("http.proxyPort","8080");
    			System.setProperty("http.proxyUserName","username");
    			System.setProperty("http.proxyPassword","password");
    			System.setProperty("http.proxySet","true");
    			System.setProperty("https.proxyHost","bmserver");
    			System.setProperty("https.proxyPort","8080");
    			System.setProperty("https.proxyUserName","username");
    			System.setProperty("https.proxyPassword","password");
    			System.setProperty("https.proxySet","true");
       		    	System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    		    	
    			Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    			
    			// connect to get the web page
    			URL url = new URL("http://www.google.com");
    			URLConnection connection = url.openConnection();
    						
    			// get the contents of the web page
    			InputStream stream = connection.getInputStream();
    			BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
    
    			// read in the entire web page
    			StringBuffer webPage = new StringBuffer();
    			String line = null;
    			
    			while(true)
    			{
    				line = reader.readLine(); // STOPS HERE
    				if (line == null)
    				{
    					break;
    				}
    				webPage = webPage.append(line);
    			}
    								
    			// close all resources that we do not need
    			// now that the web page has been obtained			
    			stream.close();
    			reader.close();
    			
    		}
    		catch (MalformedURLException e)
    		{
    			System.out.println("MalformedURLException");
    		}
    		catch (IOException e)
    		{
    			System.out.println(e.toString());		
    		}
    	}
    }


    There were no errors when I installed the certificates to the keystore using the keytool.



    I will keep you updated if I have any further advances.
  2. #2
  3. Java PHP Oracle Developer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    C-Bus OH-IO
    Posts
    204
    Rep Power
    11
    I get the following when trying to connect when using the SSLSocketClientWithTunneling class that Sun wrote. This may offer some insight.

    Code:
    java.io.IOException: Unable to tunnel through bmserver:8080.  Proxy returns "HTTP/1.0 302 Moved Temporarily"
    	at com.MattSidesinger.test.SSLSocketClientWithTunneling.doTunnelHandshake(SSLSocketClientWithTunneling.java:348)
    	at com.MattSidesinger.test.SSLSocketClientWithTunneling.doIt(SSLSocketClientWithTunneling.java:140)
    	at com.MattSidesinger.test.SSLSocketClientWithTunneling.main(SSLSocketClientWithTunneling.java:110)
    javax.net.ssl.SSLException: Unrecognized SSL handshake.
    	at com.sun.net.ssl.internal.ssl.InputRecord.read(DashoA6275)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
    	at com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA6275)
    	at java.io.OutputStream.write(OutputStream.java:67)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(DashoA6275)
    	at com.MattSidesinger.test.SSLSocketClientWithTunneling.doIt(SSLSocketClientWithTunneling.java:238)
    	at com.MattSidesinger.test.SSLSocketClientWithTunneling.main(SSLSocketClientWithTunneling.java:110)
    Last edited by MattSidesinger; February 6th, 2004 at 10:44 AM.

IMN logo majestic logo threadwatch logo seochat tools logo