You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/08/12 16:13:53 UTC

svn commit: r1157115 - in /httpcomponents/httpcore/branches/4.1.x: ./ httpcore-ab/src/main/java/org/apache/http/benchmark/ httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/

Author: olegk
Date: Fri Aug 12 14:13:52 2011
New Revision: 1157115

URL: http://svn.apache.org/viewvc?rev=1157115&view=rev
Log:
HTTPCORE-268: handle runtime exceptions thrown by SSLEngine (merged from trunk)

Modified:
    httpcomponents/httpcore/branches/4.1.x/   (props changed)
    httpcomponents/httpcore/branches/4.1.x/RELEASE_NOTES.txt
    httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java   (props changed)
    httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/CommandLineUtils.java   (props changed)
    httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/Config.java   (props changed)
    httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/DefaultHeader.java   (props changed)
    httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/HttpBenchmark.java   (props changed)
    httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/ResultProcessor.java   (props changed)
    httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/Stats.java   (props changed)
    httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java

Propchange: httpcomponents/httpcore/branches/4.1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 12 14:13:52 2011
@@ -1,2 +1,2 @@
 /httpcomponents/httpcore/branches/ibm_compat_branch:755687-758898
-/httpcomponents/httpcore/trunk:1102241-1102657,1133031-1134569,1134571,1139799-1140255,1149742-1150202,1157055
+/httpcomponents/httpcore/trunk:1102241-1102657,1133031-1134569,1134571,1139799-1140255,1149742-1150202,1157055,1157114

Modified: httpcomponents/httpcore/branches/4.1.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.1.x/RELEASE_NOTES.txt?rev=1157115&r1=1157114&r2=1157115&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.1.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/branches/4.1.x/RELEASE_NOTES.txt Fri Aug 12 14:13:52 2011
@@ -1,3 +1,9 @@
+Changes since 4.1.3
+-------------------
+
+* [HTTPCORE-268] Handle runtime exceptions thrown by SSLEngine.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 Release 4.1.3
 -------------------
 

Propchange: httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 12 14:13:52 2011
@@ -1,2 +1,2 @@
 /httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-ab/src/main/java/org/apache/http/contrib/benchmark/BenchmarkWorker.java:755687-758898
-/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java:1157055
+/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java:1157055,1157114

Propchange: httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/CommandLineUtils.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 12 14:13:52 2011
@@ -1,2 +1,2 @@
 /httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-ab/src/main/java/org/apache/http/contrib/benchmark/CommandLineUtils.java:755687-758898
-/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/CommandLineUtils.java:1157055
+/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/CommandLineUtils.java:1157055,1157114

Propchange: httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/Config.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 12 14:13:52 2011
@@ -1,2 +1,2 @@
 /httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-ab/src/main/java/org/apache/http/contrib/benchmark/Config.java:755687-758898
-/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/Config.java:1157055
+/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/Config.java:1157055,1157114

Propchange: httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/DefaultHeader.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 12 14:13:52 2011
@@ -1,2 +1,2 @@
 /httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-ab/src/main/java/org/apache/http/contrib/benchmark/DefaultHeader.java:755687-758898
-/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/DefaultHeader.java:1157055
+/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/DefaultHeader.java:1157055,1157114

Propchange: httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/HttpBenchmark.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 12 14:13:52 2011
@@ -1,2 +1,2 @@
 /httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-ab/src/main/java/org/apache/http/contrib/benchmark/HttpBenchmark.java:755687-758898
-/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/HttpBenchmark.java:1157055
+/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/HttpBenchmark.java:1157055,1157114

Propchange: httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/ResultProcessor.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 12 14:13:52 2011
@@ -1,2 +1,2 @@
 /httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-ab/src/main/java/org/apache/http/contrib/benchmark/ResultProcessor.java:755687-758898
-/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/ResultProcessor.java:1157055
+/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/ResultProcessor.java:1157055,1157114

Propchange: httpcomponents/httpcore/branches/4.1.x/httpcore-ab/src/main/java/org/apache/http/benchmark/Stats.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 12 14:13:52 2011
@@ -1,2 +1,2 @@
 /httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-ab/src/main/java/org/apache/http/contrib/benchmark/Stats.java:755687-758898
