Package io.grpc.alts.internal
Class AltsHandshakerClient
- java.lang.Object
-
- io.grpc.alts.internal.AltsHandshakerClient
-
class AltsHandshakerClient extends java.lang.Object
An API for conducting handshakes via ALTS handshaker service.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
APPLICATION_PROTOCOL
private boolean
closed
private AltsHandshakerOptions
handshakerOptions
private AltsHandshakerStub
handshakerStub
private static int
KEY_LENGTH
private io.grpc.ChannelLogger
logger
private static java.lang.String
RECORD_PROTOCOL
private HandshakerResult
result
private HandshakerStatus
status
-
Constructor Summary
Constructors Constructor Description AltsHandshakerClient(AltsHandshakerStub handshakerStub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
AltsHandshakerClient(HandshakerServiceGrpc.HandshakerServiceStub stub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
Starts a new handshake interacting with the handshaker service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the connection.(package private) static java.lang.String
getApplicationProtocol()
byte[]
getKey()
Returns the resulting key of the handshake, if the handshake is completed.(package private) static java.lang.String
getRecordProtocol()
HandshakerResult
getResult()
Returns the result data of the handshake, if the handshake is completed.HandshakerStatus
getStatus()
Returns the handshake status.private void
handleResponse(HandshakerResp resp)
Parses a handshake response, setting the status, result, and closing the handshaker, as needed.boolean
isFinished()
Returns true if the handshake is complete.java.nio.ByteBuffer
next(java.nio.ByteBuffer inBytes)
Processes the next bytes in a handshake.private void
setStartClientFields(HandshakerReq.Builder req)
Sets the start client fields for the passed handshake request.private void
setStartServerFields(HandshakerReq.Builder req, java.nio.ByteBuffer inBytes)
Sets the start server fields for the passed handshake request.java.nio.ByteBuffer
startClientHandshake()
Starts a client handshake.java.nio.ByteBuffer
startServerHandshake(java.nio.ByteBuffer inBytes)
Starts a server handshake.
-
-
-
Field Detail
-
APPLICATION_PROTOCOL
private static final java.lang.String APPLICATION_PROTOCOL
- See Also:
- Constant Field Values
-
RECORD_PROTOCOL
private static final java.lang.String RECORD_PROTOCOL
- See Also:
- Constant Field Values
-
KEY_LENGTH
private static final int KEY_LENGTH
-
handshakerStub
private final AltsHandshakerStub handshakerStub
-
handshakerOptions
private final AltsHandshakerOptions handshakerOptions
-
result
private HandshakerResult result
-
status
private HandshakerStatus status
-
logger
private final io.grpc.ChannelLogger logger
-
closed
private boolean closed
-
-
Constructor Detail
-
AltsHandshakerClient
AltsHandshakerClient(HandshakerServiceGrpc.HandshakerServiceStub stub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
Starts a new handshake interacting with the handshaker service.
-
AltsHandshakerClient
AltsHandshakerClient(AltsHandshakerStub handshakerStub, AltsHandshakerOptions options, io.grpc.ChannelLogger logger)
-
-
Method Detail
-
getApplicationProtocol
static java.lang.String getApplicationProtocol()
-
getRecordProtocol
static java.lang.String getRecordProtocol()
-
setStartClientFields
private void setStartClientFields(HandshakerReq.Builder req)
Sets the start client fields for the passed handshake request.
-
setStartServerFields
private void setStartServerFields(HandshakerReq.Builder req, java.nio.ByteBuffer inBytes)
Sets the start server fields for the passed handshake request.
-
isFinished
public boolean isFinished()
Returns true if the handshake is complete.
-
getStatus
public HandshakerStatus getStatus()
Returns the handshake status.
-
getResult
public HandshakerResult getResult()
Returns the result data of the handshake, if the handshake is completed.
-
getKey
public byte[] getKey()
Returns the resulting key of the handshake, if the handshake is completed. Note that the key data returned from the handshake may be more than the key length required for the record protocol, thus we need to truncate to the right size.
-
handleResponse
private void handleResponse(HandshakerResp resp) throws java.security.GeneralSecurityException
Parses a handshake response, setting the status, result, and closing the handshaker, as needed.- Throws:
java.security.GeneralSecurityException
-
startClientHandshake
public java.nio.ByteBuffer startClientHandshake() throws java.security.GeneralSecurityException
Starts a client handshake. A GeneralSecurityException is thrown if the handshaker service is interrupted or fails. Note that isFinished() must be false before this function is called.- Returns:
- the frame to give to the peer.
- Throws:
java.security.GeneralSecurityException
- or IllegalStateException
-
startServerHandshake
public java.nio.ByteBuffer startServerHandshake(java.nio.ByteBuffer inBytes) throws java.security.GeneralSecurityException
Starts a server handshake. A GeneralSecurityException is thrown if the handshaker service is interrupted or fails. Note that isFinished() must be false before this function is called.- Parameters:
inBytes
- the bytes received from the peer.- Returns:
- the frame to give to the peer.
- Throws:
java.security.GeneralSecurityException
- or IllegalStateException
-
next
public java.nio.ByteBuffer next(java.nio.ByteBuffer inBytes) throws java.security.GeneralSecurityException
Processes the next bytes in a handshake. A GeneralSecurityException is thrown if the handshaker service is interrupted or fails. Note that isFinished() must be false before this function is called.- Parameters:
inBytes
- the bytes received from the peer.- Returns:
- the frame to give to the peer.
- Throws:
java.security.GeneralSecurityException
- or IllegalStateException
-
close
public void close()
Closes the connection.
-
-