Package io.grpc.alts.internal
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 Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes resources.createFrameProtector
(int maxFrameSize, io.netty.buffer.ByteBufAllocator alloc) Creates a frame protector from a completed handshake.createFrameProtector
(io.netty.buffer.ByteBufAllocator alloc) Creates a frame protector from a completed handshake.Returns the peer extracted from a completed handshake.Returns the peer extracted from a completed handshake.void
getBytesToSendToPeer
(ByteBuffer bytes) Gets bytes that need to be sent to the peer.boolean
Returns true if and only if the handshake is still in progress.boolean
processBytesFromPeer
(ByteBuffer bytes) Process the bytes received from the peer.
-
Method Details
-
getBytesToSendToPeer
Gets bytes that need to be sent to the peer.- Parameters:
bytes
- The buffer to put handshake bytes.- Throws:
GeneralSecurityException
-
processBytesFromPeer
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
Returns the peer extracted from a completed handshake.- Returns:
- the extracted peer.
- Throws:
GeneralSecurityException
-
extractPeerObject
Returns the peer extracted from a completed handshake.- Returns:
- the extracted peer.
- Throws:
GeneralSecurityException
-
createFrameProtector
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
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.
-