Skip to content

Instantly share code, notes, and snippets.

@kusor
Created August 24, 2012 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kusor/3452172 to your computer and use it in GitHub Desktop.
Save kusor/3452172 to your computer and use it in GitHub Desktop.
Trying to figure out different behavior on crypto module for node-v0.6 and node-v0.8
// IDENTITY_FILE=/Users/<USERNAME>/.ssh/id_rsa node crypto-signature.js
if (!process.env.IDENTITY_FILE) {
console.error('IDENTITY_FILE ENV var requiered');
process.exit(1);
};
var crypto = require('crypto'),
fs = require('fs'),
identity = process.env.IDENTITY_FILE,
signingKey;
fs.readFile(identity, 'ascii', function (err, file) {
if (err) {
console.error(err);
process.exit(1);
}
signingKey = file;
console.log('Signing key is: %s', signingKey);
var alg = / DSA /.test(signingKey) ? 'DSA-SHA1' : 'RSA-SHA256';
console.log('Algorithm is: %s', alg);
var signer = crypto.createSign(alg);
var now = new Date().toUTCString();
signer.update(now);
var signature = signer.sign(signingKey, 'base64');
console.log('Signature is: %s', signature);
process.exit(0);
});
@pborenstein
Copy link

I compiled node 0.8.8 with OPENSSL_NO_TTY commented out deps/openssl/openssl.gyp and this test script worked as expected.

There must be a way to either check ssh-agent (node-smartdc does, apparently) or to have us ask the user for the passphrase and pass it to crypto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment