Fix crash when receiving a PreKey message in a new session.

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.
master
Greyson Parrelli 2019-12-04 10:21:33 -05:00
parent 6f91f62db2
commit db19077834
2 changed files with 13 additions and 2 deletions

View File

@ -293,7 +293,18 @@ public class SignalServiceCipher {
} 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);
}
}

View File

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