summaryrefslogtreecommitdiffstats
path: root/vendor/go.mau.fi/whatsmeow/pair.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2023-01-28 22:57:53 +0100
committerGitHub <noreply@github.com>2023-01-28 22:57:53 +0100
commit880586bac42817ffcfea5d9f746f503fa29915b8 (patch)
treea89374cba6f88975f12316ec8d1b8aa1d4c6ba79 /vendor/go.mau.fi/whatsmeow/pair.go
parenteac2a8c8dc831f946970d327e2a80b26b0684255 (diff)
downloadmatterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.tar.gz
matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.tar.bz2
matterbridge-msglm-880586bac42817ffcfea5d9f746f503fa29915b8.zip
Update dependencies (#1951)
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/pair.go')
-rw-r--r--vendor/go.mau.fi/whatsmeow/pair.go50
1 files changed, 27 insertions, 23 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/pair.go b/vendor/go.mau.fi/whatsmeow/pair.go
index 41dfa086..573b0387 100644
--- a/vendor/go.mau.fi/whatsmeow/pair.go
+++ b/vendor/go.mau.fi/whatsmeow/pair.go
@@ -13,11 +13,9 @@ import (
"encoding/base64"
"fmt"
"strings"
- "time"
-
- "google.golang.org/protobuf/proto"
"go.mau.fi/libsignal/ecc"
+ "google.golang.org/protobuf/proto"
waBinary "go.mau.fi/whatsmeow/binary"
waProto "go.mau.fi/whatsmeow/binary/proto"
@@ -26,8 +24,6 @@ import (
"go.mau.fi/whatsmeow/util/keys"
)
-const qrScanTimeout = 30 * time.Second
-
func (cli *Client) handleIQ(node *waBinary.Node) {
children := node.GetChildren()
if len(children) != 1 || node.Attrs["from"] != types.ServerJID {
@@ -105,28 +101,28 @@ func (cli *Client) handlePair(deviceIdentityBytes []byte, reqID, businessName, p
var deviceIdentityContainer waProto.ADVSignedDeviceIdentityHMAC
err := proto.Unmarshal(deviceIdentityBytes, &deviceIdentityContainer)
if err != nil {
- cli.sendIQError(reqID, 500, "internal-error")
- return fmt.Errorf("failed to parse device identity container in pair success message: %w", err)
+ cli.sendPairError(reqID, 500, "internal-error")
+ return &PairProtoError{"failed to parse device identity container in pair success message", err}
}
h := hmac.New(sha256.New, cli.Store.AdvSecretKey)
h.Write(deviceIdentityContainer.Details)
if !bytes.Equal(h.Sum(nil), deviceIdentityContainer.Hmac) {
cli.Log.Warnf("Invalid HMAC from pair success message")
- cli.sendIQError(reqID, 401, "not-authorized")
- return fmt.Errorf("invalid device identity HMAC in pair success message")
+ cli.sendPairError(reqID, 401, "not-authorized")
+ return ErrPairInvalidDeviceIdentityHMAC
}
var deviceIdentity waProto.ADVSignedDeviceIdentity
err = proto.Unmarshal(deviceIdentityContainer.Details, &deviceIdentity)
if err != nil {
- cli.sendIQError(reqID, 500, "internal-error")
- return fmt.Errorf("failed to parse signed device identity in pair success message: %w", err)
+ cli.sendPairError(reqID, 500, "internal-error")
+ return &PairProtoError{"failed to parse signed device identity in pair success message", err}
}
if !verifyDeviceIdentityAccountSignature(&deviceIdentity, cli.Store.IdentityKey) {
- cli.sendIQError(reqID, 401, "not-authorized")
- return fmt.Errorf("invalid device signature in pair success message")
+ cli.sendPairError(reqID, 401, "not-authorized")
+ return ErrPairInvalidDeviceSignature
}
deviceIdentity.DeviceSignature = generateDeviceSignature(&deviceIdentity, cli.Store.IdentityKey)[:]
@@ -134,8 +130,13 @@ func (cli *Client) handlePair(deviceIdentityBytes []byte, reqID, businessName, p
var deviceIdentityDetails waProto.ADVDeviceIdentity
err = proto.Unmarshal(deviceIdentity.Details, &deviceIdentityDetails)
if err != nil {
- cli.sendIQError(reqID, 500, "internal-error")
- return fmt.Errorf("failed to parse device identity details in pair success message: %w", err)
+ cli.sendPairError(reqID, 500, "internal-error")
+ return &PairProtoError{"failed to parse device identity details in pair success message", err}
+ }
+
+ if cli.PrePairCallback != nil && !cli.PrePairCallback(jid, platform, businessName) {
+ cli.sendPairError(reqID, 500, "internal-error")
+ return ErrPairRejectedLocally
}
cli.Store.Account = proto.Clone(&deviceIdentity).(*waProto.ADVSignedDeviceIdentity)
@@ -147,8 +148,8 @@ func (cli *Client) handlePair(deviceIdentityBytes []byte, reqID, businessName, p
selfSignedDeviceIdentity, err := proto.Marshal(&deviceIdentity)
if err != nil {
- cli.sendIQError(reqID, 500, "internal-error")
- return fmt.Errorf("failed to marshal self-signed device identity: %w", err)
+ cli.sendPairError(reqID, 500, "internal-error")
+ return &PairProtoError{"failed to marshal self-signed device identity", err}
}
cli.Store.ID = &jid
@@ -156,14 +157,14 @@ func (cli *Client) handlePair(deviceIdentityBytes []byte, reqID, businessName, p
cli.Store.Platform = platform
err = cli.Store.Save()
if err != nil {
- cli.sendIQError(reqID, 500, "internal-error")
- return fmt.Errorf("failed to save device store: %w", err)
+ cli.sendPairError(reqID, 500, "internal-error")
+ return &PairDatabaseError{"failed to save device store", err}
}
err = cli.Store.Identities.PutIdentity(mainDeviceJID.SignalAddress().String(), mainDeviceIdentity)
if err != nil {
_ = cli.Store.Delete()
- cli.sendIQError(reqID, 500, "internal-error")
- return fmt.Errorf("failed to store main device identity: %w", err)
+ cli.sendPairError(reqID, 500, "internal-error")
+ return &PairDatabaseError{"failed to store main device identity", err}
}
// Expect a disconnect after this and don't dispatch the usual Disconnected event
@@ -225,8 +226,8 @@ func generateDeviceSignature(deviceIdentity *waProto.ADVSignedDeviceIdentity, ik
return &sig
}
-func (cli *Client) sendIQError(id string, code int, text string) waBinary.Node {
- return waBinary.Node{
+func (cli *Client) sendPairError(id string, code int, text string) {
+ err := cli.sendNode(waBinary.Node{
Tag: "iq",
Attrs: waBinary.Attrs{
"to": types.ServerJID,
@@ -240,5 +241,8 @@ func (cli *Client) sendIQError(id string, code int, text string) waBinary.Node {
"text": text,
},
}},
+ })
+ if err != nil {
+ cli.Log.Errorf("Failed to send pair error node: %v", err)
}
}