Search in sources :

Example 1 with KeyBackupServicePinException

use of org.whispersystems.signalservice.api.KeyBackupServicePinException 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)

Aggregations

NonNull (androidx.annotation.NonNull)1 IOException (java.io.IOException)1 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)1 KbsPinData (org.whispersystems.signalservice.api.KbsPinData)1 KeyBackupService (org.whispersystems.signalservice.api.KeyBackupService)1 KeyBackupServicePinException (org.whispersystems.signalservice.api.KeyBackupServicePinException)1 HashedPin (org.whispersystems.signalservice.api.kbs.HashedPin)1 UnauthenticatedResponseException (org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException)1