Mercurial > hg > icedtea6
view patches/pr2808-fix_disabled_algorithms_test.patch @ 3228:412e3ce4141e
S8076221, PR2808: Disable RC4 cipher suites
2016-01-25 Andrew John Hughes <gnu.andrew@redhat.com>
* Makefile.am:
(ICEDTEA_PATCHES): Add new patches.
* NEWS: Updated.
* patches/openjdk/8076221-pr2808-disable_rc4_cipher_suites.patch:
Backport of 8076221 to OpenJDK 6 b38.
* patches/openjdk/8078823-disabledalgorithms_fails_intermittently.patch:
Improve reliability of DisabledAlgorithms test.
* patches/pr2808-fix_disabled_algorithms_test.patch:
Remove Java 7 features from new DisabledAlgorithms test.
author | Andrew John Hughes <gnu.andrew@redhat.com> |
---|---|
date | Mon, 25 Jan 2016 22:06:42 +0000 |
parents | |
children |
line wrap: on
line source
--- openjdk.orig/jdk/test/javax/net/ssl/ciphersuites/DisabledAlgorithms.java 2015-10-21 05:20:57.910156611 +0100 +++ openjdk/jdk/test/javax/net/ssl/ciphersuites/DisabledAlgorithms.java 2016-01-25 21:58:39.334103875 +0000 @@ -82,16 +82,14 @@ System.setProperty("javax.net.ssl.trustStore", trustFilename); System.setProperty("javax.net.ssl.trustStorePassword", passwd); - switch (args[0]) { - case "default": + if ("default".equals(args[0])) { // use default jdk.tls.disabledAlgorithms System.out.println("jdk.tls.disabledAlgorithms = " + Security.getProperty("jdk.tls.disabledAlgorithms")); // check if RC4 cipher suites can't be used by default checkFailure(rc4_ciphersuites); - break; - case "empty": + } else if ("empty".equals(args[0])) { // reset jdk.tls.disabledAlgorithms Security.setProperty("jdk.tls.disabledAlgorithms", ""); System.out.println("jdk.tls.disabledAlgorithms = " @@ -100,19 +98,19 @@ // check if RC4 cipher suites can be used // if jdk.tls.disabledAlgorithms is empty checkSuccess(rc4_ciphersuites); - break; - default: + } else { throw new RuntimeException("Wrong parameter: " + args[0]); } - - System.out.println("Test passed"); } /* * Checks if that specified cipher suites cannot be used. */ private static void checkFailure(String[] ciphersuites) throws Exception { - try (SSLServer server = SSLServer.init(ciphersuites)) { + SSLServer server = null; + + try { + server = SSLServer.init(ciphersuites); startNewThread(server); while (!server.isRunning()) { sleep(); @@ -120,16 +118,21 @@ int port = server.getPort(); for (String ciphersuite : ciphersuites) { - try (SSLClient client = SSLClient.init(port, ciphersuite)) { + SSLClient client = null; + try { + client = SSLClient.init(port, ciphersuite); client.connect(); throw new RuntimeException("Expected SSLHandshakeException " + "not thrown"); } catch (SSLHandshakeException e) { System.out.println("Expected exception on client side: " + e); + } finally { + if (client != null) { client.close(); } } } + server.stop(); while (server.isRunning()) { sleep(); } @@ -138,15 +141,18 @@ throw new RuntimeException("Expected SSL exception " + "not thrown on server side"); } + } finally { + if (server != null ) { server.close(); } } - } /* * Checks if specified cipher suites can be used. */ private static void checkSuccess(String[] ciphersuites) throws Exception { - try (SSLServer server = SSLServer.init(ciphersuites)) { + SSLServer server = null; + try { + server = SSLServer.init(ciphersuites); startNewThread(server); while (!server.isRunning()) { sleep(); @@ -154,7 +160,9 @@ int port = server.getPort(); for (String ciphersuite : ciphersuites) { - try (SSLClient client = SSLClient.init(port, ciphersuite)) { + SSLClient client = null; + try { + client = SSLClient.init(port, ciphersuite); client.connect(); String negotiated = client.getNegotiatedCipherSuite(); System.out.println("Negotiated cipher suite: " @@ -163,6 +171,8 @@ throw new RuntimeException("Unexpected cipher suite: " + negotiated); } + } finally { + if (client != null) { client.close(); } } } @@ -174,6 +184,8 @@ if (server.error()) { throw new RuntimeException("Unexpected error on server side"); } + } finally { + if (server != null) { server.close(); } } } @@ -193,7 +205,7 @@ } } - static class SSLServer implements Runnable, AutoCloseable { + static class SSLServer implements Runnable { private final SSLServerSocket ssocket; private volatile boolean stopped = false; @@ -210,7 +222,9 @@ System.out.println("Server: started"); running = true; while (!stopped) { - try (SSLSocket socket = (SSLSocket) ssocket.accept()) { + SSLSocket socket = null; + try { + socket = (SSLSocket) ssocket.accept(); System.out.println("Server: accepted client connection"); InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); @@ -225,19 +239,16 @@ } catch (SSLHandshakeException e) { System.out.println("Server: run: " + e); sslError = true; - stopped = true; } catch (IOException e) { if (!stopped) { - System.out.println("Server: run: unexpected exception: " - + e); + System.out.println("Server: run: " + e); e.printStackTrace(); otherError = true; - stopped = true; - } else { - System.out.println("Server: run: " + e); - System.out.println("The exception above occurred " - + "because socket was closed, " - + "please ignore it"); + } + } finally { + if (socket != null ) { + try { socket.close(); } + catch (IOException e) { } } } } @@ -270,7 +281,6 @@ stopped = true; if (!ssocket.isClosed()) { try { - System.out.println("Server: close socket"); ssocket.close(); } catch (IOException e) { System.out.println("Server: close: " + e); @@ -278,7 +288,6 @@ } } - @Override public void close() { stop(); } @@ -300,7 +309,7 @@ } } - static class SSLClient implements AutoCloseable { + static class SSLClient { private final SSLSocket socket; @@ -310,11 +319,12 @@ void connect() throws IOException { System.out.println("Client: connect to server"); - try ( - BufferedInputStream bis = new BufferedInputStream( - socket.getInputStream()); - BufferedOutputStream bos = new BufferedOutputStream( - socket.getOutputStream())) { + BufferedInputStream bis = null; + BufferedOutputStream bos = null; + try { + bis = new BufferedInputStream(socket.getInputStream()); + bos = new BufferedOutputStream(socket.getOutputStream()); + bos.write('x'); bos.flush(); @@ -323,6 +333,9 @@ throw new IOException("Client: couldn't read a response"); } socket.getSession().invalidate(); + } finally { + if (bis != null) { bis.close(); } + if (bos != null) { bos.close(); } } } @@ -334,7 +347,6 @@ return socket.getSession().getCipherSuite(); } - @Override public void close() throws Exception { if (!socket.isClosed()) { try {