Polish up and address review feedback
This commit is contained in:
parent
63af6aa79b
commit
4b8739a8bc
|
@ -12,7 +12,7 @@
|
|||
// 0005_waku_mode.up.sql (146B)
|
||||
// 0006_appearance.up.sql (67B)
|
||||
// 0007_enable_waku_default.up.sql (38B)
|
||||
// 0008_add_push_notifications.up.sql (294B)
|
||||
// 0008_add_push_notifications.up.sql (349B)
|
||||
// doc.go (74B)
|
||||
|
||||
package migrations
|
||||
|
@ -217,7 +217,7 @@ func _0004_pending_stickersDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0004_pending_stickers.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1584434371, 0)}
|
||||
info := bindataFileInfo{name: "0004_pending_stickers.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ func _0004_pending_stickersUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0004_pending_stickers.up.sql", size: 61, mode: os.FileMode(0644), modTime: time.Unix(1584434371, 0)}
|
||||
info := bindataFileInfo{name: "0004_pending_stickers.up.sql", size: 61, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x3c, 0xed, 0x25, 0xdf, 0x75, 0x2, 0x6c, 0xf0, 0xa2, 0xa8, 0x37, 0x62, 0x65, 0xad, 0xfd, 0x98, 0xa0, 0x9d, 0x63, 0x94, 0xdf, 0x6b, 0x46, 0xe0, 0x68, 0xec, 0x9c, 0x7f, 0x77, 0xdd, 0xb3, 0x6}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ func _0005_waku_modeDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0005_waku_mode.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1584434371, 0)}
|
||||
info := bindataFileInfo{name: "0005_waku_mode.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ func _0005_waku_modeUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0005_waku_mode.up.sql", size: 146, mode: os.FileMode(0644), modTime: time.Unix(1584434371, 0)}
|
||||
info := bindataFileInfo{name: "0005_waku_mode.up.sql", size: 146, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa6, 0x91, 0xc, 0xd7, 0x89, 0x61, 0x2e, 0x4c, 0x5a, 0xb6, 0x67, 0xd1, 0xc1, 0x42, 0x24, 0x38, 0xd6, 0x1b, 0x75, 0x41, 0x9c, 0x23, 0xb0, 0xca, 0x5c, 0xf1, 0x5c, 0xd0, 0x13, 0x92, 0x3e, 0xe1}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ func _0006_appearanceUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0006_appearance.up.sql", size: 67, mode: os.FileMode(0644), modTime: time.Unix(1585895847, 0)}
|
||||
info := bindataFileInfo{name: "0006_appearance.up.sql", size: 67, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xae, 0x6, 0x25, 0x6c, 0xe4, 0x9d, 0xa7, 0x72, 0xe8, 0xbc, 0xe4, 0x1f, 0x1e, 0x2d, 0x7c, 0xb7, 0xf6, 0xa3, 0xec, 0x3b, 0x4e, 0x93, 0x2e, 0xa4, 0xec, 0x6f, 0xe5, 0x95, 0x94, 0xe8, 0x4, 0xfb}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -317,12 +317,12 @@ func _0007_enable_waku_defaultUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0007_enable_waku_default.up.sql", size: 38, mode: os.FileMode(0644), modTime: time.Unix(1585895900, 0)}
|
||||
info := bindataFileInfo{name: "0007_enable_waku_default.up.sql", size: 38, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd4, 0x42, 0xb6, 0xe5, 0x48, 0x41, 0xeb, 0xc0, 0x7e, 0x3b, 0xe6, 0x8e, 0x96, 0x33, 0x20, 0x92, 0x24, 0x5a, 0x60, 0xfa, 0xa0, 0x3, 0x5e, 0x76, 0x4b, 0x89, 0xaa, 0x37, 0x66, 0xbc, 0x26, 0x11}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __0008_add_push_notificationsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\xce\xc1\x0a\xc2\x30\x0c\x00\xd0\xbb\x5f\x91\xff\xf0\xd4\xb9\xde\xea\x0a\x32\xcf\xa1\x76\x99\x16\xd6\x44\x9a\x28\xf8\xf7\x1e\xbd\x14\xd4\x1f\x78\x3c\x17\x66\x7f\x82\xd9\x0d\xc1\x83\x92\x59\xe1\xab\x82\x1b\x47\x38\xc4\x70\x3e\x4e\xd0\xa8\x8a\x11\xde\x1f\x7a\x43\x16\x2b\x6b\xc9\xc9\x8a\xb0\x22\x71\xba\x6c\xb4\xc0\x10\x63\xf0\x6e\xda\xef\xbe\x51\x4a\xbc\x74\xa0\xdf\x81\x4e\x42\xa9\x3d\xa9\xfd\x7f\xe9\x50\x6b\x93\x8a\x59\xd8\x52\x36\x45\xe1\xed\xf5\xe1\xde\x01\x00\x00\xff\xff\x16\x96\xb2\xb5\x26\x01\x00\x00")
|
||||
var __0008_add_push_notificationsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\xce\x51\x0e\x82\x30\x0c\x00\xd0\x7f\x4f\xd1\x7b\xf8\x35\x64\x7c\x55\x48\x70\x7c\x2f\x08\x45\x97\x40\x6b\xd6\x6a\xe2\xed\x3d\x80\x33\x9a\x78\x81\x97\xe7\x30\xf8\x1e\x82\xab\xd0\x83\x92\x59\xe2\x8b\x82\xab\x6b\x38\x74\x38\x1c\x5b\xc8\xb4\x89\x51\xbc\xdd\xf5\x1a\x59\x2c\x2d\x69\x1a\x2d\x09\x6b\x24\x1e\xcf\x2b\xcd\x50\x75\x1d\x7a\xd7\x42\xed\x1b\x37\x60\x80\xc6\xe1\xc9\xef\x77\xdf\x60\x25\x9e\x0b\xec\x1b\x17\xfa\xe1\x07\xad\xf0\x53\xca\x0f\xca\xff\x36\x0b\xf0\x92\x65\x8b\x93\xb0\x8d\x93\x69\x14\x5e\x9f\x9f\xf0\x57\x00\x00\x00\xff\xff\x30\xc0\x56\xbd\x5d\x01\x00\x00")
|
||||
|
||||
func _0008_add_push_notificationsUpSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
|
@ -337,8 +337,8 @@ func _0008_add_push_notificationsUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "0008_add_push_notifications.up.sql", size: 294, mode: os.FileMode(0644), modTime: time.Unix(1594974529, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xde, 0x81, 0x4a, 0x9, 0x4d, 0xd9, 0xa1, 0x3d, 0xc5, 0xc3, 0xd7, 0x62, 0x8f, 0xc5, 0xfd, 0xb8, 0xa2, 0x71, 0x1d, 0xbc, 0xa6, 0x0, 0x3, 0x83, 0x7a, 0x12, 0x7b, 0x1f, 0xa9, 0x2, 0x29, 0x1a}}
|
||||
info := bindataFileInfo{name: "0008_add_push_notifications.up.sql", size: 349, mode: os.FileMode(0644), modTime: time.Unix(1595832401, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x5a, 0x0, 0xbf, 0xd0, 0xdd, 0xcd, 0x73, 0xe0, 0x7c, 0x56, 0xef, 0xdc, 0x57, 0x61, 0x94, 0x64, 0x70, 0xb9, 0xfa, 0xa1, 0x2a, 0x36, 0xc, 0x2f, 0xf8, 0x95, 0xa, 0x57, 0x3e, 0x7a, 0xd7, 0x12}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
ALTER TABLE settings ADD COLUMN remote_push_notifications_enabled BOOLEAN;
|
||||
ALTER TABLE settings ADD COLUMN send_push_notifications BOOLEAN;
|
||||
ALTER TABLE settings ADD COLUMN push_notifications_server_enabled BOOLEAN;
|
||||
ALTER TABLE settings ADD COLUMN push_notifications_from_contacts_only BOOLEAN;
|
||||
ALTER TABLE settings ADD COLUMN remote_push_notifications_enabled BOOLEAN DEFAULT FALSE;
|
||||
ALTER TABLE settings ADD COLUMN send_push_notifications BOOLEAN DEFAULT TRUE;
|
||||
ALTER TABLE settings ADD COLUMN push_notifications_server_enabled BOOLEAN DEFAULT FALSE;
|
||||
ALTER TABLE settings ADD COLUMN push_notifications_from_contacts_only BOOLEAN DEFAULT FALSE;
|
||||
|
|
|
@ -59,22 +59,27 @@ type Settings struct {
|
|||
Mnemonic *string `json:"mnemonic,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Networks *json.RawMessage `json:"networks/networks"`
|
||||
// NotificationsEnabled indicates whether local notifications should be enabled (android only)
|
||||
NotificationsEnabled bool `json:"notifications-enabled?,omitempty"`
|
||||
PhotoPath string `json:"photo-path"`
|
||||
PinnedMailserver *json.RawMessage `json:"pinned-mailservers,omitempty"`
|
||||
PreferredName *string `json:"preferred-name,omitempty"`
|
||||
PreviewPrivacy bool `json:"preview-privacy?"`
|
||||
PublicKey string `json:"public-key"`
|
||||
PushNotificationsServerEnabled bool `json:"push-notifications-server-enabled,omitempty"`
|
||||
PushNotificationsFromContactsOnly bool `json:"push-notifications-from-contacts-only,omitempty"`
|
||||
// PushNotificationsServerEnabled indicates whether we should be running a push notification server
|
||||
PushNotificationsServerEnabled bool `json:"push-notifications-server-enabled?,omitempty"`
|
||||
// PushNotificationsFromContactsOnly indicates whether we should only receive push notifications from contacts
|
||||
PushNotificationsFromContactsOnly bool `json:"push-notifications-from-contacts-only?,omitempty"`
|
||||
RememberSyncingChoice bool `json:"remember-syncing-choice?,omitempty"`
|
||||
RemotePushNotificationsEnabled bool `json:"remote-push-notifications-enabled,omitempty"`
|
||||
// RemotePushNotificationsEnabled indicates whether we should be using remote notifications (ios only for now)
|
||||
RemotePushNotificationsEnabled bool `json:"remote-push-notifications-enabled?,omitempty"`
|
||||
SigningPhrase string `json:"signing-phrase"`
|
||||
StickerPacksInstalled *json.RawMessage `json:"stickers/packs-installed,omitempty"`
|
||||
StickerPacksPending *json.RawMessage `json:"stickers/packs-pending,omitempty"`
|
||||
StickersRecentStickers *json.RawMessage `json:"stickers/recent-stickers,omitempty"`
|
||||
SyncingOnMobileNetwork bool `json:"syncing-on-mobile-network?,omitempty"`
|
||||
SendPushNotifications bool `json:"send-push-notifications,omitempty"`
|
||||
// SendPushNotifications indicates whether we should send push notifications for other clients
|
||||
SendPushNotifications bool `json:"send-push-notifications?,omitempty"`
|
||||
Appearance uint `json:"appearance"`
|
||||
Usernames *json.RawMessage `json:"usernames,omitempty"`
|
||||
WalletRootAddress types.Address `json:"wallet-root-address,omitempty"`
|
||||
|
@ -250,25 +255,25 @@ func (db *Database) SaveSetting(setting string, value interface{}) error {
|
|||
return ErrInvalidConfig
|
||||
}
|
||||
update, err = db.db.Prepare("UPDATE settings SET remember_syncing_choice = ? WHERE synthetic_id = 'id'")
|
||||
case "remote-push-notifications-enabled":
|
||||
case "remote-push-notifications-enabled?":
|
||||
_, ok := value.(bool)
|
||||
if !ok {
|
||||
return ErrInvalidConfig
|
||||
}
|
||||
update, err = db.db.Prepare("UPDATE settings SET remote_push_notifications_enabled = ? WHERE synthetic_id = 'id'")
|
||||
case "push-notifications-server-enabled":
|
||||
case "push-notifications-server-enabled?":
|
||||
_, ok := value.(bool)
|
||||
if !ok {
|
||||
return ErrInvalidConfig
|
||||
}
|
||||
update, err = db.db.Prepare("UPDATE settings SET push_notifications_server_enabled = ? WHERE synthetic_id = 'id'")
|
||||
case "push-notifications-from-contacts-only":
|
||||
case "push-notifications-from-contacts-only?":
|
||||
_, ok := value.(bool)
|
||||
if !ok {
|
||||
return ErrInvalidConfig
|
||||
}
|
||||
update, err = db.db.Prepare("UPDATE settings SET push_notifications_from_contacts_only = ? WHERE synthetic_id = 'id'")
|
||||
case "send-push-notifications":
|
||||
case "send-push-notifications?":
|
||||
_, ok := value.(bool)
|
||||
if !ok {
|
||||
return ErrInvalidConfig
|
||||
|
@ -332,7 +337,7 @@ func (db *Database) GetNodeConfig(nodecfg interface{}) error {
|
|||
|
||||
func (db *Database) GetSettings() (Settings, error) {
|
||||
var s Settings
|
||||
err := db.db.QueryRow("SELECT address, chaos_mode, currency, current_network, custom_bootnodes, custom_bootnodes_enabled, dapps_address, eip1581_address, fleet, hide_home_tooltip, installation_id, key_uid, keycard_instance_uid, keycard_paired_on, keycard_pairing, last_updated, latest_derived_path, log_level, mnemonic, name, networks, notifications_enabled, photo_path, pinned_mailservers, preferred_name, preview_privacy, public_key, remember_syncing_choice, signing_phrase, stickers_packs_installed, stickers_packs_pending, stickers_recent_stickers, syncing_on_mobile_network, usernames, appearance, wallet_root_address, wallet_set_up_passed, wallet_visible_tokens, waku_enabled, waku_bloom_filter_mode FROM settings WHERE synthetic_id = 'id'").Scan(
|
||||
err := db.db.QueryRow("SELECT address, chaos_mode, currency, current_network, custom_bootnodes, custom_bootnodes_enabled, dapps_address, eip1581_address, fleet, hide_home_tooltip, installation_id, key_uid, keycard_instance_uid, keycard_paired_on, keycard_pairing, last_updated, latest_derived_path, log_level, mnemonic, name, networks, notifications_enabled, push_notifications_server_enabled, push_notifications_from_contacts_only, remote_push_notifications_enabled, send_push_notifications, photo_path, pinned_mailservers, preferred_name, preview_privacy, public_key, remember_syncing_choice, signing_phrase, stickers_packs_installed, stickers_packs_pending, stickers_recent_stickers, syncing_on_mobile_network, usernames, appearance, wallet_root_address, wallet_set_up_passed, wallet_visible_tokens, waku_enabled, waku_bloom_filter_mode FROM settings WHERE synthetic_id = 'id'").Scan(
|
||||
&s.Address,
|
||||
&s.ChaosMode,
|
||||
&s.Currency,
|
||||
|
@ -355,6 +360,10 @@ func (db *Database) GetSettings() (Settings, error) {
|
|||
&s.Name,
|
||||
&s.Networks,
|
||||
&s.NotificationsEnabled,
|
||||
&s.PushNotificationsServerEnabled,
|
||||
&s.PushNotificationsFromContactsOnly,
|
||||
&s.RemotePushNotificationsEnabled,
|
||||
&s.SendPushNotifications,
|
||||
&s.PhotoPath,
|
||||
&s.PinnedMailserver,
|
||||
&s.PreferredName,
|
||||
|
|
|
@ -5,9 +5,11 @@ import (
|
|||
"crypto/cipher"
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"io"
|
||||
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
)
|
||||
|
||||
const nonceLength = 12
|
||||
|
|
|
@ -48,10 +48,16 @@ type MessageProcessor struct {
|
|||
protocol *encryption.Protocol
|
||||
transport transport.Transport
|
||||
logger *zap.Logger
|
||||
ephemeralKeys map[string]*ecdsa.PrivateKey
|
||||
mutex sync.Mutex
|
||||
|
||||
subscriptions []chan<- *SentMessage
|
||||
// ephemeralKeys is a map that contains the ephemeral keys of the client, used
|
||||
// to decrypt messages
|
||||
ephemeralKeys map[string]*ecdsa.PrivateKey
|
||||
ephemeralKeysMutex sync.Mutex
|
||||
|
||||
// sentMessagesSubscriptions contains all the subscriptions for sent messages
|
||||
sentMessagesSubscriptions []chan<- *SentMessage
|
||||
// sentMessagesSubscriptions contains all the subscriptions for scheduled messages
|
||||
scheduledMessagesSubscriptions []chan<- *RawMessage
|
||||
|
||||
featureFlags FeatureFlags
|
||||
}
|
||||
|
@ -101,7 +107,7 @@ func NewMessageProcessor(
|
|||
}
|
||||
|
||||
func (p *MessageProcessor) Stop() {
|
||||
for _, c := range p.subscriptions {
|
||||
for _, c := range p.sentMessagesSubscriptions {
|
||||
close(c)
|
||||
}
|
||||
p.datasync.Stop() // idempotent op
|
||||
|
@ -118,10 +124,22 @@ func (p *MessageProcessor) SendPrivate(
|
|||
zap.String("public-key", types.EncodeHex(crypto.FromECDSAPub(recipient))),
|
||||
zap.String("site", "SendPrivate"),
|
||||
)
|
||||
// Currently we don't support sending through datasync and setting custom waku fields,
|
||||
// as the datasync interface is not rich enough to propagate that information, so we
|
||||
// would have to add some complexity to handle this.
|
||||
if rawMessage.ResendAutomatically && (rawMessage.Sender != nil || rawMessage.SkipEncryption) {
|
||||
return nil, errors.New("setting identity, skip-encryption and datasync not supported")
|
||||
}
|
||||
|
||||
// Set sender identity if not specified
|
||||
if rawMessage.Sender == nil {
|
||||
rawMessage.Sender = p.identity
|
||||
}
|
||||
|
||||
return p.sendPrivate(ctx, recipient, rawMessage)
|
||||
}
|
||||
|
||||
// SendGroupRaw takes encoded data, encrypts it and sends through the wire,
|
||||
// SendGroup takes encoded data, encrypts it and sends through the wire,
|
||||
// always return the messageID
|
||||
func (p *MessageProcessor) SendGroup(
|
||||
ctx context.Context,
|
||||
|
@ -132,15 +150,18 @@ func (p *MessageProcessor) SendGroup(
|
|||
"sending a private group message",
|
||||
zap.String("site", "SendGroup"),
|
||||
)
|
||||
// Set sender if not specified
|
||||
if rawMessage.Sender == nil {
|
||||
rawMessage.Sender = p.identity
|
||||
}
|
||||
// Calculate messageID first
|
||||
|
||||
// Calculate messageID first and set on raw message
|
||||
wrappedMessage, err := p.wrapMessageV1(rawMessage)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to wrap message")
|
||||
}
|
||||
messageID := v1protocol.MessageID(&rawMessage.Sender.PublicKey, wrappedMessage)
|
||||
rawMessage.ID = types.EncodeHex(messageID)
|
||||
|
||||
// Send to each recipients
|
||||
for _, recipient := range recipients {
|
||||
|
@ -160,21 +181,17 @@ func (p *MessageProcessor) sendPrivate(
|
|||
) ([]byte, error) {
|
||||
p.logger.Debug("sending private message", zap.String("recipient", types.EncodeHex(crypto.FromECDSAPub(recipient))))
|
||||
|
||||
if rawMessage.ResendAutomatically && (rawMessage.Sender != nil || rawMessage.SkipNegotiation) {
|
||||
return nil, errors.New("setting identity, skip-negotiation and datasync not supported")
|
||||
}
|
||||
|
||||
// If we use our own key we don't skip negotiation
|
||||
if rawMessage.Sender == nil {
|
||||
rawMessage.Sender = p.identity
|
||||
}
|
||||
|
||||
wrappedMessage, err := p.wrapMessageV1(rawMessage)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to wrap message")
|
||||
}
|
||||
|
||||
messageID := v1protocol.MessageID(&rawMessage.Sender.PublicKey, wrappedMessage)
|
||||
rawMessage.ID = types.EncodeHex(messageID)
|
||||
|
||||
// Notify before dispatching, otherwise the dispatch subscription might happen
|
||||
// earlier than the scheduled
|
||||
p.notifyOnScheduledMessage(rawMessage)
|
||||
|
||||
if p.featureFlags.Datasync && rawMessage.ResendAutomatically {
|
||||
// No need to call transport tracking.
|
||||
|
@ -183,7 +200,8 @@ func (p *MessageProcessor) sendPrivate(
|
|||
return nil, errors.Wrap(err, "failed to send message with datasync")
|
||||
}
|
||||
|
||||
} else if rawMessage.SkipNegotiation {
|
||||
} else if rawMessage.SkipEncryption {
|
||||
// When SkipEncryption is set we don't pass the message to the encryption layer
|
||||
messageIDs := [][]byte{messageID}
|
||||
hash, newMessage, err := p.sendRawMessage(ctx, recipient, wrappedMessage, messageIDs)
|
||||
if err != nil {
|
||||
|
@ -267,7 +285,7 @@ func (p *MessageProcessor) SendPublic(
|
|||
chatName string,
|
||||
rawMessage *RawMessage,
|
||||
) ([]byte, error) {
|
||||
var newMessage *types.NewMessage
|
||||
// Set sender
|
||||
if rawMessage.Sender == nil {
|
||||
rawMessage.Sender = p.identity
|
||||
}
|
||||
|
@ -277,20 +295,24 @@ func (p *MessageProcessor) SendPublic(
|
|||
return nil, errors.Wrap(err, "failed to wrap message")
|
||||
}
|
||||
|
||||
newMessage = &types.NewMessage{
|
||||
newMessage := &types.NewMessage{
|
||||
TTL: whisperTTL,
|
||||
Payload: wrappedMessage,
|
||||
PowTarget: calculatePoW(wrappedMessage),
|
||||
PowTime: whisperPoWTime,
|
||||
}
|
||||
|
||||
messageID := v1protocol.MessageID(&rawMessage.Sender.PublicKey, wrappedMessage)
|
||||
rawMessage.ID = types.EncodeHex(messageID)
|
||||
|
||||
// notify before dispatching
|
||||
p.notifyOnScheduledMessage(rawMessage)
|
||||
|
||||
hash, err := p.transport.SendPublic(ctx, newMessage, chatName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
messageID := v1protocol.MessageID(&rawMessage.Sender.PublicKey, wrappedMessage)
|
||||
|
||||
p.transport.Track([][]byte{messageID}, hash, newMessage)
|
||||
|
||||
return messageID, nil
|
||||
|
@ -339,24 +361,32 @@ func (p *MessageProcessor) HandleMessages(shhMessage *types.Message, application
|
|||
return statusMessages, nil
|
||||
}
|
||||
|
||||
// fetchDecryptionKey returns the private key associated with this public key, and returns true if it's an ephemeral key
|
||||
func (p *MessageProcessor) fetchDecryptionKey(destination *ecdsa.PublicKey) (*ecdsa.PrivateKey, bool) {
|
||||
destinationID := types.EncodeHex(crypto.FromECDSAPub(destination))
|
||||
|
||||
p.ephemeralKeysMutex.Lock()
|
||||
decryptionKey, ok := p.ephemeralKeys[destinationID]
|
||||
p.ephemeralKeysMutex.Unlock()
|
||||
|
||||
// the key is not there, fallback on identity
|
||||
if !ok {
|
||||
return p.identity, false
|
||||
}
|
||||
return decryptionKey, true
|
||||
}
|
||||
|
||||
func (p *MessageProcessor) handleEncryptionLayer(ctx context.Context, message *v1protocol.StatusMessage) error {
|
||||
logger := p.logger.With(zap.String("site", "handleEncryptionLayer"))
|
||||
publicKey := message.SigPubKey()
|
||||
destination := message.Dst
|
||||
|
||||
destinationID := types.EncodeHex(crypto.FromECDSAPub(destination))
|
||||
p.mutex.Lock()
|
||||
decryptionKey, ok := p.ephemeralKeys[destinationID]
|
||||
p.mutex.Unlock()
|
||||
logger.Info("destination id", zap.String("desti", destinationID))
|
||||
skipNegotiation := true
|
||||
if !ok {
|
||||
skipNegotiation = false
|
||||
decryptionKey = p.identity
|
||||
}
|
||||
// if it's an ephemeral key, we don't negotiate a topic
|
||||
decryptionKey, skipNegotiation := p.fetchDecryptionKey(message.Dst)
|
||||
|
||||
err := message.HandleEncryption(decryptionKey, publicKey, p.protocol, skipNegotiation)
|
||||
if err == encryption.ErrDeviceNotFound {
|
||||
|
||||
// if it's an ephemeral key, we don't have to handle a device not found error
|
||||
if err == encryption.ErrDeviceNotFound && !skipNegotiation {
|
||||
if err := p.handleErrDeviceNotFound(ctx, publicKey); err != nil {
|
||||
logger.Error("failed to handle ErrDeviceNotFound", zap.Error(err))
|
||||
}
|
||||
|
@ -464,7 +494,6 @@ func (p *MessageProcessor) sendRawMessage(ctx context.Context, publicKey *ecdsa.
|
|||
}
|
||||
|
||||
return hash, newMessage, nil
|
||||
|
||||
}
|
||||
|
||||
// sendMessageSpec analyses the spec properties and selects a proper transport method.
|
||||
|
@ -496,34 +525,60 @@ func (p *MessageProcessor) sendMessageSpec(ctx context.Context, publicKey *ecdsa
|
|||
MessageIDs: messageIDs,
|
||||
}
|
||||
|
||||
logger.Debug("subscriptions", zap.Int("count", len(p.subscriptions)))
|
||||
// Publish on channels, drop if buffer is full
|
||||
for _, c := range p.subscriptions {
|
||||
logger.Debug("sending on subscription")
|
||||
select {
|
||||
case c <- sentMessage:
|
||||
default:
|
||||
logger.Warn("subscription channel full, dropping message")
|
||||
}
|
||||
}
|
||||
p.notifyOnSentMessage(sentMessage)
|
||||
|
||||
return hash, newMessage, nil
|
||||
}
|
||||
|
||||
func (p *MessageProcessor) Subscribe() <-chan *SentMessage {
|
||||
// SubscribeToSentMessages returns a channel where we publish every time a message is sent
|
||||
func (p *MessageProcessor) SubscribeToSentMessages() <-chan *SentMessage {
|
||||
c := make(chan *SentMessage, 100)
|
||||
p.subscriptions = append(p.subscriptions, c)
|
||||
p.sentMessagesSubscriptions = append(p.sentMessagesSubscriptions, c)
|
||||
return c
|
||||
}
|
||||
|
||||
func (p *MessageProcessor) notifyOnSentMessage(sentMessage *SentMessage) {
|
||||
// Publish on channels, drop if buffer is full
|
||||
for _, c := range p.sentMessagesSubscriptions {
|
||||
select {
|
||||
case c <- sentMessage:
|
||||
default:
|
||||
p.logger.Warn("sent messages subscription channel full, dropping message")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// SubscribeToScheduledMessages returns a channel where we publish every time a message is scheduled for sending
|
||||
func (p *MessageProcessor) SubscribeToScheduledMessages() <-chan *RawMessage {
|
||||
c := make(chan *RawMessage, 100)
|
||||
p.scheduledMessagesSubscriptions = append(p.scheduledMessagesSubscriptions, c)
|
||||
return c
|
||||
}
|
||||
|
||||
func (p *MessageProcessor) notifyOnScheduledMessage(message *RawMessage) {
|
||||
// Publish on channels, drop if buffer is full
|
||||
for _, c := range p.scheduledMessagesSubscriptions {
|
||||
select {
|
||||
case c <- message:
|
||||
default:
|
||||
p.logger.Warn("scheduled messages subscription channel full, dropping message")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *MessageProcessor) JoinPublic(chatID string) error {
|
||||
return p.transport.JoinPublic(chatID)
|
||||
}
|
||||
|
||||
func (p *MessageProcessor) LoadKeyFilters(privateKey *ecdsa.PrivateKey) (*transport.Filter, error) {
|
||||
p.mutex.Lock()
|
||||
// AddEphemeralKey adds an ephemeral key that we will be listening to
|
||||
// note that we never removed them from now, as waku/whisper does not
|
||||
// recalculate topics on removal, so effectively there's no benefit.
|
||||
// On restart they will be gone.
|
||||
func (p *MessageProcessor) AddEphemeralKey(privateKey *ecdsa.PrivateKey) (*transport.Filter, error) {
|
||||
p.ephemeralKeysMutex.Lock()
|
||||
p.ephemeralKeys[types.EncodeHex(crypto.FromECDSAPub(&privateKey.PublicKey))] = privateKey
|
||||
p.mutex.Unlock()
|
||||
p.ephemeralKeysMutex.Unlock()
|
||||
return p.transport.LoadKeyFilters(privateKey)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"github.com/status-im/status-go/protocol"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -34,22 +33,20 @@ func TestMessageProcessorSuite(t *testing.T) {
|
|||
type MessageProcessorSuite struct {
|
||||
suite.Suite
|
||||
|
||||
processor *messageProcessor
|
||||
processor *MessageProcessor
|
||||
tmpDir string
|
||||
testMessage protocol.Message
|
||||
testMessage protobuf.ChatMessage
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func (s *MessageProcessorSuite) SetupTest() {
|
||||
s.testMessage = protocol.Message{
|
||||
ChatMessage: protobuf.ChatMessage{
|
||||
s.testMessage = protobuf.ChatMessage{
|
||||
Text: "abc123",
|
||||
ChatId: "testing-adamb",
|
||||
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
|
||||
MessageType: protobuf.ChatMessage_PUBLIC_GROUP,
|
||||
Clock: 154593077368201,
|
||||
Timestamp: 1545930773682,
|
||||
},
|
||||
}
|
||||
|
||||
var err error
|
||||
|
@ -82,8 +79,6 @@ func (s *MessageProcessorSuite) SetupTest() {
|
|||
whisperConfig.MinimumAcceptedPOW = 0
|
||||
shh := whisper.New(&whisperConfig)
|
||||
s.Require().NoError(shh.Start(nil))
|
||||
config := &protocol.config{}
|
||||
s.Require().NoError(protocol.WithDatasync()(config))
|
||||
|
||||
whisperTransport, err := transport.NewTransport(
|
||||
gethbridge.NewGethWhisperWrapper(shh),
|
||||
|
@ -95,14 +90,13 @@ func (s *MessageProcessorSuite) SetupTest() {
|
|||
)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.processor, err = newMessageProcessor(
|
||||
s.processor, err = NewMessageProcessor(
|
||||
identity,
|
||||
database,
|
||||
encryptionProtocol,
|
||||
whisperTransport,
|
||||
s.logger,
|
||||
protocol.featureFlags{},
|
||||
nil,
|
||||
FeatureFlags{},
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
@ -129,7 +123,7 @@ func (s *MessageProcessorSuite) TestHandleDecodedMessagesWrapped() {
|
|||
message.Sig = crypto.FromECDSAPub(&relayerKey.PublicKey)
|
||||
message.Payload = wrappedPayload
|
||||
|
||||
decodedMessages, err := s.processor.handleMessages(message, true)
|
||||
decodedMessages, err := s.processor.HandleMessages(message, true)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().Equal(1, len(decodedMessages))
|
||||
|
@ -137,7 +131,7 @@ func (s *MessageProcessorSuite) TestHandleDecodedMessagesWrapped() {
|
|||
s.Require().Equal(v1protocol.MessageID(&authorKey.PublicKey, wrappedPayload), decodedMessages[0].ID)
|
||||
parsedMessage := decodedMessages[0].ParsedMessage.(protobuf.ChatMessage)
|
||||
s.Require().Equal(encodedPayload, decodedMessages[0].DecryptedPayload)
|
||||
s.Require().True(proto.Equal(&s.testMessage.ChatMessage, &parsedMessage))
|
||||
s.Require().True(proto.Equal(&s.testMessage, &parsedMessage))
|
||||
s.Require().Equal(protobuf.ApplicationMetadataMessage_CHAT_MESSAGE, decodedMessages[0].Type)
|
||||
}
|
||||
|
||||
|
@ -165,7 +159,7 @@ func (s *MessageProcessorSuite) TestHandleDecodedMessagesDatasync() {
|
|||
message.Sig = crypto.FromECDSAPub(&relayerKey.PublicKey)
|
||||
message.Payload = marshalledDataSyncMessage
|
||||
|
||||
decodedMessages, err := s.processor.handleMessages(message, true)
|
||||
decodedMessages, err := s.processor.HandleMessages(message, true)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// We send two messages, the unwrapped one will be attributed to the relayer, while the wrapped one will be attributed to the author
|
||||
|
@ -174,7 +168,7 @@ func (s *MessageProcessorSuite) TestHandleDecodedMessagesDatasync() {
|
|||
s.Require().Equal(v1protocol.MessageID(&authorKey.PublicKey, wrappedPayload), decodedMessages[0].ID)
|
||||
s.Require().Equal(encodedPayload, decodedMessages[0].DecryptedPayload)
|
||||
parsedMessage := decodedMessages[0].ParsedMessage.(protobuf.ChatMessage)
|
||||
s.Require().True(proto.Equal(&s.testMessage.ChatMessage, &parsedMessage))
|
||||
s.Require().True(proto.Equal(&s.testMessage, &parsedMessage))
|
||||
s.Require().Equal(protobuf.ApplicationMetadataMessage_CHAT_MESSAGE, decodedMessages[0].Type)
|
||||
}
|
||||
|
||||
|
@ -232,7 +226,7 @@ func (s *MessageProcessorSuite) TestHandleDecodedMessagesDatasyncEncrypted() {
|
|||
message.Sig = crypto.FromECDSAPub(&relayerKey.PublicKey)
|
||||
message.Payload = encryptedPayload
|
||||
|
||||
decodedMessages, err := s.processor.handleMessages(message, true)
|
||||
decodedMessages, err := s.processor.HandleMessages(message, true)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// We send two messages, the unwrapped one will be attributed to the relayer,
|
||||
|
@ -242,6 +236,6 @@ func (s *MessageProcessorSuite) TestHandleDecodedMessagesDatasyncEncrypted() {
|
|||
s.Require().Equal(v1protocol.MessageID(&authorKey.PublicKey, wrappedPayload), decodedMessages[0].ID)
|
||||
s.Require().Equal(encodedPayload, decodedMessages[0].DecryptedPayload)
|
||||
parsedMessage := decodedMessages[0].ParsedMessage.(protobuf.ChatMessage)
|
||||
s.Require().True(proto.Equal(&s.testMessage.ChatMessage, &parsedMessage))
|
||||
s.Require().True(proto.Equal(&s.testMessage, &parsedMessage))
|
||||
s.Require().Equal(protobuf.ApplicationMetadataMessage_CHAT_MESSAGE, decodedMessages[0].Type)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ type RawMessage struct {
|
|||
SendCount int
|
||||
Sent bool
|
||||
ResendAutomatically bool
|
||||
SkipNegotiation bool
|
||||
SkipEncryption bool
|
||||
SendPushNotification bool
|
||||
MessageType protobuf.ApplicationMetadataMessage_Type
|
||||
Payload []byte
|
||||
Sender *ecdsa.PrivateKey
|
||||
|
|
|
@ -4,12 +4,12 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
v1protocol "github.com/status-im/status-go/protocol/v1"
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"crypto/ecdsa"
|
||||
"database/sql"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
@ -20,6 +19,7 @@ import (
|
|||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
enstypes "github.com/status-im/status-go/eth-node/types/ens"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/encryption"
|
||||
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
||||
"github.com/status-im/status-go/protocol/encryption/sharedsecret"
|
||||
|
@ -27,8 +27,8 @@ import (
|
|||
"github.com/status-im/status-go/protocol/identity/identicon"
|
||||
"github.com/status-im/status-go/protocol/images"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/push_notification_client"
|
||||
"github.com/status-im/status-go/protocol/push_notification_server"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationclient"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationserver"
|
||||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
"github.com/status-im/status-go/protocol/transport"
|
||||
wakutransp "github.com/status-im/status-go/protocol/transport/waku"
|
||||
|
@ -61,8 +61,8 @@ type Messenger struct {
|
|||
encryptor *encryption.Protocol
|
||||
processor *common.MessageProcessor
|
||||
handler *MessageHandler
|
||||
pushNotificationClient *push_notification_client.Client
|
||||
pushNotificationServer *push_notification_server.Server
|
||||
pushNotificationClient *pushnotificationclient.Client
|
||||
pushNotificationServer *pushnotificationserver.Server
|
||||
logger *zap.Logger
|
||||
verifyTransactionClient EthClient
|
||||
featureFlags common.FeatureFlags
|
||||
|
@ -248,27 +248,29 @@ func NewMessenger(
|
|||
return nil, errors.Wrap(err, "failed to create messageProcessor")
|
||||
}
|
||||
|
||||
var pushNotificationServer *push_notification_server.Server
|
||||
// Initialize push notification server
|
||||
var pushNotificationServer *pushnotificationserver.Server
|
||||
if c.pushNotificationServerConfig != nil {
|
||||
c.pushNotificationServerConfig.Identity = identity
|
||||
pushNotificationServerPersistence := push_notification_server.NewSQLitePersistence(database)
|
||||
pushNotificationServer = push_notification_server.New(c.pushNotificationServerConfig, pushNotificationServerPersistence, processor)
|
||||
pushNotificationServerPersistence := pushnotificationserver.NewSQLitePersistence(database)
|
||||
pushNotificationServer = pushnotificationserver.New(c.pushNotificationServerConfig, pushNotificationServerPersistence, processor)
|
||||
}
|
||||
|
||||
pushNotificationClientPersistence := push_notification_client.NewPersistence(database)
|
||||
// Initialize push notification client
|
||||
pushNotificationClientPersistence := pushnotificationclient.NewPersistence(database)
|
||||
pushNotificationClientConfig := c.pushNotificationClientConfig
|
||||
if pushNotificationClientConfig == nil {
|
||||
pushNotificationClientConfig = &push_notification_client.Config{}
|
||||
pushNotificationClientConfig = &pushnotificationclient.Config{}
|
||||
}
|
||||
|
||||
// Overriding until we handle sending/receiving from multiple identities
|
||||
// Overriding until we handle different identities
|
||||
pushNotificationClientConfig.Identity = identity
|
||||
// Hardcoding this for now, as it's the only one we support
|
||||
pushNotificationClientConfig.TokenType = protobuf.PushNotificationRegistration_APN_TOKEN
|
||||
pushNotificationClientConfig.Logger = logger
|
||||
pushNotificationClientConfig.InstallationID = installationID
|
||||
|
||||
pushNotificationClient := push_notification_client.New(pushNotificationClientPersistence, pushNotificationClientConfig, processor)
|
||||
pushNotificationClient := pushnotificationclient.New(pushNotificationClientPersistence, pushNotificationClientConfig, processor)
|
||||
|
||||
handler := newMessageHandler(identity, logger, &sqlitePersistence{db: database})
|
||||
|
||||
|
@ -318,6 +320,8 @@ func (m *Messenger) Start() error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Start push notification client
|
||||
if m.pushNotificationClient != nil {
|
||||
if err := m.pushNotificationClient.Start(); err != nil {
|
||||
return err
|
||||
|
@ -1145,7 +1149,7 @@ func (m *Messenger) saveContact(contact *Contact) error {
|
|||
}
|
||||
}
|
||||
|
||||
// We check if it should re-register
|
||||
// We check if it should re-register with the push notification server
|
||||
shouldReregisterForPushNotifications := m.pushNotificationClient != nil && (m.isNewContact(contact) || m.removedContact(contact))
|
||||
|
||||
err = m.persistence.SaveContact(contact, nil)
|
||||
|
@ -1379,7 +1383,6 @@ func (m *Messenger) SendChatMessage(ctx context.Context, message *Message) (*Mes
|
|||
|
||||
}
|
||||
logger := m.logger.With(zap.String("site", "Send"), zap.String("chatID", message.ChatId))
|
||||
logger.Info("SENDING CHAT MESSAGE")
|
||||
var response MessengerResponse
|
||||
|
||||
// A valid added chat is required.
|
||||
|
@ -1427,9 +1430,9 @@ func (m *Messenger) SendChatMessage(ctx context.Context, message *Message) (*Mes
|
|||
return nil, errors.New("chat type not supported")
|
||||
}
|
||||
|
||||
// THERE'S A RACE CONDITION, WE SHOULD CALCULATE AND TRACK THE ID FIRST
|
||||
id, err := m.dispatchMessage(ctx, &common.RawMessage{
|
||||
LocalChatID: chat.ID,
|
||||
SendPushNotification: !chat.Public(),
|
||||
Payload: encodedMessage,
|
||||
MessageType: protobuf.ApplicationMetadataMessage_CHAT_MESSAGE,
|
||||
ResendAutomatically: true,
|
||||
|
@ -1438,14 +1441,6 @@ func (m *Messenger) SendChatMessage(ctx context.Context, message *Message) (*Mes
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// If the chat is not public, we instruct the pushNotificationService to send a notification
|
||||
if !chat.Public() && m.pushNotificationClient != nil {
|
||||
if err := m.pushNotificationClient.NotifyOnMessageID(chat.ID, id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
message.ID = types.EncodeHex(id)
|
||||
err = message.PrepareContent()
|
||||
if err != nil {
|
||||
|
@ -1982,8 +1977,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
|||
continue
|
||||
}
|
||||
logger.Debug("Handling PushNotificationQuery")
|
||||
// TODO: Compare DST with Identity
|
||||
if err := m.pushNotificationServer.HandlePushNotificationQuery2(publicKey, msg.ID, msg.ParsedMessage.(protobuf.PushNotificationQuery)); err != nil {
|
||||
if err := m.pushNotificationServer.HandlePushNotificationQuery(publicKey, msg.ID, msg.ParsedMessage.(protobuf.PushNotificationQuery)); err != nil {
|
||||
logger.Warn("failed to handle PushNotificationQuery", zap.Error(err))
|
||||
}
|
||||
// We continue in any case, no changes to messenger
|
||||
|
@ -1994,7 +1988,6 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
|||
continue
|
||||
}
|
||||
logger.Debug("Handling PushNotificationRegistrationResponse")
|
||||
// TODO: Compare DST with Identity
|
||||
if err := m.pushNotificationClient.HandlePushNotificationRegistrationResponse(publicKey, msg.ParsedMessage.(protobuf.PushNotificationRegistrationResponse)); err != nil {
|
||||
logger.Warn("failed to handle PushNotificationRegistrationResponse", zap.Error(err))
|
||||
}
|
||||
|
@ -2006,7 +1999,6 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
|||
continue
|
||||
}
|
||||
logger.Debug("Handling PushNotificationResponse")
|
||||
// TODO: Compare DST with Identity
|
||||
if err := m.pushNotificationClient.HandlePushNotificationResponse(publicKey, msg.ParsedMessage.(protobuf.PushNotificationResponse)); err != nil {
|
||||
logger.Warn("failed to handle PushNotificationResponse", zap.Error(err))
|
||||
}
|
||||
|
@ -2019,7 +2011,6 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
|||
continue
|
||||
}
|
||||
logger.Debug("Handling PushNotificationQueryResponse")
|
||||
// TODO: Compare DST with Identity
|
||||
if err := m.pushNotificationClient.HandlePushNotificationQueryResponse(publicKey, msg.ParsedMessage.(protobuf.PushNotificationQueryResponse)); err != nil {
|
||||
logger.Warn("failed to handle PushNotificationQueryResponse", zap.Error(err))
|
||||
}
|
||||
|
@ -2032,8 +2023,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
|||
continue
|
||||
}
|
||||
logger.Debug("Handling PushNotificationRequest")
|
||||
// TODO: Compare DST with Identity
|
||||
if err := m.pushNotificationServer.HandlePushNotificationRequest2(publicKey, msg.ParsedMessage.(protobuf.PushNotificationRequest)); err != nil {
|
||||
if err := m.pushNotificationServer.HandlePushNotificationRequest(publicKey, msg.ParsedMessage.(protobuf.PushNotificationRequest)); err != nil {
|
||||
logger.Warn("failed to handle PushNotificationRequest", zap.Error(err))
|
||||
}
|
||||
// We continue in any case, no changes to messenger
|
||||
|
@ -2047,8 +2037,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
|||
continue
|
||||
}
|
||||
logger.Debug("Handling PushNotificationRegistration")
|
||||
// TODO: Compare DST with Identity
|
||||
if err := m.pushNotificationServer.HandlePushNotificationRegistration2(publicKey, msg.ParsedMessage.([]byte)); err != nil {
|
||||
if err := m.pushNotificationServer.HandlePushNotificationRegistration(publicKey, msg.ParsedMessage.([]byte)); err != nil {
|
||||
logger.Warn("failed to handle PushNotificationRegistration", zap.Error(err))
|
||||
}
|
||||
// We continue in any case, no changes to messenger
|
||||
|
@ -2134,6 +2123,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
|||
return messageState.Response, nil
|
||||
}
|
||||
|
||||
// SetMailserver sets the currently used mailserver
|
||||
func (m *Messenger) SetMailserver(peer []byte) {
|
||||
m.mailserver = peer
|
||||
}
|
||||
|
@ -3069,12 +3059,12 @@ func (m *Messenger) Timesource() TimeSource {
|
|||
return m.getTimesource()
|
||||
}
|
||||
|
||||
// AddPushNotificationServer adds a push notification server
|
||||
func (m *Messenger) AddPushNotificationServer(ctx context.Context, publicKey *ecdsa.PublicKey) error {
|
||||
// AddPushNotificationsServer adds a push notification server
|
||||
func (m *Messenger) AddPushNotificationsServer(ctx context.Context, publicKey *ecdsa.PublicKey) error {
|
||||
if m.pushNotificationClient == nil {
|
||||
return errors.New("push notification client not enabled")
|
||||
}
|
||||
return m.pushNotificationClient.AddPushNotificationServer(publicKey)
|
||||
return m.pushNotificationClient.AddPushNotificationsServer(publicKey)
|
||||
}
|
||||
|
||||
// RemovePushNotificationServer removes a push notification server
|
||||
|
@ -3085,10 +3075,12 @@ func (m *Messenger) RemovePushNotificationServer(ctx context.Context, publicKey
|
|||
return m.pushNotificationClient.RemovePushNotificationServer(publicKey)
|
||||
}
|
||||
|
||||
// UnregisterFromPushNotifications unregister from any server
|
||||
func (m *Messenger) UnregisterFromPushNotifications(ctx context.Context) error {
|
||||
return m.pushNotificationClient.Unregister()
|
||||
}
|
||||
|
||||
// DisableSendingPushNotifications signals the client not to send any push notification
|
||||
func (m *Messenger) DisableSendingPushNotifications() error {
|
||||
if m.pushNotificationClient == nil {
|
||||
return errors.New("push notification client not enabled")
|
||||
|
@ -3097,6 +3089,7 @@ func (m *Messenger) DisableSendingPushNotifications() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// EnableSendingPushNotifications signals the client to send push notifications
|
||||
func (m *Messenger) EnableSendingPushNotifications() error {
|
||||
if m.pushNotificationClient == nil {
|
||||
return errors.New("push notification client not enabled")
|
||||
|
@ -3142,6 +3135,7 @@ func (m *Messenger) RegisterForPushNotifications(ctx context.Context, deviceToke
|
|||
return m.pushNotificationClient.Register(deviceToken, contactIDs, mutedChatIDs)
|
||||
}
|
||||
|
||||
// RegisteredForPushNotifications returns whether we successfully registered with all the servers
|
||||
func (m *Messenger) RegisteredForPushNotifications() (bool, error) {
|
||||
if m.pushNotificationClient == nil {
|
||||
return false, errors.New("no push notification client")
|
||||
|
@ -3149,6 +3143,7 @@ func (m *Messenger) RegisteredForPushNotifications() (bool, error) {
|
|||
return m.pushNotificationClient.Registered()
|
||||
}
|
||||
|
||||
// EnablePushNotificationsFromContactsOnly is used to indicate that we want to received push notifications only from contacts
|
||||
func (m *Messenger) EnablePushNotificationsFromContactsOnly() error {
|
||||
if m.pushNotificationClient == nil {
|
||||
return errors.New("no push notification client")
|
||||
|
@ -3160,6 +3155,7 @@ func (m *Messenger) EnablePushNotificationsFromContactsOnly() error {
|
|||
return m.pushNotificationClient.EnablePushNotificationsFromContactsOnly(contactIDs, mutedChatIDs)
|
||||
}
|
||||
|
||||
// DisablePushNotificationsFromContactsOnly is used to indicate that we want to received push notifications from anyone
|
||||
func (m *Messenger) DisablePushNotificationsFromContactsOnly() error {
|
||||
if m.pushNotificationClient == nil {
|
||||
return errors.New("no push notification client")
|
||||
|
@ -3171,27 +3167,30 @@ func (m *Messenger) DisablePushNotificationsFromContactsOnly() error {
|
|||
return m.pushNotificationClient.DisablePushNotificationsFromContactsOnly(contactIDs, mutedChatIDs)
|
||||
}
|
||||
|
||||
func (m *Messenger) GetPushNotificationServers() ([]*push_notification_client.PushNotificationServer, error) {
|
||||
// GetPushNotificationServers returns the servers used for push notifications
|
||||
func (m *Messenger) GetPushNotificationServers() ([]*pushnotificationclient.PushNotificationServer, error) {
|
||||
if m.pushNotificationClient == nil {
|
||||
return nil, errors.New("no push notification client")
|
||||
}
|
||||
return m.pushNotificationClient.GetServers()
|
||||
}
|
||||
|
||||
func (m *Messenger) StartPushNotificationServer() error {
|
||||
// StartPushNotificationsServer initialize and start a push notification server, using the current messenger identity key
|
||||
func (m *Messenger) StartPushNotificationsServer() error {
|
||||
if m.pushNotificationServer == nil {
|
||||
pushNotificationServerPersistence := push_notification_server.NewSQLitePersistence(m.database)
|
||||
config := &push_notification_server.Config{
|
||||
pushNotificationServerPersistence := pushnotificationserver.NewSQLitePersistence(m.database)
|
||||
config := &pushnotificationserver.Config{
|
||||
Logger: m.logger,
|
||||
Identity: m.identity,
|
||||
}
|
||||
m.pushNotificationServer = push_notification_server.New(config, pushNotificationServerPersistence, m.processor)
|
||||
m.pushNotificationServer = pushnotificationserver.New(config, pushNotificationServerPersistence, m.processor)
|
||||
}
|
||||
|
||||
return m.pushNotificationServer.Start()
|
||||
}
|
||||
|
||||
func (m *Messenger) StopPushNotificationServer() error {
|
||||
// StopPushNotificationServer stops the push notification server if running
|
||||
func (m *Messenger) StopPushNotificationsServer() error {
|
||||
m.pushNotificationServer = nil
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,13 +2,15 @@ package protocol
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/encryption"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/push_notification_client"
|
||||
"github.com/status-im/status-go/protocol/push_notification_server"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationclient"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationserver"
|
||||
"github.com/status-im/status-go/protocol/transport"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
|
@ -34,8 +36,8 @@ type config struct {
|
|||
|
||||
verifyTransactionClient EthClient
|
||||
|
||||
pushNotificationServerConfig *push_notification_server.Config
|
||||
pushNotificationClientConfig *push_notification_client.Config
|
||||
pushNotificationServerConfig *pushnotificationserver.Config
|
||||
pushNotificationClientConfig *pushnotificationclient.Config
|
||||
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
@ -93,14 +95,14 @@ func WithDatabase(db *sql.DB) Option {
|
|||
}
|
||||
}
|
||||
|
||||
func WithPushNotificationServerConfig(pushNotificationServerConfig *push_notification_server.Config) Option {
|
||||
func WithPushNotificationServerConfig(pushNotificationServerConfig *pushnotificationserver.Config) Option {
|
||||
return func(c *config) error {
|
||||
c.pushNotificationServerConfig = pushNotificationServerConfig
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithPushNotificationClientConfig(pushNotificationClientConfig *push_notification_client.Config) Option {
|
||||
func WithPushNotificationClientConfig(pushNotificationClientConfig *pushnotificationclient.Config) Option {
|
||||
return func(c *config) error {
|
||||
c.pushNotificationClientConfig = pushNotificationClientConfig
|
||||
return nil
|
||||
|
|
|
@ -20,6 +20,8 @@ import (
|
|||
"github.com/status-im/status-go/waku"
|
||||
)
|
||||
|
||||
const statusChatID = "status"
|
||||
|
||||
func TestMessengerInstallationSuite(t *testing.T) {
|
||||
suite.Run(t, new(MessengerInstallationSuite))
|
||||
}
|
||||
|
@ -136,7 +138,7 @@ func (s *MessengerInstallationSuite) TestReceiveInstallation() {
|
|||
s.Require().Equal(contact.ID, actualContact.ID)
|
||||
s.Require().True(actualContact.IsAdded())
|
||||
|
||||
chat := CreatePublicChat("status", s.m.transport)
|
||||
chat := CreatePublicChat(statusChatID, s.m.transport)
|
||||
err = s.m.SaveChat(&chat)
|
||||
s.Require().NoError(err)
|
||||
|
||||
|
@ -149,7 +151,7 @@ func (s *MessengerInstallationSuite) TestReceiveInstallation() {
|
|||
s.Require().NoError(err)
|
||||
|
||||
actualChat := response.Chats[0]
|
||||
s.Require().Equal("status", actualChat.ID)
|
||||
s.Require().Equal(statusChatID, actualChat.ID)
|
||||
s.Require().True(actualChat.Active)
|
||||
}
|
||||
|
||||
|
@ -166,7 +168,7 @@ func (s *MessengerInstallationSuite) TestSyncInstallation() {
|
|||
s.Require().NoError(err)
|
||||
|
||||
// add chat
|
||||
chat := CreatePublicChat("status", s.m.transport)
|
||||
chat := CreatePublicChat(statusChatID, s.m.transport)
|
||||
err = s.m.SaveChat(&chat)
|
||||
s.Require().NoError(err)
|
||||
|
||||
|
@ -230,7 +232,7 @@ func (s *MessengerInstallationSuite) TestSyncInstallation() {
|
|||
|
||||
var statusChat *Chat
|
||||
for _, c := range allChats {
|
||||
if c.ID == "status" {
|
||||
if c.ID == statusChatID {
|
||||
statusChat = c
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
// 1589365189_add_pow_target.up.sql (66B)
|
||||
// 1591277220_add_index_messages.down.sql (237B)
|
||||
// 1591277220_add_index_messages.up.sql (240B)
|
||||
// 1593087212_add_mute_chat.down.sql (0)
|
||||
// 1593087212_add_mute_chat.up.sql (58B)
|
||||
// 1593087212_add_mute_chat_and_raw_message_fields.down.sql (0)
|
||||
// 1593087212_add_mute_chat_and_raw_message_fields.up.sql (215B)
|
||||
// doc.go (850B)
|
||||
|
||||
package migrations
|
||||
|
@ -138,7 +138,7 @@ func _000002_add_last_ens_clock_valueDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "000002_add_last_ens_clock_value.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1584434371, 0)}
|
||||
info := bindataFileInfo{name: "000002_add_last_ens_clock_value.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ func _000002_add_last_ens_clock_valueUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "000002_add_last_ens_clock_value.up.sql", size: 77, mode: os.FileMode(0644), modTime: time.Unix(1584434371, 0)}
|
||||
info := bindataFileInfo{name: "000002_add_last_ens_clock_value.up.sql", size: 77, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x4d, 0x3, 0x8f, 0xd5, 0x85, 0x83, 0x47, 0xbe, 0xf9, 0x82, 0x7e, 0x81, 0xa4, 0xbd, 0xaa, 0xd5, 0x98, 0x18, 0x5, 0x2d, 0x82, 0x42, 0x3b, 0x3, 0x50, 0xc3, 0x1e, 0x84, 0x35, 0xf, 0xb6, 0x2b}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ func _1586358095_add_replaceDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1586358095_add_replace.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1589265610, 0)}
|
||||
info := bindataFileInfo{name: "1586358095_add_replace.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func _1586358095_add_replaceUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1586358095_add_replace.up.sql", size: 224, mode: os.FileMode(0644), modTime: time.Unix(1589265610, 0)}
|
||||
info := bindataFileInfo{name: "1586358095_add_replace.up.sql", size: 224, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd2, 0xb3, 0xa9, 0xc7, 0x7f, 0x9d, 0x8f, 0x43, 0x8c, 0x9e, 0x58, 0x8d, 0x44, 0xbc, 0xfa, 0x6b, 0x5f, 0x3f, 0x5a, 0xbe, 0xe8, 0xb1, 0x16, 0xf, 0x91, 0x2a, 0xa0, 0x71, 0xbb, 0x8d, 0x6b, 0xcb}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ func _1588665364_add_image_dataDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1588665364_add_image_data.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1591690523, 0)}
|
||||
info := bindataFileInfo{name: "1588665364_add_image_data.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ func _1588665364_add_image_dataUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1588665364_add_image_data.up.sql", size: 186, mode: os.FileMode(0644), modTime: time.Unix(1591690523, 0)}
|
||||
info := bindataFileInfo{name: "1588665364_add_image_data.up.sql", size: 186, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd6, 0xc6, 0x35, 0xb4, 0x4c, 0x39, 0x96, 0x29, 0x30, 0xda, 0xf4, 0x8f, 0xcb, 0xf1, 0x9f, 0x84, 0xdc, 0x88, 0xd4, 0xd5, 0xbc, 0xb6, 0x5b, 0x46, 0x78, 0x67, 0x76, 0x1a, 0x5, 0x36, 0xdc, 0xe5}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ func _1589365189_add_pow_targetDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1589365189_add_pow_target.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1591690523, 0)}
|
||||
info := bindataFileInfo{name: "1589365189_add_pow_target.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ func _1589365189_add_pow_targetUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1589365189_add_pow_target.up.sql", size: 66, mode: os.FileMode(0644), modTime: time.Unix(1591690523, 0)}
|
||||
info := bindataFileInfo{name: "1589365189_add_pow_target.up.sql", size: 66, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x4e, 0x3a, 0xe2, 0x2e, 0x7d, 0xaf, 0xbb, 0xcc, 0x21, 0xa1, 0x7a, 0x41, 0x9a, 0xd0, 0xbb, 0xa9, 0xc8, 0x35, 0xf9, 0x32, 0x34, 0x46, 0x44, 0x9a, 0x86, 0x40, 0x7c, 0xb9, 0x23, 0xc7, 0x3, 0x3f}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ func _1591277220_add_index_messagesDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1591277220_add_index_messages.down.sql", size: 237, mode: os.FileMode(0644), modTime: time.Unix(1591690523, 0)}
|
||||
info := bindataFileInfo{name: "1591277220_add_index_messages.down.sql", size: 237, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x79, 0xe5, 0x42, 0x56, 0x64, 0x1d, 0xb7, 0x8a, 0x1b, 0x0, 0x99, 0xf0, 0x18, 0x8c, 0x69, 0xe3, 0x14, 0x3a, 0x7f, 0x78, 0xfe, 0xe3, 0x2e, 0xcb, 0x6e, 0x5c, 0x8c, 0x1f, 0x7b, 0xfc, 0x21, 0xc7}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -318,48 +318,48 @@ func _1591277220_add_index_messagesUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1591277220_add_index_messages.up.sql", size: 240, mode: os.FileMode(0644), modTime: time.Unix(1591690523, 0)}
|
||||
info := bindataFileInfo{name: "1591277220_add_index_messages.up.sql", size: 240, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9c, 0xfe, 0xbe, 0xd5, 0xb8, 0x8f, 0xdd, 0xef, 0xbb, 0xa8, 0xad, 0x7f, 0xed, 0x5b, 0x5b, 0x2f, 0xe6, 0x82, 0x27, 0x78, 0x1f, 0xb9, 0x57, 0xdc, 0x8, 0xc2, 0xb2, 0xa9, 0x9a, 0x4, 0xe1, 0x7a}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __1593087212_add_mute_chatDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00")
|
||||
var __1593087212_add_mute_chat_and_raw_message_fieldsDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00")
|
||||
|
||||
func _1593087212_add_mute_chatDownSqlBytes() ([]byte, error) {
|
||||
func _1593087212_add_mute_chat_and_raw_message_fieldsDownSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__1593087212_add_mute_chatDownSql,
|
||||
"1593087212_add_mute_chat.down.sql",
|
||||
__1593087212_add_mute_chat_and_raw_message_fieldsDownSql,
|
||||
"1593087212_add_mute_chat_and_raw_message_fields.down.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _1593087212_add_mute_chatDownSql() (*asset, error) {
|
||||
bytes, err := _1593087212_add_mute_chatDownSqlBytes()
|
||||
func _1593087212_add_mute_chat_and_raw_message_fieldsDownSql() (*asset, error) {
|
||||
bytes, err := _1593087212_add_mute_chat_and_raw_message_fieldsDownSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1593087212_add_mute_chat.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1594896559, 0)}
|
||||
info := bindataFileInfo{name: "1593087212_add_mute_chat_and_raw_message_fields.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1595832279, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __1593087212_add_mute_chatUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\xf4\x09\x71\x0d\x52\x08\x71\x74\xf2\x71\x55\x48\xce\x48\x2c\x29\x56\x70\x74\x71\x51\x70\xf6\xf7\x09\xf5\xf5\x53\xc8\x2d\x2d\x49\x4d\x51\x70\xf2\xf7\xf7\x71\x75\xf4\x53\x70\x71\x75\x73\x0c\xf5\x09\x51\x70\x73\xf4\x09\x76\xb5\xe6\x02\x04\x00\x00\xff\xff\x59\x4c\x4b\xec\x3a\x00\x00\x00")
|
||||
var __1593087212_add_mute_chat_and_raw_message_fieldsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\xcc\x31\x0e\xc2\x30\x0c\x00\xc0\x9d\x57\xf8\x1f\x4c\x2e\x71\x27\xd3\x48\x90\xce\x51\x94\x1a\x1a\xa1\xa6\x51\xed\x0a\xf1\x7b\x56\x58\x58\x78\xc0\x1d\x72\xa0\x0b\x04\xec\x98\x20\xcf\xc9\x14\xd0\x39\x38\x79\x1e\xcf\x03\x2c\xbb\xc9\x04\x9d\xf7\x4c\x38\x80\xa3\x1e\x47\x0e\xd0\x23\x5f\xe9\x78\xf8\x94\x5b\x7a\xc6\x45\x54\xd3\x5d\xbe\x02\x7d\x94\x16\xa5\xe6\xed\xd5\xac\xac\xf5\xaf\x4a\xea\x14\xdb\xae\x73\xac\xab\x95\x5b\xc9\xe9\xd7\xf8\x0e\x00\x00\xff\xff\xd9\x47\x38\x58\xd7\x00\x00\x00")
|
||||
|
||||
func _1593087212_add_mute_chatUpSqlBytes() ([]byte, error) {
|
||||
func _1593087212_add_mute_chat_and_raw_message_fieldsUpSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__1593087212_add_mute_chatUpSql,
|
||||
"1593087212_add_mute_chat.up.sql",
|
||||
__1593087212_add_mute_chat_and_raw_message_fieldsUpSql,
|
||||
"1593087212_add_mute_chat_and_raw_message_fields.up.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _1593087212_add_mute_chatUpSql() (*asset, error) {
|
||||
bytes, err := _1593087212_add_mute_chatUpSqlBytes()
|
||||
func _1593087212_add_mute_chat_and_raw_message_fieldsUpSql() (*asset, error) {
|
||||
bytes, err := _1593087212_add_mute_chat_and_raw_message_fieldsUpSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1593087212_add_mute_chat.up.sql", size: 58, mode: os.FileMode(0644), modTime: time.Unix(1594896559, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe, 0x9, 0xa0, 0x4a, 0x8e, 0x23, 0xe4, 0xce, 0xbc, 0xd4, 0x9, 0xeb, 0xf9, 0x67, 0x90, 0xc0, 0x4b, 0x67, 0x84, 0xe4, 0x42, 0x8d, 0x0, 0x17, 0x29, 0x7f, 0x12, 0xbf, 0x7d, 0x4e, 0x78, 0xec}}
|
||||
info := bindataFileInfo{name: "1593087212_add_mute_chat_and_raw_message_fields.up.sql", size: 215, mode: os.FileMode(0644), modTime: time.Unix(1595832279, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x73, 0x99, 0x61, 0xd1, 0xaa, 0xb4, 0xbf, 0xaf, 0xd7, 0x20, 0x17, 0x40, 0xf9, 0x2, 0xfb, 0xcc, 0x40, 0x2a, 0xd, 0x86, 0x36, 0x30, 0x88, 0x89, 0x25, 0x80, 0x42, 0xb0, 0x5b, 0xe9, 0x73, 0x78}}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
|
@ -378,7 +378,7 @@ func docGo() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "doc.go", size: 850, mode: os.FileMode(0644), modTime: time.Unix(1589265610, 0)}
|
||||
info := bindataFileInfo{name: "doc.go", size: 850, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa0, 0xcc, 0x41, 0xe1, 0x61, 0x12, 0x97, 0xe, 0x36, 0x8c, 0xa7, 0x9e, 0xe0, 0x6e, 0x59, 0x9e, 0xee, 0xd5, 0x4a, 0xcf, 0x1e, 0x60, 0xd6, 0xc3, 0x3a, 0xc9, 0x6c, 0xf2, 0x86, 0x5a, 0xb4, 0x1e}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -498,9 +498,9 @@ var _bindata = map[string]func() (*asset, error){
|
|||
|
||||
"1591277220_add_index_messages.up.sql": _1591277220_add_index_messagesUpSql,
|
||||
|
||||
"1593087212_add_mute_chat.down.sql": _1593087212_add_mute_chatDownSql,
|
||||
"1593087212_add_mute_chat_and_raw_message_fields.down.sql": _1593087212_add_mute_chat_and_raw_message_fieldsDownSql,
|
||||
|
||||
"1593087212_add_mute_chat.up.sql": _1593087212_add_mute_chatUpSql,
|
||||
"1593087212_add_mute_chat_and_raw_message_fields.up.sql": _1593087212_add_mute_chat_and_raw_message_fieldsUpSql,
|
||||
|
||||
"doc.go": docGo,
|
||||
}
|
||||
|
@ -558,8 +558,8 @@ var _bintree = &bintree{nil, map[string]*bintree{
|
|||
"1589365189_add_pow_target.up.sql": &bintree{_1589365189_add_pow_targetUpSql, map[string]*bintree{}},
|
||||
"1591277220_add_index_messages.down.sql": &bintree{_1591277220_add_index_messagesDownSql, map[string]*bintree{}},
|
||||
"1591277220_add_index_messages.up.sql": &bintree{_1591277220_add_index_messagesUpSql, map[string]*bintree{}},
|
||||
"1593087212_add_mute_chat.down.sql": &bintree{_1593087212_add_mute_chatDownSql, map[string]*bintree{}},
|
||||
"1593087212_add_mute_chat.up.sql": &bintree{_1593087212_add_mute_chatUpSql, map[string]*bintree{}},
|
||||
"1593087212_add_mute_chat_and_raw_message_fields.down.sql": &bintree{_1593087212_add_mute_chat_and_raw_message_fieldsDownSql, map[string]*bintree{}},
|
||||
"1593087212_add_mute_chat_and_raw_message_fields.up.sql": &bintree{_1593087212_add_mute_chat_and_raw_message_fieldsUpSql, map[string]*bintree{}},
|
||||
"doc.go": &bintree{docGo, map[string]*bintree{}},
|
||||
}}
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
ALTER TABLE chats ADD COLUMN muted BOOLEAN DEFAULT FALSE;
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE chats ADD COLUMN muted BOOLEAN DEFAULT FALSE;
|
||||
ALTER TABLE raw_messages ADD COLUMN skip_encryption BOOLEAN DEFAULT FALSE;
|
||||
ALTER TABLE raw_messages ADD COLUMN send_push_notification BOOLEAN DEFAULT FALSE;
|
|
@ -7,9 +7,9 @@ import (
|
|||
"encoding/gob"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -403,9 +403,11 @@ func (db sqlitePersistence) SaveRawMessage(message *common.RawMessage) error {
|
|||
message_type,
|
||||
resend_automatically,
|
||||
recipients,
|
||||
skip_encryption,
|
||||
send_push_notification,
|
||||
payload
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
message.ID,
|
||||
message.LocalChatID,
|
||||
message.LastSent,
|
||||
|
@ -414,6 +416,8 @@ func (db sqlitePersistence) SaveRawMessage(message *common.RawMessage) error {
|
|||
message.MessageType,
|
||||
message.ResendAutomatically,
|
||||
encodedRecipients.Bytes(),
|
||||
message.SkipEncryption,
|
||||
message.SendPushNotification,
|
||||
message.Payload)
|
||||
return err
|
||||
}
|
||||
|
@ -433,6 +437,8 @@ func (db sqlitePersistence) RawMessageByID(id string) (*common.RawMessage, error
|
|||
message_type,
|
||||
resend_automatically,
|
||||
recipients,
|
||||
skip_encryption,
|
||||
send_push_notification,
|
||||
payload
|
||||
FROM
|
||||
raw_messages
|
||||
|
@ -448,6 +454,8 @@ func (db sqlitePersistence) RawMessageByID(id string) (*common.RawMessage, error
|
|||
&message.MessageType,
|
||||
&message.ResendAutomatically,
|
||||
&encodedRecipients,
|
||||
&message.SkipEncryption,
|
||||
&message.SendPushNotification,
|
||||
&message.Payload,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
@ -110,17 +110,17 @@ func (x PushNotificationReport_ErrorType) String() string {
|
|||
}
|
||||
|
||||
func (PushNotificationReport_ErrorType) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{9, 0}
|
||||
return fileDescriptor_200acd86044eaa5d, []int{8, 0}
|
||||
}
|
||||
|
||||
type PushNotificationRegistration struct {
|
||||
TokenType PushNotificationRegistration_TokenType `protobuf:"varint,1,opt,name=token_type,json=tokenType,proto3,enum=protobuf.PushNotificationRegistration_TokenType" json:"token_type,omitempty"`
|
||||
Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"`
|
||||
DeviceToken string `protobuf:"bytes,2,opt,name=device_token,json=deviceToken,proto3" json:"device_token,omitempty"`
|
||||
InstallationId string `protobuf:"bytes,3,opt,name=installation_id,json=installationId,proto3" json:"installation_id,omitempty"`
|
||||
AccessToken string `protobuf:"bytes,4,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
|
||||
Enabled bool `protobuf:"varint,5,opt,name=enabled,proto3" json:"enabled,omitempty"`
|
||||
Version uint64 `protobuf:"varint,6,opt,name=version,proto3" json:"version,omitempty"`
|
||||
AllowedUserList [][]byte `protobuf:"bytes,7,rep,name=allowed_user_list,json=allowedUserList,proto3" json:"allowed_user_list,omitempty"`
|
||||
AllowedKeyList [][]byte `protobuf:"bytes,7,rep,name=allowed_key_list,json=allowedKeyList,proto3" json:"allowed_key_list,omitempty"`
|
||||
BlockedChatList [][]byte `protobuf:"bytes,8,rep,name=blocked_chat_list,json=blockedChatList,proto3" json:"blocked_chat_list,omitempty"`
|
||||
Unregister bool `protobuf:"varint,9,opt,name=unregister,proto3" json:"unregister,omitempty"`
|
||||
Grant []byte `protobuf:"bytes,10,opt,name=grant,proto3" json:"grant,omitempty"`
|
||||
|
@ -162,9 +162,9 @@ func (m *PushNotificationRegistration) GetTokenType() PushNotificationRegistrati
|
|||
return PushNotificationRegistration_UNKNOWN_TOKEN_TYPE
|
||||
}
|
||||
|
||||
func (m *PushNotificationRegistration) GetToken() string {
|
||||
func (m *PushNotificationRegistration) GetDeviceToken() string {
|
||||
if m != nil {
|
||||
return m.Token
|
||||
return m.DeviceToken
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -197,9 +197,9 @@ func (m *PushNotificationRegistration) GetVersion() uint64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
func (m *PushNotificationRegistration) GetAllowedUserList() [][]byte {
|
||||
func (m *PushNotificationRegistration) GetAllowedKeyList() [][]byte {
|
||||
if m != nil {
|
||||
return m.AllowedUserList
|
||||
return m.AllowedKeyList
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -287,63 +287,8 @@ func (m *PushNotificationRegistrationResponse) GetRequestId() []byte {
|
|||
return nil
|
||||
}
|
||||
|
||||
type PushNotificationAdvertisementInfo struct {
|
||||
PublicKey []byte `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"`
|
||||
AccessToken string `protobuf:"bytes,2,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
|
||||
InstallationId string `protobuf:"bytes,3,opt,name=installation_id,json=installationId,proto3" json:"installation_id,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *PushNotificationAdvertisementInfo) Reset() { *m = PushNotificationAdvertisementInfo{} }
|
||||
func (m *PushNotificationAdvertisementInfo) String() string { return proto.CompactTextString(m) }
|
||||
func (*PushNotificationAdvertisementInfo) ProtoMessage() {}
|
||||
func (*PushNotificationAdvertisementInfo) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{2}
|
||||
}
|
||||
|
||||
func (m *PushNotificationAdvertisementInfo) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_PushNotificationAdvertisementInfo.Unmarshal(m, b)
|
||||
}
|
||||
func (m *PushNotificationAdvertisementInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_PushNotificationAdvertisementInfo.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *PushNotificationAdvertisementInfo) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_PushNotificationAdvertisementInfo.Merge(m, src)
|
||||
}
|
||||
func (m *PushNotificationAdvertisementInfo) XXX_Size() int {
|
||||
return xxx_messageInfo_PushNotificationAdvertisementInfo.Size(m)
|
||||
}
|
||||
func (m *PushNotificationAdvertisementInfo) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_PushNotificationAdvertisementInfo.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_PushNotificationAdvertisementInfo proto.InternalMessageInfo
|
||||
|
||||
func (m *PushNotificationAdvertisementInfo) GetPublicKey() []byte {
|
||||
if m != nil {
|
||||
return m.PublicKey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PushNotificationAdvertisementInfo) GetAccessToken() string {
|
||||
if m != nil {
|
||||
return m.AccessToken
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *PushNotificationAdvertisementInfo) GetInstallationId() string {
|
||||
if m != nil {
|
||||
return m.InstallationId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ContactCodeAdvertisement struct {
|
||||
PushNotificationInfo []*PushNotificationAdvertisementInfo `protobuf:"bytes,1,rep,name=push_notification_info,json=pushNotificationInfo,proto3" json:"push_notification_info,omitempty"`
|
||||
PushNotificationInfo []*PushNotificationQueryInfo `protobuf:"bytes,1,rep,name=push_notification_info,json=pushNotificationInfo,proto3" json:"push_notification_info,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
|
@ -353,7 +298,7 @@ func (m *ContactCodeAdvertisement) Reset() { *m = ContactCodeAdvertiseme
|
|||
func (m *ContactCodeAdvertisement) String() string { return proto.CompactTextString(m) }
|
||||
func (*ContactCodeAdvertisement) ProtoMessage() {}
|
||||
func (*ContactCodeAdvertisement) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{3}
|
||||
return fileDescriptor_200acd86044eaa5d, []int{2}
|
||||
}
|
||||
|
||||
func (m *ContactCodeAdvertisement) XXX_Unmarshal(b []byte) error {
|
||||
|
@ -374,7 +319,7 @@ func (m *ContactCodeAdvertisement) XXX_DiscardUnknown() {
|
|||
|
||||
var xxx_messageInfo_ContactCodeAdvertisement proto.InternalMessageInfo
|
||||
|
||||
func (m *ContactCodeAdvertisement) GetPushNotificationInfo() []*PushNotificationAdvertisementInfo {
|
||||
func (m *ContactCodeAdvertisement) GetPushNotificationInfo() []*PushNotificationQueryInfo {
|
||||
if m != nil {
|
||||
return m.PushNotificationInfo
|
||||
}
|
||||
|
@ -392,7 +337,7 @@ func (m *PushNotificationQuery) Reset() { *m = PushNotificationQuery{} }
|
|||
func (m *PushNotificationQuery) String() string { return proto.CompactTextString(m) }
|
||||
func (*PushNotificationQuery) ProtoMessage() {}
|
||||
func (*PushNotificationQuery) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{4}
|
||||
return fileDescriptor_200acd86044eaa5d, []int{3}
|
||||
}
|
||||
|
||||
func (m *PushNotificationQuery) XXX_Unmarshal(b []byte) error {
|
||||
|
@ -424,9 +369,10 @@ type PushNotificationQueryInfo struct {
|
|||
AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
|
||||
InstallationId string `protobuf:"bytes,2,opt,name=installation_id,json=installationId,proto3" json:"installation_id,omitempty"`
|
||||
PublicKey []byte `protobuf:"bytes,3,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"`
|
||||
AllowedUserList [][]byte `protobuf:"bytes,4,rep,name=allowed_user_list,json=allowedUserList,proto3" json:"allowed_user_list,omitempty"`
|
||||
AllowedKeyList [][]byte `protobuf:"bytes,4,rep,name=allowed_key_list,json=allowedKeyList,proto3" json:"allowed_key_list,omitempty"`
|
||||
Grant []byte `protobuf:"bytes,5,opt,name=grant,proto3" json:"grant,omitempty"`
|
||||
Version uint64 `protobuf:"varint,6,opt,name=version,proto3" json:"version,omitempty"`
|
||||
ServerPublicKey []byte `protobuf:"bytes,7,opt,name=server_public_key,json=serverPublicKey,proto3" json:"server_public_key,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
|
@ -436,7 +382,7 @@ func (m *PushNotificationQueryInfo) Reset() { *m = PushNotificationQuery
|
|||
func (m *PushNotificationQueryInfo) String() string { return proto.CompactTextString(m) }
|
||||
func (*PushNotificationQueryInfo) ProtoMessage() {}
|
||||
func (*PushNotificationQueryInfo) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{5}
|
||||
return fileDescriptor_200acd86044eaa5d, []int{4}
|
||||
}
|
||||
|
||||
func (m *PushNotificationQueryInfo) XXX_Unmarshal(b []byte) error {
|
||||
|
@ -478,9 +424,9 @@ func (m *PushNotificationQueryInfo) GetPublicKey() []byte {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *PushNotificationQueryInfo) GetAllowedUserList() [][]byte {
|
||||
func (m *PushNotificationQueryInfo) GetAllowedKeyList() [][]byte {
|
||||
if m != nil {
|
||||
return m.AllowedUserList
|
||||
return m.AllowedKeyList
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -499,6 +445,13 @@ func (m *PushNotificationQueryInfo) GetVersion() uint64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
func (m *PushNotificationQueryInfo) GetServerPublicKey() []byte {
|
||||
if m != nil {
|
||||
return m.ServerPublicKey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type PushNotificationQueryResponse struct {
|
||||
Info []*PushNotificationQueryInfo `protobuf:"bytes,1,rep,name=info,proto3" json:"info,omitempty"`
|
||||
MessageId []byte `protobuf:"bytes,2,opt,name=message_id,json=messageId,proto3" json:"message_id,omitempty"`
|
||||
|
@ -512,7 +465,7 @@ func (m *PushNotificationQueryResponse) Reset() { *m = PushNotificationQ
|
|||
func (m *PushNotificationQueryResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*PushNotificationQueryResponse) ProtoMessage() {}
|
||||
func (*PushNotificationQueryResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{6}
|
||||
return fileDescriptor_200acd86044eaa5d, []int{5}
|
||||
}
|
||||
|
||||
func (m *PushNotificationQueryResponse) XXX_Unmarshal(b []byte) error {
|
||||
|
@ -569,7 +522,7 @@ func (m *PushNotification) Reset() { *m = PushNotification{} }
|
|||
func (m *PushNotification) String() string { return proto.CompactTextString(m) }
|
||||
func (*PushNotification) ProtoMessage() {}
|
||||
func (*PushNotification) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{7}
|
||||
return fileDescriptor_200acd86044eaa5d, []int{6}
|
||||
}
|
||||
|
||||
func (m *PushNotification) XXX_Unmarshal(b []byte) error {
|
||||
|
@ -637,7 +590,7 @@ func (m *PushNotificationRequest) Reset() { *m = PushNotificationRequest
|
|||
func (m *PushNotificationRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*PushNotificationRequest) ProtoMessage() {}
|
||||
func (*PushNotificationRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{8}
|
||||
return fileDescriptor_200acd86044eaa5d, []int{7}
|
||||
}
|
||||
|
||||
func (m *PushNotificationRequest) XXX_Unmarshal(b []byte) error {
|
||||
|
@ -686,7 +639,7 @@ func (m *PushNotificationReport) Reset() { *m = PushNotificationReport{}
|
|||
func (m *PushNotificationReport) String() string { return proto.CompactTextString(m) }
|
||||
func (*PushNotificationReport) ProtoMessage() {}
|
||||
func (*PushNotificationReport) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{9}
|
||||
return fileDescriptor_200acd86044eaa5d, []int{8}
|
||||
}
|
||||
|
||||
func (m *PushNotificationReport) XXX_Unmarshal(b []byte) error {
|
||||
|
@ -747,7 +700,7 @@ func (m *PushNotificationResponse) Reset() { *m = PushNotificationRespon
|
|||
func (m *PushNotificationResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*PushNotificationResponse) ProtoMessage() {}
|
||||
func (*PushNotificationResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_200acd86044eaa5d, []int{10}
|
||||
return fileDescriptor_200acd86044eaa5d, []int{9}
|
||||
}
|
||||
|
||||
func (m *PushNotificationResponse) XXX_Unmarshal(b []byte) error {
|
||||
|
@ -788,7 +741,6 @@ func init() {
|
|||
proto.RegisterEnum("protobuf.PushNotificationReport_ErrorType", PushNotificationReport_ErrorType_name, PushNotificationReport_ErrorType_value)
|
||||
proto.RegisterType((*PushNotificationRegistration)(nil), "protobuf.PushNotificationRegistration")
|
||||
proto.RegisterType((*PushNotificationRegistrationResponse)(nil), "protobuf.PushNotificationRegistrationResponse")
|
||||
proto.RegisterType((*PushNotificationAdvertisementInfo)(nil), "protobuf.PushNotificationAdvertisementInfo")
|
||||
proto.RegisterType((*ContactCodeAdvertisement)(nil), "protobuf.ContactCodeAdvertisement")
|
||||
proto.RegisterType((*PushNotificationQuery)(nil), "protobuf.PushNotificationQuery")
|
||||
proto.RegisterType((*PushNotificationQueryInfo)(nil), "protobuf.PushNotificationQueryInfo")
|
||||
|
@ -802,61 +754,60 @@ func init() {
|
|||
func init() { proto.RegisterFile("push_notifications.proto", fileDescriptor_200acd86044eaa5d) }
|
||||
|
||||
var fileDescriptor_200acd86044eaa5d = []byte{
|
||||
// 891 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0xdd, 0x6e, 0xe3, 0x44,
|
||||
0x14, 0xc7, 0xb1, 0x93, 0xb6, 0xf1, 0x49, 0x68, 0xb3, 0xa3, 0xb6, 0x6b, 0x56, 0x2c, 0x64, 0x0d,
|
||||
0x12, 0xd1, 0x22, 0x45, 0xa8, 0x48, 0xec, 0x8a, 0x2b, 0x42, 0xeb, 0x16, 0xab, 0x8d, 0x1d, 0x26,
|
||||
0x2e, 0x2b, 0x24, 0x24, 0xcb, 0x89, 0x27, 0xad, 0x55, 0xd7, 0x63, 0x66, 0xc6, 0x8b, 0x72, 0x81,
|
||||
0xc4, 0x13, 0x20, 0x21, 0x71, 0xc5, 0x53, 0x20, 0x1e, 0x89, 0x27, 0x41, 0x1e, 0xdb, 0xc1, 0xf9,
|
||||
0x68, 0x9a, 0x8b, 0xbd, 0x8a, 0xcf, 0x99, 0x73, 0x66, 0xe6, 0xfc, 0xce, 0x99, 0x7f, 0x40, 0x4f,
|
||||
0x52, 0x7e, 0xeb, 0xc5, 0x54, 0x84, 0xd3, 0x70, 0xe2, 0x8b, 0x90, 0xc6, 0xbc, 0x97, 0x30, 0x2a,
|
||||
0x28, 0x6a, 0xc8, 0x9f, 0x71, 0x3a, 0x35, 0xfe, 0xac, 0xc3, 0x87, 0xc3, 0x94, 0xdf, 0xda, 0x95,
|
||||
0x28, 0x4c, 0x6e, 0x42, 0x2e, 0x98, 0xfc, 0x46, 0x0e, 0x80, 0xa0, 0x77, 0x24, 0xf6, 0xc4, 0x2c,
|
||||
0x21, 0xba, 0xd2, 0x51, 0xba, 0xfb, 0x27, 0x5f, 0xf4, 0xca, 0xfc, 0xde, 0xa6, 0xdc, 0x9e, 0x9b,
|
||||
0x25, 0xba, 0xb3, 0x84, 0x60, 0x4d, 0x94, 0x9f, 0xe8, 0x10, 0x76, 0xa4, 0xa1, 0xab, 0x1d, 0xa5,
|
||||
0xab, 0xe1, 0xdc, 0x40, 0x9f, 0xc1, 0x41, 0x18, 0x73, 0xe1, 0x47, 0x91, 0x4c, 0xf5, 0xc2, 0x40,
|
||||
0xaf, 0xc9, 0xf5, 0xfd, 0xaa, 0xdb, 0x0a, 0xd0, 0x0b, 0x68, 0xf9, 0x93, 0x09, 0xe1, 0xdc, 0xcb,
|
||||
0x77, 0xa9, 0xcb, 0xa8, 0x66, 0xee, 0x93, 0x07, 0x22, 0x1d, 0xf6, 0x48, 0xec, 0x8f, 0x23, 0x12,
|
||||
0xe8, 0x3b, 0x1d, 0xa5, 0xdb, 0xc0, 0xa5, 0x99, 0xad, 0xbc, 0x25, 0x8c, 0x87, 0x34, 0xd6, 0x77,
|
||||
0x3b, 0x4a, 0xb7, 0x8e, 0x4b, 0x13, 0xbd, 0x84, 0x27, 0x7e, 0x14, 0xd1, 0x5f, 0x48, 0xe0, 0xa5,
|
||||
0x9c, 0x30, 0x2f, 0x0a, 0xb9, 0xd0, 0xf7, 0x3a, 0xb5, 0x6e, 0x0b, 0x1f, 0x14, 0x0b, 0xd7, 0x9c,
|
||||
0xb0, 0xab, 0x90, 0x8b, 0x2c, 0x76, 0x1c, 0xd1, 0xc9, 0x1d, 0x09, 0xbc, 0xc9, 0xad, 0x2f, 0xf2,
|
||||
0xd8, 0x46, 0x1e, 0x5b, 0x2c, 0x9c, 0xde, 0xfa, 0x42, 0xc6, 0x7e, 0x04, 0x90, 0xc6, 0x4c, 0x42,
|
||||
0x21, 0x4c, 0xd7, 0xe4, 0x75, 0x2a, 0x9e, 0x8c, 0xc6, 0x0d, 0xf3, 0x63, 0xa1, 0x43, 0x47, 0xe9,
|
||||
0xb6, 0x70, 0x6e, 0xa0, 0x57, 0xa0, 0xcb, 0x43, 0xbd, 0x29, 0xa3, 0xf7, 0xde, 0x84, 0xc6, 0xc2,
|
||||
0x9f, 0x08, 0xee, 0xd1, 0x38, 0x9a, 0xe9, 0x4d, 0xb9, 0xc7, 0x91, 0x5c, 0x3f, 0x67, 0xf4, 0xfe,
|
||||
0xb4, 0x58, 0x75, 0xe2, 0x68, 0x66, 0x9c, 0x83, 0x36, 0x87, 0x8e, 0x8e, 0x01, 0x5d, 0xdb, 0x97,
|
||||
0xb6, 0xf3, 0xc6, 0xf6, 0x5c, 0xe7, 0xd2, 0xb4, 0x3d, 0xf7, 0xc7, 0xa1, 0xd9, 0x7e, 0x0f, 0xbd,
|
||||
0x0f, 0x5a, 0x7f, 0x58, 0xf8, 0xda, 0x0a, 0x42, 0xb0, 0x7f, 0x6e, 0x61, 0xf3, 0xdb, 0xfe, 0xc8,
|
||||
0x2c, 0x7c, 0xaa, 0xf1, 0x8f, 0x0a, 0x9f, 0x6e, 0x6a, 0x2d, 0x26, 0x3c, 0xa1, 0x31, 0x27, 0x19,
|
||||
0x51, 0x9e, 0x4a, 0xf6, 0x72, 0x36, 0x1a, 0xb8, 0x34, 0x91, 0x0d, 0x3b, 0x84, 0x31, 0xca, 0x64,
|
||||
0x9f, 0xf7, 0x4f, 0x5e, 0x6f, 0x37, 0x33, 0xe5, 0xc6, 0x3d, 0x33, 0xcb, 0x95, 0xb3, 0x93, 0x6f,
|
||||
0x83, 0x9e, 0x03, 0x30, 0xf2, 0x73, 0x4a, 0xb8, 0x28, 0x87, 0xa3, 0x85, 0xb5, 0xc2, 0x63, 0x05,
|
||||
0xc6, 0x6f, 0x0a, 0x68, 0xf3, 0x9c, 0x6a, 0xe9, 0x26, 0xc6, 0x0e, 0x2e, 0x4b, 0x3f, 0x82, 0x27,
|
||||
0x83, 0xfe, 0xd5, 0xb9, 0x83, 0x07, 0xe6, 0x99, 0x37, 0x30, 0x47, 0xa3, 0xfe, 0x85, 0xd9, 0x56,
|
||||
0xd0, 0x21, 0xb4, 0x7f, 0x30, 0xf1, 0xc8, 0x72, 0x6c, 0x6f, 0x60, 0x8d, 0x06, 0x7d, 0xf7, 0xf4,
|
||||
0xbb, 0xb6, 0x8a, 0x9e, 0xc1, 0xf1, 0xb5, 0x3d, 0xba, 0x1e, 0x0e, 0x1d, 0xec, 0x9a, 0x67, 0x55,
|
||||
0x86, 0xb5, 0x0c, 0x9a, 0x65, 0xbb, 0x26, 0xb6, 0xfb, 0x57, 0xf9, 0x09, 0xed, 0xba, 0xf1, 0xbb,
|
||||
0x02, 0x2f, 0x96, 0x6b, 0xeb, 0x07, 0x6f, 0x09, 0x13, 0x21, 0x27, 0xf7, 0x24, 0x16, 0x56, 0x3c,
|
||||
0xa5, 0x59, 0x1d, 0x49, 0x3a, 0x8e, 0xc2, 0x89, 0x77, 0x47, 0x66, 0x12, 0x5a, 0x0b, 0x6b, 0xb9,
|
||||
0xe7, 0x92, 0xcc, 0x56, 0xe6, 0x5b, 0x5d, 0x9d, 0xef, 0x6d, 0xdf, 0x8a, 0xf1, 0x2b, 0xe8, 0xc5,
|
||||
0x74, 0x9c, 0xd2, 0x80, 0x2c, 0x5c, 0x05, 0xf9, 0x70, 0xbc, 0x22, 0x0f, 0x5e, 0x18, 0x4f, 0xa9,
|
||||
0xae, 0x74, 0x6a, 0xdd, 0xe6, 0xc9, 0xe7, 0x0f, 0xf7, 0x6b, 0xa5, 0x26, 0x7c, 0x98, 0x2c, 0x85,
|
||||
0x64, 0x5e, 0xe3, 0x35, 0x1c, 0x2d, 0xa7, 0x7e, 0x9f, 0x12, 0x36, 0x43, 0x1f, 0x43, 0xf3, 0x7f,
|
||||
0x04, 0x5c, 0x1e, 0xd8, 0xc2, 0x30, 0x67, 0xc0, 0x8d, 0x7f, 0x15, 0xf8, 0x60, 0x6d, 0xaa, 0x24,
|
||||
0xb8, 0x8c, 0x48, 0xd9, 0x0a, 0x91, 0xba, 0x56, 0x4e, 0x16, 0xbb, 0x51, 0x5b, 0xee, 0xc6, 0x5a,
|
||||
0x59, 0xa8, 0xaf, 0x97, 0x85, 0xf9, 0x53, 0xde, 0xa9, 0x3e, 0xe5, 0x07, 0x25, 0xc7, 0xf8, 0x43,
|
||||
0x81, 0xe7, 0x6b, 0x8b, 0x9c, 0x3f, 0xae, 0x57, 0x50, 0xaf, 0x74, 0xe4, 0x93, 0x87, 0x3b, 0x32,
|
||||
0x67, 0x83, 0x65, 0x42, 0x56, 0xd5, 0x3d, 0xe1, 0xdc, 0xbf, 0x21, 0x65, 0xe5, 0x2d, 0xac, 0x15,
|
||||
0x1e, 0x2b, 0xa8, 0x3e, 0xda, 0xda, 0xc2, 0xa3, 0x35, 0xfe, 0x56, 0xa0, 0xbd, 0xbc, 0xf9, 0x36,
|
||||
0xbc, 0x9f, 0xc2, 0x9e, 0x94, 0xc2, 0x39, 0xe7, 0xdd, 0xcc, 0x7c, 0x9c, 0xef, 0x9a, 0x3e, 0xd5,
|
||||
0xd7, 0xf6, 0x49, 0x87, 0xbd, 0xe2, 0xfe, 0x05, 0xde, 0xd2, 0x34, 0x12, 0x78, 0xba, 0x2a, 0x28,
|
||||
0x52, 0x15, 0xd0, 0x57, 0xd0, 0x28, 0x04, 0x82, 0x17, 0x0c, 0x9f, 0x6d, 0x50, 0xa1, 0x79, 0xec,
|
||||
0x23, 0xf8, 0x8c, 0xbf, 0x54, 0x38, 0x5e, 0x3d, 0x32, 0xa1, 0x4c, 0x6c, 0x90, 0xc3, 0x6f, 0x16,
|
||||
0xe5, 0xf0, 0xe5, 0x26, 0x39, 0xcc, 0xb6, 0x5a, 0x2b, 0x80, 0xef, 0x02, 0xa5, 0xf1, 0xd3, 0x36,
|
||||
0x42, 0x79, 0x00, 0xcd, 0x37, 0xd8, 0xb1, 0x2f, 0xaa, 0xff, 0x12, 0x4b, 0x82, 0xa7, 0x66, 0x3e,
|
||||
0xdb, 0x71, 0x3d, 0x6c, 0x5e, 0x58, 0x23, 0xd7, 0xc4, 0xe6, 0x59, 0xbb, 0x66, 0xa4, 0xa0, 0xaf,
|
||||
0x16, 0x54, 0xcc, 0xf3, 0x22, 0x57, 0x65, 0x79, 0x2c, 0xbf, 0x86, 0x3d, 0x26, 0x6b, 0xe7, 0xba,
|
||||
0x2a, 0xbb, 0xd5, 0x79, 0x0c, 0x12, 0x2e, 0x13, 0xc6, 0xbb, 0x32, 0xf2, 0xcb, 0xff, 0x02, 0x00,
|
||||
0x00, 0xff, 0xff, 0x90, 0x90, 0x1b, 0xe9, 0xf4, 0x08, 0x00, 0x00,
|
||||
// 878 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x41, 0x6f, 0xeb, 0x44,
|
||||
0x17, 0xfd, 0x9c, 0xa4, 0x4d, 0x72, 0x93, 0x2f, 0x4d, 0x47, 0x6d, 0x9f, 0x79, 0xa2, 0x10, 0x0c,
|
||||
0x12, 0x51, 0x17, 0x11, 0x2a, 0x12, 0xef, 0x89, 0x15, 0xa1, 0x75, 0x8b, 0xd5, 0xc6, 0x0e, 0x13,
|
||||
0x97, 0xa7, 0x27, 0x21, 0x59, 0x8e, 0x3d, 0x69, 0xad, 0xba, 0x1e, 0x33, 0x33, 0x2e, 0xca, 0x8e,
|
||||
0x1f, 0xc0, 0x86, 0x2d, 0x1b, 0xfe, 0x02, 0xe2, 0x17, 0x22, 0x8f, 0xed, 0xe0, 0x36, 0x6e, 0x5a,
|
||||
0x24, 0x56, 0xf6, 0x9c, 0xb9, 0xf7, 0xce, 0xcc, 0x39, 0xf7, 0x5c, 0x50, 0xe3, 0x84, 0xdf, 0x38,
|
||||
0x11, 0x15, 0xc1, 0x22, 0xf0, 0x5c, 0x11, 0xd0, 0x88, 0x8f, 0x62, 0x46, 0x05, 0x45, 0x2d, 0xf9,
|
||||
0x99, 0x27, 0x0b, 0xed, 0x8f, 0x06, 0x7c, 0x38, 0x4d, 0xf8, 0x8d, 0x59, 0x8a, 0xc2, 0xe4, 0x3a,
|
||||
0xe0, 0x82, 0xc9, 0x7f, 0x64, 0x01, 0x08, 0x7a, 0x4b, 0x22, 0x47, 0x2c, 0x63, 0xa2, 0x2a, 0x03,
|
||||
0x65, 0xd8, 0x3b, 0xfe, 0x62, 0x54, 0xe4, 0x8f, 0x36, 0xe5, 0x8e, 0xec, 0x34, 0xd1, 0x5e, 0xc6,
|
||||
0x04, 0xb7, 0x45, 0xf1, 0x8b, 0x3e, 0x81, 0xae, 0x4f, 0xee, 0x03, 0x8f, 0x38, 0x12, 0x53, 0x6b,
|
||||
0x03, 0x65, 0xd8, 0xc6, 0x9d, 0x0c, 0x93, 0x19, 0xe8, 0x73, 0xd8, 0x09, 0x22, 0x2e, 0xdc, 0x30,
|
||||
0x94, 0x75, 0x9c, 0xc0, 0x57, 0xeb, 0x32, 0xaa, 0x57, 0x86, 0x0d, 0x3f, 0xad, 0xe5, 0x7a, 0x1e,
|
||||
0xe1, 0x3c, 0xaf, 0xd5, 0xc8, 0x6a, 0x65, 0x58, 0x56, 0x4b, 0x85, 0x26, 0x89, 0xdc, 0x79, 0x48,
|
||||
0x7c, 0x75, 0x6b, 0xa0, 0x0c, 0x5b, 0xb8, 0x58, 0xa6, 0x3b, 0xf7, 0x84, 0xf1, 0x80, 0x46, 0xea,
|
||||
0xf6, 0x40, 0x19, 0x36, 0x70, 0xb1, 0x44, 0x43, 0xe8, 0xbb, 0x61, 0x48, 0x7f, 0x26, 0xbe, 0x73,
|
||||
0x4b, 0x96, 0x4e, 0x18, 0x70, 0xa1, 0x36, 0x07, 0xf5, 0x61, 0x17, 0xf7, 0x72, 0xfc, 0x82, 0x2c,
|
||||
0x2f, 0x03, 0x2e, 0xd0, 0x11, 0xec, 0xce, 0x43, 0xea, 0xdd, 0x12, 0xdf, 0xf1, 0x6e, 0x5c, 0x91,
|
||||
0x85, 0xb6, 0x64, 0xe8, 0x4e, 0xbe, 0x71, 0x72, 0xe3, 0x0a, 0x19, 0xfb, 0x11, 0x40, 0x12, 0x31,
|
||||
0xc9, 0x0f, 0x61, 0x6a, 0x5b, 0x5e, 0xa6, 0x84, 0xa0, 0x3d, 0xd8, 0xba, 0x66, 0x6e, 0x24, 0x54,
|
||||
0x18, 0x28, 0xc3, 0x2e, 0xce, 0x16, 0xe8, 0x0d, 0xa8, 0xf2, 0x4c, 0x67, 0xc1, 0xe8, 0x9d, 0xe3,
|
||||
0xd1, 0x48, 0xb8, 0x9e, 0xe0, 0x0e, 0x8d, 0xc2, 0xa5, 0xda, 0x91, 0x35, 0xf6, 0xe5, 0xfe, 0x19,
|
||||
0xa3, 0x77, 0x27, 0xf9, 0xae, 0x15, 0x85, 0x4b, 0xed, 0x0c, 0xda, 0x2b, 0xfe, 0xd1, 0x01, 0xa0,
|
||||
0x2b, 0xf3, 0xc2, 0xb4, 0xde, 0x99, 0x8e, 0x6d, 0x5d, 0xe8, 0xa6, 0x63, 0xbf, 0x9f, 0xea, 0xfd,
|
||||
0xff, 0xa1, 0xff, 0x43, 0x7b, 0x3c, 0xcd, 0xb1, 0xbe, 0x82, 0x10, 0xf4, 0xce, 0x0c, 0xac, 0x7f,
|
||||
0x3b, 0x9e, 0xe9, 0x39, 0x56, 0xd3, 0xfe, 0xaa, 0xc1, 0x67, 0x9b, 0x54, 0xc6, 0x84, 0xc7, 0x34,
|
||||
0xe2, 0x24, 0xe5, 0x93, 0x27, 0x92, 0x79, 0xd9, 0x26, 0x2d, 0x5c, 0x2c, 0x91, 0x09, 0x5b, 0x84,
|
||||
0x31, 0xca, 0xa4, 0xd6, 0xbd, 0xe3, 0xb7, 0x2f, 0x6b, 0x9f, 0xa2, 0xf0, 0x48, 0x4f, 0x73, 0x65,
|
||||
0x1b, 0x65, 0x65, 0xd0, 0x21, 0x00, 0x23, 0x3f, 0x25, 0x84, 0x8b, 0xa2, 0x35, 0xba, 0xb8, 0x9d,
|
||||
0x23, 0x86, 0xaf, 0xfd, 0xa2, 0x40, 0x7b, 0x95, 0x53, 0x7e, 0xba, 0x8e, 0xb1, 0x85, 0x8b, 0xa7,
|
||||
0xef, 0xc3, 0xee, 0x64, 0x7c, 0x79, 0x66, 0xe1, 0x89, 0x7e, 0xea, 0x4c, 0xf4, 0xd9, 0x6c, 0x7c,
|
||||
0xae, 0xf7, 0x15, 0xb4, 0x07, 0xfd, 0x1f, 0x74, 0x3c, 0x33, 0x2c, 0xd3, 0x99, 0x18, 0xb3, 0xc9,
|
||||
0xd8, 0x3e, 0xf9, 0xae, 0x5f, 0x43, 0xaf, 0xe1, 0xe0, 0xca, 0x9c, 0x5d, 0x4d, 0xa7, 0x16, 0xb6,
|
||||
0xf5, 0xd3, 0x32, 0x87, 0xf5, 0x94, 0x34, 0xc3, 0xb4, 0x75, 0x6c, 0x8e, 0x2f, 0xb3, 0x13, 0xfa,
|
||||
0x0d, 0x2d, 0x01, 0x35, 0x17, 0xe3, 0x84, 0xfa, 0x64, 0xec, 0xdf, 0x13, 0x26, 0x02, 0x4e, 0xee,
|
||||
0x48, 0x24, 0xd0, 0x7b, 0x38, 0x58, 0x33, 0xa6, 0x13, 0x44, 0x0b, 0xaa, 0x2a, 0x83, 0xfa, 0xb0,
|
||||
0x73, 0xfc, 0xe9, 0xd3, 0xf4, 0x7c, 0x9f, 0x10, 0xb6, 0x34, 0xa2, 0x05, 0xc5, 0x7b, 0xf1, 0xa3,
|
||||
0xad, 0x14, 0xd5, 0xde, 0xc2, 0x7e, 0x65, 0x0a, 0xfa, 0x18, 0x3a, 0x71, 0x32, 0x0f, 0x03, 0x2f,
|
||||
0x6d, 0x68, 0x2e, 0x0f, 0xea, 0x62, 0xc8, 0xa0, 0x0b, 0xb2, 0xe4, 0xda, 0xaf, 0x35, 0xf8, 0xe0,
|
||||
0xc9, 0xd3, 0xd6, 0x7c, 0xa6, 0xac, 0xfb, 0xac, 0xc2, 0xb3, 0xb5, 0x4a, 0xcf, 0x1e, 0x02, 0xfc,
|
||||
0x73, 0x95, 0x42, 0xbc, 0xd5, 0x4d, 0x2a, 0xbd, 0xd7, 0xa8, 0xf4, 0xde, 0xca, 0x2f, 0x5b, 0x65,
|
||||
0xbf, 0x3c, 0xed, 0xea, 0x23, 0xd8, 0xe5, 0x84, 0xdd, 0x13, 0xe6, 0x94, 0xce, 0x6f, 0xca, 0xdc,
|
||||
0x9d, 0x6c, 0x63, 0x5a, 0xdc, 0x42, 0xfb, 0x4d, 0x81, 0xc3, 0x4a, 0x3a, 0x56, 0xdd, 0xfe, 0x06,
|
||||
0x1a, 0xff, 0x56, 0x33, 0x99, 0x90, 0xbe, 0xff, 0x8e, 0x70, 0xee, 0x5e, 0x93, 0x82, 0xa3, 0x2e,
|
||||
0x6e, 0xe7, 0x88, 0xe1, 0x97, 0x5d, 0x54, 0x7f, 0xe0, 0x22, 0xed, 0x4f, 0x05, 0xfa, 0x8f, 0x8b,
|
||||
0xbf, 0x44, 0x99, 0x57, 0xd0, 0x94, 0xb3, 0x69, 0xa5, 0xc8, 0x76, 0xba, 0x7c, 0x5e, 0x89, 0x0a,
|
||||
0x45, 0x1b, 0x95, 0x8a, 0xaa, 0xd0, 0xcc, 0xef, 0x9f, 0x4b, 0x51, 0x2c, 0xb5, 0x18, 0x5e, 0xad,
|
||||
0x3b, 0x5c, 0xda, 0x14, 0x7d, 0x05, 0xad, 0xdc, 0xb1, 0x3c, 0xe7, 0xf0, 0xf5, 0x86, 0xb1, 0xb0,
|
||||
0x8a, 0x7d, 0x86, 0x3e, 0xed, 0xf7, 0x1a, 0x1c, 0xac, 0x1f, 0x19, 0x53, 0x26, 0x36, 0xcc, 0xa7,
|
||||
0x6f, 0x1e, 0xce, 0xa7, 0xa3, 0x4d, 0xf3, 0x29, 0x2d, 0x55, 0x39, 0x91, 0xfe, 0x0b, 0x2a, 0xb5,
|
||||
0x1f, 0x5f, 0x32, 0xb9, 0x76, 0xa0, 0xf3, 0x0e, 0x5b, 0xe6, 0x79, 0x79, 0x6c, 0x3f, 0x9a, 0x40,
|
||||
0xb5, 0x14, 0x33, 0x2d, 0xdb, 0xc1, 0xfa, 0xb9, 0x31, 0xb3, 0x75, 0xac, 0x9f, 0xf6, 0xeb, 0xe9,
|
||||
0x54, 0x5a, 0x7f, 0x50, 0xde, 0xcf, 0x0f, 0x79, 0x55, 0x1e, 0xb7, 0xe5, 0xd7, 0xd0, 0x64, 0xf2,
|
||||
0xed, 0x5c, 0xad, 0x49, 0xb5, 0x06, 0xcf, 0x91, 0x84, 0x8b, 0x84, 0xf9, 0xb6, 0x8c, 0xfc, 0xf2,
|
||||
0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x6f, 0xe8, 0xb9, 0x16, 0x90, 0x08, 0x00, 0x00,
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ message PushNotificationRegistration {
|
|||
FIREBASE_TOKEN = 2;
|
||||
}
|
||||
TokenType token_type = 1;
|
||||
string token = 2;
|
||||
string device_token = 2;
|
||||
string installation_id = 3;
|
||||
string access_token = 4;
|
||||
bool enabled = 5;
|
||||
uint64 version = 6;
|
||||
repeated bytes allowed_user_list = 7;
|
||||
repeated bytes allowed_key_list = 7;
|
||||
repeated bytes blocked_chat_list = 8;
|
||||
bool unregister = 9;
|
||||
bytes grant = 10;
|
||||
|
@ -35,14 +35,8 @@ message PushNotificationRegistrationResponse {
|
|||
}
|
||||
}
|
||||
|
||||
message PushNotificationAdvertisementInfo {
|
||||
bytes public_key = 1;
|
||||
string access_token = 2;
|
||||
string installation_id = 3;
|
||||
}
|
||||
|
||||
message ContactCodeAdvertisement {
|
||||
repeated PushNotificationAdvertisementInfo push_notification_info = 1;
|
||||
repeated PushNotificationQueryInfo push_notification_info = 1;
|
||||
}
|
||||
|
||||
message PushNotificationQuery {
|
||||
|
@ -53,9 +47,10 @@ message PushNotificationQueryInfo {
|
|||
string access_token = 1;
|
||||
string installation_id = 2;
|
||||
bytes public_key = 3;
|
||||
repeated bytes allowed_user_list = 4;
|
||||
repeated bytes allowed_key_list = 4;
|
||||
bytes grant = 5;
|
||||
uint64 version = 6;
|
||||
bytes server_public_key = 7;
|
||||
}
|
||||
|
||||
message PushNotificationQueryResponse {
|
||||
|
|
|
@ -17,12 +17,17 @@ import (
|
|||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/push_notification_client"
|
||||
"github.com/status-im/status-go/protocol/push_notification_server"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationclient"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationserver"
|
||||
"github.com/status-im/status-go/protocol/tt"
|
||||
"github.com/status-im/status-go/waku"
|
||||
)
|
||||
|
||||
const (
|
||||
bob1DeviceToken = "token-1"
|
||||
bob2DeviceToken = "token-2"
|
||||
)
|
||||
|
||||
func TestMessengerPushNotificationSuite(t *testing.T) {
|
||||
suite.Run(t, new(MessengerPushNotificationSuite))
|
||||
}
|
||||
|
@ -60,9 +65,6 @@ func (s *MessengerPushNotificationSuite) TearDownTest() {
|
|||
}
|
||||
|
||||
func (s *MessengerPushNotificationSuite) newMessengerWithOptions(shh types.Waku, privateKey *ecdsa.PrivateKey, options []Option) *Messenger {
|
||||
tmpFile, err := ioutil.TempFile("", "")
|
||||
s.Require().NoError(err)
|
||||
|
||||
m, err := NewMessenger(
|
||||
privateKey,
|
||||
&testNode{shh: shh},
|
||||
|
@ -74,8 +76,6 @@ func (s *MessengerPushNotificationSuite) newMessengerWithOptions(shh types.Waku,
|
|||
err = m.Init()
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.tmpFiles = append(s.tmpFiles, tmpFile)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ func (s *MessengerPushNotificationSuite) newMessengerWithKey(shh types.Waku, pri
|
|||
options := []Option{
|
||||
WithCustomLogger(s.logger),
|
||||
WithMessagesPersistenceEnabled(),
|
||||
WithDatabaseConfig(tmpFile.Name(), "some-key"),
|
||||
WithDatabaseConfig(tmpFile.Name(), ""),
|
||||
WithDatasync(),
|
||||
}
|
||||
return s.newMessengerWithOptions(shh, privateKey, options)
|
||||
|
@ -99,14 +99,12 @@ func (s *MessengerPushNotificationSuite) newMessenger(shh types.Waku) *Messenger
|
|||
return s.newMessengerWithKey(s.shh, privateKey)
|
||||
}
|
||||
|
||||
func (s *MessengerPushNotificationSuite) newPushNotificationServer(shh types.Waku) *Messenger {
|
||||
privateKey, err := crypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
func (s *MessengerPushNotificationSuite) newPushNotificationServer(shh types.Waku, privateKey *ecdsa.PrivateKey) *Messenger {
|
||||
|
||||
tmpFile, err := ioutil.TempFile("", "")
|
||||
s.Require().NoError(err)
|
||||
|
||||
serverConfig := &push_notification_server.Config{
|
||||
serverConfig := &pushnotificationserver.Config{
|
||||
Logger: s.logger,
|
||||
Identity: privateKey,
|
||||
}
|
||||
|
@ -123,12 +121,13 @@ func (s *MessengerPushNotificationSuite) newPushNotificationServer(shh types.Wak
|
|||
|
||||
func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
|
||||
|
||||
bob1DeviceToken := "token-1"
|
||||
bob2DeviceToken := "token-2"
|
||||
|
||||
bob1 := s.m
|
||||
bob2 := s.newMessengerWithKey(s.shh, s.m.identity)
|
||||
server := s.newPushNotificationServer(s.shh)
|
||||
|
||||
serverKey, err := crypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
server := s.newPushNotificationServer(s.shh, serverKey)
|
||||
|
||||
alice := s.newMessenger(s.shh)
|
||||
// start alice and enable sending push notifications
|
||||
s.Require().NoError(alice.Start())
|
||||
|
@ -136,7 +135,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
|
|||
bobInstallationIDs := []string{bob1.installationID, bob2.installationID}
|
||||
|
||||
// Register bob1
|
||||
err := bob1.AddPushNotificationServer(context.Background(), &server.identity.PublicKey)
|
||||
err = bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken)
|
||||
|
@ -166,7 +165,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
|
|||
s.Require().NoError(err)
|
||||
|
||||
// Register bob2
|
||||
err = bob2.AddPushNotificationServer(context.Background(), &server.identity.PublicKey)
|
||||
err = bob2.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken)
|
||||
|
@ -207,7 +206,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
|
|||
messageID, err := hex.DecodeString(messageIDString[2:])
|
||||
s.Require().NoError(err)
|
||||
|
||||
var info []*push_notification_client.PushNotificationInfo
|
||||
var info []*pushnotificationclient.PushNotificationInfo
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
|
@ -233,7 +232,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
|
|||
s.Require().NoError(err)
|
||||
|
||||
// Check we have replies for both bob1 and bob2
|
||||
var bob1Info, bob2Info *push_notification_client.PushNotificationInfo
|
||||
var bob1Info, bob2Info *pushnotificationclient.PushNotificationInfo
|
||||
|
||||
if info[0].AccessToken == bob1Servers[0].AccessToken {
|
||||
bob1Info = info[0]
|
||||
|
@ -259,7 +258,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
|
|||
s.Require().NotNil(retrievedNotificationInfo)
|
||||
s.Require().Len(retrievedNotificationInfo, 2)
|
||||
|
||||
var sentNotification *push_notification_client.SentNotification
|
||||
var sentNotification *pushnotificationclient.SentNotification
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
|
@ -289,10 +288,12 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
|
|||
|
||||
func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactOnly() {
|
||||
|
||||
bobDeviceToken := "token-1"
|
||||
|
||||
bob := s.m
|
||||
server := s.newPushNotificationServer(s.shh)
|
||||
|
||||
serverKey, err := crypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
server := s.newPushNotificationServer(s.shh, serverKey)
|
||||
|
||||
alice := s.newMessenger(s.shh)
|
||||
// start alice and enable push notifications
|
||||
s.Require().NoError(alice.Start())
|
||||
|
@ -300,7 +301,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactO
|
|||
bobInstallationIDs := []string{bob.installationID}
|
||||
|
||||
// Register bob
|
||||
err := bob.AddPushNotificationServer(context.Background(), &server.identity.PublicKey)
|
||||
err = bob.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Add alice has a contact
|
||||
|
@ -317,7 +318,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactO
|
|||
err = bob.EnablePushNotificationsFromContactsOnly()
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = bob.RegisterForPushNotifications(context.Background(), bobDeviceToken)
|
||||
err = bob.RegisterForPushNotifications(context.Background(), bob1DeviceToken)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Pull servers and check we registered
|
||||
|
@ -355,7 +356,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactO
|
|||
messageID, err := hex.DecodeString(messageIDString[2:])
|
||||
s.Require().NoError(err)
|
||||
|
||||
var info []*push_notification_client.PushNotificationInfo
|
||||
var info []*pushnotificationclient.PushNotificationInfo
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
|
@ -389,7 +390,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactO
|
|||
s.Require().NotNil(retrievedNotificationInfo)
|
||||
s.Require().Len(retrievedNotificationInfo, 1)
|
||||
|
||||
var sentNotification *push_notification_client.SentNotification
|
||||
var sentNotification *pushnotificationclient.SentNotification
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
|
@ -419,10 +420,12 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactO
|
|||
|
||||
func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
|
||||
|
||||
bobDeviceToken := "token-1"
|
||||
|
||||
bob := s.m
|
||||
server := s.newPushNotificationServer(s.shh)
|
||||
|
||||
serverKey, err := crypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
server := s.newPushNotificationServer(s.shh, serverKey)
|
||||
|
||||
alice := s.newMessenger(s.shh)
|
||||
// another contact to invalidate the token
|
||||
frank := s.newMessenger(s.shh)
|
||||
|
@ -432,7 +435,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
|
|||
bobInstallationIDs := []string{bob.installationID}
|
||||
|
||||
// Register bob
|
||||
err := bob.AddPushNotificationServer(context.Background(), &server.identity.PublicKey)
|
||||
err = bob.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Add alice has a contact
|
||||
|
@ -459,7 +462,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
|
|||
err = bob.EnablePushNotificationsFromContactsOnly()
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = bob.RegisterForPushNotifications(context.Background(), bobDeviceToken)
|
||||
err = bob.RegisterForPushNotifications(context.Background(), bob1DeviceToken)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Pull servers and check we registered
|
||||
|
@ -495,7 +498,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
|
|||
s.Require().NoError(err)
|
||||
|
||||
// We check that alice retrieves the info from the server
|
||||
var info []*push_notification_client.PushNotificationInfo
|
||||
var info []*pushnotificationclient.PushNotificationInfo
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
|
@ -603,7 +606,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
|
|||
s.Require().NotNil(retrievedNotificationInfo)
|
||||
s.Require().Len(retrievedNotificationInfo, 1)
|
||||
|
||||
var sentNotification *push_notification_client.SentNotification
|
||||
var sentNotification *pushnotificationclient.SentNotification
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
|
@ -630,3 +633,165 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
|
|||
s.Require().NoError(alice.Shutdown())
|
||||
s.Require().NoError(server.Shutdown())
|
||||
}
|
||||
|
||||
// Here bob acts as his own server
|
||||
func (s *MessengerPushNotificationSuite) TestActAsYourOwnPushNotificationServer() {
|
||||
bob1 := s.m
|
||||
server := s.newPushNotificationServer(s.shh, s.m.identity)
|
||||
bob2 := server
|
||||
alice := s.newMessenger(s.shh)
|
||||
// start alice and enable sending push notifications
|
||||
s.Require().NoError(alice.Start())
|
||||
s.Require().NoError(alice.EnableSendingPushNotifications())
|
||||
bobInstallationIDs := []string{bob1.installationID, bob2.installationID}
|
||||
|
||||
// Register bob1
|
||||
err := bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken)
|
||||
|
||||
// Pull servers and check we registered
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = bob1.RetrieveAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
registered, err := bob1.RegisteredForPushNotifications()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !registered {
|
||||
return errors.New("not registered")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// Make sure we receive it
|
||||
s.Require().NoError(err)
|
||||
bob1Servers, err := bob1.GetPushNotificationServers()
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Register bob2
|
||||
err = bob2.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken)
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = bob2.RetrieveAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
registered, err := bob2.RegisteredForPushNotifications()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !registered {
|
||||
return errors.New("not registered")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// Make sure we receive it
|
||||
s.Require().NoError(err)
|
||||
bob2Servers, err := bob2.GetPushNotificationServers()
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Create one to one chat & send message
|
||||
pkString := hex.EncodeToString(crypto.FromECDSAPub(&s.m.identity.PublicKey))
|
||||
chat := CreateOneToOneChat(pkString, &s.m.identity.PublicKey, alice.transport)
|
||||
s.Require().NoError(alice.SaveChat(&chat))
|
||||
inputMessage := buildTestMessage(chat)
|
||||
response, err := alice.SendChatMessage(context.Background(), inputMessage)
|
||||
s.Require().NoError(err)
|
||||
messageIDString := response.Messages[0].ID
|
||||
messageID, err := hex.DecodeString(messageIDString[2:])
|
||||
s.Require().NoError(err)
|
||||
|
||||
var info []*pushnotificationclient.PushNotificationInfo
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = alice.RetrieveAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
info, err = alice.pushNotificationClient.GetPushNotificationInfo(&bob1.identity.PublicKey, bobInstallationIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Check we have replies for both bob1 and bob2
|
||||
if len(info) != 2 {
|
||||
return errors.New("info not fetched")
|
||||
}
|
||||
return nil
|
||||
|
||||
})
|
||||
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Check we have replies for both bob1 and bob2
|
||||
var bob1Info, bob2Info *pushnotificationclient.PushNotificationInfo
|
||||
|
||||
if info[0].AccessToken == bob1Servers[0].AccessToken {
|
||||
bob1Info = info[0]
|
||||
bob2Info = info[1]
|
||||
} else {
|
||||
bob2Info = info[0]
|
||||
bob1Info = info[1]
|
||||
}
|
||||
|
||||
s.Require().NotNil(bob1Info)
|
||||
s.Require().Equal(bob1.installationID, bob1Info.InstallationID)
|
||||
s.Require().Equal(bob1Servers[0].AccessToken, bob1Info.AccessToken)
|
||||
s.Require().Equal(&bob1.identity.PublicKey, bob1Info.PublicKey)
|
||||
|
||||
s.Require().NotNil(bob2Info)
|
||||
s.Require().Equal(bob2.installationID, bob2Info.InstallationID)
|
||||
s.Require().Equal(bob2Servers[0].AccessToken, bob2Info.AccessToken)
|
||||
s.Require().Equal(&bob2.identity.PublicKey, bob2Info.PublicKey)
|
||||
|
||||
retrievedNotificationInfo, err := alice.pushNotificationClient.GetPushNotificationInfo(&bob1.identity.PublicKey, bobInstallationIDs)
|
||||
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(retrievedNotificationInfo)
|
||||
s.Require().Len(retrievedNotificationInfo, 2)
|
||||
|
||||
var sentNotification *pushnotificationclient.SentNotification
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
_, err = server.RetrieveAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = alice.RetrieveAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sentNotification, err = alice.pushNotificationClient.GetSentNotification(common.HashPublicKey(&bob1.identity.PublicKey), bob1.installationID, messageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if sentNotification == nil {
|
||||
return errors.New("sent notification not found")
|
||||
}
|
||||
if !sentNotification.Success {
|
||||
return errors.New("sent notification not successul")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(bob2.Shutdown())
|
||||
s.Require().NoError(alice.Shutdown())
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
package push_notification_client
|
||||
package pushnotificationclient
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -6,19 +6,22 @@ import (
|
|||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/crypto/ecies"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
"github.com/status-im/status-go/protocol/tt"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
const testDeviceToken = "test-token"
|
||||
|
||||
type ClientSuite struct {
|
||||
suite.Suite
|
||||
tmpFile *os.File
|
||||
|
@ -59,7 +62,6 @@ func (s *ClientSuite) SetupTest() {
|
|||
}
|
||||
|
||||
func (s *ClientSuite) TestBuildPushNotificationRegisterMessage() {
|
||||
myDeviceToken := "device-token"
|
||||
mutedChatList := []string{"a", "b"}
|
||||
|
||||
// build chat lish hashes
|
||||
|
@ -82,14 +84,14 @@ func (s *ClientSuite) TestBuildPushNotificationRegisterMessage() {
|
|||
// Reset random generator
|
||||
uuid.SetRand(rand.New(rand.NewSource(seed)))
|
||||
|
||||
s.client.deviceToken = myDeviceToken
|
||||
s.client.deviceToken = testDeviceToken
|
||||
// Set reader
|
||||
s.client.reader = bytes.NewReader([]byte(expectedUUID))
|
||||
|
||||
options := &protobuf.PushNotificationRegistration{
|
||||
Version: 1,
|
||||
AccessToken: expectedUUID,
|
||||
Token: myDeviceToken,
|
||||
DeviceToken: testDeviceToken,
|
||||
InstallationId: s.installationID,
|
||||
Enabled: true,
|
||||
BlockedChatList: mutedChatListHashes,
|
||||
|
@ -102,7 +104,6 @@ func (s *ClientSuite) TestBuildPushNotificationRegisterMessage() {
|
|||
}
|
||||
|
||||
func (s *ClientSuite) TestBuildPushNotificationRegisterMessageAllowFromContactsOnly() {
|
||||
myDeviceToken := "device-token"
|
||||
mutedChatList := []string{"a", "b"}
|
||||
|
||||
// build chat lish hashes
|
||||
|
@ -138,20 +139,20 @@ func (s *ClientSuite) TestBuildPushNotificationRegisterMessageAllowFromContactsO
|
|||
// Reset random generator
|
||||
uuid.SetRand(rand.New(rand.NewSource(seed)))
|
||||
|
||||
s.client.config.allowFromContactsOnly = true
|
||||
s.client.deviceToken = myDeviceToken
|
||||
s.client.config.AllowFromContactsOnly = true
|
||||
s.client.deviceToken = testDeviceToken
|
||||
// Set reader
|
||||
s.client.reader = bytes.NewReader([]byte(expectedUUID))
|
||||
|
||||
options := &protobuf.PushNotificationRegistration{
|
||||
Version: 1,
|
||||
AccessToken: expectedUUID,
|
||||
Token: myDeviceToken,
|
||||
DeviceToken: testDeviceToken,
|
||||
InstallationId: s.installationID,
|
||||
AllowFromContactsOnly: true,
|
||||
Enabled: true,
|
||||
BlockedChatList: mutedChatListHashes,
|
||||
AllowedUserList: [][]byte{encryptedToken},
|
||||
AllowedKeyList: [][]byte{encryptedToken},
|
||||
}
|
||||
|
||||
actualMessage, err := s.client.buildPushNotificationRegistrationMessage(contactIDs, mutedChatList)
|
||||
|
@ -160,13 +161,18 @@ func (s *ClientSuite) TestBuildPushNotificationRegisterMessageAllowFromContactsO
|
|||
s.Require().Equal(options, actualMessage)
|
||||
}
|
||||
|
||||
func (s *ClientSuite) TestNotifyOnMessageID() {
|
||||
func (s *ClientSuite) TestHandleMessageScheduled() {
|
||||
messageID := []byte("message-id")
|
||||
chatID := "chat-id"
|
||||
installationID1 := "1"
|
||||
installationID2 := "2"
|
||||
rawMessage := &common.RawMessage{
|
||||
ID: types.EncodeHex(messageID),
|
||||
SendPushNotification: true,
|
||||
LocalChatID: chatID,
|
||||
}
|
||||
|
||||
s.Require().NoError(s.client.NotifyOnMessageID(chatID, messageID))
|
||||
s.Require().NoError(s.client.handleMessageScheduled(rawMessage))
|
||||
|
||||
key1, err := crypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
|
@ -86,7 +86,7 @@ func _1593601729_initial_schemaDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1593601729_initial_schema.down.sql", size: 144, mode: os.FileMode(0644), modTime: time.Unix(1594896579, 0)}
|
||||
info := bindataFileInfo{name: "1593601729_initial_schema.down.sql", size: 144, mode: os.FileMode(0644), modTime: time.Unix(1595832279, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa, 0x95, 0x55, 0x64, 0x38, 0x40, 0x16, 0xbf, 0x8b, 0x1c, 0x18, 0xb4, 0xc5, 0x7f, 0xd0, 0xb8, 0xf0, 0x3c, 0xa2, 0x82, 0xf8, 0x8d, 0x5a, 0xd3, 0xb6, 0x6e, 0xa3, 0xb4, 0xc, 0x9, 0x33, 0x0}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func _1593601729_initial_schemaUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1593601729_initial_schema.up.sql", size: 1773, mode: os.FileMode(0644), modTime: time.Unix(1595256491, 0)}
|
||||
info := bindataFileInfo{name: "1593601729_initial_schema.up.sql", size: 1773, mode: os.FileMode(0644), modTime: time.Unix(1595832279, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x4e, 0x1e, 0x5, 0x35, 0x9, 0xb2, 0x2d, 0x6f, 0x33, 0x63, 0xa2, 0x7a, 0x5b, 0xd2, 0x2d, 0xcb, 0x79, 0x7e, 0x6, 0xb4, 0x9d, 0x35, 0xd8, 0x9b, 0x55, 0xe5, 0xf8, 0x44, 0xca, 0xa6, 0xf3, 0xd3}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func docGo() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1594896579, 0)}
|
||||
info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1595832279, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc0, 0x2f, 0x1e, 0x64, 0x9, 0x93, 0xe4, 0x8b, 0xf2, 0x98, 0x5a, 0x45, 0xe2, 0x80, 0x88, 0x67, 0x7a, 0x2d, 0xd7, 0x4b, 0xd1, 0x73, 0xb6, 0x6d, 0x15, 0xc2, 0x0, 0x34, 0xcd, 0xa0, 0xdb, 0x20}}
|
||||
return a, nil
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package push_notification_client
|
||||
package pushnotificationclient
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -180,10 +180,13 @@ func (p *Persistence) GetPushNotificationInfo(publicKey *ecdsa.PublicKey, instal
|
|||
|
||||
inVector := strings.Repeat("?, ", len(installationIDs)-1) + "?"
|
||||
|
||||
rows, err := p.db.Query(`SELECT server_public_key, installation_id, version, access_token, retrieved_at FROM push_notification_client_info WHERE public_key = ? AND installation_id IN (`+inVector+`)`, queryArgs...)
|
||||
rows, err := p.db.Query(`SELECT server_public_key, installation_id, version, access_token, retrieved_at FROM push_notification_client_info WHERE public_key = ? AND installation_id IN (`+inVector+`)`, queryArgs...) //nolint: gosec
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var infos []*PushNotificationInfo
|
||||
for rows.Next() {
|
||||
var serverPublicKeyBytes []byte
|
||||
|
@ -210,6 +213,8 @@ func (p *Persistence) GetPushNotificationInfoByPublicKey(publicKey *ecdsa.Public
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var infos []*PushNotificationInfo
|
||||
for rows.Next() {
|
||||
var serverPublicKeyBytes []byte
|
||||
|
@ -308,6 +313,7 @@ func (p *Persistence) GetRetriablePushNotifications() ([]*SentNotification, erro
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var publicKeyBytes []byte
|
||||
|
@ -337,6 +343,8 @@ func (p *Persistence) GetServers() ([]*PushNotificationServer, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var servers []*PushNotificationServer
|
||||
for rows.Next() {
|
||||
server := &PushNotificationServer{}
|
||||
|
@ -367,6 +375,8 @@ func (p *Persistence) GetServersByPublicKey(keys []*ecdsa.PublicKey) ([]*PushNot
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var servers []*PushNotificationServer
|
||||
for rows.Next() {
|
||||
server := &PushNotificationServer{}
|
|
@ -1,4 +1,4 @@
|
|||
package push_notification_client
|
||||
package pushnotificationclient
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
|
@ -16,6 +16,13 @@ import (
|
|||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
)
|
||||
|
||||
const (
|
||||
testAccessToken = "token"
|
||||
installationID1 = "installation-id-1"
|
||||
installationID2 = "installation-id-2"
|
||||
installationID3 = "installation-id-3"
|
||||
)
|
||||
|
||||
func TestSQLitePersistenceSuite(t *testing.T) {
|
||||
suite.Run(t, new(SQLitePersistenceSuite))
|
||||
}
|
||||
|
@ -43,13 +50,12 @@ func (s *SQLitePersistenceSuite) TearDownTest() {
|
|||
func (s *SQLitePersistenceSuite) TestSaveAndRetrieveServer() {
|
||||
key, err := crypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
accessToken := "token"
|
||||
|
||||
server := &PushNotificationServer{
|
||||
PublicKey: &key.PublicKey,
|
||||
Registered: true,
|
||||
RegisteredAt: 1,
|
||||
AccessToken: accessToken,
|
||||
AccessToken: testAccessToken,
|
||||
}
|
||||
|
||||
s.Require().NoError(s.persistence.UpsertServer(server))
|
||||
|
@ -61,7 +67,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveServer() {
|
|||
s.Require().True(retrievedServers[0].Registered)
|
||||
s.Require().Equal(int64(1), retrievedServers[0].RegisteredAt)
|
||||
s.Require().True(common.IsPubKeyEqual(retrievedServers[0].PublicKey, &key.PublicKey))
|
||||
s.Require().Equal(accessToken, retrievedServers[0].AccessToken)
|
||||
s.Require().Equal(testAccessToken, retrievedServers[0].AccessToken)
|
||||
|
||||
server.Registered = false
|
||||
server.RegisteredAt = 2
|
||||
|
@ -78,9 +84,6 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveServer() {
|
|||
}
|
||||
|
||||
func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
|
||||
installationID1 := "installation-id-1"
|
||||
installationID2 := "installation-id-2"
|
||||
installationID3 := "installation-id-3"
|
||||
key1, err := crypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
key2, err := crypto.GenerateKey()
|
||||
|
@ -88,15 +91,13 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
|
|||
serverKey, err := crypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
|
||||
accessToken := "token"
|
||||
|
||||
infos := []*PushNotificationInfo{
|
||||
{
|
||||
PublicKey: &key1.PublicKey,
|
||||
ServerPublicKey: &serverKey.PublicKey,
|
||||
RetrievedAt: 1,
|
||||
Version: 1,
|
||||
AccessToken: accessToken,
|
||||
AccessToken: testAccessToken,
|
||||
InstallationID: installationID1,
|
||||
},
|
||||
{
|
||||
|
@ -104,7 +105,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
|
|||
ServerPublicKey: &serverKey.PublicKey,
|
||||
RetrievedAt: 1,
|
||||
Version: 1,
|
||||
AccessToken: accessToken,
|
||||
AccessToken: testAccessToken,
|
||||
InstallationID: installationID2,
|
||||
},
|
||||
{
|
||||
|
@ -112,7 +113,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
|
|||
ServerPublicKey: &serverKey.PublicKey,
|
||||
RetrievedAt: 1,
|
||||
Version: 1,
|
||||
AccessToken: accessToken,
|
||||
AccessToken: testAccessToken,
|
||||
InstallationID: installationID3,
|
||||
},
|
||||
{
|
||||
|
@ -120,7 +121,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
|
|||
ServerPublicKey: &serverKey.PublicKey,
|
||||
RetrievedAt: 1,
|
||||
Version: 1,
|
||||
AccessToken: accessToken,
|
||||
AccessToken: testAccessToken,
|
||||
InstallationID: installationID1,
|
||||
},
|
||||
{
|
||||
|
@ -128,7 +129,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
|
|||
ServerPublicKey: &serverKey.PublicKey,
|
||||
RetrievedAt: 1,
|
||||
Version: 1,
|
||||
AccessToken: accessToken,
|
||||
AccessToken: testAccessToken,
|
||||
InstallationID: installationID2,
|
||||
},
|
||||
{
|
||||
|
@ -136,7 +137,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfo() {
|
|||
ServerPublicKey: &serverKey.PublicKey,
|
||||
RetrievedAt: 1,
|
||||
Version: 1,
|
||||
AccessToken: accessToken,
|
||||
AccessToken: testAccessToken,
|
||||
InstallationID: installationID3,
|
||||
},
|
||||
}
|
||||
|
@ -158,15 +159,13 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfoWithVersion() {
|
|||
serverKey2, err := crypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
|
||||
accessToken := "token"
|
||||
|
||||
infos := []*PushNotificationInfo{
|
||||
{
|
||||
PublicKey: &key.PublicKey,
|
||||
ServerPublicKey: &serverKey1.PublicKey,
|
||||
RetrievedAt: 1,
|
||||
Version: 1,
|
||||
AccessToken: accessToken,
|
||||
AccessToken: testAccessToken,
|
||||
InstallationID: installationID,
|
||||
},
|
||||
{
|
||||
|
@ -174,7 +173,7 @@ func (s *SQLitePersistenceSuite) TestSaveAndRetrieveInfoWithVersion() {
|
|||
ServerPublicKey: &serverKey2.PublicKey,
|
||||
RetrievedAt: 1,
|
||||
Version: 1,
|
||||
AccessToken: accessToken,
|
||||
AccessToken: testAccessToken,
|
||||
InstallationID: installationID,
|
||||
},
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package push_notification_server
|
||||
package pushnotificationserver
|
||||
|
||||
import "errors"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package push_notification_server
|
||||
package pushnotificationserver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -46,12 +46,11 @@ func tokenTypeToGoRushPlatform(tokenType protobuf.PushNotificationRegistration_T
|
|||
func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*RequestAndRegistration) *GoRushRequest {
|
||||
goRushRequests := &GoRushRequest{}
|
||||
for _, requestAndRegistration := range requestAndRegistrations {
|
||||
|
||||
request := requestAndRegistration.Request
|
||||
registration := requestAndRegistration.Registration
|
||||
goRushRequests.Notifications = append(goRushRequests.Notifications,
|
||||
&GoRushRequestNotification{
|
||||
Tokens: []string{registration.Token},
|
||||
Tokens: []string{registration.DeviceToken},
|
||||
Platform: tokenTypeToGoRushPlatform(registration.TokenType),
|
||||
Message: defaultNotificationMessage,
|
||||
Data: &GoRushRequestData{
|
|
@ -1,4 +1,4 @@
|
|||
package push_notification_server
|
||||
package pushnotificationserver
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
@ -38,7 +38,7 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
|
|||
Message: message1,
|
||||
},
|
||||
Registration: &protobuf.PushNotificationRegistration{
|
||||
Token: token1,
|
||||
DeviceToken: token1,
|
||||
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||
},
|
||||
},
|
||||
|
@ -50,7 +50,7 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
|
|||
Message: message2,
|
||||
},
|
||||
Registration: &protobuf.PushNotificationRegistration{
|
||||
Token: token2,
|
||||
DeviceToken: token2,
|
||||
TokenType: protobuf.PushNotificationRegistration_FIREBASE_TOKEN,
|
||||
},
|
||||
},
|
||||
|
@ -62,7 +62,7 @@ func TestPushNotificationRegistrationToGoRushRequest(t *testing.T) {
|
|||
Message: message3,
|
||||
},
|
||||
Registration: &protobuf.PushNotificationRegistration{
|
||||
Token: token3,
|
||||
DeviceToken: token3,
|
||||
TokenType: protobuf.PushNotificationRegistration_FIREBASE_TOKEN,
|
||||
},
|
||||
},
|
|
@ -86,7 +86,7 @@ func _1593601728_initial_schemaDownSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1593601728_initial_schema.down.sql", size: 200, mode: os.FileMode(0644), modTime: time.Unix(1594896579, 0)}
|
||||
info := bindataFileInfo{name: "1593601728_initial_schema.down.sql", size: 200, mode: os.FileMode(0644), modTime: time.Unix(1595832279, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x88, 0x8a, 0x61, 0x81, 0x57, 0x45, 0x9b, 0x97, 0x9b, 0x1f, 0xf6, 0x94, 0x8a, 0x20, 0xb3, 0x2b, 0xff, 0x69, 0x49, 0xf4, 0x58, 0xcc, 0xd0, 0x55, 0xcc, 0x9a, 0x8b, 0xb6, 0x7f, 0x29, 0x53, 0xc1}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func _1593601728_initial_schemaUpSql() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1593601728_initial_schema.up.sql", size: 675, mode: os.FileMode(0644), modTime: time.Unix(1594896582, 0)}
|
||||
info := bindataFileInfo{name: "1593601728_initial_schema.up.sql", size: 675, mode: os.FileMode(0644), modTime: time.Unix(1595832279, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xfd, 0x61, 0x90, 0x79, 0xd9, 0x14, 0x65, 0xe9, 0x96, 0x53, 0x17, 0x33, 0x54, 0xeb, 0x8b, 0x5d, 0x95, 0x99, 0x10, 0x36, 0x58, 0xdd, 0xb2, 0xbf, 0x45, 0xd9, 0xbb, 0xc4, 0x92, 0xe, 0xce, 0x2}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func docGo() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1594896579, 0)}
|
||||
info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1595832279, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc0, 0x2f, 0x1e, 0x64, 0x9, 0x93, 0xe4, 0x8b, 0xf2, 0x98, 0x5a, 0x45, 0xe2, 0x80, 0x88, 0x67, 0x7a, 0x2d, 0xd7, 0x4b, 0xd1, 0x73, 0xb6, 0x6d, 0x15, 0xc2, 0x0, 0x34, 0xcd, 0xa0, 0xdb, 0x20}}
|
||||
return a, nil
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package push_notification_server
|
||||
package pushnotificationserver
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
|
@ -70,7 +70,7 @@ func (p *SQLitePersistence) GetPushNotificationRegistrationByPublicKeys(publicKe
|
|||
|
||||
inVector := strings.Repeat("?, ", len(publicKeys)-1) + "?"
|
||||
|
||||
rows, err := p.db.Query(`SELECT public_key,registration FROM push_notification_server_registrations WHERE public_key IN (`+inVector+`)`, publicKeyArgs...)
|
||||
rows, err := p.db.Query(`SELECT public_key,registration FROM push_notification_server_registrations WHERE public_key IN (`+inVector+`)`, publicKeyArgs...) // nolint: gosec
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package push_notification_server
|
||||
package pushnotificationserver
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
@ -14,8 +14,6 @@ import (
|
|||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
)
|
||||
|
||||
//tmpFile, err := ioutil.TempFile("", "")
|
||||
|
||||
func TestSQLitePersistenceSuite(t *testing.T) {
|
||||
suite.Run(t, new(SQLitePersistenceSuite))
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package push_notification_server
|
||||
package pushnotificationserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -8,13 +8,13 @@ import (
|
|||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/google/uuid"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/crypto/ecies"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const encryptedPayloadKeyLength = 16
|
||||
|
@ -43,15 +43,150 @@ func New(config *Config, persistence Persistence, messageProcessor *common.Messa
|
|||
return &Server{persistence: persistence, config: config, messageProcessor: messageProcessor}
|
||||
}
|
||||
|
||||
func (p *Server) generateSharedKey(publicKey *ecdsa.PublicKey) ([]byte, error) {
|
||||
return ecies.ImportECDSA(p.config.Identity).GenerateShared(
|
||||
func (s *Server) Start() error {
|
||||
s.config.Logger.Info("starting push notification server")
|
||||
if s.config.Identity == nil {
|
||||
s.config.Logger.Info("Identity nil")
|
||||
// Pull identity from database
|
||||
identity, err := s.persistence.GetIdentity()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if identity == nil {
|
||||
identity, err = crypto.GenerateKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.persistence.SaveIdentity(identity); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
s.config.Identity = identity
|
||||
}
|
||||
|
||||
pks, err := s.persistence.GetPushNotificationRegistrationPublicKeys()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// listen to all topics for users registered
|
||||
for _, pk := range pks {
|
||||
if err := s.listenToPublicKeyQueryTopic(pk); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
s.config.Logger.Info("started push notification server", zap.String("identity", types.EncodeHex(crypto.FromECDSAPub(&s.config.Identity.PublicKey))))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HandlePushNotificationRegistration builds a response for the registration and sends it back to the user
|
||||
func (s *Server) HandlePushNotificationRegistration(publicKey *ecdsa.PublicKey, payload []byte) error {
|
||||
response := s.buildPushNotificationRegistrationResponse(publicKey, payload)
|
||||
if response == nil {
|
||||
return nil
|
||||
}
|
||||
encodedMessage, err := proto.Marshal(response)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rawMessage := &common.RawMessage{
|
||||
Payload: encodedMessage,
|
||||
MessageType: protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_REGISTRATION_RESPONSE,
|
||||
// we skip encryption as might be sent from an ephemeral key
|
||||
SkipEncryption: true,
|
||||
}
|
||||
|
||||
_, err = s.messageProcessor.SendPrivate(context.Background(), publicKey, rawMessage)
|
||||
return err
|
||||
}
|
||||
|
||||
// HandlePushNotificationQuery builds a response for the query and sends it back to the user
|
||||
func (s *Server) HandlePushNotificationQuery(publicKey *ecdsa.PublicKey, messageID []byte, query protobuf.PushNotificationQuery) error {
|
||||
response := s.buildPushNotificationQueryResponse(&query)
|
||||
if response == nil {
|
||||
return nil
|
||||
}
|
||||
response.MessageId = messageID
|
||||
encodedMessage, err := proto.Marshal(response)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rawMessage := &common.RawMessage{
|
||||
Payload: encodedMessage,
|
||||
MessageType: protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_QUERY_RESPONSE,
|
||||
// we skip encryption as sent from an ephemeral key
|
||||
SkipEncryption: true,
|
||||
}
|
||||
|
||||
_, err = s.messageProcessor.SendPrivate(context.Background(), publicKey, rawMessage)
|
||||
return err
|
||||
}
|
||||
|
||||
// HandlePushNotificationRequest will send a gorush notification and send a response back to the user
|
||||
func (s *Server) HandlePushNotificationRequest(publicKey *ecdsa.PublicKey,
|
||||
request protobuf.PushNotificationRequest) error {
|
||||
s.config.Logger.Debug("handling pn request")
|
||||
response := s.buildPushNotificationRequestResponseAndSendNotification(&request)
|
||||
if response == nil {
|
||||
return nil
|
||||
}
|
||||
encodedMessage, err := proto.Marshal(response)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rawMessage := &common.RawMessage{
|
||||
Payload: encodedMessage,
|
||||
MessageType: protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_RESPONSE,
|
||||
// We skip encryption here as the message has been sent from an ephemeral key
|
||||
SkipEncryption: true,
|
||||
}
|
||||
|
||||
_, err = s.messageProcessor.SendPrivate(context.Background(), publicKey, rawMessage)
|
||||
return err
|
||||
}
|
||||
|
||||
// buildGrantSignatureMaterial builds a grant for a specific server.
|
||||
// We use 3 components:
|
||||
// 1) The client public key. Not sure this applies to our signature scheme, but best to be conservative. https://crypto.stackexchange.com/questions/15538/given-a-message-and-signature-find-a-public-key-that-makes-the-signature-valid
|
||||
// 2) The server public key
|
||||
// 3) The access token
|
||||
// By verifying this signature, a client can trust the server was instructed to store this access token.
|
||||
func (s *Server) buildGrantSignatureMaterial(clientPublicKey *ecdsa.PublicKey, serverPublicKey *ecdsa.PublicKey, accessToken string) []byte {
|
||||
var signatureMaterial []byte
|
||||
signatureMaterial = append(signatureMaterial, crypto.CompressPubkey(clientPublicKey)...)
|
||||
signatureMaterial = append(signatureMaterial, crypto.CompressPubkey(serverPublicKey)...)
|
||||
signatureMaterial = append(signatureMaterial, []byte(accessToken)...)
|
||||
a := crypto.Keccak256(signatureMaterial)
|
||||
return a
|
||||
}
|
||||
|
||||
func (s *Server) verifyGrantSignature(clientPublicKey *ecdsa.PublicKey, accessToken string, grant []byte) error {
|
||||
signatureMaterial := s.buildGrantSignatureMaterial(clientPublicKey, &s.config.Identity.PublicKey, accessToken)
|
||||
recoveredPublicKey, err := crypto.SigToPub(signatureMaterial, grant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !common.IsPubKeyEqual(recoveredPublicKey, clientPublicKey) {
|
||||
return errors.New("pubkey mismatch")
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) generateSharedKey(publicKey *ecdsa.PublicKey) ([]byte, error) {
|
||||
return ecies.ImportECDSA(s.config.Identity).GenerateShared(
|
||||
ecies.ImportECDSAPublic(publicKey),
|
||||
encryptedPayloadKeyLength,
|
||||
encryptedPayloadKeyLength,
|
||||
)
|
||||
}
|
||||
|
||||
func (p *Server) validateUUID(u string) error {
|
||||
func (s *Server) validateUUID(u string) error {
|
||||
if len(u) == 0 {
|
||||
return errors.New("empty uuid")
|
||||
}
|
||||
|
@ -59,8 +194,8 @@ func (p *Server) validateUUID(u string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (p *Server) decryptRegistration(publicKey *ecdsa.PublicKey, payload []byte) ([]byte, error) {
|
||||
sharedKey, err := p.generateSharedKey(publicKey)
|
||||
func (s *Server) decryptRegistration(publicKey *ecdsa.PublicKey, payload []byte) ([]byte, error) {
|
||||
sharedKey, err := s.generateSharedKey(publicKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -68,9 +203,9 @@ func (p *Server) decryptRegistration(publicKey *ecdsa.PublicKey, payload []byte)
|
|||
return common.Decrypt(payload, sharedKey)
|
||||
}
|
||||
|
||||
// ValidateRegistration validates a new message against the last one received for a given installationID and and public key
|
||||
// validateRegistration validates a new message against the last one received for a given installationID and and public key
|
||||
// and return the decrypted message
|
||||
func (s *Server) ValidateRegistration(publicKey *ecdsa.PublicKey, payload []byte) (*protobuf.PushNotificationRegistration, error) {
|
||||
func (s *Server) validateRegistration(publicKey *ecdsa.PublicKey, payload []byte) (*protobuf.PushNotificationRegistration, error) {
|
||||
if payload == nil {
|
||||
return nil, ErrEmptyPushNotificationRegistrationPayload
|
||||
}
|
||||
|
@ -107,7 +242,7 @@ func (s *Server) ValidateRegistration(publicKey *ecdsa.PublicKey, payload []byte
|
|||
return nil, ErrInvalidPushNotificationRegistrationVersion
|
||||
}
|
||||
|
||||
// Unregistering message
|
||||
// unregistering message
|
||||
if registration.Unregister {
|
||||
return registration, nil
|
||||
}
|
||||
|
@ -126,7 +261,7 @@ func (s *Server) ValidateRegistration(publicKey *ecdsa.PublicKey, payload []byte
|
|||
return nil, ErrMalformedPushNotificationRegistrationGrant
|
||||
}
|
||||
|
||||
if len(registration.Token) == 0 {
|
||||
if len(registration.DeviceToken) == 0 {
|
||||
return nil, ErrMalformedPushNotificationRegistrationDeviceToken
|
||||
}
|
||||
|
||||
|
@ -137,9 +272,10 @@ func (s *Server) ValidateRegistration(publicKey *ecdsa.PublicKey, payload []byte
|
|||
return registration, nil
|
||||
}
|
||||
|
||||
func (s *Server) HandlePushNotificationQuery(query *protobuf.PushNotificationQuery) *protobuf.PushNotificationQueryResponse {
|
||||
// buildPushNotificationQueryResponse check if we have the client information and send them back
|
||||
func (s *Server) buildPushNotificationQueryResponse(query *protobuf.PushNotificationQuery) *protobuf.PushNotificationQueryResponse {
|
||||
|
||||
s.config.Logger.Info("handling push notification query")
|
||||
s.config.Logger.Debug("handling push notification query")
|
||||
response := &protobuf.PushNotificationQueryResponse{}
|
||||
if query == nil || len(query.PublicKeys) == 0 {
|
||||
return response
|
||||
|
@ -161,8 +297,9 @@ func (s *Server) HandlePushNotificationQuery(query *protobuf.PushNotificationQue
|
|||
InstallationId: registration.InstallationId,
|
||||
}
|
||||
|
||||
// if instructed to only allow from contacts, send back a list
|
||||
if registration.AllowFromContactsOnly {
|
||||
info.AllowedUserList = registration.AllowedUserList
|
||||
info.AllowedKeyList = registration.AllowedKeyList
|
||||
} else {
|
||||
info.AccessToken = registration.AccessToken
|
||||
}
|
||||
|
@ -173,8 +310,9 @@ func (s *Server) HandlePushNotificationQuery(query *protobuf.PushNotificationQue
|
|||
return response
|
||||
}
|
||||
|
||||
func (s *Server) HandlePushNotificationRequest(request *protobuf.PushNotificationRequest) *protobuf.PushNotificationResponse {
|
||||
s.config.Logger.Info("handling pn request")
|
||||
// buildPushNotificationRequestResponseAndSendNotification will build a response
|
||||
// and fire-and-forget send a query to the gorush instance
|
||||
func (s *Server) buildPushNotificationRequestResponseAndSendNotification(request *protobuf.PushNotificationRequest) *protobuf.PushNotificationResponse {
|
||||
response := &protobuf.PushNotificationResponse{}
|
||||
// We don't even send a response in this case
|
||||
if request == nil || len(request.MessageId) == 0 {
|
||||
|
@ -185,7 +323,7 @@ func (s *Server) HandlePushNotificationRequest(request *protobuf.PushNotificatio
|
|||
response.MessageId = request.MessageId
|
||||
|
||||
// TODO: filter by chat id
|
||||
// Collect successful requests & registrations
|
||||
// collect successful requests & registrations
|
||||
var requestAndRegistrations []*RequestAndRegistration
|
||||
|
||||
for _, pn := range request.Requests {
|
||||
|
@ -216,7 +354,7 @@ func (s *Server) HandlePushNotificationRequest(request *protobuf.PushNotificatio
|
|||
response.Reports = append(response.Reports, report)
|
||||
}
|
||||
|
||||
s.config.Logger.Info("built pn request")
|
||||
s.config.Logger.Debug("built pn request")
|
||||
if len(requestAndRegistrations) == 0 {
|
||||
s.config.Logger.Warn("no request and registration")
|
||||
return response
|
||||
|
@ -224,25 +362,35 @@ func (s *Server) HandlePushNotificationRequest(request *protobuf.PushNotificatio
|
|||
|
||||
// This can be done asynchronously
|
||||
goRushRequest := PushNotificationRegistrationToGoRushRequest(requestAndRegistrations)
|
||||
//TODO: REMOVE ME
|
||||
s.config.Logger.Info("REQUEST", zap.Any("REQUEST", goRushRequest))
|
||||
err := sendGoRushNotification(goRushRequest, s.config.GorushURL)
|
||||
if err != nil {
|
||||
s.config.Logger.Error("failed to send go rush notification", zap.Error(err))
|
||||
// TODO: handle this error?
|
||||
// GoRush will not let us know that the sending of the push notification has failed,
|
||||
// so this likely mean that the actual HTTP request has failed, or there was some unexpected error
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
func (s *Server) HandlePushNotificationRegistration(publicKey *ecdsa.PublicKey, payload []byte) *protobuf.PushNotificationRegistrationResponse {
|
||||
// listenToPublicKeyQueryTopic listen to a topic derived from the hashed public key
|
||||
func (s *Server) listenToPublicKeyQueryTopic(hashedPublicKey []byte) error {
|
||||
if s.messageProcessor == nil {
|
||||
return nil
|
||||
}
|
||||
encodedPublicKey := hex.EncodeToString(hashedPublicKey)
|
||||
return s.messageProcessor.JoinPublic(encodedPublicKey)
|
||||
}
|
||||
|
||||
// buildPushNotificationRegistrationResponse will check the registration is valid, save it, and listen to the topic for the queries
|
||||
func (s *Server) buildPushNotificationRegistrationResponse(publicKey *ecdsa.PublicKey, payload []byte) *protobuf.PushNotificationRegistrationResponse {
|
||||
|
||||
s.config.Logger.Info("handling push notification registration")
|
||||
response := &protobuf.PushNotificationRegistrationResponse{
|
||||
RequestId: common.Shake256(payload),
|
||||
}
|
||||
|
||||
registration, err := s.ValidateRegistration(publicKey, payload)
|
||||
registration, err := s.validateRegistration(publicKey, payload)
|
||||
|
||||
if err != nil {
|
||||
if err == ErrInvalidPushNotificationRegistrationVersion {
|
||||
|
@ -284,140 +432,3 @@ func (s *Server) HandlePushNotificationRegistration(publicKey *ecdsa.PublicKey,
|
|||
|
||||
return response
|
||||
}
|
||||
|
||||
func (s *Server) Start() error {
|
||||
s.config.Logger.Info("starting push notification server")
|
||||
if s.config.Identity == nil {
|
||||
s.config.Logger.Info("Identity nil")
|
||||
// Pull identity from database
|
||||
identity, err := s.persistence.GetIdentity()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if identity == nil {
|
||||
identity, err = crypto.GenerateKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.persistence.SaveIdentity(identity); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
s.config.Identity = identity
|
||||
}
|
||||
|
||||
pks, err := s.persistence.GetPushNotificationRegistrationPublicKeys()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, pk := range pks {
|
||||
if err := s.listenToPublicKeyQueryTopic(pk); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
s.config.Logger.Info("started push notification server", zap.String("identity", types.EncodeHex(crypto.FromECDSAPub(&s.config.Identity.PublicKey))))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) listenToPublicKeyQueryTopic(hashedPublicKey []byte) error {
|
||||
if s.messageProcessor == nil {
|
||||
return nil
|
||||
}
|
||||
encodedPublicKey := hex.EncodeToString(hashedPublicKey)
|
||||
return s.messageProcessor.JoinPublic(encodedPublicKey)
|
||||
}
|
||||
|
||||
func (p *Server) HandlePushNotificationRegistration2(publicKey *ecdsa.PublicKey, payload []byte) error {
|
||||
response := p.HandlePushNotificationRegistration(publicKey, payload)
|
||||
if response == nil {
|
||||
return nil
|
||||
}
|
||||
encodedMessage, err := proto.Marshal(response)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rawMessage := &common.RawMessage{
|
||||
Payload: encodedMessage,
|
||||
MessageType: protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_REGISTRATION_RESPONSE,
|
||||
}
|
||||
|
||||
_, err = p.messageProcessor.SendPrivate(context.Background(), publicKey, rawMessage)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *Server) HandlePushNotificationQuery2(publicKey *ecdsa.PublicKey, messageID []byte, query protobuf.PushNotificationQuery) error {
|
||||
response := p.HandlePushNotificationQuery(&query)
|
||||
if response == nil {
|
||||
return nil
|
||||
}
|
||||
response.MessageId = messageID
|
||||
encodedMessage, err := proto.Marshal(response)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rawMessage := &common.RawMessage{
|
||||
Payload: encodedMessage,
|
||||
MessageType: protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_QUERY_RESPONSE,
|
||||
SkipNegotiation: true,
|
||||
}
|
||||
|
||||
_, err = p.messageProcessor.SendPrivate(context.Background(), publicKey, rawMessage)
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) HandlePushNotificationRequest2(publicKey *ecdsa.PublicKey,
|
||||
request protobuf.PushNotificationRequest) error {
|
||||
s.config.Logger.Info("handling pn request")
|
||||
response := s.HandlePushNotificationRequest(&request)
|
||||
if response == nil {
|
||||
return nil
|
||||
}
|
||||
encodedMessage, err := proto.Marshal(response)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rawMessage := &common.RawMessage{
|
||||
Payload: encodedMessage,
|
||||
MessageType: protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_RESPONSE,
|
||||
SkipNegotiation: true,
|
||||
}
|
||||
|
||||
_, err = s.messageProcessor.SendPrivate(context.Background(), publicKey, rawMessage)
|
||||
return err
|
||||
}
|
||||
|
||||
// buildGrantSignatureMaterial builds a grant for a specific server.
|
||||
// We use 3 components:
|
||||
// 1) The client public key. Not sure this applies to our signature scheme, but best to be conservative. https://crypto.stackexchange.com/questions/15538/given-a-message-and-signature-find-a-public-key-that-makes-the-signature-valid
|
||||
// 2) The server public key
|
||||
// 3) The access token
|
||||
// By verifying this signature, a client can trust the server was instructed to store this access token.
|
||||
|
||||
func (s *Server) buildGrantSignatureMaterial(clientPublicKey *ecdsa.PublicKey, serverPublicKey *ecdsa.PublicKey, accessToken string) []byte {
|
||||
var signatureMaterial []byte
|
||||
signatureMaterial = append(signatureMaterial, crypto.CompressPubkey(clientPublicKey)...)
|
||||
signatureMaterial = append(signatureMaterial, crypto.CompressPubkey(serverPublicKey)...)
|
||||
signatureMaterial = append(signatureMaterial, []byte(accessToken)...)
|
||||
a := crypto.Keccak256(signatureMaterial)
|
||||
return a
|
||||
}
|
||||
|
||||
func (s *Server) verifyGrantSignature(clientPublicKey *ecdsa.PublicKey, accessToken string, grant []byte) error {
|
||||
signatureMaterial := s.buildGrantSignatureMaterial(clientPublicKey, &s.config.Identity.PublicKey, accessToken)
|
||||
recoveredPublicKey, err := crypto.SigToPub(signatureMaterial, grant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !common.IsPubKeyEqual(recoveredPublicKey, clientPublicKey) {
|
||||
return errors.New("pubkey mismatch")
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package push_notification_server
|
||||
package pushnotificationserver
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
|
@ -7,10 +7,10 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/sqlite"
|
||||
|
@ -76,35 +76,35 @@ func (s *ServerSuite) SetupTest() {
|
|||
func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
||||
|
||||
// Empty payload
|
||||
_, err := s.server.ValidateRegistration(&s.key.PublicKey, nil)
|
||||
_, err := s.server.validateRegistration(&s.key.PublicKey, nil)
|
||||
s.Require().Equal(ErrEmptyPushNotificationRegistrationPayload, err)
|
||||
|
||||
// Empty key
|
||||
_, err = s.server.ValidateRegistration(nil, []byte("payload"))
|
||||
_, err = s.server.validateRegistration(nil, []byte("payload"))
|
||||
s.Require().Equal(ErrEmptyPushNotificationRegistrationPublicKey, err)
|
||||
|
||||
// Invalid cyphertext length
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, []byte("too short"))
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, []byte("too short"))
|
||||
s.Require().Equal(common.ErrInvalidCiphertextLength, err)
|
||||
|
||||
// Invalid cyphertext length
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, []byte("too short"))
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, []byte("too short"))
|
||||
s.Require().Equal(common.ErrInvalidCiphertextLength, err)
|
||||
|
||||
// Invalid ciphertext
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, []byte("not too short but invalid"))
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, []byte("not too short but invalid"))
|
||||
s.Require().Error(common.ErrInvalidCiphertextLength, err)
|
||||
|
||||
// Different key ciphertext
|
||||
cyphertext, err := common.Encrypt([]byte("plaintext"), make([]byte, 32), rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Error(err)
|
||||
|
||||
// Right cyphertext but non unmarshable payload
|
||||
cyphertext, err = common.Encrypt([]byte("plaintext"), s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrCouldNotUnmarshalPushNotificationRegistration, err)
|
||||
|
||||
// Missing installationID
|
||||
|
@ -118,7 +118,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrMalformedPushNotificationRegistrationInstallationID, err)
|
||||
|
||||
// Malformed installationID
|
||||
|
@ -129,9 +129,11 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
InstallationId: "abc",
|
||||
Version: 1,
|
||||
})
|
||||
s.Require().NoError(err)
|
||||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrMalformedPushNotificationRegistrationInstallationID, err)
|
||||
|
||||
// Version set to 0
|
||||
|
@ -145,7 +147,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrInvalidPushNotificationRegistrationVersion, err)
|
||||
|
||||
// Version lower than previous one
|
||||
|
@ -169,7 +171,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
InstallationId: s.installationID,
|
||||
Version: 2}))
|
||||
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrInvalidPushNotificationRegistrationVersion, err)
|
||||
|
||||
// Cleanup persistence
|
||||
|
@ -185,7 +187,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Nil(err)
|
||||
|
||||
// Missing access token
|
||||
|
@ -199,7 +201,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrMalformedPushNotificationRegistrationAccessToken, err)
|
||||
|
||||
// Invalid access token
|
||||
|
@ -214,7 +216,7 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrMalformedPushNotificationRegistrationAccessToken, err)
|
||||
|
||||
// Missing device token
|
||||
|
@ -229,13 +231,13 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrMalformedPushNotificationRegistrationDeviceToken, err)
|
||||
|
||||
// Missing grant
|
||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||
AccessToken: s.accessToken,
|
||||
Token: "device-token",
|
||||
DeviceToken: "device-token",
|
||||
InstallationId: s.installationID,
|
||||
Version: 1,
|
||||
})
|
||||
|
@ -243,14 +245,14 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrMalformedPushNotificationRegistrationGrant, err)
|
||||
|
||||
// Invalid grant
|
||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||
AccessToken: s.accessToken,
|
||||
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||
Token: "device-token",
|
||||
DeviceToken: "device-token",
|
||||
Grant: crypto.Keccak256([]byte("invalid")),
|
||||
InstallationId: s.installationID,
|
||||
Version: 1,
|
||||
|
@ -259,13 +261,13 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrMalformedPushNotificationRegistrationGrant, err)
|
||||
|
||||
// Missing token type
|
||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||
AccessToken: s.accessToken,
|
||||
Token: "device-token",
|
||||
DeviceToken: "device-token",
|
||||
Grant: s.grant,
|
||||
InstallationId: s.installationID,
|
||||
Version: 1,
|
||||
|
@ -274,12 +276,12 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().Equal(ErrUnknownPushNotificationRegistrationTokenType, err)
|
||||
|
||||
// Successful
|
||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||
Token: "abc",
|
||||
DeviceToken: "abc",
|
||||
AccessToken: s.accessToken,
|
||||
Grant: s.grant,
|
||||
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||
|
@ -290,37 +292,37 @@ func (s *ServerSuite) TestPushNotificationServerValidateRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
_, err = s.server.ValidateRegistration(&s.key.PublicKey, cyphertext)
|
||||
_, err = s.server.validateRegistration(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
||||
// Empty payload
|
||||
response := s.server.HandlePushNotificationRegistration(&s.key.PublicKey, nil)
|
||||
response := s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, nil)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
||||
// Empty key
|
||||
response = s.server.HandlePushNotificationRegistration(nil, []byte("payload"))
|
||||
response = s.server.buildPushNotificationRegistrationResponse(nil, []byte("payload"))
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
||||
// Invalid cyphertext length
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, []byte("too short"))
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, []byte("too short"))
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
||||
// Invalid cyphertext length
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, []byte("too short"))
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, []byte("too short"))
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
||||
// Invalid ciphertext
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, []byte("not too short but invalid"))
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, []byte("not too short but invalid"))
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
@ -328,7 +330,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
// Different key ciphertext
|
||||
cyphertext, err := common.Encrypt([]byte("plaintext"), make([]byte, 32), rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
@ -336,7 +338,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
// Right cyphertext but non unmarshable payload
|
||||
cyphertext, err = common.Encrypt([]byte("plaintext"), s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
@ -351,7 +353,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
@ -363,9 +365,10 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
Grant: s.grant,
|
||||
Version: 1,
|
||||
})
|
||||
s.Require().NoError(err)
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
@ -380,7 +383,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_VERSION_MISMATCH)
|
||||
|
@ -404,7 +407,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
InstallationId: s.installationID,
|
||||
Version: 2}))
|
||||
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_VERSION_MISMATCH)
|
||||
|
@ -422,7 +425,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
@ -438,7 +441,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
@ -454,14 +457,14 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().False(response.Success)
|
||||
s.Require().Equal(response.Error, protobuf.PushNotificationRegistrationResponse_MALFORMED_MESSAGE)
|
||||
|
||||
// Successful
|
||||
registration := &protobuf.PushNotificationRegistration{
|
||||
Token: "abc",
|
||||
DeviceToken: "abc",
|
||||
AccessToken: s.accessToken,
|
||||
Grant: s.grant,
|
||||
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||
|
@ -473,7 +476,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().True(response.Success)
|
||||
|
||||
|
@ -485,7 +488,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
|
||||
// Unregistering message
|
||||
payload, err = proto.Marshal(&protobuf.PushNotificationRegistration{
|
||||
Token: "token",
|
||||
DeviceToken: "token",
|
||||
InstallationId: s.installationID,
|
||||
Unregister: true,
|
||||
Version: 2,
|
||||
|
@ -494,7 +497,7 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
|
||||
cyphertext, err = common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response = s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response = s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().True(response.Success)
|
||||
|
||||
|
@ -503,17 +506,17 @@ func (s *ServerSuite) TestPushNotificationHandleRegistration() {
|
|||
s.Require().NoError(err)
|
||||
s.Require().NotNil(retrievedRegistration)
|
||||
s.Require().Empty(retrievedRegistration.AccessToken)
|
||||
s.Require().Empty(retrievedRegistration.Token)
|
||||
s.Require().Empty(retrievedRegistration.DeviceToken)
|
||||
s.Require().Equal(uint64(2), retrievedRegistration.Version)
|
||||
s.Require().Equal(s.installationID, retrievedRegistration.InstallationId)
|
||||
s.Require().Equal(common.Shake256(cyphertext), response.RequestId)
|
||||
}
|
||||
|
||||
func (s *ServerSuite) TestHandlePushNotificationQueryNoFiltering() {
|
||||
func (s *ServerSuite) TestbuildPushNotificationQueryResponseNoFiltering() {
|
||||
hashedPublicKey := common.HashPublicKey(&s.key.PublicKey)
|
||||
// Successful
|
||||
registration := &protobuf.PushNotificationRegistration{
|
||||
Token: "abc",
|
||||
DeviceToken: "abc",
|
||||
AccessToken: s.accessToken,
|
||||
Grant: s.grant,
|
||||
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||
|
@ -525,7 +528,7 @@ func (s *ServerSuite) TestHandlePushNotificationQueryNoFiltering() {
|
|||
|
||||
cyphertext, err := common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response := s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response := s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().True(response.Success)
|
||||
|
||||
|
@ -533,29 +536,29 @@ func (s *ServerSuite) TestHandlePushNotificationQueryNoFiltering() {
|
|||
PublicKeys: [][]byte{[]byte("non-existing"), hashedPublicKey},
|
||||
}
|
||||
|
||||
queryResponse := s.server.HandlePushNotificationQuery(query)
|
||||
queryResponse := s.server.buildPushNotificationQueryResponse(query)
|
||||
s.Require().NotNil(queryResponse)
|
||||
s.Require().True(queryResponse.Success)
|
||||
s.Require().Len(queryResponse.Info, 1)
|
||||
s.Require().Equal(s.accessToken, queryResponse.Info[0].AccessToken)
|
||||
s.Require().Equal(hashedPublicKey, queryResponse.Info[0].PublicKey)
|
||||
s.Require().Equal(s.installationID, queryResponse.Info[0].InstallationId)
|
||||
s.Require().Nil(queryResponse.Info[0].AllowedUserList)
|
||||
s.Require().Nil(queryResponse.Info[0].AllowedKeyList)
|
||||
}
|
||||
|
||||
func (s *ServerSuite) TestHandlePushNotificationQueryWithFiltering() {
|
||||
func (s *ServerSuite) TestbuildPushNotificationQueryResponseWithFiltering() {
|
||||
hashedPublicKey := common.HashPublicKey(&s.key.PublicKey)
|
||||
allowedUserList := [][]byte{[]byte("a")}
|
||||
allowedKeyList := [][]byte{[]byte("a")}
|
||||
// Successful
|
||||
|
||||
registration := &protobuf.PushNotificationRegistration{
|
||||
Token: "abc",
|
||||
DeviceToken: "abc",
|
||||
AccessToken: s.accessToken,
|
||||
Grant: s.grant,
|
||||
TokenType: protobuf.PushNotificationRegistration_APN_TOKEN,
|
||||
InstallationId: s.installationID,
|
||||
AllowFromContactsOnly: true,
|
||||
AllowedUserList: allowedUserList,
|
||||
AllowedKeyList: allowedKeyList,
|
||||
Version: 1,
|
||||
}
|
||||
payload, err := proto.Marshal(registration)
|
||||
|
@ -563,7 +566,7 @@ func (s *ServerSuite) TestHandlePushNotificationQueryWithFiltering() {
|
|||
|
||||
cyphertext, err := common.Encrypt(payload, s.sharedKey, rand.Reader)
|
||||
s.Require().NoError(err)
|
||||
response := s.server.HandlePushNotificationRegistration(&s.key.PublicKey, cyphertext)
|
||||
response := s.server.buildPushNotificationRegistrationResponse(&s.key.PublicKey, cyphertext)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().True(response.Success)
|
||||
|
||||
|
@ -571,11 +574,11 @@ func (s *ServerSuite) TestHandlePushNotificationQueryWithFiltering() {
|
|||
PublicKeys: [][]byte{[]byte("non-existing"), hashedPublicKey},
|
||||
}
|
||||
|
||||
queryResponse := s.server.HandlePushNotificationQuery(query)
|
||||
queryResponse := s.server.buildPushNotificationQueryResponse(query)
|
||||
s.Require().NotNil(queryResponse)
|
||||
s.Require().True(queryResponse.Success)
|
||||
s.Require().Len(queryResponse.Info, 1)
|
||||
s.Require().Equal(hashedPublicKey, queryResponse.Info[0].PublicKey)
|
||||
s.Require().Equal(s.installationID, queryResponse.Info[0].InstallationId)
|
||||
s.Require().Equal(allowedUserList, queryResponse.Info[0].AllowedUserList)
|
||||
s.Require().Equal(allowedKeyList, queryResponse.Info[0].AllowedKeyList)
|
||||
}
|
|
@ -7,8 +7,8 @@ import (
|
|||
|
||||
encryptmigrations "github.com/status-im/status-go/protocol/encryption/migrations"
|
||||
appmigrations "github.com/status-im/status-go/protocol/migrations"
|
||||
push_notification_client_migrations "github.com/status-im/status-go/protocol/push_notification_client/migrations"
|
||||
push_notification_server_migrations "github.com/status-im/status-go/protocol/push_notification_server/migrations"
|
||||
push_notification_client_migrations "github.com/status-im/status-go/protocol/pushnotificationclient/migrations"
|
||||
push_notification_server_migrations "github.com/status-im/status-go/protocol/pushnotificationserver/migrations"
|
||||
wakumigrations "github.com/status-im/status-go/protocol/transport/waku/migrations"
|
||||
whispermigrations "github.com/status-im/status-go/protocol/transport/whisper/migrations"
|
||||
)
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/status-im/status-go/mailserver"
|
||||
"github.com/status-im/status-go/protocol"
|
||||
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
||||
"github.com/status-im/status-go/protocol/push_notification_client"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationclient"
|
||||
"github.com/status-im/status-go/protocol/transport"
|
||||
"github.com/status-im/status-go/services/ext/mailservers"
|
||||
)
|
||||
|
@ -403,30 +403,31 @@ func (api *PublicAPI) UpdateMailservers(enodes []string) error {
|
|||
return api.service.UpdateMailservers(nodes)
|
||||
}
|
||||
|
||||
// PushNotifications server
|
||||
// PushNotifications server endpoints
|
||||
|
||||
func (api *PublicAPI) StartPushNotificationServer() error {
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-server-enabled", true)
|
||||
func (api *PublicAPI) StartPushNotificationsServer() error {
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-server-enabled?", true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return api.service.messenger.StartPushNotificationServer()
|
||||
return api.service.messenger.StartPushNotificationsServer()
|
||||
}
|
||||
|
||||
func (api *PublicAPI) StopPushNotificationServer() error {
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-server-enabled", false)
|
||||
func (api *PublicAPI) StopPushNotificationsServer() error {
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-server-enabled?", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return api.service.messenger.StopPushNotificationServer()
|
||||
return api.service.messenger.StopPushNotificationsServer()
|
||||
}
|
||||
|
||||
// PushNotification client
|
||||
// PushNotification client endpoints
|
||||
|
||||
func (api *PublicAPI) RegisterForPushNotifications(ctx context.Context, deviceToken string) error {
|
||||
err := api.service.accountsDB.SaveSetting("remote-push-notifications-enabled", true)
|
||||
// We set both for now as they are equivalent
|
||||
err := api.service.accountsDB.SaveSetting("remote-push-notifications-enabled?", true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -439,7 +440,7 @@ func (api *PublicAPI) RegisterForPushNotifications(ctx context.Context, deviceTo
|
|||
}
|
||||
|
||||
func (api *PublicAPI) UnregisterForPushNotifications(ctx context.Context) error {
|
||||
err := api.service.accountsDB.SaveSetting("remote-push-notifications-enabled", false)
|
||||
err := api.service.accountsDB.SaveSetting("remote-push-notifications-enabled?", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -452,7 +453,7 @@ func (api *PublicAPI) UnregisterForPushNotifications(ctx context.Context) error
|
|||
}
|
||||
|
||||
func (api *PublicAPI) DisableSendingNotifications(ctx context.Context) error {
|
||||
err := api.service.accountsDB.SaveSetting("send-push-notifications", false)
|
||||
err := api.service.accountsDB.SaveSetting("send-push-notifications?", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -461,7 +462,7 @@ func (api *PublicAPI) DisableSendingNotifications(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (api *PublicAPI) EnableSendingNotifications(ctx context.Context) error {
|
||||
err := api.service.accountsDB.SaveSetting("send-push-notifications", true)
|
||||
err := api.service.accountsDB.SaveSetting("send-push-notifications?", true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -469,7 +470,7 @@ func (api *PublicAPI) EnableSendingNotifications(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (api *PublicAPI) EnablePushNotificationsFromContactsOnly(ctx context.Context) error {
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-from-contacts-only", true)
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-from-contacts-only?", true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -477,20 +478,20 @@ func (api *PublicAPI) EnablePushNotificationsFromContactsOnly(ctx context.Contex
|
|||
}
|
||||
|
||||
func (api *PublicAPI) DisablePushNotificationsFromContactsOnly(ctx context.Context) error {
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-from-contacts-only", false)
|
||||
err := api.service.accountsDB.SaveSetting("push-notifications-from-contacts-only?", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return api.service.messenger.DisablePushNotificationsFromContactsOnly()
|
||||
}
|
||||
|
||||
func (api *PublicAPI) AddPushNotificationServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
|
||||
func (api *PublicAPI) AddPushNotificationsServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
|
||||
publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return api.service.messenger.AddPushNotificationServer(ctx, publicKey)
|
||||
return api.service.messenger.AddPushNotificationsServer(ctx, publicKey)
|
||||
}
|
||||
|
||||
func (api *PublicAPI) RemovePushNotificationServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
|
||||
|
@ -502,7 +503,7 @@ func (api *PublicAPI) RemovePushNotificationServer(ctx context.Context, publicKe
|
|||
return api.service.messenger.RemovePushNotificationServer(ctx, publicKey)
|
||||
}
|
||||
|
||||
func (api *PublicAPI) GetPushNotificationServers() ([]*push_notification_client.PushNotificationServer, error) {
|
||||
func (api *PublicAPI) GetPushNotificationServers() ([]*pushnotificationclient.PushNotificationServer, error) {
|
||||
return api.service.messenger.GetPushNotificationServers()
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ import (
|
|||
coretypes "github.com/status-im/status-go/eth-node/core/types"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol"
|
||||
"github.com/status-im/status-go/protocol/push_notification_client"
|
||||
"github.com/status-im/status-go/protocol/push_notification_server"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationclient"
|
||||
"github.com/status-im/status-go/protocol/pushnotificationserver"
|
||||
"github.com/status-im/status-go/protocol/transport"
|
||||
)
|
||||
|
||||
|
@ -465,19 +465,20 @@ func buildMessengerOptions(
|
|||
options = append(options, protocol.WithDatasync())
|
||||
}
|
||||
settings, err := accountsDB.GetSettings()
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows && err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if settings.PushNotificationsServerEnabled {
|
||||
config := &push_notification_server.Config{
|
||||
config := &pushnotificationserver.Config{
|
||||
Logger: logger,
|
||||
}
|
||||
options = append(options, protocol.WithPushNotificationServerConfig(config))
|
||||
}
|
||||
|
||||
options = append(options, protocol.WithPushNotificationClientConfig(&push_notification_client.Config{
|
||||
options = append(options, protocol.WithPushNotificationClientConfig(&pushnotificationclient.Config{
|
||||
SendEnabled: settings.SendPushNotifications,
|
||||
AllowFromContactsOnly: settings.PushNotificationsFromContactsOnly,
|
||||
RemoteNotificationsEnabled: settings.RemotePushNotificationsEnabled,
|
||||
}))
|
||||
|
||||
|
|
|
@ -24,12 +24,12 @@ import (
|
|||
"github.com/syndtr/goleveldb/leveldb"
|
||||
"github.com/syndtr/goleveldb/leveldb/storage"
|
||||
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/services/ext"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/whisper/v6"
|
||||
)
|
||||
|
@ -209,7 +209,7 @@ func TestInitProtocol(t *testing.T) {
|
|||
tmpdir, err := ioutil.TempDir("", "test-shhext-service-init-protocol")
|
||||
require.NoError(t, err)
|
||||
|
||||
sqlDB, err := sqlite.OpenDB(fmt.Sprintf("%s/db.sql", tmpdir), "password")
|
||||
sqlDB, err := appdatabase.InitializeDB(fmt.Sprintf("%s/db.sql", tmpdir), "password")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = service.InitProtocol(privateKey, sqlDB, zap.NewNop())
|
||||
|
@ -262,7 +262,7 @@ func (s *ShhExtSuite) createAndAddNode() {
|
|||
s.Require().NoError(err)
|
||||
nodeWrapper := ext.NewTestNodeWrapper(gethbridge.NewGethWhisperWrapper(whisper), nil)
|
||||
service := New(config, nodeWrapper, nil, nil, db)
|
||||
sqlDB, err := sqlite.OpenDB(fmt.Sprintf("%s/%d", s.dir, idx), "password")
|
||||
sqlDB, err := appdatabase.InitializeDB(fmt.Sprintf("%s/%d", s.dir, idx), "password")
|
||||
s.Require().NoError(err)
|
||||
privateKey, err := crypto.GenerateKey()
|
||||
s.NoError(err)
|
||||
|
|
|
@ -23,12 +23,12 @@ import (
|
|||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/services/ext"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
"github.com/status-im/status-go/t/helpers"
|
||||
"github.com/status-im/status-go/waku"
|
||||
wakucommon "github.com/status-im/status-go/waku/common"
|
||||
|
@ -126,7 +126,7 @@ func TestInitProtocol(t *testing.T) {
|
|||
tmpdir, err := ioutil.TempDir("", "test-shhext-service-init-protocol")
|
||||
require.NoError(t, err)
|
||||
|
||||
sqlDB, err := sqlite.OpenDB(fmt.Sprintf("%s/db.sql", tmpdir), "password")
|
||||
sqlDB, err := appdatabase.InitializeDB(fmt.Sprintf("%s/db.sql", tmpdir), "password")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = service.InitProtocol(privateKey, sqlDB, zap.NewNop())
|
||||
|
@ -179,7 +179,7 @@ func (s *ShhExtSuite) createAndAddNode() {
|
|||
s.Require().NoError(err)
|
||||
nodeWrapper := ext.NewTestNodeWrapper(nil, gethbridge.NewGethWakuWrapper(w))
|
||||
service := New(config, nodeWrapper, nil, nil, db)
|
||||
sqlDB, err := sqlite.OpenDB(fmt.Sprintf("%s/%d", s.dir, idx), "password")
|
||||
sqlDB, err := appdatabase.InitializeDB(fmt.Sprintf("%s/%d", s.dir, idx), "password")
|
||||
s.Require().NoError(err)
|
||||
privateKey, err := crypto.GenerateKey()
|
||||
s.NoError(err)
|
||||
|
|
|
@ -97,7 +97,7 @@ func ConfigReadmeMd() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "../config/README.md", size: 3132, mode: os.FileMode(0644), modTime: time.Unix(1584434371, 0)}
|
||||
info := bindataFileInfo{name: "../config/README.md", size: 3132, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd0, 0x71, 0x14, 0x3e, 0x9d, 0x9c, 0x11, 0x40, 0xe1, 0xe9, 0x8b, 0xcc, 0x38, 0x17, 0x69, 0xb, 0xa7, 0xf2, 0x91, 0xa6, 0x4a, 0x9f, 0xd2, 0xc6, 0xf4, 0xff, 0x37, 0x5d, 0xd3, 0xed, 0x7c, 0xbd}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ func ConfigCliFleetEthProdJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "../config/cli/fleet-eth.prod.json", size: 3625, mode: os.FileMode(0644), modTime: time.Unix(1585559578, 0)}
|
||||
info := bindataFileInfo{name: "../config/cli/fleet-eth.prod.json", size: 3625, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x1c, 0x86, 0x93, 0x3b, 0x8c, 0xb4, 0x1b, 0x8b, 0x70, 0xe6, 0x90, 0x3, 0xc9, 0x93, 0x99, 0x97, 0x18, 0xb7, 0x49, 0xbf, 0x2d, 0x35, 0x98, 0xb8, 0x49, 0xa8, 0x73, 0x30, 0xf5, 0x2d, 0x7f, 0x5c}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ func ConfigCliFleetEthStagingJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1846, mode: os.FileMode(0644), modTime: time.Unix(1585559578, 0)}
|
||||
info := bindataFileInfo{name: "../config/cli/fleet-eth.staging.json", size: 1846, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xd1, 0xef, 0x3d, 0x5c, 0x41, 0xb1, 0xc8, 0x54, 0xd3, 0x82, 0x60, 0xcf, 0x5f, 0x8b, 0x92, 0xd0, 0x41, 0xa7, 0xff, 0xfd, 0x2c, 0x95, 0x44, 0x68, 0xd3, 0xad, 0x16, 0x8c, 0x49, 0x10, 0x4e, 0xb7}}
|
||||
return a, nil
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ func ConfigCliFleetEthTestJson() (*asset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1855, mode: os.FileMode(0644), modTime: time.Unix(1585559578, 0)}
|
||||
info := bindataFileInfo{name: "../config/cli/fleet-eth.test.json", size: 1855, mode: os.FileMode(0644), modTime: time.Unix(1595493797, 0)}
|
||||
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe4, 0x90, 0x4, 0x6, 0x2b, 0xe4, 0x67, 0x7a, 0xfc, 0x70, 0xa9, 0xb, 0x85, 0x8c, 0xb3, 0x8, 0x8e, 0xee, 0xec, 0x64, 0xb7, 0xac, 0x4c, 0x6, 0x4d, 0xcc, 0x4f, 0xda, 0xbd, 0xed, 0x17, 0x53}}
|
||||
return a, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue