Search in sources :

Example 1 with KbsEnclave

use of org.thoughtcrime.securesms.KbsEnclave in project Signal-Android by WhisperSystems.

the class PinState method onPinChangedOrCreated.

/**
 * Invoked whenever the Signal PIN is changed or created.
 */
@WorkerThread
public static synchronized void onPinChangedOrCreated(@NonNull Context context, @NonNull String pin, @NonNull PinKeyboardType keyboard) throws IOException, UnauthenticatedResponseException, InvalidKeyException {
    Log.i(TAG, "onPinChangedOrCreated()");
    KbsEnclave kbsEnclave = KbsEnclaves.current();
    KbsValues kbsValues = SignalStore.kbsValues();
    boolean isFirstPin = !kbsValues.hasPin() || kbsValues.hasOptedOut();
    MasterKey masterKey = kbsValues.getOrCreateMasterKey();
    KeyBackupService keyBackupService = ApplicationDependencies.getKeyBackupService(kbsEnclave);
    KeyBackupService.PinChangeSession pinChangeSession = keyBackupService.newPinChangeSession();
    HashedPin hashedPin = PinHashing.hashPin(pin, pinChangeSession);
    KbsPinData kbsData = pinChangeSession.setPin(hashedPin, masterKey);
    kbsValues.setKbsMasterKey(kbsData, pin);
    TextSecurePreferences.clearRegistrationLockV1(context);
    SignalStore.pinValues().setKeyboardType(keyboard);
    SignalStore.pinValues().resetPinReminders();
    ApplicationDependencies.getMegaphoneRepository().markFinished(Megaphones.Event.PINS_FOR_ALL);
    if (isFirstPin) {
        Log.i(TAG, "First time setting a PIN. Refreshing attributes to set the 'storage' capability. Enclave: " + kbsEnclave.getEnclaveName());
        bestEffortRefreshAttributes();
    } else {
        Log.i(TAG, "Not the first time setting a PIN. Enclave: " + kbsEnclave.getEnclaveName());
    }
    updateState(buildInferredStateFromOtherFields());
}
Also used : KbsEnclave(org.thoughtcrime.securesms.KbsEnclave) KeyBackupService(org.whispersystems.signalservice.api.KeyBackupService) MasterKey(org.whispersystems.signalservice.api.kbs.MasterKey) KbsValues(org.thoughtcrime.securesms.keyvalue.KbsValues) KbsPinData(org.whispersystems.signalservice.api.KbsPinData) HashedPin(org.whispersystems.signalservice.api.kbs.HashedPin) WorkerThread(androidx.annotation.WorkerThread)

Example 2 with KbsEnclave

use of org.thoughtcrime.securesms.KbsEnclave in project Signal-Android by WhisperSystems.

the class KbsRepository method getTokenSync.

@NonNull
private TokenData getTokenSync(@Nullable String authorization) throws IOException {
    TokenData firstKnownTokenData = null;
    for (KbsEnclave enclave : KbsEnclaves.all()) {
        KeyBackupService kbs = ApplicationDependencies.getKeyBackupService(enclave);
        authorization = authorization == null ? kbs.getAuthorization() : authorization;
        TokenResponse token = kbs.getToken(authorization);
        TokenData tokenData = new TokenData(enclave, authorization, token);
        if (tokenData.getTriesRemaining() > 0) {
            Log.i(TAG, "Found data! " + enclave.getEnclaveName());
            return tokenData;
        } else if (firstKnownTokenData == null) {
            Log.i(TAG, "No data, but storing as the first response. " + enclave.getEnclaveName());
            firstKnownTokenData = tokenData;
        } else {
            Log.i(TAG, "No data, and we already have a 'first response'. " + enclave.getEnclaveName());
        }
    }
    return Objects.requireNonNull(firstKnownTokenData);
}
Also used : KbsEnclave(org.thoughtcrime.securesms.KbsEnclave) TokenResponse(org.whispersystems.signalservice.internal.contacts.entities.TokenResponse) KeyBackupService(org.whispersystems.signalservice.api.KeyBackupService) NonNull(androidx.annotation.NonNull)

Example 3 with KbsEnclave

