From c274c1bb289922facdf51915b416ada977253b9a Mon Sep 17 00:00:00 2001 From: Jeffrey Griffin Date: Thu, 18 Apr 2019 13:01:53 -0700 Subject: [PATCH] Eliminate noisy directory feedback We observed IOExceptions loading the Contact Discovery IAS KeyStore. We will now throw an AssertionError upon any error creating the IAS KeyStore, matching the behaviour for creation of the TrustStore used for the main Signal Service. NB: If this assertion is hit, the user will not even be able to refresh their contacts with the old directory service. --- .../securesms/util/DirectoryHelper.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java index 9d7b6c1263..558a8ec65d 100644 --- a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java +++ b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java @@ -42,6 +42,7 @@ import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.signalservice.api.SignalServiceAccountManager; import org.whispersystems.signalservice.api.push.ContactTokenDetails; import org.whispersystems.signalservice.api.push.TrustStore; +import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException; import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException; import org.whispersystems.signalservice.internal.contacts.crypto.Quote; import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedQuoteException; @@ -364,10 +365,11 @@ public class DirectoryHelper { Set sanitizedNumbers = sanitizeNumbers(eligibleContactNumbers); List> batches = splitIntoBatches(sanitizedNumbers, CONTACT_DISCOVERY_BATCH_SIZE); List>> futures = new ArrayList<>(batches.size()); + KeyStore iasKeyStore = getIasKeyStore(context); for (Set batch : batches) { Future> future = SignalExecutors.IO.submit(() -> { - return new HashSet<>(accountManager.getRegisteredUsers(getIasKeyStore(context), batch, BuildConfig.MRENCLAVE)); + return new HashSet<>(accountManager.getRegisteredUsers(iasKeyStore, batch, BuildConfig.MRENCLAVE)); }); futures.add(future); } @@ -414,6 +416,9 @@ public class DirectoryHelper { } else if (e.getCause() instanceof PushNetworkException) { Log.w(TAG, "Failed due to poor network.", e); return Optional.absent(); + } else if (e.getCause() instanceof NonSuccessfulResponseCodeException) { + Log.w(TAG, "Failed due to non successful response code.", e); + return Optional.absent(); } else { Log.w(TAG, "Failed for an unknown reason.", e); accountManager.reportContactDiscoveryServiceUnexpectedError(buildErrorReason(e.getCause())); @@ -432,15 +437,17 @@ public class DirectoryHelper { e instanceof Quote.InvalidQuoteFormatException; } - private static KeyStore getIasKeyStore(@NonNull Context context) - throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException - { - TrustStore contactTrustStore = new IasTrustStore(context); + private static KeyStore getIasKeyStore(@NonNull Context context) { + try { + TrustStore contactTrustStore = new IasTrustStore(context); - KeyStore keyStore = KeyStore.getInstance("BKS"); - keyStore.load(contactTrustStore.getKeyStoreInputStream(), contactTrustStore.getKeyStorePassword().toCharArray()); + KeyStore keyStore = KeyStore.getInstance("BKS"); + keyStore.load(contactTrustStore.getKeyStoreInputStream(), contactTrustStore.getKeyStorePassword().toCharArray()); - return keyStore; + return keyStore; + } catch (KeyStoreException | CertificateException | IOException | NoSuchAlgorithmException e) { + throw new AssertionError(e); + } } private static String buildErrorReason(@Nullable Throwable t) {