]> nmode's Git Repositories - signal-cli/commitdiff
Set uuid after verify and linking and request it at startup for existing clients
authorAsamK <asamk@gmx.de>
Mon, 23 Mar 2020 20:56:51 +0000 (21:56 +0100)
committerAsamK <asamk@gmx.de>
Tue, 24 Mar 2020 13:36:12 +0000 (14:36 +0100)
build.gradle
src/main/java/org/asamk/signal/manager/Manager.java
src/main/java/org/asamk/signal/storage/SignalAccount.java

index 558206775598a8dfcc5c4c753b67451bc4f7e53a..1b88f353a70c73c823e049ad58e2cd7cef898a6e 100644 (file)
@@ -20,7 +20,7 @@ repositories {
 }
 
 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 'net.sourceforge.argparse4j:argparse4j:0.8.1'
     compile 'org.freedesktop.dbus:dbus-java:2.7.0'
index 9ff1540ec471a92b685330ca555c39c0528313ce..0aada70364fa2802448136be4e12cfdd40886dae 100644 (file)
@@ -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();
index 6d83f78f999933ac19d498d802adb64e0ea74bd5..ebf7a8463e0283b1feafab484aab45797f3cb5a2 100644 (file)
@@ -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);
     }