mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 01:06:50 +00:00
Don't assume presence of phone numbers in account deletion
This commit is contained in:
1 parent
713ab0314e
commit
af6e2c2f2b
5 files changed
+84
-43
No files matched your search
@@ -28,6 +28,7 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
@@ -38,7 +39,9 @@ import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.auth.SaltedTokenHash;
|
||||
import org.whispersystems.textsecuregcm.auth.StoredRegistrationLock;
|
||||
import org.whispersystems.textsecuregcm.entities.AccountAttributes;
|
||||
import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.identity.IdentityType;
|
||||
import org.whispersystems.textsecuregcm.identity.PniServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.identity.ServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.util.ByteArrayBase64UrlAdapter;
|
||||
import org.whispersystems.textsecuregcm.util.IdentityKeyAdapter;
|
||||
|
||||
@@ -1388,12 +1388,17 @@ public class Accounts {
|
||||
account = maybeAccount.get();
|
||||
}
|
||||
|
||||
final List<TransactWriteItem> transactWriteItems = new ArrayList<>(List.of(
|
||||
buildConditionalDeleteAccount(account),
|
||||
buildDelete(phoneNumberConstraintTableName, ATTR_ACCOUNT_E164, account.getNumber()),
|
||||
buildDelete(phoneNumberIdentifierConstraintTableName, ATTR_PNI_UUID, account.getPhoneNumberIdentifier()),
|
||||
buildPutDeletedAccount(uuid, account.getPhoneNumberIdentifier())
|
||||
));
|
||||
|
||||
final List<TransactWriteItem> transactWriteItems = new ArrayList<>();
|
||||
transactWriteItems.add(buildConditionalDeleteAccount(account));
|
||||
|
||||
account.getNumberOptional().ifPresent(e164 -> transactWriteItems.add(
|
||||
buildDelete(phoneNumberConstraintTableName, ATTR_ACCOUNT_E164, e164)));
|
||||
|
||||
account.getPhoneNumberIdentifierOptional().ifPresent(pni -> {
|
||||
transactWriteItems.add(buildDelete(phoneNumberIdentifierConstraintTableName, ATTR_PNI_UUID, pni));
|
||||
transactWriteItems.add(buildPutDeletedAccount(uuid, pni));
|
||||
});
|
||||
|
||||
account.getUsernameHash().ifPresent(usernameHash -> transactWriteItems.add(
|
||||
buildDelete(usernamesConstraintTableName, UsernameTable.KEY_USERNAME_HASH, usernameHash)));
|
||||
|
||||
+9
-12
@@ -735,7 +735,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
account.getIdentifier(IdentityType.ACI),
|
||||
account.getPhoneNumberIdentifierOptional(),
|
||||
deviceId));
|
||||
|
||||
try {
|
||||
accounts.updateTransactionally(account, additionalWriteItems);
|
||||
|
||||
@@ -1282,7 +1281,7 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
final Account account = maybeAccount.get();
|
||||
|
||||
try {
|
||||
accountLockManager.withLock(Set.of(account.getPhoneNumberIdentifier()), () -> {
|
||||
accountLockManager.withSingleAccountLock(account, () -> {
|
||||
delete(account);
|
||||
return null;
|
||||
}, accountLockExecutor);
|
||||
@@ -1312,16 +1311,14 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
|
||||
account.getPhoneNumberIdentifierOptional().ifPresent(phoneNumberIdentifier ->
|
||||
additionalWriteItems.add(phoneNumberRecoveryPasswordsManager.buildTransactWriteItemForRemovePassword(phoneNumberIdentifier)));
|
||||
|
||||
CompletableFuture.allOf(
|
||||
secureStorageClient.deleteStoredData(account.getAccountIdentifier()),
|
||||
secureValueRecovery2Client.removeData(account.getAccountIdentifier()),
|
||||
keysManager.deleteSingleUsePreKeys(account.getAccountIdentifier()),
|
||||
keysManager.deleteSingleUsePreKeys(account.getPhoneNumberIdentifier()),
|
||||
account.getPhoneNumberIdentifierOptional().map(keysManager::deleteSingleUsePreKeys).orElse(CompletableFuture.completedFuture(null)),
|
||||
messagesManager.clear(account.getAccountIdentifier()),
|
||||
profilesManager.deleteAll(account.getAccountIdentifier(), true))
|
||||
.join();
|
||||
|
||||
accounts.delete(account.getAccountIdentifier(), additionalWriteItems);
|
||||
redisDelete(account);
|
||||
|
||||
@@ -1476,11 +1473,6 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
if (StringUtils.isNotBlank(accountJson)) {
|
||||
Account account = SystemMapper.jsonMapper().readValue(accountJson, Account.class);
|
||||
account.setAccountIdentifier(uuid);
|
||||
|
||||
if (account.getPhoneNumberIdentifier() == null) {
|
||||
logger.warn("Account {} loaded from Redis is missing a PNI", uuid);
|
||||
}
|
||||
|
||||
return Optional.of(account);
|
||||
}
|
||||
|
||||
@@ -1497,11 +1489,16 @@ public class AccountsManager extends RedisPubSubAdapter<String, String> implemen
|
||||
}
|
||||
|
||||
private void redisDelete(final Account account) {
|
||||
final List<String> keysToDelete = new ArrayList<>(2);
|
||||
account.getPhoneNumberIdentifierOptional()
|
||||
.map(pni -> getAccountMapKey(pni.toString()))
|
||||
.ifPresent(keysToDelete::add);
|
||||
keysToDelete.add(getAccountEntityKey(account.getAccountIdentifier()));
|
||||
|
||||
ResilienceUtil.getGeneralRedisRetry(RETRY_NAME).executeRunnable(() ->
|
||||
redisDeleteTimer.record(() ->
|
||||
cacheCluster.useCluster(connection ->
|
||||
connection.sync().del(getAccountMapKey(account.getPhoneNumberIdentifier().toString()),
|
||||
getAccountEntityKey(account.getAccountIdentifier())))));
|
||||
connection.sync().del(keysToDelete.toArray(String[]::new)))));
|
||||
}
|
||||
|
||||
public CompletableFuture<Optional<DeviceInfo>> waitForNewLinkedDevice(
|
||||
|
||||
+49
-25
@@ -39,6 +39,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.junitpioneer.jupiter.cartesian.ArgumentSets;
|
||||
import org.junitpioneer.jupiter.cartesian.CartesianTest;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
@@ -60,6 +61,7 @@ import org.whispersystems.textsecuregcm.securestorage.SecureStorageClient;
|
||||
import org.whispersystems.textsecuregcm.securevaluerecovery.SecureValueRecoveryClient;
|
||||
import org.whispersystems.textsecuregcm.tests.util.KeysHelper;
|
||||
import org.whispersystems.textsecuregcm.util.TestRandomUtil;
|
||||
import org.whispersystems.textsecuregcm.util.ValidBase64URLString;
|
||||
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
|
||||
|
||||
public class AccountCreationDeletionIntegrationTest {
|
||||
@@ -493,8 +495,10 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
account.getAccountIdentifier().equals(existingAccountUuid) && account != reregisteredAccount));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAccountWithNumber() throws InterruptedException {
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void deleteAccount(final boolean hasE164)
|
||||
throws InvalidInputException, VerificationFailedException, ReceiptAlreadyRedeemedException {
|
||||
final String number = PhoneNumberUtil.getInstance().format(
|
||||
PhoneNumberUtil.getInstance().getExampleNumber("US"),
|
||||
PhoneNumberUtil.PhoneNumberFormat.E164);
|
||||
@@ -531,38 +535,58 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
final KEMSignedPreKey aciPqLastResortPreKey = KeysHelper.signedKEMPreKey(3, aciKeyPair);
|
||||
final KEMSignedPreKey pniPqLastResortPreKey = KeysHelper.signedKEMPreKey(4, pniKeyPair);
|
||||
|
||||
final Account account = accountsManager.create(number,
|
||||
accountAttributes,
|
||||
badges,
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||
new DeviceSpec(
|
||||
deviceName,
|
||||
password,
|
||||
signalAgent,
|
||||
deviceCapabilities,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(pniRegistrationId, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty()),
|
||||
null);
|
||||
final Account account;
|
||||
if (hasE164) {
|
||||
account = accountsManager.create(number,
|
||||
accountAttributes,
|
||||
badges,
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||
new DeviceSpec(
|
||||
deviceName,
|
||||
password,
|
||||
signalAgent,
|
||||
deviceCapabilities,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(pniRegistrationId, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty()),
|
||||
null);
|
||||
assertTrue(phoneNumberRecoveryPasswordsManager.verify(account.getPhoneNumberIdentifierOptional().orElseThrow(),
|
||||
accountAttributes.recoveryPassword().orElseThrow()));
|
||||
} else {
|
||||
account = accountsManager.create(accountAttributes,
|
||||
badges,
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
receiptPresentation(CLOCK.instant().plus(Duration.ofDays(30)), 1),
|
||||
new DeviceSpec(
|
||||
deviceName,
|
||||
password,
|
||||
signalAgent,
|
||||
deviceCapabilities,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty()),
|
||||
null);
|
||||
}
|
||||
|
||||
final UUID aci = account.getIdentifier(IdentityType.ACI);
|
||||
|
||||
assertTrue(accountsManager.getByAccountIdentifier(aci).isPresent());
|
||||
assertTrue(phoneNumberRecoveryPasswordsManager.verify(account.getPhoneNumberIdentifierOptional().orElseThrow(),
|
||||
accountAttributes.recoveryPassword().orElseThrow()));
|
||||
|
||||
accountsManager.delete(account.getIdentifier(IdentityType.ACI), AccountsManager.DeletionReason.ADMIN_DELETED);
|
||||
|
||||
assertFalse(accountsManager.getByAccountIdentifier(aci).isPresent());
|
||||
assertFalse(keysManager.getEcSignedPreKey(account.getAccountIdentifier(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(keysManager.getEcSignedPreKey(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(keysManager.getLastResort(account.getAccountIdentifier(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(keysManager.getLastResort(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(phoneNumberRecoveryPasswordsManager.verify(account.getPhoneNumberIdentifierOptional().orElseThrow(),
|
||||
accountAttributes.recoveryPassword().orElseThrow()));
|
||||
if (hasE164) {
|
||||
assertFalse(keysManager.getEcSignedPreKey(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(keysManager.getLastResort(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(phoneNumberRecoveryPasswordsManager.verify(account.getPhoneNumberIdentifierOptional().orElseThrow(),
|
||||
accountAttributes.recoveryPassword().orElseThrow()));
|
||||
}
|
||||
|
||||
verify(disconnectionRequestManager).requestDisconnection(argThat(disconnectedAccount ->
|
||||
disconnectedAccount.getIdentifier(IdentityType.ACI).equals(account.getIdentifier(IdentityType.ACI))));
|
||||
|
||||
@@ -63,6 +63,8 @@ import org.junit.jupiter.params.provider.NullSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.junitpioneer.jupiter.cartesian.ArgumentSets;
|
||||
import org.junitpioneer.jupiter.cartesian.CartesianTest;
|
||||
import org.signal.libsignal.zkgroup.InvalidInputException;
|
||||
import org.signal.libsignal.zkgroup.VerificationFailedException;
|
||||
import org.signal.libsignal.zkgroup.ZkCredentialKeyPair;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupCredentialType;
|
||||
import org.signal.libsignal.zkgroup.receipts.ReceiptCredentialPresentation;
|
||||
@@ -1108,6 +1110,16 @@ class AccountsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteNumberless() throws InvalidInputException, VerificationFailedException {
|
||||
final Account deletedAccount = generateNumberlessAccount(UUID.randomUUID());
|
||||
createNumberlessAccount(deletedAccount, receiptPresentation());
|
||||
|
||||
assertThat(accounts.getByAccountIdentifier(deletedAccount.getAccountIdentifier())).isPresent();
|
||||
accounts.delete(deletedAccount.getAccountIdentifier(), Collections.emptyList());
|
||||
assertThat(accounts.getByAccountIdentifier(deletedAccount.getAccountIdentifier())).isNotPresent();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"+14151112222"})
|
||||
@NullSource
|
||||
|
||||
Reference in new issue
Block a user