From db7dc60f30a776c82c753718615ab59e7862f613 Mon Sep 17 00:00:00 2001 From: "aaron@nanu-c.org" Date: Sun, 21 Aug 2022 23:09:12 +0200 Subject: [PATCH] fix handling sealed sender envelopes --- cmd/textsecure/crayfish | 2 +- crayfish/backend.go | 8 +++++++- crayfish/envelope.go | 4 +++- crayfish/messages.go | 4 +++- textsecure.go | 14 +++++++++----- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cmd/textsecure/crayfish b/cmd/textsecure/crayfish index 7bbaf16..473c842 160000 --- a/cmd/textsecure/crayfish +++ b/cmd/textsecure/crayfish @@ -1 +1 @@ -Subproject commit 7bbaf1665234ce8dd3455ded2164b107fae7f972 +Subproject commit 473c842e45e32cd2a02b4c6281d06b0a2aec2058 diff --git a/crayfish/backend.go b/crayfish/backend.go index 31cdc25..b5a11bd 100644 --- a/crayfish/backend.go +++ b/crayfish/backend.go @@ -17,6 +17,7 @@ import ( // "github.com/nanu-c/textsecure/app/ui" + "github.com/signal-golang/textsecure/config" "github.com/signal-golang/textsecure/rootCa" log "github.com/sirupsen/logrus" ) @@ -33,6 +34,8 @@ type CrayfishInstance struct { cmd *exec.Cmd stopping bool receiveChannel chan *CrayfishWebSocketResponseMessage + LocalUUID string + LocalDeviceID int32 } const ( @@ -109,7 +112,10 @@ type Conn struct { } func Run() { - Instance = &CrayfishInstance{} + Instance = &CrayfishInstance{ + LocalUUID: config.ConfigFile.UUID, + LocalDeviceID: 0, + } log.Infoln("[textsecure-crayfish] Starting crayfish-backend") path, err := exec.LookPath("crayfish") if err != nil { diff --git a/crayfish/envelope.go b/crayfish/envelope.go index 96d745c..b7c2833 100644 --- a/crayfish/envelope.go +++ b/crayfish/envelope.go @@ -12,7 +12,9 @@ func (c *CrayfishInstance) HandleEnvelope(msg []byte) (*CrayfishWebSocketRespons requestType := CrayfishWebSocketRequestMessageTyp_HANDLE_ENVELOPE sEnc := b64.StdEncoding.EncodeToString(msg) envelopeMessage := &CrayfishWebSocketRequest_HANDLE_ENVELOPE_MESSAGE{ - Message: sEnc, + Message: sEnc, + LocalUUUID: c.LocalUUID, + LocalDeviceID: c.LocalDeviceID, } log.Debugln("[textsecure-crayfish-ws] Sending envelope") diff --git a/crayfish/messages.go b/crayfish/messages.go index 239b6f5..f5fa085 100644 --- a/crayfish/messages.go +++ b/crayfish/messages.go @@ -21,7 +21,9 @@ type CrayfishWebSocketResponse_VERIFY_REGISTER_MESSAGE struct { StorageCapable bool `json:"storage_capable"` } type CrayfishWebSocketRequest_HANDLE_ENVELOPE_MESSAGE struct { - Message string `json:"message"` + Message string `json:"message"` + LocalUUUID string `json:"local_uuid"` + LocalDeviceID int32 `json:"local_device_id"` } type CrayfishWebSocketResponse_HANDLE_ENVELOPE_MESSAGE struct { Message string `json:"message"` diff --git a/textsecure.go b/textsecure.go index d820dc7..8ab3dcb 100644 --- a/textsecure.go +++ b/textsecure.go @@ -10,7 +10,6 @@ import ( "fmt" "io" "os" - "strconv" "strings" "bytes" @@ -261,11 +260,11 @@ func setupLogging() { // Setup initializes the package. func Setup(c *Client) error { - go crayfish.Run() var err error client = c config.ConfigFile, err = loadConfig() + go crayfish.Run() if err != nil { return err } @@ -634,6 +633,7 @@ func handleReceivedMessage(env *signalservice.Envelope) error { } p, _ := proto.Marshal(env) + log.Debugf("[textsecure] Incoming UnidentifiedSenderMessage %s.\n", env) data, err := crayfish.Instance.HandleEnvelope(p) if err != nil { return err @@ -643,9 +643,13 @@ func handleReceivedMessage(env *signalservice.Envelope) error { return err } env.Content = content - phoneNumber := "+" + strconv.FormatUint(data.Sender.PhoneNumber.Code.Value, 10) + strconv.FormatUint(data.Sender.PhoneNumber.National.Value, 10) - log.Println("[textsecure] handleReceivedMessage:", phoneNumber, data.Sender.UUID) - err = handleMessage(phoneNumber, data.Sender.UUID, uint64(data.Timestamp), content) + log.Println("[textsecure] handleReceivedMessage:", data.Sender.UUID) + log.Debugln("[textsecure] handleReceivedMessage content length: ", len(content)) + if len(content) == 0 { + err = errors.New("[textsecure] handleReceivedMessage content length is 0") + return err + } + err = handleMessage("", data.Sender.UUID, uint64(data.Timestamp), content) if err != nil { return err }