* Start real work on SSH using ssh2 module
This commit is contained in:
parent
008e9f46d8
commit
d3e35d286a
|
@ -43,7 +43,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
ssh : {
|
ssh : {
|
||||||
port : 8889,
|
port : 8889,
|
||||||
enabled : false,
|
enabled : true,
|
||||||
rsaPrivateKey : paths.join(__dirname, './../misc/default_key.rsa'),
|
rsaPrivateKey : paths.join(__dirname, './../misc/default_key.rsa'),
|
||||||
dsaPrivateKey : paths.join(__dirname, './../misc/default_key.dsa'),
|
dsaPrivateKey : paths.join(__dirname, './../misc/default_key.dsa'),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
"use strict";
|
/* jslint node: true */
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var libssh = require('ssh');
|
// ENiGMA½
|
||||||
var conf = require('../config.js');
|
var conf = require('../config.js');
|
||||||
|
var baseClient = require('../client.js');
|
||||||
|
var user = require('../user.js');
|
||||||
|
|
||||||
/*
|
var ssh2 = require('ssh2');
|
||||||
Notes on getting libssh to work. This will ultimately require some contribs back
|
var fs = require('fs');
|
||||||
* Can't install without --nodedir= as had to upgrade node on the box for other reasons
|
|
||||||
* From ssh dir, node-gyp --nodedir=... configure build
|
|
||||||
* nan is out of date and doesn't work with existing node. Had to update. ( was "~0.6.0") (npm update after this)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
exports.moduleInfo = {
|
exports.moduleInfo = {
|
||||||
name : 'SSH',
|
name : 'SSH',
|
||||||
|
@ -17,13 +15,60 @@ exports.moduleInfo = {
|
||||||
author : 'NuSkooler'
|
author : 'NuSkooler'
|
||||||
};
|
};
|
||||||
|
|
||||||
function createServer() {
|
exports.createServer = createServer;
|
||||||
var server = libssh.createServer(
|
|
||||||
conf.config.servers.ssh.rsaPrivateKey,
|
|
||||||
conf.config.servers.ssh.dsaPrivateKey);
|
|
||||||
|
|
||||||
server.on('connection', function onConnection(session) {
|
function SSHClient(input, output) {
|
||||||
console.log('ermergerd')
|
baseClient.Client.apply(this, arguments);
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
this.input.on('authentication', function onAuthentication(ctx) {
|
||||||
|
console.log('auth: ' + ctx.method);
|
||||||
|
|
||||||
|
if('password' == ctx.method) {
|
||||||
|
// :TODO: Log attempts
|
||||||
|
user.authenticate(ctx.username, ctx.password, self, function onAuthResult(isAuth) {
|
||||||
|
if(isAuth) {
|
||||||
|
ctx.accept();
|
||||||
|
} else {
|
||||||
|
ctx.reject();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if('publickey' == ctx.method) {
|
||||||
|
console.log('pub key path');
|
||||||
|
// :TODO: support this. Allow users to generate a key for use or w/e
|
||||||
|
} else {
|
||||||
|
ctx.reject();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.input.on('ready', function onReady() {
|
||||||
|
console.log('Client authenticated');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.input.on('session', function onSession(accept, reject) {
|
||||||
|
var session = accept();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.input.on('end', function onEnd() {
|
||||||
|
self.emit('end');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
require('util').inherits(SSHClient, baseClient.Client);
|
||||||
|
|
||||||
|
function createServer() {
|
||||||
|
// :TODO: setup all options here. What should the banner, etc. really be????
|
||||||
|
var serverConf = {
|
||||||
|
privateKey : fs.readFileSync(conf.config.servers.ssh.rsaPrivateKey),
|
||||||
|
banner : 'ENiGMA½ BBS SSH Server',
|
||||||
|
debug : function onDebug(s) { console.log(s); }
|
||||||
|
};
|
||||||
|
|
||||||
|
var server = ssh2.Server(serverConf);
|
||||||
|
server.on('connection', function onConnection(conn) {
|
||||||
|
var client = new SSHClient(conn, conn);
|
||||||
|
this.emit('client', client);
|
||||||
});
|
});
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
|
|
|
@ -728,4 +728,4 @@ function createServer() {
|
||||||
});
|
});
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
};
|
}
|
||||||
|
|
Loading…
Reference in New Issue