Handle upstream multi-line SASL

References: https://todo.sr.ht/~emersion/soju/173
This commit is contained in:
Simon Ser 2021-12-10 10:44:40 +01:00
parent e7f9d2332b
commit fe564af756
3 changed files with 21 additions and 10 deletions

View file

@ -983,7 +983,7 @@ func (dc *downstreamConn) handleAuthenticateCommand(msg *irc.Message) (result *d
dc.sasl.pendingResp.WriteString(chunk) dc.sasl.pendingResp.WriteString(chunk)
if len(chunk) == 400 { if len(chunk) == maxSASLLength {
return nil, nil // Multi-line response, wait for the next command return nil, nil // Multi-line response, wait for the next command
} }

1
irc.go
View file

@ -25,6 +25,7 @@ const (
const ( const (
maxMessageLength = 512 maxMessageLength = 512
maxMessageParams = 15 maxMessageParams = 15
maxSASLLength = 400
) )
// The server-time layout, as defined in the IRCv3 spec. // The server-time layout, as defined in the IRCv3 spec.

View file

@ -619,16 +619,26 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
return err return err
} }
// TODO: send response in multiple chunks if >= 400 bytes // <= instead of < because we need to send a final empty response if
var respStr = "+" // the last chunk is exactly 400 bytes long
if len(resp) != 0 { for i := 0; i <= len(resp); i += maxSASLLength {
respStr = base64.StdEncoding.EncodeToString(resp) j := i + maxSASLLength
} if j > len(resp) {
j = len(resp)
}
uc.SendMessage(ctx, &irc.Message{ chunk := resp[i:j]
Command: "AUTHENTICATE",
Params: []string{respStr}, var respStr = "+"
}) if len(chunk) != 0 {
respStr = base64.StdEncoding.EncodeToString(chunk)
}
uc.SendMessage(ctx, &irc.Message{
Command: "AUTHENTICATE",
Params: []string{respStr},
})
}
case irc.RPL_LOGGEDIN: case irc.RPL_LOGGEDIN:
if err := parseMessageParams(msg, nil, nil, &uc.account); err != nil { if err := parseMessageParams(msg, nil, nil, &uc.account); err != nil {
return err return err