Class AgentProxy
java.lang.Object
com.hierynomus.sshj.userauth.agent.AgentProxy
- All Implemented Interfaces:
Closeable,AutoCloseable
A client for the SSH authentication agent protocol (draft-miller-ssh-agent / OpenSSH's
PROTOCOL.agent).
This is the recommended way to authenticate with a FIDO/U2F security key (an
sk-ecdsa-sha2-nistp256@openssh.com or sk-ssh-ed25519@openssh.com key): load the
key into your agent once with ssh-add, and the agent performs the hardware tap on every
sign. The agent returns a fully formed SSH signature - including the security-key flags and
counter - so sshj forwards it verbatim and never has to talk to the hardware itself.
It works for ordinary keys too (RSA, ECDSA, Ed25519), so it doubles as general ssh-agent support.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSign flag asking the agent for anrsa-sha2-256signature from an RSA key.static final intSign flag asking the agent for anrsa-sha2-512signature from an RSA key. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static AgentProxyConnect to the agent indicated by theSSH_AUTH_SOCKenvironment variable over a unix- domain socket.List the identities the agent holds.byte[]sign(byte[] keyBlob, byte[] data, int flags) Ask the agent to signdatawith the key identified bykeyBlob.
-
Field Details
-
SSH_AGENT_RSA_SHA2_256
public static final int SSH_AGENT_RSA_SHA2_256Sign flag asking the agent for anrsa-sha2-256signature from an RSA key.- See Also:
-
SSH_AGENT_RSA_SHA2_512
public static final int SSH_AGENT_RSA_SHA2_512Sign flag asking the agent for anrsa-sha2-512signature from an RSA key.- See Also:
-
-
Constructor Details
-
AgentProxy
- Throws:
IOException
-
-
Method Details
-
fromEnvironment
Connect to the agent indicated by theSSH_AUTH_SOCKenvironment variable over a unix- domain socket. Requires a Java 16+ runtime; on older runtimes construct anAgentProxywith your ownAgentConnection.- Throws:
IOException- ifSSH_AUTH_SOCKis unset or the agent cannot be reached
-
getIdentities
List the identities the agent holds. Identities whose key type sshj does not understand are skipped (logged at debug), rather than failing the whole listing.- Throws:
IOException
-
sign
Ask the agent to signdatawith the key identified bykeyBlob.- Parameters:
keyBlob- the identity's key blob, exactly as returned bygetIdentities()data- the data to signflags- sign flags, e.g.SSH_AGENT_RSA_SHA2_256;0for Ed25519 and security keys- Returns:
- the SSH signature value (
string signature_format || string signature_blob, with any security-key flags and counter already appended by the agent), ready to be written as a single SSHstring - Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-