Top Description Fields Constructors Methods
org.conscrypt

pack-priv final Class ConscryptEngine

extends AbstractConscryptEngine
implements SSLHandshakeCallbacks, AliasChooser, PSKCallbacks
Class Inheritance
All Implemented Interfaces
org.conscrypt.SSLParametersImpl.PSKCallbacks, org.conscrypt.SSLParametersImpl.AliasChooser, org.conscrypt.NativeCrypto.SSLHandshakeCallbacks
Static Imports
java.lang.Math.max, .Math.min, javax.net.ssl.SSLEngineResult.HandshakeStatus.FINISHED, .SSLEngineResult.HandshakeStatus.NEED_UNWRAP, .SSLEngineResult.HandshakeStatus.NEED_WRAP, .SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING, .SSLEngineResult.Status.BUFFER_OVERFLOW, .SSLEngineResult.Status.BUFFER_UNDERFLOW, .SSLEngineResult.Status.CLOSED, .SSLEngineResult.Status.OK, org.conscrypt.NativeConstants.SSL3_RT_HEADER_LENGTH, .NativeConstants.SSL3_RT_MAX_PACKET_SIZE, .NativeConstants.SSL3_RT_MAX_PLAIN_LENGTH, .NativeConstants.SSL_CB_HANDSHAKE_DONE, .NativeConstants.SSL_CB_HANDSHAKE_START, .NativeConstants.SSL_ERROR_WANT_READ, .NativeConstants.SSL_ERROR_WANT_WRITE, .NativeConstants.SSL_ERROR_ZERO_RETURN, .Preconditions.checkArgument, .Preconditions.checkNotNull, .Preconditions.checkPositionIndexes, .SSLUtils.EngineStates.STATE_CLOSED, .SSLUtils.EngineStates.STATE_CLOSED_INBOUND, .SSLUtils.EngineStates.STATE_CLOSED_OUTBOUND, .SSLUtils.EngineStates.STATE_HANDSHAKE_COMPLETED, .SSLUtils.EngineStates.STATE_HANDSHAKE_STARTED, .SSLUtils.EngineStates.STATE_MODE_SET, .SSLUtils.EngineStates.STATE_NEW, .SSLUtils.EngineStates.STATE_READY, .SSLUtils.EngineStates.STATE_READY_HANDSHAKE_CUT_THROUGH, .SSLUtils.calculateOutNetBufSize, .SSLUtils.toSSLHandshakeException

Implements the SSLEngine API using OpenSSL's non-blocking interfaces.

Field Summary

Modifier and TypeField and Description
private ActiveSession
activeSession

Set during startHandshake.

private BufferAllocator
private OpenSSLKey
channelIdPrivateKey

Private key for the TLS Channel ID extension.

private static final SSLEngineResult
private SessionSnapshot
closedSession

A snapshot of the active session when the engine was closed.

private static BufferAllocator
private final SSLSession
externalSession

The session object exposed externally from this class.

private boolean
private HandshakeListener
private ByteBuffer
lazyDirectBuffer

A lazy-created direct buffer used as a bridge between heap buffers provided by the application and JNI.

private int
private static final SSLEngineResult
private static final SSLEngineResult
private static final SSLEngineResult
private static final SSLEngineResult
private final NativeSsl.BioWrapper
networkBio

The BIO used for reading/writing encrypted bytes.

private String
peerHostname

Hostname used with the TLS extension SNI hostname.

private final PeerInfoProvider
private final ByteBuffer[]
private final ByteBuffer[]
private final NativeSsl
ssl

Wrapper around the underlying SSL object.

private final SSLParametersImpl
private int

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
ConscryptEngine(String host, int port, SSLParametersImpl sslParameters)

pack-priv
ConscryptEngine(SSLParametersImpl sslParameters, PeerInfoProvider peerInfoProvider, SSLParametersImpl.AliasChooser aliasChooser)

Method Summary

Modifier and TypeMethod and Description
public void
beginHandshake()

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

