APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.security.ssl

pack-priv final Class SSLEngineImpl

extends SSLEngine
implements SSLTransport
Class Inheritance
All Implemented Interfaces
sun.security.ssl.SSLTransport
Imports
java.io.IOException, java.nio.ByteBuffer, .ReadOnlyBufferException, java.util.List, .Map, java.util.concurrent.locks.ReentrantLock, java.util.function.BiFunction, javax.net.ssl.SSLEngine, .SSLEngineResult, .SSLEngineResult.HandshakeStatus, .SSLEngineResult.Status, .SSLException, .SSLHandshakeException, .SSLKeyException, .SSLParameters, .SSLPeerUnverifiedException, .SSLProtocolException, .SSLSession

Implementation of a non-blocking SSLEngine.
Author
Brad Wetmore

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
SSLEngineImpl.DelegatedTask

Implement a simple task delegator.

Field Summary

Modifier and TypeField and Description
pack-priv final TransportContext
private final ReentrantLock
private final SSLContextImpl

Constructor Summary

AccessConstructor and Description
pack-priv
SSLEngineImpl(SSLContextImpl sslContext)

Constructor for an SSLEngine from SSLContext, without host/port hints.

pack-priv
SSLEngineImpl(SSLContextImpl sslContext, String host, int port)

Constructor for an SSLEngine from SSLContext.

Method Summary

Modifier and TypeMethod and Description
public void
beginHandshake()

Implements abstract javax.net.ssl.SSLEngine.beginHandshake.

Begins handshaking on this SSLEngine.

private static void
checkParams(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength)

private void
public void
closeInbound()

Implements abstract javax.net.ssl.SSLEngine.closeInbound.

Signals that no more inbound network data will be sent to this SSLEngine.

public void
closeOutbound()

Implements abstract javax.net.ssl.SSLEngine.closeOutbound.

Signals that no more outbound application data will be sent on this SSLEngine.

private Plaintext
decode(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength)

private Ciphertext
encode(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength)

public String
getApplicationProtocol()

Overrides javax.net.ssl.SSLEngine.getApplicationProtocol.

Returns the most recent application protocol value negotiated for this connection.

public Runnable
getDelegatedTask()

Implements abstract javax.net.ssl.SSLEngine.getDelegatedTask.

Returns a delegated Runnable task for this SSLEngine.

public String[]
getEnabledCipherSuites()

Implements abstract javax.net.ssl.SSLEngine.getEnabledCipherSuites.

Returns the names of the SSL cipher suites which are currently enabled for use on this engine.

public String[]
getEnabledProtocols()

Implements abstract javax.net.ssl.SSLEngine.getEnabledProtocols.

Returns the names of the protocol versions which are currently enabled for use with this SSLEngine.

public boolean
getEnableSessionCreation()

Implements abstract javax.net.ssl.SSLEngine.getEnableSessionCreation.

Returns true if new SSL sessions may be established by this engine.

public String
getHandshakeApplicationProtocol()

Overrides javax.net.ssl.SSLEngine.getHandshakeApplicationProtocol.

Returns the application protocol value negotiated on a SSL/TLS handshake currently in progress.

public BiFunction<SSLEngine, List<String>, String>
getHandshakeApplicationProtocolSelector()

Overrides javax.net.ssl.SSLEngine.getHandshakeApplicationProtocolSelector.

Retrieves the callback function that selects an application protocol value during a SSL/TLS/DTLS handshake.

public SSLSession
getHandshakeSession()

Overrides javax.net.ssl.SSLEngine.getHandshakeSession.

Returns the SSLSession being constructed during a SSL/TLS/DTLS handshake.

public SSLEngineResult.HandshakeStatus
getHandshakeStatus()

Implements abstract javax.net.ssl.SSLEngine.getHandshakeStatus.

Returns the current handshake status for this SSLEngine.

public boolean
getNeedClientAuth()

Implements abstract javax.net.ssl.SSLEngine.getNeedClientAuth.

Returns true if the engine will require client authentication.

public SSLSession
getSession()

