Skip to content

Instantly share code, notes, and snippets.

@auscompgeek
Last active July 14, 2020 11:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auscompgeek/8111321 to your computer and use it in GitHub Desktop.
Save auscompgeek/8111321 to your computer and use it in GitHub Desktop.
SASL plugin for ChatZilla by Gryllida, cleaned up
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* SASL plugin for ChatZilla.
*
* ChatZilla is a clean, easy to use and highly extensible Internet Relay Chat (IRC) client.
* Get it here: https://addons.mozilla.org/addon/16
* Standalone version here: http://chatzilla.rdmsoft.com/xulrunner/
*
* How do I install scripts?
* http://chatzilla.hacksrus.com/faq/#install-script
*
* *****************************************************************************************
*
* Plugin usage:
*
* /plugin-pref cz_sasl
* /plugin-pref cz_sasl sasl.servername SERVER_THAT_SUPPORTS_SASL
* /plugin-pref cz_sasl sasl.username YOUR_USERNAME
* /plugin-pref cz_sasl sasl.password YOUR_PASSWORD
* /plugin-pref cz_sasl sasl.proceed_on_fail (true|false)
*
* *****************************************************************************************
*
* (C) 2011 Gryllida A <Gryllida@gmail.com>
* (C) 2013 auscompgeek <auscompgeek@myopera.com>
*/
plugin.id = "cz_sasl";
plugin.init =
function initPlugin(glob) {
this.major = 0;
this.minor = 6;
this.version = this.major + "." + this.minor;
this.description = "Adds SASL authentication support. To setup, |/plugin-pref cz_sasl|";
this.prefary = this.prefary.concat([
["sasl.servername", "chat.freenode.net", ""],
["sasl.username", "", ""],
["sasl.password", "", ""],
["sasl.proceed_on_fail", false, ""]
]);
return "OK";
};
plugin.enable =
function enablePlugin(status) {
client.eventPump.addHook([{ set: "server", type: "parseddata" }], this.onData, this.id + "-hook-data");
client.eventPump.addHook([{ set: "server", type: "connect" }], this.onconnect, this.id + "-hook-connect");
return true;
};
plugin.disable =
function disablePlugin(status) {
client.eventPump.removeHookByName(this.id + "-hook-data");
client.eventPump.removeHookByName(this.id + "-hook-connect");
return true;
};
plugin.onConnect =
function onConnect(e) {
if (e.server.hostname === this.prefs["sasl.servername"]) {
e.server.performSASLChecks = true;
e.server.sendData("CAP LS\n");
}
};
plugin.onData =
function onData(e) {
if (!e.server.performSASLChecks) {
return;
}
if (e.data === "AUTHENTICATE +") {
// Response to "AUTHENTICATE" command. Server has given us the OK to authenticate.
var auth = btoa(this.prefs["sasl.username"] + '\0' + this.prefs["sasl.username"] + '\0' + this.prefs["sasl.password"]);
e.server.sendData("AUTHENTICATE " + auth + "\n");
return;
}
switch (e.params[0]) {
case "CAP":
// Response to CAP command.
if (e.params[2] === "LS") {
// Response to CAP LS command: listing of extended capabilities.
var capList = e.params[3];
e.server.parent.display("This server supports extended capabilities: " + capList);
capList = capList.split(" ");
if (capList.indexOf("sasl") !== -1) {
e.server.sendData("CAP REQ :sasl\n");
}
// We don't want to show the user the raw message now.
return true;
}
if (e.params[2] === "ACK" && e.params[3] === "sasl ") {
// Response to "CAP REQ :sasl". Start authentication process.
e.server.sendData("AUTHENTICATE PLAIN\n");
}
break;
case "903":
// Authentication succeeded, continue connecting.
e.server.performSASLChecks = false;
e.server.sendData("CAP END\n");
break;
case "904": case "905":
// Authentication failed.
e.server.performSASLChecks = false;
e.server.sendData("CAP END\n");
e.server.parent.display("SASL authentication failed - invalid username or password. " +
"Please use the account name (not a nick) as the username, and try again.", "WARNING");
if (!plugin.prefs["sasl.proceed_on_fail"]) {
// Disconnect if we're configured to stop if we fail.
e.server.dispatch("cancel");
}
break;
}
};

cz_sasl.js

SASL plugin for ChatZilla.

This document contains some notes found in the original cz_sasl.js by Gryllida.

How to enable ChatZilla's debug mode

  • Set browser.dom.window.dump.enabled to true in about:config.
  • Run /pref debugMode cdt in ChatZilla.
  • Start ChatZilla from console, like seamonkey -chat or firefox.exe -chat -console.

Raw SASL

~$ telnet irc.freenode.net 6667
Trying 78.40.125.4...
Connected to chat.freenode.net.
Escape character is '^]'.
:barjavel.freenode.net NOTICE * :*** Looking up your hostname...
:barjavel.freenode.net NOTICE * :*** Checking Ident
:barjavel.freenode.net NOTICE * :*** Found your hostname
CAP LS
NICK test
USER test 8 * :test
:barjavel.freenode.net NOTICE * :*** No Ident response
:barjavel.freenode.net CAP * LS :identify-msg multi-prefix sasl
CAP REQ :multi-prefix sasl
:barjavel.freenode.net CAP test ACK :multi-prefix sasl 
AUTHENTICATE PLAIN
AUTHENTICATE +
AUTHENTICATE R3...WYx <-- "user\0user\0pass" base64 encoded
:barjavel.freenode.net 900 test test!test@unaffiliated/user user :You are now logged in as user.
:barjavel.freenode.net 903 test :SASL authentication successful
CAP END
Copy link

ghost commented Feb 23, 2016

Can I use this script with multiple different servers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment