client: ignore connect success before pairing is completed

This commit is contained in:
Tulir Asokan
2026-06-22 21:54:15 +03:00
parent c50f490413
commit 5f04eac6db
4 changed files with 9 additions and 0 deletions
+2
View File
@@ -70,6 +70,7 @@ type Client struct {
socketWait chan struct{}
isLoggedIn atomic.Bool
paired atomic.Bool
expectedDisconnect *exsync.Event
forceAutoReconnect atomic.Bool
EnableAutoReconnect bool
@@ -282,6 +283,7 @@ func NewClient(deviceStore *store.Device, log waLog.Logger) *Client {
BackgroundEventCtx: context.Background(),
}
cli.paired.Store(deviceStore.ID != nil)
cli.nodeHandlers = map[string]nodeHandler{
"message": cli.handleEncryptedMessage,
"appdata": cli.handleEncryptedMessage,
+4
View File
@@ -156,6 +156,10 @@ func (cli *Client) handleConnectFailure(ctx context.Context, node *waBinary.Node
}
func (cli *Client) handleConnectSuccess(ctx context.Context, node *waBinary.Node) {
if !cli.paired.Load() {
cli.Log.Warnf("Received connect success without pairing, ignoring")
return
}
cli.Log.Infof("Successfully authenticated")
cli.LastSuccessfulConnect = time.Now()
cli.AutoReconnectErrors = 0
+1
View File
@@ -161,6 +161,7 @@ func (cli *Client) handleCodePairNotification(ctx context.Context, parentNode *w
if linkCache == nil {
return fmt.Errorf("received code pair notification without a pending pairing")
}
cli.paired.Store(false)
linkCodePairingRef, _ := node.GetChildByTag("link_code_pairing_ref").Content.([]byte)
if string(linkCodePairingRef) != linkCache.pairingRef {
return fmt.Errorf("pairing ref mismatch in code pair notification")
+2
View File
@@ -49,6 +49,7 @@ func (cli *Client) handleIQ(ctx context.Context, node *waBinary.Node) {
}
func (cli *Client) handlePairDevice(ctx context.Context, node *waBinary.Node) {
cli.paired.Store(false)
pairDevice := node.GetChildByTag("pair-device")
err := cli.sendNode(ctx, waBinary.Node{
Tag: "iq",
@@ -222,6 +223,7 @@ func (cli *Client) handlePair(ctx context.Context, deviceIdentityBytes []byte, r
// Expect a disconnect after this and don't dispatch the usual Disconnected event
cli.expectDisconnect()
cli.paired.Store(true)
err = cli.sendNode(ctx, waBinary.Node{
Tag: "iq",