From c600e10faf59e96be6b0ad440bd4c5d8cc13d38a Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 27 Jun 2023 16:43:45 +0200 Subject: xmpp: Re-introduce SASL authentication --- xmpp/sasl.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 xmpp/sasl.go (limited to 'xmpp/sasl.go') diff --git a/xmpp/sasl.go b/xmpp/sasl.go new file mode 100644 index 0000000..1cb3670 --- /dev/null +++ b/xmpp/sasl.go @@ -0,0 +1,36 @@ +package xmpp + +import ( + "encoding/xml" + "encoding/base64" + "log" +) + +func (s *session) sasl() { + tokens := make([]xml.Token, 0, 3) + + 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) + + end := start.End() + tokens = append(tokens, end) + + for _, t := range tokens { + err := s.ed.encodeToken(t) + if err != nil { + log.Println("Could not encode stream end!") + return + } + } +} -- cgit v1.2.3-70-g09d2