|
Recently I'm involved in a project in which we have the following (simplest) scenario. Two machines are using RMI in a network. We want to use RMI over SSL in order to make it secure. And we want to be able to read certificates in both sides, server and client. In both sides we want to check the contents of the certificates before actually establishing a connection. For this purpose I wrote a very basic implementation of ServerSocket. In this class I delegate the methods to SSLServerSocket and CryptoBroker is a class which provides a Context, with which we construct an SSLServerSocket. You should write your own methods to do this.
/** * */ package test.ssl; import org. apache. log4j. Logger; import detos.conframe.ssl.CryptoBroker; /** * @author gurito Our own implementation of ServerSocket The goal is to check a * certificate before actually establishing a connection private * KeyStore ks; */ /** * @throws Exception, * IOException */ CryptoBroker cb = CryptoBroker.getInstance("config/cacert.pem", "config/server.pem"); ssf = cb.getContext().getServerSocketFactory(); } /** * @param port * @throws IOException */ CryptoBroker cb = CryptoBroker.getInstance("config/cacert.pem", "config/server.pem"); ssf = cb.getContext().getServerSocketFactory(); } /** * @param port * @param backlog * @throws IOException */ CryptoBroker cb = CryptoBroker.getInstance("config/cacert.pem", "config/server.pem"); ssf = cb.getContext().getServerSocketFactory(); } /** * @param arg0 * @param arg1 * @param arg2 * @throws IOException */ CryptoBroker cb = CryptoBroker.getInstance("config/cacert.pem", "config/server.pem"); ssf = cb.getContext().getServerSocketFactory(); } /** * accept() listens for connections and, after checking the certificate, * establishes one. * * @return SSLSocket * @throws IOException */ s.setEnableSessionCreation(true); s.setNeedClientAuth(true); if (zokete.isConnected()) { LOG.info("connected"); checkCertificates(session); } return zokete; } private boolean checkCertificates (SSLSession session ) { // TODO Do something here if (session != null) { LOG.info("Successfully established a session!!!"); try { .getPeerCertificates(); String name = certs [0]. getSubjectX500Principal(). getName(); LOG.info("Name of the cert: " + name); // TODO Auto-generated catch block LOG.error("Caught an Exception: " + e + " --> " + e.getMessage()); } return true; } return false; } }
|