2015-03-17 04:41:14 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-03-17 04:41:14 +00:00
|
|
|
// ENiGMA½
|
2015-03-23 04:52:04 +00:00
|
|
|
var conf = require('../config.js');
|
|
|
|
var baseClient = require('../client.js');
|
|
|
|
var user = require('../user.js');
|
|
|
|
var ServerModule = require('../server_module.js').ServerModule;
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-03-17 04:41:14 +00:00
|
|
|
var ssh2 = require('ssh2');
|
|
|
|
var fs = require('fs');
|
2015-03-23 04:52:04 +00:00
|
|
|
var util = require('util');
|
2014-10-17 02:21:06 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'SSH',
|
|
|
|
desc : 'SSH Server',
|
2015-03-17 04:41:14 +00:00
|
|
|
author : 'NuSkooler'
|
2014-10-17 02:21:06 +00:00
|
|
|
};
|
|
|
|
|
2015-03-23 04:52:04 +00:00
|
|
|
exports.getModule = SSHServerModule;
|
2015-03-17 04:41:14 +00:00
|
|
|
|
|
|
|
function SSHClient(input, output) {
|
|
|
|
baseClient.Client.apply(this, arguments);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.input.on('authentication', function onAuthentication(ctx) {
|
|
|
|
console.log('auth: ' + ctx.method);
|
|
|
|
|
2015-03-19 05:08:23 +00:00
|
|
|
if('password' === ctx.method) {
|
2015-03-17 04:41:14 +00:00
|
|
|
// :TODO: Log attempts
|
|
|
|
user.authenticate(ctx.username, ctx.password, self, function onAuthResult(isAuth) {
|
|
|
|
if(isAuth) {
|
|
|
|
ctx.accept();
|
|
|
|
} else {
|
|
|
|
ctx.reject();
|
|
|
|
}
|
|
|
|
});
|
2015-03-19 05:08:23 +00:00
|
|
|
} else if('publickey' === ctx.method) {
|
2015-03-17 04:41:14 +00:00
|
|
|
console.log('pub key path');
|
2015-03-19 05:08:23 +00:00
|
|
|
} else if('keyboard-interactive' === ctx.method) {
|
|
|
|
ctx.reject(['password']);
|
2015-03-17 04:41:14 +00:00
|
|
|
// :TODO: support this. Allow users to generate a key for use or w/e
|
2015-03-19 05:08:23 +00:00
|
|
|
|
|
|
|
/*} else if('keyboard-interactive' === ctx.method) {
|
|
|
|
console.log(ctx.submethods); // :TODO: proper logging; handle known types, etc.
|
|
|
|
|
|
|
|
ctx.prompt([ { prompt : 'Password: ', echo : false } ], function onPromptResponses(err, responses) {
|
|
|
|
console.log(err);
|
|
|
|
console.log(responses);
|
|
|
|
});*/
|
2015-03-17 04:41:14 +00:00
|
|
|
} else {
|
|
|
|
ctx.reject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.input.on('ready', function onReady() {
|
|
|
|
console.log('Client authenticated');
|
|
|
|
|
2015-03-19 05:08:23 +00:00
|
|
|
self.input.on('session', function onSession(accept, reject) {
|
|
|
|
|
|
|
|
});
|
2015-03-17 04:41:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.input.on('end', function onEnd() {
|
|
|
|
self.emit('end');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-23 04:52:04 +00:00
|
|
|
util.inherits(SSHClient, baseClient.Client);
|
|
|
|
|
|
|
|
function SSHServerModule() {
|
|
|
|
ServerModule.call(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(SSHServerModule, ServerModule);
|
|
|
|
|
|
|
|
SSHServerModule.prototype.createServer = function() {
|
|
|
|
SSHServerModule.super_.prototype.createServer.call(this);
|
2015-03-17 04:41:14 +00:00
|
|
|
|
|
|
|
// :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); }
|
|
|
|
};
|
2014-10-17 02:21:06 +00:00
|
|
|
|
2015-03-17 04:41:14 +00:00
|
|
|
var server = ssh2.Server(serverConf);
|
2015-03-19 05:08:23 +00:00
|
|
|
server.on('connection', function onConnection(conn, info) {
|
|
|
|
console.log(info); // :TODO: Proper logging
|
2015-03-17 04:41:14 +00:00
|
|
|
var client = new SSHClient(conn, conn);
|
|
|
|
this.emit('client', client);
|
2014-10-17 02:21:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return server;
|
2015-03-23 04:52:04 +00:00
|
|
|
};
|