public class SshAgentClient extends Object implements SignatureGenerator
Modifier and Type | Field and Description |
---|---|
static String |
HASH_AND_SIGN |
static String |
WINDOWS_SSH_AGENT_SERVICE |
Constructor and Description |
---|
SshAgentClient(boolean isForwarded,
String application,
Closeable socket,
InputStream in,
OutputStream out,
boolean isRFC) |
SshAgentClient(boolean isForwarded,
String application,
Socket socket) |
Modifier and Type | Method and Description |
---|---|
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,
AgentSocketType type)
Connect a socket to the agent at the location specified.
|
static 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 |
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.
|
boolean |
isRFCAgent() |
Map<SshPublicKey,String> |
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 AgentMessage |
readMessage()
Read a single message from the inputstream and convert into a valid
subsystem message
|
protected void |
registerMessages() |
protected void |
sendForwardingNotice()
Send a forwarding notice.
|
protected void |
sendMessage(AgentMessage msg)
Send a subsystem message
|
protected void |
sendVersionRequest(String application)
Request the agent version.
|
byte[] |
sign(SshPublicKey key,
byte[] data)
Sign the data using the private key of the public key provided.
|
boolean |
unlockAgent(String password)
Unlock the agent
|
public static final String HASH_AND_SIGN
public static String WINDOWS_SSH_AGENT_SERVICE
public SshAgentClient(boolean isForwarded, String application, Socket socket) throws IOException
IOException
public SshAgentClient(boolean isForwarded, String application, Closeable socket, InputStream in, OutputStream out, boolean isRFC) throws IOException
IOException
public boolean isRFCAgent()
public static SshAgentClient connectOpenSSHAgent(String application) throws AgentNotAvailableException, IOException
public static SshAgentClient connectOpenSSHAgent(String application, String location) throws AgentNotAvailableException, IOException
application
- location
- AgentNotAvailableException
IOException
public static SshAgentClient connectLocalAgent(String application, String location, AgentSocketType type, boolean RFCAgent) throws AgentNotAvailableException, IOException
application
- the application connectinglocation
- the location of the agent, in the form "localhost:port"AgentNotAvailableException
- if the agent is not available at the location specifiedIOException
- if an IO error occurspublic static Socket connectAgentSocket(String location, AgentSocketType type) throws AgentNotAvailableException, IOException
location
- the location of the agent, in the form "localhost:port"AgentNotAvailableException
- if an agent is not available at the location specifiedIOException
- if an IO error occurspublic void close()
public void ping(byte[] padding) throws IOException
padding
- the padding dataIOException
- if an IO error occursprotected void registerMessages()
protected void sendForwardingNotice() throws IOException
IOException
- if an IO error occursprotected void sendMessage(AgentMessage msg) throws IOException
msg
- the message to sendIOException
- if an IO error occursprotected void sendVersionRequest(String application) throws IOException
application
- the application connectingIOException
- if an IO error occurspublic void deleteAllKeys() throws IOException
IOException
- if an IO error occursprotected AgentMessage readMessage() throws InvalidMessageException
InvalidMessageException
- if the message received is invalidpublic void addKey(SshPrivateKey prvkey, SshPublicKey pubkey, String description, KeyConstraints constraints) throws IOException
prvkey
- the private key to addpubkey
- the private keys public keydescription
- a description of the keyconstraints
- a set of contraints for key useIOException
- if an IO error occurspublic Map<SshPublicKey,String> listKeys() throws IOException
IOException
- if an IO error occurspublic boolean lockAgent(String password) throws IOException
password
- password that will be required to unlockIOException
- if an IO error occurspublic boolean unlockAgent(String password) throws IOException
password
- the password to unlockIOException
- if an IO error occurspublic byte[] getRandomData(int count) throws IOException
count
- the number of bytes neededIOException
- if an IO error occurspublic void deleteKey(SshPublicKey key, String description) throws IOException
key
- the public key of the private key to deletedescription
- the description of the keyIOException
- if an IO error occurspublic byte[] hashAndSign(SshPublicKey key, byte[] data) throws IOException
key
- the public key of the required private keydata
- the data to has and signIOException
- if an IO error occurspublic byte[] sign(SshPublicKey key, byte[] data) throws SshException
SignatureGenerator
sign
in interface SignatureGenerator
SshException
Copyright © 2024. All rights reserved.