mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +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
|
@ -1931,6 +1931,17 @@
|
||||||
"allDeclaredMethods":true,
|
"allDeclaredMethods":true,
|
||||||
"allDeclaredConstructors":true
|
"allDeclaredConstructors":true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name":"org.whispersystems.signalservice.api.account.ChangePhoneNumberRequest",
|
||||||
|
"allDeclaredFields":true,
|
||||||
|
"queryAllDeclaredMethods":true,
|
||||||
|
"queryAllDeclaredConstructors":true,
|
||||||
|
"methods":[
|
||||||
|
{"name":"getCode","parameterTypes":[] },
|
||||||
|
{"name":"getNumber","parameterTypes":[] },
|
||||||
|
{"name":"getRegistrationLock","parameterTypes":[] }
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name":"org.whispersystems.signalservice.api.groupsv2.CredentialResponse",
|
"name":"org.whispersystems.signalservice.api.groupsv2.CredentialResponse",
|
||||||
"allDeclaredFields":true,
|
"allDeclaredFields":true,
|
||||||
|
@ -2937,6 +2948,13 @@
|
||||||
"allDeclaredMethods":true,
|
"allDeclaredMethods":true,
|
||||||
"allDeclaredConstructors":true
|
"allDeclaredConstructors":true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name":"org.whispersystems.signalservice.internal.push.WhoAmIResponse",
|
||||||
|
"allDeclaredFields":true,
|
||||||
|
"queryAllDeclaredMethods":true,
|
||||||
|
"queryAllDeclaredConstructors":true,
|
||||||
|
"methods":[{"name":"<init>","parameterTypes":[] }]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name":"org.whispersystems.signalservice.internal.serialize.protos.AddressProto",
|
"name":"org.whispersystems.signalservice.internal.serialize.protos.AddressProto",
|
||||||
"fields":[
|
"fields":[
|
||||||
|
|
|
@ -68,6 +68,11 @@ public class SignalDependencies {
|
||||||
this.sessionLock = sessionLock;
|
this.sessionLock = sessionLock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetAfterAddressChange() {
|
||||||
|
this.messageSender = null;
|
||||||
|
this.cipher = null;
|
||||||
|
}
|
||||||
|
|
||||||
public ServiceEnvironmentConfig getServiceEnvironmentConfig() {
|
public ServiceEnvironmentConfig getServiceEnvironmentConfig() {
|
||||||
return serviceEnvironmentConfig;
|
return serviceEnvironmentConfig;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +86,16 @@ public class SignalDependencies {
|
||||||
ServiceConfig.AUTOMATIC_NETWORK_RETRY));
|
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() {
|
public GroupsV2Api getGroupsV2Api() {
|
||||||
return getOrCreate(() -> groupsV2Api, () -> groupsV2Api = getAccountManager().getGroupsV2Api());
|
return getOrCreate(() -> groupsV2Api, () -> groupsV2Api = getAccountManager().getGroupsV2Api());
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class ServiceConfig {
|
||||||
public static final AccountAttributes.Capabilities capabilities;
|
public static final AccountAttributes.Capabilities capabilities;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
capabilities = new AccountAttributes.Capabilities(false, true, false, true, true, true, false);
|
capabilities = new AccountAttributes.Capabilities(false, true, false, true, true, true, true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TrustStore contactTrustStore = new IasTrustStore();
|
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.DeviceLinkInfo;
|
||||||
import org.asamk.signal.manager.SignalDependencies;
|
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.InvalidDeviceLinkException;
|
||||||
|
import org.asamk.signal.manager.api.PinLockedException;
|
||||||
import org.asamk.signal.manager.config.ServiceConfig;
|
import org.asamk.signal.manager.config.ServiceConfig;
|
||||||
import org.asamk.signal.manager.storage.SignalAccount;
|
import org.asamk.signal.manager.storage.SignalAccount;
|
||||||
import org.asamk.signal.manager.util.KeyUtils;
|
import org.asamk.signal.manager.util.KeyUtils;
|
||||||
|
import org.asamk.signal.manager.util.NumberVerificationUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.libsignal.InvalidKeyException;
|
import org.whispersystems.libsignal.InvalidKeyException;
|
||||||
|
@ -76,10 +80,30 @@ public class AccountHelper {
|
||||||
account.setNumber(number);
|
account.setNumber(number);
|
||||||
account.setAci(aci);
|
account.setAci(aci);
|
||||||
account.getRecipientStore().resolveSelfRecipientTrusted(account.getSelfRecipientAddress());
|
account.getRecipientStore().resolveSelfRecipientTrusted(account.getSelfRecipientAddress());
|
||||||
context.getAccountFileUpdater().updateAccountIdentifiers(account.getNumber(), account.getAci());
|
|
||||||
// TODO check and update remote storage
|
// TODO check and update remote storage
|
||||||
context.getUnidentifiedAccessHelper().rotateSenderCertificates();
|
context.getUnidentifiedAccessHelper().rotateSenderCertificates();
|
||||||
|
dependencies.resetAfterAddressChange();
|
||||||
dependencies.getSignalWebSocket().forceNewWebSockets();
|
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) {
|
public void setDeviceName(String deviceName) {
|
||||||
|
|
|
@ -189,7 +189,7 @@ public class StorageHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!accountRecord.getE164().equals(account.getNumber())) {
|
if (!accountRecord.getE164().equals(account.getNumber())) {
|
||||||
// TODO implement changed number handling
|
context.getAccountHelper().checkWhoAmiI();
|
||||||
}
|
}
|
||||||
|
|
||||||
account.getConfigurationStore().setReadReceipts(accountRecord.isReadReceiptsEnabled());
|
account.getConfigurationStore().setReadReceipts(accountRecord.isReadReceiptsEnabled());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue