mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Implement support for change number as linked device
This commit is contained in:
parent
f207c2abc3
commit
d690b35ed9
5 changed files with 60 additions and 3 deletions
|
@ -68,6 +68,11 @@ public class SignalDependencies {
|
|||
this.sessionLock = sessionLock;
|
||||
}
|
||||
|
||||
public void resetAfterAddressChange() {
|
||||
this.messageSender = null;
|
||||
this.cipher = null;
|
||||
}
|
||||
|
||||
public ServiceEnvironmentConfig getServiceEnvironmentConfig() {
|
||||
return serviceEnvironmentConfig;
|
||||
}
|
||||
|
@ -81,6 +86,16 @@ public class SignalDependencies {
|
|||
ServiceConfig.AUTOMATIC_NETWORK_RETRY));
|
||||
}
|
||||
|
||||
public SignalServiceAccountManager createUnauthenticatedAccountManager(String number, String password) {
|
||||
return new SignalServiceAccountManager(getServiceEnvironmentConfig().getSignalServiceConfiguration(),
|
||||
null,
|
||||
number,
|
||||
password,
|
||||
SignalServiceAddress.DEFAULT_DEVICE_ID,
|
||||
userAgent,
|
||||
ServiceConfig.AUTOMATIC_NETWORK_RETRY);
|
||||
}
|
||||
|
||||
public GroupsV2Api getGroupsV2Api() {
|
||||
return getOrCreate(() -> groupsV2Api, () -> groupsV2Api = getAccountManager().getGroupsV2Api());
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class ServiceConfig {
|
|||
public static final AccountAttributes.Capabilities capabilities;
|
||||
|
||||
static {
|
||||
capabilities = new AccountAttributes.Capabilities(false, true, false, true, true, true, false);
|
||||
capabilities = new AccountAttributes.Capabilities(false, true, false, true, true, true, true);
|
||||
|
||||
try {
|
||||
TrustStore contactTrustStore = new IasTrustStore();
|
||||
|
|
|
@ -2,10 +2,14 @@ package org.asamk.signal.manager.helper;
|
|||
|
||||
import org.asamk.signal.manager.DeviceLinkInfo;
|
||||
import org.asamk.signal.manager.SignalDependencies;
|
||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.IncorrectPinException;
|
||||
import org.asamk.signal.manager.api.InvalidDeviceLinkException;
|
||||
import org.asamk.signal.manager.api.PinLockedException;
|
||||
import org.asamk.signal.manager.config.ServiceConfig;
|
||||
import org.asamk.signal.manager.storage.SignalAccount;
|
||||
import org.asamk.signal.manager.util.KeyUtils;
|
||||
import org.asamk.signal.manager.util.NumberVerificationUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
|
@ -76,10 +80,30 @@ public class AccountHelper {
|
|||
account.setNumber(number);
|
||||
account.setAci(aci);
|
||||
account.getRecipientStore().resolveSelfRecipientTrusted(account.getSelfRecipientAddress());
|
||||
context.getAccountFileUpdater().updateAccountIdentifiers(account.getNumber(), account.getAci());
|
||||
// TODO check and update remote storage
|
||||
context.getUnidentifiedAccessHelper().rotateSenderCertificates();
|
||||
dependencies.resetAfterAddressChange();
|
||||
dependencies.getSignalWebSocket().forceNewWebSockets();
|
||||
context.getAccountFileUpdater().updateAccountIdentifiers(account.getNumber(), account.getAci());
|
||||
}
|
||||
|
||||
public void startChangeNumber(
|
||||
String newNumber, String captcha, boolean voiceVerification
|
||||
) throws IOException, CaptchaRequiredException {
|
||||
final var accountManager = dependencies.createUnauthenticatedAccountManager(newNumber, account.getPassword());
|
||||
NumberVerificationUtils.requestVerificationCode(accountManager, captcha, voiceVerification);
|
||||
}
|
||||
|
||||
public void finishChangeNumber(
|
||||
String newNumber, String verificationCode, String pin
|
||||
) throws IncorrectPinException, PinLockedException, IOException {
|
||||
final var result = NumberVerificationUtils.verifyNumber(verificationCode,
|
||||
pin,
|
||||
context.getPinHelper(),
|
||||
(verificationCode1, registrationLock) -> dependencies.getAccountManager()
|
||||
.changeNumber(verificationCode1, newNumber, registrationLock));
|
||||
// TODO handle response
|
||||
updateSelfIdentifiers(newNumber, account.getAci());
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName) {
|
||||
|
|
|
@ -189,7 +189,7 @@ public class StorageHelper {
|
|||
}
|
||||
|
||||
if (!accountRecord.getE164().equals(account.getNumber())) {
|
||||
// TODO implement changed number handling
|
||||
context.getAccountHelper().checkWhoAmiI();
|
||||
}
|
||||
|
||||
account.getConfigurationStore().setReadReceipts(accountRecord.isReadReceiptsEnabled());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue