Package net.targetr.wtm3.net
Class SuperSocket
java.lang.Object
net.targetr.wtm3.net.SuperSocket
- All Implemented Interfaces:
Closeable,AutoCloseable
Custom implementation of a socket supporting both plain and secure
connections on same port.
- Author:
- Dr Michael Gardiner
-
Constructor Summary
ConstructorsConstructorDescriptionSuperSocket(Socket socket) Creates a new SuperSocket from a regular socket.SuperSocket(Socket socket, boolean secure, String alias, InputStream rawIn, byte[] overread, int overreadLen) Creates a new SuperSocket and sets up TLS according to paramters. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the socket.Returns the address of the remote client.Get the InputStream of data received from the client.Get the OutputStream for sending data to the client.Returns the raw socket connected to the remote client.booleanisLocal()Returns true if the socket is connected to a local address.booleanisSecure()Query if this socket is secure.voidsetInputInterception(OutputStream interception) Directs all input communications to an output stream.voidsetOutputInterception(OutputStream interception) Directs all output communications to an output stream.voidsetSoTimeout(int timeout) Set the socket timeout.voidstartTls(String alias, ByteArrayInputStream consumed) Starts TLS on a socket that has already had data consumed.
-
Constructor Details
-
SuperSocket
Creates a new SuperSocket from a regular socket.For plain text only.
- Parameters:
socket- The Socket to upgrade to a SuperSocket.- Throws:
IOException- if an I/O error occurs
-
SuperSocket
public SuperSocket(Socket socket, boolean secure, String alias, InputStream rawIn, byte[] overread, int overreadLen) throws IOException Creates a new SuperSocket and sets up TLS according to paramters.For TLS or plain text.
- Parameters:
socket- The Socket to upgrade to a SuperSocket.secure- The connection will use TLS.alias- The alias to read from a keystore to find a certificate.rawIn- The raw, unwrapped InputStream that will have been sniffed previously.overread- A buffer containing initial bytes of the InputStream read during sniffing.overreadLen- The number of bytes in the buffer read during sniffing.- Throws:
IOException- if an I/O error occurs
-
-
Method Details
-
startTls
Starts TLS on a socket that has already had data consumed.- Parameters:
alias- The alias to a certificate in the keystore.consumed- An input stream providing the already consumed data or null.- Throws:
IOException- if an I/O error occurs
-
getInputStream
Get the InputStream of data received from the client.- Returns:
- stream of data from the client.
- Throws:
IOException- if an I/O error occurs
-
getOutputStream
Get the OutputStream for sending data to the client.- Returns:
- stream of data to send to client.
- Throws:
IOException- if an I/O error occurs
-
close
Closes the socket.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getSocket
Returns the raw socket connected to the remote client.- Returns:
- Socket or SSLSocket connected to remote client.
-
isSecure
public boolean isSecure()Query if this socket is secure.- Returns:
- true if socket is secure.
-
isLocal
public boolean isLocal()Returns true if the socket is connected to a local address.- Returns:
- true if the socket is connected to a local address.
-
getInetAddress
Returns the address of the remote client.- Returns:
- Address of the remote client.
-
setSoTimeout
Set the socket timeout.This is the number of miliseconds a read will block before a timeout exception.
- Parameters:
timeout- Milliseconds to block on an InputStream read operation.- Throws:
SocketException- if an error occurs in the underlying protocol
-
setInputInterception
Directs all input communications to an output stream.Used for debugging and storing wire communications.
- Parameters:
interception- Output stream to send bytes from request.- Throws:
IOException- if an I/O error occurs
-
setOutputInterception
Directs all output communications to an output stream.Used for debugging and storing wire communications.
- Parameters:
interception- Output stream to send bytes from response.- Throws:
IOException- if an I/O error occurs
-