SSL Simple Server : SSL Socket « Security « Java Tutorial






import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;

public class MainClass extends Thread {

  public static void main(String[] args) throws Exception {
    ServerSocketFactory ssf = SSLServerSocketFactory.getDefault();
    ServerSocket ss = ssf.createServerSocket(9096);

    while (true) {
      new SSLSimpleServer(ss.accept()).start();
    }
  }
  private Socket sock;
  public SSLSimpleServer(Socket s) {
    sock = s;
  }
  public void run() {
    try {
      BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
      PrintWriter pw = new PrintWriter(sock.getOutputStream());

      String data = br.readLine();
      pw.println("What is she?");
      pw.close();
      sock.close();
    } catch (IOException ioe) {
      // Client disconnected
    }
  }
}








36.44.SSL Socket
36.44.1.Use SSLServerSocketFactory to create a SSL Server
36.44.2.SSL Server Session
36.44.3.SSL Client Session
36.44.4.Send html(gif) file through SSLSocket
36.44.5.SSL Client Demo
36.44.6.SSL Client with javax.net.ssl.trustStore setting
36.44.7.SSL Socket Server
36.44.8.SSL Socket Client
36.44.9.Sun SSL Socket Client
36.44.10.Sun SSL Socket Server
36.44.11.SSL Simple Client
36.44.12.SSL Simple Server
36.44.13.SSL Client Verifier
36.44.14.SSLContext and Key manager
36.44.15.SSL Server with KeyStore and Key Store Password setting
36.44.16.Get peer certificate from SSL session
36.44.17.Retrieving the Certification Path of an SSL Server