Initiates handshaking (initial or renegotiation) on this SSLEngine.
private void
private static int
calcDstsLength(ByteBuffer[] dsts, int dstsOffset, int dstsLength)

private static long
calcSrcsLength(ByteBuffer[] srcs, int srcsOffset, int srcsEndOffset)

public String
public String
chooseClientPSKIdentity(PSKKeyManager keyManager, String identityHint)

Implements org.conscrypt.SSLParametersImpl.PSKCallbacks.chooseClientPSKIdentity.

Deprecated as a consequence of PSKKeyManager being deprecated.
public String
public String
public void
clientCertificateRequested(byte[]
key types supported by the server, convertible to strings with #keyType
keyTypeBytes
,
int[] signatureAlgs, byte[][]
CAs known to the server
asn1DerEncodedPrincipals
)

Implements org.conscrypt.NativeCrypto.SSLHandshakeCallbacks.clientCertificateRequested.

Called on an SSL client when the server requests (or requires a certificate).
public int
clientPSKKeyRequested(String
PSK identity hint provided by the server or null if no hint provided.
identityHint
,
byte[]
buffer to be populated with PSK identity (NULL-terminated modified UTF-8) by this method. This identity will be provided to the server.
identity
,
byte[]
buffer to be populated with key material by this method.
key
)

Implements org.conscrypt.NativeCrypto.SSLHandshakeCallbacks.clientPSKKeyRequested.

Gets the key to be used in client mode for this connection in Pre-Shared Key (PSK) key exchange.
private ClientSessionContext
private void
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 SSLException
private long
directByteBufferAddress(ByteBuffer directBuffer, int pos)

pack-priv byte[]
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
)

Implements abstract org.conscrypt.AbstractConscryptEngine.exportKeyingMaterial.

Exports a value derived from the TLS master secret as described in RFC 5705.
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
private void
private void
public String
getApplicationProtocol()

Implements abstract org.conscrypt.AbstractConscryptEngine.getApplicationProtocol.

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

Implements abstract org.conscrypt.AbstractConscryptEngine.getApplicationProtocols.

Returns the list of supported ALPN protocols.
pack-priv byte[]

Returns:

channel ID or null if not available.
getChannelId
()

Implements abstract org.conscrypt.AbstractConscryptEngine.getChannelId.

Gets the TLS Channel ID for this server engine.
pack-priv static BufferAllocator
getDefaultBufferAllocator()

Returns the default BufferAllocator, which may be null if no default has been explicitly set.

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.
private SSLEngineResult.Status
public String
getHandshakeApplicationProtocol()

Implements abstract org.conscrypt.AbstractConscryptEngine.getHandshakeApplicationProtocol.

Returns the application protocol value negotiated on a SSL/TLS handshake currently in progress.
public SSLEngineResult.HandshakeStatus
getHandshakeStatus()

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

Returns the current handshake status for this SSLEngine.
private SSLEngineResult.HandshakeStatus
getHandshakeStatus(int pending)

private SSLEngineResult.HandshakeStatus
pack-priv String
getHostname()

Implements abstract org.conscrypt.AbstractConscryptEngine.getHostname.

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

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

Returns true if the engine will require client authentication.
private ByteBuffer
public String
getPeerHost()

Implements abstract org.conscrypt.AbstractConscryptEngine.getPeerHost.

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

Implements abstract org.conscrypt.AbstractConscryptEngine.getPeerPort.

Returns the port number of the peer.
public SecretKey
getPSKKey(PSKKeyManager keyManager, String identityHint, String identity)

Implements org.conscrypt.SSLParametersImpl.PSKCallbacks.getPSKKey.

Deprecated as a consequence of PSKKeyManager being deprecated.
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.
pack-priv byte[]
getTlsUnique()

Implements abstract org.conscrypt.AbstractConscryptEngine.getTlsUnique.

Returns the tls-unique channel binding value for this connection, per RFC 5929.
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.
private SSLEngineResult.HandshakeStatus
pack-priv SSLSession
handshakeSession()

Implements abstract org.conscrypt.AbstractConscryptEngine.handshakeSession.

