summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-22 21:07:57 +0200
committerxengineering <me@xengineering.eu>2023-05-22 21:07:57 +0200
commitefd5c81ca00136d3a673d99e699f16d050fcfaa6 (patch)
tree43f07ee17df972cab179cd1cd1c4990eafca4ce6
parent4fa114cd1efcba90054247f30fad957c8f0ec06d (diff)
downloadlimox-efd5c81ca00136d3a673d99e699f16d050fcfaa6.tar
limox-efd5c81ca00136d3a673d99e699f16d050fcfaa6.tar.zst
limox-efd5c81ca00136d3a673d99e699f16d050fcfaa6.zip
Introduce new xmpp/sasl.go
-rw-r--r--xmpp/routing.go44
-rw-r--r--xmpp/sasl.go50
2 files changed, 50 insertions, 44 deletions
diff --git a/xmpp/routing.go b/xmpp/routing.go
index 23f92bb..48c9763 100644
--- a/xmpp/routing.go
+++ b/xmpp/routing.go
@@ -2,7 +2,6 @@ package xmpp
import (
"encoding/xml"
- "encoding/base64"
"errors"
"log"
)
@@ -101,46 +100,3 @@ func streamFeatures(b []xml.Token, c *Conn) error {
return nil
}
-
-func sendSaslAuth(b []xml.Token, c *Conn) 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" {
- start := xml.StartElement{
- xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "auth"},
- []xml.Attr{
- xml.Attr{xml.Name{"", "mechanism"}, "PLAIN"},
- },
- }
-
- data := []byte("\x00" + username(c.jid) + "\x00" + c.pwd)
- dst := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
- base64.StdEncoding.Encode(dst, data)
- payload := xml.CharData(dst)
-
- end := start.End()
-
- c.enc.encodeNow(start)
- c.enc.encode(payload)
- c.enc.encodeNow(end)
-
- return nil
- }
- }
-
- return errors.New("No compatible SASL mechanism given")
-}
diff --git a/xmpp/sasl.go b/xmpp/sasl.go
new file mode 100644
index 0000000..cbc1f11
--- /dev/null
+++ b/xmpp/sasl.go
@@ -0,0 +1,50 @@
+package xmpp
+
+import (
+ "encoding/xml"
+ "encoding/base64"
+ "errors"
+)
+
+func sendSaslAuth(b []xml.Token, c *Conn) 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" {
+ start := xml.StartElement{
+ xml.Name{"urn:ietf:params:xml:ns:xmpp-sasl", "auth"},
+ []xml.Attr{
+ xml.Attr{xml.Name{"", "mechanism"}, "PLAIN"},
+ },
+ }
+
+ data := []byte("\x00" + username(c.jid) + "\x00" + c.pwd)
+ dst := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
+ base64.StdEncoding.Encode(dst, data)
+ payload := xml.CharData(dst)
+
+ end := start.End()
+
+ c.enc.encodeNow(start)
+ c.enc.encode(payload)
+ c.enc.encodeNow(end)
+
+ return nil
+ }
+ }
+
+ return errors.New("No compatible SASL mechanism given")
+}