NAME

Crypt::MultiKey::SSHAgentClient - Interact with the user's SSH Agent

SYNOPSIS

my $agent= Crypt::MultiKey::SSHAgentClient->new;
my @keys= $agent->list_keys;
my $signature_bytes= $agent->sign($keys[0], $data_bytes);

DESCRIPTION

You can ask OpenSSH to sign arbitrary data using ssh-keygen -Y, however this feature is an option when building OpenSSH and even some modern Linux distros haven't enabled it. So, this module makes a direct socket connection to your SSH agent! If that fails, it falls back to running the ssh-add(1) and ssh-keygen(1) commands.

CONSTRUCTORS

new

Create a new object. This object connects to the agent on demand, so creating the object might succeed but then throw an exception during list_keys if it can't connect and the ssh-add program isn't found or ssh-keygen doesn't support -Y.

ATTRIBUTES

ssh_auth_sock

Path of SSH agent socket. Defaults to $ENV{SSH_AUTH_SOCK}.

ssh_add_cmd

Path to ssh-add(1) command, defaulting to 'ssh-add' which lets the OS find it.

ssh_keygen_cmd

Path to ssh-keygen(1) command, defaulting to 'ssh-keygen' which lets the OS find it.

METHODS

list_keys

my @keys= $agent->list_keys;
# (
#   { type          => $algo,
#     pubkey_base64 => $base64,
#     comment       => $text,
#   },
#   ...
# )

Return a list of keys available in the agent. type, pubkey_base64, and comment are the exact strings seen in the output of ssh-add -L.

This list is cached for 0.1s to avoid spamming the connection if many PKeys are being checked.

sign

my $signature_bytes= $agent->sign($pubkey, $data_bytes, $namespace);

The $pubkey can be either the base64 string of the public key, or the hashref for that key returned by list_keys. $data_bytes can be any scalar containing bytes. The $namespace defaults to "Crypt::MultiKey".

CONFIGURATION

You can specify the paths to the exeutables used by this module with the %Crypt::MultiKey::command_path global variable:

ssh-add

$Crypt::MultiKey::command_path{'ssh-add'}

ssh-keygen

$Crypt::MultiKey::command_path{'ssh-keygen'}.

For security, these are not configurable from an environment variable.

VERSION

version 0.000_001

AUTHOR

Michael Conrad <mike@nrdvana.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Michael Conrad.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.