From d5f1dc66aa6e7290d3c1e0b8f5982ad553e2b15a Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Fri, 22 May 2015 14:05:39 -0700 Subject: [PATCH] Consistent use of SSLHandshakeException for ALPN Motiviation: The OpenSSL engine uses SSLHandshakeException in the event of failures that occur during the handshake process. The alpn-boot project's getSSLException will also map the no_application_protocol to a SSLHandshakeException exception. We should be consistent and use SSLHandshakeException for handshake failure events. Modifications: -Update JdkAlpnSslEngine to propagate an SSLHandshakeException in the event of a failure. Result: Consistent usage of SSLHandshakeException during a handshake failure event. --- .../netty/handler/ssl/JdkAlpnSslEngine.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java b/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java index 5390c738ee..bdf3aca146 100644 --- a/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java +++ b/handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java @@ -16,17 +16,19 @@ package io.netty.handler.ssl; import static io.netty.util.internal.ObjectUtil.checkNotNull; - import io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelectionListener; import io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelector; -import org.eclipse.jetty.alpn.ALPN; -import org.eclipse.jetty.alpn.ALPN.ClientProvider; -import org.eclipse.jetty.alpn.ALPN.ServerProvider; + +import java.util.LinkedHashSet; +import java.util.List; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; -import java.util.LinkedHashSet; -import java.util.List; +import javax.net.ssl.SSLHandshakeException; + +import org.eclipse.jetty.alpn.ALPN; +import org.eclipse.jetty.alpn.ALPN.ClientProvider; +import org.eclipse.jetty.alpn.ALPN.ServerProvider; final class JdkAlpnSslEngine extends JdkSslEngine { private static boolean available; @@ -63,12 +65,12 @@ final class JdkAlpnSslEngine extends JdkSslEngine { public String select(List protocols) throws SSLException { try { return protocolSelector.select(protocols); - } catch (SSLException e) { + } catch (SSLHandshakeException e) { throw e; } catch (Throwable t) { - // Ensure that all exceptions are propagated as SSLExceptions - // so that the SslHandler properly fails the handshake. - throw new SSLException(t); + SSLHandshakeException e = new SSLHandshakeException(t.getMessage()); + e.initCause(t); + throw e; } } @@ -91,12 +93,12 @@ final class JdkAlpnSslEngine extends JdkSslEngine { public void selected(String protocol) throws SSLException { try { protocolListener.selected(protocol); - } catch (SSLException e) { + } catch (SSLHandshakeException e) { throw e; } catch (Throwable t) { - // Ensure that all exceptions are propagated as SSLExceptions - // so that the SslHandler properly fails the handshake. - throw new SSLException(t); + SSLHandshakeException e = new SSLHandshakeException(t.getMessage()); + e.initCause(t); + throw e; } }