TritonDataCenter / node-sshpk-agent

ssh-agent library for use with sshpk
MIT License
7 stars 5 forks source link

sshpk-agent

A library for using the ssh-agent protocol, written to leverage the modern node Streams API and use sshpk objects. Supports most client operations (including key add/remove), but agent support is coming. Re-uses socket connections where possible for lower latency operation.

Install

npm install sshpk-agent

Examples

var agent = require('sshpk-agent');
var sshpk = require('sshpk');

var client = new agent.Client();

/* Add a new key to the agent */
var pk = sshpk.parsePrivateKey(fs.readFileSync('id_rsa'), 'pem');
client.addKey(pk, function (err) {
  ...
});

/* List all the keys stored in the agent */
var key;
client.listKeys(function (err, keys) {
  if (err)
    return;
  /* keys is an array of sshpk.Key objects */
  key = keys[0];
});

/* Sign some data with a key */
var data = 'foobar';
client.sign(key, data, function (err, signature) {
  /* signature is an sshpk.Signature object */
  ...
  /* to find out what hash algorithm the agent used -- it chooses for you */
  var algo = signature.hashAlgorithm;
  ...
});

Usage

new Client([options]);

Creates a new ssh-agent client.

Parameters

Client#listKeys([options, ]callback);

Retrieves a list of all keys stored in the agent.

Parameters

Client#listCertificates([options, ]callback);

Retrieves a list of all certificates stored in the agent.

Parameters

Client#sign(key, data[, options], callback);

Uses a key stored in the agent to sign some data.

Parameters

Client#createSelfSignedCertificate(subject, key, options, cb)

Uses a key stored in the agent to create a self-signed certificate for that key. The certificate can be read back in both OpenSSH and X.509 formats.

Parameters

Client#createCertificate(subject, subjectKey, issuer, key, options, cb)

Uses a key stored in the agent to create and sign a certificate for some other key (not necessarily in the agent). The certificate can be read back in both OpenSSH and X.509 formats.

Parameters

Client#addKey(privkey[, options], callback);

Adds a new private key to the agent.

Parameters

Client#addCertificate(cert, privkey[, options], callback);

Adds a new certificate and private key pair to the agent.

Parameters

Client#removeKey(key[, options], callback);

Removes a private key from the agent.

Parameters

Client#removeAllKeys([options, ]callback);

Removes all private keys from the agent.

Parameters

Client#lock(password[, options], callback);

Locks the agent with a password, causing it to respond with failure to all requests (except a request to list keys, which always returns an empty list), until unlocked with the same password.

Parameters

Client#unlock(password[, options], callback);

Unlocks an agent that has been previously locked. The given password must match the password used to lock the agent.

Parameters

Client#listExtensions(callback);

Requests the "query" extension (see draft-miller-ssh-agent-00) from the agent to list what agent protocol extensions are supported. These are returned as a list of Strings.

Parameters