summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-07-02 11:40:42 +0200
committerxengineering <me@xengineering.eu>2023-07-03 20:54:35 +0200
commit6a623ed4ec649f0fcfa775405ad5584bc1cd6762 (patch)
tree159afd15f23348255f7fbda07f64e99b1ba7c308
parent5570ccd1d6b50042acbf2fad3793afa6dde79ca2 (diff)
downloadlimox-6a623ed4ec649f0fcfa775405ad5584bc1cd6762.tar
limox-6a623ed4ec649f0fcfa775405ad5584bc1cd6762.tar.zst
limox-6a623ed4ec649f0fcfa775405ad5584bc1cd6762.zip
Switch to EncodeElement() for SASL auth
-rw-r--r--xmpp/sasl.go26
1 files changed, 10 insertions, 16 deletions
diff --git a/xmpp/sasl.go b/xmpp/sasl.go
index 512fd58..24edc9a 100644
--- a/xmpp/sasl.go
+++ b/xmpp/sasl.go
@@ -6,32 +6,26 @@ import (
"log"
)
-func (s *session) sasl() {
- tokens := make([]xml.Token, 0, 3)
+type saslRequest struct {
+ Payload []byte `xml:",chardata"`
+}
+func (s *session) sasl() {
start := xml.StartElement{
xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "auth"},
[]xml.Attr{
xml.Attr{xml.Name{"", "mechanism"}, "PLAIN"},
},
}
- tokens = append(tokens, start)
data := []byte("\x00" + username(s.jid) + "\x00" + s.pwd)
- dst := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
- base64.StdEncoding.Encode(dst, data)
- payload := xml.CharData(dst)
- tokens = append(tokens, payload)
+ inner := saslRequest{}
+ inner.Payload = make([]byte, base64.StdEncoding.EncodedLen(len(data)))
+ base64.StdEncoding.Encode(inner.Payload, data)
- end := start.End()
- tokens = append(tokens, end)
-
- for _, t := range tokens {
- err := s.ed.encodeToken(t)
- if err != nil {
- log.Println("Could not encode SASL PLAIN element!")
- return
- }
+ err := s.ed.tx.EncodeElement(inner, start)
+ if err != nil {
+ log.Println("Could not encode SASL PLAIN element!")
}
}