Implements abstract javax.net.ssl.SSLEngine.getSession.

Returns the SSLSession in use in this SSLEngine.

public SSLParameters
getSSLParameters()

Overrides javax.net.ssl.SSLEngine.getSSLParameters.

Returns the SSLParameters in effect for this SSLEngine.

public String[]
getSupportedCipherSuites()

Implements abstract javax.net.ssl.SSLEngine.getSupportedCipherSuites.

Returns the names of the cipher suites which could be enabled for use on this engine.

public String[]
getSupportedProtocols()

Implements abstract javax.net.ssl.SSLEngine.getSupportedProtocols.

Returns the names of the protocols which could be enabled for use with this SSLEngine.

private static SSLException
public boolean
getUseClientMode()

Implements abstract javax.net.ssl.SSLEngine.getUseClientMode.

Returns true if the engine is set to use client mode when handshaking.

public boolean
getWantClientAuth()

Implements abstract javax.net.ssl.SSLEngine.getWantClientAuth.

Returns true if the engine will request client authentication.

public boolean
isInboundDone()

Implements abstract javax.net.ssl.SSLEngine.isInboundDone.

Returns whether unwrap(ByteBuffer, ByteBuffer) will accept any more inbound data messages.

public boolean
isOutboundDone()

Implements abstract javax.net.ssl.SSLEngine.isOutboundDone.

Returns whether wrap(ByteBuffer, ByteBuffer) will produce any more outbound data messages.

private SSLEngineResult
readRecord(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength)

public void
setEnabledCipherSuites(String[] suites)

Implements abstract javax.net.ssl.SSLEngine.setEnabledCipherSuites.

Sets the cipher suites enabled for use on this engine.

public void
setEnabledProtocols(String[] protocols)

Implements abstract javax.net.ssl.SSLEngine.setEnabledProtocols.

Set the protocol versions enabled for use on this engine.

public void
setEnableSessionCreation(boolean flag)

Implements abstract javax.net.ssl.SSLEngine.setEnableSessionCreation.

Controls whether new SSL sessions may be established by this engine.

public void
setHandshakeApplicationProtocolSelector(BiFunction<SSLEngine, List<String>, String> selector)

Overrides javax.net.ssl.SSLEngine.setHandshakeApplicationProtocolSelector.

Registers a callback function that selects an application protocol value for a SSL/TLS/DTLS handshake.

public void
setNeedClientAuth(boolean need)

Implements abstract javax.net.ssl.SSLEngine.setNeedClientAuth.

Configures the engine to require client authentication.

public void
setSSLParameters(SSLParameters params)

Overrides javax.net.ssl.SSLEngine.setSSLParameters.

Applies SSLParameters to this engine.

public void
setUseClientMode(boolean mode)

Implements abstract javax.net.ssl.SSLEngine.setUseClientMode.

Configures the engine to use client (or server) mode when handshaking.

public void
setWantClientAuth(boolean want)

Implements abstract javax.net.ssl.SSLEngine.setWantClientAuth.

Configures the engine to request client authentication.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private SSLEngineResult.HandshakeStatus
tryKeyUpdate(SSLEngineResult.HandshakeStatus currentHandshakeStatus)

Try key update for sequence number wrap or key usage limit.

private SSLEngineResult.HandshakeStatus
private SSLEngineResult.HandshakeStatus
tryToFinishHandshake(byte contentType)

public SSLEngineResult
unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length)

Implements abstract javax.net.ssl.SSLEngine.unwrap.

Attempts to decode SSL/TLS/DTLS network data into a subsequence of plaintext application data buffers.

public SSLEngineResult
unwrap(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength)

public boolean
useDelegatedTask()

Implements sun.security.ssl.SSLTransport.useDelegatedTask.

Return true if delegated tasks used for handshaking operations.

public SSLEngineResult
wrap(ByteBuffer[] appData, int offset, int length, ByteBuffer netData)

Implements abstract javax.net.ssl.SSLEngine.wrap.

Attempts to encode plaintext bytes from a subsequence of data buffers into SSL/TLS/DTLS network data.

