From f688465164a30b871ed00d2155008bd4266998dd Mon Sep 17 00:00:00 2001 From: Evert Date: Sun, 25 Sep 2016 17:13:14 +0300 Subject: [PATCH] secure connections --- client.config.example.toml | 5 +++++ public/index.html | 2 ++ public/js/main.js | 3 ++- server/irc.js | 14 +++++++++----- teemant.js | 11 +++++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/client.config.example.toml b/client.config.example.toml index 68f5fa2..e39df3b 100644 --- a/client.config.example.toml +++ b/client.config.example.toml @@ -8,3 +8,8 @@ default_quit_msg="Teemant IRC" default_part_msg="Bye!" secure_by_default=false + timeout=3000 + encoding="utf-8" + +[tls] + rejectUnauthorized=false diff --git a/public/index.html b/public/index.html index d176e75..49a0f7b 100644 --- a/public/index.html +++ b/public/index.html @@ -31,6 +31,8 @@ + + Use SSL diff --git a/public/js/main.js b/public/js/main.js index a67d778..b62d072 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -750,7 +750,7 @@ class IRCConnector { server: server, port: port, password: null, - secure: false }); + secure: clientdom.connector.secure.checked }); return true; } @@ -1250,6 +1250,7 @@ window.onload = function() { clientdom.connector['channel'] = clientdom.connector.form.querySelector('#channel'); clientdom.connector['server'] = clientdom.connector.form.querySelector('#server'); clientdom.connector['port'] = clientdom.connector.form.querySelector('#port'); + clientdom.connector['secure'] = clientdom.connector.form.querySelector('#secure'); clientdom['tabby'] = irc.primaryFrame.querySelector('.tabby') clientdom['frame'] = irc.primaryFrame.querySelector('#chat'); clientdom['letterbox'] = clientdom.frame.querySelector('.letterbox'); diff --git a/server/irc.js b/server/irc.js index d07dc6d..0e05f21 100644 --- a/server/irc.js +++ b/server/irc.js @@ -1,5 +1,6 @@ let EventEmitter = require('events').EventEmitter; let net = require('net'); +let tls = require('tls'); let configuration = require(__dirname+"/config"); let parse = require(__dirname+"/parser"); let webirc = require(__dirname+"/webirc"); @@ -174,7 +175,7 @@ class IRCConnectionHandler { case "NOTICE": if(line.user.nickname != "") this.conn.emit('pass_to_client', {type: "message", messageType: "notice", to: line.arguments[0], - user: line.user, message: line.trailing, server: serverName}); + user: line.user, message: line.trailing, server: serverName}); else this.conn.emit('pass_to_client', {type: "server_message", messageType: "notice", message: line.trailing, server: serverName, from: realServerName}); break; @@ -357,7 +358,8 @@ class IRCConnection extends EventEmitter { autojoin: [], secure: configuration.client.secure_by_default, password: "", - address: "0.0.0.0" + address: "0.0.0.0", + rejectUnauthorized: configuration.tls.rejectUnauthorized }; this.userInfo = userInfo; @@ -379,6 +381,7 @@ class IRCConnection extends EventEmitter { max_channel_length: 64, supportedModes: {} }; + this.authorizationError = ''; this.queue = {}; } @@ -391,13 +394,14 @@ class IRCConnection extends EventEmitter { } connect() { - this.socket = net.createConnection(this.config.port, this.config.server, () => { + this.socket = (this.config.secure ? tls : net).connect({port: this.config.port, host: this.config.server, + rejectUnauthorized: this.config.rejectUnauthorized}, () => { this.connected = true; this.authenticate(); }); - this.socket.setEncoding('utf8'); - this.socket.setTimeout(3000); + this.socket.setEncoding(configuration.client.encoding); + this.socket.setTimeout(configuration.client.timeout); this.socket.on('error', (data) => { this.emit('connerror', {type: "sock_error", message: "A socket error occured.", raw: data}); diff --git a/teemant.js b/teemant.js index adeae76..b2867b7 100755 --- a/teemant.js +++ b/teemant.js @@ -109,6 +109,10 @@ io.sockets.on('connection', function (socket) { newConnection.on('line', function(line) { console.log("["+socket.id+"] <-", line); }); + + newConnection.on('debug_log', function(data) { + console.log("["+socket.id+"] <-", data); + }); } newConnection.on('connerror', (data) => { @@ -123,6 +127,9 @@ io.sockets.on('connection', function (socket) { inconnect = false; } + if(config.server.debug) + console.log(data); + socket.emit('act_client', {type: (inconnect == true ? 'server_message' : 'connect_message'), server: connectiondata.server, message: message, error: true}); }); @@ -136,6 +143,10 @@ io.sockets.on('connection', function (socket) { if(newConnection.authenticated == false) { message = "Failed to connect to the server!"; + + if(config.server.debug) + console.log(data); + inconnect = false; }