Add Exodus door server support
This commit is contained in:
parent
4b8369a41f
commit
ca45656c11
|
@ -0,0 +1,220 @@
|
||||||
|
/* jslint node: true */
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// ENiGMA½
|
||||||
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||||
|
const resetScreen = require('../core/ansi_term.js').resetScreen;
|
||||||
|
const Config = require('./config.js').config;
|
||||||
|
const Errors = require('./enig_error.js').Errors;
|
||||||
|
const Log = require('./logger.js').log;
|
||||||
|
const getEnigmaUserAgent = require('./misc_util.js').getEnigmaUserAgent;
|
||||||
|
|
||||||
|
// deps
|
||||||
|
const async = require('async');
|
||||||
|
const _ = require('lodash');
|
||||||
|
const joinPath = require('path').join;
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const moment = require('moment');
|
||||||
|
const https = require('https');
|
||||||
|
const querystring = require('querystring');
|
||||||
|
const fs = require('fs');
|
||||||
|
const SSHClient = require('ssh2').Client;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Configuration block:
|
||||||
|
|
||||||
|
|
||||||
|
someDoor: {
|
||||||
|
module: exodus
|
||||||
|
config: {
|
||||||
|
// defaults
|
||||||
|
ticketHost: oddnetwork.org
|
||||||
|
ticketPort: 1984
|
||||||
|
ticketPath: /exodus
|
||||||
|
rejectUnauthorized: false // set to true to allow untrusted CA's (dangerous!)
|
||||||
|
sshHost: oddnetwork.org
|
||||||
|
sshPort: 22
|
||||||
|
sshUser: exodus
|
||||||
|
sshKeyPem: /path/to/enigma-bbs/misc/exodus.id_rsa
|
||||||
|
|
||||||
|
// optional
|
||||||
|
caPem: /path/to/cacerts.pem // see https://curl.haxx.se/docs/caextract.html
|
||||||
|
|
||||||
|
// required
|
||||||
|
board: XXXX
|
||||||
|
key: XXXX
|
||||||
|
door: some_door
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
exports.moduleInfo = {
|
||||||
|
name : 'Exodus',
|
||||||
|
desc : 'Exodus Door Server Access Module - https://oddnetwork.org/exodus/',
|
||||||
|
author : 'NuSkooler',
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getModule = class ExodusModule extends MenuModule {
|
||||||
|
constructor(options) {
|
||||||
|
super(options);
|
||||||
|
|
||||||
|
this.config = options.menuConfig.config || {};
|
||||||
|
this.config.ticketHost = this.config.ticketHost || 'oddnetwork.org';
|
||||||
|
this.config.ticketPort = this.config.ticketPort || 1984,
|
||||||
|
this.config.ticketPath = this.config.ticketPath || '/exodus';
|
||||||
|
this.config.rejectUnauthorized = _.get(this.config, 'rejectUnauthorized', true);
|
||||||
|
this.config.sshHost = this.config.sshHost || this.config.ticketHost;
|
||||||
|
this.config.sshPort = this.config.sshPort || 22;
|
||||||
|
this.config.sshUser = this.config.sshUser || 'exodus_server';
|
||||||
|
this.config.sshKeyPem = this.config.sshKeyPem || joinPath(Config.paths.misc, 'exodus.id_rsa');
|
||||||
|
}
|
||||||
|
|
||||||
|
initSequence() {
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
let clientTerminated = false;
|
||||||
|
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
function validateConfig(callback) {
|
||||||
|
// very basic validation on optionals
|
||||||
|
async.each( [ 'board', 'key', 'door' ], (key, next) => {
|
||||||
|
return _.isString(self.config[key]) ? next(null) : next(Errors.MissingConfig(`Config requires "${key}"!`));
|
||||||
|
}, callback);
|
||||||
|
},
|
||||||
|
function loadCertAuthorities(callback) {
|
||||||
|
if(!_.isString(self.config.caPem)) {
|
||||||
|
return callback(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.readFile(self.config.caPem, (err, certAuthorities) => {
|
||||||
|
return callback(err, certAuthorities);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function getTicket(certAuthorities, callback) {
|
||||||
|
const now = moment.utc().unix();
|
||||||
|
const sha256 = crypto.createHash('sha256').update(`${self.config.key}${now}`).digest('hex');
|
||||||
|
const token = `${sha256}|${now}`;
|
||||||
|
|
||||||
|
const postData = querystring.stringify({
|
||||||
|
token : token,
|
||||||
|
board : self.config.board,
|
||||||
|
user : self.client.user.username,
|
||||||
|
door : self.config.door,
|
||||||
|
});
|
||||||
|
|
||||||
|
const reqOptions = {
|
||||||
|
hostname : self.config.ticketHost,
|
||||||
|
port : self.config.ticketPort,
|
||||||
|
path : self.config.ticketPath,
|
||||||
|
rejectUnauthorized : self.config.rejectUnauthorized,
|
||||||
|
method : 'POST',
|
||||||
|
headers : {
|
||||||
|
'Content-Type' : 'application/x-www-form-urlencoded',
|
||||||
|
'Content-Length' : postData.length,
|
||||||
|
'User-Agent' : getEnigmaUserAgent(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if(certAuthorities) {
|
||||||
|
reqOptions.ca = certAuthorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
let ticket = '';
|
||||||
|
const req = https.request(reqOptions, res => {
|
||||||
|
res.on('data', data => {
|
||||||
|
ticket += data;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('end', () => {
|
||||||
|
if(ticket.length !== 36) {
|
||||||
|
return callback(Errors.Invalid(`Invalid Exodus ticket: ${ticket}`));
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(null, ticket);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on('error', err => {
|
||||||
|
return callback(Errors.General(`Exodus error: ${err.message}`));
|
||||||
|
});
|
||||||
|
|
||||||
|
req.write(postData);
|
||||||
|
req.end();
|
||||||
|
},
|
||||||
|
function loadPrivateKey(ticket, callback) {
|
||||||
|
fs.readFile(self.config.sshKeyPem, (err, privateKey) => {
|
||||||
|
return callback(err, ticket, privateKey);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function establishSecureConnection(ticket, privateKey, callback) {
|
||||||
|
|
||||||
|
let pipeRestored = false;
|
||||||
|
let pipedStream;
|
||||||
|
|
||||||
|
function restorePipe() {
|
||||||
|
if(pipedStream && !pipeRestored && !clientTerminated) {
|
||||||
|
self.client.term.output.unpipe(pipedStream);
|
||||||
|
self.client.term.output.resume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.client.term.write(resetScreen());
|
||||||
|
self.client.term.write('Connecting to Exodus server, please wait...\n');
|
||||||
|
|
||||||
|
const sshClient = new SSHClient();
|
||||||
|
|
||||||
|
const shellOptions = {
|
||||||
|
env : {
|
||||||
|
exodus : ticket,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
sshClient.on('ready', () => {
|
||||||
|
self.client.once('end', () => {
|
||||||
|
self.client.log.info('Connection ended. Terminating Exodus connection');
|
||||||
|
clientTerminated = true;
|
||||||
|
return sshClient.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
sshClient.shell(shellOptions, (err, stream) => {
|
||||||
|
|
||||||
|
pipedStream = stream; // :TODO: ewwwwwwwww hack
|
||||||
|
self.client.term.output.pipe(stream);
|
||||||
|
|
||||||
|
stream.on('data', d => {
|
||||||
|
return self.client.term.rawWrite(d);
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on('close', () => {
|
||||||
|
restorePipe();
|
||||||
|
return sshClient.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
sshClient.on('close', () => {
|
||||||
|
restorePipe();
|
||||||
|
return callback(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
sshClient.connect({
|
||||||
|
host : self.config.sshHost,
|
||||||
|
port : self.config.sshPort,
|
||||||
|
username : self.config.sshUser,
|
||||||
|
privateKey : privateKey,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
],
|
||||||
|
err => {
|
||||||
|
if(err) {
|
||||||
|
self.client.log.warn( { error : err.message }, 'Exodus error');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!clientTerminated) {
|
||||||
|
self.prevMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
|
@ -4,6 +4,7 @@
|
||||||
let Config = require('./config.js').config;
|
let Config = require('./config.js').config;
|
||||||
let Address = require('./ftn_address.js');
|
let Address = require('./ftn_address.js');
|
||||||
let FNV1a = require('./fnv1a.js');
|
let FNV1a = require('./fnv1a.js');
|
||||||
|
const getCleanEnigmaVersion = require('./misc_util.js').getCleanEnigmaVersion;
|
||||||
|
|
||||||
let _ = require('lodash');
|
let _ = require('lodash');
|
||||||
let iconv = require('iconv-lite');
|
let iconv = require('iconv-lite');
|
||||||
|
@ -146,11 +147,7 @@ function getMessageIdentifier(message, address) {
|
||||||
// in which (<os>; <arch>; <nodeVer>) is used instead
|
// in which (<os>; <arch>; <nodeVer>) is used instead
|
||||||
//
|
//
|
||||||
function getProductIdentifier() {
|
function getProductIdentifier() {
|
||||||
const version = packageJson.version
|
const version = getCleanEnigmaVersion();
|
||||||
.replace(/\-/g, '.')
|
|
||||||
.replace(/alpha/,'a')
|
|
||||||
.replace(/beta/,'b');
|
|
||||||
|
|
||||||
const nodeVer = process.version.substr(1); // remove 'v' prefix
|
const nodeVer = process.version.substr(1); // remove 'v' prefix
|
||||||
|
|
||||||
return `ENiGMA1/2 ${version} (${os.platform()}; ${os.arch()}; ${nodeVer})`;
|
return `ENiGMA1/2 ${version} (${os.platform()}; ${os.arch()}; ${nodeVer})`;
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
/* jslint node: true */
|
/* jslint node: true */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var paths = require('path');
|
const paths = require('path');
|
||||||
|
|
||||||
|
const os = require('os');
|
||||||
|
const packageJson = require('../package.json');
|
||||||
|
|
||||||
exports.isProduction = isProduction;
|
exports.isProduction = isProduction;
|
||||||
exports.isDevelopment = isDevelopment;
|
exports.isDevelopment = isDevelopment;
|
||||||
exports.valueWithDefault = valueWithDefault;
|
exports.valueWithDefault = valueWithDefault;
|
||||||
exports.resolvePath = resolvePath;
|
exports.resolvePath = resolvePath;
|
||||||
|
exports.getCleanEnigmaVersion = getCleanEnigmaVersion;
|
||||||
|
exports.getEnigmaUserAgent = getEnigmaUserAgent;
|
||||||
|
|
||||||
function isProduction() {
|
function isProduction() {
|
||||||
var env = process.env.NODE_ENV || 'dev';
|
var env = process.env.NODE_ENV || 'dev';
|
||||||
|
@ -28,3 +33,20 @@ function resolvePath(path) {
|
||||||
}
|
}
|
||||||
return paths.resolve(path);
|
return paths.resolve(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCleanEnigmaVersion() {
|
||||||
|
return packageJson.version
|
||||||
|
.replace(/\-/g, '.')
|
||||||
|
.replace(/alpha/,'a')
|
||||||
|
.replace(/beta/,'b')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See also ftn_util.js getTearLine() & getProductIdentifier()
|
||||||
|
function getEnigmaUserAgent() {
|
||||||
|
// can't have 1/2 or ½ in User-Agent according to RFC 1945 :(
|
||||||
|
const version = getCleanEnigmaVersion();
|
||||||
|
const nodeVer = process.version.substr(1); // remove 'v' prefix
|
||||||
|
|
||||||
|
return `ENiGMA-BBS/${version} (${os.platform()}; ${os.arch()}; ${nodeVer})`;
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEowIBAAKCAQEAmpwn/vJ1CAIkVnQGDZumvEDsMyFSHioGO5RM/T2Id6XLX91r
|
||||||
|
feJI6w48yqLV+HgKLUK7eeTOzb/l4VShH9AzOqTbAxwfZ6fgzV2cI/wZxO0S6QpS
|
||||||
|
7IrwcVK1Bm7Wu45Kp7LcGHB66nHSb+wqIYkZobIc8Z9arClJxV4AzgaUxjJrk0wT
|
||||||
|
hW81r5TicbTG7zm+bOMLO/mln+HA/EOtx/yfKDcfkl+mLzzbMpojor+KdwuKJUb1
|
||||||
|
+r4PhPVl6pZgOuQIl37Qh5SPY3mMjwyXW/tUe+ZmPpfOm3CKf/pTLsA45QzUbNBY
|
||||||
|
GPLjbEcMJ4R5T3c2LXCKR+Wi9/pCkeZT7/1BbQIDAQABAoIBAQCCasrK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N/7zTHdk/BnT9C//pR2nOK+G9FpayNSBvT
|
||||||
|
ttXCKUyuou8I22kzc2Kzay5JYxf9CXHspl4b2D+OcTQXQUSZYTIlum+alq3LswqN
|
||||||
|
ANIIxQKBgHauoT79sViuB/wHcp2W/mek0p9aLkgQKt+riPJ4vKXc8DtapTgQzXkk
|
||||||
|
6yQCOSD8T9DcVGBcap9n6T21NOyDQwM0gg+DoHVeYqBrAa93jufOi7EY3MFrkjH6
|
||||||
|
tC0crKBcUkxu43zhY4DkHLxId5btSPH57U+lhrJGjKXdvlJrGGOM
|
||||||
|
-----END RSA PRIVATE KEY-----
|
Loading…
Reference in New Issue