Skip to content

Commit

Permalink
Merge pull request #545 from stack-fault/MRC-SSL-Support
Browse files Browse the repository at this point in the history
Added SSL support
  • Loading branch information
NuSkooler authored Jul 21, 2024
2 parents 4a48553 + c24274e commit 9c0bc88
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
2 changes: 2 additions & 0 deletions core/config_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ module.exports = () => {
enabled: false,
serverHostname: 'mrc.bottomlessabyss.net',
serverPort: 5000,
serverSslPort: 5001,
useSsl: false,
retryDelay: 10000,
multiplexerPort: 5000,
},
Expand Down
40 changes: 33 additions & 7 deletions core/servers/chat/mrc_multiplexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const _ = require('lodash');
const os = require('os');

// MRC
const protocolVersion = '1.2.9';
const clientVersion = '1.3.1';
const lineDelimiter = new RegExp('\r\n|\r|\n'); // eslint-disable-line no-control-regex

const ModuleInfo = (exports.moduleInfo = {
Expand All @@ -35,20 +35,32 @@ exports.getModule = class MrcModule extends ServerModule {
this.log = Log.child({ server: 'MRC' });

const config = Config();
this.boardName = config.general.prettyBoardName || config.general.boardName;
this.mrcConnectOpts = {
this.boardName = config.general.boardName;

// Use prettyBoardName only if non-default
if (config.general.prettyBoardName != '|08XXXXX') this.boardName = config.general.prettyBoardName;

this.mrcConfig = {
host: config.chatServers.mrc.serverHostname || 'mrc.bottomlessabyss.net',
port: config.chatServers.mrc.serverPort || 5000,
sslport: config.chatServers.mrc.serverSslPort || 5001,
retryDelay: config.chatServers.mrc.retryDelay || 10000,
useSsl: config.chatServers.mrc.useSsl || false,
};

this.mrcConnectOpts = {
host: this.mrcConfig.host,
port: this.mrcConfig.port,
retryDelay: this.mrcConfig.retryDelay
}
}

_connectionHandler() {
const enigmaVersion = 'ENiGMA½-BBS_' + require('../../../package.json').version;

const handshake = `${
this.boardName
}~${enigmaVersion}/${os.platform()}.${os.arch()}/${protocolVersion}`;
}~${enigmaVersion}/${os.platform()}.${os.arch()}/${clientVersion}`;
this.log.debug({ handshake: handshake }, 'Handshaking with MRC server');

this.sendRaw(handshake);
Expand Down Expand Up @@ -96,13 +108,27 @@ exports.getModule = class MrcModule extends ServerModule {
connectToMrc() {
const self = this;

// create connection to MRC server
this.mrcClient = net.createConnection(
if (this.mrcConfig.useSsl) {
this.mrcConnectOpts.port = this.mrcConfig.sslport;
}

// Create connection
this.mrcSocket = net.createConnection(
this.mrcConnectOpts,
self._connectionHandler.bind(self)
);

this.mrcClient.requestedDisconnect = false;
this.mrcSocket.requestedDisconnect = false;

// Check if we upgrade the connection to SSL
if (this.mrcConfig.useSsl) {
const tls = require('tls')
this.mrcSecureSocket = new tls.TLSSocket(this.mrcSocket, { isServer: false });
this.mrcClient = this.mrcSecureSocket;
}
else {
this.mrcClient = this.mrcSocket;
}

// do things when we get data from MRC central
let buffer = new Buffer.from('');
Expand Down
10 changes: 7 additions & 3 deletions misc/config_template.in.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,13 @@
// Make sure to adjust 'prettyBoardName' to your liking in your config before enabling

mrc: {
enabled : false
serverHostname : 'mrc.bottomlessabyss.net'
serverPort : 5000
enabled : false
serverHostname : 'mrc.bottomlessabyss.net'
serverPort : 5000
serverSslPort : 5001
useSsl : true
retryDelay : 10000
multiplexerPort : 5000
}
}

Expand Down

0 comments on commit 9c0bc88

Please sign in to comment.