public SSLEngineResult
wrap(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength)

private SSLEngineResult
writeRecord(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength)

Inherited from javax.net.ssl.SSLEngine:
getPeerHostgetPeerPortunwrapunwrapwrapwrap

Field Detail

conContextback to summary
pack-priv final TransportContext conContext
engineLockback to summary
private final ReentrantLock engineLock
sslContextback to summary
private final SSLContextImpl sslContext

Constructor Detail

SSLEngineImplback to summary
pack-priv SSLEngineImpl(SSLContextImpl sslContext)

Constructor for an SSLEngine from SSLContext, without host/port hints. This Engine will not be able to cache sessions, but must renegotiate everything by hand.

SSLEngineImplback to summary
pack-priv SSLEngineImpl(SSLContextImpl sslContext, String host, int port)

Constructor for an SSLEngine from SSLContext.

Method Detail

beginHandshakeback to summary
public void beginHandshake() throws SSLException

Implements abstract javax.net.ssl.SSLEngine.beginHandshake.

Doc from javax.net.ssl.SSLEngine.beginHandshake.

Begins handshaking on this SSLEngine.

Common reasons include a need to initiate a new protected session, create new encryption keys, or to change cipher suites. To force complete reauthentication, the current session should be invalidated before starting this handshake.

The behavior of this method is protocol (and possibly implementation) dependent. For example, in TLSv1.3 calling this method after the connection has been established will force a key update. For prior TLS versions it will force a renegotiation (re-handshake).

This method is not needed for the initial handshake, as the wrap() and unwrap() methods will implicitly call this method if handshaking has not already begun.

Note that the peer may also request a session renegotiation with this SSLEngine by sending the appropriate session renegotiate handshake message.

Unlike the SSLSocket#startHandshake() method, this method does not block until handshaking is completed.

Some protocols may not support multiple handshakes on an existing engine and may throw an SSLException.

Annotations
@Override
Exceptions
SSLException:
if a problem was encountered while signaling the SSLEngine to begin a new handshake. See the class description for more information on engine closure.
checkParamsback to summary
private static void checkParams(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength)
checkTaskThrownback to summary
private void checkTaskThrown() throws SSLException
closeInboundback to summary
public void closeInbound() throws SSLException

Implements abstract javax.net.ssl.SSLEngine.closeInbound.

Doc from javax.net.ssl.SSLEngine.closeInbound.

Signals that no more inbound network data will be sent to this SSLEngine.

If the application initiated the closing process by calling closeOutbound(), under some circumstances it is not required that the initiator wait for the peer's corresponding close message. (See section 7.2.1 of the TLS specification (RFC 2246) for more information on waiting for closure alerts.) In such cases, this method need not be called.

But if the application did not initiate the closure process, or if the circumstances above do not apply, this method should be called whenever the end of the SSL/TLS/DTLS data stream is reached. This ensures closure of the inbound side, and checks that the peer followed the SSL/TLS/DTLS close procedure properly, thus detecting possible truncation attacks.

This method is idempotent: if the inbound side has already been closed, this method does not do anything.

wrap() should be called to flush any remaining handshake data.

Annotations
@Override
Exceptions
SSLException:
if this engine has not received the proper SSL/TLS/DTLS close notification message from the peer.
closeOutboundback to summary
public void closeOutbound()

Implements abstract javax.net.ssl.SSLEngine.closeOutbound.

Doc from javax.net.ssl.SSLEngine.closeOutbound.

Signals that no more outbound application data will be sent on this SSLEngine.

This method is idempotent: if the outbound side has already been closed, this method does not do anything.

wrap(ByteBuffer, ByteBuffer) should be called to flush any remaining handshake data.

Annotations
@Override
decodeback to summary
private Plaintext decode(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength) throws IOException
encodeback to summary
private Ciphertext encode(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength) throws IOException
getApplicationProtocolback to summary
public String getApplicationProtocol()

Overrides javax.net.ssl.SSLEngine.getApplicationProtocol.

Doc from javax.net.ssl.SSLEngine.getApplicationProtocol.

