go-sendxmpp/helpers.go

253 lines
7.1 KiB
Go
Raw Normal View History

2023-05-11 18:05:31 +00:00
// Copyright Martin Dosch.
2022-04-09 03:00:38 +00:00
// Use of this source code is governed by the BSD-2-clause
// license that can be found in the LICENSE file.
package main
import (
"bytes"
2024-04-10 13:19:50 +00:00
"crypto/aes"
"crypto/cipher"
"crypto/rand"
2024-04-10 13:19:50 +00:00
"encoding/gob"
Add support for SASL2 and BIND2 Squashed commit of the following: commit 0805b1f06a755d65f5e7ca6dd3c9279a407b8153 Author: Martin Dosch <martin@mdosch.de> Date: Tue Apr 9 10:57:29 2024 +0200 Move to upstream go-xmpp. commit 557d1052385e9ddf8454a7004b12a3ec5d3d771d Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 12:45:10 2024 +0200 Do not use sasl2 uuid attribute. commit 986aea79576fa24b37beac5a9ad4424aaadd579b Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 11:29:33 2024 +0200 Don't print error on io.EOF commit ef927ce5cc0741a441781fdbdd097d9942593186 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 11:25:40 2024 +0200 Detect stream error while receiving stanzas. commit 73b00f0612ec46ed324a08dfae35c26a1f00d3aa Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 10:00:54 2024 +0200 Use a client uuid per JID. commit b2d090a623c60b7faab18ba9b40981d3dc93b424 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 09:29:50 2024 +0200 Improve sasl2 user agent id stuff. commit c7376832ce52960e90c1b2ca7c8c82a4dc09f8ca Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 09:11:03 2024 +0200 Rework getting data path. commit 080100486e83c44eaaada991c870e2e92c3f76d5 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 08:49:49 2024 +0200 Update go-xmpp. commit 9c56a79baea2ea01e06a77282f4f53d0b0accdac Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 00:26:04 2024 +0200 SASL2: Create per client installation ID. commit cce36b070a7cff3167e076eab03dcf1a3e10f707 Author: Martin Dosch <martin@mdosch.de> Date: Sat Apr 6 22:20:35 2024 +0200 Update go-xmpp. commit 1c4acfd07c687613f5c109fc25f3b02446ddc000 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 12:04:09 2024 +0200 Update go-xmpp. commit 0703a7c2d618b586f5ba6455db5bc4351a8db33b Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 11:38:28 2024 +0200 Update go-xmpp. commit 4f033fc5b973088f160a4dd16a6cba56675010ff Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:39:30 2024 +0200 Update vendored lib. commit a44554218dc5c2b36803fc474cd740d7b13f9ef2 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:32:54 2024 +0200 Use google/uuid for message IDs. It is used for go-xmpp in the sasl2 branch anyway. commit 3e57ec3603a3d49fbd6afed66e799dba91dc0b09 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:12:50 2024 +0200 Update vendored modules. commit ead44ef99d7f92306f32a39bc6e92a7d74bdf435 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:12:25 2024 +0200 Add . between go-sendxmpp and short id. commit b3271a353010c4446af176c7eba523eb39604b6c Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 08:38:03 2024 +0200 Update Changelog. commit 639b9b6657b37052bf548bcdabf3715079dc0fb3 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 08:22:56 2024 +0200 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. commit 680593359b4b1b858a2a9150520d9a143675fb4e Author: Martin Dosch <martin@mdosch.de> Date: Thu Apr 4 23:56:15 2024 +0200 Experimental sasl2 support.
2024-04-09 08:59:00 +00:00
"errors"
2022-04-09 03:00:38 +00:00
"fmt"
"log"
"math/big"
2023-02-18 14:42:04 +00:00
"net/url"
"os"
"regexp"
"runtime"
"strings"
Add support for SASL2 and BIND2 Squashed commit of the following: commit 0805b1f06a755d65f5e7ca6dd3c9279a407b8153 Author: Martin Dosch <martin@mdosch.de> Date: Tue Apr 9 10:57:29 2024 +0200 Move to upstream go-xmpp. commit 557d1052385e9ddf8454a7004b12a3ec5d3d771d Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 12:45:10 2024 +0200 Do not use sasl2 uuid attribute. commit 986aea79576fa24b37beac5a9ad4424aaadd579b Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 11:29:33 2024 +0200 Don't print error on io.EOF commit ef927ce5cc0741a441781fdbdd097d9942593186 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 11:25:40 2024 +0200 Detect stream error while receiving stanzas. commit 73b00f0612ec46ed324a08dfae35c26a1f00d3aa Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 10:00:54 2024 +0200 Use a client uuid per JID. commit b2d090a623c60b7faab18ba9b40981d3dc93b424 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 09:29:50 2024 +0200 Improve sasl2 user agent id stuff. commit c7376832ce52960e90c1b2ca7c8c82a4dc09f8ca Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 09:11:03 2024 +0200 Rework getting data path. commit 080100486e83c44eaaada991c870e2e92c3f76d5 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 08:49:49 2024 +0200 Update go-xmpp. commit 9c56a79baea2ea01e06a77282f4f53d0b0accdac Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 00:26:04 2024 +0200 SASL2: Create per client installation ID. commit cce36b070a7cff3167e076eab03dcf1a3e10f707 Author: Martin Dosch <martin@mdosch.de> Date: Sat Apr 6 22:20:35 2024 +0200 Update go-xmpp. commit 1c4acfd07c687613f5c109fc25f3b02446ddc000 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 12:04:09 2024 +0200 Update go-xmpp. commit 0703a7c2d618b586f5ba6455db5bc4351a8db33b Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 11:38:28 2024 +0200 Update go-xmpp. commit 4f033fc5b973088f160a4dd16a6cba56675010ff Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:39:30 2024 +0200 Update vendored lib. commit a44554218dc5c2b36803fc474cd740d7b13f9ef2 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:32:54 2024 +0200 Use google/uuid for message IDs. It is used for go-xmpp in the sasl2 branch anyway. commit 3e57ec3603a3d49fbd6afed66e799dba91dc0b09 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:12:50 2024 +0200 Update vendored modules. commit ead44ef99d7f92306f32a39bc6e92a7d74bdf435 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:12:25 2024 +0200 Add . between go-sendxmpp and short id. commit b3271a353010c4446af176c7eba523eb39604b6c Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 08:38:03 2024 +0200 Update Changelog. commit 639b9b6657b37052bf548bcdabf3715079dc0fb3 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 08:22:56 2024 +0200 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. commit 680593359b4b1b858a2a9150520d9a143675fb4e Author: Martin Dosch <martin@mdosch.de> Date: Thu Apr 4 23:56:15 2024 +0200 Experimental sasl2 support.
2024-04-09 08:59:00 +00:00
2024-04-10 13:19:50 +00:00
"github.com/google/uuid" // BSD-3-Clause
"github.com/xmppo/go-xmpp" // BSD-3-Clause
"golang.org/x/crypto/scrypt" // BSD-3-Clause
2022-04-09 03:00:38 +00:00
)
func validUTF8(s string) string {
// Remove invalid code points.
s = strings.ToValidUTF8(s, "<22>")
reg := regexp.MustCompile(`[\x{0000}-\x{0008}\x{000B}\x{000C}\x{000E}-\x{001F}]`)
s = reg.ReplaceAllString(s, "<22>")
return s
}
2023-02-18 15:24:46 +00:00
func validURI(s string) (*url.URL, error) {
2023-02-18 14:42:04 +00:00
// Check if URI is valid
2023-02-18 15:24:46 +00:00
uri, err := url.ParseRequestURI(s)
2023-06-06 20:09:59 +00:00
return uri, fmt.Errorf("validURI: %w", err)
2023-02-18 14:42:04 +00:00
}
func readFile(path string) (*bytes.Buffer, error) {
file, err := os.Open(path)
if err != nil {
2023-06-06 20:09:59 +00:00
return nil, fmt.Errorf("readFile: %w", err)
}
buffer := new(bytes.Buffer)
_, err = buffer.ReadFrom(file)
if err != nil {
2023-06-06 20:09:59 +00:00
return nil, fmt.Errorf("readFile: %w", err)
}
2023-06-04 13:15:31 +00:00
err = file.Close()
if err != nil {
2023-06-06 20:09:59 +00:00
fmt.Println("error while closing file:", err)
2023-06-04 13:15:31 +00:00
}
return buffer, nil
}
2024-04-10 13:19:50 +00:00
func getFastData(jid string, password string) (xmpp.Fast, error) {
folder := strings.Replace(strings.Replace(jid, "@", "_at_", -1), ".", "_", -1)
var fast xmpp.Fast
fastPath, err := getDataPath(folder)
if err != nil {
return xmpp.Fast{}, fmt.Errorf("getFastData: failed to read fast cache folder: %w", err)
2024-04-10 13:19:50 +00:00
}
fastFileLoc := fastPath + "fast.bin"
2024-04-10 13:19:50 +00:00
buf, err := readFile(fastFileLoc)
if err != nil {
return xmpp.Fast{}, fmt.Errorf("getFastData: failed to read fast cache file: %w", err)
}
decBuf := bytes.NewBuffer(buf.Bytes())
decoder := gob.NewDecoder(decBuf)
err = decoder.Decode(&fast)
if err != nil {
return xmpp.Fast{}, fmt.Errorf("getFastData: failed to read fast cache file: %w", err)
}
salt := make([]byte, 32)
key, err := scrypt.Key([]byte(password), salt, 32768, 8, 1, 32)
if err != nil {
return xmpp.Fast{}, fmt.Errorf("getFastData: failed to create aes key: %w", err)
}
c, err := aes.NewCipher([]byte(key))
if err != nil {
return xmpp.Fast{}, fmt.Errorf("getFastData: failed to read fast cache file: %w", err)
}
gcm, err := cipher.NewGCM(c)
if err != nil {
return xmpp.Fast{}, fmt.Errorf("getFastData: failed to read fast cache file: %w", err)
}
nonceSize := gcm.NonceSize()
cryptBuf := []byte(fast.Token)
nonce, cryptBuf := cryptBuf[:nonceSize], cryptBuf[nonceSize:]
tokenBuf, err := gcm.Open(nil, []byte(nonce), cryptBuf, nil)
if err != nil {
return xmpp.Fast{}, fmt.Errorf("getFastData: failed to read fast cache file: %w", err)
}
fast.Token = string(tokenBuf)
return fast, nil
}
func writeFastData(jid string, password string, fast xmpp.Fast) error {
var encBuf bytes.Buffer
folder := strings.Replace(strings.Replace(jid, "@", "_at_", -1), ".", "_", -1)
fastPath, err := getDataPath(folder)
if err != nil {
return fmt.Errorf("writeFastData: failed to write fast cache file: %w", err)
}
fastFileLoc := fastPath + "fast.bin"
2024-04-10 13:19:50 +00:00
salt := make([]byte, 32)
key, err := scrypt.Key([]byte(password), salt, 32768, 8, 1, 32)
if err != nil {
return fmt.Errorf("writeFastData: failed to create aes cipher: %w", err)
}
c, err := aes.NewCipher(key)
if err != nil {
return fmt.Errorf("writeFastData: failed to create aes cipher: %w", err)
}
gcm, err := cipher.NewGCM(c)
if err != nil {
return fmt.Errorf("writeFastData: failed to create aes cipher: %w", err)
}
nonce := make([]byte, gcm.NonceSize())
_, err = rand.Read(nonce)
if err != nil {
return fmt.Errorf("writeFastData: failed to create aes cipher: %w", err)
}
buf := gcm.Seal(nonce, nonce, []byte(fast.Token), nil)
fast.Token = string(buf)
encode := gob.NewEncoder(&encBuf)
err = encode.Encode(fast)
if err != nil {
return fmt.Errorf("writeFastData: failed to create fast token file: %w", err)
}
file, err := os.Create(fastFileLoc)
if err != nil {
return fmt.Errorf("writeFastData: failed to create fast token file: %w", err)
}
defer file.Close()
if runtime.GOOS != "windows" {
_ = file.Chmod(os.FileMode(defaultFileRights))
} else {
_ = file.Chmod(os.FileMode(defaultFileRightsWin))
}
_, err = file.Write(encBuf.Bytes())
if err != nil {
return fmt.Errorf("writeFastData: failed to write fast token file: %w", err)
}
return nil
}
func getClientID(jid string) (string, error) {
var clientID string
folder := strings.Replace(strings.Replace(jid, "@", "_at_", -1), ".", "_", -1)
clientIDLoc, err := getClientIDLoc(folder)
if err != nil {
return strError, err
}
buf, err := readFile(clientIDLoc)
if err != nil {
clientID = uuid.NewString()
file, err := os.Create(clientIDLoc)
if err != nil {
return strEmpty, fmt.Errorf("getClientID: failed to create clientid file: %w", err)
}
defer file.Close()
if runtime.GOOS != "windows" {
_ = file.Chmod(os.FileMode(defaultFileRights))
} else {
_ = file.Chmod(os.FileMode(defaultFileRightsWin))
}
_, err = file.Write([]byte(clientID))
if err != nil {
return strEmpty, fmt.Errorf("getClientID: failed to write client id file: %w", err)
}
} else {
clientID = buf.String()
}
return clientID, nil
}
Add support for SASL2 and BIND2 Squashed commit of the following: commit 0805b1f06a755d65f5e7ca6dd3c9279a407b8153 Author: Martin Dosch <martin@mdosch.de> Date: Tue Apr 9 10:57:29 2024 +0200 Move to upstream go-xmpp. commit 557d1052385e9ddf8454a7004b12a3ec5d3d771d Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 12:45:10 2024 +0200 Do not use sasl2 uuid attribute. commit 986aea79576fa24b37beac5a9ad4424aaadd579b Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 11:29:33 2024 +0200 Don't print error on io.EOF commit ef927ce5cc0741a441781fdbdd097d9942593186 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 11:25:40 2024 +0200 Detect stream error while receiving stanzas. commit 73b00f0612ec46ed324a08dfae35c26a1f00d3aa Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 10:00:54 2024 +0200 Use a client uuid per JID. commit b2d090a623c60b7faab18ba9b40981d3dc93b424 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 09:29:50 2024 +0200 Improve sasl2 user agent id stuff. commit c7376832ce52960e90c1b2ca7c8c82a4dc09f8ca Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 09:11:03 2024 +0200 Rework getting data path. commit 080100486e83c44eaaada991c870e2e92c3f76d5 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 08:49:49 2024 +0200 Update go-xmpp. commit 9c56a79baea2ea01e06a77282f4f53d0b0accdac Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 00:26:04 2024 +0200 SASL2: Create per client installation ID. commit cce36b070a7cff3167e076eab03dcf1a3e10f707 Author: Martin Dosch <martin@mdosch.de> Date: Sat Apr 6 22:20:35 2024 +0200 Update go-xmpp. commit 1c4acfd07c687613f5c109fc25f3b02446ddc000 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 12:04:09 2024 +0200 Update go-xmpp. commit 0703a7c2d618b586f5ba6455db5bc4351a8db33b Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 11:38:28 2024 +0200 Update go-xmpp. commit 4f033fc5b973088f160a4dd16a6cba56675010ff Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:39:30 2024 +0200 Update vendored lib. commit a44554218dc5c2b36803fc474cd740d7b13f9ef2 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:32:54 2024 +0200 Use google/uuid for message IDs. It is used for go-xmpp in the sasl2 branch anyway. commit 3e57ec3603a3d49fbd6afed66e799dba91dc0b09 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:12:50 2024 +0200 Update vendored modules. commit ead44ef99d7f92306f32a39bc6e92a7d74bdf435 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:12:25 2024 +0200 Add . between go-sendxmpp and short id. commit b3271a353010c4446af176c7eba523eb39604b6c Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 08:38:03 2024 +0200 Update Changelog. commit 639b9b6657b37052bf548bcdabf3715079dc0fb3 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 08:22:56 2024 +0200 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. commit 680593359b4b1b858a2a9150520d9a143675fb4e Author: Martin Dosch <martin@mdosch.de> Date: Thu Apr 4 23:56:15 2024 +0200 Experimental sasl2 support.
2024-04-09 08:59:00 +00:00
func getDataPath(folder string) (string, error) {
var err error
var homeDir, dataDir string
switch {
case os.Getenv("$XDG_DATA_HOME") != "":
dataDir = os.Getenv("$XDG_DATA_HOME")
case os.Getenv("$XDG_HOME") != "":
homeDir = os.Getenv("$XDG_HOME")
dataDir = homeDir + "/.local/share"
case os.Getenv("$HOME") != "":
homeDir = os.Getenv("$HOME")
dataDir = homeDir + "/.local/share"
default:
homeDir, err = os.UserHomeDir()
if err != nil {
return strError, fmt.Errorf("getDataPath: failed to determine user dir: %w", err)
}
if homeDir == "" {
return strError, errors.New("getDataPath: received empty string for home directory")
}
dataDir = homeDir + "/.local/share"
}
if folder != "" && !strings.HasSuffix(folder, "/") {
folder = fmt.Sprintf("%s/", folder)
}
dataDir = fmt.Sprintf("%s/go-sendxmpp/%s", dataDir, folder)
if _, err = os.Stat(dataDir); os.IsNotExist(err) {
err = os.MkdirAll(dataDir, defaultDirRights)
if err != nil {
return strError, fmt.Errorf("getDataPath: could not create folder: %w", err)
}
}
return dataDir, nil
}
func getClientIDLoc(folder string) (string, error) {
dataDir, err := getDataPath(folder)
if err != nil {
return strError, fmt.Errorf("getClientIDLoc: %w", err)
}
dataFile := dataDir + "clientid"
return dataFile, nil
}
func getRpad(messageLength int) string {
rpadRunes := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
length := defaultRpadMultiple - messageLength%defaultRpadMultiple
max := big.NewInt(int64(len(rpadRunes)))
rpad := make([]rune, length)
for i := range rpad {
randInt, err := rand.Int(rand.Reader, max)
if err != nil {
log.Fatal(err)
}
rpad[i] = rpadRunes[randInt.Int64()]
}
return string(rpad)
}
2022-04-09 03:00:38 +00:00
func getID() string {
Add support for SASL2 and BIND2 Squashed commit of the following: commit 0805b1f06a755d65f5e7ca6dd3c9279a407b8153 Author: Martin Dosch <martin@mdosch.de> Date: Tue Apr 9 10:57:29 2024 +0200 Move to upstream go-xmpp. commit 557d1052385e9ddf8454a7004b12a3ec5d3d771d Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 12:45:10 2024 +0200 Do not use sasl2 uuid attribute. commit 986aea79576fa24b37beac5a9ad4424aaadd579b Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 11:29:33 2024 +0200 Don't print error on io.EOF commit ef927ce5cc0741a441781fdbdd097d9942593186 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 11:25:40 2024 +0200 Detect stream error while receiving stanzas. commit 73b00f0612ec46ed324a08dfae35c26a1f00d3aa Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 10:00:54 2024 +0200 Use a client uuid per JID. commit b2d090a623c60b7faab18ba9b40981d3dc93b424 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 09:29:50 2024 +0200 Improve sasl2 user agent id stuff. commit c7376832ce52960e90c1b2ca7c8c82a4dc09f8ca Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 09:11:03 2024 +0200 Rework getting data path. commit 080100486e83c44eaaada991c870e2e92c3f76d5 Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 08:49:49 2024 +0200 Update go-xmpp. commit 9c56a79baea2ea01e06a77282f4f53d0b0accdac Author: Martin Dosch <martin@mdosch.de> Date: Sun Apr 7 00:26:04 2024 +0200 SASL2: Create per client installation ID. commit cce36b070a7cff3167e076eab03dcf1a3e10f707 Author: Martin Dosch <martin@mdosch.de> Date: Sat Apr 6 22:20:35 2024 +0200 Update go-xmpp. commit 1c4acfd07c687613f5c109fc25f3b02446ddc000 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 12:04:09 2024 +0200 Update go-xmpp. commit 0703a7c2d618b586f5ba6455db5bc4351a8db33b Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 11:38:28 2024 +0200 Update go-xmpp. commit 4f033fc5b973088f160a4dd16a6cba56675010ff Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:39:30 2024 +0200 Update vendored lib. commit a44554218dc5c2b36803fc474cd740d7b13f9ef2 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:32:54 2024 +0200 Use google/uuid for message IDs. It is used for go-xmpp in the sasl2 branch anyway. commit 3e57ec3603a3d49fbd6afed66e799dba91dc0b09 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:12:50 2024 +0200 Update vendored modules. commit ead44ef99d7f92306f32a39bc6e92a7d74bdf435 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 09:12:25 2024 +0200 Add . between go-sendxmpp and short id. commit b3271a353010c4446af176c7eba523eb39604b6c Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 08:38:03 2024 +0200 Update Changelog. commit 639b9b6657b37052bf548bcdabf3715079dc0fb3 Author: Martin Dosch <martin@mdosch.de> Date: Fri Apr 5 08:22:56 2024 +0200 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. commit 680593359b4b1b858a2a9150520d9a143675fb4e Author: Martin Dosch <martin@mdosch.de> Date: Thu Apr 4 23:56:15 2024 +0200 Experimental sasl2 support.
2024-04-09 08:59:00 +00:00
return uuid.NewString()
2022-04-09 03:00:38 +00:00
}
func getShortID() string {
id := make([]byte, defaultShortIDBytes)
2022-05-02 14:13:00 +00:00
_, err := rand.Read(id)
if err != nil {
log.Fatal(err)
}
2022-05-02 14:13:00 +00:00
return fmt.Sprintf("%x", id[0:4])
}