Sun SSL Socket Server : SSL Socket « Security « Java Tutorial






import java.io.*;
import java.net.*;
import java.security.*;

import javax.net.ssl.*;

import com.sun.net.ssl.*;

public class MainClass {

  private static final int PORT = 8080;

  public static void main(String[] args) throws Exception {
    char[] passphrase = "password".toCharArray();
    KeyStore keystore = KeyStore.getInstance("JKS");
    keystore.load(new FileInputStream(".keystore"), passphrase);
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(keystore, passphrase);
    SSLContext context = SSLContext.getInstance("TLS");
    KeyManager[] keyManagers = kmf.getKeyManagers();

    context.init(keyManagers, null, null);

    SSLServerSocketFactory ssf = context.getServerSocketFactory();
    ServerSocket ss = ssf.createServerSocket(PORT);

    Socket s = ss.accept();

    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));

    String line = null;
    while (((line = in.readLine()) != null)) {
      System.out.println(line);
    }
    in.close();
    s.close();
  }
}








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