Add short ID back to resource string.

That's still necessary to avoid two instances with the same resource
when using SASL instead of SASL2.
sasl2
Martin Dosch 2 months ago
parent 680593359b
commit 639b9b6657
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D

@ -9,7 +9,7 @@ require (
github.com/beevik/etree v1.3.0
github.com/gabriel-vasile/mimetype v1.4.3
github.com/pborman/getopt/v2 v2.1.0
github.com/xmppo/go-xmpp v0.1.5-0.20240404090514-0324b31f56ee
github.com/xmppo/go-xmpp v0.1.5
salsa.debian.org/mdosch/xmppsrv v0.2.6
)

@ -288,7 +288,7 @@ func main() {
Host: server,
User: user,
DialTimeout: timeout,
Resource: "go-sendxmpp",
Resource: "go-sendxmpp" + getShortID(),
Password: password,
// NoTLS doesn't mean that no TLS is used at all but that instead
// of using an encrypted connection to the server (direct TLS)
@ -296,12 +296,12 @@ func main() {
// set when NoTLS is set go-sendxmpp won't use unencrypted
// client-to-server connections.
// See https://pkg.go.dev/github.com/xmppo/go-xmpp#Options
NoTLS: !*flagDirectTLS,
StartTLS: !*flagDirectTLS,
Debug: *flagDebug,
TLSConfig: &tlsConfig,
Mechanism: *flagSCRAMPinning,
SSDP: !*flagSSDPOff,
NoTLS: !*flagDirectTLS,
StartTLS: !*flagDirectTLS,
Debug: *flagDebug,
TLSConfig: &tlsConfig,
Mechanism: *flagSCRAMPinning,
SSDP: !*flagSSDPOff,
UserAgentSW: "go-sendxmpp",
}

@ -23,7 +23,6 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/base64"
"encoding/binary"
"encoding/xml"
"errors"
"fmt"
@ -68,14 +67,6 @@ var DebugWriter io.Writer = os.Stderr
// Cookie is a unique XMPP session identifier
type Cookie uint64
func getCookie() Cookie {
var buf [8]byte
if _, err := rand.Reader.Read(buf[:]); err != nil {
panic("Failed to read random bytes: " + err.Error())
}
return Cookie(binary.LittleEndian.Uint64(buf[:]))
}
// Client holds XMPP connection options
type Client struct {
conn net.Conn // connection to server
@ -584,7 +575,7 @@ func (c *Client) init(o *Options) error {
if o.Resource != "" {
resource = o.Resource
} else {
resource = fmt.Sprint(getCookie())
resource = uuid.NewString()
}
bind2Data = fmt.Sprintf("<bind xmlns='%s'><tag>%s</tag></bind>",
nsBind2, resource)
@ -885,7 +876,7 @@ func (c *Client) init(o *Options) error {
if !bind2 {
// Generate a unique cookie
cookie := getCookie()
cookie := uuid.New()
// Send IQ message asking to bind to the local user name.
if o.Resource == "" {
@ -917,7 +908,7 @@ func (c *Client) init(o *Options) error {
}
if o.Session {
// if server support session, open it
cookie := getCookie() // generate new id value for session
cookie := uuid.New() // generate new id value for session
fmt.Fprintf(c.stanzaWriter, "<iq to='%s' type='set' id='%x'><session xmlns='%s'/></iq>\n", xmlEscape(domain), cookie, nsSession)
}

@ -2,7 +2,8 @@ package xmpp
import (
"fmt"
"strconv"
"github.com/google/uuid"
)
const (
@ -12,8 +13,8 @@ const (
)
func (c *Client) Discovery() (string, error) {
// use getCookie for a pseudo random id.
reqID := strconv.FormatUint(uint64(getCookie()), 10)
// use UUIDv4 for a pseudo random id.
reqID := uuid.NewString()
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, XMPPNS_DISCO_ITEMS, "")
}

@ -60,7 +60,7 @@ github.com/pborman/getopt/v2
# github.com/pkg/errors v0.9.1
## explicit
github.com/pkg/errors
# github.com/xmppo/go-xmpp v0.1.5-0.20240404090514-0324b31f56ee => /home/martin/build/go-xmpp
# github.com/xmppo/go-xmpp v0.1.5 => /home/martin/build/go-xmpp
## explicit; go 1.21.5
github.com/xmppo/go-xmpp
# golang.org/x/crypto v0.22.0

Loading…
Cancel
Save