Created
August 24, 2012 15:46
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); |
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.
I think I see what's going on.
Node 0.8.x was compiled with OPENSSL_NO_TTY defined.
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
Please, do not paste the contents of the output generated by this file nowhere public, it will include information regarding your private ssh key!