-/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/Stats.java:1157055
+/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/Stats.java:1157055,1157114

Modified: httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java?rev=1157115&r1=1157114&r2=1157115&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java (original)
+++ httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java Fri Aug 12 14:13:52 2011
@@ -142,6 +142,46 @@ public class SSLIOSession implements IOS
         doHandshake();
     }
 
+    // A works-around for exception handling craziness in Sun/Oracle's SSLEngine
+    // implementation.
+    //
+    // sun.security.pkcs11.wrapper.PKCS11Exception is re-thrown as
+    // plain RuntimeException in sun.security.ssl.Handshaker#checkThrown
+    private SSLException convert(final RuntimeException ex) throws SSLException {
+		Throwable cause = ex.getCause();
+		if (cause == null) {
+			cause = ex;
+		}
+		return new SSLException(cause);
+    }
+
+    private SSLEngineResult doWrap(final ByteBuffer src, final ByteBuffer dst) throws SSLException {
+    	try {
+        	return this.sslEngine.wrap(src, dst);
+    	} catch (RuntimeException ex) {
+    		throw convert(ex);
+    	}
+    }
+
+    private SSLEngineResult doUnwrap(final ByteBuffer src, final ByteBuffer dst) throws SSLException {
+    	try {
+        	return this.sslEngine.unwrap(src, dst);
+    	} catch (RuntimeException ex) {
+    		throw convert(ex);
+    	}
+    }
+
+    private void doRunTask() throws SSLException {
+    	try {
+            Runnable r = this.sslEngine.getDelegatedTask();
+            if (r != null) {
+            	r.run();
+            }
+    	} catch (RuntimeException ex) {
+    		throw convert(ex);
+    	}
+    }
+
     private void doHandshake() throws SSLException {
         boolean handshaking = true;
 
@@ -151,7 +191,7 @@ public class SSLIOSession implements IOS
             case NEED_WRAP:
                 // Generate outgoing handshake data
                 this.outPlain.flip();
-                result = this.sslEngine.wrap(this.outPlain, this.outEncrypted);
+                result = doWrap(this.outPlain, this.outEncrypted);
                 this.outPlain.compact();
                 if (result.getStatus() != Status.OK) {
                     handshaking = false;
@@ -160,15 +200,14 @@ public class SSLIOSession implements IOS
             case NEED_UNWRAP:
                 // Process incoming handshake data
                 this.inEncrypted.flip();
-                result = this.sslEngine.unwrap(this.inEncrypted, this.inPlain);
+                result = doUnwrap(this.inEncrypted, this.inPlain);
                 this.inEncrypted.compact();
                 if (result.getStatus() != Status.OK) {
                     handshaking = false;
                 }
                 break;
             case NEED_TASK:
-                Runnable r = this.sslEngine.getDelegatedTask();
-                r.run();
+            	doRunTask();
                 break;
             case NOT_HANDSHAKING:
                 handshaking = false;
@@ -246,7 +285,7 @@ public class SSLIOSession implements IOS
         SSLEngineResult.Status opStatus = Status.OK;
         while (this.inEncrypted.position() > 0 && opStatus == Status.OK) {
             this.inEncrypted.flip();
-            SSLEngineResult result = this.sslEngine.unwrap(this.inEncrypted, this.inPlain);
+            SSLEngineResult result = doUnwrap(this.inEncrypted, this.inPlain);
             this.inEncrypted.compact();
 
             opStatus = result.getStatus();
@@ -302,11 +341,11 @@ public class SSLIOSession implements IOS
         }
         if (this.outPlain.position() > 0) {
             this.outPlain.flip();
-            this.sslEngine.wrap(this.outPlain, this.outEncrypted);
+            doWrap(this.outPlain, this.outEncrypted);
             this.outPlain.compact();
         }
         if (this.outPlain.position() == 0) {
-            SSLEngineResult result = this.sslEngine.wrap(src, this.outEncrypted);
+            SSLEngineResult result = doWrap(src, this.outEncrypted);
             if (result.getStatus() == Status.CLOSED) {
                 this.status = CLOSED;
             }