Returns the most recent application protocol value negotiated for this connection.

If supported by the underlying SSL/TLS/DTLS implementation, application name negotiation mechanisms such as RFC 7301 , the Application-Layer Protocol Negotiation (ALPN), can negotiate application-level values between peers.

Annotations
@Override
getDelegatedTaskback to summary
public Runnable getDelegatedTask()

Implements abstract javax.net.ssl.SSLEngine.getDelegatedTask.

Doc from javax.net.ssl.SSLEngine.getDelegatedTask.

Returns a delegated Runnable task for this SSLEngine.

SSLEngine operations may require the results of operations that block, or may take an extended period of time to complete. This method is used to obtain an outstanding java.lang.Runnable operation (task). Each task must be assigned a thread (possibly the current) to perform the run operation. Once the run method returns, the Runnable object is no longer needed and may be discarded.

A call to this method will return each outstanding task exactly once.

Multiple delegated tasks can be run in parallel.

Annotations
@Override
getEnabledCipherSuitesback to summary
public String[] getEnabledCipherSuites()

Implements abstract javax.net.ssl.SSLEngine.getEnabledCipherSuites.

Doc from javax.net.ssl.SSLEngine.getEnabledCipherSuites.

Returns the names of the SSL cipher suites which are currently enabled for use on this engine. When an SSLEngine is first created, all enabled cipher suites support a minimum quality of service. Thus, in some environments this value might be empty.

Note that even if a suite is enabled, it may never be used. This can occur if the peer does not support it, or its use is restricted, or the requisite certificates (and private keys) for the suite are not available, or an anonymous suite is enabled but authentication is required.

The returned array includes cipher suites from the list of standard cipher suite names in the JSSE Cipher Suite Names section of the Java Security Standard Algorithm Names Specification, and may also include other cipher suites that the provider supports.

Annotations
@Override
getEnabledProtocolsback to summary
public String[] getEnabledProtocols()

Implements abstract javax.net.ssl.SSLEngine.getEnabledProtocols.

Doc from javax.net.ssl.SSLEngine.getEnabledProtocols.

Returns the names of the protocol versions which are currently enabled for use with this SSLEngine.

Note that even if a protocol is enabled, it may never be used. This can occur if the peer does not support the protocol, or its use is restricted, or there are no enabled cipher suites supported by the protocol.

Annotations
@Override
getEnableSessionCreationback to summary
public boolean getEnableSessionCreation()

Implements abstract javax.net.ssl.SSLEngine.getEnableSessionCreation.

Doc from javax.net.ssl.SSLEngine.getEnableSessionCreation.

Returns true if new SSL sessions may be established by this engine.

Annotations
@Override
getHandshakeApplicationProtocolback to summary
public String getHandshakeApplicationProtocol()

Overrides javax.net.ssl.SSLEngine.getHandshakeApplicationProtocol.

Doc from javax.net.ssl.SSLEngine.getHandshakeApplicationProtocol.

Returns the application protocol value negotiated on a SSL/TLS handshake currently in progress.

Like getHandshakeSession(), a connection may be in the middle of a handshake. The application protocol may or may not yet be available.

Annotations
@Override
getHandshakeApplicationProtocolSelectorback to summary
public BiFunction<SSLEngine, List<String>, String> getHandshakeApplicationProtocolSelector()

Overrides javax.net.ssl.SSLEngine.getHandshakeApplicationProtocolSelector.

Doc from javax.net.ssl.SSLEngine.getHandshakeApplicationProtocolSelector.

Retrieves the callback function that selects an application protocol value during a SSL/TLS/DTLS handshake. See setHandshakeApplicationProtocolSelector for the function's type parameters.

Annotations
@Override
getHandshakeSessionback to summary
public SSLSession getHandshakeSession()

Overrides javax.net.ssl.SSLEngine.getHandshakeSession.

Doc from javax.net.ssl.SSLEngine.getHandshakeSession.

Returns the SSLSession being constructed during a SSL/TLS/DTLS handshake.

