Skip to content

Commit c89249e

Browse files
authored
Correct sasl authentication base64 splitting (#299)
* Correct sasl authentication base64 splitting Fixes #296 * Simplify the base64 splitting
1 parent 9804749 commit c89249e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/commands/handlers/registration.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,17 @@ const handlers = {
274274
saslAuth.account + '\0' +
275275
saslAuth.password;
276276
const b = Buffer.from(auth_str, 'utf8');
277-
let b64 = b.toString('base64');
277+
const b64 = b.toString('base64');
278278

279-
while (b64.length >= 400) {
280-
handler.connection.write('AUTHENTICATE ' + b64.slice(0, 399));
281-
b64 = b64.slice(399);
279+
// https://ircv3.net/specs/extensions/sasl-3.1#the-authenticate-command
280+
const singleAuthCommandLength = 400;
281+
let sliceOffset = 0;
282+
283+
while (b64.length > sliceOffset) {
284+
handler.connection.write('AUTHENTICATE ' + b64.substr(sliceOffset, singleAuthCommandLength));
285+
sliceOffset += singleAuthCommandLength;
282286
}
283-
if (b64.length > 0) {
284-
handler.connection.write('AUTHENTICATE ' + b64);
285-
} else {
287+
if (b64.length === sliceOffset) {
286288
handler.connection.write('AUTHENTICATE +');
287289
}
288290
},

0 commit comments

Comments
 (0)