Package org.simpleframework.transport
Class Handshake
java.lang.Object
org.simpleframework.transport.Handshake
- All Implemented Interfaces:
Runnable
,Negotiation
,Operation
The
Handshake
object is used to perform secure SSL
negotiations on a pipeline or Transport
. 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
TheCommitter
task is used to transfer the transport created to the processor.private class
TheConsumer
task is used to schedule the negotiation for a read operation.private class
TheProducer
is used to schedule the negotiation for a write operation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SocketChannel
This is the socket channel used to read and write data to.private final boolean
This determines if the handshake is from the client side.private final ByteBuffer
This is an empty byte buffer used to generate a response.private final SSLEngine
This is the SSL engine used to direct the conversation.private final ByteBuffer
This is the input buffer used to read data from the socket.private final ByteBuffer
This is the output buffer used to generate data to.private final TransportProcessor
This is the processor used to process the secure transport.private final Reactor
This is the reactor used to register for I/O notifications.private final NegotiationState
This is the certificate associated with this negotiation.private final Trace
This is the trace that is used to monitor handshake events.private final Transport
This is the transport dispatched when the negotiation ends. -
Constructor Summary
ConstructorsConstructorDescriptionHandshake
(TransportProcessor processor, Transport transport, Reactor reactor) Constructor for theHandshake
object.Handshake
(TransportProcessor processor, Transport transport, Reactor reactor, boolean client) Constructor for theHandshake
object.Handshake
(TransportProcessor processor, Transport transport, Reactor reactor, int size) Constructor for theHandshake
object.Handshake
(TransportProcessor processor, Transport transport, Reactor reactor, int size, boolean client) Constructor for theHandshake
object. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
begin()
This is used to start the negotation.void
cancel()
This is used to terminate the negotiation.void
commit()
This method is invoked when the negotiation is done and the next phase of the connection is to take place.private void
complete()
This is used to execute the completion task after a challenge for the clients X509 certificate.private void
dispatch()
This method is invoked when the negotiation is done and the next phase of the connection is to take place.private PhaseType
exchange()
This is the main point of execution within the negotiation.private void
execute()
This is used to execute the delegated tasks.This returns the socket channel for the connected pipeline.getTrace()
This is used to acquire the trace object that is associated with the operation.private Runnable
process()
This is the main point of execution within the negotiation.private PhaseType
read()
This is used to perform the read part of the negotiation.private PhaseType
read
(int count) This is used to perform the read part of the negotiation.boolean
receive()
This is used to receive data from the client.void
resume()
This is the main point of execution within the negotiation.void
run()
This is used to start the negotiation.boolean
send()
Here we attempt to send all data within the output buffer.private void
This method is used to terminate the handshake.private PhaseType
write()
This is used to perform the write part of the negotiation.private PhaseType
write
(int count) This is used to perform the write part of the negotiation.
-
Field Details
-
processor
This is the processor used to process the secure transport. -
state
This is the certificate associated with this negotiation. -
channel
This is the socket channel used to read and write data to. -
transport
This is the transport dispatched when the negotiation ends. -
reactor
This is the reactor used to register for I/O notifications. -
output
This is the output buffer used to generate data to. -
input
This is the input buffer used to read data from the socket. -
empty
This is an empty byte buffer used to generate a response. -
engine
This is the SSL engine used to direct the conversation. -
trace
This is the trace that is used to monitor handshake events. -
client
private final boolean clientThis determines if the handshake is from the client side.
-
-
Constructor Details
-
Handshake
Constructor for theHandshake
object. 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
Constructor for theHandshake
object. 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 notificationssize
- the size of the buffers used for the negotiation
-
Handshake
public Handshake(TransportProcessor processor, Transport transport, Reactor reactor, boolean client) Constructor for theHandshake
object. 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 notificationsclient
- determines the side of the SSL handshake
-
Handshake
public Handshake(TransportProcessor processor, Transport transport, Reactor reactor, int size, boolean client) Constructor for theHandshake
object. 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 notificationssize
- the size of the buffers used for the negotiationclient
- determines the side of the SSL handshake
-
-
Method Details
-
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
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:
getChannel
in 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. -
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
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 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:
resume
in interfaceNegotiation
- Throws:
IOException
-
process
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 a task used to execute the next phase
- Throws:
IOException
-
exchange
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:
IOException
-
read
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:
IOException
-
read
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:
IOException
-
write
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:
IOException
-
write
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:
IOException
-
execute
This 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:
IOException
-
receive
This 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:
receive
in interfaceNegotiation
- Returns:
- this returns true when the message has been read
- Throws:
IOException
-
send
Here 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:
send
in interfaceNegotiation
- Returns:
- this returns true if all of the content is delivered
- Throws:
IOException
-
dispatch
This 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:
IOException
-
terminate
This 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:
IOException
-
complete
This 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:
IOException
-
commit
This 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:
commit
in interfaceNegotiation
- Throws:
IOException
-