TLS/DTLS protocols may negotiate parameters that are needed when using an instance of this class, but before the SSLSession has been completely initialized and made available via getSession. For example, the list of valid signature algorithms may restrict the type of certificates that can be used during TrustManager decisions, or the maximum TLS/DTLS fragment packet sizes can be resized to better support the network environment.

This method provides early access to the SSLSession being constructed. Depending on how far the handshake has progressed, some data may not yet be available for use. For example, if a remote server will be sending a Certificate chain, but that chain has yet not been processed, the getPeerCertificates method of SSLSession will throw a SSLPeerUnverifiedException. Once that chain has been processed, getPeerCertificates will return the proper value.

Annotations
@Override
getHandshakeStatusback to summary
public SSLEngineResult.HandshakeStatus getHandshakeStatus()

Implements abstract javax.net.ssl.SSLEngine.getHandshakeStatus.

Doc from javax.net.ssl.SSLEngine.getHandshakeStatus.

Returns the current handshake status for this SSLEngine.

Annotations
@Override
getNeedClientAuthback to summary
public boolean getNeedClientAuth()

Implements abstract javax.net.ssl.SSLEngine.getNeedClientAuth.

Doc from javax.net.ssl.SSLEngine.getNeedClientAuth.

Returns true if the engine will require client authentication. This option is only useful to engines in the server mode.

Annotations
@Override
getSessionback to summary
public SSLSession getSession()

Implements abstract javax.net.ssl.SSLEngine.getSession.

Doc from javax.net.ssl.SSLEngine.getSession.

Returns the SSLSession in use in this SSLEngine.

These can be long-lived, and frequently correspond to an entire login session for some user. The session specifies a particular cipher suite which is being actively used by all connections in that session, as well as the identities of the session's client and server.

Unlike SSLSocket#getSession() this method does not block until handshaking is complete.

Until the initial handshake has completed, this method returns a session object which reports an invalid cipher suite of "SSL_NULL_WITH_NULL_NULL".

Annotations
@Override
getSSLParametersback to summary
public SSLParameters getSSLParameters()

Overrides javax.net.ssl.SSLEngine.getSSLParameters.

Doc from javax.net.ssl.SSLEngine.getSSLParameters.

Returns the SSLParameters in effect for this SSLEngine. The ciphersuites and protocols of the returned SSLParameters are always non-null.

Annotations
@Override
getSupportedCipherSuitesback to summary
public String[] getSupportedCipherSuites()

Implements abstract javax.net.ssl.SSLEngine.getSupportedCipherSuites.

Doc from javax.net.ssl.SSLEngine.getSupportedCipherSuites.

Returns the names of the cipher suites which could be enabled for use on this engine. Normally, only a subset of these will actually be enabled by default, since this list may include cipher suites which do not meet quality of service requirements for those defaults. Such cipher suites might be useful in specialized applications.

The returned array includes cipher suites from the list of standard cipher suite names in the JSSE Cipher Suite Names section of the Java Security Standard Algorithm Names Specification, and may also include other cipher suites that the provider supports.

Annotations
@Override
getSupportedProtocolsback to summary
public String[] getSupportedProtocols()

Implements abstract javax.net.ssl.SSLEngine.getSupportedProtocols.

Doc from javax.net.ssl.SSLEngine.getSupportedProtocols.

Returns the names of the protocols which could be enabled for use with this SSLEngine.

Annotations
@Override
getTaskThrownback to summary
private static SSLException getTaskThrown(Exception taskThrown)
getUseClientModeback to summary
public boolean getUseClientMode()

Implements abstract javax.net.ssl.SSLEngine.getUseClientMode.

Doc from javax.net.ssl.SSLEngine.getUseClientMode.

Returns true if the engine is set to use client mode when handshaking.

Annotations
@Override
getWantClientAuthback to summary
public boolean getWantClientAuth()

Implements abstract javax.net.ssl.SSLEngine.getWantClientAuth.

Doc from javax.net.ssl.SSLEngine.getWantClientAuth.

Returns true if the engine will request client authentication. This option is only useful for engines in the server mode.

Annotations
@Override
isInboundDoneback to summary
public boolean isInboundDone()

