2019-11-21 16:19:22 +00:00
|
|
|
package protocol
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
"encoding/json"
|
2020-07-22 14:54:24 +00:00
|
|
|
"reflect"
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"github.com/jinzhu/copier"
|
2019-09-26 07:01:17 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2021-11-11 16:13:55 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2019-11-23 17:57:05 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2019-11-21 16:19:22 +00:00
|
|
|
"github.com/status-im/status-go/protocol/encryption"
|
2020-07-31 12:22:05 +00:00
|
|
|
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
|
|
|
"github.com/status-im/status-go/protocol/encryption/sharedsecret"
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2019-07-26 07:17:29 +00:00
|
|
|
)
|
|
|
|
|
2019-11-06 16:23:11 +00:00
|
|
|
type StatusMessageT int
|
|
|
|
|
2019-07-26 07:17:29 +00:00
|
|
|
// StatusMessage is any Status Protocol message.
|
|
|
|
type StatusMessage struct {
|
2019-09-26 07:01:17 +00:00
|
|
|
// TransportMessage is the parsed message received from the transport layer, i.e the input
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
TransportMessage *types.Message `json:"transportMessage"`
|
2019-12-02 15:34:05 +00:00
|
|
|
// Type is the type of application message contained
|
|
|
|
Type protobuf.ApplicationMetadataMessage_Type `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
// ParsedMessage is the parsed message by the application layer, i.e the output
|
2020-07-27 10:13:22 +00:00
|
|
|
ParsedMessage *reflect.Value `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
// TransportPayload is the payload as received from the transport layer
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
TransportPayload []byte `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
// DecryptedPayload is the payload after having been processed by the encryption layer
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
DecryptedPayload []byte `json:"decryptedPayload"`
|
2020-11-18 09:16:51 +00:00
|
|
|
// UnwrappedPayload is the payload after having been unwrapped from the applicaition metadata layer
|
|
|
|
UnwrappedPayload []byte `json:"unwrappedPayload"`
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
// ID is the canonical ID of the message
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
ID types.HexBytes `json:"id"`
|
2019-07-26 07:17:29 +00:00
|
|
|
// Hash is the transport layer hash
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
Hash []byte `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
|
2020-07-03 10:08:47 +00:00
|
|
|
// Dst is the targeted public key
|
|
|
|
Dst *ecdsa.PublicKey
|
|
|
|
|
2019-07-26 07:17:29 +00:00
|
|
|
// TransportLayerSigPubKey contains the public key provided by the transport layer
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
TransportLayerSigPubKey *ecdsa.PublicKey `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
// ApplicationMetadataLayerPubKey contains the public key provided by the application metadata layer
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
ApplicationMetadataLayerSigPubKey *ecdsa.PublicKey `json:"-"`
|
2020-07-31 12:22:05 +00:00
|
|
|
|
|
|
|
// Installations is the new installations returned by the encryption layer
|
|
|
|
Installations []*multidevice.Installation
|
|
|
|
// SharedSecret is the shared secret returned by the encryption layer
|
|
|
|
SharedSecrets []*sharedsecret.Secret
|
2022-09-21 16:05:29 +00:00
|
|
|
|
|
|
|
// HashRatchetInfo is the information about a new hash ratchet group/key pair
|
|
|
|
HashRatchetInfo []*encryption.HashRatchetInfo
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Temporary JSON marshaling for those messages that are not yet processed
|
|
|
|
// by the go code
|
|
|
|
func (m *StatusMessage) MarshalJSON() ([]byte, error) {
|
|
|
|
item := struct {
|
|
|
|
ID types.HexBytes `json:"id"`
|
|
|
|
Payload string `json:"payload"`
|
|
|
|
From types.HexBytes `json:"from"`
|
|
|
|
Timestamp uint32 `json:"timestamp"`
|
|
|
|
}{
|
|
|
|
ID: m.ID,
|
2020-11-18 09:16:51 +00:00
|
|
|
Payload: string(m.UnwrappedPayload),
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
Timestamp: m.TransportMessage.Timestamp,
|
|
|
|
From: m.TransportMessage.Sig,
|
|
|
|
}
|
|
|
|
return json.Marshal(item)
|
2019-07-26 07:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SigPubKey returns the most important signature, from the application layer to transport
|
2019-11-23 17:57:05 +00:00
|
|
|
func (m *StatusMessage) SigPubKey() *ecdsa.PublicKey {
|
|
|
|
if m.ApplicationMetadataLayerSigPubKey != nil {
|
|
|
|
return m.ApplicationMetadataLayerSigPubKey
|
2019-07-26 07:17:29 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
return m.TransportLayerSigPubKey
|
2019-07-26 07:17:29 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
func (m *StatusMessage) Clone() (*StatusMessage, error) {
|
2019-07-26 07:17:29 +00:00
|
|
|
copy := &StatusMessage{}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
err := copier.Copy(©, m)
|
2019-07-26 07:17:29 +00:00
|
|
|
return copy, err
|
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
func (m *StatusMessage) HandleTransport(shhMessage *types.Message) error {
|
2019-07-26 07:17:29 +00:00
|
|
|
publicKey, err := crypto.UnmarshalPubkey(shhMessage.Sig)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get signature")
|
|
|
|
}
|
|
|
|
|
|
|
|
m.TransportMessage = shhMessage
|
|
|
|
m.Hash = shhMessage.Hash
|
|
|
|
m.TransportLayerSigPubKey = publicKey
|
|
|
|
m.TransportPayload = shhMessage.Payload
|
|
|
|
|
2020-07-03 10:08:47 +00:00
|
|
|
if shhMessage.Dst != nil {
|
|
|
|
publicKey, err := crypto.UnmarshalPubkey(shhMessage.Dst)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.Dst = publicKey
|
|
|
|
}
|
|
|
|
|
2019-07-26 07:17:29 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-21 15:41:10 +00:00
|
|
|
func (m *StatusMessage) HandleEncryption(myKey *ecdsa.PrivateKey, senderKey *ecdsa.PublicKey, enc *encryption.Protocol, skipNegotiation bool) error {
|
2019-07-26 07:17:29 +00:00
|
|
|
// As we handle non-encrypted messages, we make sure that DecryptPayload
|
|
|
|
// is set regardless of whether this step is successful
|
|
|
|
m.DecryptedPayload = m.TransportPayload
|
2020-07-21 15:41:10 +00:00
|
|
|
// Nothing to do
|
|
|
|
if skipNegotiation {
|
|
|
|
return nil
|
|
|
|
}
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
var protocolMessage encryption.ProtocolMessage
|
|
|
|
err := proto.Unmarshal(m.TransportPayload, &protocolMessage)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to unmarshal ProtocolMessage")
|
|
|
|
}
|
|
|
|
|
2020-07-31 12:22:05 +00:00
|
|
|
response, err := enc.HandleMessage(
|
2019-07-26 07:17:29 +00:00
|
|
|
myKey,
|
|
|
|
senderKey,
|
|
|
|
&protocolMessage,
|
|
|
|
m.Hash,
|
|
|
|
)
|
|
|
|
|
2022-09-21 16:05:29 +00:00
|
|
|
if err == encryption.ErrHashRatchetGroupIDNotFound {
|
|
|
|
|
|
|
|
if response != nil {
|
|
|
|
m.HashRatchetInfo = response.HashRatchetInfo
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-26 07:17:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to handle Encryption message")
|
|
|
|
}
|
|
|
|
|
2020-07-31 12:22:05 +00:00
|
|
|
m.DecryptedPayload = response.DecryptedMessage
|
|
|
|
m.Installations = response.Installations
|
|
|
|
m.SharedSecrets = response.SharedSecrets
|
2022-09-21 16:05:29 +00:00
|
|
|
m.HashRatchetInfo = response.HashRatchetInfo
|
2019-07-26 07:17:29 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *StatusMessage) HandleApplicationMetadata() error {
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
message, err := protobuf.Unmarshal(m.DecryptedPayload)
|
2019-07-26 07:17:29 +00:00
|
|
|
if err != nil {
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
return err
|
2019-07-26 07:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
recoveredKey, err := message.RecoverKey()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.ApplicationMetadataLayerSigPubKey = recoveredKey
|
2019-08-27 12:04:15 +00:00
|
|
|
// Calculate ID using the wrapped record
|
|
|
|
m.ID = MessageID(recoveredKey, m.DecryptedPayload)
|
2021-11-11 16:13:55 +00:00
|
|
|
log.Debug("calculated ID for envelope", "envelopeHash", hexutil.Encode(m.Hash), "messageId", hexutil.Encode(m.ID))
|
|
|
|
|
2020-11-18 09:16:51 +00:00
|
|
|
m.UnwrappedPayload = message.Payload
|
2019-12-02 15:34:05 +00:00
|
|
|
m.Type = message.Type
|
2019-07-26 07:17:29 +00:00
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *StatusMessage) HandleApplication() error {
|
2019-12-02 15:34:05 +00:00
|
|
|
switch m.Type {
|
|
|
|
case protobuf.ApplicationMetadataMessage_CHAT_MESSAGE:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.ChatMessage))
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
|
2019-12-02 15:34:05 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.MembershipUpdateMessage))
|
2019-12-02 15:34:05 +00:00
|
|
|
|
2020-01-10 18:59:01 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.AcceptRequestAddressForTransaction))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_SEND_TRANSACTION:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.SendTransaction))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_REQUEST_TRANSACTION:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.RequestTransaction))
|
2019-12-02 15:34:05 +00:00
|
|
|
|
2020-01-10 18:59:01 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.DeclineRequestAddressForTransaction))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.DeclineRequestTransaction))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_REQUEST_ADDRESS_FOR_TRANSACTION:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.RequestAddressForTransaction))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_CONTACT_UPDATE:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.ContactUpdate))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
2021-05-14 21:22:50 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_PIN_MESSAGE:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.PinMessage))
|
|
|
|
|
2020-01-10 18:59:01 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncInstallation))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT:
|
2021-11-11 16:13:55 +00:00
|
|
|
log.Debug("Sync installation contact")
|
2021-09-03 08:26:05 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncInstallationContactV2))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncInstallationPublicChat))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncInstallationAccount))
|
2020-01-10 18:59:01 +00:00
|
|
|
|
2022-03-24 09:35:56 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_PROFILE_PICTURE:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncProfilePictures))
|
|
|
|
|
2020-01-10 18:59:01 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_PAIR_INSTALLATION:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.PairInstallation))
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_COMMUNITY:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncCommunity))
|
2020-07-03 08:26:35 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_CONTACT_CODE_ADVERTISEMENT:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.ContactCodeAdvertisement))
|
2020-07-03 08:26:35 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_REQUEST:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.PushNotificationRequest))
|
2020-07-03 08:26:35 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_REGISTRATION_RESPONSE:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.PushNotificationRegistrationResponse))
|
2020-07-03 08:26:35 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_QUERY:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.PushNotificationQuery))
|
2020-07-03 08:26:35 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_QUERY_RESPONSE:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.PushNotificationQueryResponse))
|
2020-07-03 08:26:35 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_RESPONSE:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.PushNotificationResponse))
|
2020-07-22 12:59:53 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_EMOJI_REACTION:
|
2020-07-22 14:54:24 +00:00
|
|
|
return m.unmarshalProtobufData(new(protobuf.EmojiReaction))
|
2020-08-07 13:49:37 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_GROUP_CHAT_INVITATION:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.GroupChatInvitation))
|
2020-11-18 09:16:51 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_COMMUNITY_DESCRIPTION:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.CommunityDescription))
|
|
|
|
case protobuf.ApplicationMetadataMessage_COMMUNITY_INVITATION:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.CommunityInvitation))
|
2021-01-11 10:32:51 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.CommunityRequestToJoin))
|
2022-07-01 13:54:02 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN_RESPONSE:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.CommunityRequestToJoinResponse))
|
2022-10-28 08:41:20 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_COMMUNITY_CANCEL_REQUEST_TO_JOIN:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.CommunityCancelRequestToJoin))
|
2022-08-22 10:10:31 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_LEAVE:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.CommunityRequestToLeave))
|
2021-06-07 08:31:27 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_EDIT_MESSAGE:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.EditMessage))
|
2021-07-26 21:06:32 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_DELETE_MESSAGE:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.DeleteMessage))
|
2022-09-28 11:42:17 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_DELETE_FOR_ME_MESSAGE:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.DeleteForMeMessage))
|
2021-07-22 17:41:49 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_STATUS_UPDATE:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.StatusUpdate))
|
2020-07-22 14:54:24 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_REGISTRATION:
|
|
|
|
// This message is a bit different as it's encrypted, so we pass it straight through
|
2020-11-18 09:16:51 +00:00
|
|
|
v := reflect.ValueOf(m.UnwrappedPayload)
|
2020-07-27 10:13:22 +00:00
|
|
|
m.ParsedMessage = &v
|
2020-07-22 14:54:24 +00:00
|
|
|
return nil
|
2020-12-02 14:21:26 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_CHAT_IDENTITY:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.ChatIdentity))
|
2021-09-01 12:02:18 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_ANONYMOUS_METRIC_BATCH:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.AnonymousMetricBatch))
|
2021-10-05 17:26:02 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_CHAT_REMOVED:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncChatRemoved))
|
2021-10-12 10:33:32 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_CHAT_MESSAGES_READ:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncChatMessagesRead))
|
2021-10-11 15:39:52 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_BACKUP:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.Backup))
|
2021-12-02 14:23:02 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_ACTIVITY_CENTER_READ:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncActivityCenterRead))
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_ACTIVITY_CENTER_ACCEPTED:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncActivityCenterAccepted))
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_ACTIVITY_CENTER_DISMISSED:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncActivityCenterDismissed))
|
2022-01-17 03:42:11 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_BOOKMARK:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncBookmark))
|
2022-02-10 10:00:59 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_CLEAR_HISTORY:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncClearHistory))
|
2022-03-23 18:47:00 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_SETTING:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncSetting))
|
2022-04-22 07:42:22 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_COMMUNITY_ARCHIVE_MAGNETLINK:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.CommunityMessageArchiveMagnetlink))
|
2023-05-16 10:48:00 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_ACCOUNT:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncAccount))
|
2022-01-18 16:31:34 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_ACCEPT_CONTACT_REQUEST:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.AcceptContactRequest))
|
|
|
|
case protobuf.ApplicationMetadataMessage_RETRACT_CONTACT_REQUEST:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.RetractContactRequest))
|
2022-06-01 07:55:48 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_COMMUNITY_SETTINGS:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncCommunitySettings))
|
2022-07-05 19:49:44 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_REQUEST_CONTACT_VERIFICATION:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.RequestContactVerification))
|
|
|
|
case protobuf.ApplicationMetadataMessage_ACCEPT_CONTACT_VERIFICATION:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.AcceptContactVerification))
|
2022-12-14 08:27:02 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_CANCEL_CONTACT_VERIFICATION:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.CancelContactVerification))
|
2022-07-05 19:49:44 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_DECLINE_CONTACT_VERIFICATION:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.DeclineContactVerification))
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_TRUSTED_USER:
|
|
|
|
return m.unmarshalProtobufData((new(protobuf.SyncTrustedUser)))
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_VERIFICATION_REQUEST:
|
|
|
|
return m.unmarshalProtobufData((new(protobuf.SyncVerificationRequest)))
|
2022-08-07 14:25:03 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_CONTACT_REQUEST_DECISION:
|
|
|
|
return m.unmarshalProtobufData((new(protobuf.SyncContactRequestDecision)))
|
2022-09-14 10:46:11 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_SAVED_ADDRESS:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncSavedAddress))
|
2023-02-21 12:35:26 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_KEYCARD_ACTION:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncKeycardAction))
|
2023-06-05 11:10:26 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_SOCIAL_LINKS:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncSocialLinks))
|
2023-04-26 15:37:18 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_ENS_USERNAME_DETAIL:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncEnsUsernameDetail))
|
2023-05-16 10:48:00 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_KEYPAIR:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncKeypair))
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_FULL_KEYPAIR:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncKeypairFull))
|
2023-06-10 02:00:17 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_ACTIVITY_CENTER_NOTIFICATION:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncActivityCenterNotifications))
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_ACTIVITY_CENTER_NOTIFICATION_STATE:
|
|
|
|
return m.unmarshalProtobufData(new(protobuf.SyncActivityCenterNotificationState))
|
2020-01-10 18:59:01 +00:00
|
|
|
}
|
2019-07-26 07:17:29 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-07-22 14:54:24 +00:00
|
|
|
|
|
|
|
func (m *StatusMessage) unmarshalProtobufData(pb proto.Message) error {
|
|
|
|
var ptr proto.Message
|
|
|
|
rv := reflect.ValueOf(pb)
|
|
|
|
if rv.Kind() == reflect.Ptr {
|
|
|
|
ptr = pb
|
|
|
|
} else {
|
|
|
|
ptr = rv.Addr().Interface().(proto.Message)
|
|
|
|
}
|
|
|
|
|
2020-11-18 09:16:51 +00:00
|
|
|
err := proto.Unmarshal(m.UnwrappedPayload, ptr)
|
2020-07-22 14:54:24 +00:00
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
2021-11-11 16:13:55 +00:00
|
|
|
log.Error("[message::DecodeMessage] could not decode %T: %#x, err: %v", pb, m.Hash, err.Error())
|
2020-07-22 14:54:24 +00:00
|
|
|
} else {
|
|
|
|
rv = reflect.ValueOf(ptr)
|
2020-07-27 10:13:22 +00:00
|
|
|
elem := rv.Elem()
|
|
|
|
m.ParsedMessage = &elem
|
2020-07-22 14:54:24 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|