Search in sources :

Example 1 with UnauthenticatedQuoteException

use of org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedQuoteException in project Signal-Android by signalapp.

the class ContactDiscoveryV2 method getDirectoryResult.

@WorkerThread
static DirectoryResult getDirectoryResult(@NonNull Context context, @NonNull Set<String> databaseNumbers, @NonNull Set<String> systemNumbers) throws IOException {
    Set<String> allNumbers = SetUtil.union(databaseNumbers, systemNumbers);
    FuzzyPhoneNumberHelper.InputResult inputResult = FuzzyPhoneNumberHelper.generateInput(allNumbers, databaseNumbers);
    Set<String> sanitizedNumbers = sanitizeNumbers(inputResult.getNumbers());
    Set<String> ignoredNumbers = new HashSet<>();
    if (sanitizedNumbers.size() > MAX_NUMBERS) {
        Set<String> randomlySelected = randomlySelect(sanitizedNumbers, MAX_NUMBERS);
        ignoredNumbers = SetUtil.difference(sanitizedNumbers, randomlySelected);
        sanitizedNumbers = randomlySelected;
    }
    SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
    KeyStore iasKeyStore = getIasKeyStore(context);
    try {
        Map<String, ACI> results = accountManager.getRegisteredUsers(iasKeyStore, sanitizedNumbers, BuildConfig.CDS_MRENCLAVE);
        FuzzyPhoneNumberHelper.OutputResult outputResult = FuzzyPhoneNumberHelper.generateOutput(results, inputResult);
        return new DirectoryResult(outputResult.getNumbers(), outputResult.getRewrites(), ignoredNumbers);
    } catch (SignatureException | UnauthenticatedQuoteException | UnauthenticatedResponseException | Quote.InvalidQuoteFormatException | InvalidKeyException e) {
        Log.w(TAG, "Attestation error.", e);
        throw new IOException(e);
    }
}
Also used : SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) ACI(org.whispersystems.signalservice.api.push.ACI) SignatureException(java.security.SignatureException) IOException(java.io.IOException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) KeyStore(java.security.KeyStore) DirectoryResult(org.thoughtcrime.securesms.contacts.sync.DirectoryHelper.DirectoryResult) UnauthenticatedResponseException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException) HashSet(java.util.HashSet) UnauthenticatedQuoteException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedQuoteException) WorkerThread(androidx.annotation.WorkerThread)

Example 2 with UnauthenticatedQuoteException

use of org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedQuoteException in project Signal-Android by WhisperSystems.

the class ContactDiscoveryV2 method getDirectoryResult.

@WorkerThread
static DirectoryResult getDirectoryResult(@NonNull Context context, @NonNull Set<String> databaseNumbers, @NonNull Set<String> systemNumbers) throws IOException {
    Set<String> allNumbers = SetUtil.union(databaseNumbers, systemNumbers);
    FuzzyPhoneNumberHelper.InputResult inputResult = FuzzyPhoneNumberHelper.generateInput(allNumbers, databaseNumbers);
    Set<String> sanitizedNumbers = sanitizeNumbers(inputResult.getNumbers());
    Set<String> ignoredNumbers = new HashSet<>();
    if (sanitizedNumbers.size() > MAX_NUMBERS) {
        Set<String> randomlySelected = randomlySelect(sanitizedNumbers, MAX_NUMBERS);
        ignoredNumbers = SetUtil.difference(sanitizedNumbers, randomlySelected);
        sanitizedNumbers = randomlySelected;
    }
    SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
    KeyStore iasKeyStore = getIasKeyStore(context);
    try {
        Map<String, ACI> results = accountManager.getRegisteredUsers(iasKeyStore, sanitizedNumbers, BuildConfig.CDS_MRENCLAVE);
        FuzzyPhoneNumberHelper.OutputResult outputResult = FuzzyPhoneNumberHelper.generateOutput(results, inputResult);
        return new DirectoryResult(outputResult.getNumbers(), outputResult.getRewrites(), ignoredNumbers);
    } catch (SignatureException | UnauthenticatedQuoteException | UnauthenticatedResponseException | Quote.InvalidQuoteFormatException | InvalidKeyException e) {
        Log.w(TAG, "Attestation error.", e);
        throw new IOException(e);
    }
}
Also used : SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) ACI(org.whispersystems.signalservice.api.push.ACI) SignatureException(java.security.SignatureException) IOException(java.io.IOException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) KeyStore(java.security.KeyStore) DirectoryResult(org.thoughtcrime.securesms.contacts.sync.DirectoryHelper.DirectoryResult) UnauthenticatedResponseException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException) HashSet(java.util.HashSet) UnauthenticatedQuoteException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedQuoteException) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)2 IOException (java.io.IOException)2 KeyStore (java.security.KeyStore)2 SignatureException (java.security.SignatureException)2 HashSet (java.util.HashSet)2 DirectoryResult (org.thoughtcrime.securesms.contacts.sync.DirectoryHelper.DirectoryResult)2 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)2 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)2 ACI (org.whispersystems.signalservice.api.push.ACI)2 UnauthenticatedQuoteException (org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedQuoteException)2 UnauthenticatedResponseException (org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException)2