Implements abstract javax.net.ssl.SSLEngine.isInboundDone.

Doc from javax.net.ssl.SSLEngine.isInboundDone.

Returns whether unwrap(ByteBuffer, ByteBuffer) will accept any more inbound data messages.

Annotations
@Override
isOutboundDoneback to summary
public boolean isOutboundDone()

Implements abstract javax.net.ssl.SSLEngine.isOutboundDone.

Doc from javax.net.ssl.SSLEngine.isOutboundDone.

Returns whether wrap(ByteBuffer, ByteBuffer) will produce any more outbound data messages.

Note that during the closure phase, a SSLEngine may generate handshake closure data that must be sent to the peer. wrap() must be called to generate this data. When this method returns true, no more outbound data will be created.

Annotations
@Override
readRecordback to summary
private SSLEngineResult readRecord(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength) throws IOException
setEnabledCipherSuitesback to summary
public void setEnabledCipherSuites(String[] suites)

Implements abstract javax.net.ssl.SSLEngine.setEnabledCipherSuites.

Doc from javax.net.ssl.SSLEngine.setEnabledCipherSuites.

Sets the cipher suites enabled for use on this engine.

Each cipher suite in the suites parameter must have been listed by getSupportedCipherSuites(), or the method will fail. Following a successful call to this method, only suites listed in the suites parameter are enabled for use.

Note that the standard list of cipher suite names may be found in the JSSE Cipher Suite Names section of the Java Security Standard Algorithm Names Specification. Providers may support cipher suite names not found in this list or might not use the recommended name for a certain cipher suite.

See getEnabledCipherSuites() for more information on why a specific cipher suite may never be used on an engine.

Annotations
@Override
setEnabledProtocolsback to summary
public void setEnabledProtocols(String[] protocols)

Implements abstract javax.net.ssl.SSLEngine.setEnabledProtocols.

Doc from javax.net.ssl.SSLEngine.setEnabledProtocols.

Set the protocol versions enabled for use on this engine.

The protocols must have been listed by getSupportedProtocols() as being supported. Following a successful call to this method, only protocols listed in the protocols parameter are enabled for use.

Annotations
@Override
setEnableSessionCreationback to summary
public void setEnableSessionCreation(boolean flag)

Implements abstract javax.net.ssl.SSLEngine.setEnableSessionCreation.

Doc from javax.net.ssl.SSLEngine.setEnableSessionCreation.

Controls whether new SSL sessions may be established by this engine. If session creations are not allowed, and there are no existing sessions to resume, there will be no successful handshaking.

Annotations
@Override
setHandshakeApplicationProtocolSelectorback to summary
public void setHandshakeApplicationProtocolSelector(BiFunction<SSLEngine, List<String>, String> selector)

Overrides javax.net.ssl.SSLEngine.setHandshakeApplicationProtocolSelector.

Doc from javax.net.ssl.SSLEngine.setHandshakeApplicationProtocolSelector.

Registers a callback function that selects an application protocol value for a SSL/TLS/DTLS handshake. The function overrides any values supplied using SSLParameters.setApplicationProtocols and it supports the following type parameters:

SSLEngine
The function's first argument allows the current SSLEngine to be inspected, including the handshake session and configuration settings.
List<String>
The function's second argument lists the application protocol names advertised by the TLS peer.
String
The function's result is an application protocol name, or null to indicate that none of the advertised names are acceptable. If the return value is an empty String then application protocol indications will not be used. If the return value is null (no value chosen) or is a value that was not advertised by the peer, the underlying protocol will determine what action to take. (For example, ALPN will send a "no_application_protocol" alert and terminate the connection.)
For example, the following call registers a callback function that examines the TLS handshake parameters and selects an application protocol name:
serverEngine.setHandshakeApplicationProtocolSelector(
        (serverEngine, clientProtocols) -> {
            SSLSession session = serverEngine.getHandshakeSession();
            return chooseApplicationProtocol(
                serverEngine,
                clientProtocols,
                session.getProtocol(),
                session.getCipherSuite());
        });
