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

Commit

Permalink
fall back to uuid for incoming messages, when e164 fails
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Oct 2, 2021
1 parent c84e822 commit 7c74cc0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion contactsDiscovery/remoteAttestationUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func validateAndBuildRemoteAttestation(
enclaveName string,
) (*RemoteAttestation, error) {
keys, err := remoteAttestationKeys(keyPair, remoteAttestation.ServerEphemeralPublic, remoteAttestation.ServerStaticPublic)
log.Debugln("[textsecure] validateAndBuildRemoteAttestation ", err)
log.Debugln("[textsecure] validateAndBuildRemoteAttestation ")
if err != nil {
return nil, err
}
Expand Down
11 changes: 9 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,10 @@ func buildMessage(reciever string, paddedMessage []byte, devices []uint32, isSyn
if len(reciever) == 0 {
return nil, fmt.Errorf("empty reciever")
}
recid := recID(reciever)
recid, err := recID(reciever)
if err != nil {
return nil, err
}
messages := []jsonMessage{}
for _, devid := range devices {
if !textSecureStore.ContainsSession(recid, devid) {
Expand Down Expand Up @@ -884,7 +887,11 @@ func buildAndSendMessage(uuid string, paddedMessage []byte, isSync bool, timesta
dec.Decode(&j)
log.Debugf("[textsecure] Stale devices: %+v\n", j)
for _, id := range j.StaleDevices {
textSecureStore.DeleteSession(recID(uuid), id)
uuidCleanup, err := recID(uuid)
if err != nil {
return nil, err
}
textSecureStore.DeleteSession(uuidCleanup, id)
}
return buildAndSendMessage(uuid, paddedMessage, isSync, timestamp)
}
Expand Down
6 changes: 5 additions & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ func (err UnknownContactError) Error() string {
// ContactIdentityKey returns the serialized public key of the given contact
func ContactIdentityKey(id string) ([]byte, error) {
s := textSecureStore
idkeyfile := filepath.Join(s.identityDir, "remote_"+recID(id))
idClean, err := recID(id)
if err != nil {
return nil, err
}
idkeyfile := filepath.Join(s.identityDir, "remote_"+idClean)
if !exists(idkeyfile) {
return nil, UnknownContactError{id}
}
Expand Down
30 changes: 22 additions & 8 deletions textsecure.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ func EndSession(uuid string, msg string) (uint64, error) {
if err != nil {
return 0, err
}
textSecureStore.DeleteAllSessions(recID(uuid))
uuidClean, err := recID(uuid)
if err != nil {
return 0, err
}
textSecureStore.DeleteAllSessions(uuidClean)
return ts, nil
}

Expand Down Expand Up @@ -468,11 +472,15 @@ func handleReceipt(env *signalservice.Envelope) {
}

// recID removes the + from phone numbers
func recID(source string) string {
if source[0] == '+' {
return source[1:]
func recID(source string) (string, error) {
if len(source) == 0 {
return source[1:], nil
} else if len(source) > 0 && source[0] == '+' {
log.Errorln("[textsecure] invalid recipient id", source)
return "", errors.New("invalid recipient id")

}
return source
return source, nil
}

// EndSessionFlag signals that this message resets the session
Expand All @@ -485,8 +493,11 @@ func handleFlags(src string, dm *signalservice.DataMessage) (uint32, error) {
flags := uint32(0)
if dm.GetFlags() == uint32(signalservice.DataMessage_END_SESSION) {
flags = EndSessionFlag

textSecureStore.DeleteAllSessions(recID(src))
srcClean, err := recID(src)
if err != nil {
return 0, err
}
textSecureStore.DeleteAllSessions(srcClean)
textSecureStore.DeleteAllSessions(src)
}
if dm.GetFlags() == uint32(signalservice.DataMessage_PROFILE_KEY_UPDATE) {
Expand Down Expand Up @@ -567,7 +578,10 @@ func handleReceivedMessage(msg []byte) error {
// try the legacy way
log.Infof("[textsecure] Incoming WhisperMessage try legacy decrypting")

recid := recID(env.GetSourceE164())
recid, err := recID(env.GetSourceE164())
if err != nil {
recid = env.GetSourceUuid()
}
sc := axolotl.NewSessionCipher(textSecureStore, textSecureStore, textSecureStore, textSecureStore, recid, env.GetSourceDevice())
b, err = sc.SessionDecryptWhisperMessage(wm)
if _, ok := err.(axolotl.DuplicateMessageError); ok {
Expand Down

0 comments on commit 7c74cc0

Please sign in to comment.