use of org.thoughtcrime.securesms.KbsEnclave in project Signal-Android by WhisperSystems.

the class PinState method onMigrateToRegistrationLockV2.

/**
 * Should only be called by {@link org.thoughtcrime.securesms.migrations.RegistrationPinV2MigrationJob}.
 */
@WorkerThread
public static synchronized void onMigrateToRegistrationLockV2(@NonNull Context context, @NonNull String pin) throws IOException, UnauthenticatedResponseException, InvalidKeyException {
    Log.i(TAG, "onMigrateToRegistrationLockV2()");
    KbsEnclave kbsEnclave = KbsEnclaves.current();
    Log.i(TAG, "Enclave: " + kbsEnclave.getEnclaveName());
    KbsValues kbsValues = SignalStore.kbsValues();
    MasterKey masterKey = kbsValues.getOrCreateMasterKey();
    KeyBackupService keyBackupService = ApplicationDependencies.getKeyBackupService(kbsEnclave);
    KeyBackupService.PinChangeSession pinChangeSession = keyBackupService.newPinChangeSession();
    HashedPin hashedPin = PinHashing.hashPin(pin, pinChangeSession);
    KbsPinData kbsData = pinChangeSession.setPin(hashedPin, masterKey);
    pinChangeSession.enableRegistrationLock(masterKey);
    kbsValues.setKbsMasterKey(kbsData, pin);
    TextSecurePreferences.clearRegistrationLockV1(context);
    updateState(buildInferredStateFromOtherFields());
}
Also used : KbsEnclave(org.thoughtcrime.securesms.KbsEnclave) KeyBackupService(org.whispersystems.signalservice.api.KeyBackupService) MasterKey(org.whispersystems.signalservice.api.kbs.MasterKey) KbsValues(org.thoughtcrime.securesms.keyvalue.KbsValues) KbsPinData(org.whispersystems.signalservice.api.KbsPinData) HashedPin(org.whispersystems.signalservice.api.kbs.HashedPin) WorkerThread(androidx.annotation.WorkerThread)

Example 4 with KbsEnclave

use of org.thoughtcrime.securesms.KbsEnclave in project Signal-Android by WhisperSystems.

the class PinState method onEnableRegistrationLockForUserWithPin.

/**
 * Invoked whenever a Signal PIN user enables registration lock.
 */
@WorkerThread
public static synchronized void onEnableRegistrationLockForUserWithPin() throws IOException {
    Log.i(TAG, "onEnableRegistrationLockForUserWithPin()");
    if (getState() == State.PIN_WITH_REGISTRATION_LOCK_ENABLED) {
        Log.i(TAG, "Registration lock already enabled. Skipping.");
        return;
    }
    assertState(State.PIN_WITH_REGISTRATION_LOCK_DISABLED);
    KbsEnclave kbsEnclave = KbsEnclaves.current();
    Log.i(TAG, "Enclave: " + kbsEnclave.getEnclaveName());
    SignalStore.kbsValues().setV2RegistrationLockEnabled(false);
    ApplicationDependencies.getKeyBackupService(kbsEnclave).newPinChangeSession(SignalStore.kbsValues().getRegistrationLockTokenResponse()).enableRegistrationLock(SignalStore.kbsValues().getOrCreateMasterKey());
    SignalStore.kbsValues().setV2RegistrationLockEnabled(true);
    updateState(State.PIN_WITH_REGISTRATION_LOCK_ENABLED);
}
Also used : KbsEnclave(org.thoughtcrime.securesms.KbsEnclave) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

KbsEnclave (org.thoughtcrime.securesms.KbsEnclave)4 WorkerThread (androidx.annotation.WorkerThread)3 KeyBackupService (org.whispersystems.signalservice.api.KeyBackupService)3 KbsValues (org.thoughtcrime.securesms.keyvalue.KbsValues)2 KbsPinData (org.whispersystems.signalservice.api.KbsPinData)2 HashedPin (org.whispersystems.signalservice.api.kbs.HashedPin)2 MasterKey (org.whispersystems.signalservice.api.kbs.MasterKey)2 NonNull (androidx.annotation.NonNull)1 TokenResponse (org.whispersystems.signalservice.internal.contacts.entities.TokenResponse)1