Annotations
@Override
setNeedClientAuthback to summary
public void setNeedClientAuth(boolean need)

Implements abstract javax.net.ssl.SSLEngine.setNeedClientAuth.

Doc from javax.net.ssl.SSLEngine.setNeedClientAuth.

Configures the engine to require client authentication. This option is only useful for engines in the server mode.

An engine's client authentication setting is one of the following:

  • client authentication required
  • client authentication requested
  • no client authentication desired

Unlike setWantClientAuth(boolean), if this option is set and the client chooses not to provide authentication information about itself, the negotiations will stop and the engine will begin its closure procedure.

Calling this method overrides any previous setting made by this method or setWantClientAuth(boolean).

Annotations
@Override
setSSLParametersback to summary
public void setSSLParameters(SSLParameters params)

Overrides javax.net.ssl.SSLEngine.setSSLParameters.

Doc from javax.net.ssl.SSLEngine.setSSLParameters.

Applies SSLParameters to this engine.

This means:

  • If params.getCipherSuites() is non-null, setEnabledCipherSuites() is called with that value.
  • If params.getProtocols() is non-null, setEnabledProtocols() is called with that value.
  • If params.getNeedClientAuth() or params.getWantClientAuth() return true, setNeedClientAuth(true) and setWantClientAuth(true) are called, respectively; otherwise setWantClientAuth(false) is called.
  • If params.getServerNames() is non-null, the engine will configure its server names with that value.
  • If params.getSNIMatchers() is non-null, the engine will configure its SNI matchers with that value.
Annotations
@Override
setUseClientModeback to summary
public void setUseClientMode(boolean mode)

Implements abstract javax.net.ssl.SSLEngine.setUseClientMode.

Doc from javax.net.ssl.SSLEngine.setUseClientMode.

Configures the engine to use client (or server) mode when handshaking.

This method must be called before any handshaking occurs. Once handshaking has begun, the mode can not be reset for the life of this engine.

Servers normally authenticate themselves, and clients are not required to do so.

Annotations
@Override
setWantClientAuthback to summary
public void setWantClientAuth(boolean want)

Implements abstract javax.net.ssl.SSLEngine.setWantClientAuth.

Doc from javax.net.ssl.SSLEngine.setWantClientAuth.

Configures the engine to request client authentication. This option is only useful for engines in the server mode.

An engine's client authentication setting is one of the following:

  • client authentication required
  • client authentication requested
  • no client authentication desired

Unlike setNeedClientAuth(boolean), if this option is set and the client chooses not to provide authentication information about itself, the negotiations will continue.

Calling this method overrides any previous setting made by this method or setNeedClientAuth(boolean).

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
tryKeyUpdateback to summary
private SSLEngineResult.HandshakeStatus tryKeyUpdate(SSLEngineResult.HandshakeStatus currentHandshakeStatus) throws IOException

Try key update for sequence number wrap or key usage limit. Note that in order to maintain the handshake status properly, we check the sequence number and key usage limit after the last record reading/writing process. As we request renegotiation or close the connection for wrapped sequence number when there is enough sequence number space left to handle a few more records, so the sequence number of the last record cannot be wrapped.

tryNewSessionTicketback to summary
private SSLEngineResult.HandshakeStatus tryNewSessionTicket(SSLEngineResult.HandshakeStatus currentHandshakeStatus) throws IOException
tryToFinishHandshakeback to summary
private SSLEngineResult.HandshakeStatus tryToFinishHandshake(byte contentType)
unwrapback to summary
public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length) throws SSLException

Implements abstract javax.net.ssl.SSLEngine.unwrap.

Doc from javax.net.ssl.SSLEngine.unwrap.

Attempts to decode SSL/TLS/DTLS network data into a subsequence of plaintext application data buffers. This "scattering" operation decodes, in a single invocation, a sequence of bytes into one or more of a given sequence of buffers. Scattering unwraps are often useful when implementing network protocols or file formats that, for example, group data into segments consisting of one or more fixed-length headers followed by a variable-length body. See java.nio.channels.ScatteringByteChannel for more information on scattering, and java.nio.channels.ScatteringByteChannel#read(ByteBuffer[], int, int) for more information on the subsequence behavior.

