From cb827f78cb1417ec2b8ff2f1400f623dc8f545d1 Mon Sep 17 00:00:00 2001 From: Gabriel Farrell Date: Thu, 27 Dec 2012 14:39:19 -0500 Subject: [PATCH 1/4] Added SASL support Set sasl: true in options, along with nick, userName, and password, for SASL login (required for some IP ranges for connecting to Freenode, etc.). --- lib/irc.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/irc.js b/lib/irc.js index c8428091..d0ef64a6 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -48,6 +48,7 @@ function Client(server, nick, opt) { certExpired: false, floodProtection: false, floodProtectionDelay: 1000, + sasl: false, stripColors: false, channelPrefixes: "&#", messageSplit: 512 @@ -510,6 +511,23 @@ function Client(server, nick, opt) { // who, reason, channels self.emit('quit', message.nick, message.args[0], channels, message); break; + + // for sasl + case "CAP": + if ( message.args[0] === '*' ) self.send("AUTHENTICATE", "PLAIN"); + break; + case "AUTHENTICATE": + if ( message.args[0] === '+' ) self.send("AUTHENTICATE", + new Buffer( + self.opt.nick + '\0' + + self.opt.userName + '\0' + + self.opt.password + ).toString('base64')); + break; + case "903": + self.send("CAP", "END"); + break; + case "err_umodeunknownflag": if ( self.opt.showErrors ) util.log("\033[01;31mERROR: " + util.inspect(message) + "\033[0m"); @@ -614,7 +632,10 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{ self.conn.setTimeout(0); self.conn.setEncoding('utf8'); self.conn.addListener("connect", function () { - if ( self.opt.password !== null ) { + if ( self.opt.sasl ) { + // see http://ircv3.atheme.org/extensions/sasl-3.1 + self.send("CAP REQ", "sasl"); + } else if ( self.opt.password !== null ) { self.send( "PASS", self.opt.password ); } self.send("NICK", self.opt.nick); From d9e32dea1f978132d41395076ea36933847b75f6 Mon Sep 17 00:00:00 2001 From: Gabriel Farrell Date: Thu, 27 Dec 2012 14:45:51 -0500 Subject: [PATCH 2/4] Missed a colon --- lib/irc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/irc.js b/lib/irc.js index d0ef64a6..0f6ad5a1 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -634,7 +634,7 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{ self.conn.addListener("connect", function () { if ( self.opt.sasl ) { // see http://ircv3.atheme.org/extensions/sasl-3.1 - self.send("CAP REQ", "sasl"); + self.send("CAP REQ", ":sasl"); } else if ( self.opt.password !== null ) { self.send( "PASS", self.opt.password ); } From 61b88d6161967f517f62948d54cf19272dec5fad Mon Sep 17 00:00:00 2001 From: Gabriel Farrell Date: Fri, 28 Dec 2012 09:15:20 -0500 Subject: [PATCH 3/4] Be more specific with CAP event --- lib/irc.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/irc.js b/lib/irc.js index 0f6ad5a1..579381d4 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -514,7 +514,10 @@ function Client(server, nick, opt) { // for sasl case "CAP": - if ( message.args[0] === '*' ) self.send("AUTHENTICATE", "PLAIN"); + if ( message.args[0] === '*' && + message.args[1] === 'ACK' && + message.args[2] === 'sasl ' ) // there's a space after sasl + self.send("AUTHENTICATE", "PLAIN"); break; case "AUTHENTICATE": if ( message.args[0] === '+' ) self.send("AUTHENTICATE", From 0dd7ac1af65b7d70f6c0b31fb17ddc659c3bc516 Mon Sep 17 00:00:00 2001 From: Gabriel Farrell Date: Fri, 28 Dec 2012 09:15:59 -0500 Subject: [PATCH 4/4] Added a note about the sasl option to the docs --- docs/API.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/API.rst b/docs/API.rst index 296c6cba..031dc228 100644 --- a/docs/API.rst +++ b/docs/API.rst @@ -29,6 +29,7 @@ Client certExpired: false, floodProtection: false, floodProtectionDelay: 1000, + sasl: false, stripColors: false, channelPrefixes: "&#", messageSplit: 512 @@ -47,14 +48,17 @@ Client `floodProtectionDelay` sets the amount of time that the client will wait between sending subsequent messages when `floodProtection` is enabled. - `messageSplit` will split up large messages sent with the `say` method - into multiple messages of length fewer than `messageSplit` characters. + Set `sasl` to true to enable SASL support. You'll also want to set `nick`, + `userName`, and `password` for authentication. `stripColors` removes mirc colors (0x03 followed by one or two ascii numbers for foreground,background) and ircII "effect" codes (0x02 bold, 0x1f underline, 0x16 reverse, 0x0f reset) from the entire message before parsing it and passing it along. + `messageSplit` will split up large messages sent with the `say` method + into multiple messages of length fewer than `messageSplit` characters. + Setting `autoConnect` to false prevents the Client from connecting on instantiation. You will need to call `connect()` on the client instance::