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.SSLSocketAbstract base class for all ConscryptSSLSocketclasses.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanautoCloseprivate java.util.List<javax.net.ssl.HandshakeCompletedListener>listenersprivate java.lang.StringpeerHostnameThe peer's DNS hostname if it was supplied during creation.private PeerInfoProviderpeerInfoProviderprivate intpeerPortThe peer's port if it was supplied during creation.private intreadTimeoutMillisecondsLocal cache of timeout to avoid getsockopt on every read and write for non-wrapped sockets.(package private) java.net.Socketsocket
-
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 voidaddHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)voidbind(java.net.SocketAddress bindpoint)(package private) voidcheckOpen()voidclose()voidconnect(java.net.SocketAddress endpoint)voidconnect(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.SSLSessiongetActiveSession()Called bynotifyHandshakeCompletedListeners()to get the currently active session.(package private) abstract byte[]getAlpnSelectedProtocol()Deprecated.usegetApplicationProtocol()instead.abstract java.lang.StringgetApplicationProtocol()(package private) abstract java.lang.String[]getApplicationProtocols()Returns the list of supported ALPN protocols.java.nio.channels.SocketChannelgetChannel()(package private) abstract byte[]getChannelId()Gets the TLS Channel ID for this server socket.java.io.FileDescriptorgetFileDescriptor$()abstract java.lang.StringgetHandshakeApplicationProtocol()abstract javax.net.ssl.SSLSessiongetHandshakeSession()(package private) java.lang.StringgetHostname()Returns the hostname that was supplied during socket creation.(package private) java.lang.StringgetHostnameOrIP()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.InetAddressgetInetAddress()java.io.InputStreamgetInputStream()booleangetKeepAlive()java.net.InetAddressgetLocalAddress()intgetLocalPort()java.net.SocketAddressgetLocalSocketAddress()(package private) byte[]getNpnSelectedProtocol()Deprecated.NPN is not supportedbooleangetOOBInline()java.io.OutputStreamgetOutputStream()intgetPort()intgetReceiveBufferSize()java.net.SocketAddressgetRemoteSocketAddress()booleangetReuseAddress()intgetSendBufferSize()intgetSoLinger()intgetSoTimeout()(package private) intgetSoWriteTimeout()Note write timeouts are not part of the javax.net.ssl.SSLSocket APIbooleangetTcpNoDelay()(package private) abstract byte[]getTlsUnique()Returns the tls-unique channel binding value for this connection, per RFC 5929.intgetTrafficClass()booleanisBound()booleanisClosed()booleanisConnected()private booleanisDelegating()booleanisInputShutdown()booleanisOutputShutdown()(package private) voidnotifyHandshakeCompletedListeners()(package private) PeerInfoProviderpeerInfoProvider()voidremoveHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)voidsendUrgentData(int data)(package private) abstract voidsetAlpnProtocols(byte[] alpnProtocols)Deprecated.UsesetApplicationProtocols(String[])instead.(package private) abstract voidsetAlpnProtocols(java.lang.String[] alpnProtocols)Deprecated.usesetApplicationProtocols(String[])instead.(package private) abstract voidsetApplicationProtocols(java.lang.String[] protocols)Sets the list of ALPN protocols.(package private) abstract voidsetApplicationProtocolSelector(ApplicationProtocolSelector selector)Sets an application-provided ALPN protocol selector.(package private) abstract voidsetApplicationProtocolSelector(ApplicationProtocolSelectorAdapter selector)(package private) abstract voidsetChannelIdEnabled(boolean enabled)Enables/disables TLS Channel ID for this server socket.(package private) abstract voidsetChannelIdPrivateKey(java.security.PrivateKey privateKey)Sets thePrivateKeyto be used for TLS Channel ID by this client socket.(package private) voidsetHandshakeTimeout(int handshakeTimeoutMilliseconds)Set the handshake timeout on this socket.(package private) voidsetHostname(java.lang.String hostname)This method enables Server Name IndicationvoidsetKeepAlive(boolean on)(package private) voidsetNpnProtocols(byte[] npnProtocols)Deprecated.NPN is not supportedvoidsetOOBInline(boolean on)voidsetPerformancePreferences(int connectionTime, int latency, int bandwidth)voidsetReceiveBufferSize(int size)voidsetReuseAddress(boolean on)voidsetSendBufferSize(int size)voidsetSoLinger(boolean on, int linger)voidsetSoTimeout(int readTimeoutMilliseconds)(package private) voidsetSoWriteTimeout(int writeTimeoutMilliseconds)Note write timeouts are not part of the javax.net.ssl.SSLSocket APIvoidsetTcpNoDelay(boolean on)voidsetTrafficClass(int tc)(package private) abstract voidsetUseSessionTickets(boolean useSessionTickets)This method enables session ticket support.voidshutdownInput()voidshutdownOutput()java.lang.StringtoString()-
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 ifpeerHostnameis 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:
connectin classjava.net.Socket- Throws:
java.io.IOException
-
connect
public final void connect(java.net.SocketAddress endpoint, int timeout) throws java.io.IOExceptionTry to extract the peer's hostname if it's available from the endpoint address.- Overrides:
connectin classjava.net.Socket- Throws:
java.io.IOException
-
bind
public void bind(java.net.SocketAddress bindpoint) throws java.io.IOException- Overrides:
bindin classjava.net.Socket- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.net.Socket- Throws:
java.io.IOException
-
getInetAddress
public java.net.InetAddress getInetAddress()
- Overrides:
getInetAddressin classjava.net.Socket
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
- Overrides:
getLocalAddressin classjava.net.Socket
-
getLocalPort
public int getLocalPort()
- Overrides:
getLocalPortin classjava.net.Socket
-
getRemoteSocketAddress
public java.net.SocketAddress getRemoteSocketAddress()
- Overrides:
getRemoteSocketAddressin classjava.net.Socket
-
getLocalSocketAddress
public java.net.SocketAddress getLocalSocketAddress()
- Overrides:
getLocalSocketAddressin classjava.net.Socket
-
getPort
public final int getPort()
- Overrides:
getPortin classjava.net.Socket
-
addHandshakeCompletedListener
public void addHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)
- Specified by:
addHandshakeCompletedListenerin classjavax.net.ssl.SSLSocket
-
removeHandshakeCompletedListener
public void removeHandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener listener)
- Specified by:
removeHandshakeCompletedListenerin classjavax.net.ssl.SSLSocket
-
getFileDescriptor$
public java.io.FileDescriptor getFileDescriptor$()
-
setSoTimeout
public final void setSoTimeout(int readTimeoutMilliseconds) throws java.net.SocketException- Overrides:
setSoTimeoutin classjava.net.Socket- Throws:
java.net.SocketException
-
getSoTimeout
public final int getSoTimeout() throws java.net.SocketException- Overrides:
getSoTimeoutin classjava.net.Socket- Throws:
java.net.SocketException
-
sendUrgentData
public final void sendUrgentData(int data) throws java.io.IOException- Overrides:
sendUrgentDatain classjava.net.Socket- Throws:
java.io.IOException
-
setOOBInline
public final void setOOBInline(boolean on) throws java.net.SocketException- Overrides:
setOOBInlinein classjava.net.Socket- Throws:
java.net.SocketException
-
getOOBInline
public boolean getOOBInline() throws java.net.SocketException- Overrides:
getOOBInlinein classjava.net.Socket- Throws:
java.net.SocketException
-
getChannel
public java.nio.channels.SocketChannel getChannel()
- Overrides:
getChannelin classjava.net.Socket
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException- Overrides:
getInputStreamin classjava.net.Socket- Throws:
java.io.IOException
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOException- Overrides:
getOutputStreamin classjava.net.Socket- Throws:
java.io.IOException
-
setTcpNoDelay
public void setTcpNoDelay(boolean on) throws java.net.SocketException- Overrides:
setTcpNoDelayin classjava.net.Socket- Throws:
java.net.SocketException
-
getTcpNoDelay
public boolean getTcpNoDelay() throws java.net.SocketException- Overrides:
getTcpNoDelayin classjava.net.Socket- Throws:
java.net.SocketException
-
setSoLinger
public void setSoLinger(boolean on, int linger) throws java.net.SocketException- Overrides:
setSoLingerin classjava.net.Socket- Throws:
java.net.SocketException
-
getSoLinger
public int getSoLinger() throws java.net.SocketException- Overrides:
getSoLingerin classjava.net.Socket- Throws:
java.net.SocketException
-
setSendBufferSize
public void setSendBufferSize(int size) throws java.net.SocketException- Overrides:
setSendBufferSizein classjava.net.Socket- Throws:
java.net.SocketException
-
getSendBufferSize
public int getSendBufferSize() throws java.net.SocketException- Overrides:
getSendBufferSizein classjava.net.Socket- Throws:
java.net.SocketException
-
setReceiveBufferSize
public void setReceiveBufferSize(int size) throws java.net.SocketException- Overrides:
setReceiveBufferSizein classjava.net.Socket- Throws:
java.net.SocketException
-
getReceiveBufferSize
public int getReceiveBufferSize() throws java.net.SocketException- Overrides:
getReceiveBufferSizein classjava.net.Socket- Throws:
java.net.SocketException
-
setKeepAlive
public void setKeepAlive(boolean on) throws java.net.SocketException- Overrides:
setKeepAlivein classjava.net.Socket- Throws:
java.net.SocketException
-
getKeepAlive
public boolean getKeepAlive() throws java.net.SocketException- Overrides:
getKeepAlivein classjava.net.Socket- Throws:
java.net.SocketException
-
setTrafficClass
public void setTrafficClass(int tc) throws java.net.SocketException- Overrides:
setTrafficClassin classjava.net.Socket- Throws:
java.net.SocketException
-
getTrafficClass
public int getTrafficClass() throws java.net.SocketException- Overrides:
getTrafficClassin classjava.net.Socket- Throws:
java.net.SocketException
-
setReuseAddress
public void setReuseAddress(boolean on) throws java.net.SocketException- Overrides:
setReuseAddressin classjava.net.Socket- Throws:
java.net.SocketException
-
getReuseAddress
public boolean getReuseAddress() throws java.net.SocketException- Overrides:
getReuseAddressin classjava.net.Socket- Throws:
java.net.SocketException
-
shutdownInput
public void shutdownInput() throws java.io.IOException- Overrides:
shutdownInputin classjava.net.Socket- Throws:
java.io.IOException
-
shutdownOutput
public void shutdownOutput() throws java.io.IOException- Overrides:
shutdownOutputin classjava.net.Socket- Throws:
java.io.IOException
-
isConnected
public boolean isConnected()
- Overrides:
isConnectedin classjava.net.Socket
-
isBound
public boolean isBound()
- Overrides:
isBoundin classjava.net.Socket
-
isClosed
public boolean isClosed()
- Overrides:
isClosedin classjava.net.Socket
-
isInputShutdown
public boolean isInputShutdown()
- Overrides:
isInputShutdownin classjava.net.Socket
-
isOutputShutdown
public boolean isOutputShutdown()
- Overrides:
isOutputShutdownin classjava.net.Socket
-
setPerformancePreferences
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth)- Overrides:
setPerformancePreferencesin classjava.net.Socket
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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.SocketExceptionNote write timeouts are not part of the javax.net.ssl.SSLSocket API- Throws:
java.net.SocketException
-
getSoWriteTimeout
int getSoWriteTimeout() throws java.net.SocketExceptionNote write timeouts are not part of the javax.net.ssl.SSLSocket API- Throws:
java.net.SocketException
-
setHandshakeTimeout
void setHandshakeTimeout(int handshakeTimeoutMilliseconds) throws java.net.SocketExceptionSet 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:
getHandshakeSessionin 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.SSLExceptionGets the TLS Channel ID for this server socket. Channel ID is only available once the handshake completes.- Returns:
- channel ID or
nullif 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 thePrivateKeyto 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) ornullfor 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, ornullif 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:
getApplicationProtocolin classjavax.net.ssl.SSLSocket
-
getHandshakeApplicationProtocol
public abstract java.lang.String getHandshakeApplicationProtocol()
- Overrides:
getHandshakeApplicationProtocolin 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 returnnullif 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.SSLExceptionExports 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 benullto 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
nullif the handshake has not yet completed or the connection has been closed. - Throws:
javax.net.ssl.SSLException- if the value could not be exported.
-
-