Fix SSL + BIO + Java 7
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 23 Sep 2011 16:58:50 +0000 (16:58 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 23 Sep 2011 16:58:50 +0000 (16:58 +0000)
The implementation of InputStream.read(byte[0]) has changed so it always returns zero without checking for EOF. This broke the old way of doing things.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1174884 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/net/jsse/JSSESupport.java

index 6d9edbd..f0fcfd9 100644 (file)
@@ -175,7 +175,7 @@ class JSSESupport implements SSLSupport, SSLSessionManager {
         InputStream in = ssl.getInputStream();
         int oldTimeout = ssl.getSoTimeout();
         ssl.setSoTimeout(1000);
-        byte[] b = new byte[0];
+        byte[] b = new byte[1];
         listener.reset();
         ssl.startHandshake();
         int maxTries = 60; // 60 * 1000 = example 1 minute time out
@@ -183,7 +183,14 @@ class JSSESupport implements SSLSupport, SSLSessionManager {
             if (log.isTraceEnabled())
                 log.trace("Reading for try #" + i);
             try {
-                in.read(b);
+                int read = in.read(b);
+                if (read > 0) {
+                    // Shouldn't happen as all input should have been swallowed
+                    // before trying to do the handshake. If it does, something
+                    // went wrong so lets bomb out now.
+                    throw new SSLException(
+                            sm.getString("jsseSupport.unexpectedData"));
+                }
             } catch(SSLException sslex) {
                 log.info(sm.getString("jsseSupport.clientCertError"), sslex);
                 throw sslex;