mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Set uuid after verify and linking and request it at startup for existing clients
This commit is contained in:
parent
1b56485fc8
commit
6665dc0e48
3 changed files with 30 additions and 8 deletions
|
@ -20,7 +20,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.github.turasa:signal-service-java:2.15.3_unofficial_4'
|
compile 'com.github.turasa:signal-service-java:2.15.3_unofficial_5'
|
||||||
compile 'org.bouncycastle:bcprov-jdk15on:1.64'
|
compile 'org.bouncycastle:bcprov-jdk15on:1.64'
|
||||||
compile 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
compile 'net.sourceforge.argparse4j:argparse4j:0.8.1'
|
||||||
compile 'org.freedesktop.dbus:dbus-java:2.7.0'
|
compile 'org.freedesktop.dbus:dbus-java:2.7.0'
|
||||||
|
|
|
@ -137,6 +137,7 @@ import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
@ -176,7 +177,7 @@ public class Manager implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignalServiceAccountManager getSignalServiceAccountManager() {
|
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() {
|
private IdentityKey getIdentity() {
|
||||||
|
@ -215,10 +216,16 @@ public class Manager implements Signal {
|
||||||
|
|
||||||
accountManager = getSignalServiceAccountManager();
|
accountManager = getSignalServiceAccountManager();
|
||||||
try {
|
try {
|
||||||
if (account.isRegistered() && accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) {
|
if (account.isRegistered()) {
|
||||||
|
if (accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) {
|
||||||
refreshPreKeys();
|
refreshPreKeys();
|
||||||
account.save();
|
account.save();
|
||||||
}
|
}
|
||||||
|
if (account.getUuid() == null) {
|
||||||
|
account.setUuid(accountManager.getOwnUuid());
|
||||||
|
account.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (AuthorizationFailedException e) {
|
} catch (AuthorizationFailedException e) {
|
||||||
System.err.println("Authorization failed, was the number registered elsewhere?");
|
System.err.println("Authorization failed, was the number registered elsewhere?");
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -345,7 +352,7 @@ public class Manager implements Signal {
|
||||||
throw new IOException("Received invalid profileKey", e);
|
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();
|
refreshPreKeys();
|
||||||
|
|
||||||
|
@ -423,10 +430,11 @@ public class Manager implements Signal {
|
||||||
verificationCode = verificationCode.replace("-", "");
|
verificationCode = verificationCode.replace("-", "");
|
||||||
account.setSignalingKey(KeyUtils.createSignalingKey());
|
account.setSignalingKey(KeyUtils.createSignalingKey());
|
||||||
// TODO make unrestricted unidentified access configurable
|
// 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)));
|
//accountManager.setGcmId(Optional.of(GoogleCloudMessaging.getInstance(this).register(REGISTRATION_ID)));
|
||||||
account.setRegistered(true);
|
account.setRegistered(true);
|
||||||
|
account.setUuid(uuid);
|
||||||
account.setRegistrationLockPin(pin);
|
account.setRegistrationLockPin(pin);
|
||||||
|
|
||||||
refreshPreKeys();
|
refreshPreKeys();
|
||||||
|
|
|
@ -92,13 +92,14 @@ public class SignalAccount {
|
||||||
return account;
|
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);
|
IOUtils.createPrivateDirectories(dataPath);
|
||||||
|
|
||||||
SignalAccount account = new SignalAccount();
|
SignalAccount account = new SignalAccount();
|
||||||
account.openFileChannel(getFileName(dataPath, username));
|
account.openFileChannel(getFileName(dataPath, username));
|
||||||
|
|
||||||
account.username = username;
|
account.username = username;
|
||||||
|
account.uuid = uuid;
|
||||||
account.password = password;
|
account.password = password;
|
||||||
account.profileKey = profileKey;
|
account.profileKey = profileKey;
|
||||||
account.deviceId = deviceId;
|
account.deviceId = deviceId;
|
||||||
|
@ -140,6 +141,14 @@ public class SignalAccount {
|
||||||
rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
|
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");
|
JsonNode node = rootNode.get("deviceId");
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
deviceId = node.asInt();
|
deviceId = node.asInt();
|
||||||
|
@ -218,6 +227,7 @@ public class SignalAccount {
|
||||||
}
|
}
|
||||||
ObjectNode rootNode = jsonProcessor.createObjectNode();
|
ObjectNode rootNode = jsonProcessor.createObjectNode();
|
||||||
rootNode.put("username", username)
|
rootNode.put("username", username)
|
||||||
|
.put("uuid", uuid == null ? null : uuid.toString())
|
||||||
.put("deviceId", deviceId)
|
.put("deviceId", deviceId)
|
||||||
.put("isMultiDevice", isMultiDevice)
|
.put("isMultiDevice", isMultiDevice)
|
||||||
.put("password", password)
|
.put("password", password)
|
||||||
|
@ -292,6 +302,10 @@ public class SignalAccount {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUuid(final UUID uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public SignalServiceAddress getSelfAddress() {
|
public SignalServiceAddress getSelfAddress() {
|
||||||
return new SignalServiceAddress(uuid, username);
|
return new SignalServiceAddress(uuid, username);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue