From 965ce9cdb9b85973473a646a2c1105ddf64ec57a Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 30 Jun 2024 23:42:31 +0200 Subject: [PATCH] xirc: fix chunking in GenerateSASL The SASL response needs to be encoded into base64, then split into 400 byte chunks. We were doing it in reverse order. --- xirc/genmsg.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/xirc/genmsg.go b/xirc/genmsg.go index 91c02cc..9327d49 100644 --- a/xirc/genmsg.go +++ b/xirc/genmsg.go @@ -206,25 +206,25 @@ func GenerateNamesReply(channel string, status ChannelStatus, members []string) } func GenerateSASL(resp []byte) []*irc.Message { + encoded := base64.StdEncoding.EncodeToString(resp) + // <= instead of < because we need to send a final empty response if // the last chunk is exactly 400 bytes long var msgs []*irc.Message - for i := 0; i <= len(resp); i += MaxSASLLength { + for i := 0; i <= len(encoded); i += MaxSASLLength { j := i + MaxSASLLength - if j > len(resp) { - j = len(resp) + if j > len(encoded) { + j = len(encoded) } - chunk := resp[i:j] - - var respStr = "+" - if len(chunk) != 0 { - respStr = base64.StdEncoding.EncodeToString(chunk) + chunk := encoded[i:j] + if chunk == "" { + chunk = "+" } msgs = append(msgs, &irc.Message{ Command: "AUTHENTICATE", - Params: []string{respStr}, + Params: []string{chunk}, }) } return msgs