wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes Custom Proxy server handling both http  and https? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Custom Proxy server handling both http  and https?" Watch "Custom Proxy server handling both http  and https?" New topic
Author

Custom Proxy server handling both http and https?

steve labar
Ranch Hand

Joined: Sep 10, 2008
Posts: 55
I have been trying for a while now to get a functional proxy going for http requests with no luck. I am currently using the http core Apache library as well as the http client to make it all work. Setting up the proxy to handle http was quite easy. However, as soon as I try to add anything that is coming from https the application fails. I think that part of my problem is that I'm still not entirely sure how the process is supposed to be handled. Initially, I was thinking that you set up a socket connection listen on port 8080 (or whatever port of your choosing) and as the browser sends the http requests the socket recognizes those requests are you as the programmer take those requests and making them and pass the response back to the browser. Problem is if my socket is a standard socket connection listening on port 8080 is handled fine. As soon as an https request comes in I received CONNECT request.once I see that connect request I change my clients on my proxy to send to the server via SSL and send back a response to the browser saying the handshake was complete. The problem is the next request that comes from the browser which I'm assuming is encrypted the socket closes. initially I thought that when I see the connect request I would change the socket to an SSL socket however what was happening then was if anything else from the browser came over the 8080 sslsocket was in clear text the SSL socket would throw a plaintext exception. So I'm thinking that the proxy server does not have to change the connection to SSL and simply just has to pass along the encrypted data to the server. Does this sound correct? Should I be able to simply create a standard connection on port 8080 and be able to handle both http and https?
If that is the case than though no cert will be needed between the browser and my proxy. However i think if the browser is sending https encrypted data its going to want to do a handshake and that cannot be done with standard socket. So needless to say im very confused!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

If I understand correctly, you've written your own proxy that listens on only one port, right? Because of the encryption HTTPS provides, HTTP and HTTPS are different protocols, and should be handled by different ports. The defaults are 80 and 443 respectively, and Tomcat for one uses 8080 and 8443 by default.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom Proxy server handling both http and https?
 
Similar Threads
My SCEA Part 1Study Notes
Apache in DMZ and HTTPS
Creating Proxy cannot correctly tunnel through SSL after browser sends CONNECT request?
Protocols
Question on HTTPS ?