- theirProfileKey = new ProfileKey(Base64.decode(contact.profileKey));
- } catch (InvalidInputException e) {
- throw new AssertionError(e);
- }
- SignalProfile targetProfile = decryptProfile(getRecipientProfile(recipient, Optional.absent()), theirProfileKey);
-
- if (targetProfile == null || targetProfile.getUnidentifiedAccess() == null) {
- return null;
- }
-
- if (targetProfile.isUnrestrictedUnidentifiedAccess()) {
- return KeyUtils.createUnrestrictedUnidentifiedAccess();
- }
-
- return UnidentifiedAccess.deriveAccessKeyFrom(theirProfileKey);
- }
-
- private Optional<UnidentifiedAccessPair> getAccessForSync() throws IOException {
- byte[] selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey();
- byte[] selfUnidentifiedAccessCertificate = getSenderCertificate();
-
- if (selfUnidentifiedAccessKey == null || selfUnidentifiedAccessCertificate == null) {
- return Optional.absent();
- }
-
- try {
- return Optional.of(new UnidentifiedAccessPair(
- new UnidentifiedAccess(selfUnidentifiedAccessKey, selfUnidentifiedAccessCertificate),
- new UnidentifiedAccess(selfUnidentifiedAccessKey, selfUnidentifiedAccessCertificate)
- ));
- } catch (InvalidCertificateException e) {
- return Optional.absent();
- }
- }
-
- private List<Optional<UnidentifiedAccessPair>> getAccessFor(Collection<SignalServiceAddress> recipients) throws IOException {
- List<Optional<UnidentifiedAccessPair>> result = new ArrayList<>(recipients.size());
- for (SignalServiceAddress recipient : recipients) {
- result.add(getAccessFor(recipient));
- }
- return result;
- }
-
- private Optional<UnidentifiedAccessPair> getAccessFor(SignalServiceAddress recipient) throws IOException {
- byte[] recipientUnidentifiedAccessKey = getTargetUnidentifiedAccessKey(recipient);
- byte[] selfUnidentifiedAccessKey = getSelfUnidentifiedAccessKey();
- byte[] selfUnidentifiedAccessCertificate = getSenderCertificate();
-
- if (recipientUnidentifiedAccessKey == null || selfUnidentifiedAccessKey == null || selfUnidentifiedAccessCertificate == null) {
- return Optional.absent();
- }
-
- try {
- return Optional.of(new UnidentifiedAccessPair(
- new UnidentifiedAccess(recipientUnidentifiedAccessKey, selfUnidentifiedAccessCertificate),
- new UnidentifiedAccess(selfUnidentifiedAccessKey, selfUnidentifiedAccessCertificate)
- ));
- } catch (InvalidCertificateException e) {
- return Optional.absent();
- }
- }
-
- private void sendSyncMessage(SignalServiceSyncMessage message)
- throws IOException, UntrustedIdentityException {
- SignalServiceMessageSender messageSender = getMessageSender();
- try {
- messageSender.sendMessage(message, getAccessForSync());
- } catch (UntrustedIdentityException e) {
- account.getSignalProtocolStore().saveIdentity(e.getIdentifier(), e.getIdentityKey(), TrustLevel.UNTRUSTED);
- throw e;
- }
- }
-
- /**
- * This method throws an EncapsulatedExceptions exception instead of returning a list of SendMessageResult.
- */
- private void sendMessageLegacy(SignalServiceDataMessage.Builder messageBuilder, Collection<SignalServiceAddress> recipients)
- throws EncapsulatedExceptions, IOException {
- List<SendMessageResult> results = sendMessage(messageBuilder, recipients);
-
- List<UntrustedIdentityException> untrustedIdentities = new LinkedList<>();
- List<UnregisteredUserException> unregisteredUsers = new LinkedList<>();
- List<NetworkFailureException> networkExceptions = new LinkedList<>();
-
- for (SendMessageResult result : results) {
- if (result.isUnregisteredFailure()) {
- unregisteredUsers.add(new UnregisteredUserException(result.getAddress().getNumber().get(), null));
- } else if (result.isNetworkFailure()) {
- networkExceptions.add(new NetworkFailureException(result.getAddress().getNumber().get(), null));
- } else if (result.getIdentityFailure() != null) {
- untrustedIdentities.add(new UntrustedIdentityException("Untrusted", result.getAddress().getNumber().get(), result.getIdentityFailure().getIdentityKey()));
- }
- }
- if (!untrustedIdentities.isEmpty() || !unregisteredUsers.isEmpty() || !networkExceptions.isEmpty()) {
- throw new EncapsulatedExceptions(untrustedIdentities, unregisteredUsers, networkExceptions);
- }
- }
-
- private Collection<SignalServiceAddress> getSignalServiceAddresses(Collection<String> numbers) throws InvalidNumberException {
- final Set<SignalServiceAddress> signalServiceAddresses = new HashSet<>(numbers.size());
- final String username = account.getUsername();
-
- for (String number : numbers) {
- String canonicalizedNumber = Utils.canonicalizeNumber(number, username);
- if (canonicalizedNumber.equals(username)) {
- signalServiceAddresses.add(account.getSelfAddress());
+ registeredUsers = accountManager.getRegisteredUsers(getIasKeyStore(),
+ missingUuids.stream().map(a -> a.getNumber().get()).collect(Collectors.toSet()),
+ CDS_MRENCLAVE);
+ } catch (IOException | Quote.InvalidQuoteFormatException | UnauthenticatedQuoteException | SignatureException | UnauthenticatedResponseException e) {
+ logger.warn("Failed to resolve uuids from server, ignoring: {}", e.getMessage());
+ registeredUsers = new HashMap<>();
+ }
+
+ for (SignalServiceAddress address : missingUuids) {
+ final String number = address.getNumber().get();
+ if (registeredUsers.containsKey(number)) {
+ final SignalServiceAddress newAddress = resolveSignalServiceAddress(new SignalServiceAddress(
+ registeredUsers.get(number),
+ number));
+ signalServiceAddresses.add(newAddress);