com.sshtools.j2ssh.agent

Class SshAgentClient


public class SshAgentClient
extends java.lang.Object

Provides a client connection to the ssh agent.
Version:
$Revision: 1.17 $
Author:
$author$

Field Summary

static String
HASH_AND_SIGN
The hash and sign private key operation

Method Summary

void
addKey(SshPrivateKey prvkey, SshPublicKey pubkey, String description, KeyConstraints constraints)
Add a key to the agent
void
close()
Close the agent
static Socket
connectAgentSocket(String location)
Connect a socket to the agent at the location specified.
static SshAgentClient
connectLocalAgent(String application, String location)
Connect to the local agent.
void
deleteAllKeys()
Delete all the keys held by the agent.
void
deleteKey(SshPublicKey key, String description)
Delete a key held by the agent
byte[]
getRandomData(int count)
Request some random data from the remote side
byte[]
hashAndSign(SshPublicKey key, byte[] data)
Request a hash and sign operation be performed for a given public key.
Map
listKeys()
List all the keys on the agent.
boolean
lockAgent(String password)
Lock the agent
void
ping(byte[] padding)
Ping the remote side with some random padding data
protected SubsystemMessage
readMessage()
Read a single message from the inputstream and convert into a valid subsystem message
protected void
registerMessages()
Register the subsystem messages
protected void
sendForwardingNotice()
Send a forwarding notice.
protected void
sendMessage(SubsystemMessage msg)
Send a subsystem message
protected void
sendVersionRequest(String application)
Request the agent version.
boolean
unlockAgent(String password)
Unlock the agent

Field Details

HASH_AND_SIGN

public static final String HASH_AND_SIGN
The hash and sign private key operation

Method Details

addKey

public void addKey(SshPrivateKey prvkey,
                   SshPublicKey pubkey,
                   String description,
                   KeyConstraints constraints)
            throws IOException
Add a key to the agent
Parameters:
prvkey - the private key to add
pubkey - the private keys public key
description - a description of the key
constraints - a set of contraints for key use

close

public void close()
Close the agent

connectAgentSocket

public static Socket connectAgentSocket(String location)
            throws AgentNotAvailableException,
                   IOException
Connect 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 specified

connectLocalAgent

public static SshAgentClient connectLocalAgent(String application,
                                               String location)
            throws AgentNotAvailableException,
                   IOException
Connect to the local agent.
Parameters:
application - the application connecting
location - 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 specified

deleteAllKeys

public void deleteAllKeys()
            throws IOException
Delete all the keys held by the agent.

deleteKey

public void deleteKey(SshPublicKey key,
                      String description)
            throws IOException
Delete a key held by the agent
Parameters:
key - the public key of the private key to delete
description - the description of the key

getRandomData

public byte[] getRandomData(int count)
            throws IOException
Request some random data from the remote side
Parameters:
count - the number of bytes needed
Returns:
the random data received

hashAndSign

public byte[] hashAndSign(SshPublicKey key,
                          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 key
data - the data to has and sign
Returns:
the hashed and signed data

listKeys

public Map listKeys()
            throws IOException
List all the keys on the agent.
Returns:
a map of public keys and descriptions

lockAgent

public boolean lockAgent(String password)
            throws IOException
Lock the agent
Parameters:
password - password that will be required to unlock
Returns:
true if the agent was locked, otherwise false

ping

public void ping(byte[] padding)
            throws IOException
Ping the remote side with some random padding data
Parameters:
padding - the padding data

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

registerMessages

protected void registerMessages()
Register the subsystem messages

sendForwardingNotice

protected void sendForwardingNotice()
            throws IOException
Send a forwarding notice.

sendMessage

protected void sendMessage(SubsystemMessage msg)
            throws IOException
Send a subsystem message
Parameters:
msg - the message to send

sendVersionRequest

protected void sendVersionRequest(String application)
            throws IOException
Request the agent version.
Parameters:
application - the application connecting

unlockAgent

public boolean unlockAgent(String password)
            throws IOException
Unlock the agent
Parameters:
password - the password to unlock
Returns:
true if the agent was unlocked, otherwise false

Copyright © 2002-2003 Lee David Painter & Contributors. All Rights Reserved.