Merge sshkeys

This commit is contained in:
Nick O'Leary
2017-12-20 15:12:10 +00:00
14 changed files with 1704 additions and 82 deletions

View File

@@ -45,7 +45,7 @@ var ResponseServer = function(auth) {
parts.push(data.substring(0, m));
data = data.substring(m);
var line = parts.join("");
console.log("LINE",line);
console.log("LINE:",line);
parts = [];
if (line==='Username') {
connection.end(auth.username);
@@ -79,8 +79,54 @@ var ResponseServer = function(auth) {
});
}
var ResponseSSHServer = function(auth) {
return new Promise(function(resolve, reject) {
server = net.createServer(function(connection) {
connection.setEncoding('utf8');
var parts = [];
connection.on('data', function(data) {
var m = data.indexOf("\n");
if (m !== -1) {
parts.push(data.substring(0, m));
data = data.substring(m);
var line = parts.join("");
console.log("LINE:",line);
parts = [];
if (line==='The') {
connection.end('yes');
// server.close();
} else if (line === 'Enter') {
connection.end(auth.passphrase);
// server.close();
} else {
}
}
if (data.length > 0) {
parts.push(data);
}
});
});
var listenPath = getListenPath();
server.listen(listenPath, function(ready) {
resolve({path:listenPath,close:function() { server.close(); }});
});
server.on('close', function() {
// console.log("Closing response server");
fs.removeSync(listenPath);
});
server.on('error',function(err) {
console.log("ResponseServer unexpectedError:",err.toString());
server.close();
reject(err);
})
});
}
module.exports = {
ResponseServer: ResponseServer
ResponseServer: ResponseServer,
ResponseSSHServer: ResponseSSHServer
}

View File

@@ -18,6 +18,7 @@ var when = require('when');
var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var authResponseServer = require('./authServer').ResponseServer;
var sshResponseServer = require('./authServer').ResponseSSHServer;
var clone = require('clone');
var path = require("path");
@@ -50,6 +51,8 @@ function runGitCommand(args,cwd,env) {
err.code = "git_auth_failed";
} else if(/HTTP Basic: Access denied/.test(stderr)) {
err.code = "git_auth_failed";
} else if(/Permission denied \(publickey\)/.test(stderr)) {
err.code = "git_auth_failed";
} else if(/Connection refused/.test(stderr)) {
err.code = "git_connection_failed";
} else if (/commit your changes or stash/.test(stderr)) {
@@ -80,6 +83,22 @@ function runGitCommandWithAuth(args,cwd,auth) {
})
}
function runGitCommandWithSSHCommand(args,cwd,auth) {
return sshResponseServer(auth).then(function(rs) {
var commandEnv = clone(process.env);
commandEnv.SSH_ASKPASS = path.join(__dirname,"node-red-ask-pass.sh");
commandEnv.DISPLAY = "dummy:0";
commandEnv.NODE_RED_GIT_NODE_PATH = process.execPath;
commandEnv.NODE_RED_GIT_SOCK_PATH = rs.path;
commandEnv.NODE_RED_GIT_ASKPASS_PATH = path.join(__dirname,"authWriter.js");
commandEnv.GIT_SSH_COMMAND = "ssh -i " + auth.key_path + " -F /dev/null";
// console.log('commandEnv:', commandEnv);
return runGitCommand(args,cwd,commandEnv).finally(function() {
rs.close();
});
})
}
function cleanFilename(name) {
if (name[0] !== '"') {
return name;
@@ -362,7 +381,12 @@ module.exports = {
}
var promise;
if (auth) {
promise = runGitCommandWithAuth(args,cwd,auth);
if ( auth.key_path ) {
promise = runGitCommandWithSSHCommand(args,cwd,auth);
}
else {
promise = runGitCommandWithAuth(args,cwd,auth);
}
} else {
promise = runGitCommand(args,cwd)
}
@@ -393,7 +417,12 @@ module.exports = {
args.push("--porcelain");
var promise;
if (auth) {
promise = runGitCommandWithAuth(args,cwd,auth);
if ( auth.key_path ) {
promise = runGitCommandWithSSHCommand(args,cwd,auth);
}
else {
promise = runGitCommandWithAuth(args,cwd,auth);
}
} else {
promise = runGitCommand(args,cwd)
}
@@ -418,7 +447,12 @@ module.exports = {
}
args.push(".");
if (auth) {
return runGitCommandWithAuth(args,cwd,auth);
if ( auth.key_path ) {
return runGitCommandWithSSHCommand(args,cwd,auth);
}
else {
return runGitCommandWithAuth(args,cwd,auth);
}
} else {
return runGitCommand(args,cwd);
}
@@ -477,7 +511,12 @@ module.exports = {
fetch: function(cwd,remote,auth) {
var args = ["fetch",remote];
if (auth) {
return runGitCommandWithAuth(args,cwd,auth);
if ( auth.key_path ) {
return runGitCommandWithSSHCommand(args,cwd,auth);
}
else {
return runGitCommandWithAuth(args,cwd,auth);
}
} else {
return runGitCommand(args,cwd);
}