Package com.sshtools.client
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 Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected byte[]
protected BigInteger
protected byte[]
The exchange hash produced during key exchange.protected BigInteger
protected boolean
protected byte[]
The server's host key.protected com.sshtools.common.ssh.components.SshPublicKey
protected BigInteger
The secret value produced during key exchange.protected String
protected byte[]
protected byte[]
The signature generated over the exchange hashprotected com.sshtools.synergy.ssh.SshTransport<SshClientContext>
The transport protocol for sending/receiving messagesprotected boolean
-
Constructor Summary
ConstructorsConstructorDescriptionSshKeyExchangeClient
(String hashAlgorithm, com.sshtools.common.ssh.SecurityLevel securityLevel, int priority) Contruct an uninitialized key exchange -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Calculates the exchange hash as an SHA1 hash of the following data.byte[]
Get the output of the key exchangebyte[]
Get the host key supplied during key exchange.int
Get the secret value produced during key exchange.com.sshtools.common.ssh.SecurityLevel
byte[]
Get the signature produced during key exchange.boolean
boolean
boolean
abstract boolean
processMessage
(byte[] msg) Process a key exchange messagevoid
reset()
Reset the key exchange.void
setReceivedNewKeys
(boolean receivedNewKeys) void
setSentNewKeys
(boolean sentNewKeys) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.sshtools.synergy.ssh.components.SshKeyExchange
getAlgorithm, getProvider, init, test
-
Field Details
-
secret
The secret value produced during key exchange. -
exchangeHash
protected byte[] exchangeHashThe exchange hash produced during key exchange. -
hostKey
protected byte[] hostKeyThe server's host key. -
signature
protected byte[] signatureThe signature generated over the exchange hash -
clientId
-
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
-
f
-
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 interfacecom.sshtools.common.ssh.SecureComponent
-
getPriority
public int getPriority()- Specified by:
getPriority
in interfacecom.sshtools.common.ssh.SecureComponent
-
setReceivedNewKeys
public void setReceivedNewKeys(boolean receivedNewKeys) - Specified by:
setReceivedNewKeys
in interfacecom.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
-
setSentNewKeys
public void setSentNewKeys(boolean sentNewKeys) - Specified by:
setSentNewKeys
in interfacecom.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
-
hasSentNewKeys
public boolean hasSentNewKeys()- Specified by:
hasSentNewKeys
in interfacecom.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
-
hasReceivedNewKeys
public boolean hasReceivedNewKeys()- Specified by:
hasReceivedNewKeys
in interfacecom.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
-
getExchangeHash
public byte[] getExchangeHash()Get the output of the key exchange- Specified by:
getExchangeHash
in interfacecom.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 interfacecom.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
- Returns:
- the server's host key
-
getSecret
Get the secret value produced during key exchange.- Specified by:
getSecret
in interfacecom.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 interfacecom.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 interfacecom.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
- Specified by:
getHashAlgorithm
in interfacecom.sshtools.synergy.ssh.components.SshKeyExchange<SshClientContext>
-
calculateExchangeHash
protected void calculateExchangeHash() throws com.sshtools.common.ssh.SshExceptionCalculates 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
-