Skip to content

Commit

Permalink
Fix crash when receiving a PreKey message in a new session.
Browse files Browse the repository at this point in the history
We don't allow creating recipients with only a UUID at the moment
(for good reason), but the way the decrypt method was written, it
was possible to do so. Until we have CDS, we should prefer the phone
number in scenarios like these.
  • Loading branch information
greyson-signal committed Dec 4, 2019
1 parent 6f91f62 commit db19077
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Expand Up @@ -293,7 +293,18 @@ private static SignalProtocolAddress getPreferredProtocolAddress(SignalProtocolS
} else if (e164Address != null && store.containsSession(e164Address)) {
return e164Address;
} else {
return new SignalProtocolAddress(address.getIdentifier(), sourceDevice);
// TODO [greyson][uuid] We should switch to preferring the UUID once we allow UUID-only recipients
String preferred;

if (address.getNumber().isPresent()) {
preferred = address.getNumber().get();
} else if (address.getUuid().isPresent()) {
preferred = address.getUuid().get().toString();
} else {
throw new AssertionError("Given the constrains of creating a SignalServiceAddress, this should not be possible.");
}

return new SignalProtocolAddress(preferred, sourceDevice);
}
}

Expand Down
Expand Up @@ -65,7 +65,7 @@ public String getIdentifier() {
} else if (e164.isPresent()) {
return e164.get();
} else {
return null;
throw new AssertionError("Given the checks in the constructor, this should not be possible.");
}
}

Expand Down

0 comments on commit db19077

Please sign in to comment.