Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
fix handling sealed sender envelopes
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Aug 21, 2022
1 parent ad86da8 commit db7dc60
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
8 changes: 7 additions & 1 deletion crayfish/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -33,6 +34,8 @@ type CrayfishInstance struct {
cmd *exec.Cmd
stopping bool
receiveChannel chan *CrayfishWebSocketResponseMessage
LocalUUID string
LocalDeviceID int32
}

const (
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion crayfish/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 3 additions & 1 deletion crayfish/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
14 changes: 9 additions & 5 deletions textsecure.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"io"
"os"
"strconv"
"strings"

"bytes"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit db7dc60

Please sign in to comment.