Interface TsiHandshaker

All Known Implementing Classes:
AltsTsiHandshaker

public interface TsiHandshaker
This object protects and unprotects buffers once the handshake is done.

A typical usage of this object would be:


 ByteBuffer buffer = allocateDirect(ALLOCATE_SIZE);
 while (true) {
   while (true) {
     tsiHandshaker.getBytesToSendToPeer(buffer.clear());
     if (!buffer.hasRemaining()) break;
     yourTransportSendMethod(buffer.flip());
     assert(!buffer.hasRemaining());  // Guaranteed by yourTransportReceiveMethod(...)
   }
   if (!tsiHandshaker.isInProgress()) break;
   while (true) {
     assert(!buffer.hasRemaining());
     yourTransportReceiveMethod(buffer.clear());
     if (tsiHandshaker.processBytesFromPeer(buffer.flip())) break;
   }
   if (!tsiHandshaker.isInProgress()) break;
   assert(!buffer.hasRemaining());
 }
 yourCheckPeerMethod(tsiHandshaker.extractPeer());
 TsiFrameProtector tsiFrameProtector = tsiHandshaker.createFrameProtector(MAX_FRAME_SIZE);
 if (buffer.hasRemaining()) tsiFrameProtector.unprotect(buffer, messageBuffer);
 

Implementations of this object must be thread compatible.

  • Method Details

    • getBytesToSendToPeer

      void getBytesToSendToPeer(ByteBuffer bytes) throws GeneralSecurityException
      Gets bytes that need to be sent to the peer.
      Parameters:
      bytes - The buffer to put handshake bytes.
      Throws:
      GeneralSecurityException
    • processBytesFromPeer

      boolean processBytesFromPeer(ByteBuffer bytes) throws GeneralSecurityException
      Process the bytes received from the peer.
      Parameters:
      bytes - The buffer containing the handshake bytes from the peer.
      Returns:
      true, if the handshake has all the data it needs to process and false, if the method must be called again to complete processing.
      Throws:
      GeneralSecurityException
    • isInProgress

      boolean isInProgress()
      Returns true if and only if the handshake is still in progress.
      Returns:
      true, if the handshake is still in progress, false otherwise.
    • extractPeer

      TsiPeer extractPeer() throws GeneralSecurityException
      Returns the peer extracted from a completed handshake.
      Returns:
      the extracted peer.
      Throws:
      GeneralSecurityException
    • extractPeerObject

      Object extractPeerObject() throws GeneralSecurityException
      Returns the peer extracted from a completed handshake.
      Returns:
      the extracted peer.
      Throws:
      GeneralSecurityException
    • createFrameProtector

      TsiFrameProtector createFrameProtector(int maxFrameSize, io.netty.buffer.ByteBufAllocator alloc)
      Creates a frame protector from a completed handshake. No other methods may be called after the frame protector is created.
      Parameters:
      maxFrameSize - the requested max frame size, the callee is free to ignore.
      alloc - used for allocating ByteBufs.
      Returns:
      a new TsiFrameProtector.
    • createFrameProtector

      TsiFrameProtector createFrameProtector(io.netty.buffer.ByteBufAllocator alloc)
      Creates a frame protector from a completed handshake. No other methods may be called after the frame protector is created.
      Parameters:
      alloc - used for allocating ByteBufs.
      Returns:
      a new TsiFrameProtector.
    • close

      void close()
      Closes resources.