Top Description Constructors Methods
org.conscrypt

pack-priv abstract Class AbstractConscryptEngine

extends SSLEngine
Class Inheritance
Known Direct Subclasses
org.conscrypt.Java8EngineWrapper, org.conscrypt.ConscryptEngine
Imports
java.nio.ByteBuffer, java.security.PrivateKey, javax.net.ssl.SSLEngine, .SSLEngineResult, .SSLException, .SSLSession

Abstract base class for all Conscrypt SSLEngine classes.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract byte[]

Returns:

a value of the specified length, or null if the handshake has not yet completed or the connection has been closed.
exportKeyingMaterial
(String
the label to use in calculating the exported value. This must be an ASCII-only string.
label
,
byte[]
the application-specific context value to use in calculating the exported value. This may be null to use no application context, which is treated differently than an empty byte array.
context
,
int
the number of bytes of keying material to return.
length
)

Exports a value derived from the TLS master secret as described in RFC 5705.

public abstract String
getApplicationProtocol()

Overrides javax.net.ssl.SSLEngine.getApplicationProtocol.

Returns the most recent application protocol value negotiated for this connection.
pack-priv abstract String[]
getApplicationProtocols()

Returns the list of supported ALPN protocols.

pack-priv abstract byte[]

Returns:

channel ID or null if not available.
getChannelId
()

Gets the TLS Channel ID for this server engine.

public abstract String
getHandshakeApplicationProtocol()

Overrides javax.net.ssl.SSLEngine.getHandshakeApplicationProtocol.

Returns the application protocol value negotiated on a SSL/TLS handshake currently in progress.
public final SSLSession
getHandshakeSession()

Overrides javax.net.ssl.SSLEngine.getHandshakeSession.

Returns the SSLSession being constructed during a SSL/TLS/DTLS handshake.
pack-priv abstract String
getHostname()

Returns the hostname from setHostname(String) or supplied by the PeerInfoProvider upon creation.

public abstract String
getPeerHost()

Overrides javax.net.ssl.SSLEngine.getPeerHost.

Returns the host name of the peer.
public abstract int
getPeerPort()

Overrides javax.net.ssl.SSLEngine.getPeerPort.

Returns the port number of the peer.
pack-priv abstract byte[]
getTlsUnique()

Returns the tls-unique channel binding value for this connection, per RFC 5929.

pack-priv abstract SSLSession
handshakeSession()

Work-around to allow this method to be called on older versions of Android.

pack-priv abstract int
maxSealOverhead()

Returns the maximum overhead, in bytes, of sealing a record with SSL.

pack-priv abstract void
setApplicationProtocols(String[]
the list of ALPN protocols
protocols
)

Sets the list of ALPN protocols.

pack-priv abstract void
setApplicationProtocolSelector(ApplicationProtocolSelector selector)

Sets an application-provided ALPN protocol selector.

pack-priv abstract void
pack-priv abstract void
setChannelIdEnabled(boolean enabled)

Enables/disables TLS Channel ID for this server engine.

pack-priv abstract void
setChannelIdPrivateKey(PrivateKey
private key (enables TLS Channel ID) or null for no key (disables TLS Channel ID). The private key must be an Elliptic Curve (EC) key based on the NIST P-256 curve (aka SECG secp256r1 or ANSI X9.62 prime256v1).
privateKey
)

Sets the PrivateKey to be used for TLS Channel ID by this client engine.

pack-priv abstract void
setHandshakeListener(HandshakeListener handshakeListener)

Sets the listener for the completion of the TLS handshake.

pack-priv abstract void
setHostname(String hostname)

This method enables Server Name Indication (SNI) and overrides the PeerInfoProvider supplied during engine creation.

pack-priv abstract void
setUseSessionTickets(boolean
True to enable session tickets
useSessionTickets
)

This method enables session ticket support.

public abstract SSLEngineResult
unwrap(ByteBuffer
a ByteBuffer containing inbound network data.
src
,
ByteBuffer
a ByteBuffer to hold inbound application data.
dst
)

