diff options
author | xengineering <me@xengineering.eu> | 2023-07-04 21:24:04 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-07-04 21:24:04 +0200 |
commit | 2c71877e392da6c2691827160142e95142f7bea6 (patch) | |
tree | f7b3a0b9d8d98e422a5ca579fd8fbceb654ad0a6 | |
parent | e529bab2e5df93ff8e9fd415b9d65e9bb6d17695 (diff) | |
download | limox-2c71877e392da6c2691827160142e95142f7bea6.tar limox-2c71877e392da6c2691827160142e95142f7bea6.tar.zst limox-2c71877e392da6c2691827160142e95142f7bea6.zip |
Re-implement SASL
Was broken because of switch to new RX concept.
-rw-r--r-- | xmpp/routing.go | 4 | ||||
-rw-r--r-- | xmpp/session.go | 2 | ||||
-rw-r--r-- | xmpp/streams.go | 21 |
3 files changed, 20 insertions, 7 deletions
diff --git a/xmpp/routing.go b/xmpp/routing.go index b184b1c..a9dd8b6 100644 --- a/xmpp/routing.go +++ b/xmpp/routing.go @@ -23,10 +23,10 @@ func parse[T any](data T, s *xml.StartElement, d *xml.Decoder, c chan<- any) { } } -func handle(element any) { +func handle(s *session, element any) { switch t := element.(type) { case streamFeatures: - log.Println("Handling stream features ...") + handleStreamFeatures(s, t) default: log.Printf("Unknown parsed element: %v", t) } diff --git a/xmpp/session.go b/xmpp/session.go index a4120e9..7a07280 100644 --- a/xmpp/session.go +++ b/xmpp/session.go @@ -64,7 +64,7 @@ func (s *session) run() { for { select { case e := <-s.rx: - handle(e) + handle(s, e) case signal := <-s.in: switch signal.(type) { case SessionShouldDisconnect: diff --git a/xmpp/streams.go b/xmpp/streams.go index 3aca8a2..8f6fd03 100644 --- a/xmpp/streams.go +++ b/xmpp/streams.go @@ -5,6 +5,23 @@ import ( "log" ) +type streamFeatures struct { + SaslMechanisms []string `xml:"mechanisms>mechanism"` +} + +func handleStreamFeatures(s *session, f streamFeatures) { + if len(f.SaslMechanisms) > 0 { + for _, v := range f.SaslMechanisms { + if v == "PLAIN" { + s.sasl() + return + } + } + log.Println("No compatible SASL mechanism found!") + return + } +} + func openStream(e *xml.Encoder, jid string) { start := xml.StartElement{ xml.Name{"jabber:client", "stream:stream"}, @@ -63,7 +80,3 @@ func iqHandler(s *session, e []xml.Token) { } } } - -type streamFeatures struct { - SaslMechanisms []string `xml:"mechanisms>mechanism"` -} |