Package com.sshtools.agent.client
Class SshAgentClient
java.lang.Object
com.sshtools.agent.client.SshAgentClient
- All Implemented Interfaces:
com.sshtools.common.publickey.SignatureGenerator
,Closeable
,AutoCloseable
public class SshAgentClient
extends Object
implements com.sshtools.common.publickey.SignatureGenerator, Closeable
Maintain the public keys for SshConnection
- Author:
- Aruna Abesekara
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSshAgentClient
(boolean isForwarded, String application, Closeable socket, InputStream in, OutputStream out, boolean isRFC) SshAgentClient
(boolean isForwarded, String application, Socket socket) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addKey
(com.sshtools.common.ssh.components.SshPrivateKey prvkey, com.sshtools.common.ssh.components.SshPublicKey pubkey, String description, KeyConstraints constraints) Add a key to the agentvoid
close()
Close the agentstatic SshAgentClient
connectLocalAgent
(String application, String location, AgentSocketType type, boolean RFCAgent) Connect to the local agent.static SshAgentClient
connectOpenSSHAgent
(String application) static SshAgentClient
connectOpenSSHAgent
(String application, String location) Determines operating system type (windows or not) and connects using the appropriate socket type for the platform.void
Delete all the keys held by the agent.void
Delete a key held by the agentstatic String
Collection<com.sshtools.common.ssh.components.SshPublicKey>
byte[]
getRandomData
(int count) Request some random data from the remote sidebyte[]
hashAndSign
(com.sshtools.common.ssh.components.SshPublicKey key, String signingAlgorithm, byte[] data) Request a hash and sign operation be performed for a given public key.boolean
listKeys()
List all the keys on the agent.boolean
Lock the agentvoid
ping
(byte[] padding) Ping the remote side with some random padding dataprotected AgentMessage
Read a single message from the inputstream and convert into a valid subsystem messageprotected void
protected void
Send a forwarding notice.protected void
sendMessage
(AgentMessage msg) Send a subsystem messageprotected void
sendVersionRequest
(String application) Request the agent version.byte[]
boolean
unlockAgent
(String password) Unlock the agent
-
Field Details
-
HASH_AND_SIGN
- See Also:
-
WINDOWS_SSH_AGENT_SERVICE
-
-
Constructor Details
-
SshAgentClient
- Throws:
IOException
-
SshAgentClient
public SshAgentClient(boolean isForwarded, String application, Closeable socket, InputStream in, OutputStream out, boolean isRFC) throws IOException - Throws:
IOException
-
-
Method Details
-
isRFCAgent
public boolean isRFCAgent() -
connectOpenSSHAgent
public static SshAgentClient connectOpenSSHAgent(String application) throws AgentNotAvailableException, IOException -
connectOpenSSHAgent
public static SshAgentClient connectOpenSSHAgent(String application, String location) throws AgentNotAvailableException, IOException Determines operating system type (windows or not) and connects using the appropriate socket type for the platform.- Parameters:
application
-location
-- Returns:
- Throws:
AgentNotAvailableException
IOException
-
connectLocalAgent
public static SshAgentClient connectLocalAgent(String application, String location, AgentSocketType type, boolean RFCAgent) throws AgentNotAvailableException, IOException Connect to the local agent.- Parameters:
application
- the application connectinglocation
- the location of the agent, in the form "localhost:port"- Returns:
- a connected agent client
- Throws:
AgentNotAvailableException
- if the agent is not available at the location specifiedIOException
- if an IO error occurs
-
close
public void close()Close the agent- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
ping
Ping the remote side with some random padding data- Parameters:
padding
- the padding data- Throws:
IOException
- if an IO error occurs
-
registerMessages
protected void registerMessages() -
sendForwardingNotice
Send a forwarding notice.- Throws:
IOException
- if an IO error occurs
-
sendMessage
Send a subsystem message- Parameters:
msg
- the message to send- Throws:
IOException
- if an IO error occurs
-
sendVersionRequest
Request the agent version.- Parameters:
application
- the application connecting- Throws:
IOException
- if an IO error occurs
-
deleteAllKeys
Delete all the keys held by the agent.- Throws:
IOException
- if an IO error occurs
-
readMessage
Read a single message from the inputstream and convert into a valid subsystem message- Returns:
- the next available subsystem message
- Throws:
InvalidMessageException
- if the message received is invalid
-
addKey
public void addKey(com.sshtools.common.ssh.components.SshPrivateKey prvkey, com.sshtools.common.ssh.components.SshPublicKey pubkey, String description, KeyConstraints constraints) throws IOException Add a key to the agent- Parameters:
prvkey
- the private key to addpubkey
- the private keys public keydescription
- a description of the keyconstraints
- a set of contraints for key use- Throws:
IOException
- if an IO error occurs
-
listKeys
List all the keys on the agent.- Returns:
- a map of public keys and descriptions
- Throws:
IOException
- if an IO error occurs
-
lockAgent
Lock the agent- Parameters:
password
- password that will be required to unlock- Returns:
- true if the agent was locked, otherwise false
- Throws:
IOException
- if an IO error occurs
-
unlockAgent
Unlock the agent- Parameters:
password
- the password to unlock- Returns:
- true if the agent was unlocked, otherwise false
- Throws:
IOException
- if an IO error occurs
-
getRandomData
Request some random data from the remote side- Parameters:
count
- the number of bytes needed- Returns:
- the random data received
- Throws:
IOException
- if an IO error occurs
-
deleteKey
public void deleteKey(com.sshtools.common.ssh.components.SshPublicKey key, String description) throws IOException Delete a key held by the agent- Parameters:
key
- the public key of the private key to deletedescription
- the description of the key- Throws:
IOException
- if an IO error occurs
-
hashAndSign
public byte[] hashAndSign(com.sshtools.common.ssh.components.SshPublicKey key, String signingAlgorithm, byte[] data) throws IOException Request a hash and sign operation be performed for a given public key.- Parameters:
key
- the public key of the required private keydata
- the data to has and sign- Returns:
- the hashed and signed data
- Throws:
IOException
- if an IO error occurs
-
sign
public byte[] sign(com.sshtools.common.ssh.components.SshPublicKey key, String signingAlgorithm, byte[] data) throws com.sshtools.common.ssh.SshException - Specified by:
sign
in interfacecom.sshtools.common.publickey.SignatureGenerator
- Throws:
com.sshtools.common.ssh.SshException
-
getPublicKeys
public Collection<com.sshtools.common.ssh.components.SshPublicKey> getPublicKeys() throws IOException- Specified by:
getPublicKeys
in interfacecom.sshtools.common.publickey.SignatureGenerator
- Throws:
IOException
-
getEnvironmentSocket
- Throws:
AgentNotAvailableException
-