summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-06-30 12:28:48 +0200
committerxengineering <me@xengineering.eu>2023-06-30 12:30:38 +0200
commitd6fa15b7b66d679b7a6291aa6c85780a09cb1755 (patch)
treeddf5c089882b828d6c9c0cd602e65e5f9f13127d
parent2f6b1a11209260f4ee7b9469e39d16e78fb23a0f (diff)
downloadlimox-d6fa15b7b66d679b7a6291aa6c85780a09cb1755.tar
limox-d6fa15b7b66d679b7a6291aa6c85780a09cb1755.tar.zst
limox-d6fa15b7b66d679b7a6291aa6c85780a09cb1755.zip
Add detection for SASL mechanism
This is needed to respond with a SASL auth attempt.
-rw-r--r--xmpp/stream_pair.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/xmpp/stream_pair.go b/xmpp/stream_pair.go
index 3e42cd1..b353947 100644
--- a/xmpp/stream_pair.go
+++ b/xmpp/stream_pair.go
@@ -91,6 +91,31 @@ func closeStream(s *session) {
}
}
+func getCharData(t xml.Token) string {
+ switch c := t.(type) {
+ case xml.CharData:
+ return string(c)
+ default:
+ return ""
+ }
+}
+
func streamFeaturesHandler(e []xml.Token) {
- log.Println("Received stream features")
+ mechanism := xml.Name{`urn:ietf:params:xml:ns:xmpp-sasl`, `mechanism`}
+
+ for i, t := range e {
+ switch s := t.(type) {
+ case xml.StartElement:
+ if s.Name == mechanism {
+ if i+1 < len(e) {
+ if getCharData(e[i+1]) == `PLAIN` {
+ log.Println("Got offer for SASL PLAIN")
+ return
+ }
+ }
+ }
+ }
+ }
+
+ log.Println("No compatible SASL mechanism offered!")
}