client: generate curve25519 key for push

This commit is contained in:
Tulir Asokan 2025-03-11 18:43:51 +02:00
parent 5b1effcd51
commit 7319d429d7
2 changed files with 9 additions and 5 deletions

View file

@ -25,13 +25,13 @@ import (
"time" "time"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"go.mau.fi/util/random"
"go.mau.fi/whatsmeow" "go.mau.fi/whatsmeow"
waBinary "go.mau.fi/whatsmeow/binary" waBinary "go.mau.fi/whatsmeow/binary"
"go.mau.fi/whatsmeow/proto/waHistorySync" "go.mau.fi/whatsmeow/proto/waHistorySync"
"go.mau.fi/whatsmeow/proto/waWa6" "go.mau.fi/whatsmeow/proto/waWa6"
"go.mau.fi/whatsmeow/store" "go.mau.fi/whatsmeow/store"
"go.mau.fi/whatsmeow/types" "go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/util/keys"
waLog "go.mau.fi/whatsmeow/util/log" waLog "go.mau.fi/whatsmeow/util/log"
"golang.org/x/sync/semaphore" "golang.org/x/sync/semaphore"
"maunium.net/go/mautrix/bridge/status" "maunium.net/go/mautrix/bridge/status"
@ -150,14 +150,17 @@ func (wa *WhatsAppClient) RegisterPushNotifications(ctx context.Context, pushTyp
} }
case bridgev2.PushTypeAPNs: case bridgev2.PushTypeAPNs:
meta := wa.UserLogin.Metadata.(*waid.UserLoginMetadata) meta := wa.UserLogin.Metadata.(*waid.UserLoginMetadata)
if meta.APNSEncKey == nil { if meta.APNSEncPubKey == nil {
meta.APNSEncKey = random.Bytes(32) k := keys.NewKeyPair()
meta.APNSEncPubKey = k.Pub[:]
meta.APNSEncPrivKey = k.Priv[:]
err := wa.UserLogin.Save(ctx) err := wa.UserLogin.Save(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to save push enc key: %w", err) return fmt.Errorf("failed to save push enc key: %w", err)
} }
} }
pc = &whatsmeow.APNsPushConfig{Token: token, MsgIDEncKey: meta.APNSEncKey} // TODO figure out if the key is supposed to be aes or curve25519
pc = &whatsmeow.APNsPushConfig{Token: token, MsgIDEncKey: meta.APNSEncPubKey}
default: default:
return fmt.Errorf("unsupported push type %s", pushType) return fmt.Errorf("unsupported push type %s", pushType)
} }

View file

@ -33,7 +33,8 @@ type UserLoginMetadata struct {
PhoneLastPinged jsontime.Unix `json:"phone_last_pinged"` PhoneLastPinged jsontime.Unix `json:"phone_last_pinged"`
Timezone string `json:"timezone"` Timezone string `json:"timezone"`
PushKeys *PushKeys `json:"push_keys,omitempty"` PushKeys *PushKeys `json:"push_keys,omitempty"`
APNSEncKey []byte `json:"apns_enc_key,omitempty"` APNSEncPubKey []byte `json:"apns_enc_pubkey,omitempty"`
APNSEncPrivKey []byte `json:"apns_enc_privkey,omitempty"`
HistorySyncPortalsNeedCreating bool `json:"history_sync_portals_need_creating,omitempty"` HistorySyncPortalsNeedCreating bool `json:"history_sync_portals_need_creating,omitempty"`
} }