Path: blob/master/src/java.base/share/classes/javax/net/ssl/SSLSocket.java
41159 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526package javax.net.ssl;2728import java.io.IOException;29import java.net.*;30import java.util.List;31import java.util.function.BiFunction;3233/**34* This class extends <code>Socket</code> and provides secure35* sockets using protocols such as the "Secure36* Sockets Layer" (SSL) or IETF "Transport Layer Security" (TLS) protocols.37* <P>38* Such sockets are normal stream sockets, but they39* add a layer of security protections over the underlying network transport40* protocol, such as TCP. Those protections include: <UL>41*42* <LI> <em>Integrity Protection</em>. SSL protects against43* modification of messages by an active wiretapper.44*45* <LI> <em>Authentication</em>. In most modes, SSL provides46* peer authentication. Servers are usually authenticated,47* and clients may be authenticated as requested by servers.48*49* <LI> <em>Confidentiality (Privacy Protection)</em>. In most50* modes, SSL encrypts data being sent between client and server.51* This protects the confidentiality of data, so that passive52* wiretappers won't see sensitive data such as financial53* information or personal information of many kinds.54*55* </UL>56*57* <P>These kinds of protection are specified by a "cipher suite", which58* is a combination of cryptographic algorithms used by a given SSL connection.59* During the negotiation process, the two endpoints must agree on60* a ciphersuite that is available in both environments.61* If there is no such suite in common, no SSL connection can62* be established, and no data can be exchanged.63*64* <P> The cipher suite used is established by a negotiation process65* called "handshaking". The goal of this66* process is to create or rejoin a "session", which may protect many67* connections over time. After handshaking has completed, you can access68* session attributes by using the <em>getSession</em> method.69* The initial handshake on this connection can be initiated in70* one of three ways: <UL>71*72* <LI> calling <code>startHandshake</code> which explicitly73* begins handshakes, or74* <LI> any attempt to read or write application data on75* this socket causes an implicit handshake, or76* <LI> a call to <code>getSession</code> tries to set up a session77* if there is no currently valid session, and78* an implicit handshake is done.79* </UL>80*81* <P>If handshaking fails for any reason, the <code>SSLSocket</code>82* is closed, and no further communications can be done.83*84* <P>There are two groups of cipher suites which you will need to know85* about when managing cipher suites: <UL>86*87* <LI> <em>Supported</em> cipher suites: all the suites which are88* supported by the SSL implementation. This list is reported89* using <em>getSupportedCipherSuites</em>.90*91* <LI> <em>Enabled</em> cipher suites, which may be fewer92* than the full set of supported suites. This group is93* set using the <em>setEnabledCipherSuites</em> method, and94* queried using the <em>getEnabledCipherSuites</em> method.95* Initially, a default set of cipher suites will be enabled on96* a new socket that represents the minimum suggested configuration.97*98* </UL>99*100* <P> Implementation defaults require that only cipher101* suites which authenticate servers and provide confidentiality102* be enabled by default.103* Only if both sides explicitly agree to unauthenticated and/or104* non-private (unencrypted) communications will such a ciphersuite be105* selected.106*107* <P>When an <code>SSLSocket</code> is first created, no handshaking108* is done so that applications may first set their communication109* preferences: what cipher suites to use, whether the socket should be110* in client or server mode, etc.111* However, security is always provided by the time that application data112* is sent over the connection.113*114* <P> You may register to receive event notification of handshake115* completion. This involves116* the use of two additional classes. <em>HandshakeCompletedEvent</em>117* objects are passed to <em>HandshakeCompletedListener</em> instances,118* which are registered by users of this API.119*120* An <code>SSLSocket</code> is created by <code>SSLSocketFactory</code>,121* or by <code>accept</code>ing a connection from a122* <code>SSLServerSocket</code>.123*124* <P>A SSL socket must choose to operate in the client or server mode.125* This will determine who begins the handshaking process, as well126* as which messages should be sent by each party. Each127* connection must have one client and one server, or handshaking128* will not progress properly. Once the initial handshaking has started, a129* socket can not switch between client and server modes, even when130* performing renegotiations.131*132* <P> The ApplicationProtocol {@code String} values returned by the methods133* in this class are in the network byte representation sent by the peer.134* The bytes could be directly compared, or converted to its Unicode135* {code String} format for comparison.136*137* <blockquote><pre>138* String networkString = sslSocket.getHandshakeApplicationProtocol();139* byte[] bytes = networkString.getBytes(StandardCharsets.ISO_8859_1);140*141* //142* // Match using bytes:143* //144* // "http/1.1" (7-bit ASCII values same in UTF-8)145* // MEETEI MAYEK LETTERS "HUK UN I" (Unicode 0xabcd->0xabcf)146* //147* String HTTP1_1 = "http/1.1";148* byte[] HTTP1_1_BYTES = HTTP1_1.getBytes(StandardCharsets.UTF_8);149*150* byte[] HUK_UN_I_BYTES = new byte[] {151* (byte) 0xab, (byte) 0xcd,152* (byte) 0xab, (byte) 0xce,153* (byte) 0xab, (byte) 0xcf};154*155* if ((Arrays.compare(bytes, HTTP1_1_BYTES) == 0 )156* || Arrays.compare(bytes, HUK_UN_I_BYTES) == 0) {157* ...158* }159*160* //161* // Alternatively match using string.equals() if we know the ALPN value162* // was encoded from a {@code String} using a certain character set,163* // for example {@code UTF-8}. The ALPN value must first be properly164* // decoded to a Unicode {@code String} before use.165* //166* String unicodeString = new String(bytes, StandardCharsets.UTF_8);167* if (unicodeString.equals(HTTP1_1)168* || unicodeString.equals("\u005cuabcd\u005cuabce\u005cuabcf")) {169* ...170* }171* </pre></blockquote>172*173* @apiNote174* When the connection is no longer needed, the client and server175* applications should each close both sides of their respective connection.176* For {@code SSLSocket} objects, for example, an application can call177* {@link Socket#shutdownOutput()} or {@link java.io.OutputStream#close()}178* for output stream close and call {@link Socket#shutdownInput()} or179* {@link java.io.InputStream#close()} for input stream close. Note that180* in some cases, closing the input stream may depend on the peer's output181* stream being closed first. If the connection is not closed in an orderly182* manner (for example {@link Socket#shutdownInput()} is called before the183* peer's write closure notification has been received), exceptions may184* be raised to indicate that an error has occurred. Once an185* {@code SSLSocket} is closed, it is not reusable: a new {@code SSLSocket}186* must be created.187*188* @see java.net.Socket189* @see SSLServerSocket190* @see SSLSocketFactory191*192* @since 1.4193* @author David Brownell194*/195public abstract class SSLSocket extends Socket196{197/**198* Used only by subclasses.199* Constructs an uninitialized, unconnected TCP socket.200*/201protected SSLSocket()202{ super(); }203204205/**206* Used only by subclasses.207* Constructs a TCP connection to a named host at a specified port.208* This acts as the SSL client.209* <p>210* If there is a security manager, its <code>checkConnect</code>211* method is called with the host address and <code>port</code>212* as its arguments. This could result in a SecurityException.213*214* @param host name of the host with which to connect, or215* <code>null</code> for the loopback address.216* @param port number of the server's port217* @throws IOException if an I/O error occurs when creating the socket218* @throws SecurityException if a security manager exists and its219* <code>checkConnect</code> method doesn't allow the operation.220* @throws UnknownHostException if the host is not known221* @throws IllegalArgumentException if the port parameter is outside the222* specified range of valid port values, which is between 0 and223* 65535, inclusive.224* @see SecurityManager#checkConnect225*/226protected SSLSocket(String host, int port)227throws IOException, UnknownHostException228{ super(host, port); }229230231/**232* Used only by subclasses.233* Constructs a TCP connection to a server at a specified address234* and port. This acts as the SSL client.235* <p>236* If there is a security manager, its <code>checkConnect</code>237* method is called with the host address and <code>port</code>238* as its arguments. This could result in a SecurityException.239*240* @param address the server's host241* @param port its port242* @throws IOException if an I/O error occurs when creating the socket243* @throws SecurityException if a security manager exists and its244* <code>checkConnect</code> method doesn't allow the operation.245* @throws IllegalArgumentException if the port parameter is outside the246* specified range of valid port values, which is between 0 and247* 65535, inclusive.248* @throws NullPointerException if <code>address</code> is null.249* @see SecurityManager#checkConnect250*/251protected SSLSocket(InetAddress address, int port)252throws IOException253{ super(address, port); }254255256/**257* Used only by subclasses.258* Constructs an SSL connection to a named host at a specified port,259* binding the client side of the connection a given address and port.260* This acts as the SSL client.261* <p>262* If there is a security manager, its <code>checkConnect</code>263* method is called with the host address and <code>port</code>264* as its arguments. This could result in a SecurityException.265*266* @param host name of the host with which to connect, or267* <code>null</code> for the loopback address.268* @param port number of the server's port269* @param clientAddress the client's address the socket is bound to, or270* <code>null</code> for the <code>anyLocal</code> address.271* @param clientPort the client's port the socket is bound to, or272* <code>zero</code> for a system selected free port.273* @throws IOException if an I/O error occurs when creating the socket274* @throws SecurityException if a security manager exists and its275* <code>checkConnect</code> method doesn't allow the operation.276* @throws UnknownHostException if the host is not known277* @throws IllegalArgumentException if the port parameter or clientPort278* parameter is outside the specified range of valid port values,279* which is between 0 and 65535, inclusive.280* @see SecurityManager#checkConnect281*/282protected SSLSocket(String host, int port,283InetAddress clientAddress, int clientPort)284throws IOException, UnknownHostException285{ super(host, port, clientAddress, clientPort); }286287288/**289* Used only by subclasses.290* Constructs an SSL connection to a server at a specified address291* and TCP port, binding the client side of the connection a given292* address and port. This acts as the SSL client.293* <p>294* If there is a security manager, its <code>checkConnect</code>295* method is called with the host address and <code>port</code>296* as its arguments. This could result in a SecurityException.297*298* @param address the server's host299* @param port its port300* @param clientAddress the client's address the socket is bound to, or301* <code>null</code> for the <code>anyLocal</code> address.302* @param clientPort the client's port the socket is bound to, or303* <code>zero</code> for a system selected free port.304* @throws IOException if an I/O error occurs when creating the socket305* @throws SecurityException if a security manager exists and its306* <code>checkConnect</code> method doesn't allow the operation.307* @throws IllegalArgumentException if the port parameter or clientPort308* parameter is outside the specified range of valid port values,309* which is between 0 and 65535, inclusive.310* @throws NullPointerException if <code>address</code> is null.311* @see SecurityManager#checkConnect312*/313protected SSLSocket(InetAddress address, int port,314InetAddress clientAddress, int clientPort)315throws IOException316{ super(address, port, clientAddress, clientPort); }317318319/**320* Returns the names of the cipher suites which could be enabled for use321* on this connection. Normally, only a subset of these will actually322* be enabled by default, since this list may include cipher suites which323* do not meet quality of service requirements for those defaults. Such324* cipher suites might be useful in specialized applications.325* <P>326* The returned array includes cipher suites from the list of standard327* cipher suite names in the <a href=328* "{@docRoot}/../specs/security/standard-names.html#jsse-cipher-suite-names">329* JSSE Cipher Suite Names</a> section of the Java Cryptography330* Architecture Standard Algorithm Name Documentation, and may also331* include other cipher suites that the provider supports.332*333* @return an array of cipher suite names334* @see #getEnabledCipherSuites()335* @see #setEnabledCipherSuites(String [])336*/337public abstract String [] getSupportedCipherSuites();338339340/**341* Returns the names of the SSL cipher suites which are currently342* enabled for use on this connection. When an SSLSocket is first343* created, all enabled cipher suites support a minimum quality of344* service. Thus, in some environments this value might be empty.345* <P>346* Note that even if a suite is enabled, it may never be used. This347* can occur if the peer does not support it, or its use is restricted,348* or the requisite certificates (and private keys) for the suite are349* not available, or an anonymous suite is enabled but authentication350* is required.351* <P>352* The returned array includes cipher suites from the list of standard353* cipher suite names in the <a href=354* "{@docRoot}/../specs/security/standard-names.html#jsse-cipher-suite-names">355* JSSE Cipher Suite Names</a> section of the Java Cryptography356* Architecture Standard Algorithm Name Documentation, and may also357* include other cipher suites that the provider supports.358*359* @return an array of cipher suite names360* @see #getSupportedCipherSuites()361* @see #setEnabledCipherSuites(String [])362*/363public abstract String [] getEnabledCipherSuites();364365366/**367* Sets the cipher suites enabled for use on this connection.368* <P>369* Each cipher suite in the <code>suites</code> parameter must have370* been listed by getSupportedCipherSuites(), or the method will371* fail. Following a successful call to this method, only suites372* listed in the <code>suites</code> parameter are enabled for use.373* <P>374* Note that the standard list of cipher suite names may be found in the375* <a href=376* "{@docRoot}/../specs/security/standard-names.html#jsse-cipher-suite-names">377* JSSE Cipher Suite Names</a> section of the Java Cryptography378* Architecture Standard Algorithm Name Documentation. Providers379* may support cipher suite names not found in this list or might not380* use the recommended name for a certain cipher suite.381* <P>382* See {@link #getEnabledCipherSuites()} for more information383* on why a specific ciphersuite may never be used on a connection.384*385* @param suites Names of all the cipher suites to enable386* @throws IllegalArgumentException when one or more of the ciphers387* named by the parameter is not supported, or when the388* parameter is null.389* @see #getSupportedCipherSuites()390* @see #getEnabledCipherSuites()391*/392public abstract void setEnabledCipherSuites(String suites []);393394395/**396* Returns the names of the protocols which could be enabled for use397* on an SSL connection.398*399* @return an array of protocols supported400*/401public abstract String [] getSupportedProtocols();402403404/**405* Returns the names of the protocol versions which are currently406* enabled for use on this connection.407* <P>408* Note that even if a protocol is enabled, it may never be used.409* This can occur if the peer does not support the protocol, or its410* use is restricted, or there are no enabled cipher suites supported411* by the protocol.412*413* @see #setEnabledProtocols(String [])414* @return an array of protocols415*/416public abstract String [] getEnabledProtocols();417418419/**420* Sets the protocol versions enabled for use on this connection.421* <P>422* The protocols must have been listed by423* <code>getSupportedProtocols()</code> as being supported.424* Following a successful call to this method, only protocols listed425* in the <code>protocols</code> parameter are enabled for use.426*427* @param protocols Names of all the protocols to enable.428* @throws IllegalArgumentException when one or more of429* the protocols named by the parameter is not supported or430* when the protocols parameter is null.431* @see #getEnabledProtocols()432*/433public abstract void setEnabledProtocols(String protocols[]);434435436/**437* Returns the SSL Session in use by this connection. These can438* be long lived, and frequently correspond to an entire login session439* for some user. The session specifies a particular cipher suite440* which is being actively used by all connections in that session,441* as well as the identities of the session's client and server.442* <P>443* This method will initiate the initial handshake if444* necessary and then block until the handshake has been445* established.446* <P>447* If an error occurs during the initial handshake, this method448* returns an invalid session object which reports an invalid449* cipher suite of "SSL_NULL_WITH_NULL_NULL".450*451* @return the <code>SSLSession</code>452*/453public abstract SSLSession getSession();454455456/**457* Returns the {@code SSLSession} being constructed during a SSL/TLS458* handshake.459* <p>460* TLS protocols may negotiate parameters that are needed when using461* an instance of this class, but before the {@code SSLSession} has462* been completely initialized and made available via {@code getSession}.463* For example, the list of valid signature algorithms may restrict464* the type of certificates that can be used during TrustManager465* decisions, or the maximum TLS fragment packet sizes can be466* resized to better support the network environment.467* <p>468* This method provides early access to the {@code SSLSession} being469* constructed. Depending on how far the handshake has progressed,470* some data may not yet be available for use. For example, if a471* remote server will be sending a Certificate chain, but that chain472* has yet not been processed, the {@code getPeerCertificates}473* method of {@code SSLSession} will throw a474* SSLPeerUnverifiedException. Once that chain has been processed,475* {@code getPeerCertificates} will return the proper value.476* <p>477* Unlike {@link #getSession()}, this method does not initiate the478* initial handshake and does not block until handshaking is479* complete.480*481* @see SSLEngine482* @see SSLSession483* @see ExtendedSSLSession484* @see X509ExtendedKeyManager485* @see X509ExtendedTrustManager486*487* @return null if this instance is not currently handshaking, or488* if the current handshake has not progressed far enough to489* create a basic SSLSession. Otherwise, this method returns the490* {@code SSLSession} currently being negotiated.491* @throws UnsupportedOperationException if the underlying provider492* does not implement the operation.493*494* @since 1.7495*/496public SSLSession getHandshakeSession() {497throw new UnsupportedOperationException();498}499500501/**502* Registers an event listener to receive notifications that an503* SSL handshake has completed on this connection.504*505* @param listener the HandShake Completed event listener506* @see #startHandshake()507* @see #removeHandshakeCompletedListener(HandshakeCompletedListener)508* @throws IllegalArgumentException if the argument is null.509*/510public abstract void addHandshakeCompletedListener(511HandshakeCompletedListener listener);512513514/**515* Removes a previously registered handshake completion listener.516*517* @param listener the HandShake Completed event listener518* @throws IllegalArgumentException if the listener is not registered,519* or the argument is null.520* @see #addHandshakeCompletedListener(HandshakeCompletedListener)521*/522public abstract void removeHandshakeCompletedListener(523HandshakeCompletedListener listener);524525526/**527* Starts an SSL handshake on this connection. Common reasons include528* a need to use new encryption keys, to change cipher suites, or to529* initiate a new session. To force complete reauthentication, the530* current session could be invalidated before starting this handshake.531*532* <P> If data has already been sent on the connection, it continues533* to flow during this handshake. When the handshake completes, this534* will be signaled with an event.535*536* This method is synchronous for the initial handshake on a connection537* and returns when the negotiated handshake is complete. Some538* protocols may not support multiple handshakes on an existing socket539* and may throw an IOException.540*541* @throws IOException on a network level error542* @see #addHandshakeCompletedListener(HandshakeCompletedListener)543*/544public abstract void startHandshake() throws IOException;545546547/**548* Configures the socket to use client (or server) mode when549* handshaking.550* <P>551* This method must be called before any handshaking occurs.552* Once handshaking has begun, the mode can not be reset for the553* life of this socket.554* <P>555* Servers normally authenticate themselves, and clients556* are not required to do so.557*558* @param mode true if the socket should start its handshaking559* in "client" mode560* @throws IllegalArgumentException if a mode change is attempted561* after the initial handshake has begun.562* @see #getUseClientMode()563*/564public abstract void setUseClientMode(boolean mode);565566567/**568* Returns true if the socket is set to use client mode when569* handshaking.570*571* @return true if the socket should do handshaking572* in "client" mode573* @see #setUseClientMode(boolean)574*/575public abstract boolean getUseClientMode();576577578/**579* Configures the socket to <i>require</i> client authentication. This580* option is only useful for sockets in the server mode.581* <P>582* A socket's client authentication setting is one of the following:583* <ul>584* <li> client authentication required585* <li> client authentication requested586* <li> no client authentication desired587* </ul>588* <P>589* Unlike {@link #setWantClientAuth(boolean)}, if this option is set and590* the client chooses not to provide authentication information591* about itself, <i>the negotiations will stop and the connection592* will be dropped</i>.593* <P>594* Calling this method overrides any previous setting made by595* this method or {@link #setWantClientAuth(boolean)}.596*597* @param need set to true if client authentication is required,598* or false if no client authentication is desired.599* @see #getNeedClientAuth()600* @see #setWantClientAuth(boolean)601* @see #getWantClientAuth()602* @see #setUseClientMode(boolean)603*/604public abstract void setNeedClientAuth(boolean need);605606607/**608* Returns true if the socket will <i>require</i> client authentication.609* This option is only useful to sockets in the server mode.610*611* @return true if client authentication is required,612* or false if no client authentication is desired.613* @see #setNeedClientAuth(boolean)614* @see #setWantClientAuth(boolean)615* @see #getWantClientAuth()616* @see #setUseClientMode(boolean)617*/618public abstract boolean getNeedClientAuth();619620621/**622* Configures the socket to <i>request</i> client authentication.623* This option is only useful for sockets in the server mode.624* <P>625* A socket's client authentication setting is one of the following:626* <ul>627* <li> client authentication required628* <li> client authentication requested629* <li> no client authentication desired630* </ul>631* <P>632* Unlike {@link #setNeedClientAuth(boolean)}, if this option is set and633* the client chooses not to provide authentication information634* about itself, <i>the negotiations will continue</i>.635* <P>636* Calling this method overrides any previous setting made by637* this method or {@link #setNeedClientAuth(boolean)}.638*639* @param want set to true if client authentication is requested,640* or false if no client authentication is desired.641* @see #getWantClientAuth()642* @see #setNeedClientAuth(boolean)643* @see #getNeedClientAuth()644* @see #setUseClientMode(boolean)645*/646public abstract void setWantClientAuth(boolean want);647648649/**650* Returns true if the socket will <i>request</i> client authentication.651* This option is only useful for sockets in the server mode.652*653* @return true if client authentication is requested,654* or false if no client authentication is desired.655* @see #setNeedClientAuth(boolean)656* @see #getNeedClientAuth()657* @see #setWantClientAuth(boolean)658* @see #setUseClientMode(boolean)659*/660public abstract boolean getWantClientAuth();661662663/**664* Controls whether new SSL sessions may be established by this socket.665* If session creations are not allowed, and there are no666* existing sessions to resume, there will be no successful667* handshaking.668*669* @param flag true indicates that sessions may be created; this670* is the default. false indicates that an existing session671* must be resumed672* @see #getEnableSessionCreation()673*/674public abstract void setEnableSessionCreation(boolean flag);675676677/**678* Returns true if new SSL sessions may be established by this socket.679*680* @return true indicates that sessions may be created; this681* is the default. false indicates that an existing session682* must be resumed683* @see #setEnableSessionCreation(boolean)684*/685public abstract boolean getEnableSessionCreation();686687/**688* Returns the SSLParameters in effect for this SSLSocket.689* The ciphersuites and protocols of the returned SSLParameters690* are always non-null.691*692* @return the SSLParameters in effect for this SSLSocket.693* @since 1.6694*/695public SSLParameters getSSLParameters() {696SSLParameters params = new SSLParameters();697params.setCipherSuites(getEnabledCipherSuites());698params.setProtocols(getEnabledProtocols());699if (getNeedClientAuth()) {700params.setNeedClientAuth(true);701} else if (getWantClientAuth()) {702params.setWantClientAuth(true);703}704return params;705}706707/**708* Applies SSLParameters to this socket.709*710* <p>This means:711* <ul>712* <li>If {@code params.getCipherSuites()} is non-null,713* {@code setEnabledCipherSuites()} is called with that value.</li>714* <li>If {@code params.getProtocols()} is non-null,715* {@code setEnabledProtocols()} is called with that value.</li>716* <li>If {@code params.getNeedClientAuth()} or717* {@code params.getWantClientAuth()} return {@code true},718* {@code setNeedClientAuth(true)} and719* {@code setWantClientAuth(true)} are called, respectively;720* otherwise {@code setWantClientAuth(false)} is called.</li>721* <li>If {@code params.getServerNames()} is non-null, the socket will722* configure its server names with that value.</li>723* <li>If {@code params.getSNIMatchers()} is non-null, the socket will724* configure its SNI matchers with that value.</li>725* </ul>726*727* @param params the parameters728* @throws IllegalArgumentException if the setEnabledCipherSuites() or729* the setEnabledProtocols() call fails730* @since 1.6731*/732public void setSSLParameters(SSLParameters params) {733String[] s;734s = params.getCipherSuites();735if (s != null) {736setEnabledCipherSuites(s);737}738s = params.getProtocols();739if (s != null) {740setEnabledProtocols(s);741}742if (params.getNeedClientAuth()) {743setNeedClientAuth(true);744} else if (params.getWantClientAuth()) {745setWantClientAuth(true);746} else {747setWantClientAuth(false);748}749}750751/**752* Returns the most recent application protocol value negotiated for this753* connection.754* <p>755* If supported by the underlying SSL/TLS/DTLS implementation,756* application name negotiation mechanisms such as <a757* href="http://www.ietf.org/rfc/rfc7301.txt"> RFC 7301 </a>, the758* Application-Layer Protocol Negotiation (ALPN), can negotiate759* application-level values between peers.760*761* @implSpec762* The implementation in this class throws763* {@code UnsupportedOperationException} and performs no other action.764*765* @return null if it has not yet been determined if application766* protocols might be used for this connection, an empty767* {@code String} if application protocols values will not768* be used, or a non-empty application protocol {@code String}769* if a value was successfully negotiated.770* @throws UnsupportedOperationException if the underlying provider771* does not implement the operation.772* @since 9773*/774public String getApplicationProtocol() {775throw new UnsupportedOperationException();776}777778/**779* Returns the application protocol value negotiated on a SSL/TLS780* handshake currently in progress.781* <p>782* Like {@link #getHandshakeSession()},783* a connection may be in the middle of a handshake. The784* application protocol may or may not yet be available.785*786* @implSpec787* The implementation in this class throws788* {@code UnsupportedOperationException} and performs no other action.789*790* @return null if it has not yet been determined if application791* protocols might be used for this handshake, an empty792* {@code String} if application protocols values will not793* be used, or a non-empty application protocol {@code String}794* if a value was successfully negotiated.795* @throws UnsupportedOperationException if the underlying provider796* does not implement the operation.797* @since 9798*/799public String getHandshakeApplicationProtocol() {800throw new UnsupportedOperationException();801}802803804/**805* Registers a callback function that selects an application protocol806* value for a SSL/TLS/DTLS handshake.807* The function overrides any values supplied using808* {@link SSLParameters#setApplicationProtocols809* SSLParameters.setApplicationProtocols} and it supports the following810* type parameters:811* <blockquote>812* <dl>813* <dt> {@code SSLSocket}814* <dd> The function's first argument allows the current {@code SSLSocket}815* to be inspected, including the handshake session and configuration816* settings.817* <dt> {@code List<String>}818* <dd> The function's second argument lists the application protocol names819* advertised by the TLS peer.820* <dt> {@code String}821* <dd> The function's result is an application protocol name, or null to822* indicate that none of the advertised names are acceptable.823* If the return value is an empty {@code String} then application824* protocol indications will not be used.825* If the return value is null (no value chosen) or is a value that826* was not advertised by the peer, the underlying protocol will827* determine what action to take. (For example, ALPN will send a828* "no_application_protocol" alert and terminate the connection.)829* </dl>830* </blockquote>831*832* For example, the following call registers a callback function that833* examines the TLS handshake parameters and selects an application protocol834* name:835* <pre>{@code836* serverSocket.setHandshakeApplicationProtocolSelector(837* (serverSocket, clientProtocols) -> {838* SSLSession session = serverSocket.getHandshakeSession();839* return chooseApplicationProtocol(840* serverSocket,841* clientProtocols,842* session.getProtocol(),843* session.getCipherSuite());844* });845* }</pre>846*847* @apiNote848* This method should be called by TLS server applications before the TLS849* handshake begins. Also, this {@code SSLSocket} should be configured with850* parameters that are compatible with the application protocol selected by851* the callback function. For example, enabling a poor choice of cipher852* suites could result in no suitable application protocol.853* See {@link SSLParameters}.854*855* @implSpec856* The implementation in this class throws857* {@code UnsupportedOperationException} and performs no other action.858*859* @param selector the callback function, or null to de-register.860* @throws UnsupportedOperationException if the underlying provider861* does not implement the operation.862* @since 9863*/864public void setHandshakeApplicationProtocolSelector(865BiFunction<SSLSocket, List<String>, String> selector) {866throw new UnsupportedOperationException();867}868869/**870* Retrieves the callback function that selects an application protocol871* value during a SSL/TLS/DTLS handshake.872* See {@link #setHandshakeApplicationProtocolSelector873* setHandshakeApplicationProtocolSelector}874* for the function's type parameters.875*876* @implSpec877* The implementation in this class throws878* {@code UnsupportedOperationException} and performs no other action.879*880* @return the callback function, or null if none has been set.881* @throws UnsupportedOperationException if the underlying provider882* does not implement the operation.883* @since 9884*/885public BiFunction<SSLSocket, List<String>, String>886getHandshakeApplicationProtocolSelector() {887throw new UnsupportedOperationException();888}889}890891892