Package com.sshtools.j2ssh.agent
Class SshAgentClient
- java.lang.Object
-
- com.sshtools.j2ssh.agent.SshAgentClient
-
public class SshAgentClient extends java.lang.ObjectProvides a client connection to the ssh agent.- Version:
- $Revision: 1.17 $
- Author:
- $author$
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHASH_AND_SIGNThe hash and sign private key operation
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddKey(SshPrivateKey prvkey, SshPublicKey pubkey, java.lang.String description, KeyConstraints constraints)Add a key to the agentvoidclose()Close the agentstatic java.net.SocketconnectAgentSocket(java.lang.String location)Connect a socket to the agent at the location specified.static SshAgentClientconnectLocalAgent(java.lang.String application, java.lang.String location)Connect to the local agent.voiddeleteAllKeys()Delete all the keys held by the agent.voiddeleteKey(SshPublicKey key, java.lang.String description)Delete a key held by the agentbyte[]getRandomData(int count)Request some random data from the remote sidebyte[]hashAndSign(SshPublicKey key, byte[] data)Request a hash and sign operation be performed for a given public key.java.util.MaplistKeys()List all the keys on the agent.booleanlockAgent(java.lang.String password)Lock the agentvoidping(byte[] padding)Ping the remote side with some random padding dataprotected SubsystemMessagereadMessage()Read a single message from the inputstream and convert into a valid subsystem messageprotected voidregisterMessages()Register the subsystem messagesprotected voidsendForwardingNotice()Send a forwarding notice.protected voidsendMessage(SubsystemMessage msg)Send a subsystem messageprotected voidsendVersionRequest(java.lang.String application)Request the agent version.booleanunlockAgent(java.lang.String password)Unlock the agent
-
-
-
Field Detail
-
HASH_AND_SIGN
public static final java.lang.String HASH_AND_SIGN
The hash and sign private key operation- See Also:
- Constant Field Values
-
-
Method Detail
-
connectLocalAgent
public static SshAgentClient connectLocalAgent(java.lang.String application, java.lang.String location) throws AgentNotAvailableException, java.io.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 specifiedjava.io.IOException- if an IO error occurs
-
connectAgentSocket
public static java.net.Socket connectAgentSocket(java.lang.String location) throws AgentNotAvailableException, java.io.IOExceptionConnect a socket to the agent at the location specified.- Parameters:
location- the location of the agent, in the form "localhost:port"- Returns:
- the connected socket
- Throws:
AgentNotAvailableException- if an agent is not available at the location specifiedjava.io.IOException- if an IO error occurs
-
close
public void close()
Close the agent
-
registerMessages
protected void registerMessages()
Register the subsystem messages
-
sendVersionRequest
protected void sendVersionRequest(java.lang.String application) throws java.io.IOExceptionRequest the agent version.- Parameters:
application- the application connecting- Throws:
java.io.IOException- if an IO error occurs
-
addKey
public void addKey(SshPrivateKey prvkey, SshPublicKey pubkey, java.lang.String description, KeyConstraints constraints) throws java.io.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:
java.io.IOException- if an IO error occurs
-
hashAndSign
public byte[] hashAndSign(SshPublicKey key, byte[] data) throws java.io.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:
java.io.IOException- if an IO error occurs
-
listKeys
public java.util.Map listKeys() throws java.io.IOExceptionList all the keys on the agent.- Returns:
- a map of public keys and descriptions
- Throws:
java.io.IOException- if an IO error occurs
-
lockAgent
public boolean lockAgent(java.lang.String password) throws java.io.IOExceptionLock the agent- Parameters:
password- password that will be required to unlock- Returns:
- true if the agent was locked, otherwise false
- Throws:
java.io.IOException- if an IO error occurs
-
unlockAgent
public boolean unlockAgent(java.lang.String password) throws java.io.IOExceptionUnlock the agent- Parameters:
password- the password to unlock- Returns:
- true if the agent was unlocked, otherwise false
- Throws:
java.io.IOException- if an IO error occurs
-
getRandomData
public byte[] getRandomData(int count) throws java.io.IOExceptionRequest some random data from the remote side- Parameters:
count- the number of bytes needed- Returns:
- the random data received
- Throws:
java.io.IOException- if an IO error occurs
-
ping
public void ping(byte[] padding) throws java.io.IOExceptionPing the remote side with some random padding data- Parameters:
padding- the padding data- Throws:
java.io.IOException- if an IO error occurs
-
deleteKey
public void deleteKey(SshPublicKey key, java.lang.String description) throws java.io.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:
java.io.IOException- if an IO error occurs
-
deleteAllKeys
public void deleteAllKeys() throws java.io.IOExceptionDelete all the keys held by the agent.- Throws:
java.io.IOException- if an IO error occurs
-
sendForwardingNotice
protected void sendForwardingNotice() throws java.io.IOExceptionSend a forwarding notice.- Throws:
java.io.IOException- if an IO error occurs
-
sendMessage
protected void sendMessage(SubsystemMessage msg) throws java.io.IOException
Send a subsystem message- Parameters:
msg- the message to send- Throws:
java.io.IOException- if an IO error occurs
-
readMessage
protected SubsystemMessage readMessage() throws InvalidMessageException
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
-
-