Overrides javax.net.ssl.SSLEngine.unwrap.

Attempts to decode SSL/TLS/DTLS network data into a plaintext application data buffer.
public abstract SSLEngineResult
unwrap(ByteBuffer
a ByteBuffer containing inbound network data.
src
,
ByteBuffer[]
an array of ByteBuffers to hold inbound application data.
dsts
)

Overrides javax.net.ssl.SSLEngine.unwrap.

Attempts to decode SSL/TLS/DTLS network data into a sequence of plaintext application data buffers.
public abstract SSLEngineResult
unwrap(final ByteBuffer
a ByteBuffer containing inbound network data.
src
,
final ByteBuffer[]
an array of ByteBuffers to hold inbound application data.
dsts
,
final int
The offset within the buffer array of the first buffer from which bytes are to be transferred; it must be non-negative and no larger than dsts.length.
offset
,
final int
The maximum number of buffers to be accessed; it must be non-negative and no larger than dsts.length - offset.
length
)

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

Attempts to decode SSL/TLS/DTLS network data into a subsequence of plaintext application data buffers.
pack-priv abstract SSLEngineResult
unwrap(final ByteBuffer[] srcs, final ByteBuffer[] dsts)

pack-priv abstract SSLEngineResult
unwrap(final ByteBuffer[] srcs, int srcsOffset, final int srcsLength, final ByteBuffer[] dsts, final int dstsOffset, final int dstsLength)

public abstract SSLEngineResult
wrap(ByteBuffer
a ByteBuffer containing outbound application data
src
,
ByteBuffer
a ByteBuffer to hold outbound network data
dst
)

Overrides javax.net.ssl.SSLEngine.wrap.

Attempts to encode a buffer of plaintext application data into SSL/TLS/DTLS network data.
public abstract SSLEngineResult
wrap(ByteBuffer[]
an array of ByteBuffers containing the outbound application data
srcs
,
int
The offset within the buffer array of the first buffer from which bytes are to be retrieved; it must be non-negative and no larger than srcs.length
srcsOffset
,
int
The maximum number of buffers to be accessed; it must be non-negative and no larger than srcs.length - offset
srcsLength
,
ByteBuffer
a ByteBuffer to hold outbound network data
dst
)

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

Attempts to encode plaintext bytes from a subsequence of data buffers into SSL/TLS/DTLS network data.
Inherited from javax.net.ssl.SSLEngine:
beginHandshakecloseInboundcloseOutboundgetDelegatedTaskgetEnabledCipherSuitesgetEnabledProtocolsgetEnableSessionCreationgetHandshakeApplicationProtocolSelectorgetHandshakeStatusgetNeedClientAuthgetSessiongetSSLParametersgetSupportedCipherSuitesgetSupportedProtocolsgetUseClientModegetWantClientAuthisInboundDoneisOutboundDonesetEnabledCipherSuitessetEnabledProtocolssetEnableSessionCreationsetHandshakeApplicationProtocolSelectorsetNeedClientAuthsetSSLParameterssetUseClientModesetWantClientAuthwrap

Constructor Detail

AbstractConscryptEngineback to summary
pack-priv AbstractConscryptEngine()

Method Detail

exportKeyingMaterialback to summary
pack-priv abstract byte[] exportKeyingMaterial(String label, byte[] context, int length) throws SSLException

Exports a value derived from the TLS master secret as described in RFC 5705.

Parameters
label:String

the label to use in calculating the exported value. This must be an ASCII-only string.

context:byte[]

the application-specific context value to use in calculating the exported value. This may be null to use no application context, which is treated differently than an empty byte array.

length:int

the number of bytes of keying material to return.

Returns:byte[]

a value of the specified length, or null if the handshake has not yet completed or the connection has been closed.

Exceptions
SSLException:
if the value could not be exported.
getApplicationProtocolback to summary
public abstract 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.

Returns:String

null if it has not yet been determined if application protocols might be used for this connection, an empty String if application protocols values will not be used, or a non-empty application protocol String if a value was successfully negotiated.

