summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/whatsmeow/store/sqlstore
diff options
context:
space:
mode:
authorWim <wim@42.be>2022-06-11 23:07:42 +0200
committerGitHub <noreply@github.com>2022-06-11 23:07:42 +0200
commit8751fb4bb1eb7cd34ed63be9b3801b8aeac71a1d (patch)
tree601d2616b05b5b197bd2a3ae7cb245b1a0ea17e7 /vendor/go.mau.fi/whatsmeow/store/sqlstore
parent3819062574ac7e4af6a562bf40a425469a7752fb (diff)
downloadmatterbridge-msglm-8751fb4bb1eb7cd34ed63be9b3801b8aeac71a1d.tar.gz
matterbridge-msglm-8751fb4bb1eb7cd34ed63be9b3801b8aeac71a1d.tar.bz2
matterbridge-msglm-8751fb4bb1eb7cd34ed63be9b3801b8aeac71a1d.zip
Update dependencies (#1841)
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/store/sqlstore')
-rw-r--r--vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go10
-rw-r--r--vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go36
2 files changed, 40 insertions, 6 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go b/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go
index 3150cfec..b7c0a7c4 100644
--- a/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go
+++ b/vendor/go.mau.fi/whatsmeow/store/sqlstore/container.go
@@ -78,7 +78,7 @@ func NewWithDB(db *sql.DB, dialect string, log waLog.Logger) *Container {
const getAllDevicesQuery = `
SELECT jid, registration_id, noise_key, identity_key,
signed_pre_key, signed_pre_key_id, signed_pre_key_sig,
- adv_key, adv_details, adv_account_sig, adv_device_sig,
+ adv_key, adv_details, adv_account_sig, adv_account_sig_key, adv_device_sig,
platform, business_name, push_name
FROM whatsmeow_device
`
@@ -100,7 +100,7 @@ func (c *Container) scanDevice(row scannable) (*store.Device, error) {
err := row.Scan(
&device.ID, &device.RegistrationID, &noisePriv, &identityPriv,
&preKeyPriv, &device.SignedPreKey.KeyID, &preKeySig,
- &device.AdvSecretKey, &account.Details, &account.AccountSignature, &account.DeviceSignature,
+ &device.AdvSecretKey, &account.Details, &account.AccountSignature, &account.AccountSignatureKey, &account.DeviceSignature,
&device.Platform, &device.BusinessName, &device.PushName)
if err != nil {
return nil, fmt.Errorf("failed to scan session: %w", err)
@@ -178,9 +178,9 @@ const (
insertDeviceQuery = `
INSERT INTO whatsmeow_device (jid, registration_id, noise_key, identity_key,
signed_pre_key, signed_pre_key_id, signed_pre_key_sig,
- adv_key, adv_details, adv_account_sig, adv_device_sig,
+ adv_key, adv_details, adv_account_sig, adv_account_sig_key, adv_device_sig,
platform, business_name, push_name)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
ON CONFLICT (jid) DO UPDATE SET platform=$12, business_name=$13, push_name=$14
`
deleteDeviceQuery = `DELETE FROM whatsmeow_device WHERE jid=$1`
@@ -222,7 +222,7 @@ func (c *Container) PutDevice(device *store.Device) error {
_, err := c.db.Exec(insertDeviceQuery,
device.ID.String(), device.RegistrationID, device.NoiseKey.Priv[:], device.IdentityKey.Priv[:],
device.SignedPreKey.Priv[:], device.SignedPreKey.KeyID, device.SignedPreKey.Signature[:],
- device.AdvSecretKey, device.Account.Details, device.Account.AccountSignature, device.Account.DeviceSignature,
+ device.AdvSecretKey, device.Account.Details, device.Account.AccountSignature, device.Account.AccountSignatureKey, device.Account.DeviceSignature,
device.Platform, device.BusinessName, device.PushName)
if !device.Initialized {
diff --git a/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go b/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go
index b98f2d61..37bd7c29 100644
--- a/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go
+++ b/vendor/go.mau.fi/whatsmeow/store/sqlstore/upgrade.go
@@ -16,7 +16,7 @@ type upgradeFunc func(*sql.Tx, *Container) error
//
// This may be of use if you want to manage the database fully manually, but in most cases you
// should just call Container.Upgrade to let the library handle everything.
-var Upgrades = [...]upgradeFunc{upgradeV1}
+var Upgrades = [...]upgradeFunc{upgradeV1, upgradeV2}
func (c *Container) getVersion() (int, error) {
_, err := c.db.Exec("CREATE TABLE IF NOT EXISTS whatsmeow_version (version INTEGER)")
@@ -56,6 +56,7 @@ func (c *Container) Upgrade() error {
}
migrateFunc := Upgrades[version]
+ c.log.Infof("Upgrading database to v%d", version+1)
err = migrateFunc(tx, c)
if err != nil {
_ = tx.Rollback()
@@ -212,3 +213,36 @@ func upgradeV1(tx *sql.Tx, _ *Container) error {
}
return nil
}
+
+const fillSigKeyPostgres = `
+UPDATE whatsmeow_device SET adv_account_sig_key=(
+ SELECT identity
+ FROM whatsmeow_identity_keys
+ WHERE our_jid=whatsmeow_device.jid
+ AND their_id=concat(split_part(whatsmeow_device.jid, '.', 1), ':0')
+);
+DELETE FROM whatsmeow_device WHERE adv_account_sig_key IS NULL;
+ALTER TABLE whatsmeow_device ALTER COLUMN adv_account_sig_key SET NOT NULL;
+`
+
+const fillSigKeySQLite = `
+UPDATE whatsmeow_device SET adv_account_sig_key=(
+ SELECT identity
+ FROM whatsmeow_identity_keys
+ WHERE our_jid=whatsmeow_device.jid
+ AND their_id=substr(whatsmeow_device.jid, 0, instr(whatsmeow_device.jid, '.')) || ':0'
+)
+`
+
+func upgradeV2(tx *sql.Tx, container *Container) error {
+ _, err := tx.Exec("ALTER TABLE whatsmeow_device ADD COLUMN adv_account_sig_key bytea CHECK ( length(adv_account_sig_key) = 32 )")
+ if err != nil {
+ return err
+ }
+ if container.dialect == "postgres" {
+ _, err = tx.Exec(fillSigKeyPostgres)
+ } else {
+ _, err = tx.Exec(fillSigKeySQLite)
+ }
+ return err
+}