Package org.simpleframework.transport
Class SecureTransport
- java.lang.Object
-
- org.simpleframework.transport.SecureTransport
-
class SecureTransport extends java.lang.Object implements Transport
TheSecureTransportobject provides an implementation of a transport used to send and receive data over SSL. Data read from this transport is decrypted using anSSLEngine. 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
Fields Modifier and Type Field Description private CertificatecertificateThis is the certificate associated with this SSL connection.private booleanclosedThis is used to determine if the transport was closed.private javax.net.ssl.SSLEngineengineThis is the SSL engine used to encrypt and decrypt data.private booleanfinishedThis is used to determine if the end of stream was reached.private java.nio.ByteBufferinputThis is the internal buffer used to exchange the SSL data.private java.nio.ByteBufferoutputThis buffer is used to output the data for the SSL sent.private java.nio.ByteBufferswapThis is the internal buffer used to exchange the SSL data.private TracetraceThis is the trace that is used to monitor socket activity.private TransporttransportThis is the transport used to send data over the socket.
-
Constructor Summary
Constructors Constructor Description SecureTransport(Transport transport, Certificate certificate, java.nio.ByteBuffer input, java.nio.ByteBuffer swap)Constructor for theSecureTransportobject.SecureTransport(Transport transport, Certificate certificate, java.nio.ByteBuffer input, java.nio.ByteBuffer swap, int size)Constructor for theSecureTransportobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private intappend(java.nio.ByteBuffer buffer, int count)This will append bytes within the transport to the given buffer.voidclose()This is used to close the sender and the underlying transport.private intfill(java.nio.ByteBuffer buffer)This is used to fill the provided buffer with data that has been read from the secure socket channel.private intfill(java.nio.ByteBuffer buffer, int count)This is used to fill the provided buffer with data that has been read from the secure socket channel.voidflush()This method is used to flush the contents of the buffer to the client.java.util.MapgetAttributes()This method is used to get theMapof attributes by this pipeline.CertificategetCertificate()This is used to acquire the SSL certificate used when the server is using a HTTPS connection.java.nio.channels.SocketChannelgetChannel()This method is used to acquire theSocketChannelfor the connection.javax.net.ssl.SSLEnginegetEngine()This is used to acquire the SSL engine used for HTTPS.TracegetTrace()This is used to acquire the trace object that is associated with the socket.private intprocess(java.nio.ByteBuffer buffer)This is used to perform a non-blocking read on the transport.intread(java.nio.ByteBuffer buffer)This is used to perform a non-blocking read on the transport.private voidreceive()This is used to perform a non-blocking read on the transport.private voidsend(java.nio.ByteBuffer buffer)This method is used to deliver the provided buffer of bytes to the underlying transport.voidwrite(java.nio.ByteBuffer buffer)This method is used to deliver the provided buffer of bytes to the underlying transport.
-
-
-
Field Detail
-
certificate
private Certificate certificate
This is the certificate associated with this SSL connection.
-
transport
private Transport transport
This is the transport used to send data over the socket.
-
output
private java.nio.ByteBuffer output
This buffer is used to output the data for the SSL sent.
-
input
private java.nio.ByteBuffer input
This is the internal buffer used to exchange the SSL data.
-
swap
private java.nio.ByteBuffer swap
This is the internal buffer used to exchange the SSL data.
-
engine
private javax.net.ssl.SSLEngine engine
This is the SSL engine used to encrypt and decrypt data.
-
trace
private Trace trace
This is the trace that is used to monitor socket activity.
-
closed
private boolean closed
This is used to determine if the transport was closed.
-
finished
private boolean finished
This is used to determine if the end of stream was reached.
-
-
Constructor Detail
-
SecureTransport
public SecureTransport(Transport transport, Certificate certificate, java.nio.ByteBuffer input, java.nio.ByteBuffer swap)
Constructor for theSecureTransportobject. 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, java.nio.ByteBuffer input, java.nio.ByteBuffer swap, int size)
Constructor for theSecureTransportobject. 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 Detail
-
getCertificate
public Certificate 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:
getCertificatein interfaceTransport- Returns:
- this returns the associated SSL certificate if any
-
getTrace
public Trace 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
public javax.net.ssl.SSLEngine 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
public java.util.Map getAttributes()
This method is used to get theMapof 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:
getAttributesin interfaceSocket- Returns:
- this returns the map of attributes for this pipeline
-
getChannel
public java.nio.channels.SocketChannel getChannel()
This method is used to acquire theSocketChannelfor 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:
getChannelin interfaceSocket- Returns:
- this returns the socket used by this HTTP pipeline
-
read
public int read(java.nio.ByteBuffer buffer) throws java.io.IOExceptionThis 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.
-
process
private int process(java.nio.ByteBuffer buffer) throws java.io.IOExceptionThis 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:
java.io.IOException
-
fill
private int fill(java.nio.ByteBuffer buffer) throws java.io.IOExceptionThis 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:
java.io.IOException
-
fill
private int fill(java.nio.ByteBuffer buffer, int count) throws java.io.IOExceptionThis 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:
java.io.IOException
-
append
private int append(java.nio.ByteBuffer buffer, int count) throws java.io.IOExceptionThis 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:
java.io.IOException
-
receive
private void receive() throws java.io.IOExceptionThis 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:
java.io.IOException
-
write
public void write(java.nio.ByteBuffer buffer) throws java.io.IOExceptionThis 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.
-
send
private void send(java.nio.ByteBuffer buffer) throws java.io.IOExceptionThis 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:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionThis 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.
-
close
public void close() throws java.io.IOExceptionThis 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.
-
-