99ce156
From f7b8e27b5f55c4a21cf84fb56a616b8bfd4af8da Mon Sep 17 00:00:00 2001
99ce156
From: Michael Simacek <msimacek@redhat.com>
99ce156
Date: Fri, 7 Jul 2017 16:07:23 +0200
99ce156
Subject: [PATCH 2/3] Remove NPN
99ce156
99ce156
---
99ce156
 handler/pom.xml                                    |   5 -
99ce156
 .../ssl/JdkNpnApplicationProtocolNegotiator.java   | 120 --------------------
99ce156
 .../java/io/netty/handler/ssl/JdkSslContext.java   |  30 -----
99ce156
 .../io/netty/handler/ssl/JettyNpnSslEngine.java    | 122 ---------------------
99ce156
 .../io/netty/handler/ssl/JdkSslEngineTest.java     |   2 +-
99ce156
 5 files changed, 1 insertion(+), 278 deletions(-)
99ce156
 delete mode 100644 handler/src/main/java/io/netty/handler/ssl/JdkNpnApplicationProtocolNegotiator.java
99ce156
 delete mode 100644 handler/src/main/java/io/netty/handler/ssl/JettyNpnSslEngine.java
99ce156
99ce156
diff --git a/handler/pom.xml b/handler/pom.xml
99ce156
index d0ed1bc..52e63ca 100644
99ce156
--- a/handler/pom.xml
99ce156
+++ b/handler/pom.xml
99ce156
@@ -55,11 +55,6 @@
99ce156
       <optional>true</optional>
99ce156
     </dependency>
99ce156
     <dependency>
99ce156
-      <groupId>org.eclipse.jetty.npn</groupId>
99ce156
-      <artifactId>npn-api</artifactId>
99ce156
-      <optional>true</optional>
99ce156
-    </dependency>
99ce156
-    <dependency>
99ce156
       <groupId>org.eclipse.jetty.alpn</groupId>
99ce156
       <artifactId>alpn-api</artifactId>
99ce156
       <optional>true</optional>
