mirror of
https://github.com/aljazceru/signal-cli.git
synced 2025-12-26 10:34:23 +01:00
Set uuid after verify and linking and request it at startup for existing clients
This commit is contained in:
@@ -137,6 +137,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.zip.ZipEntry;
|
||||
@@ -176,7 +177,7 @@ public class Manager implements Signal {
|
||||
}
|
||||
|
||||
private SignalServiceAccountManager getSignalServiceAccountManager() {
|
||||
return new SignalServiceAccountManager(BaseConfig.serviceConfiguration, null, account.getUsername(), account.getPassword(), account.getDeviceId(), BaseConfig.USER_AGENT, timer);
|
||||
return new SignalServiceAccountManager(BaseConfig.serviceConfiguration, account.getUuid(), account.getUsername(), account.getPassword(), account.getDeviceId(), BaseConfig.USER_AGENT, timer);
|
||||
}
|
||||
|
||||
private IdentityKey getIdentity() {
|
||||
@@ -215,9 +216,15 @@ public class Manager implements Signal {
|
||||
|
||||
accountManager = getSignalServiceAccountManager();
|
||||
try {
|
||||
if (account.isRegistered() && accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) {
|
||||
refreshPreKeys();
|
||||
account.save();
|
||||
if (account.isRegistered()) {
|
||||
if (accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) {
|
||||
refreshPreKeys();
|
||||
account.save();
|
||||
}
|
||||
if (account.getUuid() == null) {
|
||||
account.setUuid(accountManager.getOwnUuid());
|
||||
account.save();
|
||||
}
|
||||
}
|
||||
} catch (AuthorizationFailedException e) {
|
||||
System.err.println("Authorization failed, was the number registered elsewhere?");
|
||||
@@ -345,7 +352,7 @@ public class Manager implements Signal {
|
||||
throw new IOException("Received invalid profileKey", e);
|
||||
}
|
||||
}
|
||||
account = SignalAccount.createLinkedAccount(dataPath, username, account.getPassword(), ret.getDeviceId(), ret.getIdentity(), account.getSignalProtocolStore().getLocalRegistrationId(), account.getSignalingKey(), profileKey);
|
||||
account = SignalAccount.createLinkedAccount(dataPath, username, ret.getUuid(), account.getPassword(), ret.getDeviceId(), ret.getIdentity(), account.getSignalProtocolStore().getLocalRegistrationId(), account.getSignalingKey(), profileKey);
|
||||
|
||||
refreshPreKeys();
|
||||
|
||||
@@ -423,10 +430,11 @@ public class Manager implements Signal {
|
||||
verificationCode = verificationCode.replace("-", "");
|
||||
account.setSignalingKey(KeyUtils.createSignalingKey());
|
||||
// TODO make unrestricted unidentified access configurable
|
||||
accountManager.verifyAccountWithCode(verificationCode, account.getSignalingKey(), account.getSignalProtocolStore().getLocalRegistrationId(), true, pin, null, getSelfUnidentifiedAccessKey(), false, capabilities);
|
||||
UUID uuid = accountManager.verifyAccountWithCode(verificationCode, account.getSignalingKey(), account.getSignalProtocolStore().getLocalRegistrationId(), true, pin, null, getSelfUnidentifiedAccessKey(), false, capabilities);
|
||||
|
||||
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
|
||||
account.setRegistered(true);
|
||||
account.setUuid(uuid);
|
||||
account.setRegistrationLockPin(pin);
|
||||
|
||||
refreshPreKeys();
|
||||
|
||||
@@ -92,13 +92,14 @@ public class SignalAccount {
|
||||
return account;
|
||||
}
|
||||
|
||||
public static SignalAccount createLinkedAccount(String dataPath, String username, String password, int deviceId, IdentityKeyPair identityKey, int registrationId, String signalingKey, ProfileKey profileKey) throws IOException {
|
||||
public static SignalAccount createLinkedAccount(String dataPath, String username, UUID uuid, String password, int deviceId, IdentityKeyPair identityKey, int registrationId, String signalingKey, ProfileKey profileKey) throws IOException {
|
||||
IOUtils.createPrivateDirectories(dataPath);
|
||||
|
||||
SignalAccount account = new SignalAccount();
|
||||
account.openFileChannel(getFileName(dataPath, username));
|
||||
|
||||
account.username = username;
|
||||
account.uuid = uuid;
|
||||
account.password = password;
|
||||
account.profileKey = profileKey;
|
||||
account.deviceId = deviceId;
|
||||
@@ -140,6 +141,14 @@ public class SignalAccount {
|
||||
rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
|
||||
}
|
||||
|
||||
JsonNode uuidNode = rootNode.get("uuid");
|
||||
if (uuidNode != null && !uuidNode.isNull()) {
|
||||
try {
|
||||
uuid = UUID.fromString(uuidNode.asText());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IOException("Config file contains an invalid uuid, needs to be a valid UUID", e);
|
||||
}
|
||||
}
|
||||
JsonNode node = rootNode.get("deviceId");
|
||||
if (node != null) {
|
||||
deviceId = node.asInt();
|
||||
@@ -218,6 +227,7 @@ public class SignalAccount {
|
||||
}
|
||||
ObjectNode rootNode = jsonProcessor.createObjectNode();
|
||||
rootNode.put("username", username)
|
||||
.put("uuid", uuid == null ? null : uuid.toString())
|
||||
.put("deviceId", deviceId)
|
||||
.put("isMultiDevice", isMultiDevice)
|
||||
.put("password", password)
|
||||
@@ -292,6 +302,10 @@ public class SignalAccount {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(final UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public SignalServiceAddress getSelfAddress() {
|
||||
return new SignalServiceAddress(uuid, username);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user