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 Detail

      • getBytesToSendToPeer

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

        boolean processBytesFromPeer​(java.nio.ByteBuffer bytes)
                              throws java.security.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:
        java.security.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 java.security.GeneralSecurityException
        Returns the peer extracted from a completed handshake.
        Returns:
        the extracted peer.
        Throws:
        java.security.GeneralSecurityException
      • extractPeerObject

        java.lang.Object extractPeerObject()
                                    throws java.security.GeneralSecurityException
        Returns the peer extracted from a completed handshake.
        Returns:
        the extracted peer.
        Throws:
        java.security.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.