Work-around to allow this method to be called on older versions of Android.
private boolean
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.
pack-priv int
maxSealOverhead()

Implements abstract org.conscrypt.AbstractConscryptEngine.maxSealOverhead.

Returns the maximum overhead, in bytes, of sealing a record with SSL.
private SSLEngineResult.HandshakeStatus
private SSLEngineResult
newResult(int bytesConsumed, int bytesProduced, SSLEngineResult.HandshakeStatus status)

private static NativeSsl
private SSLException
public void
onNewSessionEstablished(long sslSessionNativePtr)

Implements org.conscrypt.NativeCrypto.SSLHandshakeCallbacks.onNewSessionEstablished.

Called when a new session has been established and may be added to the session cache.
public void
onSSLStateChange(int type, int val)

Implements org.conscrypt.NativeCrypto.SSLHandshakeCallbacks.onSSLStateChange.

Called when SSL state changes.
private int
pack-priv int
private static SSLEngineResult.HandshakeStatus
pendingStatus(int pendingOutboundBytes)

private ConscryptSession
private ConscryptSession
private ConscryptSession
private int
readEncryptedData(final ByteBuffer dst, final int pending)

Read encrypted data from the OpenSSL network BIO

private int
readEncryptedDataDirect(ByteBuffer dst, int pos, int len)

private int
private SSLEngineResult
readPendingBytesFromBIO(ByteBuffer dst, int bytesConsumed, int bytesProduced, SSLEngineResult.HandshakeStatus status)

private int
readPlaintextData(final ByteBuffer dst)

Read plaintext data from the OpenSSL internal BIO

private int
readPlaintextDataDirect(ByteBuffer dst, int pos, int len)

private int
private void
private void
public int
selectApplicationProtocol(byte[]
list of application protocols in length-prefix format
protocols
)

Implements org.conscrypt.NativeCrypto.SSLHandshakeCallbacks.selectApplicationProtocol.

Called when acting as a server, the socket has an ApplicationProtocolSelectorAdapter associated with it, and the application protocol needs to be selected.
private void
public void
serverCertificateRequested()

Implements org.conscrypt.NativeCrypto.SSLHandshakeCallbacks.serverCertificateRequested.

Called when acting as a server during ClientHello processing before a decision to resume a session is made.
public int
serverPSKKeyRequested(String
PSK identity hint provided by this server to the client or null if no hint was provided.
identityHint
,
String
PSK identity provided by the client.
identity
,
byte[]
buffer to be populated with key material by this method.
key
)

Implements org.conscrypt.NativeCrypto.SSLHandshakeCallbacks.serverPSKKeyRequested.

Gets the key to be used in server mode for this connection in Pre-Shared Key (PSK) key exchange.
public long
serverSessionRequested(byte[]
the ID of the session to find.
id
)

Implements org.conscrypt.NativeCrypto.SSLHandshakeCallbacks.serverSessionRequested.

Called for servers where TLS < 1.3 (TLS 1.3 uses session tickets rather than application session caches).
private AbstractSessionContext
pack-priv void
setApplicationProtocols(String[]
the list of ALPN protocols
protocols
)

Implements abstract org.conscrypt.AbstractConscryptEngine.setApplicationProtocols.

Sets the list of ALPN protocols.
pack-priv void
setApplicationProtocolSelector(ApplicationProtocolSelector selector)

Implements abstract org.conscrypt.AbstractConscryptEngine.setApplicationProtocolSelector.

Sets an application-provided ALPN protocol selector.
pack-priv void
pack-priv void
pack-priv void
setChannelIdEnabled(boolean enabled)

Implements abstract org.conscrypt.AbstractConscryptEngine.setChannelIdEnabled.

Enables/disables TLS Channel ID for this server engine.
pack-priv 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
)

Implements abstract org.conscrypt.AbstractConscryptEngine.setChannelIdPrivateKey.

Sets the PrivateKey to be used for TLS Channel ID by this client engine.
pack-priv static void
setDefaultBufferAllocator(BufferAllocator bufferAllocator)

