Class SshKeyExchangeClient

java.lang.Object
com.sshtools.client.SshKeyExchangeClient
All Implemented Interfaces:
com.sshtools.common.ssh.components.Component, com.sshtools.common.ssh.components.SshComponent, com.sshtools.common.ssh.SecureComponent, com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
Direct Known Subclasses:
Curve25519SHA256Client, DiffieHellmanEcdh, DiffieHellmanGroup, DiffieHellmanGroupExchange, Rsa1024Sha1, Rsa2048Sha256

public abstract class SshKeyExchangeClient extends Object implements com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
An abstract base class for all key exchange implementations.
  • Field Details

    • secret

      protected BigInteger secret
      The secret value produced during key exchange.
    • exchangeHash

      protected byte[] exchangeHash
      The exchange hash produced during key exchange.
    • hostKey

      protected byte[] hostKey
      The server's host key.
    • signature

      protected byte[] signature
      The signature generated over the exchange hash
    • clientId

      protected String clientId
    • serverId

      protected String serverId
    • clientKexInit

      protected byte[] clientKexInit
    • serverKexInit

      protected byte[] serverKexInit
    • key

      protected com.sshtools.common.ssh.components.SshPublicKey key
    • firstPacketFollows

      protected boolean firstPacketFollows
    • useFirstPacket

      protected boolean useFirstPacket
    • e

      protected BigInteger e
    • f

      protected BigInteger f
    • transport

      protected com.sshtools.synergy.ssh.SshTransport<SshClientContext> transport
      The transport protocol for sending/receiving messages
  • Constructor Details

    • SshKeyExchangeClient

      public SshKeyExchangeClient(String hashAlgorithm, com.sshtools.common.ssh.SecurityLevel securityLevel, int priority)
      Contruct an uninitialized key exchange
  • Method Details

    • getSecurityLevel

      public com.sshtools.common.ssh.SecurityLevel getSecurityLevel()
      Specified by:
      getSecurityLevel in interface com.sshtools.common.ssh.SecureComponent
    • getPriority

      public int getPriority()
      Specified by:
      getPriority in interface com.sshtools.common.ssh.SecureComponent
    • setReceivedNewKeys

      public void setReceivedNewKeys(boolean receivedNewKeys)
      Specified by:
      setReceivedNewKeys in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
    • setSentNewKeys

      public void setSentNewKeys(boolean sentNewKeys)
      Specified by:
      setSentNewKeys in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
    • hasSentNewKeys

      public boolean hasSentNewKeys()
      Specified by:
      hasSentNewKeys in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
    • hasReceivedNewKeys

      public boolean hasReceivedNewKeys()
      Specified by:
      hasReceivedNewKeys in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
    • getExchangeHash

      public byte[] getExchangeHash()
      Get the output of the key exchange
      Specified by:
      getExchangeHash in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
      Returns:
      the exchange hash output.
    • getHostKey

      public byte[] getHostKey()
      Get the host key supplied during key exchange.
      Specified by:
      getHostKey in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
      Returns:
      the server's host key
    • getSecret

      public BigInteger getSecret()
      Get the secret value produced during key exchange.
      Specified by:
      getSecret in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
      Returns:
      The secret value produced during key exchange
    • getSignature

      public byte[] getSignature()
      Get the signature produced during key exchange.
      Specified by:
      getSignature in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
      Returns:
      the signature produced from the exchange hash.
    • processMessage

      public abstract boolean processMessage(byte[] msg) throws com.sshtools.common.ssh.SshException, IOException
      Process a key exchange message
      Specified by:
      processMessage in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
      Parameters:
      msg -
      Returns:
      boolean, indicating whether it has processed the message or not
      Throws:
      IOException
      com.sshtools.common.ssh.SshException
    • reset

      public void reset()
      Reset the key exchange.
    • isComplete

      public boolean isComplete()
    • getHashAlgorithm

      public String getHashAlgorithm()
      Specified by:
      getHashAlgorithm in interface com.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
    • calculateExchangeHash

      protected void calculateExchangeHash() throws com.sshtools.common.ssh.SshException

      Calculates the exchange hash as an SHA1 hash of the following data.

        String         the client's version string (CR and NL excluded)
        String         the server's version string (CR and NL excluded)
        String         the payload of the client's SSH_MSG_KEXINIT
        String         the payload of the server's SSH_MSG_KEXINIT
        String         the host key
        BigInteger     e, exchange value sent by the client
        BigInteger     f, exchange value sent by the server
        BigInteger     K, the shared secret
       

      Throws:
      IOException
      com.sshtools.common.ssh.SshException