From 37753409dc55da1a1cc3feed139f287a2d6215bb Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 21 May 2023 13:00:58 +0200 Subject: Implement SASL method parsing --- xmpp/routing.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'xmpp/routing.go') diff --git a/xmpp/routing.go b/xmpp/routing.go index 34136f4..55ec135 100644 --- a/xmpp/routing.go +++ b/xmpp/routing.go @@ -95,7 +95,35 @@ type elementRoutingTable []struct { } func streamFeatures(b []xml.Token) error { - log.Println("Received stream features") + err := sendSaslAuth(b) + if err != nil { + return err + } return nil } + +func sendSaslAuth(b []xml.Token) error { + mechanisms := make([]string, 0) + for i, v := range(b) { + switch token := v.(type) { + case xml.StartElement: + expected := xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "mechanism"} + if token.Name == expected { + if i >= (len(b)-1) { continue } + switch payload := b[i+1].(type) { + case xml.CharData: + mechanisms = append(mechanisms, string(payload)) + } + } + } + } + + for _, v := range(mechanisms) { + if v == "PLAIN" { + return nil + } + } + + return errors.New("No compatible SASL mechanism given") +} -- cgit v1.2.3-70-g09d2