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);
});
@kusor
Copy link
Author

kusor commented Aug 24, 2012

Please, do not paste the contents of the output generated by this file nowhere public, it will include information regarding your private ssh key!

@pborenstein
Copy link

If it works, and your SSH key has a passphrase, you should be prompted for your passphrase and the signature printed out. This is what happens in node 0.6.20

Under node 0.8.7, this code does not prompt for a passphrase, and the signature is blank.

@pborenstein
Copy link

I think I see what's going on.

Node 0.8.x was compiled with OPENSSL_NO_TTY defined.

@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