From b2d090a623c60b7faab18ba9b40981d3dc93b424 Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Sun, 7 Apr 2024 09:29:50 +0200 Subject: [PATCH] Improve sasl2 user agent id stuff. --- const.go | 1 + helpers.go | 4 ++-- vendor/github.com/xmppo/go-xmpp/xmpp.go | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/const.go b/const.go index 62363e6..c08e779 100644 --- a/const.go +++ b/const.go @@ -41,6 +41,7 @@ const ( oxAltBody = "This message is encrypted (XEP-0373: OpenPGP for XMPP)." pubsubPubOptions = "http://jabber.org/protocol/pubsub#publish-options" strChat = "chat" + strEmpty = "" strError = "error" strGroupchat = "groupchat" strHeadline = "headline" diff --git a/helpers.go b/helpers.go index 47f8662..b4a1abe 100644 --- a/helpers.go +++ b/helpers.go @@ -63,7 +63,7 @@ func getClientID() (string, error) { clientID = uuid.NewString() file, err := os.Create(clientIDLoc) if err != nil { - return strError, fmt.Errorf("getClientID: failed to create clientid file: %w", err) + return strEmpty, fmt.Errorf("getClientID: failed to create clientid file: %w", err) } defer file.Close() if runtime.GOOS != "windows" { @@ -73,7 +73,7 @@ func getClientID() (string, error) { } _, err = file.Write([]byte(clientID)) if err != nil { - return strError, fmt.Errorf("getClientID: failed to write client id file: %w", err) + return strEmpty, fmt.Errorf("getClientID: failed to write client id file: %w", err) } } else { clientID = buf.String() diff --git a/vendor/github.com/xmppo/go-xmpp/xmpp.go b/vendor/github.com/xmppo/go-xmpp/xmpp.go index d9d5842..e022ebf 100644 --- a/vendor/github.com/xmppo/go-xmpp/xmpp.go +++ b/vendor/github.com/xmppo/go-xmpp/xmpp.go @@ -431,7 +431,7 @@ func (c *Client) init(o *Options) error { return err } var mechanism, channelBinding, clientFirstMessage, clientFinalMessageBare, authMessage string - var bind2Data, resource, userAgentSW, userAgentDev string + var bind2Data, resource, userAgentSW, userAgentDev, userAgentID string var serverSignature, keyingMaterial []byte var scramPlus, ok, tlsConnOK, tls13, serverEndPoint, sasl2, bind2 bool var cbsSlice, mechSlice []string @@ -601,9 +601,12 @@ func (c *Client) init(o *Options) error { if o.UserAgentDev != "" { userAgentDev = fmt.Sprintf("%s", o.UserAgentDev) } + if o.UserAgentID != "" { + userAgentID = fmt.Sprintf(" id='%s'", o.UserAgentID) + } fmt.Fprintf(c.stanzaWriter, - "%s%s%s%s\n", - nsSASL2, mechanism, base64.StdEncoding.EncodeToString([]byte(clientFirstMessage)), o.UserAgentID, userAgentSW, userAgentDev, bind2Data) + "%s%s%s%s\n", + nsSASL2, mechanism, base64.StdEncoding.EncodeToString([]byte(clientFirstMessage)), userAgentID, userAgentSW, userAgentDev, bind2Data) } else { fmt.Fprintf(c.stanzaWriter, "%s\n", nsSASL, mechanism, base64.StdEncoding.EncodeToString([]byte(clientFirstMessage)))