Prevent SSLEngineKeyLimit from hanging JDK-8145252-TLS13-branch
authorascarpino
Fri, 01 Jun 2018 08:11:45 -0700
branchJDK-8145252-TLS13-branch
changeset 56650 6a168579df31
parent 56649 50595f26ea8a
child 56651 0c13b82d3274
Prevent SSLEngineKeyLimit from hanging
test/jdk/sun/security/ssl/SSLEngineImpl/SSLEngineKeyLimit.java
--- a/test/jdk/sun/security/ssl/SSLEngineImpl/SSLEngineKeyLimit.java	Fri Jun 01 10:07:24 2018 -0400
+++ b/test/jdk/sun/security/ssl/SSLEngineImpl/SSLEngineKeyLimit.java	Fri Jun 01 08:11:45 2018 -0700
@@ -68,15 +68,17 @@
 
     static String pathToStores = "../../../../javax/net/ssl/etc/";
     static String keyStoreFile = "keystore";
-    static String trustStoreFile = "truststore";
     static String passwd = "passphrase";
     static String keyFilename;
     static int dataLen = 10240;
     static boolean serverwrite = true;
     int totalDataLen = 0;
     static boolean sc = true;
+    int delay = 1;
+    static boolean readdone = false;
+
+    // Turn on debugging
     static boolean debug = false;
-    int delay = 1;
 
     SSLEngineKeyLimit() {
         buf = ByteBuffer.allocate(dataLen*4);
@@ -180,7 +182,7 @@
         if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_TASK) {
             Runnable runnable;
             while ((runnable = engine.getDelegatedTask()) != null) {
-                System.out.println("\trunning delegated task...");
+                print("\trunning delegated task...");
                 runnable.run();
             }
             SSLEngineResult.HandshakeStatus hsStatus = engine.getHandshakeStatus();
@@ -220,6 +222,9 @@
 
         while (i++ < 120) {
             while (sc) {
+                if (readdone) {
+                    return;
+                }
                 Thread.sleep(delay);
             }
 
@@ -230,11 +235,11 @@
                 r = eng.wrap(outdata, getWriteBuf());
                 log("write wrap", r);
                 if (debug && r.getStatus() != SSLEngineResult.Status.OK) {
-                    System.out.println("outdata pos: " + outdata.position() +
+                    print("outdata pos: " + outdata.position() +
                             " rem: " + outdata.remaining() +
                             " lim: " + outdata.limit() +
                             " cap: " + outdata.capacity());
-                    System.out.println("writebuf pos: " + getWriteBuf().position() +
+                    print("writebuf pos: " + getWriteBuf().position() +
                             " rem: " + getWriteBuf().remaining() +
                             " lim: " + getWriteBuf().limit() +
                             " cap: " + getWriteBuf().capacity());
@@ -251,6 +256,9 @@
             getWriteBuf().flip();
             sc = true;
             while (sc) {
+                if (readdone) {
+                    return;
+                }
                 Thread.sleep(delay);
             }
 
@@ -259,11 +267,11 @@
                 r = eng.unwrap(getReadBuf(), buf);
                 log("write unwrap", r);
                 if (debug && r.getStatus() != SSLEngineResult.Status.OK) {
-                    System.out.println("buf pos: " + buf.position() +
+                    print("buf pos: " + buf.position() +
                             " rem: " + buf.remaining() +
                             " lim: " + buf.limit() +
                             " cap: " + buf.capacity());
-                    System.out.println("readbuf pos: " + getReadBuf().position() +
+                    print("readbuf pos: " + getReadBuf().position() +
                             " rem: " + getReadBuf().remaining() +
                             " lim: " + getReadBuf().limit() +
                             " cap:"  + getReadBuf().capacity());
@@ -307,11 +315,11 @@
                     buf2.flip();
                     r = eng.wrap(buf2, getWriteBuf());
                     log("read wrap", r);
-                    if (debug ) { //&& r.getStatus() != SSLEngineResult.Status.OK) {
-                        System.out.println("buf2 pos: " + buf2.position() +
+                    if (debug) { //&& r.getStatus() != SSLEngineResult.Status.OK) {
+                        print("buf2 pos: " + buf2.position() +
                                 " rem: " + buf2.remaining() +
                                 " cap: " + buf2.capacity());
-                        System.out.println("writebuf pos: " + getWriteBuf().position() +
+                        print("writebuf pos: " + getWriteBuf().position() +
                                 " rem: " + getWriteBuf().remaining() +
                                 " cap: " + getWriteBuf().capacity());
                     }
@@ -338,11 +346,11 @@
                         r = eng.unwrap(getReadBuf(), buf);
                         log("read unwrap", r);
                         if (debug && r.getStatus() != SSLEngineResult.Status.OK) {
-                            System.out.println("buf pos " + buf.position() +
+                            print("buf pos " + buf.position() +
                                     " rem: " + buf.remaining() +
                                     " lim: " + buf.limit() +
                                     " cap: " + buf.capacity());
-                            System.out.println("readbuf pos: " + getReadBuf().position() +
+                            print("readbuf pos: " + getReadBuf().position() +
                                     " rem: " + getReadBuf().remaining() +
                                     " lim: " + getReadBuf().limit() +
                                     " cap: " + getReadBuf().capacity());
@@ -366,10 +374,12 @@
                 sc = false;
             }
         } catch (Exception e) {
+            sc = false;
+            readdone = true;
             System.out.println(e.getMessage());
             e.printStackTrace();
+            print("Total data read = " + totalDataLen);
         }
-        print("TotalDataLen = " + totalDataLen);
     }
 
     ByteBuffer getReadBuf() {
@@ -447,6 +457,7 @@
                 System.out.println("client: " + e.getMessage());
                 e.printStackTrace();
             }
+            System.out.println("Client closed");
         }
         @Override
         ByteBuffer getWriteBuf() {