Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows support #5

Merged
merged 1 commit into from
Aug 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added bin/ssh-keygen-32.exe
Binary file not shown.
Binary file added bin/ssh-keygen-64.exe
Binary file not shown.
16 changes: 13 additions & 3 deletions src/ssh-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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){
Expand Down