Reputation: 357
I am trying to write a custom proxy server to handle https connection. Is there anything in Java that's equivalent to .NET SSLStream ?
Upvotes: 2
Views: 1175
Reputation:
You may need to use SSLSocketFactory
for creating a SSL ServerSocket
. The related server socket will take care about(has specific/implemented in
and out
streams) data encryption and related processes.
You may specify the SSL settings as system properties as following.
System.setProperty("javax.net.ssl.trustStore", "<<path of your key>>");
System.setProperty("javax.net.ssl.trustStorePassword", "<<store passwd if specified>>");
//System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
System.setProperty("javax.net.debug", "all");
Later, you need to initialize the ServerSocket
as following
int port=3128,backlog=32;
ServerSocket ss=SSLServerSocketFactory.getDefault().createServerSocket(port, backlog, InetAddress.getLoopbackAddress());
The rest work is just like plain(non-ssl) process, just listen for a request and proceed it.
while(ss.isBound()){
Socket s=ss.accept();
InputStram in=s.getInputStream();
OutputStream os=s.getOutputStream();
//.....rest of teh work
}
Upvotes: 2