Package org.conscrypt
Class AbstractConscryptSocket
- java.lang.Object
-
- java.net.Socket
-
- javax.net.ssl.SSLSocket
-
- org.conscrypt.AbstractConscryptSocket
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
OpenSSLSocketImpl
abstract class AbstractConscryptSocket extends javax.net.ssl.SSLSocket
Abstract base class for all ConscryptSSLSocket
classes.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
autoClose
private java.util.List<javax.net.ssl.HandshakeCompletedListener>
listeners
private java.lang.String
peerHostname
The peer's DNS hostname if it was supplied during creation.private PeerInfoProvider
peerInfoProvider
private int
peerPort
The peer's port if it was supplied during creation.private int
readTimeoutMilliseconds
Local cache of timeout to avoid getsockopt on every read and write for non-wrapped sockets.(package private) java.net.Socket
socket
-
Constructor Summary
Constructors Constructor Description AbstractConscryptSocket()
AbstractConscryptSocket(java.lang.String hostname, int port)
AbstractConscryptSocket(java.lang.String hostname, int port, java.net.InetAddress clientAddress, int clientPort)
AbstractConscryptSocket(java.net.InetAddress address, int port)
AbstractConscryptSocket(java.net.InetAddress address, int port, java.net.InetAddress clientAddress, int clientPort)
AbstractConscryptSocket(java.net.Socket socket, java.lang.String hostname, int port, boolean autoClose)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)
void
bind(java.net.SocketAddress bindpoint)
(package private) void
checkOpen()
void
close()
void
connect(java.net.SocketAddress endpoint)
void
connect(java.net.SocketAddress endpoint, int timeout)
Try to extract the peer's hostname if it's available from the endpoint address.(package private) abstract byte[]
exportKeyingMaterial(java.lang.String label, byte[] context, int length)
Exports a value derived from the TLS master secret as described in RFC 5705.(package private) abstract javax.net.ssl.SSLSession
getActiveSession()
Called bynotifyHandshakeCompletedListeners()
to get the currently active session.(package private) abstract byte[]
getAlpnSelectedProtocol()
Deprecated.usegetApplicationProtocol()
instead.abstract java.lang.String
getApplicationProtocol()
(package private) abstract java.lang.String[]
getApplicationProtocols()
Returns the list of supported ALPN protocols.java.nio.channels.SocketChannel
getChannel()
(package private) abstract byte[]
getChannelId()
Gets the TLS Channel ID for this server socket.java.io.FileDescriptor
getFileDescriptor$()
abstract java.lang.String
getHandshakeApplicationProtocol()
abstract javax.net.ssl.SSLSession
getHandshakeSession()
(package private) java.lang.String
getHostname()
Returns the hostname that was supplied during socket creation.(package private) java.lang.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.java.net.InetAddress
getInetAddress()
java.io.InputStream
getInputStream()
boolean
getKeepAlive()
java.net.InetAddress
getLocalAddress()
int
getLocalPort()
java.net.SocketAddress
getLocalSocketAddress()
(package private) byte[]
getNpnSelectedProtocol()
Deprecated.NPN is not supportedboolean
getOOBInline()
java.io.OutputStream
getOutputStream()
int
getPort()
int
getReceiveBufferSize()
java.net.SocketAddress
getRemoteSocketAddress()
boolean
getReuseAddress()
int
getSendBufferSize()
int
getSoLinger()
int
getSoTimeout()
(package private) int
getSoWriteTimeout()
Note write timeouts are not part of the javax.net.ssl.SSLSocket APIboolean
getTcpNoDelay()
(package private) abstract byte[]
getTlsUnique()
Returns the tls-unique channel binding value for this connection, per RFC 5929.int
getTrafficClass()
boolean
isBound()
boolean
isClosed()
boolean
isConnected()
private boolean
isDelegating()
boolean
isInputShutdown()
boolean
isOutputShutdown()
(package private) void
notifyHandshakeCompletedListeners()
(package private) PeerInfoProvider
peerInfoProvider()
void
removeHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)
void
sendUrgentData(int data)
(package private) abstract void
setAlpnProtocols(byte[] alpnProtocols)
Deprecated.UsesetApplicationProtocols(String[])
instead.(package private) abstract void
setAlpnProtocols(java.lang.String[] alpnProtocols)
Deprecated.usesetApplicationProtocols(String[])
instead.(package private) abstract void
setApplicationProtocols(java.lang.String[] protocols)
Sets the list of ALPN protocols.(package private) abstract void
setApplicationProtocolSelector(ApplicationProtocolSelector selector)
Sets an application-provided ALPN protocol selector.(package private) abstract void
setApplicationProtocolSelector(ApplicationProtocolSelectorAdapter selector)
(package private) abstract void
setChannelIdEnabled(boolean enabled)
Enables/disables TLS Channel ID for this server socket.(package private) abstract void
setChannelIdPrivateKey(java.security.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(java.lang.String hostname)
This method enables Server Name Indicationvoid
setKeepAlive(boolean on)
(package private) void
setNpnProtocols(byte[] npnProtocols)
Deprecated.NPN is not supportedvoid
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)
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
shutdownInput()
void
shutdownOutput()
java.lang.String
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
-
-
-
-
Field Detail
-
socket
final java.net.Socket socket
-
autoClose
private final boolean autoClose
-
peerHostname
private java.lang.String 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 peerPort
The peer's port if it was supplied during creation. Should only be set ifpeerHostname
is also set.
-
peerInfoProvider
private final PeerInfoProvider peerInfoProvider
-
listeners
private final java.util.List<javax.net.ssl.HandshakeCompletedListener> listeners
-
readTimeoutMilliseconds
private int readTimeoutMilliseconds
Local 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 Detail
-
AbstractConscryptSocket
AbstractConscryptSocket() throws java.io.IOException
- Throws:
java.io.IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(java.lang.String hostname, int port) throws java.io.IOException
- Throws:
java.io.IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(java.net.InetAddress address, int port) throws java.io.IOException
- Throws:
java.io.IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(java.lang.String hostname, int port, java.net.InetAddress clientAddress, int clientPort) throws java.io.IOException
- Throws:
java.io.IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(java.net.InetAddress address, int port, java.net.InetAddress clientAddress, int clientPort) throws java.io.IOException
- Throws:
java.io.IOException
-
AbstractConscryptSocket
AbstractConscryptSocket(java.net.Socket socket, java.lang.String hostname, int port, boolean autoClose) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
connect
public final void connect(java.net.SocketAddress endpoint) throws java.io.IOException
- Overrides:
connect
in classjava.net.Socket
- Throws:
java.io.IOException
-
connect
public final void connect(java.net.SocketAddress endpoint, int timeout) throws java.io.IOException
Try to extract the peer's hostname if it's available from the endpoint address.- Overrides:
connect
in classjava.net.Socket
- Throws:
java.io.IOException
-
bind
public void bind(java.net.SocketAddress bindpoint) throws java.io.IOException
- Overrides:
bind
in classjava.net.Socket
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.net.Socket
- Throws:
java.io.IOException
-
getInetAddress
public java.net.InetAddress getInetAddress()
- Overrides:
getInetAddress
in classjava.net.Socket
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
- Overrides:
getLocalAddress
in classjava.net.Socket
-
getLocalPort
public int getLocalPort()
- Overrides:
getLocalPort
in classjava.net.Socket
-
getRemoteSocketAddress
public java.net.SocketAddress getRemoteSocketAddress()
- Overrides:
getRemoteSocketAddress
in classjava.net.Socket
-
getLocalSocketAddress
public java.net.SocketAddress getLocalSocketAddress()
- Overrides:
getLocalSocketAddress
in classjava.net.Socket
-
getPort
public final int getPort()
- Overrides:
getPort
in classjava.net.Socket
-
addHandshakeCompletedListener
public void addHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)
- Specified by:
addHandshakeCompletedListener
in classjavax.net.ssl.SSLSocket
-
removeHandshakeCompletedListener
public void removeHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)
- Specified by:
removeHandshakeCompletedListener
in classjavax.net.ssl.SSLSocket
-
getFileDescriptor$
public java.io.FileDescriptor getFileDescriptor$()
-
setSoTimeout
public final void setSoTimeout(int readTimeoutMilliseconds) throws java.net.SocketException
- Overrides:
setSoTimeout
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getSoTimeout
public final int getSoTimeout() throws java.net.SocketException
- Overrides:
getSoTimeout
in classjava.net.Socket
- Throws:
java.net.SocketException
-
sendUrgentData
public final void sendUrgentData(int data) throws java.io.IOException
- Overrides:
sendUrgentData
in classjava.net.Socket
- Throws:
java.io.IOException
-
setOOBInline
public final void setOOBInline(boolean on) throws java.net.SocketException
- Overrides:
setOOBInline
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getOOBInline
public boolean getOOBInline() throws java.net.SocketException
- Overrides:
getOOBInline
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getChannel
public java.nio.channels.SocketChannel getChannel()
- Overrides:
getChannel
in classjava.net.Socket
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
- Overrides:
getInputStream
in classjava.net.Socket
- Throws:
java.io.IOException
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOException
- Overrides:
getOutputStream
in classjava.net.Socket
- Throws:
java.io.IOException
-
setTcpNoDelay
public void setTcpNoDelay(boolean on) throws java.net.SocketException
- Overrides:
setTcpNoDelay
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getTcpNoDelay
public boolean getTcpNoDelay() throws java.net.SocketException
- Overrides:
getTcpNoDelay
in classjava.net.Socket
- Throws:
java.net.SocketException
-
setSoLinger
public void setSoLinger(boolean on, int linger) throws java.net.SocketException
- Overrides:
setSoLinger
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getSoLinger
public int getSoLinger() throws java.net.SocketException
- Overrides:
getSoLinger
in classjava.net.Socket
- Throws:
java.net.SocketException
-
setSendBufferSize
public void setSendBufferSize(int size) throws java.net.SocketException
- Overrides:
setSendBufferSize
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getSendBufferSize
public int getSendBufferSize() throws java.net.SocketException
- Overrides:
getSendBufferSize
in classjava.net.Socket
- Throws:
java.net.SocketException
-
setReceiveBufferSize
public void setReceiveBufferSize(int size) throws java.net.SocketException
- Overrides:
setReceiveBufferSize
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getReceiveBufferSize
public int getReceiveBufferSize() throws java.net.SocketException
- Overrides:
getReceiveBufferSize
in classjava.net.Socket
- Throws:
java.net.SocketException
-
setKeepAlive
public void setKeepAlive(boolean on) throws java.net.SocketException
- Overrides:
setKeepAlive
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getKeepAlive
public boolean getKeepAlive() throws java.net.SocketException
- Overrides:
getKeepAlive
in classjava.net.Socket
- Throws:
java.net.SocketException
-
setTrafficClass
public void setTrafficClass(int tc) throws java.net.SocketException
- Overrides:
setTrafficClass
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getTrafficClass
public int getTrafficClass() throws java.net.SocketException
- Overrides:
getTrafficClass
in classjava.net.Socket
- Throws:
java.net.SocketException
-
setReuseAddress
public void setReuseAddress(boolean on) throws java.net.SocketException
- Overrides:
setReuseAddress
in classjava.net.Socket
- Throws:
java.net.SocketException
-
getReuseAddress
public boolean getReuseAddress() throws java.net.SocketException
- Overrides:
getReuseAddress
in classjava.net.Socket
- Throws:
java.net.SocketException
-
shutdownInput
public void shutdownInput() throws java.io.IOException
- Overrides:
shutdownInput
in classjava.net.Socket
- Throws:
java.io.IOException
-
shutdownOutput
public void shutdownOutput() throws java.io.IOException
- Overrides:
shutdownOutput
in classjava.net.Socket
- Throws:
java.io.IOException
-
isConnected
public boolean isConnected()
- Overrides:
isConnected
in classjava.net.Socket
-
isBound
public boolean isBound()
- Overrides:
isBound
in classjava.net.Socket
-
isClosed
public boolean isClosed()
- Overrides:
isClosed
in classjava.net.Socket
-
isInputShutdown
public boolean isInputShutdown()
- Overrides:
isInputShutdown
in classjava.net.Socket
-
isOutputShutdown
public boolean isOutputShutdown()
- Overrides:
isOutputShutdown
in classjava.net.Socket
-
setPerformancePreferences
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth)
- Overrides:
setPerformancePreferences
in classjava.net.Socket
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.net.Socket
-
getHostname
java.lang.String getHostname()
Returns the hostname that was supplied during socket creation. No DNS resolution is attempted before returning the hostname.
-
setHostname
void setHostname(java.lang.String hostname)
This method enables Server Name Indication- Parameters:
hostname
- the desired SNI hostname, or null to disable
-
getHostnameOrIP
java.lang.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
void setSoWriteTimeout(int writeTimeoutMilliseconds) throws java.net.SocketException
Note write timeouts are not part of the javax.net.ssl.SSLSocket API- Throws:
java.net.SocketException
-
getSoWriteTimeout
int getSoWriteTimeout() throws java.net.SocketException
Note write timeouts are not part of the javax.net.ssl.SSLSocket API- Throws:
java.net.SocketException
-
setHandshakeTimeout
void setHandshakeTimeout(int handshakeTimeoutMilliseconds) throws java.net.SocketException
Set the handshake timeout on this socket. This timeout is specified in milliseconds and will be used only during the handshake process.- Throws:
java.net.SocketException
-
checkOpen
final void checkOpen() throws java.net.SocketException
- Throws:
java.net.SocketException
-
peerInfoProvider
final PeerInfoProvider peerInfoProvider()
-
getActiveSession
abstract javax.net.ssl.SSLSession getActiveSession()
Called bynotifyHandshakeCompletedListeners()
to get the currently active session. UnlikeSSLSocket.getSession()
, this method must not block.
-
setApplicationProtocolSelector
abstract void setApplicationProtocolSelector(ApplicationProtocolSelectorAdapter selector)
-
notifyHandshakeCompletedListeners
final void notifyHandshakeCompletedListeners()
-
isDelegating
private boolean isDelegating()
-
getHandshakeSession
public abstract javax.net.ssl.SSLSession getHandshakeSession()
- Overrides:
getHandshakeSession
in classjavax.net.ssl.SSLSocket
-
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:
java.lang.IllegalStateException
- if this is a client socket or if the handshake has already started.
-
getChannelId
abstract byte[] getChannelId() throws javax.net.ssl.SSLException
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:
java.lang.IllegalStateException
- if this is a client socket or if the handshake has not yet completed.javax.net.ssl.SSLException
- if channel ID is available but could not be obtained.
-
setChannelIdPrivateKey
abstract void setChannelIdPrivateKey(java.security.PrivateKey privateKey)
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:
java.lang.IllegalStateException
- if this is a server socket or if the handshake has already started.
-
getNpnSelectedProtocol
@Deprecated byte[] getNpnSelectedProtocol()
Deprecated.NPN is not supportedReturns null always for backward compatibility.
-
setNpnProtocols
@Deprecated void setNpnProtocols(byte[] npnProtocols)
Deprecated.NPN is not supportedThis method does nothing and is kept for backward compatibility.
-
getAlpnSelectedProtocol
@Deprecated abstract byte[] getAlpnSelectedProtocol()
Deprecated.usegetApplicationProtocol()
instead.Returns the protocol agreed upon by client and server, ornull
if no protocol was agreed upon.
-
setAlpnProtocols
@Deprecated abstract void setAlpnProtocols(java.lang.String[] alpnProtocols)
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 abstract void setAlpnProtocols(byte[] alpnProtocols)
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
abstract void setApplicationProtocols(java.lang.String[] protocols)
Sets the list of ALPN protocols.- Parameters:
protocols
- the list of ALPN protocols
-
getApplicationProtocols
abstract java.lang.String[] getApplicationProtocols()
Returns the list of supported ALPN protocols.
-
getApplicationProtocol
public abstract java.lang.String getApplicationProtocol()
- Overrides:
getApplicationProtocol
in classjavax.net.ssl.SSLSocket
-
getHandshakeApplicationProtocol
public abstract java.lang.String getHandshakeApplicationProtocol()
- Overrides:
getHandshakeApplicationProtocol
in classjavax.net.ssl.SSLSocket
-
setApplicationProtocolSelector
abstract void setApplicationProtocolSelector(ApplicationProtocolSelector selector)
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
abstract byte[] exportKeyingMaterial(java.lang.String label, byte[] context, int length) throws javax.net.ssl.SSLException
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:
javax.net.ssl.SSLException
- if the value could not be exported.
-
-