Annotations
@SuppressWarnings:MissingOverride
getApplicationProtocolsback to summary
pack-priv abstract String[] getApplicationProtocols()

Returns the list of supported ALPN protocols.

getChannelIdback to summary
pack-priv abstract byte[] getChannelId() throws SSLException

Gets the TLS Channel ID for this server engine. Channel ID is only available once the handshake completes.

Returns:byte[]

channel ID or null if not available.

Exceptions
SSLException:
if channel ID is available but could not be obtained.
IllegalStateException:
if this is a client engine or if the handshake has not yet completed.
getHandshakeApplicationProtocolback to summary
public abstract 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.

Returns:String

null if it has not yet been determined if application protocols might be used for this handshake, an empty String if application protocols values will not be used, or a non-empty application protocol String if a value was successfully negotiated.

Annotations
@SuppressWarnings:MissingOverride
getHandshakeSessionback to summary
public final 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.

Returns:SSLSession

null if this instance is not currently handshaking, or if the current handshake has not progressed far enough to create a basic SSLSession. Otherwise, this method returns the SSLSession currently being negotiated.

Annotations
@SuppressWarnings:MissingOverride
getHostnameback to summary
pack-priv abstract String getHostname()

Returns the hostname from setHostname(String) or supplied by the PeerInfoProvider upon creation. No DNS resolution is attempted before returning the hostname.

getPeerHostback to summary
public abstract String getPeerHost()

Overrides javax.net.ssl.SSLEngine.getPeerHost.

Doc from javax.net.ssl.SSLEngine.getPeerHost.

Returns the host name of the peer.

Note that the value is not authenticated, and should not be relied upon.

Returns:String

the host name of the peer, or null if nothing is available.

Annotations
@Override
getPeerPortback to summary
public abstract int getPeerPort()

Overrides javax.net.ssl.SSLEngine.getPeerPort.

Doc from javax.net.ssl.SSLEngine.getPeerPort.

Returns the port number of the peer.

Note that the value is not authenticated, and should not be relied upon.

Returns:int

the port number of the peer, or -1 if nothing is available.

Annotations
@Override
getTlsUniqueback to summary
pack-priv abstract byte[] getTlsUnique()

Returns the tls-unique channel binding value for this connection, per RFC 5929. This will return null if there is no such value available, such as if the handshake has not yet completed or this connection is closed.

handshakeSessionback to summary
pack-priv abstract SSLSession handshakeSession()

Work-around to allow this method to be called on older versions of Android.

maxSealOverheadback to summary
pack-priv abstract int maxSealOverhead()

Returns the maximum overhead, in bytes, of sealing a record with SSL.

setApplicationProtocolsback to summary
pack-priv abstract void setApplicationProtocols(String[] protocols)

Sets the list of ALPN protocols.

Parameters
protocols:String[]

the list of ALPN protocols

setApplicationProtocolSelectorback to summary
pack-priv abstract void setApplicationProtocolSelector(ApplicationProtocolSelector selector)

Sets an application-provided ALPN protocol selector. If provided, this will override the list of protocols set by setApplicationProtocols(String[]).

setBufferAllocatorback to summary
pack-priv abstract void setBufferAllocator(BufferAllocator bufferAllocator)
setChannelIdEnabledback to summary
pack-priv abstract void setChannelIdEnabled(boolean enabled)

Enables/disables TLS Channel ID for this server engine.

This method needs to be invoked before the handshake starts.

Exceptions
IllegalStateException:
if this is a client engine or if the handshake has already started.
setChannelIdPrivateKeyback to summary
pack-priv abstract void setChannelIdPrivateKey(PrivateKey privateKey)

Sets the PrivateKey to be used for TLS Channel ID by this client engine.

This method needs to be invoked before the handshake starts.

Parameters
privateKey:PrivateKey

private key (enables TLS Channel ID) or null for no key (disables TLS Channel ID). The private key must be an Elliptic Curve (EC) key based on the NIST P-256 curve (aka SECG secp256r1 or ANSI X9.62 prime256v1).

