From 1cfdc14eb8522f5065af9e0d5b0a477e99201ca6 Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Mon, 24 Feb 2020 23:53:59 -0800 Subject: [PATCH] Send NickServ messages when SASL is disabled I'm not sure this is the correct user interface, so I'm writing this patch as more of a way to describe my issue. I'm running my own instance of this appservice, and I'm using it to connect to OFTC. OFTC supports SASL, but requires a certificate-based authentication mechanism as opposed to the password-based mechanism that's supported by this appservice. As a result, even after sending a "!storepass irc.oftc.net $PASSWORD" I don't get logged in and still must identify with NickServ manually whenever the appservice reconnects to OFTC. In practice I just keep getting kicked from the one OFTC channel I care about, which requires registered nicks. I can think of two possible ways to fix this: either add support certificate-based SASL authentication (which seems complicated) or add support for NickServ. I chose to add support for NickServ, which simply involves sending a private message to NickServ containing the user's password. I think that's a sound feature, but I don't like how it's exposed to the user. With this patch the appservice will send a NickServ message containing the user's password whenever SASL is disabled in the server's configuration file. While this works for me, I'm not sure it's a good idea to just start sending out passwords with such an implicit configuration option. If I was to spend some more time on this, I'd probably do something like add an "authentication_mechanism" configuration option that can be set to either "none" (which would do nothing, aka sasl=false), "sasl_password" (which would do sasl=true) or "nickserv" (which would do this). Since there's a bit of plumbing involved and I've never written any typescript before, I wanted to send this patch out before going any farther -- if you're not interested in NickServ auth then I can just carry the patch myself. Signed-off-by: Palmer Dabbelt --- src/irc/ConnectionInstance.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/irc/ConnectionInstance.ts b/src/irc/ConnectionInstance.ts index dd50f90f5..07c7a1041 100644 --- a/src/irc/ConnectionInstance.ts +++ b/src/irc/ConnectionInstance.ts @@ -107,7 +107,7 @@ export class ConnectionInstance { * connect. * @return {Promise} Resolves if connected; rejects if failed to connect. */ - public connect(): Promise { + public connect(onConnect: () => void): Promise { if (this.dead) { throw new Error("connect() called on dead client: " + this.nick); } @@ -128,6 +128,7 @@ export class ConnectionInstance { this.state = "connected"; this.resetPingSendTimer(); this.connectDefer.resolve(this); + onConnect() }); return this.connectDefer.promise; } @@ -379,7 +380,13 @@ export class ConnectionInstance { if (onCreatedCallback) { onCreatedCallback(inst); } - return inst.connect(); + const onConnect = () => { + if (opts.password && !server.useSasl()) { + nodeClient.say("NickServ", "IDENTIFY " + opts.password); + } + } + const conn = inst.connect(onConnect); + return conn; }; let connAttempts = 0;