1 /* 2 * Copyright 2014 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package io.netty5.handler.ssl; 17 18 import javax.net.ssl.SSLEngine; 19 20 /** 21 * The {@link JdkApplicationProtocolNegotiator} to use if you need NPN and are using {@link SslProvider#JDK}. 22 * 23 * @deprecated use {@link ApplicationProtocolConfig}. 24 */ 25 @Deprecated 26 public final class JdkNpnApplicationProtocolNegotiator extends JdkBaseApplicationProtocolNegotiator { 27 private static final SslEngineWrapperFactory NPN_WRAPPER = new SslEngineWrapperFactory() { 28 { 29 if (!JettyNpnSslEngine.isAvailable()) { 30 throw new RuntimeException("NPN unsupported. Is your classpath configured correctly?" 31 + " See https://wiki.eclipse.org/Jetty/Feature/NPN"); 32 } 33 } 34 35 @Override 36 public SSLEngine wrapSslEngine(SSLEngine engine, 37 JdkApplicationProtocolNegotiator applicationNegotiator, boolean isServer) { 38 return new JettyNpnSslEngine(engine, applicationNegotiator, isServer); 39 } 40 }; 41 42 /** 43 * Create a new instance. 44 * @param protocols The order of iteration determines the preference of support for protocols. 45 */ 46 public JdkNpnApplicationProtocolNegotiator(Iterable<String> protocols) { 47 this(false, protocols); 48 } 49 50 /** 51 * Create a new instance. 52 * @param protocols The order of iteration determines the preference of support for protocols. 53 */ 54 public JdkNpnApplicationProtocolNegotiator(String... protocols) { 55 this(false, protocols); 56 } 57 58 /** 59 * Create a new instance. 60 * @param failIfNoCommonProtocols Fail with a fatal alert if not common protocols are detected. 61 * @param protocols The order of iteration determines the preference of support for protocols. 62 */ 63 public JdkNpnApplicationProtocolNegotiator(boolean failIfNoCommonProtocols, Iterable<String> protocols) { 64 this(failIfNoCommonProtocols, failIfNoCommonProtocols, protocols); 65 } 66 67 /** 68 * Create a new instance. 69 * @param failIfNoCommonProtocols Fail with a fatal alert if not common protocols are detected. 70 * @param protocols The order of iteration determines the preference of support for protocols. 71 */ 72 public JdkNpnApplicationProtocolNegotiator(boolean failIfNoCommonProtocols, String... protocols) { 73 this(failIfNoCommonProtocols, failIfNoCommonProtocols, protocols); 74 } 75 76 /** 77 * Create a new instance. 78 * @param clientFailIfNoCommonProtocols Client side fail with a fatal alert if not common protocols are detected. 79 * @param serverFailIfNoCommonProtocols Server side fail with a fatal alert if not common protocols are detected. 80 * @param protocols The order of iteration determines the preference of support for protocols. 81 */ 82 public JdkNpnApplicationProtocolNegotiator(boolean clientFailIfNoCommonProtocols, 83 boolean serverFailIfNoCommonProtocols, Iterable<String> protocols) { 84 this(clientFailIfNoCommonProtocols ? FAIL_SELECTOR_FACTORY : NO_FAIL_SELECTOR_FACTORY, 85 serverFailIfNoCommonProtocols ? FAIL_SELECTION_LISTENER_FACTORY : NO_FAIL_SELECTION_LISTENER_FACTORY, 86 protocols); 87 } 88 89 /** 90 * Create a new instance. 91 * @param clientFailIfNoCommonProtocols Client side fail with a fatal alert if not common protocols are detected. 92 * @param serverFailIfNoCommonProtocols Server side fail with a fatal alert if not common protocols are detected. 93 * @param protocols The order of iteration determines the preference of support for protocols. 94 */ 95 public JdkNpnApplicationProtocolNegotiator(boolean clientFailIfNoCommonProtocols, 96 boolean serverFailIfNoCommonProtocols, String... protocols) { 97 this(clientFailIfNoCommonProtocols ? FAIL_SELECTOR_FACTORY : NO_FAIL_SELECTOR_FACTORY, 98 serverFailIfNoCommonProtocols ? FAIL_SELECTION_LISTENER_FACTORY : NO_FAIL_SELECTION_LISTENER_FACTORY, 99 protocols); 100 } 101 102 /** 103 * Create a new instance. 104 * @param selectorFactory The factory which provides classes responsible for selecting the protocol. 105 * @param listenerFactory The factory which provides to be notified of which protocol was selected. 106 * @param protocols The order of iteration determines the preference of support for protocols. 107 */ 108 public JdkNpnApplicationProtocolNegotiator(ProtocolSelectorFactory selectorFactory, 109 ProtocolSelectionListenerFactory listenerFactory, Iterable<String> protocols) { 110 super(NPN_WRAPPER, selectorFactory, listenerFactory, protocols); 111 } 112 113 /** 114 * Create a new instance. 115 * @param selectorFactory The factory which provides classes responsible for selecting the protocol. 116 * @param listenerFactory The factory which provides to be notified of which protocol was selected. 117 * @param protocols The order of iteration determines the preference of support for protocols. 118 */ 119 public JdkNpnApplicationProtocolNegotiator(ProtocolSelectorFactory selectorFactory, 120 ProtocolSelectionListenerFactory listenerFactory, String... protocols) { 121 super(NPN_WRAPPER, selectorFactory, listenerFactory, protocols); 122 } 123 }