Package io.grpc.alts.internal
Class AltsTsiHandshaker
- java.lang.Object
-
- io.grpc.alts.internal.AltsTsiHandshaker
-
- All Implemented Interfaces:
TsiHandshaker
public final class AltsTsiHandshaker extends java.lang.Object implements TsiHandshaker
Negotiates a grpc channel key to be used by the TsiFrameProtector, using ALTs handshaker service.
-
-
Field Summary
Fields Modifier and Type Field Description private AltsHandshakerClient
handshaker
private boolean
isClient
private io.grpc.ChannelLogger
logger
private java.nio.ByteBuffer
outputFrame
static java.lang.String
TSI_SERVICE_ACCOUNT_PEER_PROPERTY
-
Constructor Summary
Constructors Modifier Constructor Description (package private)
AltsTsiHandshaker(boolean isClient, AltsHandshakerClient handshaker, io.grpc.ChannelLogger logger)
private
AltsTsiHandshaker(boolean isClient, HandshakerServiceGrpc.HandshakerServiceStub stub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
Starts a new TSI handshaker with client options.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes resources.TsiFrameProtector
createFrameProtector(int maxFrameSize, io.netty.buffer.ByteBufAllocator alloc)
Creates a frame protector from a completed handshake.TsiFrameProtector
createFrameProtector(io.netty.buffer.ByteBufAllocator alloc)
Creates a frame protector from a completed handshake.TsiPeer
extractPeer()
Returns the peer extracted from a completed handshake.java.lang.Object
extractPeerObject()
Returns the peer extracted from a completed handshake.void
getBytesToSendToPeer(java.nio.ByteBuffer bytes)
Gets bytes that need to be sent to the peer.boolean
isInProgress()
Returns true if and only if the handshake is still in progress.static TsiHandshaker
newClient(HandshakerServiceGrpc.HandshakerServiceStub stub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
Creates a new TsiHandshaker for use by the client.static TsiHandshaker
newServer(HandshakerServiceGrpc.HandshakerServiceStub stub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
Creates a new TsiHandshaker for use by the server.boolean
processBytesFromPeer(java.nio.ByteBuffer bytes)
Process the bytes received from the peer.
-
-
-
Field Detail
-
logger
private final io.grpc.ChannelLogger logger
-
TSI_SERVICE_ACCOUNT_PEER_PROPERTY
public static final java.lang.String TSI_SERVICE_ACCOUNT_PEER_PROPERTY
- See Also:
- Constant Field Values
-
isClient
private final boolean isClient
-
handshaker
private final AltsHandshakerClient handshaker
-
outputFrame
private java.nio.ByteBuffer outputFrame
-
-
Constructor Detail
-
AltsTsiHandshaker
private AltsTsiHandshaker(boolean isClient, HandshakerServiceGrpc.HandshakerServiceStub stub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
Starts a new TSI handshaker with client options.
-
AltsTsiHandshaker
AltsTsiHandshaker(boolean isClient, AltsHandshakerClient handshaker, io.grpc.ChannelLogger logger)
-
-
Method Detail
-
processBytesFromPeer
public boolean processBytesFromPeer(java.nio.ByteBuffer bytes) throws java.security.GeneralSecurityException
Process the bytes received from the peer.- Specified by:
processBytesFromPeer
in interfaceTsiHandshaker
- 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
-
extractPeer
public TsiPeer extractPeer() throws java.security.GeneralSecurityException
Returns the peer extracted from a completed handshake.- Specified by:
extractPeer
in interfaceTsiHandshaker
- Returns:
- the extracted peer.
- Throws:
java.security.GeneralSecurityException
-
extractPeerObject
public java.lang.Object extractPeerObject() throws java.security.GeneralSecurityException
Returns the peer extracted from a completed handshake.- Specified by:
extractPeerObject
in interfaceTsiHandshaker
- Returns:
- the extracted peer.
- Throws:
java.security.GeneralSecurityException
-
newClient
public static TsiHandshaker newClient(HandshakerServiceGrpc.HandshakerServiceStub stub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
Creates a new TsiHandshaker for use by the client.
-
newServer
public static TsiHandshaker newServer(HandshakerServiceGrpc.HandshakerServiceStub stub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
Creates a new TsiHandshaker for use by the server.
-
getBytesToSendToPeer
public void getBytesToSendToPeer(java.nio.ByteBuffer bytes) throws java.security.GeneralSecurityException
Gets bytes that need to be sent to the peer.- Specified by:
getBytesToSendToPeer
in interfaceTsiHandshaker
- Parameters:
bytes
- The buffer to put handshake bytes.- Throws:
java.security.GeneralSecurityException
-
isInProgress
public boolean isInProgress()
Returns true if and only if the handshake is still in progress.- Specified by:
isInProgress
in interfaceTsiHandshaker
- Returns:
- true, if the handshake is still in progress, false otherwise.
-
createFrameProtector
public 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.- Specified by:
createFrameProtector
in interfaceTsiHandshaker
- Parameters:
maxFrameSize
- the requested max frame size, the callee is free to ignore.alloc
- used for allocating ByteBufs.- Returns:
- a new TsiFrameProtector.
-
createFrameProtector
public 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.- Specified by:
createFrameProtector
in interfaceTsiHandshaker
- Parameters:
alloc
- used for allocating ByteBufs.- Returns:
- a new TsiFrameProtector.
-
close
public void close()
Description copied from interface:TsiHandshaker
Closes resources.- Specified by:
close
in interfaceTsiHandshaker
-
-