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.
This commit is contained in:
Simon Ser 2024-06-30 23:42:31 +02:00
parent 0c86b96e86
commit 965ce9cdb9

View file

@ -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