Improve sasl2 user agent id stuff.

This commit is contained in:
Martin Dosch 2024-04-07 09:29:50 +02:00
parent c7376832ce
commit b2d090a623
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D
3 changed files with 9 additions and 5 deletions

View File

@ -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"

View File

@ -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()

View File

@ -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("<device>%s</device>", o.UserAgentDev)
}
if o.UserAgentID != "" {
userAgentID = fmt.Sprintf(" id='%s'", o.UserAgentID)
}
fmt.Fprintf(c.stanzaWriter,
"<authenticate xmlns='%s' mechanism='%s'><initial-response>%s</initial-response><user-agent id='%s'>%s%s</user-agent>%s</authenticate>\n",
nsSASL2, mechanism, base64.StdEncoding.EncodeToString([]byte(clientFirstMessage)), o.UserAgentID, userAgentSW, userAgentDev, bind2Data)
"<authenticate xmlns='%s' mechanism='%s'><initial-response>%s</initial-response><user-agent%s>%s%s</user-agent>%s</authenticate>\n",
nsSASL2, mechanism, base64.StdEncoding.EncodeToString([]byte(clientFirstMessage)), userAgentID, userAgentSW, userAgentDev, bind2Data)
} else {
fmt.Fprintf(c.stanzaWriter, "<auth xmlns='%s' mechanism='%s'>%s</auth>\n",
nsSASL, mechanism, base64.StdEncoding.EncodeToString([]byte(clientFirstMessage)))