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.
This commit is contained in:
Scott Mitchell 2015-05-22 14:05:39 -07:00
parent 0f28bdf7bb
commit d5f1dc66aa

View File

@ -16,17 +16,19 @@
package io.netty.handler.ssl; package io.netty.handler.ssl;
import static io.netty.util.internal.ObjectUtil.checkNotNull; import static io.netty.util.internal.ObjectUtil.checkNotNull;
import io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelectionListener; import io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelectionListener;
import io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelector; import io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelector;
import org.eclipse.jetty.alpn.ALPN;
import org.eclipse.jetty.alpn.ALPN.ClientProvider; import java.util.LinkedHashSet;
import org.eclipse.jetty.alpn.ALPN.ServerProvider; import java.util.List;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import java.util.LinkedHashSet; import javax.net.ssl.SSLHandshakeException;
import java.util.List;
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 { final class JdkAlpnSslEngine extends JdkSslEngine {
private static boolean available; private static boolean available;
@ -63,12 +65,12 @@ final class JdkAlpnSslEngine extends JdkSslEngine {
public String select(List<String> protocols) throws SSLException { public String select(List<String> protocols) throws SSLException {
try { try {
return protocolSelector.select(protocols); return protocolSelector.select(protocols);
} catch (SSLException e) { } catch (SSLHandshakeException e) {
throw e; throw e;
} catch (Throwable t) { } catch (Throwable t) {
// Ensure that all exceptions are propagated as SSLExceptions SSLHandshakeException e = new SSLHandshakeException(t.getMessage());
// so that the SslHandler properly fails the handshake. e.initCause(t);
throw new SSLException(t); throw e;
} }
} }
@ -91,12 +93,12 @@ final class JdkAlpnSslEngine extends JdkSslEngine {
public void selected(String protocol) throws SSLException { public void selected(String protocol) throws SSLException {
try { try {
protocolListener.selected(protocol); protocolListener.selected(protocol);
} catch (SSLException e) { } catch (SSLHandshakeException e) {
throw e; throw e;
} catch (Throwable t) { } catch (Throwable t) {
// Ensure that all exceptions are propagated as SSLExceptions SSLHandshakeException e = new SSLHandshakeException(t.getMessage());
// so that the SslHandler properly fails the handshake. e.initCause(t);
throw new SSLException(t); throw e;
} }
} }