1 package com.freemindcafe.socket.ssl.sample3;
4 import javax.net.ssl.SSLServerSocket;
5 import javax.net.ssl.SSLServerSocketFactory;
6 import javax.net.ssl.SSLSocket;
10 import java.io.BufferedReader;
11 import java.io.InputStream;
12 import java.io.InputStreamReader;
17 public void ssl_server_that_demands_client_auth() {
21 "javax.net.ssl.trustStore",currentDir()+
"/src/com/freemindcafe/socket/ssl/sample3/serverkeystore.jks");
22 System.setProperty(
"javax.net.ssl.trustStorePassword",
"password");
24 "javax.net.ssl.keyStore",
25 currentDir()+
"/src/com/freemindcafe/socket/ssl/sample3/serverkeystore.jks");
26 System.setProperty(
"javax.net.ssl.keyStorePassword",
"password");
27 System.setProperty(
"javax.net.debug",
"ssl:handshake");
29 SSLServerSocketFactory sslserversocketfactory = (SSLServerSocketFactory) SSLServerSocketFactory
31 SSLServerSocket sslserversocket = (SSLServerSocket) sslserversocketfactory
32 .createServerSocket(9999);
34 sslserversocket.setNeedClientAuth(
true);
35 SSLSocket sslsocket = (SSLSocket) sslserversocket.accept();
37 InputStream inputstream = sslsocket.getInputStream();
38 InputStreamReader inputstreamreader =
new InputStreamReader(
40 BufferedReader bufferedreader =
new BufferedReader(
44 while ((
string = bufferedreader.readLine()) != null) {
45 System.out.println(
"server printing ################");
46 System.out.println(
string);
49 }
catch (Exception exception) {
50 exception.printStackTrace();