Search in sources :

Example 6 with KbsValues

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

the class RefreshAttributesJob method onRun.

@Override
public void onRun() throws IOException {
    if (!SignalStore.account().isRegistered() || SignalStore.account().getE164() == null) {
        Log.w(TAG, "Not yet registered. Skipping.");
        return;
    }
    if (!forced && hasRefreshedThisAppCycle) {
        Log.d(TAG, "Already refreshed this app cycle. Skipping.");
        return;
    }
    int registrationId = SignalStore.account().getRegistrationId();
    boolean fetchesMessages = !SignalStore.account().isFcmEnabled();
    byte[] unidentifiedAccessKey = UnidentifiedAccess.deriveAccessKeyFrom(ProfileKeyUtil.getSelfProfileKey());
    boolean universalUnidentifiedAccess = TextSecurePreferences.isUniversalUnidentifiedAccess(context);
    String registrationLockV1 = null;
    String registrationLockV2 = null;
    KbsValues kbsValues = SignalStore.kbsValues();
    if (kbsValues.isV2RegistrationLockEnabled()) {
        registrationLockV2 = kbsValues.getRegistrationLockToken();
    } else if (TextSecurePreferences.isV1RegistrationLockEnabled(context)) {
        // noinspection deprecation Ok to read here as they have not migrated
        registrationLockV1 = TextSecurePreferences.getDeprecatedV1RegistrationLockPin(context);
    }
    boolean phoneNumberDiscoverable = SignalStore.phoneNumberPrivacy().getPhoneNumberListingMode().isDiscoverable();
    String deviceName = SignalStore.account().getDeviceName();
    byte[] encryptedDeviceName = (deviceName == null) ? null : DeviceNameCipher.encryptDeviceName(deviceName.getBytes(StandardCharsets.UTF_8), SignalStore.account().getAciIdentityKey());
    AccountAttributes.Capabilities capabilities = AppCapabilities.getCapabilities(kbsValues.hasPin() && !kbsValues.hasOptedOut());
    Log.i(TAG, "Calling setAccountAttributes() reglockV1? " + !TextUtils.isEmpty(registrationLockV1) + ", reglockV2? " + !TextUtils.isEmpty(registrationLockV2) + ", pin? " + kbsValues.hasPin() + "\n    Phone number discoverable : " + phoneNumberDiscoverable + "\n    Device Name : " + (encryptedDeviceName != null) + "\n  Capabilities:" + "\n    Storage? " + capabilities.isStorage() + "\n    GV2? " + capabilities.isGv2() + "\n    GV1 Migration? " + capabilities.isGv1Migration() + "\n    Sender Key? " + capabilities.isSenderKey() + "\n    Announcement Groups? " + capabilities.isAnnouncementGroup() + "\n    Change Number? " + capabilities.isChangeNumber() + "\n    UUID? " + capabilities.isUuid());
    SignalServiceAccountManager signalAccountManager = ApplicationDependencies.getSignalServiceAccountManager();
    signalAccountManager.setAccountAttributes(null, registrationId, fetchesMessages, registrationLockV1, registrationLockV2, unidentifiedAccessKey, universalUnidentifiedAccess, capabilities, phoneNumberDiscoverable, encryptedDeviceName);
    ApplicationDependencies.getJobManager().add(new RefreshOwnProfileJob());
    hasRefreshedThisAppCycle = true;
}
Also used : AccountAttributes(org.whispersystems.signalservice.api.account.AccountAttributes) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) KbsValues(org.thoughtcrime.securesms.keyvalue.KbsValues) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)

Example 7 with KbsValues

use of org.thoughtcrime.securesms.keyvalue.KbsValues in project Signal-Android by signalapp.

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 8 with KbsValues

use of org.thoughtcrime.securesms.keyvalue.KbsValues in project Signal-Android by signalapp.

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)

Aggregations

KbsValues (org.thoughtcrime.securesms.keyvalue.KbsValues)8 WorkerThread (androidx.annotation.WorkerThread)4 KbsEnclave (org.thoughtcrime.securesms.KbsEnclave)4 KbsPinData (org.whispersystems.signalservice.api.KbsPinData)4 KeyBackupService (org.whispersystems.signalservice.api.KeyBackupService)4 HashedPin (org.whispersystems.signalservice.api.kbs.HashedPin)4 MasterKey (org.whispersystems.signalservice.api.kbs.MasterKey)4 Context (android.content.Context)2 NonNull (androidx.annotation.NonNull)2 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)2 SignalServiceAccountManager (org.whispersystems.signalservice.api.SignalServiceAccountManager)2 AccountAttributes (org.whispersystems.signalservice.api.account.AccountAttributes)2