mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Store information if account is registerd on LIVE or STAGING env in account file
Fixes #896
This commit is contained in:
parent
656282459c
commit
55dde93811
6 changed files with 58 additions and 3 deletions
|
@ -136,6 +136,7 @@ class ProvisioningManagerImpl implements ProvisioningManager {
|
|||
account = SignalAccount.createOrUpdateLinkedAccount(pathConfig.dataPath(),
|
||||
accountPath,
|
||||
number,
|
||||
serviceEnvironmentConfig.getType(),
|
||||
aci,
|
||||
pni,
|
||||
password,
|
||||
|
@ -209,6 +210,13 @@ class ProvisioningManagerImpl implements ProvisioningManager {
|
|||
logger.debug("Account is a master device.");
|
||||
return false;
|
||||
}
|
||||
if (signalAccount.isRegistered()
|
||||
&& signalAccount.getServiceEnvironment() != null
|
||||
&& signalAccount.getServiceEnvironment() != serviceEnvironmentConfig.getType()) {
|
||||
logger.debug("Account is registered in another environment: {}.",
|
||||
signalAccount.getServiceEnvironment());
|
||||
return false;
|
||||
}
|
||||
|
||||
final var m = new ManagerImpl(signalAccount,
|
||||
pathConfig,
|
||||
|
|
|
@ -95,6 +95,12 @@ class RegistrationManagerImpl implements RegistrationManager {
|
|||
|
||||
@Override
|
||||
public void register(boolean voiceVerification, String captcha) throws IOException, CaptchaRequiredException {
|
||||
if (account.isRegistered()
|
||||
&& account.getServiceEnvironment() != null
|
||||
&& account.getServiceEnvironment() != serviceEnvironmentConfig.getType()) {
|
||||
throw new IOException("Account is registered in another environment: " + account.getServiceEnvironment());
|
||||
}
|
||||
|
||||
if (account.getAci() != null && attemptReactivateAccount()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public class SignalAccountFiles {
|
|||
private static final Logger logger = LoggerFactory.getLogger(MultiAccountManager.class);
|
||||
|
||||
private final PathConfig pathConfig;
|
||||
private final ServiceEnvironment serviceEnvironment;
|
||||
private final ServiceEnvironmentConfig serviceEnvironmentConfig;
|
||||
private final String userAgent;
|
||||
private final TrustNewIdentity trustNewIdentity;
|
||||
|
@ -36,7 +37,8 @@ public class SignalAccountFiles {
|
|||
final TrustNewIdentity trustNewIdentity
|
||||
) throws IOException {
|
||||
this.pathConfig = PathConfig.createDefault(settingsPath);
|
||||
this.serviceEnvironmentConfig = ServiceConfig.getServiceEnvironmentConfig(serviceEnvironment, userAgent);
|
||||
this.serviceEnvironment = serviceEnvironment;
|
||||
this.serviceEnvironmentConfig = ServiceConfig.getServiceEnvironmentConfig(this.serviceEnvironment, userAgent);
|
||||
this.userAgent = userAgent;
|
||||
this.trustNewIdentity = trustNewIdentity;
|
||||
this.accountsStore = new AccountsStore(pathConfig.dataPath());
|
||||
|
@ -85,6 +87,10 @@ public class SignalAccountFiles {
|
|||
throw new NotRegisteredException();
|
||||
}
|
||||
|
||||
if (account.getServiceEnvironment() != null && account.getServiceEnvironment() != serviceEnvironment) {
|
||||
throw new IOException("Account is registered in another environment: " + account.getServiceEnvironment());
|
||||
}
|
||||
|
||||
account.initDatabase();
|
||||
|
||||
final var manager = new ManagerImpl(account,
|
||||
|
@ -100,6 +106,10 @@ public class SignalAccountFiles {
|
|||
throw new AccountCheckException("Error while checking account " + number + ": " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (account.getServiceEnvironment() == null) {
|
||||
account.setServiceEnvironment(serviceEnvironment);
|
||||
}
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
@ -133,6 +143,7 @@ public class SignalAccountFiles {
|
|||
var account = SignalAccount.create(pathConfig.dataPath(),
|
||||
newAccountPath,
|
||||
number,
|
||||
serviceEnvironment,
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
registrationId,
|
||||
|
|
|
@ -75,11 +75,13 @@ public class ServiceConfig {
|
|||
final var interceptors = List.of(userAgentInterceptor);
|
||||
|
||||
return switch (serviceEnvironment) {
|
||||
case LIVE -> new ServiceEnvironmentConfig(LiveConfig.createDefaultServiceConfiguration(interceptors),
|
||||
case LIVE -> new ServiceEnvironmentConfig(serviceEnvironment,
|
||||
LiveConfig.createDefaultServiceConfiguration(interceptors),
|
||||
LiveConfig.getUnidentifiedSenderTrustRoot(),
|
||||
LiveConfig.createKeyBackupConfig(),
|
||||
LiveConfig.getCdsMrenclave());
|
||||
case STAGING -> new ServiceEnvironmentConfig(StagingConfig.createDefaultServiceConfiguration(interceptors),
|
||||
case STAGING -> new ServiceEnvironmentConfig(serviceEnvironment,
|
||||
StagingConfig.createDefaultServiceConfiguration(interceptors),
|
||||
StagingConfig.getUnidentifiedSenderTrustRoot(),
|
||||
StagingConfig.createKeyBackupConfig(),
|
||||
StagingConfig.getCdsMrenclave());
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.whispersystems.signalservice.internal.configuration.SignalServiceConf
|
|||
|
||||
public class ServiceEnvironmentConfig {
|
||||
|
||||
private final ServiceEnvironment type;
|
||||
private final SignalServiceConfiguration signalServiceConfiguration;
|
||||
|
||||
private final ECPublicKey unidentifiedSenderTrustRoot;
|
||||
|
@ -14,17 +15,23 @@ public class ServiceEnvironmentConfig {
|
|||
private final String cdsMrenclave;
|
||||
|
||||
public ServiceEnvironmentConfig(
|
||||
final ServiceEnvironment type,
|
||||
final SignalServiceConfiguration signalServiceConfiguration,
|
||||
final ECPublicKey unidentifiedSenderTrustRoot,
|
||||
final KeyBackupConfig keyBackupConfig,
|
||||
final String cdsMrenclave
|
||||
) {
|
||||
this.type = type;
|
||||
this.signalServiceConfiguration = signalServiceConfiguration;
|
||||
this.unidentifiedSenderTrustRoot = unidentifiedSenderTrustRoot;
|
||||
this.keyBackupConfig = keyBackupConfig;
|
||||
this.cdsMrenclave = cdsMrenclave;
|
||||
}
|
||||
|
||||
public ServiceEnvironment getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public SignalServiceConfiguration getSignalServiceConfiguration() {
|
||||
return signalServiceConfiguration;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
|
||||
import org.asamk.signal.manager.api.Pair;
|
||||
import org.asamk.signal.manager.api.TrustLevel;
|
||||
import org.asamk.signal.manager.config.ServiceEnvironment;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.storage.configuration.ConfigurationStore;
|
||||
import org.asamk.signal.manager.storage.contacts.ContactsStore;
|
||||
|
@ -95,6 +96,7 @@ public class SignalAccount implements Closeable {
|
|||
|
||||
private File dataPath;
|
||||
private String accountPath;
|
||||
private ServiceEnvironment serviceEnvironment;
|
||||
private String number;
|
||||
private ACI aci;
|
||||
private PNI pni;
|
||||
|
@ -170,6 +172,7 @@ public class SignalAccount implements Closeable {
|
|||
File dataPath,
|
||||
String accountPath,
|
||||
String number,
|
||||
ServiceEnvironment serviceEnvironment,
|
||||
IdentityKeyPair aciIdentityKey,
|
||||
IdentityKeyPair pniIdentityKey,
|
||||
int registrationId,
|
||||
|
@ -187,6 +190,7 @@ public class SignalAccount implements Closeable {
|
|||
|
||||
signalAccount.accountPath = accountPath;
|
||||
signalAccount.number = number;
|
||||
signalAccount.serviceEnvironment = serviceEnvironment;
|
||||
signalAccount.profileKey = profileKey;
|
||||
|
||||
signalAccount.dataPath = dataPath;
|
||||
|
@ -213,6 +217,7 @@ public class SignalAccount implements Closeable {
|
|||
File dataPath,
|
||||
String accountPath,
|
||||
String number,
|
||||
ServiceEnvironment serviceEnvironment,
|
||||
ACI aci,
|
||||
PNI pni,
|
||||
String password,
|
||||
|
@ -230,6 +235,7 @@ public class SignalAccount implements Closeable {
|
|||
return createLinkedAccount(dataPath,
|
||||
accountPath,
|
||||
number,
|
||||
serviceEnvironment,
|
||||
aci,
|
||||
pni,
|
||||
password,
|
||||
|
@ -279,6 +285,7 @@ public class SignalAccount implements Closeable {
|
|||
File dataPath,
|
||||
String accountPath,
|
||||
String number,
|
||||
ServiceEnvironment serviceEnvironment,
|
||||
ACI aci,
|
||||
PNI pni,
|
||||
String password,
|
||||
|
@ -308,6 +315,7 @@ public class SignalAccount implements Closeable {
|
|||
|
||||
signalAccount.dataPath = dataPath;
|
||||
signalAccount.accountPath = accountPath;
|
||||
signalAccount.serviceEnvironment = serviceEnvironment;
|
||||
signalAccount.localRegistrationId = registrationId;
|
||||
signalAccount.trustNewIdentity = trustNewIdentity;
|
||||
signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath),
|
||||
|
@ -489,6 +497,9 @@ public class SignalAccount implements Closeable {
|
|||
if (rootNode.hasNonNull("password")) {
|
||||
password = rootNode.get("password").asText();
|
||||
}
|
||||
if (rootNode.hasNonNull("serviceEnvironment")) {
|
||||
serviceEnvironment = ServiceEnvironment.valueOf(rootNode.get("serviceEnvironment").asText());
|
||||
}
|
||||
registered = Utils.getNotNullNode(rootNode, "registered").asBoolean();
|
||||
if (rootNode.hasNonNull("uuid")) {
|
||||
try {
|
||||
|
@ -814,6 +825,7 @@ public class SignalAccount implements Closeable {
|
|||
var rootNode = jsonProcessor.createObjectNode();
|
||||
rootNode.put("version", CURRENT_STORAGE_VERSION)
|
||||
.put("username", number)
|
||||
.put("serviceEnvironment", serviceEnvironment == null ? null : serviceEnvironment.name())
|
||||
.put("uuid", aci == null ? null : aci.toString())
|
||||
.put("pni", pni == null ? null : pni.toString())
|
||||
.put("deviceName", encryptedDeviceName)
|
||||
|
@ -1109,6 +1121,15 @@ public class SignalAccount implements Closeable {
|
|||
save();
|
||||
}
|
||||
|
||||
public ServiceEnvironment getServiceEnvironment() {
|
||||
return serviceEnvironment;
|
||||
}
|
||||
|
||||
public void setServiceEnvironment(final ServiceEnvironment serviceEnvironment) {
|
||||
this.serviceEnvironment = serviceEnvironment;
|
||||
save();
|
||||
}
|
||||
|
||||
public ACI getAci() {
|
||||
return aci;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue