0
votes

I'm working on a project where I have to send HTTP requests through multiple servers, encrypt and decrypt them, encrypt and decrypt responses.

Here is the idea:

  1. I send requests from a web browser on which I configure proxy settings (via SwitchyOmega because I can't modify my connection proxy settings) to connect to "Server 1"
  2. "Server 1" receive the request as a byte array
  3. "Server 1" encrypt the request
  4. "Server 1" send the encrypted request to "Server 2" via "Proxy"
  5. "Server 2" decrypt request
  6. "Server 2" execute request
  7. "Server 2" get response
  8. "Server 2" encrypt the response
  9. "Server 2" send the encrypted response to "Server 1" 10."Server 1" decrypt the response and send it to the web browser.

here is a little diagram:

architectural diagram

I don't have access to "proxy", but everything is on my hand for "Server 1" and "Server 2". They preferably have to be little portable java applications.

I found a lot of things about making a proxy with java but as my "Server 1" receive request as a byte array, i would like to find an API that can execute it correctly. I tries by converting the bytes to String, get host and port and using things like URLConnection yc = oracle.openConnection(); or HttpURLConnection con = (HttpURLConnection) obj.openConnection(); but I had to parse the byte[] to retrieve informations such as methodes (get, post,...), host, port, protocol,... and rebuild the query. As the request is already build, it seems a lot for nothing.

I have read a lot about Apache Commons HttpClient which seems great, but I did not find a way to execute correctly the queries.

Is there a way for Apache Commons HttpClient to execute raw bytes queries? Or do you have another suggetion to execute raw bytes queries?

1

1 Answers

0
votes

The easiest way to send raw bytes request is to open a socket write directly into its OutputStream. However you will have to parse the response or take its bytes and send them back to the other connection, from which they have come from. The hardest part will be to properly close the sockets/streams, depending on Connection Keep-Alive and content lengths, etc.