Package org.conscrypt
Class AbstractConscryptSocket
java.lang.Object
java.net.Socket
javax.net.ssl.SSLSocket
org.conscrypt.AbstractConscryptSocket
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
OpenSSLSocketImpl
Abstract base class for all Conscrypt
SSLSocket
classes.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private final List
<HandshakeCompletedListener> private String
The peer's DNS hostname if it was supplied during creation.private final PeerInfoProvider
private final int
The peer's port if it was supplied during creation.private int
Local cache of timeout to avoid getsockopt on every read and write for non-wrapped sockets.(package private) final Socket
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractConscryptSocket
(String hostname, int port) AbstractConscryptSocket
(String hostname, int port, InetAddress clientAddress, int clientPort) AbstractConscryptSocket
(InetAddress address, int port) AbstractConscryptSocket
(InetAddress address, int port, InetAddress clientAddress, int clientPort) AbstractConscryptSocket
(Socket socket, String hostname, int port, boolean autoClose) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
bind
(SocketAddress bindpoint) (package private) final void
void
close()
final void
connect
(SocketAddress endpoint) final void
connect
(SocketAddress endpoint, int timeout) Try to extract the peer's hostname if it's available from the endpoint address.(package private) abstract byte[]
exportKeyingMaterial
(String label, byte[] context, int length) Exports a value derived from the TLS master secret as described in RFC 5705.(package private) abstract SSLSession
Called bynotifyHandshakeCompletedListeners()
to get the currently active session.(package private) abstract byte[]
Deprecated.abstract String
(package private) abstract String[]
Returns the list of supported ALPN protocols.(package private) abstract byte[]
Gets the TLS Channel ID for this server socket.abstract String
abstract SSLSession
(package private) String
Returns the hostname that was supplied during socket creation.(package private) String
For the purposes of an SSLSession, we want a way to represent the supplied hostname or the IP address in a textual representation.boolean
int
(package private) byte[]
Deprecated.NPN is not supportedboolean
final int
getPort()
int
boolean
int
int
final int
(package private) int
Note write timeouts are not part of the javax.net.ssl.SSLSocket APIboolean
(package private) abstract byte[]
Returns the tls-unique channel binding value for this connection, per RFC 5929.int
boolean
isBound()
boolean
isClosed()
boolean
private boolean
boolean
boolean
(package private) final void
(package private) final PeerInfoProvider
void
final void
sendUrgentData
(int data) (package private) abstract void
setAlpnProtocols
(byte[] alpnProtocols) Deprecated.UsesetApplicationProtocols(String[])
instead.(package private) abstract void
setAlpnProtocols
(String[] alpnProtocols) Deprecated.usesetApplicationProtocols(String[])
instead.(package private) abstract void
setApplicationProtocols
(String[] protocols) Sets the list of ALPN protocols.(package private) abstract void
Sets an application-provided ALPN protocol selector.(package private) abstract void
(package private) abstract void
setChannelIdEnabled
(boolean enabled) Enables/disables TLS Channel ID for this server socket.(package private) abstract void
setChannelIdPrivateKey
(PrivateKey privateKey) Sets thePrivateKey
to be used for TLS Channel ID by this client socket.(package private) void
setHandshakeTimeout
(int handshakeTimeoutMilliseconds) Set the handshake timeout on this socket.(package private) void
setHostname
(String hostname) This method enables Server Name Indicationvoid
setKeepAlive
(boolean on) (package private) void
setNpnProtocols
(byte[] npnProtocols) Deprecated.NPN is not supportedfinal void
setOOBInline
(boolean on) void
setPerformancePreferences
(int connectionTime, int latency, int bandwidth) void
setReceiveBufferSize
(int size) void
setReuseAddress
(boolean on) void
setSendBufferSize
(int size) void
setSoLinger
(boolean on, int linger) final void
setSoTimeout
(int readTimeoutMilliseconds) (package private) void
setSoWriteTimeout
(int writeTimeoutMilliseconds) Note write timeouts are not part of the javax.net.ssl.SSLSocket APIvoid
setTcpNoDelay
(boolean on) void
setTrafficClass
(int tc) (package private) abstract void
setUseSessionTickets
(boolean useSessionTickets) This method enables session ticket support.void
void
toString()
Methods inherited from class javax.net.ssl.SSLSocket
getEnabledCipherSuites, getEnabledProtocols, getEnableSessionCreation, getHandshakeApplicationProtocolSelector, getNeedClientAuth, getSession, getSSLParameters, getSupportedCipherSuites, getSupportedProtocols, getUseClientMode, getWantClientAuth, setEnabledCipherSuites, setEnabledProtocols, setEnableSessionCreation, setHandshakeApplicationProtocolSelector, setNeedClientAuth, setSSLParameters, setUseClientMode, setWantClientAuth, startHandshake
Methods inherited from class java.net.Socket
getOption, setOption, setSocketImplFactory, supportedOptions
-
Field Details
-
socket
-
autoClose
private final boolean autoClose -
peerHostname
The peer's DNS hostname if it was supplied during creation. Note that this may be a raw IP address, so it should be checked before use with extensions that don't use it like Server Name Indication (SNI). -
peerPort
private final int peerPortThe peer's port if it was supplied during creation. Should only be set ifpeerHostname
is also set. -
peerInfoProvider
-
listeners
-
readTimeoutMilliseconds
private int readTimeoutMillisecondsLocal cache of timeout to avoid getsockopt on every read and write for non-wrapped sockets. Note that this is not used when delegating to another socket.
-
-
Constructor Details
-
AbstractConscryptSocket
AbstractConscryptSocket() throws IOException- Throws:
IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(String hostname, int port) throws IOException - Throws:
IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(InetAddress address, int port) throws IOException - Throws:
IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(String hostname, int port, InetAddress clientAddress, int clientPort) throws IOException - Throws:
IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(InetAddress address, int port, InetAddress clientAddress, int clientPort) throws IOException - Throws:
IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(Socket socket, String hostname, int port, boolean autoClose) throws IOException - Throws:
IOException
-
-
Method Details
-
connect
- Overrides:
connect
in classSocket
- Throws:
IOException
-
connect
Try to extract the peer's hostname if it's available from the endpoint address.- Overrides:
connect
in classSocket
- Throws:
IOException
-
bind
- Overrides:
bind
in classSocket
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classSocket
- Throws:
IOException
-
getInetAddress
- Overrides:
getInetAddress
in classSocket
-
getLocalAddress
- Overrides:
getLocalAddress
in classSocket
-
getLocalPort
public int getLocalPort()- Overrides:
getLocalPort
in classSocket
-
getRemoteSocketAddress
- Overrides:
getRemoteSocketAddress
in classSocket
-
getLocalSocketAddress
- Overrides:
getLocalSocketAddress
in classSocket
-
getPort
public final int getPort() -
addHandshakeCompletedListener
- Specified by:
addHandshakeCompletedListener
in classSSLSocket
-
removeHandshakeCompletedListener
- Specified by:
removeHandshakeCompletedListener
in classSSLSocket
-
getFileDescriptor$
-
setSoTimeout
- Overrides:
setSoTimeout
in classSocket
- Throws:
SocketException
-
getSoTimeout
- Overrides:
getSoTimeout
in classSocket
- Throws:
SocketException
-
sendUrgentData
- Overrides:
sendUrgentData
in classSocket
- Throws:
IOException
-
setOOBInline
- Overrides:
setOOBInline
in classSocket
- Throws:
SocketException
-
getOOBInline
- Overrides:
getOOBInline
in classSocket
- Throws:
SocketException
-
getChannel
- Overrides:
getChannel
in classSocket
-
getInputStream
- Overrides:
getInputStream
in classSocket
- Throws:
IOException
-
getOutputStream
- Overrides:
getOutputStream
in classSocket
- Throws:
IOException
-
setTcpNoDelay
- Overrides:
setTcpNoDelay
in classSocket
- Throws:
SocketException
-
getTcpNoDelay
- Overrides:
getTcpNoDelay
in classSocket
- Throws:
SocketException
-
setSoLinger
- Overrides:
setSoLinger
in classSocket
- Throws:
SocketException
-
getSoLinger
- Overrides:
getSoLinger
in classSocket
- Throws:
SocketException
-
setSendBufferSize
- Overrides:
setSendBufferSize
in classSocket
- Throws:
SocketException
-
getSendBufferSize
- Overrides:
getSendBufferSize
in classSocket
- Throws:
SocketException
-
setReceiveBufferSize
- Overrides:
setReceiveBufferSize
in classSocket
- Throws:
SocketException
-
getReceiveBufferSize
- Overrides:
getReceiveBufferSize
in classSocket
- Throws:
SocketException
-
setKeepAlive
- Overrides:
setKeepAlive
in classSocket
- Throws:
SocketException
-
getKeepAlive
- Overrides:
getKeepAlive
in classSocket
- Throws:
SocketException
-
setTrafficClass
- Overrides:
setTrafficClass
in classSocket
- Throws:
SocketException
-
getTrafficClass
- Overrides:
getTrafficClass
in classSocket
- Throws:
SocketException
-
setReuseAddress
- Overrides:
setReuseAddress
in classSocket
- Throws:
SocketException
-
getReuseAddress
- Overrides:
getReuseAddress
in classSocket
- Throws:
SocketException
-
shutdownInput
- Overrides:
shutdownInput
in classSocket
- Throws:
IOException
-
shutdownOutput
- Overrides:
shutdownOutput
in classSocket
- Throws:
IOException
-
isConnected
public boolean isConnected()- Overrides:
isConnected
in classSocket
-
isBound
public boolean isBound() -
isClosed
public boolean isClosed() -
isInputShutdown
public boolean isInputShutdown()- Overrides:
isInputShutdown
in classSocket
-
isOutputShutdown
public boolean isOutputShutdown()- Overrides:
isOutputShutdown
in classSocket
-
setPerformancePreferences
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) - Overrides:
setPerformancePreferences
in classSocket
-
toString
-
getHostname
String getHostname()Returns the hostname that was supplied during socket creation. No DNS resolution is attempted before returning the hostname. -
setHostname
This method enables Server Name Indication- Parameters:
hostname
- the desired SNI hostname, or null to disable
-
getHostnameOrIP
String getHostnameOrIP()For the purposes of an SSLSession, we want a way to represent the supplied hostname or the IP address in a textual representation. We do not want to perform reverse DNS lookups on this address. -
setSoWriteTimeout
Note write timeouts are not part of the javax.net.ssl.SSLSocket API- Throws:
SocketException
-
getSoWriteTimeout
Note write timeouts are not part of the javax.net.ssl.SSLSocket API- Throws:
SocketException
-
setHandshakeTimeout
Set the handshake timeout on this socket. This timeout is specified in milliseconds and will be used only during the handshake process.- Throws:
SocketException
-
checkOpen
- Throws:
SocketException
-
peerInfoProvider
-
getActiveSession
Called bynotifyHandshakeCompletedListeners()
to get the currently active session. UnlikeSSLSocket.getSession()
, this method must not block. -
setApplicationProtocolSelector
-
notifyHandshakeCompletedListeners
final void notifyHandshakeCompletedListeners() -
isDelegating
private boolean isDelegating() -
getHandshakeSession
- Overrides:
getHandshakeSession
in classSSLSocket
-
setUseSessionTickets
abstract void setUseSessionTickets(boolean useSessionTickets) This method enables session ticket support.- Parameters:
useSessionTickets
- True to enable session tickets
-
setChannelIdEnabled
abstract void setChannelIdEnabled(boolean enabled) Enables/disables TLS Channel ID for this server socket.This method needs to be invoked before the handshake starts.
- Throws:
IllegalStateException
- if this is a client socket or if the handshake has already started.
-
getChannelId
Gets the TLS Channel ID for this server socket. Channel ID is only available once the handshake completes.- Returns:
- channel ID or
null
if not available. - Throws:
IllegalStateException
- if this is a client socket or if the handshake has not yet completed.SSLException
- if channel ID is available but could not be obtained.
-
setChannelIdPrivateKey
Sets thePrivateKey
to be used for TLS Channel ID by this client socket.This method needs to be invoked before the handshake starts.
- Parameters:
privateKey
- private key (enables TLS Channel ID) ornull
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).- Throws:
IllegalStateException
- if this is a server socket or if the handshake has already started.
-
getNpnSelectedProtocol
Deprecated.NPN is not supportedReturns null always for backward compatibility. -
setNpnProtocols
Deprecated.NPN is not supportedThis method does nothing and is kept for backward compatibility. -
getAlpnSelectedProtocol
Deprecated.usegetApplicationProtocol()
instead.Returns the protocol agreed upon by client and server, ornull
if no protocol was agreed upon. -
setAlpnProtocols
Deprecated.usesetApplicationProtocols(String[])
instead.Sets the list of ALPN protocols. This method internally converts the protocols to their wire-format form.- Parameters:
alpnProtocols
- the list of ALPN protocols
-
setAlpnProtocols
Deprecated.UsesetApplicationProtocols(String[])
instead.Alternate version ofsetAlpnProtocols(String[])
that directly sets the list of ALPN in the wire-format form used by BoringSSL (length-prefixed 8-bit strings). Requires that all strings be encoded with US-ASCII.- Parameters:
alpnProtocols
- the encoded form of the ALPN protocol list
-
setApplicationProtocols
Sets the list of ALPN protocols.- Parameters:
protocols
- the list of ALPN protocols
-
getApplicationProtocols
Returns the list of supported ALPN protocols. -
getApplicationProtocol
- Overrides:
getApplicationProtocol
in classSSLSocket
-
getHandshakeApplicationProtocol
- Overrides:
getHandshakeApplicationProtocol
in classSSLSocket
-
setApplicationProtocolSelector
Sets an application-provided ALPN protocol selector. If provided, this will override the list of protocols set bysetApplicationProtocols(String[])
. -
getTlsUnique
abstract byte[] getTlsUnique()Returns the tls-unique channel binding value for this connection, per RFC 5929. This will returnnull
if there is no such value available, such as if the handshake has not yet completed or this connection is closed. -
exportKeyingMaterial
Exports a value derived from the TLS master secret as described in RFC 5705.- Parameters:
label
- the label to use in calculating the exported value. This must be an ASCII-only string.context
- the application-specific context value to use in calculating the exported value. This may benull
to use no application context, which is treated differently than an empty byte array.length
- the number of bytes of keying material to return.- Returns:
- a value of the specified length, or
null
if the handshake has not yet completed or the connection has been closed. - Throws:
SSLException
- if the value could not be exported.
-
getApplicationProtocol()
instead.