Package org.simpleframework.transport
Class SecureTransport
java.lang.Object
org.simpleframework.transport.SecureTransport
The
SecureTransport
object provides an implementation
of a transport used to send and receive data over SSL. Data read
from this transport is decrypted using an SSLEngine
.
Also, all data is written is encrypted with the same engine. This
ensures that data can be send and received in a transparent way.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Certificate
This is the certificate associated with this SSL connection.private boolean
This is used to determine if the transport was closed.private SSLEngine
This is the SSL engine used to encrypt and decrypt data.private boolean
This is used to determine if the end of stream was reached.private ByteBuffer
This is the internal buffer used to exchange the SSL data.private ByteBuffer
This buffer is used to output the data for the SSL sent.private ByteBuffer
This is the internal buffer used to exchange the SSL data.private Trace
This is the trace that is used to monitor socket activity.private Transport
This is the transport used to send data over the socket. -
Constructor Summary
ConstructorsConstructorDescriptionSecureTransport
(Transport transport, Certificate certificate, ByteBuffer input, ByteBuffer swap) Constructor for theSecureTransport
object.SecureTransport
(Transport transport, Certificate certificate, ByteBuffer input, ByteBuffer swap, int size) Constructor for theSecureTransport
object. -
Method Summary
Modifier and TypeMethodDescriptionprivate int
append
(ByteBuffer buffer, int count) This will append bytes within the transport to the given buffer.void
close()
This is used to close the sender and the underlying transport.private int
fill
(ByteBuffer buffer) This is used to fill the provided buffer with data that has been read from the secure socket channel.private int
fill
(ByteBuffer buffer, int count) This is used to fill the provided buffer with data that has been read from the secure socket channel.void
flush()
This method is used to flush the contents of the buffer to the client.This method is used to get theMap
of attributes by this pipeline.This is used to acquire the SSL certificate used when the server is using a HTTPS connection.This method is used to acquire theSocketChannel
for the connection.This is used to acquire the SSL engine used for HTTPS.getTrace()
This is used to acquire the trace object that is associated with the socket.private int
process
(ByteBuffer buffer) This is used to perform a non-blocking read on the transport.int
read
(ByteBuffer buffer) This is used to perform a non-blocking read on the transport.private void
receive()
This is used to perform a non-blocking read on the transport.private void
send
(ByteBuffer buffer) This method is used to deliver the provided buffer of bytes to the underlying transport.void
write
(ByteBuffer buffer) This method is used to deliver the provided buffer of bytes to the underlying transport.
-
Field Details
-
certificate
This is the certificate associated with this SSL connection. -
transport
This is the transport used to send data over the socket. -
output
This buffer is used to output the data for the SSL sent. -
input
This is the internal buffer used to exchange the SSL data. -
swap
This is the internal buffer used to exchange the SSL data. -
engine
This is the SSL engine used to encrypt and decrypt data. -
trace
This is the trace that is used to monitor socket activity. -
closed
private boolean closedThis is used to determine if the transport was closed. -
finished
private boolean finishedThis is used to determine if the end of stream was reached.
-
-
Constructor Details
-
SecureTransport
public SecureTransport(Transport transport, Certificate certificate, ByteBuffer input, ByteBuffer swap) Constructor for theSecureTransport
object. This is used to create a transport for sending and receiving data over SSL. This must be created with a pipeline that has already performed the SSL handshake and is read to used.- Parameters:
transport
- this is the transport to delegate operations tocertificate
- this is the certificate for the connectioninput
- this is the input buffer used to read the dataswap
- this is the swap buffer to be used for reading
-
SecureTransport
public SecureTransport(Transport transport, Certificate certificate, ByteBuffer input, ByteBuffer swap, int size) Constructor for theSecureTransport
object. This is used to create a transport for sending and receiving data over SSL. This must be created with a pipeline that has already performed the SSL handshake and is read to used.- Parameters:
transport
- this is the transport to delegate operations tocertificate
- this is the certificate for the connectioninput
- this is the input buffer used to read the dataswap
- this is the swap buffer to be used for readingsize
- this is the size of the buffers to be allocated
-
-
Method Details
-
getCertificate
This is used to acquire the SSL certificate used when the server is using a HTTPS connection. For plain text connections or connections that use a security mechanism other than SSL this will be null. This is only available when the connection makes specific use of an SSL engine to secure the connection.- Specified by:
getCertificate
in interfaceTransport
- Returns:
- this returns the associated SSL certificate if any
-
getTrace
This is used to acquire the trace object that is associated with the socket. A trace object is used to collection details on what operations are being performed on the socket. For instance it may contain information relating to I/O events or more application specific events such as errors. -
getEngine
This is used to acquire the SSL engine used for HTTPS. If the pipeline is connected to an SSL transport this returns an SSL engine which can be used to establish the secure connection and send and receive content over that connection. If this is null then the pipeline represents a normal transport. -
getAttributes
This method is used to get theMap
of attributes by this pipeline. The attributes map is used to maintain details about the connection. Information such as security credentials to client details can be placed within the attribute map.- Specified by:
getAttributes
in interfaceSocket
- Returns:
- this returns the map of attributes for this pipeline
-
getChannel
This method is used to acquire theSocketChannel
for the connection. This allows the server to acquire the input and output streams with which to communicate. It can also be used to configure the connection and perform various network operations that could otherwise not be performed.- Specified by:
getChannel
in interfaceSocket
- Returns:
- this returns the socket used by this HTTP pipeline
-
read
This is used to perform a non-blocking read on the transport. If there are no bytes available on the input buffers then this method will return zero and the buffer will remain the same. If there is data and the buffer can be filled then this will return the number of bytes read. Finally if the socket is closed this will return a -1 value.- Specified by:
read
in interfaceTransport
- Parameters:
buffer
- this is the buffer to append the bytes to- Returns:
- this returns the number of bytes that have been read
- Throws:
IOException
-
process
This is used to perform a non-blocking read on the transport. If there are no bytes available on the input buffers then this method will return zero and the buffer will remain the same. If there is data and the buffer can be filled then this will return the number of bytes read.- Parameters:
buffer
- this is the buffer to append the bytes to- Returns:
- this returns the number of bytes that have been read
- Throws:
IOException
-
fill
This is used to fill the provided buffer with data that has been read from the secure socket channel. This enables reading of the decrypted data in chunks that are smaller than the size of the input buffer used to contain the plain text data.- Parameters:
buffer
- this is the buffer to append the bytes to- Returns:
- this returns the number of bytes that have been read
- Throws:
IOException
-
fill
This is used to fill the provided buffer with data that has been read from the secure socket channel. This enables reading of the decrypted data in chunks that are smaller than the size of the input buffer used to contain the plain text data.- Parameters:
buffer
- this is the buffer to append the bytes tocount
- this is the number of bytes that are to be read- Returns:
- this returns the number of bytes that have been read
- Throws:
IOException
-
append
This will append bytes within the transport to the given buffer. Once invoked the buffer will contain the transport bytes, which will have been drained from the buffer. This effectively moves the bytes in the buffer to the end of the packet instance.- Parameters:
buffer
- this is the buffer containing the bytescount
- this is the number of bytes that should be used- Returns:
- returns the number of bytes that have been moved
- Throws:
IOException
-
receive
This is used to perform a non-blocking read on the transport. If there are no bytes available on the input buffers then this method will return zero and the buffer will remain the same. If there is data and the buffer can be filled then this will return the number of bytes read. Finally if the socket is closed this will return a -1 value.- Throws:
IOException
-
write
This method is used to deliver the provided buffer of bytes to the underlying transport. Depending on the connection type the array may be encoded for SSL transport or send directly. Any implementation may choose to buffer the bytes for performance.- Specified by:
write
in interfaceTransport
- Parameters:
buffer
- this is the array of bytes to send to the client- Throws:
IOException
-
send
This method is used to deliver the provided buffer of bytes to the underlying transport. Depending on the connection type the array may be encoded for SSL transport or send directly. Any implementation may choose to buffer the bytes for performance.- Parameters:
buffer
- this is the array of bytes to send to the client- Throws:
IOException
-
flush
This method is used to flush the contents of the buffer to the client. This method will block until such time as all of the data has been sent to the client. If at any point there is an error sending the content an exception is thrown.- Specified by:
flush
in interfaceTransport
- Throws:
IOException
-
close
This is used to close the sender and the underlying transport. If a close is performed on the sender then no more bytes can be read from or written to the transport and the client will received a connection close on their side.- Specified by:
close
in interfaceTransport
- Throws:
IOException
-