HTTPS with Applet over Proxy Issue

An applet using HttpURLConnection within a Java Applet. The Connection is formulated as follows:

HttpURLConnection urlConn = (HttpURLConnection)destURL

.openConnection( );

urlConn.setDoOutput(true );

urlConn.setDoInput(true );

urlConn.setUseCaches(false );

urlConn.setAllowUserInteraction(false );

urlConn.setRequestProperty("Content-type","multipart/form-data" );

urlConn.setRequestProperty("Content-length","" + parameters.length( );

This works fine with numerous proxy servers and other network

topologies, except one. The issue I am told occurs when we are trying to

connect over https. For background, my understanding is this causes the Java Plug-in to :

* invoke the http CONNECT command

* wait for the 200 OK indicating that the secure tunnel is established

* then send the request securely.

Doing a packet trace shows that the headers set in the code are

actually being _included_ with the CONNECT. However the Java Plug

(1.4.2_06) does not sent the body with the CONNECT. I am told this

causes the proxy to wait for an entity that never arrives, because, on

the other end, the plug-in is waiting for 200 OK. After 8 secs the

plug-in resets the connection and fails.

Packet traces on other proxies show the same content-length header being

included, but they decide ignore it. From Googling I note some folks

claim that this is expected, because CONNECT is non-entity enclosing.

Doc's are scant on the CONNECT command. In some cases they seem to imply

that no data should go with the CONNECT (making it non-entity

enclosing), but later they state it supports data-pipelining, making the

content-length relevant, as the CONNECT may well contain an entity.

Moreover, is the intent of Applet Framework to insulate the programmer

from having to worry about issues like this? For example this Applet can

and does connect to a myriad of HTTP/1.1 or 1.0 server through a proxy

or not; in the case of no proxy or non secure proxy, the content-length

header is valid as the request goes out in one go with associated

headers. So writing the code as above, does not seem to be inherently

flawed, IMO. <-- And that is a question too :).

I note there is an isProxy() method, but this can only be determined

after connection (obviously) and parameters cannot be changed once the

connection is made. So creating a dummy connection first is possible I

suppose, but it seems a slippery slope to start coding for exceptions

like this, unless absolutely necessary.

On the face of it, it could be argued that this appears to be a bug in

the plug-in but with very little hits in google I am doubtful. To that

end, does anyone have any thoughts or experience with either working

around the problem (it would seem to be a pity to have to have a setting

per client), or whether in fact this proxy server is being too draconian

in its interpretation.

Thanks in advance,

Gary

Refs:

RFC2616

http://www.web-cache.com/Writings/Internet-Drafts/draft-luotonen-web-proxy-tunneling-01.txt

[3547 byte] By [gary_mcma] at [2007-10-1 15:27:10]
# 1

I have the same config - Applet, https, proxy, java plug-in 1.4.2

Most of the time, it works fine, but sometimes (maybe when the network is heavily loaded), the applet makes SocketException with "unexpected end of file" or "Software caused connection abort: recv failed" message.

Could it be the symptom of the issue you mentioned ?

Is it solved with plug-in 1.5 ?

Fabien_Bergereta at 2007-7-10 19:40:04 > top of Java-index,Security,Other Security APIs, Tools, and Issues...
# 2
No this is repeateable with one specific kind of Proxy Server. 1.5 formulates the request differently and it works a tiny bit better but still is subject to the lock-ups.
gary_mcma at 2007-7-10 19:40:04 > top of Java-index,Security,Other Security APIs, Tools, and Issues...
# 3

Pardon my ignorance about proxies, but how do you tell the plug-in that there is a proxy in between you and the destination?

The reason I ask is because with the https protocol, the first thing that happens is that an SSL connection is set up between the endpoints, and only after, through this secure tunnel, is the GET request or whatever sent. The proxy never gets to see any of the HTTP headers.

ghstarka at 2007-7-10 19:40:04 > top of Java-index,Security,Other Security APIs, Tools, and Issues...
# 4

You don't have to. It's the plugin that decides what to do about the connection. And this is the issue. If you look at the origianly code I posted, it sets the content length, however it adds that header to the CONNECT command and this is what is throwing off the proxy in question. The RFCs are ambiguous in this regard.

gary_mcma at 2007-7-10 19:40:04 > top of Java-index,Security,Other Security APIs, Tools, and Issues...