Handshake failures (#5624)

* BAEL-2250: Adding files for the article on SSL handshake failure.

* BAEL-2250 cleanup formatting

* Applied review feedback on the article.

* Adding cipher suite and protocol selection in server and client

* Corrected some code conventions.

* Revert: BAEL-2250 cleanup formatting

* Made further changes for the review comments on the tutorial.

* Fixed some formatting issues.
This commit is contained in:
Kumar Chandrakant 2018-11-05 23:51:10 +00:00 committed by Emily Cheyne
parent 433bb89de6
commit e52a4d0ce6
2 changed files with 13 additions and 9 deletions

View File

@ -8,22 +8,26 @@ import java.net.Socket;
import javax.net.SocketFactory; import javax.net.SocketFactory;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.SSLParameters;
public class SimpleClient { public class SimpleClient {
static void startClient(String host, int port) throws IOException { static String startClient(String host, int port) throws IOException {
SocketFactory factory = SSLSocketFactory.getDefault(); SocketFactory factory = SSLSocketFactory.getDefault();
try (Socket connection = factory.createSocket(host, port)) { try (Socket connection = factory.createSocket(host, port)) {
((SSLSocket) connection).setEnabledCipherSuites( ((SSLSocket) connection).setEnabledCipherSuites(
new String[] { "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256"}); new String[] { "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256"});
((SSLSocket) connection).setEnabledProtocols( ((SSLSocket) connection).setEnabledProtocols(
new String[] { "TLSv1.2"}); new String[] { "TLSv1.2"});
BufferedReader input = new BufferedReader( SSLParameters sslParams = new SSLParameters();
new InputStreamReader(connection.getInputStream())); sslParams.setEndpointIdentificationAlgorithm("HTTPS");
System.out.println(input.readLine()); ((SSLSocket) connection).setSSLParameters(sslParams);
BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
return input.readLine();
} }
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
startClient("localhost", 1234); System.out.println(startClient("localhost", 8443));
} }
} }

View File

@ -4,7 +4,6 @@ import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.Date;
import javax.net.ServerSocketFactory; import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLServerSocket;
@ -13,6 +12,7 @@ import javax.net.ssl.SSLServerSocketFactory;
public class SimpleServer { public class SimpleServer {
static void startServer(int port) throws IOException { static void startServer(int port) throws IOException {
ServerSocketFactory factory = SSLServerSocketFactory.getDefault(); ServerSocketFactory factory = SSLServerSocketFactory.getDefault();
try (ServerSocket listener = factory.createServerSocket(port)) { try (ServerSocket listener = factory.createServerSocket(port)) {
((SSLServerSocket) listener).setNeedClientAuth(true); ((SSLServerSocket) listener).setNeedClientAuth(true);
((SSLServerSocket) listener).setEnabledCipherSuites( ((SSLServerSocket) listener).setEnabledCipherSuites(
@ -22,13 +22,13 @@ public class SimpleServer {
while (true) { while (true) {
try (Socket socket = listener.accept()) { try (Socket socket = listener.accept()) {
PrintWriter out = new PrintWriter(socket.getOutputStream(), true); PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println(new Date().toString()); out.println("Hello World!");
} }
} }
} }
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
startServer(1234); startServer(8443);
} }
} }