Search in sources :

Example 1 with UnauthenticatedResponseException

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

the class KbsRepository method restoreMasterKeyFromEnclave.

@NonNull
private static KbsPinData restoreMasterKeyFromEnclave(@NonNull KbsEnclave enclave, @NonNull String pin, @NonNull String basicStorageCredentials, @NonNull TokenResponse tokenResponse) throws IOException, KeyBackupSystemWrongPinException, KeyBackupSystemNoDataException {
    KeyBackupService keyBackupService = ApplicationDependencies.getKeyBackupService(enclave);
    KeyBackupService.RestoreSession session = keyBackupService.newRegistrationSession(basicStorageCredentials, tokenResponse);
    try {
        Log.i(TAG, "Restoring pin from KBS");
        HashedPin hashedPin = PinHashing.hashPin(pin, session);
        KbsPinData kbsData = session.restorePin(hashedPin);
        if (kbsData != null) {
            Log.i(TAG, "Found registration lock token on KBS.");
        } else {
            throw new AssertionError("Null not expected");
        }
        return kbsData;
    } catch (UnauthenticatedResponseException | InvalidKeyException e) {
        Log.w(TAG, "Failed to restore key", e);
        throw new IOException(e);
    } catch (KeyBackupServicePinException e) {
        Log.w(TAG, "Incorrect pin", e);
        throw new KeyBackupSystemWrongPinException(e.getToken());
    }
}
Also used : KeyBackupService(org.whispersystems.signalservice.api.KeyBackupService) UnauthenticatedResponseException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException) KeyBackupServicePinException(org.whispersystems.signalservice.api.KeyBackupServicePinException) KbsPinData(org.whispersystems.signalservice.api.KbsPinData) HashedPin(org.whispersystems.signalservice.api.kbs.HashedPin) IOException(java.io.IOException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) NonNull(androidx.annotation.NonNull)

Example 2 with UnauthenticatedResponseException

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

the class ConfirmKbsPinRepository method setPin.

void setPin(@NonNull KbsPin kbsPin, @NonNull PinKeyboardType keyboard, @NonNull Consumer<PinSetResult> resultConsumer) {
    Context context = ApplicationDependencies.getApplication();
    String pinValue = kbsPin.toString();
    SimpleTask.run(() -> {
        try {
            Log.i(TAG, "Setting pin on KBS");
            PinState.onPinChangedOrCreated(context, pinValue, keyboard);
            Log.i(TAG, "Pin set on KBS");
            return PinSetResult.SUCCESS;
        } catch (IOException | UnauthenticatedResponseException | InvalidKeyException e) {
            Log.w(TAG, e);
            PinState.onPinCreateFailure();
            return PinSetResult.FAILURE;
        }
    }, resultConsumer::accept);
}
Also used : Context(android.content.Context) UnauthenticatedResponseException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException) IOException(java.io.IOException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException)

Example 3 with UnauthenticatedResponseException

use of org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException 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)

Example 4 with UnauthenticatedResponseException

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

the class SignalServiceAccountManager method getRegisteredUsers.

@SuppressWarnings("SameParameterValue")
public Map<String, ACI> getRegisteredUsers(KeyStore iasKeyStore, Set<String> e164numbers, String mrenclave) throws IOException, Quote.InvalidQuoteFormatException, UnauthenticatedQuoteException, SignatureException, UnauthenticatedResponseException, InvalidKeyException {
    if (e164numbers.isEmpty()) {
        return Collections.emptyMap();
    }
    try {
        String authorization = this.pushServiceSocket.getContactDiscoveryAuthorization();
        Map<String, RemoteAttestation> attestations = RemoteAttestationUtil.getAndVerifyMultiRemoteAttestation(pushServiceSocket, PushServiceSocket.ClientSet.ContactDiscovery, iasKeyStore, mrenclave, mrenclave, authorization);
        List<String> addressBook = new ArrayList<>(e164numbers.size());
        for (String e164number : e164numbers) {
            addressBook.add(e164number.substring(1));
        }
        List<String> cookies = attestations.values().iterator().next().getCookies();
        DiscoveryRequest request = ContactDiscoveryCipher.createDiscoveryRequest(addressBook, attestations);
        DiscoveryResponse response = this.pushServiceSocket.getContactDiscoveryRegisteredUsers(authorization, request, cookies, mrenclave);
        byte[] data = ContactDiscoveryCipher.getDiscoveryResponseData(response, attestations.values());
        HashMap<String, ACI> results = new HashMap<>(addressBook.size());
        DataInputStream uuidInputStream = new DataInputStream(new ByteArrayInputStream(data));
        for (String candidate : addressBook) {
            long candidateUuidHigh = uuidInputStream.readLong();
            long candidateUuidLow = uuidInputStream.readLong();
            if (candidateUuidHigh != 0 || candidateUuidLow != 0) {
                results.put('+' + candidate, ACI.from(new UUID(candidateUuidHigh, candidateUuidLow)));
            }
        }
        return results;
    } catch (InvalidCiphertextException e) {
        throw new UnauthenticatedResponseException(e);
    }
}
Also used : DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) HashMap(java.util.HashMap) ACI(org.whispersystems.signalservice.api.push.ACI) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) DataInputStream(java.io.DataInputStream) RemoteAttestation(org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation) ByteArrayInputStream(java.io.ByteArrayInputStream) UnauthenticatedResponseException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException) DiscoveryRequest(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest) UUID(java.util.UUID)

Aggregations

UnauthenticatedResponseException (org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException)4 IOException (java.io.IOException)3 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)3 ACI (org.whispersystems.signalservice.api.push.ACI)2 Context (android.content.Context)1 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 ByteString (com.google.protobuf.ByteString)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 KeyStore (java.security.KeyStore)1 SignatureException (java.security.SignatureException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 DirectoryResult (org.thoughtcrime.securesms.contacts.sync.DirectoryHelper.DirectoryResult)1 KbsPinData (org.whispersystems.signalservice.api.KbsPinData)1 KeyBackupService (org.whispersystems.signalservice.api.KeyBackupService)1 KeyBackupServicePinException (org.whispersystems.signalservice.api.KeyBackupServicePinException)1