List of usage examples for org.apache.commons.ssl SSLServer SSLServer
public SSLServer() throws GeneralSecurityException, IOException
From source file:servidor.Servidor.java
public static void main(String[] arstring) { try {/* w w w .j a v a 2 s . c o m*/ SSLServer server = new SSLServer(); // Server needs some key material. We'll use an OpenSSL/PKCS8 style key (possibly encrypted). String certificateChain = "/lib/server.crt"; String privateKey = "/lib/server.key"; char[] password = "clave".toCharArray(); KeyMaterial km = new KeyMaterial(certificateChain, privateKey, password); server.setKeyMaterial(km); // These settings have to do with how we'll treat client certificates that are presented // to us. If the client doesn't present any client certificate, then these are ignored. server.setCheckHostname(false); // default setting is "false" for SSLServer server.setCheckExpiry(true); // default setting is "true" for SSLServer server.setCheckCRL(true); // default setting is "true" for SSLServer // This server trusts all client certificates presented (usually people won't present // client certs, but if they do, we'll give them a socket at the very least). server.addTrustMaterial(TrustMaterial.TRUST_ALL); SSLServerSocket ss = (SSLServerSocket) server.createServerSocket(7443); SSLSocket s = (SSLSocket) ss.accept(); PrintWriter writer = new PrintWriter(s.getOutputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream())); System.out.println(reader.readLine()); } catch (Exception e) { } }