99ce156
diff --git a/handler/src/main/java/io/netty/handler/ssl/JdkNpnApplicationProtocolNegotiator.java b/handler/src/main/java/io/netty/handler/ssl/JdkNpnApplicationProtocolNegotiator.java
99ce156
deleted file mode 100644
99ce156
index 06b29b7..0000000
99ce156
--- a/handler/src/main/java/io/netty/handler/ssl/JdkNpnApplicationProtocolNegotiator.java
99ce156
+++ /dev/null
99ce156
@@ -1,120 +0,0 @@
99ce156
-/*
99ce156
- * Copyright 2014 The Netty Project
99ce156
- *
99ce156
- * The Netty Project licenses this file to you under the Apache License,
99ce156
- * version 2.0 (the "License"); you may not use this file except in compliance
99ce156
- * with the License. You may obtain a copy of the License at:
99ce156
- *
99ce156
- *   http://www.apache.org/licenses/LICENSE-2.0
99ce156
- *
99ce156
- * Unless required by applicable law or agreed to in writing, software
99ce156
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
99ce156
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
99ce156
- * License for the specific language governing permissions and limitations
99ce156
- * under the License.
99ce156
- */
99ce156
-package io.netty.handler.ssl;
99ce156
-
99ce156
-import javax.net.ssl.SSLEngine;
99ce156
-
99ce156
-/**
99ce156
- * The {@link JdkApplicationProtocolNegotiator} to use if you need NPN and are using {@link SslProvider#JDK}.
99ce156
- */
99ce156
-public final class JdkNpnApplicationProtocolNegotiator extends JdkBaseApplicationProtocolNegotiator {
99ce156
-    private static final SslEngineWrapperFactory NPN_WRAPPER = new SslEngineWrapperFactory() {
99ce156
-        {
99ce156
-            if (!JettyNpnSslEngine.isAvailable()) {
99ce156
-                throw new RuntimeException("NPN unsupported. Is your classpath configured correctly?"
99ce156
-                        + " See https://wiki.eclipse.org/Jetty/Feature/NPN");
99ce156
-            }
99ce156
-        }
99ce156
-
99ce156
-        @Override
99ce156
-        public SSLEngine wrapSslEngine(SSLEngine engine, JdkApplicationProtocolNegotiator applicationNegotiator,
99ce156
-                boolean isServer) {
99ce156
-            return new JettyNpnSslEngine(engine, applicationNegotiator, isServer);
99ce156
-        }
99ce156
-    };
99ce156
-
99ce156
-    /**
99ce156
-     * Create a new instance.
99ce156
-     * @param protocols The order of iteration determines the preference of support for protocols.
99ce156
-     */
99ce156
-    public JdkNpnApplicationProtocolNegotiator(Iterable<String> protocols) {
99ce156
-        this(false, protocols);
99ce156
-    }
99ce156
-
99ce156
-    /**
99ce156
-     * Create a new instance.
99ce156
-     * @param protocols The order of iteration determines the preference of support for protocols.
99ce156
-     */
99ce156
-    public JdkNpnApplicationProtocolNegotiator(String... protocols) {
99ce156
-        this(false, protocols);
99ce156
-    }
99ce156
-
99ce156
-    /**
99ce156
-     * Create a new instance.
99ce156
-     * @param failIfNoCommonProtocols Fail with a fatal alert if not common protocols are detected.
99ce156
-     * @param protocols The order of iteration determines the preference of support for protocols.
99ce156
-     */
99ce156
-    public JdkNpnApplicationProtocolNegotiator(boolean failIfNoCommonProtocols, Iterable<String> protocols) {
99ce156
-        this(failIfNoCommonProtocols, failIfNoCommonProtocols, protocols);
99ce156
-    }
99ce156
-
99ce156
-    /**
99ce156
-     * Create a new instance.
99ce156
-     * @param failIfNoCommonProtocols Fail with a fatal alert if not common protocols are detected.
99ce156
-     * @param protocols The order of iteration determines the preference of support for protocols.
99ce156
-     */
99ce156
-    public JdkNpnApplicationProtocolNegotiator(boolean failIfNoCommonProtocols, String... protocols) {
99ce156
-        this(failIfNoCommonProtocols, failIfNoCommonProtocols, protocols);
99ce156
-    }
99ce156
-
99ce156
-    /**
99ce156
-     * Create a new instance.
99ce156
-     * @param clientFailIfNoCommonProtocols Client side fail with a fatal alert if not common protocols are detected.
99ce156
-     * @param serverFailIfNoCommonProtocols Server side fail with a fatal alert if not common protocols are detected.
99ce156
-     * @param protocols The order of iteration determines the preference of support for protocols.
99ce156
-     */
99ce156
-    public JdkNpnApplicationProtocolNegotiator(boolean clientFailIfNoCommonProtocols,
99ce156
-            boolean serverFailIfNoCommonProtocols, Iterable<String> protocols) {
99ce156
-        this(clientFailIfNoCommonProtocols ? FAIL_SELECTOR_FACTORY : NO_FAIL_SELECTOR_FACTORY,
99ce156
-                serverFailIfNoCommonProtocols ? FAIL_SELECTION_LISTENER_FACTORY : NO_FAIL_SELECTION_LISTENER_FACTORY,
99ce156
-                protocols);
99ce156
-    }
99ce156
-
99ce156
-    /**
99ce156
-     * Create a new instance.
99ce156
-     * @param clientFailIfNoCommonProtocols Client side fail with a fatal alert if not common protocols are detected.
99ce156
-     * @param serverFailIfNoCommonProtocols Server side fail with a fatal alert if not common protocols are detected.
99ce156
-     * @param protocols The order of iteration determines the preference of support for protocols.
99ce156
-     */
99ce156
-    public JdkNpnApplicationProtocolNegotiator(boolean clientFailIfNoCommonProtocols,
99ce156
-            boolean serverFailIfNoCommonProtocols, String... protocols) {
99ce156
-        this(clientFailIfNoCommonProtocols ? FAIL_SELECTOR_FACTORY : NO_FAIL_SELECTOR_FACTORY,
99ce156
-                serverFailIfNoCommonProtocols ? FAIL_SELECTION_LISTENER_FACTORY : NO_FAIL_SELECTION_LISTENER_FACTORY,
99ce156
-                protocols);
99ce156
-    }
99ce156
-
99ce156
-    /**
99ce156
-     * Create a new instance.
99ce156
-     * @param selectorFactory The factory which provides classes responsible for selecting the protocol.
99ce156
-     * @param listenerFactory The factory which provides to be notified of which protocol was selected.
99ce156
-     * @param protocols The order of iteration determines the preference of support for protocols.
99ce156
-     */
99ce156
-    public JdkNpnApplicationProtocolNegotiator(ProtocolSelectorFactory selectorFactory,
99ce156
-            ProtocolSelectionListenerFactory listenerFactory, Iterable<String> protocols) {
99ce156
-        super(NPN_WRAPPER, selectorFactory, listenerFactory, protocols);
99ce156
-    }
99ce156
-
99ce156
-    /**
99ce156
-     * Create a new instance.
99ce156
-     * @param selectorFactory The factory which provides classes responsible for selecting the protocol.
99ce156
-     * @param listenerFactory The factory which provides to be notified of which protocol was selected.
99ce156
-     * @param protocols The order of iteration determines the preference of support for protocols.
99ce156
-     */
99ce156
-    public JdkNpnApplicationProtocolNegotiator(ProtocolSelectorFactory selectorFactory,
99ce156
-            ProtocolSelectionListenerFactory listenerFactory, String... protocols) {
99ce156
-        super(NPN_WRAPPER, selectorFactory, listenerFactory, protocols);
99ce156
-    }
99ce156
-}
99ce156
diff --git a/handler/src/main/java/io/netty/handler/ssl/JdkSslContext.java b/handler/src/main/java/io/netty/handler/ssl/JdkSslContext.java
99ce156
index 0ad6639..d5b86ff 100644
99ce156
--- a/handler/src/main/java/io/netty/handler/ssl/JdkSslContext.java
99ce156
+++ b/handler/src/main/java/io/netty/handler/ssl/JdkSslContext.java
99ce156
@@ -288,47 +288,17 @@ public class JdkSslContext extends SslContext {
99ce156
         case ALPN:
99ce156
             if (isServer) {
99ce156
                 switch(config.selectorFailureBehavior()) {
99ce156
-                case FATAL_ALERT:
99ce156
-                    return new JdkAlpnApplicationProtocolNegotiator(true, config.supportedProtocols());
99ce156
-                case NO_ADVERTISE:
99ce156
-                    return new JdkAlpnApplicationProtocolNegotiator(false, config.supportedProtocols());
99ce156
                 default:
99ce156
                     throw new UnsupportedOperationException(new StringBuilder("JDK provider does not support ")
99ce156
                     .append(config.selectorFailureBehavior()).append(" failure behavior").toString());
99ce156
                 }
99ce156
             } else {
99ce156
                 switch(config.selectedListenerFailureBehavior()) {
99ce156
-                case ACCEPT:
99ce156
-                    return new JdkAlpnApplicationProtocolNegotiator(false, config.supportedProtocols());
99ce156
-                case FATAL_ALERT:
99ce156
-                    return new JdkAlpnApplicationProtocolNegotiator(true, config.supportedProtocols());
99ce156
                 default:
99ce156
                     throw new UnsupportedOperationException(new StringBuilder("JDK provider does not support ")
99ce156
                     .append(config.selectedListenerFailureBehavior()).append(" failure behavior").toString());
99ce156
                 }
99ce156
             }
99ce156
-        case NPN:
99ce156
-            if (isServer) {
99ce156
-                switch(config.selectedListenerFailureBehavior()) {
99ce156
-                case ACCEPT:
99ce156
-                    return new JdkNpnApplicationProtocolNegotiator(false, config.supportedProtocols());
99ce156
-                case FATAL_ALERT:
99ce156
-                    return new JdkNpnApplicationProtocolNegotiator(true, config.supportedProtocols());
99ce156
-                default:
99ce156
-                    throw new UnsupportedOperationException(new StringBuilder("JDK provider does not support ")
99ce156
-                    .append(config.selectedListenerFailureBehavior()).append(" failure behavior").toString());
99ce156
-                }
99ce156
-            } else {
99ce156
-                switch(config.selectorFailureBehavior()) {
99ce156
-                case FATAL_ALERT:
99ce156
-                    return new JdkNpnApplicationProtocolNegotiator(true, config.supportedProtocols());
99ce156
-                case NO_ADVERTISE:
99ce156
-                    return new JdkNpnApplicationProtocolNegotiator(false, config.supportedProtocols());
99ce156
-                default:
99ce156
-                    throw new UnsupportedOperationException(new StringBuilder("JDK provider does not support ")
99ce156
-                    .append(config.selectorFailureBehavior()).append(" failure behavior").toString());
99ce156
-                }
99ce156
-            }
99ce156
         default:
99ce156
             throw new UnsupportedOperationException(new StringBuilder("JDK provider does not support ")
99ce156
             .append(config.protocol()).append(" protocol").toString());
99ce156
diff --git a/handler/src/main/java/io/netty/handler/ssl/JettyNpnSslEngine.java b/handler/src/main/java/io/netty/handler/ssl/JettyNpnSslEngine.java
99ce156
deleted file mode 100644
99ce156
index 77e7366..0000000
99ce156
--- a/handler/src/main/java/io/netty/handler/ssl/JettyNpnSslEngine.java
99ce156
+++ /dev/null
99ce156
@@ -1,122 +0,0 @@
99ce156
-/*
99ce156
- * Copyright 2014 The Netty Project
99ce156
- *
99ce156
- * The Netty Project licenses this file to you under the Apache License,
99ce156
- * version 2.0 (the "License"); you may not use this file except in compliance
99ce156
- * with the License. You may obtain a copy of the License at:
99ce156
- *
99ce156
- *   http://www.apache.org/licenses/LICENSE-2.0
99ce156
- *
99ce156
- * Unless required by applicable law or agreed to in writing, software
99ce156
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
99ce156
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
99ce156
- * License for the specific language governing permissions and limitations
99ce156
- * under the License.
99ce156
- */
99ce156
-
99ce156
-package io.netty.handler.ssl;
99ce156
-
99ce156
-import static io.netty.util.internal.ObjectUtil.checkNotNull;
99ce156
-import io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelectionListener;
99ce156
-import io.netty.handler.ssl.JdkApplicationProtocolNegotiator.ProtocolSelector;
99ce156
-import io.netty.util.internal.PlatformDependent;
99ce156
-
99ce156
-import java.util.LinkedHashSet;
99ce156
-import java.util.List;
99ce156
-
99ce156
-import javax.net.ssl.SSLEngine;
99ce156
-import javax.net.ssl.SSLException;
99ce156
-
99ce156
-import org.eclipse.jetty.npn.NextProtoNego;
99ce156
-import org.eclipse.jetty.npn.NextProtoNego.ClientProvider;
99ce156
-import org.eclipse.jetty.npn.NextProtoNego.ServerProvider;
99ce156
-
99ce156
-final class JettyNpnSslEngine extends JdkSslEngine {
99ce156
-    private static boolean available;
99ce156
-
99ce156
-    static boolean isAvailable() {
99ce156
-        updateAvailability();
99ce156
-        return available;
99ce156
-    }
99ce156
-
99ce156
-    private static void updateAvailability() {
99ce156
-        if (available) {
99ce156
-            return;
99ce156
-        }
99ce156
-        try {
99ce156
-            // Always use bootstrap class loader.
99ce156
-            Class.forName("sun.security.ssl.NextProtoNegoExtension", true, null);
99ce156
-            available = true;
99ce156
-        } catch (Exception ignore) {
99ce156
-            // npn-boot was not loaded.
99ce156
-        }
99ce156
-    }
99ce156
-
99ce156
-    JettyNpnSslEngine(SSLEngine engine, final JdkApplicationProtocolNegotiator applicationNegotiator, boolean server) {
99ce156
-        super(engine);
99ce156
-        checkNotNull(applicationNegotiator, "applicationNegotiator");
99ce156
-
99ce156
-        if (server) {
99ce156
-            final ProtocolSelectionListener protocolListener = checkNotNull(applicationNegotiator
99ce156
-                    .protocolListenerFactory().newListener(this, applicationNegotiator.protocols()),
99ce156
-                    "protocolListener");
99ce156
-            NextProtoNego.put(engine, new ServerProvider() {
99ce156
-                @Override
99ce156
-                public void unsupported() {
99ce156
-                    protocolListener.unsupported();
99ce156
-                }
99ce156
-
99ce156
-                @Override
99ce156
-                public List<String> protocols() {
99ce156
-                    return applicationNegotiator.protocols();
99ce156
-                }
99ce156
-
99ce156
-                @Override
99ce156
-                public void protocolSelected(String protocol) {
99ce156
-                    try {
99ce156
-                        protocolListener.selected(protocol);
99ce156
-                    } catch (Throwable t) {
99ce156
-                        PlatformDependent.throwException(t);
99ce156
-                    }
99ce156
-                }
99ce156
-            });
99ce156
-        } else {
99ce156
-            final ProtocolSelector protocolSelector = checkNotNull(applicationNegotiator.protocolSelectorFactory()
99ce156
-                    .newSelector(this, new LinkedHashSet<String>(applicationNegotiator.protocols())),
99ce156
-                    "protocolSelector");
99ce156
-            NextProtoNego.put(engine, new ClientProvider() {
99ce156
-                @Override
99ce156
-                public boolean supports() {
99ce156
-                    return true;
99ce156
-                }
99ce156
-
99ce156
-                @Override
99ce156
-                public void unsupported() {
99ce156
-                    protocolSelector.unsupported();
99ce156
-                }
99ce156
-
99ce156
-                @Override
99ce156
-                public String selectProtocol(List<String> protocols) {
99ce156
-                    try {
99ce156
-                        return protocolSelector.select(protocols);
99ce156
-                    } catch (Throwable t) {
99ce156
-                        PlatformDependent.throwException(t);
99ce156
-                        return null;
99ce156
-                    }
99ce156
-                }
99ce156
-            });
99ce156
-        }
99ce156
-    }
99ce156
-
99ce156
-    @Override
99ce156
-    public void closeInbound() throws SSLException {
99ce156
-        NextProtoNego.remove(getWrappedEngine());
99ce156
-        super.closeInbound();
99ce156
-    }
99ce156
-
99ce156
-    @Override
99ce156
-    public void closeOutbound() {
99ce156
-        NextProtoNego.remove(getWrappedEngine());
99ce156
-        super.closeOutbound();
99ce156
-    }
99ce156
-}
99ce156
diff --git a/handler/src/test/java/io/netty/handler/ssl/JdkSslEngineTest.java b/handler/src/test/java/io/netty/handler/ssl/JdkSslEngineTest.java
99ce156
index d6cd94d..4489b16 100644
99ce156
--- a/handler/src/test/java/io/netty/handler/ssl/JdkSslEngineTest.java
99ce156
+++ b/handler/src/test/java/io/netty/handler/ssl/JdkSslEngineTest.java
99ce156
@@ -46,7 +46,7 @@ public class JdkSslEngineTest extends SSLEngineTest {
99ce156
         NPN_DEFAULT {
99ce156
             @Override
99ce156
             boolean isAvailable() {
99ce156
-                return JettyNpnSslEngine.isAvailable();
99ce156
+                return false;
99ce156
             }
99ce156
 
99ce156
             @Override
99ce156
-- 
99ce156
2.9.4
99ce156