From fe50f12ac923aa625cdc4a1d12f43e80ce3031a0 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 25 Apr 2022 15:27:40 +0400 Subject: [PATCH] fix: pubkey marshalling --- nodecfg/node_config.go | 6 +++--- params/config.go | 22 ++++++++++++++++++++-- services/ext/service.go | 7 ++++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/nodecfg/node_config.go b/nodecfg/node_config.go index e9f6b868f58..83b326704a5 100644 --- a/nodecfg/node_config.go +++ b/nodecfg/node_config.go @@ -207,8 +207,8 @@ func insertShhExtConfig(tx *sql.Tx, c *params.NodeConfig) error { return err } - for _, pubKey := range c.ShhextConfig.DefaultPushNotificationsServers { - hexpubk := hexutil.Encode(crypto.FromECDSAPub(pubKey)) + for _, pushNotifServ := range c.ShhextConfig.DefaultPushNotificationsServers { + hexpubk := hexutil.Encode(crypto.FromECDSAPub(pushNotifServ.PublicKey)) _, err := tx.Exec(`INSERT OR REPLACE INTO shhext_default_push_notification_servers (public_key, synthetic_id) VALUES (?, 'id')`, hexpubk) if err != nil { return err @@ -637,7 +637,7 @@ func loadNodeConfig(tx *sql.Tx) (*params.NodeConfig, error) { if err != nil { return nil, err } - nodecfg.ShhextConfig.DefaultPushNotificationsServers = append(nodecfg.ShhextConfig.DefaultPushNotificationsServers, pubKey) + nodecfg.ShhextConfig.DefaultPushNotificationsServers = append(nodecfg.ShhextConfig.DefaultPushNotificationsServers, ¶ms.PushNotificationServer{PublicKey: pubKey}) } } diff --git a/params/config.go b/params/config.go index 5f37c69e7b3..de2bbbaf842 100644 --- a/params/config.go +++ b/params/config.go @@ -539,6 +539,24 @@ type BridgeConfig struct { Enabled bool } +type PushNotificationServer struct { + *ecdsa.PublicKey +} + +func (p *PushNotificationServer) MarshalText() ([]byte, error) { + return []byte(hex.EncodeToString(crypto.FromECDSAPub(p.PublicKey))), nil +} + +func (p *PushNotificationServer) UnmarshalText(data []byte) error { + pk, err := crypto.UnmarshalPubkey(data) + if err != nil { + return err + } + + p.PublicKey = pk + return nil +} + // ShhextConfig defines options used by shhext service. type ShhextConfig struct { PFSEnabled bool @@ -590,7 +608,7 @@ type ShhextConfig struct { VerifyTransactionChainID int64 // DefaultPushNotificationsServers is the default-status run push notification servers - DefaultPushNotificationsServers []*ecdsa.PublicKey + DefaultPushNotificationsServers []*PushNotificationServer // AnonMetricsSendID is the public key used by a metrics node to decrypt metrics protobufs AnonMetricsSendID string @@ -722,7 +740,7 @@ func (c *NodeConfig) setDefaultPushNotificationsServers() error { if err != nil { return err } - c.ShhextConfig.DefaultPushNotificationsServers = append(c.ShhextConfig.DefaultPushNotificationsServers, key) + c.ShhextConfig.DefaultPushNotificationsServers = append(c.ShhextConfig.DefaultPushNotificationsServers, &PushNotificationServer{PublicKey: key}) } } return nil diff --git a/services/ext/service.go b/services/ext/service.go index e05126bbe5a..55dfc945c15 100644 --- a/services/ext/service.go +++ b/services/ext/service.go @@ -464,8 +464,13 @@ func buildMessengerOptions( options = append(options, protocol.WithPushNotificationServerConfig(config)) } + var pushNotifServKey []*ecdsa.PublicKey + for _, d := range config.ShhextConfig.DefaultPushNotificationsServers { + pushNotifServKey = append(pushNotifServKey, d.PublicKey) + } + options = append(options, protocol.WithPushNotificationClientConfig(&pushnotificationclient.Config{ - DefaultServers: config.ShhextConfig.DefaultPushNotificationsServers, + DefaultServers: pushNotifServKey, BlockMentions: settings.PushNotificationsBlockMentions, SendEnabled: settings.SendPushNotifications, AllowFromContactsOnly: settings.PushNotificationsFromContactsOnly,