Search in sources :

Example 16 with HashedPin

use of org.whispersystems.signalservice.api.kbs.HashedPin in project Signal-Android by WhisperSystems.

the class PinState method setPinOnEnclave.

@WorkerThread
@NonNull
private static KbsPinData setPinOnEnclave(@NonNull KbsEnclave enclave, @NonNull String pin, @NonNull MasterKey masterKey) throws IOException, UnauthenticatedResponseException {
    Log.i(TAG, "Setting PIN on enclave: " + enclave.getEnclaveName());
    KeyBackupService kbs = ApplicationDependencies.getKeyBackupService(enclave);
    KeyBackupService.PinChangeSession pinChangeSession = kbs.newPinChangeSession();
    HashedPin hashedPin = PinHashing.hashPin(pin, pinChangeSession);
    KbsPinData newData = pinChangeSession.setPin(hashedPin, masterKey);
    SignalStore.kbsValues().setKbsMasterKey(newData, pin);
    return newData;
}
Also used : KeyBackupService(org.whispersystems.signalservice.api.KeyBackupService) KbsPinData(org.whispersystems.signalservice.api.KbsPinData) HashedPin(org.whispersystems.signalservice.api.kbs.HashedPin) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 17 with HashedPin

use of org.whispersystems.signalservice.api.kbs.HashedPin in project Signal-Android by WhisperSystems.

the class HashedPinKbsDataTest method vectors_createNewKbsData.

@Test
public void vectors_createNewKbsData() throws IOException {
    for (KbsTestVector vector : getKbsTestVectorList()) {
        HashedPin hashedPin = HashedPin.fromArgon2Hash(vector.getArgon2Hash());
        KbsData kbsData = hashedPin.createNewKbsData(MasterKey.createNew(mockRandom(vector.getMasterKey())));
        assertArrayEquals(vector.getMasterKey(), kbsData.getMasterKey().serialize());
        assertArrayEquals(vector.getIvAndCipher(), kbsData.getCipherText());
        assertArrayEquals(vector.getKbsAccessKey(), kbsData.getKbsAccessKey());
        assertEquals(vector.getRegistrationLock(), kbsData.getMasterKey().deriveRegistrationLock());
    }
}
Also used : KbsTestVector(org.thoughtcrime.securesms.registration.v2.testdata.KbsTestVector) KbsData(org.whispersystems.signalservice.api.kbs.KbsData) HashedPin(org.whispersystems.signalservice.api.kbs.HashedPin) Test(org.junit.Test)

Example 18 with HashedPin

use of org.whispersystems.signalservice.api.kbs.HashedPin in project Signal-Android by signalapp.

the class PinHashing_hashPin_Test method argon2_hashed_pin_another_password.

@Test
public void argon2_hashed_pin_another_password() throws IOException {
    String pin = "anotherpassword";
    byte[] backupId = Hex.fromStringCondensed("202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f");
    MasterKey masterKey = new MasterKey(Hex.fromStringCondensed("88a787415a2ecd79da0d1016a82a27c5c695c9a19b88b0aa1d35683280aa9a67"));
    HashedPin hashedPin = PinHashing.hashPin(pin, () -> backupId);
    KbsData kbsData = hashedPin.createNewKbsData(masterKey);
    assertArrayEquals(hashedPin.getKbsAccessKey(), kbsData.getKbsAccessKey());
    assertArrayEquals(Hex.fromStringCondensed("301d9dd1e96f20ce51083f67d3298fd37b97525de8324d5e12ed2d407d3d927b"), kbsData.getKbsAccessKey());
    assertArrayEquals(Hex.fromStringCondensed("9d9b05402ea39c17ff1c9298c8a0e86784a352aa02a74943bf8bcf07ec0f4b574a5b786ad0182c8d308d9eb06538b8c9"), kbsData.getCipherText());
    assertEquals(masterKey, kbsData.getMasterKey());
    String localPinHash = PinHashing.localPinHash(pin);
    assertTrue(PinHashing.verifyLocalPinHash(localPinHash, pin));
}
Also used : KbsData(org.whispersystems.signalservice.api.kbs.KbsData) MasterKey(org.whispersystems.signalservice.api.kbs.MasterKey) HashedPin(org.whispersystems.signalservice.api.kbs.HashedPin) Test(org.junit.Test)

Example 19 with HashedPin

use of org.whispersystems.signalservice.api.kbs.HashedPin 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 20 with HashedPin

use of org.whispersystems.signalservice.api.kbs.HashedPin 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

HashedPin (org.whispersystems.signalservice.api.kbs.HashedPin)20 Test (org.junit.Test)12 KbsData (org.whispersystems.signalservice.api.kbs.KbsData)12 MasterKey (org.whispersystems.signalservice.api.kbs.MasterKey)12 KbsPinData (org.whispersystems.signalservice.api.KbsPinData)8 KeyBackupService (org.whispersystems.signalservice.api.KeyBackupService)8 WorkerThread (androidx.annotation.WorkerThread)6 NonNull (androidx.annotation.NonNull)4 KbsEnclave (org.thoughtcrime.securesms.KbsEnclave)4 KbsValues (org.thoughtcrime.securesms.keyvalue.KbsValues)4 KbsTestVector (org.thoughtcrime.securesms.registration.v2.testdata.KbsTestVector)4 IOException (java.io.IOException)2 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)2 KeyBackupServicePinException (org.whispersystems.signalservice.api.KeyBackupServicePinException)2 UnauthenticatedResponseException (org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException)2