Configures the default BufferAllocator to be used by all future SSLEngine and ConscryptEngineSocket instances from this provider.

public void
setEnabledCipherSuites(String[]
Names of all the cipher suites to enable
suites
)

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

Sets the cipher suites enabled for use on this engine.
public void
setEnabledProtocols(String[]
Names of all the protocols to enable.
protocols
)

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

Set the protocol versions enabled for use on this engine.
public void
setEnableSessionCreation(boolean
true indicates that sessions may be created; this is the default. false indicates that an existing session must be resumed
flag
)

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

Controls whether new SSL sessions may be established by this engine.
pack-priv void
setHandshakeListener(HandshakeListener handshakeListener)

Implements abstract org.conscrypt.AbstractConscryptEngine.setHandshakeListener.

Sets the listener for the completion of the TLS handshake.
pack-priv void
setHostname(String hostname)

Implements abstract org.conscrypt.AbstractConscryptEngine.setHostname.

This method enables Server Name Indication (SNI) and overrides the PeerInfoProvider supplied during engine creation.
public void
setNeedClientAuth(boolean
set to true if client authentication is required, or false if no client authentication is desired.
need
)

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

Configures the engine to require client authentication.
public void
setSSLParameters(SSLParameters
the parameters
p
)

Overrides javax.net.ssl.SSLEngine.setSSLParameters.

Applies SSLParameters to this engine.
public void
setUseClientMode(boolean
true if the engine should start its handshaking in "client" mode
mode
)

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

Configures the engine to use client (or server) mode when handshaking.
pack-priv void
setUseSessionTickets(boolean
True to enable session tickets
useSessionTickets
)

Implements abstract org.conscrypt.AbstractConscryptEngine.setUseSessionTickets.

This method enables session ticket support.
public void
setWantClientAuth(boolean
set to true if client authentication is requested, or false if no client authentication is desired.
want
)

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

Configures the engine to request client authentication.
private ByteBuffer[]
private ByteBuffer[]
private void
transitionTo(int newState)

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

Implements abstract org.conscrypt.AbstractConscryptEngine.unwrap.

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

Implements abstract org.conscrypt.AbstractConscryptEngine.unwrap.

Attempts to decode SSL/TLS/DTLS network data into a sequence of plaintext application data buffers.
public 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 org.conscrypt.AbstractConscryptEngine.unwrap.

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

Implements abstract org.conscrypt.AbstractConscryptEngine.unwrap.

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

Implements abstract org.conscrypt.AbstractConscryptEngine.unwrap.

public void
verifyCertificateChain(byte[][]
chain of X.509 certificates in their encoded form
certChain
,
String
auth algorithm name
authMethod
)

Implements org.conscrypt.NativeCrypto.SSLHandshakeCallbacks.verifyCertificateChain.

Verify that the certificate chain is trusted.
public SSLEngineResult
wrap(ByteBuffer
a ByteBuffer containing outbound application data
src
,
ByteBuffer
a ByteBuffer to hold outbound network data
dst
)

Implements abstract org.conscrypt.AbstractConscryptEngine.wrap.

Attempts to encode a buffer of plaintext application data into SSL/TLS/DTLS network data.
public 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 org.conscrypt.AbstractConscryptEngine.wrap.

Attempts to encode plaintext bytes from a subsequence of data buffers into SSL/TLS/DTLS network data.
private int
writeEncryptedData(final ByteBuffer src, int len)

Write encrypted data to the OpenSSL network BIO.

private int
writeEncryptedDataDirect(ByteBuffer src, int pos, int len)

private int
writeEncryptedDataHeap(ByteBuffer src, int pos, int len)

private int
writePlaintextData(final ByteBuffer src, int len)

Write plaintext data to the OpenSSL internal BIO Calling this function with src.remaining == 0 is undefined.

private int
writePlaintextDataDirect(ByteBuffer src, int pos, int len)

private int
writePlaintextDataHeap(ByteBuffer src, int pos, int len)

Inherited from org.conscrypt.AbstractConscryptEngine:
getHandshakeSession