Store information if account is registerd on LIVE or STAGING env in account file

Fixes #896
This commit is contained in:
AsamK 2022-05-15 16:13:01 +02:00
parent 656282459c
commit 55dde93811
6 changed files with 58 additions and 3 deletions

View file

@ -136,6 +136,7 @@ class ProvisioningManagerImpl implements ProvisioningManager {
account = SignalAccount.createOrUpdateLinkedAccount(pathConfig.dataPath(), account = SignalAccount.createOrUpdateLinkedAccount(pathConfig.dataPath(),
accountPath, accountPath,
number, number,
serviceEnvironmentConfig.getType(),
aci, aci,
pni, pni,
password, password,
@ -209,6 +210,13 @@ class ProvisioningManagerImpl implements ProvisioningManager {
logger.debug("Account is a master device."); logger.debug("Account is a master device.");
return false; 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, final var m = new ManagerImpl(signalAccount,
pathConfig, pathConfig,

View file

@ -95,6 +95,12 @@ class RegistrationManagerImpl implements RegistrationManager {
@Override @Override
public void register(boolean voiceVerification, String captcha) throws IOException, CaptchaRequiredException { 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()) { if (account.getAci() != null && attemptReactivateAccount()) {
return; return;
} }

View file

@ -24,6 +24,7 @@ public class SignalAccountFiles {
private static final Logger logger = LoggerFactory.getLogger(MultiAccountManager.class); private static final Logger logger = LoggerFactory.getLogger(MultiAccountManager.class);
private final PathConfig pathConfig; private final PathConfig pathConfig;
private final ServiceEnvironment serviceEnvironment;
private final ServiceEnvironmentConfig serviceEnvironmentConfig; private final ServiceEnvironmentConfig serviceEnvironmentConfig;
private final String userAgent; private final String userAgent;
private final TrustNewIdentity trustNewIdentity; private final TrustNewIdentity trustNewIdentity;
@ -36,7 +37,8 @@ public class SignalAccountFiles {
final TrustNewIdentity trustNewIdentity final TrustNewIdentity trustNewIdentity
) throws IOException { ) throws IOException {
this.pathConfig = PathConfig.createDefault(settingsPath); 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.userAgent = userAgent;
this.trustNewIdentity = trustNewIdentity; this.trustNewIdentity = trustNewIdentity;
this.accountsStore = new AccountsStore(pathConfig.dataPath()); this.accountsStore = new AccountsStore(pathConfig.dataPath());
@ -85,6 +87,10 @@ public class SignalAccountFiles {
throw new NotRegisteredException(); throw new NotRegisteredException();
} }
if (account.getServiceEnvironment() != null && account.getServiceEnvironment() != serviceEnvironment) {
throw new IOException("Account is registered in another environment: " + account.getServiceEnvironment());
}
account.initDatabase(); account.initDatabase();
final var manager = new ManagerImpl(account, final var manager = new ManagerImpl(account,
@ -100,6 +106,10 @@ public class SignalAccountFiles {
throw new AccountCheckException("Error while checking account " + number + ": " + e.getMessage(), e); throw new AccountCheckException("Error while checking account " + number + ": " + e.getMessage(), e);
} }
if (account.getServiceEnvironment() == null) {
account.setServiceEnvironment(serviceEnvironment);
}
return manager; return manager;
} }
@ -133,6 +143,7 @@ public class SignalAccountFiles {
var account = SignalAccount.create(pathConfig.dataPath(), var account = SignalAccount.create(pathConfig.dataPath(),
newAccountPath, newAccountPath,
number, number,
serviceEnvironment,
aciIdentityKey, aciIdentityKey,
pniIdentityKey, pniIdentityKey,
registrationId, registrationId,

View file

@ -75,11 +75,13 @@ public class ServiceConfig {
final var interceptors = List.of(userAgentInterceptor); final var interceptors = List.of(userAgentInterceptor);
return switch (serviceEnvironment) { return switch (serviceEnvironment) {
case LIVE -> new ServiceEnvironmentConfig(LiveConfig.createDefaultServiceConfiguration(interceptors), case LIVE -> new ServiceEnvironmentConfig(serviceEnvironment,
LiveConfig.createDefaultServiceConfiguration(interceptors),
LiveConfig.getUnidentifiedSenderTrustRoot(), LiveConfig.getUnidentifiedSenderTrustRoot(),
LiveConfig.createKeyBackupConfig(), LiveConfig.createKeyBackupConfig(),
LiveConfig.getCdsMrenclave()); LiveConfig.getCdsMrenclave());
case STAGING -> new ServiceEnvironmentConfig(StagingConfig.createDefaultServiceConfiguration(interceptors), case STAGING -> new ServiceEnvironmentConfig(serviceEnvironment,
StagingConfig.createDefaultServiceConfiguration(interceptors),
StagingConfig.getUnidentifiedSenderTrustRoot(), StagingConfig.getUnidentifiedSenderTrustRoot(),
StagingConfig.createKeyBackupConfig(), StagingConfig.createKeyBackupConfig(),
StagingConfig.getCdsMrenclave()); StagingConfig.getCdsMrenclave());

View file

@ -5,6 +5,7 @@ import org.whispersystems.signalservice.internal.configuration.SignalServiceConf
public class ServiceEnvironmentConfig { public class ServiceEnvironmentConfig {
private final ServiceEnvironment type;
private final SignalServiceConfiguration signalServiceConfiguration; private final SignalServiceConfiguration signalServiceConfiguration;
private final ECPublicKey unidentifiedSenderTrustRoot; private final ECPublicKey unidentifiedSenderTrustRoot;
@ -14,17 +15,23 @@ public class ServiceEnvironmentConfig {
private final String cdsMrenclave; private final String cdsMrenclave;
public ServiceEnvironmentConfig( public ServiceEnvironmentConfig(
final ServiceEnvironment type,
final SignalServiceConfiguration signalServiceConfiguration, final SignalServiceConfiguration signalServiceConfiguration,
final ECPublicKey unidentifiedSenderTrustRoot, final ECPublicKey unidentifiedSenderTrustRoot,
final KeyBackupConfig keyBackupConfig, final KeyBackupConfig keyBackupConfig,
final String cdsMrenclave final String cdsMrenclave
) { ) {
this.type = type;
this.signalServiceConfiguration = signalServiceConfiguration; this.signalServiceConfiguration = signalServiceConfiguration;
this.unidentifiedSenderTrustRoot = unidentifiedSenderTrustRoot; this.unidentifiedSenderTrustRoot = unidentifiedSenderTrustRoot;
this.keyBackupConfig = keyBackupConfig; this.keyBackupConfig = keyBackupConfig;
this.cdsMrenclave = cdsMrenclave; this.cdsMrenclave = cdsMrenclave;
} }
public ServiceEnvironment getType() {
return type;
}
public SignalServiceConfiguration getSignalServiceConfiguration() { public SignalServiceConfiguration getSignalServiceConfiguration() {
return signalServiceConfiguration; return signalServiceConfiguration;
} }

View file

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.asamk.signal.manager.api.Pair; import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.TrustLevel; 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.groups.GroupId;
import org.asamk.signal.manager.storage.configuration.ConfigurationStore; import org.asamk.signal.manager.storage.configuration.ConfigurationStore;
import org.asamk.signal.manager.storage.contacts.ContactsStore; import org.asamk.signal.manager.storage.contacts.ContactsStore;
@ -95,6 +96,7 @@ public class SignalAccount implements Closeable {
private File dataPath; private File dataPath;
private String accountPath; private String accountPath;
private ServiceEnvironment serviceEnvironment;
private String number; private String number;
private ACI aci; private ACI aci;
private PNI pni; private PNI pni;
@ -170,6 +172,7 @@ public class SignalAccount implements Closeable {
File dataPath, File dataPath,
String accountPath, String accountPath,
String number, String number,
ServiceEnvironment serviceEnvironment,
IdentityKeyPair aciIdentityKey, IdentityKeyPair aciIdentityKey,
IdentityKeyPair pniIdentityKey, IdentityKeyPair pniIdentityKey,
int registrationId, int registrationId,
@ -187,6 +190,7 @@ public class SignalAccount implements Closeable {
signalAccount.accountPath = accountPath; signalAccount.accountPath = accountPath;
signalAccount.number = number; signalAccount.number = number;
signalAccount.serviceEnvironment = serviceEnvironment;
signalAccount.profileKey = profileKey; signalAccount.profileKey = profileKey;
signalAccount.dataPath = dataPath; signalAccount.dataPath = dataPath;
@ -213,6 +217,7 @@ public class SignalAccount implements Closeable {
File dataPath, File dataPath,
String accountPath, String accountPath,
String number, String number,
ServiceEnvironment serviceEnvironment,
ACI aci, ACI aci,
PNI pni, PNI pni,
String password, String password,
@ -230,6 +235,7 @@ public class SignalAccount implements Closeable {
return createLinkedAccount(dataPath, return createLinkedAccount(dataPath,
accountPath, accountPath,
number, number,
serviceEnvironment,
aci, aci,
pni, pni,
password, password,
@ -279,6 +285,7 @@ public class SignalAccount implements Closeable {
File dataPath, File dataPath,
String accountPath, String accountPath,
String number, String number,
ServiceEnvironment serviceEnvironment,
ACI aci, ACI aci,
PNI pni, PNI pni,
String password, String password,
@ -308,6 +315,7 @@ public class SignalAccount implements Closeable {
signalAccount.dataPath = dataPath; signalAccount.dataPath = dataPath;
signalAccount.accountPath = accountPath; signalAccount.accountPath = accountPath;
signalAccount.serviceEnvironment = serviceEnvironment;
signalAccount.localRegistrationId = registrationId; signalAccount.localRegistrationId = registrationId;
signalAccount.trustNewIdentity = trustNewIdentity; signalAccount.trustNewIdentity = trustNewIdentity;
signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath), signalAccount.groupStore = new GroupStore(getGroupCachePath(dataPath, accountPath),
@ -489,6 +497,9 @@ public class SignalAccount implements Closeable {
if (rootNode.hasNonNull("password")) { if (rootNode.hasNonNull("password")) {
password = rootNode.get("password").asText(); password = rootNode.get("password").asText();
} }
if (rootNode.hasNonNull("serviceEnvironment")) {
serviceEnvironment = ServiceEnvironment.valueOf(rootNode.get("serviceEnvironment").asText());
}
registered = Utils.getNotNullNode(rootNode, "registered").asBoolean(); registered = Utils.getNotNullNode(rootNode, "registered").asBoolean();
if (rootNode.hasNonNull("uuid")) { if (rootNode.hasNonNull("uuid")) {
try { try {
@ -814,6 +825,7 @@ public class SignalAccount implements Closeable {
var rootNode = jsonProcessor.createObjectNode(); var rootNode = jsonProcessor.createObjectNode();
rootNode.put("version", CURRENT_STORAGE_VERSION) rootNode.put("version", CURRENT_STORAGE_VERSION)
.put("username", number) .put("username", number)
.put("serviceEnvironment", serviceEnvironment == null ? null : serviceEnvironment.name())
.put("uuid", aci == null ? null : aci.toString()) .put("uuid", aci == null ? null : aci.toString())
.put("pni", pni == null ? null : pni.toString()) .put("pni", pni == null ? null : pni.toString())
.put("deviceName", encryptedDeviceName) .put("deviceName", encryptedDeviceName)
@ -1109,6 +1121,15 @@ public class SignalAccount implements Closeable {
save(); save();
} }
public ServiceEnvironment getServiceEnvironment() {
return serviceEnvironment;
}
public void setServiceEnvironment(final ServiceEnvironment serviceEnvironment) {
this.serviceEnvironment = serviceEnvironment;
save();
}
public ACI getAci() { public ACI getAci() {
return aci; return aci;
} }