Java Proxy (not game related)

Well this isn’t really for a game, but I’m trying to write a proxy in java.

It works well and all, but I just don’t know how to get it to work with SSL connections.

It reads headers from the client (my browser) and just sends them directly to the remote address being accessed, only the first line of the headers is modified as so:

byte[] headerAsBytes = (tokens[0] + " " + tokens[1] + " HTTP/1.0\r\n").getBytes();

tokens[0] is the request method (which is “CONNECT” for https) and tokens[1] is the (local address, example if you are accessing example.com/cool, tokens[1] would be “/cool”).

I send the rest of the headers directly after reading:

			int totalHeader = 0;
			int len;
			while ((len = in.read(buf)) != -1) {
				out.write(buf, 0, len);
				println("Wrote " + len + " header bytes.");
				out.flush();
				totalHeader += len;
				if (in.available() == 0)
					break;
			}

now how do I go about making this work with secure connections :\

A quick google search http://www.google.com/search?rlz=1C1TSND_enUS407US407&gcx=c&sourceid=chrome&ie=UTF-8&q=java+ssl yieilded this: you use

java.net.ssl.*

, but you need a keystore. You can make one with JDK or Java SE with keytool.exe in the java folder\bin. Just open cmd and type

keytool -genkey -alias "alias_here" -keyalg RSA -keystore "C:\path_to_keystore\keystore.jks" -keysize 2048

then use java.net.ssl.SSLServerSocket instead of java.net.ServerSocket (get full code here: http://stilius.net/java/java_ssl.php) and run it with

java -Djavax.net.ssl.keyStore="C:\path_to_keystore\keystore.jks" -Djavax.net.ssl.keyStorePassword="password you chose in keytool.exe" server_class_here