Depending on the state of the SSLEngine, this method may consume network data without producing any application data (for example, it may consume handshake data.)

The application is responsible for reliably obtaining the network data from the peer, and for invoking unwrap() on the data in the order it was received. The application must properly synchronize multiple calls to this method.

If this SSLEngine has not yet started its initial handshake, this method will automatically start the handshake.

This method will attempt to consume one complete SSL/TLS/DTLS network packet, but will never consume more than the sum of the bytes remaining in the buffers. Each ByteBuffer's position is updated to reflect the amount of data consumed or produced. The limits remain the same.

The underlying memory used by the src and dsts ByteBuffers must not be the same.

The inbound network buffer, src, may be modified as a result of this call: therefore if the network data packet is required for some secondary purpose, the data should be duplicated before calling this method.

Note

the network data will not be useful to a second SSLEngine, as each SSLEngine contains unique random state which influences the SSL/TLS/DTLS messages.

See the class description for more information on engine closure.

Annotations
@Override
Exceptions
SSLException:
A problem was encountered while processing the data that caused the SSLEngine to abort. See the class description for more information on engine closure.
unwrapback to summary
public SSLEngineResult unwrap(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength) throws SSLException
useDelegatedTaskback to summary
public boolean useDelegatedTask()

Implements sun.security.ssl.SSLTransport.useDelegatedTask.

Doc from sun.security.ssl.SSLTransport.useDelegatedTask.

Return true if delegated tasks used for handshaking operations.

Annotations
@Override
wrapback to summary
public SSLEngineResult wrap(ByteBuffer[] appData, int offset, int length, ByteBuffer netData) throws SSLException

Implements abstract javax.net.ssl.SSLEngine.wrap.

Doc from javax.net.ssl.SSLEngine.wrap.

Attempts to encode plaintext bytes from a subsequence of data buffers into SSL/TLS/DTLS network data. This "gathering" operation encodes, in a single invocation, a sequence of bytes from one or more of a given sequence of buffers. Gathering wraps are often useful when implementing network protocols or file formats that, for example, group data into segments consisting of one or more fixed-length headers followed by a variable-length body. See java.nio.channels.GatheringByteChannel for more information on gathering, and java.nio.channels.GatheringByteChannel#write(ByteBuffer[], int, int) for more information on the subsequence behavior.

Depending on the state of the SSLEngine, this method may produce network data without consuming any application data (for example, it may generate handshake data.)

The application is responsible for reliably transporting the network data to the peer, and for ensuring that data created by multiple calls to wrap() is transported in the same order in which it was generated. The application must properly synchronize multiple calls to this method.

If this SSLEngine has not yet started its initial handshake, this method will automatically start the handshake.

This method will attempt to produce SSL/TLS/DTLS records, and will consume as much source data as possible, but will never consume more than the sum of the bytes remaining in each buffer. Each ByteBuffer's position is updated to reflect the amount of data consumed or produced. The limits remain the same.

The underlying memory used by the srcs and dst ByteBuffers must not be the same.

See the class description for more information on engine closure.

Annotations
@Override
Exceptions
SSLException:
A problem was encountered while processing the data that caused the SSLEngine to abort. See the class description for more information on engine closure.
wrapback to summary
public SSLEngineResult wrap(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength) throws SSLException
writeRecordback to summary
private SSLEngineResult writeRecord(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer[] dsts, int dstsOffset, int dstsLength) throws IOException
sun.security.ssl back to summary

private Class SSLEngineImpl.DelegatedTask

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Implement a simple task delegator.

Field Summary

Modifier and TypeField and Description
private final SSLEngineImpl

Constructor Summary

AccessConstructor and Description
pack-priv
DelegatedTask(SSLEngineImpl engineInstance)

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

engineback to summary
private final SSLEngineImpl engine

Constructor Detail

DelegatedTaskback to summary
pack-priv DelegatedTask(SSLEngineImpl engineInstance)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override