Package org.simpleframework.transport
Class Handshake
- java.lang.Object
-
- org.simpleframework.transport.Handshake
-
- All Implemented Interfaces:
java.lang.Runnable,Negotiation,Operation
class Handshake extends java.lang.Object implements Negotiation
TheHandshakeobject is used to perform secure SSL negotiations on a pipeline orTransport. This can be used to perform an SSL handshake. To perform the negotiation this uses an SSL engine provided with the transport to direct the conversation. The SSL engine tells the negotiation what is expected next, whether this is a response to the client or a message from it. During the negotiation this may need to wait for either a write ready event or a read ready event. Event notification is done using the processor provided.- See Also:
TransportProcessor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classHandshake.CommitterTheCommittertask is used to transfer the transport created to the processor.private classHandshake.ConsumerTheConsumertask is used to schedule the negotiation for a read operation.private classHandshake.ProducerTheProduceris used to schedule the negotiation for a write operation.
-
Field Summary
Fields Modifier and Type Field Description private java.nio.channels.SocketChannelchannelThis is the socket channel used to read and write data to.private booleanclientThis determines if the handshake is from the client side.private java.nio.ByteBufferemptyThis is an empty byte buffer used to generate a response.private javax.net.ssl.SSLEngineengineThis is the SSL engine used to direct the conversation.private java.nio.ByteBufferinputThis is the input buffer used to read data from the socket.private java.nio.ByteBufferoutputThis is the output buffer used to generate data to.private TransportProcessorprocessorThis is the processor used to process the secure transport.private ReactorreactorThis is the reactor used to register for I/O notifications.private NegotiationStatestateThis is the certificate associated with this negotiation.private TracetraceThis is the trace that is used to monitor handshake events.private TransporttransportThis is the transport dispatched when the negotiation ends.
-
Constructor Summary
Constructors Constructor Description Handshake(TransportProcessor processor, Transport transport, Reactor reactor)Constructor for theHandshakeobject.Handshake(TransportProcessor processor, Transport transport, Reactor reactor, boolean client)Constructor for theHandshakeobject.Handshake(TransportProcessor processor, Transport transport, Reactor reactor, int size)Constructor for theHandshakeobject.Handshake(TransportProcessor processor, Transport transport, Reactor reactor, int size, boolean client)Constructor for theHandshakeobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbegin()This is used to start the negotation.voidcancel()This is used to terminate the negotiation.voidcommit()This method is invoked when the negotiation is done and the next phase of the connection is to take place.private voidcomplete()This is used to execute the completion task after a challenge for the clients X509 certificate.private voiddispatch()This method is invoked when the negotiation is done and the next phase of the connection is to take place.private PhaseTypeexchange()This is the main point of execution within the negotiation.private voidexecute()This is used to execute the delegated tasks.java.nio.channels.SelectableChannelgetChannel()This returns the socket channel for the connected pipeline.TracegetTrace()This is used to acquire the trace object that is associated with the operation.private java.lang.Runnableprocess()This is the main point of execution within the negotiation.private PhaseTyperead()This is used to perform the read part of the negotiation.private PhaseTyperead(int count)This is used to perform the read part of the negotiation.booleanreceive()This is used to receive data from the client.voidresume()This is the main point of execution within the negotiation.voidrun()This is used to start the negotiation.booleansend()Here we attempt to send all data within the output buffer.private voidterminate()This method is used to terminate the handshake.private PhaseTypewrite()This is used to perform the write part of the negotiation.private PhaseTypewrite(int count)This is used to perform the write part of the negotiation.
-
-
-
Field Detail
-
processor
private final TransportProcessor processor
This is the processor used to process the secure transport.
-
state
private final NegotiationState state
This is the certificate associated with this negotiation.
-
channel
private final java.nio.channels.SocketChannel channel
This is the socket channel used to read and write data to.
-
transport
private final Transport transport
This is the transport dispatched when the negotiation ends.
-
reactor
private final Reactor reactor
This is the reactor used to register for I/O notifications.
-
output
private final java.nio.ByteBuffer output
This is the output buffer used to generate data to.
-
input
private final java.nio.ByteBuffer input
This is the input buffer used to read data from the socket.
-
empty
private final java.nio.ByteBuffer empty
This is an empty byte buffer used to generate a response.
-
engine
private final javax.net.ssl.SSLEngine engine
This is the SSL engine used to direct the conversation.
-
trace
private final Trace trace
This is the trace that is used to monitor handshake events.
-
client
private final boolean client
This determines if the handshake is from the client side.
-
-
Constructor Detail
-
Handshake
public Handshake(TransportProcessor processor, Transport transport, Reactor reactor)
Constructor for theHandshakeobject. This is used to create an operation capable of performing negotiations for SSL connections. Typically this is used to perform request response negotiations, such as a handshake or termination.- Parameters:
processor- the processor used to dispatch the transporttransport- the transport to perform the negotiation forreactor- this is the reactor used for I/O notifications
-
Handshake
public Handshake(TransportProcessor processor, Transport transport, Reactor reactor, int size)
Constructor for theHandshakeobject. This is used to create an operation capable of performing negotiations for SSL connections. Typically this is used to perform request response negotiations, such as a handshake or termination.- Parameters:
transport- the transport to perform the negotiation forprocessor- the processor used to dispatch the transportreactor- this is the reactor used for I/O notificationssize- the size of the buffers used for the negotiation
-
Handshake
public Handshake(TransportProcessor processor, Transport transport, Reactor reactor, boolean client)
Constructor for theHandshakeobject. This is used to create an operation capable of performing negotiations for SSL connections. Typically this is used to perform request response negotiations, such as a handshake or termination.- Parameters:
transport- the transport to perform the negotiation forprocessor- the processor used to dispatch the transportreactor- this is the reactor used for I/O notificationsclient- determines the side of the SSL handshake
-
Handshake
public Handshake(TransportProcessor processor, Transport transport, Reactor reactor, int size, boolean client)
Constructor for theHandshakeobject. This is used to create an operation capable of performing negotiations for SSL connections. Typically this is used to perform request response negotiations, such as a handshake or termination.- Parameters:
transport- the transport to perform the negotiation forprocessor- the processor used to dispatch the transportreactor- this is the reactor used for I/O notificationssize- the size of the buffers used for the negotiationclient- determines the side of the SSL handshake
-
-
Method Detail
-
getTrace
public Trace getTrace()
This is used to acquire the trace object that is associated with the operation. A trace object is used to collection details on what operations are being performed. For instance it may contain information relating to I/O events or errors.
-
getChannel
public java.nio.channels.SelectableChannel getChannel()
This returns the socket channel for the connected pipeline. It is this channel that is used to determine if there are bytes that can be read. When closed this is no longer selectable.- Specified by:
getChannelin interfaceOperation- Returns:
- this returns the connected channel for the pipeline
-
run
public void run()
This is used to start the negotiation. Once started this will send a message to the other side, once sent the negotiation reads the response. However if the response is not yet ready this will schedule the negotiation for a selectable operation ensuring that it can resume execution when ready.- Specified by:
runin interfacejava.lang.Runnable
-
cancel
public void cancel()
This is used to terminate the negotiation. This is excecuted when the negotiation times out. When the negotiation expires it is rejected by the processor and must be canceled. Canceling is basically termination of the connection to free resources.
-
begin
private void begin()
This is used to start the negotation. Once started this will send a message to the other side, once sent the negotiation reads the response. However if the response is not yet ready this will schedule the negotiation for a selectable operation ensuring that it can resume execution when ready.
-
resume
public void resume() throws java.io.IOExceptionThis is the main point of execution within the negotiation. It is where the negotiation is performed. Negotiations are done by performing a request response flow, governed by the SSL engine associated with the pipeline. Typically the client is the one to initiate the handshake and the server initiates the termination sequence. This may be executed several times depending on whether reading or writing blocks.- Specified by:
resumein interfaceNegotiation- Throws:
java.io.IOException
-
process
private java.lang.Runnable process() throws java.io.IOExceptionThis is the main point of execution within the negotiation. It is where the negotiation is performed. Negotiations are done by performing a request response flow, governed by the SSL engine associated with the transport. Typically the client is the one to initiate the handshake and the server initiates the termination sequence. This may be executed several times depending on whether reading or writing blocks.- Returns:
- this returns a task used to execute the next phase
- Throws:
java.io.IOException
-
exchange
private PhaseType exchange() throws java.io.IOException
This is the main point of execution within the negotiation. It is where the negotiation is performed. Negotiations are done by performing a request response flow, governed by the SSL engine associated with the transport. Typically the client is the one to initiate the handshake and the server initiates the termination sequence. This may be executed several times depending on whether reading or writing blocks.- Returns:
- this returns what is expected next in the negotiation
- Throws:
java.io.IOException
-
read
private PhaseType read() throws java.io.IOException
This is used to perform the read part of the negotiation. The read part is where the other side sends information where it is consumed and is used to determine what action to take. Typically it is the SSL engine that determines what action is to be taken depending on the data send from the other side.- Returns:
- the next action that should be taken by the handshake
- Throws:
java.io.IOException
-
read
private PhaseType read(int count) throws java.io.IOException
This is used to perform the read part of the negotiation. The read part is where the other side sends information where it is consumed and is used to determine what action to take. Typically it is the SSL engine that determines what action is to be taken depending on the data send from the other side.- Parameters:
count- this is the number of times a read can repeat- Returns:
- the next action that should be taken by the handshake
- Throws:
java.io.IOException
-
write
private PhaseType write() throws java.io.IOException
This is used to perform the write part of the negotiation. The read part is where the this sends information to the other side and the other side interprets the data and determines what action to take. After a write the negotiation typically completes or waits for the next response from the other side.- Returns:
- the next action that should be taken by the handshake
- Throws:
java.io.IOException
-
write
private PhaseType write(int count) throws java.io.IOException
This is used to perform the write part of the negotiation. The read part is where the this sends information to the other side and the other side interprets the data and determines what action to take. After a write the negotiation typically completes or waits for the next response from the other side.- Parameters:
count- this is the number of times a read can repeat- Returns:
- the next action that should be taken by the handshake
- Throws:
java.io.IOException
-
execute
private void execute() throws java.io.IOExceptionThis is used to execute the delegated tasks. These tasks are used to digest the information received from the client in order to generate a response. This may need to execute several tasks from the associated SSL engine.- Throws:
java.io.IOException
-
receive
public boolean receive() throws java.io.IOExceptionThis is used to receive data from the client. If at any point during the negotiation a message is required that can not be read immediately this is used to asynchronously read the data when a select operation is signalled.- Specified by:
receivein interfaceNegotiation- Returns:
- this returns true when the message has been read
- Throws:
java.io.IOException
-
send
public boolean send() throws java.io.IOExceptionHere we attempt to send all data within the output buffer. If all of the data is delivered to the other side then this will return true. If however there is content yet to be sent to the other side then this returns false, telling the negotiation that in order to resume it must attempt to send the content again after a write ready operation on the underlying socket.- Specified by:
sendin interfaceNegotiation- Returns:
- this returns true if all of the content is delivered
- Throws:
java.io.IOException
-
dispatch
private void dispatch() throws java.io.IOExceptionThis method is invoked when the negotiation is done and the next phase of the connection is to take place. This will be invoked when the SSL handshake has completed and the new secure transport is to be handed to the processor.- Throws:
java.io.IOException
-
terminate
private void terminate() throws java.io.IOExceptionThis method is used to terminate the handshake. Termination typically occurs when there has been some error in the handshake or when there is a timeout on some event, such as waiting for for a read or write operation to occur. As a result the TCP channel is closed and any challenge future is cancelled.- Throws:
java.io.IOException
-
complete
private void complete() throws java.io.IOExceptionThis is used to execute the completion task after a challenge for the clients X509 certificate. Execution of the completion task in this way allows any challanger to be notified that the handshake has complete.- Throws:
java.io.IOException
-
commit
public void commit() throws java.io.IOExceptionThis method is invoked when the negotiation is done and the next phase of the connection is to take place. If a certificate challenge was issued then the completion task is executed, if this was the handshake for the initial connection a transport is created and handed to the processor.- Specified by:
commitin interfaceNegotiation- Throws:
java.io.IOException
-
-