Class AltsHandshakerClient


  • class AltsHandshakerClient
    extends java.lang.Object
    An API for conducting handshakes via ALTS handshaker service.
    • 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.
      • 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.