--- old/test/jdk/sun/net/www/protocol/https/ChunkedOutputStream.java 2019-08-13 16:22:26.000000000 +0100 +++ new/test/jdk/sun/net/www/protocol/https/ChunkedOutputStream.java 2019-08-13 16:22:26.000000000 +0100 @@ -138,6 +138,17 @@ } } + public boolean closeOnException(Exception ex) { + if (ex instanceof SSLException) { + if (ex.toString().contains("Unrecognized SSL message, plaintext connection?")) { + System.out.println("TestHttpsServer receveived rogue connection: " + ex); + System.out.println("Ignoring rogue connection..."); + return true; + } + } + return false; + } + static void readAndCompare(InputStream is, String cmp) throws IOException { int c; byte buf[] = new byte[1024]; --- old/test/jdk/sun/net/www/protocol/https/HttpCallback.java 2019-08-13 16:22:28.000000000 +0100 +++ new/test/jdk/sun/net/www/protocol/https/HttpCallback.java 2019-08-13 16:22:27.000000000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,4 +36,14 @@ * client and used to send the response */ void request (HttpTransaction msg); + + /** + * Tells whether the server should simply close the + * connection and ignore the request when an exception + * occurs. Default is to propagate the exception. + * @return true if the request should be ignored. + **/ + default boolean closeOnException(Exception ex) { + return false; + } } --- old/test/jdk/sun/net/www/protocol/https/TestHttpsServer.java 2019-08-13 16:22:29.000000000 +0100 +++ new/test/jdk/sun/net/www/protocol/https/TestHttpsServer.java 2019-08-13 16:22:29.000000000 +0100 @@ -316,6 +316,7 @@ HttpCallback cb; HandshakeStatus currentHSStatus; boolean initialHSComplete; + boolean handshakeStarted; /* * All inbound data goes through this buffer. * @@ -372,7 +373,19 @@ * be generated here. */ inNetBB.flip(); - result = sslEng.unwrap(inNetBB, inAppBB); + try { + result = sslEng.unwrap(inNetBB, inAppBB); + if (bytes > 0) handshakeStarted = true; + } catch(SSLException se) { + // Sometime a rogue client may try to open a plain + // connection with our server. Calling this method + // gives a chance to the test logic to ignore such + // rogue connections. + if (!handshakeStarted && cb.closeOnException(se)) { + try { schan.close(); } catch (IOException x) { }; + return; + } else throw se; + } inNetBB.compact(); currentHSStatus = result.getHandshakeStatus();