mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 10:20:25 +01:00
Start mirroring to SVR2.
This commit is contained in:
committed by
Clark Chen
parent
dfb7304626
commit
e1570e9512
@@ -245,8 +245,8 @@ internal class PaymentsValues internal constructor(store: KeyValueStore) : Signa
|
||||
|
||||
fun showUpdatePinInfoCard(): Boolean {
|
||||
return if (userHasLargeBalance() &&
|
||||
SignalStore.kbsValues().hasPin() &&
|
||||
!SignalStore.kbsValues().hasOptedOut() && SignalStore.pinValues().keyboardType == PinKeyboardType.NUMERIC
|
||||
SignalStore.svr().hasPin() &&
|
||||
!SignalStore.svr().hasOptedOut() && SignalStore.pinValues().keyboardType == PinKeyboardType.NUMERIC
|
||||
) {
|
||||
store.getBoolean(SHOW_CASHING_OUT_INFO_CARD, true)
|
||||
} else {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
@@ -11,13 +8,11 @@ import org.thoughtcrime.securesms.lock.SignalPinReminders;
|
||||
import org.thoughtcrime.securesms.lock.v2.PinKeyboardType;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Specifically handles just the UI/UX state around PINs. For actual keys, see {@link KbsValues}.
|
||||
* Specifically handles just the UI/UX state around PINs. For actual keys, see {@link SvrValues}.
|
||||
*/
|
||||
public final class PinValues extends SignalStoreValues {
|
||||
|
||||
@@ -50,7 +45,7 @@ public final class PinValues extends SignalStoreValues {
|
||||
.putLong(NEXT_INTERVAL, nextInterval)
|
||||
.apply();
|
||||
|
||||
SignalStore.kbsValues().setPinIfNotPresent(pin);
|
||||
SignalStore.svr().setPinIfNotPresent(pin);
|
||||
}
|
||||
|
||||
public void onEntrySuccessWithWrongGuess(@NonNull String pin) {
|
||||
@@ -62,7 +57,7 @@ public final class PinValues extends SignalStoreValues {
|
||||
.putLong(NEXT_INTERVAL, nextInterval)
|
||||
.apply();
|
||||
|
||||
SignalStore.kbsValues().setPinIfNotPresent(pin);
|
||||
SignalStore.svr().setPinIfNotPresent(pin);
|
||||
}
|
||||
|
||||
public void onEntrySkipWithWrongGuess() {
|
||||
|
||||
@@ -19,7 +19,7 @@ public final class SignalStore {
|
||||
private KeyValueStore store;
|
||||
|
||||
private final AccountValues accountValues;
|
||||
private final KbsValues kbsValues;
|
||||
private final SvrValues svrValues;
|
||||
private final RegistrationValues registrationValues;
|
||||
private final PinValues pinValues;
|
||||
private final RemoteConfigValues remoteConfigValues;
|
||||
@@ -63,7 +63,7 @@ public final class SignalStore {
|
||||
private SignalStore(@NonNull KeyValueStore store) {
|
||||
this.store = store;
|
||||
this.accountValues = new AccountValues(store);
|
||||
this.kbsValues = new KbsValues(store);
|
||||
this.svrValues = new SvrValues(store);
|
||||
this.registrationValues = new RegistrationValues(store);
|
||||
this.pinValues = new PinValues(store);
|
||||
this.remoteConfigValues = new RemoteConfigValues(store);
|
||||
@@ -92,7 +92,7 @@ public final class SignalStore {
|
||||
|
||||
public static void onFirstEverAppLaunch() {
|
||||
account().onFirstEverAppLaunch();
|
||||
kbsValues().onFirstEverAppLaunch();
|
||||
svr().onFirstEverAppLaunch();
|
||||
registrationValues().onFirstEverAppLaunch();
|
||||
pinValues().onFirstEverAppLaunch();
|
||||
remoteConfigValues().onFirstEverAppLaunch();
|
||||
@@ -121,7 +121,7 @@ public final class SignalStore {
|
||||
public static List<String> getKeysToIncludeInBackup() {
|
||||
List<String> keys = new ArrayList<>();
|
||||
keys.addAll(account().getKeysToIncludeInBackup());
|
||||
keys.addAll(kbsValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(svr().getKeysToIncludeInBackup());
|
||||
keys.addAll(registrationValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(pinValues().getKeysToIncludeInBackup());
|
||||
keys.addAll(remoteConfigValues().getKeysToIncludeInBackup());
|
||||
@@ -168,8 +168,8 @@ public final class SignalStore {
|
||||
return getInstance().accountValues;
|
||||
}
|
||||
|
||||
public static @NonNull KbsValues kbsValues() {
|
||||
return getInstance().kbsValues;
|
||||
public static @NonNull SvrValues svr() {
|
||||
return getInstance().svrValues;
|
||||
}
|
||||
|
||||
public static @NonNull RegistrationValues registrationValues() {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class StorageServiceValues extends SignalStoreValues {
|
||||
if (getStore().containsKey(SYNC_STORAGE_KEY)) {
|
||||
return new StorageKey(getBlob(SYNC_STORAGE_KEY, null));
|
||||
}
|
||||
return SignalStore.kbsValues().getOrCreateMasterKey().deriveStorageServiceKey();
|
||||
return SignalStore.svr().getOrCreateMasterKey().deriveStorageServiceKey();
|
||||
}
|
||||
|
||||
public long getLastSyncTime() {
|
||||
|
||||
@@ -5,7 +5,6 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.core.util.StringStringSerializer;
|
||||
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||
import org.whispersystems.signalservice.api.KbsPinData;
|
||||
import org.whispersystems.signalservice.api.kbs.MasterKey;
|
||||
import org.whispersystems.signalservice.api.kbs.PinHashUtil;
|
||||
import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse;
|
||||
@@ -13,14 +12,13 @@ import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class KbsValues extends SignalStoreValues {
|
||||
public final class SvrValues extends SignalStoreValues {
|
||||
|
||||
public static final String V2_LOCK_ENABLED = "kbs.v2_lock_enabled";
|
||||
public static final String REGISTRATION_LOCK_ENABLED = "kbs.v2_lock_enabled";
|
||||
private static final String MASTER_KEY = "kbs.registration_lock_master_key";
|
||||
private static final String TOKEN_RESPONSE = "kbs.token_response";
|
||||
private static final String PIN = "kbs.pin";
|
||||
@@ -28,10 +26,10 @@ public final class KbsValues extends SignalStoreValues {
|
||||
private static final String LAST_CREATE_FAILED_TIMESTAMP = "kbs.last_create_failed_timestamp";
|
||||
public static final String OPTED_OUT = "kbs.opted_out";
|
||||
private static final String PIN_FORGOTTEN_OR_SKIPPED = "kbs.pin.forgotten.or.skipped";
|
||||
private static final String KBS_AUTH_TOKENS = "kbs.kbs_auth_tokens";
|
||||
private static final String KBS_LAST_AUTH_REFRESH_TIMESTAMP = "kbs.kbs_auth_tokens.last_refresh_timestamp";
|
||||
private static final String SVR_AUTH_TOKENS = "kbs.kbs_auth_tokens";
|
||||
private static final String SVR_LAST_AUTH_REFRESH_TIMESTAMP = "kbs.kbs_auth_tokens.last_refresh_timestamp";
|
||||
|
||||
KbsValues(KeyValueStore store) {
|
||||
SvrValues(KeyValueStore store) {
|
||||
super(store);
|
||||
}
|
||||
|
||||
@@ -42,39 +40,27 @@ public final class KbsValues extends SignalStoreValues {
|
||||
@Override
|
||||
@NonNull
|
||||
List<String> getKeysToIncludeInBackup() {
|
||||
return List.of(KBS_AUTH_TOKENS);
|
||||
return List.of(SVR_AUTH_TOKENS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliberately does not clear the {@link #MASTER_KEY}.
|
||||
*
|
||||
* Should only be called by {@link org.thoughtcrime.securesms.pin.PinState}
|
||||
*/
|
||||
public void clearRegistrationLockAndPin() {
|
||||
getStore().beginWrite()
|
||||
.remove(V2_LOCK_ENABLED)
|
||||
.remove(REGISTRATION_LOCK_ENABLED)
|
||||
.remove(TOKEN_RESPONSE)
|
||||
.remove(LOCK_LOCAL_PIN_HASH)
|
||||
.remove(PIN)
|
||||
.remove(LAST_CREATE_FAILED_TIMESTAMP)
|
||||
.remove(OPTED_OUT)
|
||||
.remove(KBS_AUTH_TOKENS)
|
||||
.remove(KBS_LAST_AUTH_REFRESH_TIMESTAMP)
|
||||
.remove(SVR_AUTH_TOKENS)
|
||||
.remove(SVR_LAST_AUTH_REFRESH_TIMESTAMP)
|
||||
.commit();
|
||||
}
|
||||
|
||||
/** Should only be set by {@link org.thoughtcrime.securesms.pin.PinState}. */
|
||||
public synchronized void setKbsMasterKey(@NonNull KbsPinData pinData, @NonNull String pin) {
|
||||
MasterKey masterKey = pinData.getMasterKey();
|
||||
String tokenResponse;
|
||||
try {
|
||||
tokenResponse = JsonUtils.toJson(pinData.getTokenResponse());
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
||||
public synchronized void setMasterKey(@NonNull MasterKey masterKey, @NonNull String pin) {
|
||||
getStore().beginWrite()
|
||||
.putString(TOKEN_RESPONSE, tokenResponse)
|
||||
.putBlob(MASTER_KEY, masterKey.serialize())
|
||||
.putString(LOCK_LOCAL_PIN_HASH, PinHashUtil.localPinHash(pin))
|
||||
.putString(PIN, pin)
|
||||
@@ -89,19 +75,17 @@ public final class KbsValues extends SignalStoreValues {
|
||||
}
|
||||
}
|
||||
|
||||
/** Should only be set by {@link org.thoughtcrime.securesms.pin.PinState}. */
|
||||
public synchronized void setV2RegistrationLockEnabled(boolean enabled) {
|
||||
putBoolean(V2_LOCK_ENABLED, enabled);
|
||||
public synchronized void setRegistrationLockEnabled(boolean enabled) {
|
||||
putBoolean(REGISTRATION_LOCK_ENABLED, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not registration lock V2 is enabled.
|
||||
*/
|
||||
public synchronized boolean isV2RegistrationLockEnabled() {
|
||||
return getBoolean(V2_LOCK_ENABLED, false);
|
||||
public synchronized boolean isRegistrationLockEnabled() {
|
||||
return getBoolean(REGISTRATION_LOCK_ENABLED, false);
|
||||
}
|
||||
|
||||
/** Should only be set by {@link org.thoughtcrime.securesms.pin.PinState}. */
|
||||
public synchronized void onPinCreateFailure() {
|
||||
putLong(LAST_CREATE_FAILED_TIMESTAMP, System.currentTimeMillis());
|
||||
}
|
||||
@@ -136,7 +120,7 @@ public final class KbsValues extends SignalStoreValues {
|
||||
* Returns null if master key is not backed up by a pin.
|
||||
*/
|
||||
public synchronized @Nullable MasterKey getPinBackedMasterKey() {
|
||||
if (!isV2RegistrationLockEnabled()) return null;
|
||||
if (!isRegistrationLockEnabled()) return null;
|
||||
return getMasterKey();
|
||||
}
|
||||
|
||||
@@ -184,12 +168,12 @@ public final class KbsValues extends SignalStoreValues {
|
||||
}
|
||||
|
||||
public synchronized void putAuthTokenList(List<String> tokens) {
|
||||
putList(KBS_AUTH_TOKENS, tokens, StringStringSerializer.INSTANCE);
|
||||
putList(SVR_AUTH_TOKENS, tokens, StringStringSerializer.INSTANCE);
|
||||
setLastRefreshAuthTimestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public synchronized List<String> getKbsAuthTokenList() {
|
||||
return getList(KBS_AUTH_TOKENS, StringStringSerializer.INSTANCE);
|
||||
public synchronized List<String> getAuthTokenList() {
|
||||
return getList(SVR_AUTH_TOKENS, StringStringSerializer.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +182,7 @@ public final class KbsValues extends SignalStoreValues {
|
||||
* @return whether the token was added (new) or ignored (already existed)
|
||||
*/
|
||||
public synchronized boolean appendAuthTokenToList(String token) {
|
||||
List<String> tokens = getKbsAuthTokenList();
|
||||
List<String> tokens = getAuthTokenList();
|
||||
if (tokens.contains(token)) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -209,7 +193,7 @@ public final class KbsValues extends SignalStoreValues {
|
||||
}
|
||||
|
||||
public boolean removeAuthTokens(@NonNull List<String> invalid) {
|
||||
List<String> tokens = new ArrayList<>(getKbsAuthTokenList());
|
||||
List<String> tokens = new ArrayList<>(getAuthTokenList());
|
||||
if (tokens.removeAll(invalid)) {
|
||||
putAuthTokenList(tokens);
|
||||
return true;
|
||||
@@ -218,7 +202,6 @@ public final class KbsValues extends SignalStoreValues {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Should only be called by {@link org.thoughtcrime.securesms.pin.PinState}. */
|
||||
public synchronized void optOut() {
|
||||
getStore().beginWrite()
|
||||
.putBoolean(OPTED_OUT, true)
|
||||
@@ -247,10 +230,10 @@ public final class KbsValues extends SignalStoreValues {
|
||||
}
|
||||
|
||||
private void setLastRefreshAuthTimestamp(long timestamp) {
|
||||
putLong(KBS_LAST_AUTH_REFRESH_TIMESTAMP, timestamp);
|
||||
putLong(SVR_LAST_AUTH_REFRESH_TIMESTAMP, timestamp);
|
||||
}
|
||||
|
||||
public long getLastRefreshAuthTimestamp() {
|
||||
return getLong(KBS_LAST_AUTH_REFRESH_TIMESTAMP, 0L);
|
||||
return getLong(SVR_LAST_AUTH_REFRESH_TIMESTAMP, 0L);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user