Package io.grpc.alts.internal
Class AltsHandshakerClient
- java.lang.Object
-
- io.grpc.alts.internal.AltsHandshakerClient
-
class AltsHandshakerClient extends java.lang.ObjectAn API for conducting handshakes via ALTS handshaker service.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringAPPLICATION_PROTOCOLprivate booleanclosedprivate AltsHandshakerOptionshandshakerOptionsprivate AltsHandshakerStubhandshakerStubprivate static intKEY_LENGTHprivate io.grpc.ChannelLoggerloggerprivate static java.lang.StringRECORD_PROTOCOLprivate HandshakerResultresultprivate HandshakerStatusstatus
-
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 voidclose()Closes the connection.(package private) static java.lang.StringgetApplicationProtocol()byte[]getKey()Returns the resulting key of the handshake, if the handshake is completed.(package private) static java.lang.StringgetRecordProtocol()HandshakerResultgetResult()Returns the result data of the handshake, if the handshake is completed.HandshakerStatusgetStatus()Returns the handshake status.private voidhandleResponse(HandshakerResp resp)Parses a handshake response, setting the status, result, and closing the handshaker, as needed.booleanisFinished()Returns true if the handshake is complete.java.nio.ByteBuffernext(java.nio.ByteBuffer inBytes)Processes the next bytes in a handshake.private voidsetStartClientFields(HandshakerReq.Builder req)Sets the start client fields for the passed handshake request.private voidsetStartServerFields(HandshakerReq.Builder req, java.nio.ByteBuffer inBytes)Sets the start server fields for the passed handshake request.java.nio.ByteBufferstartClientHandshake()Starts a client handshake.java.nio.ByteBufferstartServerHandshake(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.GeneralSecurityExceptionStarts 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.GeneralSecurityExceptionStarts 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.GeneralSecurityExceptionProcesses 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.
-
-