dev@glassfish.java.net

Re: Unable to tunnel through proxy for HTTPS

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Fri, 19 May 2006 10:42:12 -0700

Deepa,

Deepa Singh wrote On 05/18/06 11:16,:
> Hi All,
> I had a non appserver related question
>
> I am trying to access a HTTPS URL from my client socket . This URL is
> external to Sun, on regular internet, I am able to lookup from browser
> fine, but when I open a URLConnection to it,I get following exception,
> I set proxy as follows:
>
> System.setProperty("https.proxyHost", proxyHost);
> System.setProperty("https.proxyPort", proxyPort);
> URL url = new URL(secureURL);
> URLConnection conn = url.openConnection();
>
> java.io.IOException: Unable to tunnel through proxy. Proxy returns
> "HTTP/1.1 400 Bad request"

A search for "jsse proxy" came up a few helpful links.

According to:

   http://archives.java.sun.com/cgi-bin/wa?A2=ind0009&L=java-security&P=7090

this seems to be a known JSSE issue:

   Yesterday I sent the message below describing a problem I am having
   and I believe I have some additional information. It looks like the
   JSSE proxy code is expecting the response protocol and version to
   match the request's protocol and version exactly. JSSE sends a
   "CONNECT host:port HTTP/1.0" and expects HTTP/1.0 200 " but my MS
   Proxy is returning "HTTP/1.1 200 Connection established" the response
   minor version does not match the request minor version. If I am
   interpreting the HTTP 1.1 standard correctly the proxy response must
   have the same major version but it doesn't require
   the same minor version, which would imply this is a bug in the JSSE
   HTTP protocol layer.

This tech tip:

   http://www.javaworld.com/javaworld/javatips/jw-javatip111.html

offers a workaround:

   The Java Secure Socket Extension (JSSE) library from Sun Microsystems
   lets you access a secure Web server from behind a firewall via proxy
   tunneling. To do this, the JSSE application needs to set the
   https.ProxyHost and https.ProxyPort system properties. The tunneling
   code in JSSE checks for "HTTP 1.0" in the proxy's response. If your
   proxy, like many, returns "HTTP 1.1", you will get an IOException. In
   this case, you need to implement your own HTTPS tunneling protocol.

Which version of JSSE are you using?


Jan



> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>
> at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
> at
> sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1202)
>
> at java.security.AccessController.doPrivileged(Native Method)
> at
> sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1196)
>
> at
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:885)
>
> at
> sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
>
> at
> com.sun.glassfish.bugbridge.issuetracker.IssueTrackerClient.doPOST(Unknown
> Source)
> at
> com.sun.glassfish.bugbridge.issuetracker.IssueTrackerClient.main(Unknown
> Source)
> Caused by: java.io.IOException: Unable to tunnel through proxy. Proxy
> returns "HTTP/1.1 400 Bad request"
> at
> sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:1324)
>
> at
> sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:168)
>
> at
> sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:1698)
>
> at
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1085)
>
> at
> sun.net.www.protocol.http.HttpURLConnection.getHeaderFieldKey(HttpURLConnection.java:1919)
>
> at
> sun.net.www.protocol.https.HttpsURLConnectionImpl.getHeaderFieldKey(HttpsURLConnectionImpl.java:287)
>
> ... 2 more
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>