Bug 1106246 - Improve SASL error messages. r=clokep
authoraleth <aleth@instantbird.org>
Thu, 04 Dec 2014 10:00:28 +0100
changeset 16979 7ad9619c5ac573d43876a44178592a7401125b13
parent 16978 4de62824831f112b49ed856c8364aa3bad7bfdb1
child 16980 0e07208d399fcac113ac724525986547a11f20cf
push id1305
push usermbanner@mozilla.com
push dateMon, 23 Feb 2015 19:48:12 +0000
treeherdercomm-esr52@110abf3d7989 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
bugs1106246
Bug 1106246 - Improve SASL error messages. r=clokep
chat/protocols/irc/ircSASL.jsm
--- a/chat/protocols/irc/ircSASL.jsm
+++ b/chat/protocols/irc/ircSASL.jsm
@@ -1,15 +1,16 @@
 /* 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/. */
 
 /*
  * This implements SASL for IRC.
  *   https://raw.github.com/atheme/atheme/master/doc/SASL
+ *   https://github.com/ircv3/ircv3-specifications/blob/master/extensions/sasl-3.1
  */
 
 const EXPORTED_SYMBOLS = ["ircSASL", "capSASL"];
 
 const Cu = Components.utils;
 
 Cu.import("resource:///modules/ircHandlers.jsm");
 Cu.import("resource:///modules/ircUtils.jsm");
@@ -36,59 +37,93 @@ var ircSASL = {
       // btoa for Unicode, see https://developer.mozilla.org/en-US/docs/DOM/window.btoa
       let base64Data = btoa(unescape(encodeURIComponent(data)));
       this.sendMessage("AUTHENTICATE", base64Data,
                        "AUTHENTICATE <base64 encoded nick, user and password not logged>");
       return true;
     },
 
     "900": function(aMessage) {
+      // RPL_LOGGEDIN
       // <nick>!<ident>@<host> <account> :You are now logged in as <user>
       // Now logged in ("whether by SASL or otherwise").
+      this.isAuthenticated = true;
+      return true;
+    },
+
+    "901": function(aMessage) {
+      // RPL_LOGGEDOUT
+      // The user's account name is unset (whether by SASL or otherwise).
+      this.isAuthenticated = false;
+      return true;
+    },
+
+    "902": function(aMessage) {
+      // ERR_NICKLOCKED
+      // Authentication failed because the account is currently locked out,
+      // held, or otherwise administratively made unavailable.
+      this.WARN("You must use a nick assigned to you. SASL authentication failed.");
+      this.removeCAP("sasl");
       return true;
     },
 
     "903": function(aMessage) {
+      // RPL_SASLSUCCESS
       // Authentication was successful.
       this.isAuthenticated = true;
       this.LOG("SASL authentication successful.");
       // We may receive this again while already connected if the user manually
       // identifies with Nickserv.
       if (!this.connected)
         this.removeCAP("sasl");
       return true;
     },
 
     "904": function(aMessage) {
-      // AUTHENTICATE message failed.
-      // Only PLAIN is currently supported, so fail here.
-      this.WARN("The server does not support SASL PLAIN authentication.");
+      // ERR_SASLFAIL
+      // Sent when the SASL authentication fails because of invalid credentials
+      // or other errors not explicitly mentioned by other numerics.
+      this.WARN("Authentication with SASL failed.");
       this.removeCAP("sasl");
       return true;
     },
 
     "905": function(aMessage) {
-      this.ERROR("Authentication with SASL failed.");
+      // ERR_SASLTOOLONG
+      // Sent when credentials are valid, but the SASL authentication fails
+      // because the client-sent `AUTHENTICATE` command was too long.
+      this.ERROR("SASL: AUTHENTICATE command was too long.");
       this.removeCAP("sasl");
       return true;
     },
 
     "906": function(aMessage) {
-      // The client completed registration before SASL authentication completed.
+      // ERR_SASLABORTED
+      // The client completed registration before SASL authentication completed,
+      // or because we sent `AUTHENTICATE` with `*` as the parameter.
       this.ERROR("Registration completed before SASL authentication completed.");
       this.removeCAP("sasl");
       return true;
     },
 
     "907": function(aMessage) {
+      // ERR_SASLALREADY
       // Response if client attempts to AUTHENTICATE after successful
       // authentication.
       this.ERROR("Attempting SASL authentication twice?!");
       this.removeCAP("sasl");
       return true;
+    },
+
+    "908": function(aMessage) {
+      // RPL_SASLMECHS
+      // <nick> <mechanisms> :are available SASL mechanisms
+      // List of SASL mechanisms supported by the server (or network, services).
+      // The numeric contains a comma-separated list of mechanisms.
+      return false;
     }
   }
 };
 
 var capSASL = {
   name: "SASL CAP",
   priority: ircHandlers.DEFAULT_PRIORITY,
   isEnabled: function() true,