diff --git a/README.md b/README.md index 252ea3f..880725d 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,10 @@ It is advisable to generate your keys on a machine with a significant random sou ssh-keygen is [open source](https://github.com/ericvicenti/ssh-keygen/blob/master/LICENSE.md) under the MIT license +### Windows + +This package bundles binaries for windows. The current version is: `2.4.4.2-rc3` + ### Todo * Real tests diff --git a/bin/ssh-keygen-32.exe b/bin/ssh-keygen-32.exe new file mode 100755 index 0000000..6862a37 Binary files /dev/null and b/bin/ssh-keygen-32.exe differ diff --git a/bin/ssh-keygen-64.exe b/bin/ssh-keygen-64.exe new file mode 100755 index 0000000..64d7a13 Binary files /dev/null and b/bin/ssh-keygen-64.exe differ diff --git a/src/ssh-keygen.js b/src/ssh-keygen.js index 4607271..a99dfec 100644 --- a/src/ssh-keygen.js +++ b/src/ssh-keygen.js @@ -7,6 +7,16 @@ var path = require('path'); var log = function(a){ if(process.env.VERBOSE) console.log('ssh-keygen: '+a); } +function binPath() { + if(process.platform !== 'win32') return 'ssh-keygen'; + + switch(process.arch) { + case 'ia32': return path.join(__dirname, '..', 'bin', 'ssh-keygen-32.exe'); + case 'x64': return path.join(__dirname, '..', 'bin', 'ssh-keygen-64.exe'); + } + + throw new Error('Unsupported platform'); +} function checkAvailability(location, force, callback){ var pubLocation = location+'.pub'; log('checking availability: '+location); @@ -20,7 +30,7 @@ function checkAvailability(location, force, callback){ if(!force && keyExists) return callback(location+' already exists'); if(!force && pubKeyExists) return callback(pubLocation+' already exists'); if(!keyExists && !pubKeyExists) return callback(); - if(keyExists){ + if(keyExists){ log('removing '+location); fs.unlink(location, function(err){ if(err) return callback(err); @@ -45,7 +55,7 @@ function ssh_keygen(location, opts, callback){ if(!opts.comment) opts.comment = ''; if(!opts.password) opts.password = ''; - var keygen = spawn('ssh-keygen', [ + var keygen = spawn(binPath(), [ '-t','rsa', '-b','2048', '-C', opts.comment, @@ -64,7 +74,7 @@ function ssh_keygen(location, opts, callback){ log('exited'); if(read){ log('reading key '+location); - fs.readFile(location, 'utf8', function(err, key){ + fs.readFile(location, 'utf8', function(err, key){ if(destroy){ log('destroying key '+location); fs.unlink(location, function(err){