Package org.conscrypt
Class OpenSSLSocketImplWrapper
- java.lang.Object
-
- java.net.Socket
-
- javax.net.ssl.SSLSocket
-
- org.conscrypt.OpenSSLSocketImpl
-
- org.conscrypt.OpenSSLSocketImplWrapper
-
- All Implemented Interfaces:
Closeable,AutoCloseable,NativeCrypto.SSLHandshakeCallbacks,SSLParametersImpl.AliasChooser,SSLParametersImpl.PSKCallbacks
public class OpenSSLSocketImplWrapper extends OpenSSLSocketImpl
This class wraps the SSL functionality over an existing connected socket.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedOpenSSLSocketImplWrapper(Socket socket, String hostname, int port, boolean autoClose, SSLParametersImpl sslParameters)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(SocketAddress sockaddr)Binds this socket to the given local host address and port specified by the SocketAddresslocalAddr.voidconnect(SocketAddress sockaddr)Connects this socket to the given remote host address and port specified by the SocketAddressremoteAddr.voidconnect(SocketAddress sockaddr, int timeout)Connects this socket to the given remote host address and port specified by the SocketAddressremoteAddrwith the specified timeout.InetAddressgetInetAddress()Returns the IP address of the target host this socket is connected to, or null if this socket is not yet connected.booleangetKeepAlive()Returns this socket'sSocketOptions.SO_KEEPALIVEsetting.InetAddressgetLocalAddress()Returns the local IP address this socket is bound to, or an address for whichInetAddress.isAnyLocalAddress()returns true if the socket is closed or unbound.intgetLocalPort()Returns the local port this socket is bound to, or -1 if the socket is unbound.SocketAddressgetLocalSocketAddress()Returns the local address and port of this socket as a SocketAddress or null if the socket has never been bound.booleangetOOBInline()Returns this socket'sSocketOptions.SO_OOBINLINEsetting.intgetPort()Returns the port number of the target host this socket is connected to, or 0 if this socket is not yet connected.intgetReceiveBufferSize()Returns this socket'sreceive buffer size.SocketAddressgetRemoteSocketAddress()Returns the remote address and port of this socket as aSocketAddressor null if the socket is not connected.booleangetReuseAddress()Returns this socket'sSocketOptions.SO_REUSEADDRsetting.intgetSendBufferSize()Returns this socket'ssend buffer size.intgetSoLinger()Returns this socket'slingertimeout in seconds, or -1 for no linger (i.e.intgetSoTimeout()Returns this socket'sreceive timeout.booleangetTcpNoDelay()Returns this socket'sSocketOptions#TCP_NODELAYsetting.intgetTrafficClass()Returns this socket's {@see SocketOptions#IP_TOS} setting.booleanisBound()Returns whether this socket is bound to a local address and port.booleanisClosed()Returns whether this socket is closed.booleanisConnected()Returns whether this socket is connected to a remote host.booleanisInputShutdown()Returns whether the incoming channel of the socket has already been closed.booleanisOutputShutdown()Returns whether the outgoing channel of the socket has already been closed.voidsetKeepAlive(boolean on)Sets this socket'sSocketOptions.SO_KEEPALIVEoption.voidsetReceiveBufferSize(int size)Sets this socket'sreceive buffer size.voidsetReuseAddress(boolean on)Sets this socket'sSocketOptions.SO_REUSEADDRoption.voidsetSendBufferSize(int size)Sets this socket'ssend buffer size.voidsetSoLinger(boolean on, int linger)Sets this socket'slingertimeout in seconds.voidsetSoTimeout(int to)Sets this socket'sread timeoutin milliseconds.voidsetTcpNoDelay(boolean on)Sets this socket'sSocketOptions.TCP_NODELAYoption.voidsetTrafficClass(int tos)Sets this socket'sSocketOptions.IP_TOSvalue for every packet sent by this socket.StringtoString()Returns aStringcontaining a concise, human-readable description of the socket.-
Methods inherited from class org.conscrypt.OpenSSLSocketImpl
addHandshakeCompletedListener, chooseClientAlias, chooseClientPSKIdentity, chooseServerAlias, chooseServerPSKIdentityHint, clientCertificateRequested, clientPSKKeyRequested, close, finalize, getAlpnSelectedProtocol, getChannelId, getEnabledCipherSuites, getEnabledProtocols, getEnableSessionCreation, getFileDescriptor$, getInputStream, getNeedClientAuth, getNpnSelectedProtocol, getOutputStream, getPSKKey, getSession, getSoWriteTimeout, getSupportedCipherSuites, getSupportedProtocols, getUseClientMode, getWantClientAuth, onSSLStateChange, removeHandshakeCompletedListener, sendUrgentData, serverPSKKeyRequested, setAlpnProtocols, setChannelIdEnabled, setChannelIdPrivateKey, setEnabledCipherSuites, setEnabledProtocols, setEnableSessionCreation, setHandshakeTimeout, setHostname, setNeedClientAuth, setNpnProtocols, setOOBInline, setSoWriteTimeout, setUseClientMode, setUseSessionTickets, setWantClientAuth, startHandshake, verifyCertificateChain
-
Methods inherited from class javax.net.ssl.SSLSocket
getSSLParameters, setSSLParameters, shutdownInput, shutdownOutput
-
Methods inherited from class java.net.Socket
getChannel, getReusePort, onBind, onClose, onConnect, setPerformancePreferences, setReusePort, setSocketImplFactory
-
-
-
-
Constructor Detail
-
OpenSSLSocketImplWrapper
protected OpenSSLSocketImplWrapper(Socket socket, String hostname, int port, boolean autoClose, SSLParametersImpl sslParameters) throws IOException
- Throws:
IOException
-
-
Method Detail
-
connect
public void connect(SocketAddress sockaddr, int timeout) throws IOException
Description copied from class:SocketConnects this socket to the given remote host address and port specified by the SocketAddressremoteAddrwith the specified timeout. The connecting method will block until the connection is established or an error occurred.- Overrides:
connectin classSocket- Parameters:
sockaddr- the address and port of the remote host to connect to.timeout- the timeout value in milliseconds or0for an infinite timeout.- Throws:
IOException- if the socket is already connected or an error occurs while connecting.
-
connect
public void connect(SocketAddress sockaddr) throws IOException
Description copied from class:SocketConnects this socket to the given remote host address and port specified by the SocketAddressremoteAddr.- Overrides:
connectin classSocket- Parameters:
sockaddr- the address and port of the remote host to connect to.- Throws:
IOException- if the socket is already connected or an error occurs while connecting.
-
bind
public void bind(SocketAddress sockaddr) throws IOException
Description copied from class:SocketBinds this socket to the given local host address and port specified by the SocketAddresslocalAddr. IflocalAddris set tonull, this socket will be bound to an available local address on any free port.- Overrides:
bindin classSocket- Parameters:
sockaddr- the specific address and port on the local machine to bind to.- Throws:
IOException- if the socket is already bound or an error occurs while binding.
-
getRemoteSocketAddress
public SocketAddress getRemoteSocketAddress()
Description copied from class:SocketReturns the remote address and port of this socket as aSocketAddressor null if the socket is not connected.- Overrides:
getRemoteSocketAddressin classSocket- Returns:
- the remote socket address and port.
-
getLocalSocketAddress
public SocketAddress getLocalSocketAddress()
Description copied from class:SocketReturns the local address and port of this socket as a SocketAddress or null if the socket has never been bound. If the socket is closed but has previously been bound then an address for whichInetAddress.isAnyLocalAddress()returns true will be returned with the previously-bound port. This is useful on multihomed hosts.- Overrides:
getLocalSocketAddressin classSocket
-
getLocalAddress
public InetAddress getLocalAddress()
Description copied from class:SocketReturns the local IP address this socket is bound to, or an address for whichInetAddress.isAnyLocalAddress()returns true if the socket is closed or unbound.- Overrides:
getLocalAddressin classSocket
-
getInetAddress
public InetAddress getInetAddress()
Description copied from class:SocketReturns the IP address of the target host this socket is connected to, or null if this socket is not yet connected.- Overrides:
getInetAddressin classSocket
-
toString
public String toString()
Description copied from class:SocketReturns aStringcontaining a concise, human-readable description of the socket.
-
setSoLinger
public void setSoLinger(boolean on, int linger) throws SocketExceptionDescription copied from class:Socket- Overrides:
setSoLingerin classSocket- Throws:
SocketException
-
setTcpNoDelay
public void setTcpNoDelay(boolean on) throws SocketExceptionDescription copied from class:SocketSets this socket'sSocketOptions.TCP_NODELAYoption.- Overrides:
setTcpNoDelayin classSocket- Throws:
SocketException
-
setReuseAddress
public void setReuseAddress(boolean on) throws SocketExceptionDescription copied from class:SocketSets this socket'sSocketOptions.SO_REUSEADDRoption.- Overrides:
setReuseAddressin classSocket- Throws:
SocketException
-
setKeepAlive
public void setKeepAlive(boolean on) throws SocketExceptionDescription copied from class:SocketSets this socket'sSocketOptions.SO_KEEPALIVEoption.- Overrides:
setKeepAlivein classSocket- Throws:
SocketException
-
setTrafficClass
public void setTrafficClass(int tos) throws SocketExceptionDescription copied from class:SocketSets this socket'sSocketOptions.IP_TOSvalue for every packet sent by this socket.- Overrides:
setTrafficClassin classSocket- Throws:
SocketException
-
setSoTimeout
public void setSoTimeout(int to) throws SocketExceptionDescription copied from class:SocketSets this socket'sread timeoutin milliseconds. Use 0 for no timeout. To take effect, this option must be set before the blocking method was called.- Overrides:
setSoTimeoutin classOpenSSLSocketImpl- Throws:
SocketException
-
setSendBufferSize
public void setSendBufferSize(int size) throws SocketExceptionDescription copied from class:SocketSets this socket'ssend buffer size.- Overrides:
setSendBufferSizein classSocket- Throws:
SocketException
-
setReceiveBufferSize
public void setReceiveBufferSize(int size) throws SocketExceptionDescription copied from class:SocketSets this socket'sreceive buffer size.- Overrides:
setReceiveBufferSizein classSocket- Throws:
SocketException
-
getTcpNoDelay
public boolean getTcpNoDelay() throws SocketExceptionDescription copied from class:SocketReturns this socket'sSocketOptions#TCP_NODELAYsetting.- Overrides:
getTcpNoDelayin classSocket- Throws:
SocketException
-
getReuseAddress
public boolean getReuseAddress() throws SocketExceptionDescription copied from class:SocketReturns this socket'sSocketOptions.SO_REUSEADDRsetting.- Overrides:
getReuseAddressin classSocket- Throws:
SocketException
-
getOOBInline
public boolean getOOBInline() throws SocketExceptionDescription copied from class:SocketReturns this socket'sSocketOptions.SO_OOBINLINEsetting.- Overrides:
getOOBInlinein classSocket- Throws:
SocketException
-
getKeepAlive
public boolean getKeepAlive() throws SocketExceptionDescription copied from class:SocketReturns this socket'sSocketOptions.SO_KEEPALIVEsetting.- Overrides:
getKeepAlivein classSocket- Throws:
SocketException
-
getTrafficClass
public int getTrafficClass() throws SocketExceptionDescription copied from class:SocketReturns this socket's {@see SocketOptions#IP_TOS} setting.- Overrides:
getTrafficClassin classSocket- Throws:
SocketException
-
getSoTimeout
public int getSoTimeout() throws SocketExceptionDescription copied from class:SocketReturns this socket'sreceive timeout.- Overrides:
getSoTimeoutin classOpenSSLSocketImpl- Throws:
SocketException
-
getSoLinger
public int getSoLinger() throws SocketExceptionDescription copied from class:SocketReturns this socket'slingertimeout in seconds, or -1 for no linger (i.e.closewill return immediately).- Overrides:
getSoLingerin classSocket- Throws:
SocketException
-
getSendBufferSize
public int getSendBufferSize() throws SocketExceptionDescription copied from class:SocketReturns this socket'ssend buffer size.- Overrides:
getSendBufferSizein classSocket- Throws:
SocketException
-
getReceiveBufferSize
public int getReceiveBufferSize() throws SocketExceptionDescription copied from class:SocketReturns this socket'sreceive buffer size.- Overrides:
getReceiveBufferSizein classSocket- Throws:
SocketException
-
isConnected
public boolean isConnected()
Description copied from class:SocketReturns whether this socket is connected to a remote host.- Overrides:
isConnectedin classSocket- Returns:
trueif the socket is connected,falseotherwise.
-
isClosed
public boolean isClosed()
Description copied from class:SocketReturns whether this socket is closed.
-
isBound
public boolean isBound()
Description copied from class:SocketReturns whether this socket is bound to a local address and port.
-
isOutputShutdown
public boolean isOutputShutdown()
Description copied from class:SocketReturns whether the outgoing channel of the socket has already been closed.- Overrides:
isOutputShutdownin classSocket- Returns:
trueif writing to this socket is not possible anymore,falseotherwise.
-
isInputShutdown
public boolean isInputShutdown()
Description copied from class:SocketReturns whether the incoming channel of the socket has already been closed.- Overrides:
isInputShutdownin classSocket- Returns:
trueif reading from this socket is not possible anymore,falseotherwise.
-
getPort
public int getPort()
Description copied from class:SocketReturns the port number of the target host this socket is connected to, or 0 if this socket is not yet connected.- Overrides:
getPortin classOpenSSLSocketImpl
-
getLocalPort
public int getLocalPort()
Description copied from class:SocketReturns the local port this socket is bound to, or -1 if the socket is unbound. If the socket has been closed this method will still return the local port the socket was bound to.- Overrides:
getLocalPortin classSocket
-
-