Exceptions
IllegalStateException:
if this is a server engine or if the handshake has already started.
setHandshakeListenerback to summary
pack-priv abstract void setHandshakeListener(HandshakeListener handshakeListener)

Sets the listener for the completion of the TLS handshake.

setHostnameback to summary
pack-priv abstract void setHostname(String hostname)

This method enables Server Name Indication (SNI) and overrides the PeerInfoProvider supplied during engine creation.

setUseSessionTicketsback to summary
pack-priv abstract void setUseSessionTickets(boolean useSessionTickets)

This method enables session ticket support.

Parameters
useSessionTickets:boolean

True to enable session tickets

unwrapback to summary
public abstract SSLEngineResult unwrap(ByteBuffer src, ByteBuffer dst) throws SSLException

Overrides javax.net.ssl.SSLEngine.unwrap.

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

Attempts to decode SSL/TLS/DTLS network data into a plaintext application data buffer.

An invocation of this method behaves in exactly the same manner as the invocation:

engine.unwrap(src, new ByteBuffer[] { dst }, 0, 1);
Parameters
src:ByteBuffer

a ByteBuffer containing inbound network data.

dst:ByteBuffer

a ByteBuffer to hold inbound application data.

Returns:SSLEngineResult

an SSLEngineResult describing the result of this operation.

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 abstract SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts) throws SSLException

Overrides javax.net.ssl.SSLEngine.unwrap.

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

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

An invocation of this method behaves in exactly the same manner as the invocation:

engine.unwrap(src, dsts, 0, dsts.length);
Parameters
src:ByteBuffer

a ByteBuffer containing inbound network data.

dsts:ByteBuffer[]

an array of ByteBuffers to hold inbound application data.

Returns:SSLEngineResult

an SSLEngineResult describing the result of this operation.

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 abstract SSLEngineResult unwrap(final ByteBuffer src, final ByteBuffer[] dsts, final int offset, final 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.

Parameters
src:ByteBuffer

a ByteBuffer containing inbound network data.

dsts:ByteBuffer[]

an array of ByteBuffers to hold inbound application data.

offset:int

The offset within the buffer array of the first buffer from which bytes are to be transferred; it must be non-negative and no larger than dsts.length.

length:int

The maximum number of buffers to be accessed; it must be non-negative and no larger than dsts.length - offset.

Returns:SSLEngineResult

an SSLEngineResult describing the result of this operation.

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
pack-priv abstract SSLEngineResult unwrap(final ByteBuffer[] srcs, final ByteBuffer[] dsts) throws SSLException
unwrapback to summary
pack-priv abstract SSLEngineResult unwrap(final ByteBuffer[] srcs, int srcsOffset, final int srcsLength, final ByteBuffer[] dsts, final int dstsOffset, final int dstsLength) throws SSLException
wrapback to summary
public abstract SSLEngineResult wrap(ByteBuffer src, ByteBuffer dst) throws SSLException

Overrides javax.net.ssl.SSLEngine.wrap.

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

Attempts to encode a buffer of plaintext application data into SSL/TLS/DTLS network data.

An invocation of this method behaves in exactly the same manner as the invocation:

engine.wrap(new ByteBuffer[] { src }, 0, 1, dst);
Parameters
src:ByteBuffer

a ByteBuffer containing outbound application data

dst:ByteBuffer

a ByteBuffer to hold outbound network data

Returns:SSLEngineResult

an SSLEngineResult describing the result of this operation.

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 abstract SSLEngineResult wrap(ByteBuffer[] srcs, int srcsOffset, int srcsLength, ByteBuffer dst) 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.

Parameters
srcs:ByteBuffer[]

an array of ByteBuffers containing the outbound application data

srcsOffset:int

The offset within the buffer array of the first buffer from which bytes are to be retrieved; it must be non-negative and no larger than srcs.length

srcsLength:int

The maximum number of buffers to be accessed; it must be non-negative and no larger than srcs.length - offset

dst:ByteBuffer

a ByteBuffer to hold outbound network data

Returns:SSLEngineResult

an SSLEngineResult describing the result of this operation.

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.