Class Handshake

java.lang.Object
org.simpleframework.transport.Handshake
All Implemented Interfaces:
Runnable, Negotiation, Operation

class Handshake extends Object implements Negotiation
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 Classes
    Modifier and Type
    Class
    Description
    private class 
    The Committer task is used to transfer the transport created to the processor.
    private class 
    The Consumer task is used to schedule the negotiation for a read operation.
    private class 
    The Producer is used to schedule the negotiation for a write operation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Constructor
    Description
    Handshake(TransportProcessor processor, Transport transport, Reactor reactor)
    Constructor for the Handshake object.
    Handshake(TransportProcessor processor, Transport transport, Reactor reactor, boolean client)
    Constructor for the Handshake object.
    Handshake(TransportProcessor processor, Transport transport, Reactor reactor, int size)
    Constructor for the Handshake object.
    Handshake(TransportProcessor processor, Transport transport, Reactor reactor, int size, boolean client)
    Constructor for the Handshake object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    This is used to start the negotation.
    void
    This is used to terminate the negotiation.
    void
    This method is invoked when the negotiation is done and the next phase of the connection is to take place.
    private void
    This is used to execute the completion task after a challenge for the clients X509 certificate.
    private void
    This method is invoked when the negotiation is done and the next phase of the connection is to take place.
    private PhaseType
    This is the main point of execution within the negotiation.
    private void
    This is used to execute the delegated tasks.
    This returns the socket channel for the connected pipeline.
    This is used to acquire the trace object that is associated with the operation.
    private Runnable
    This is the main point of execution within the negotiation.
    private PhaseType
    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
    This is used to receive data from the client.
    void
    This is the main point of execution within the negotiation.
    void
    run()
    This is used to start the negotiation.
    boolean
    Here we attempt to send all data within the output buffer.
    private void
    This method is used to terminate the handshake.
    private PhaseType
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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 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 ByteBuffer output
      This is the output buffer used to generate data to.
    • input

      private final ByteBuffer input
      This is the input buffer used to read data from the socket.
    • empty

      private final ByteBuffer empty
      This is an empty byte buffer used to generate a response.
    • engine

      private final 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 Details

    • Handshake

      public Handshake(TransportProcessor processor, Transport transport, Reactor reactor)
      Constructor for the Handshake 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 transport
      transport - the transport to perform the negotiation for
      reactor - this is the reactor used for I/O notifications
    • Handshake

      public Handshake(TransportProcessor processor, Transport transport, Reactor reactor, int size)
      Constructor for the Handshake 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 transport
      transport - the transport to perform the negotiation for
      reactor - this is the reactor used for I/O notifications
      size - the size of the buffers used for the negotiation
    • Handshake

      public Handshake(TransportProcessor processor, Transport transport, Reactor reactor, boolean client)
      Constructor for the Handshake 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 transport
      transport - the transport to perform the negotiation for
      reactor - this is the reactor used for I/O notifications
      client - determines the side of the SSL handshake
    • Handshake

      public Handshake(TransportProcessor processor, Transport transport, Reactor reactor, int size, boolean client)
      Constructor for the Handshake 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 transport
      transport - the transport to perform the negotiation for
      reactor - this is the reactor used for I/O notifications
      size - the size of the buffers used for the negotiation
      client - determines the side of the SSL handshake
  • Method Details

    • 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.
      Specified by:
      getTrace in interface Operation
      Returns:
      this returns the trace associated with this operation
    • getChannel

      public 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:
      getChannel in interface Operation
      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:
      run in interface 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.
      Specified by:
      cancel in interface Operation
    • 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 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 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 interface Negotiation
      Throws:
      IOException
    • process

      private Runnable process() throws 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 a task used to execute the next phase
      Throws:
      IOException
    • exchange

      private PhaseType exchange() throws 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:
      IOException
    • read

      private PhaseType read() throws 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:
      IOException
    • read

      private PhaseType read(int count) throws 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:
      IOException
    • write

      private PhaseType write() throws 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:
      IOException
    • write

      private PhaseType write(int count) throws 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:
      IOException
    • execute

      private void execute() throws IOException
      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

      public boolean receive() throws IOException
      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 interface Negotiation
      Returns:
      this returns true when the message has been read
      Throws:
      IOException
    • send

      public boolean send() throws IOException
      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 interface Negotiation
      Returns:
      this returns true if all of the content is delivered
      Throws:
      IOException
    • dispatch

      private void dispatch() throws IOException
      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

      private void terminate() throws IOException
      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

      private void complete() throws IOException
      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

      public void commit() throws IOException
      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 interface Negotiation
      Throws:
      IOException