]> nmode's Git Repositories - signal-cli/commitdiff
Add possibility to update the device name
authorAsamK <asamk@gmx.de>
Sun, 5 Sep 2021 09:41:38 +0000 (11:41 +0200)
committerAsamK <asamk@gmx.de>
Sun, 5 Sep 2021 09:41:38 +0000 (11:41 +0200)
CHANGELOG.md
lib/src/main/java/org/asamk/signal/manager/Manager.java
lib/src/main/java/org/asamk/signal/manager/storage/SignalAccount.java
man/signal-cli.1.adoc
src/main/java/org/asamk/signal/commands/UpdateAccountCommand.java

index e2ba6843061378dd7f2d71d61333b493e74566af..fa27507d0dd87960a164e43f1d4ae78ecc6cf3d9 100644 (file)
@@ -10,6 +10,7 @@
 
 ### Added
 - New global parameter `--trust-new-identities=always` to allow trusting any new identity key without verification
 
 ### Added
 - New global parameter `--trust-new-identities=always` to allow trusting any new identity key without verification
+- New parameter `--device-name` for `updateAccount` command to update the device name
 
 ## [0.8.5] - 2021-08-07
 ### Added
 
 ## [0.8.5] - 2021-08-07
 ### Added
index c4c77b3453c4a2764a9ecc03e17da4afd1b674ec..366fb371c41e2643b1fa59633fc4b09e2dc1be4e 100644 (file)
@@ -311,7 +311,7 @@ public class Manager implements Closeable {
         if (account.getUuid() == null) {
             account.setUuid(dependencies.getAccountManager().getOwnUuid());
         }
         if (account.getUuid() == null) {
             account.setUuid(dependencies.getAccountManager().getOwnUuid());
         }
-        updateAccountAttributes();
+        updateAccountAttributes(null);
     }
 
     /**
     }
 
     /**
@@ -343,14 +343,21 @@ public class Manager implements Closeable {
         }));
     }
 
         }));
     }
 
-    public void updateAccountAttributes() throws IOException {
+    public void updateAccountAttributes(String deviceName) throws IOException {
+        final String encryptedDeviceName;
+        if (deviceName == null) {
+            encryptedDeviceName = account.getEncryptedDeviceName();
+        } else {
+            final var privateKey = account.getIdentityKeyPair().getPrivateKey();
+            encryptedDeviceName = DeviceNameUtil.encryptDeviceName(deviceName, privateKey);
+            account.setEncryptedDeviceName(encryptedDeviceName);
+        }
         dependencies.getAccountManager()
         dependencies.getAccountManager()
-                .setAccountAttributes(account.getEncryptedDeviceName(),
+                .setAccountAttributes(encryptedDeviceName,
                         null,
                         account.getLocalRegistrationId(),
                         true,
                         null,
                         account.getLocalRegistrationId(),
                         true,
-                        // set legacy pin only if no KBS master key is set
-                        account.getPinMasterKey() == null ? account.getRegistrationLockPin() : null,
+                        null,
                         account.getPinMasterKey() == null ? null : account.getPinMasterKey().deriveRegistrationLock(),
                         account.getSelfUnidentifiedAccessKey(),
                         account.isUnrestrictedUnidentifiedAccess(),
                         account.getPinMasterKey() == null ? null : account.getPinMasterKey().deriveRegistrationLock(),
                         account.getSelfUnidentifiedAccessKey(),
                         account.isUnrestrictedUnidentifiedAccess(),
index e75996c51cd57f0087171cf6fc2067f561b67843..efdcf79813735f95cf4d8b681a0fdb83b7837cd8 100644 (file)
@@ -818,6 +818,11 @@ public class SignalAccount implements Closeable {
         return encryptedDeviceName;
     }
 
         return encryptedDeviceName;
     }
 
+    public void setEncryptedDeviceName(final String encryptedDeviceName) {
+        this.encryptedDeviceName = encryptedDeviceName;
+        save();
+    }
+
     public int getDeviceId() {
         return deviceId;
     }
     public int getDeviceId() {
         return deviceId;
     }
index b8251eb1053cf04b26b48ebdfccdc45f80ede28e..b52612beb3d0980db8de5a97e00e74194406648d 100644 (file)
@@ -110,6 +110,9 @@ CAUTION: Only delete your account if you won't use this number again!
 Update the account attributes on the signal server.
 Can fix problems with receiving messages.
 
 Update the account attributes on the signal server.
 Can fix problems with receiving messages.
 
+*-n* NAME, *--device-name* NAME::
+Set a new device name for the main or linked device
+
 === setPin
 
 Set a registration lock pin, to prevent others from registering this number.
 === setPin
 
 Set a registration lock pin, to prevent others from registering this number.
index f2ed6a98dfb47b59e71aa72ead17870296a7a277..600a38c4c85d6a86d16c17185add9fcaaab23ed4 100644 (file)
@@ -20,14 +20,16 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
     @Override
     public void attachToSubparser(final Subparser subparser) {
         subparser.help("Update the account attributes on the signal server.");
     @Override
     public void attachToSubparser(final Subparser subparser) {
         subparser.help("Update the account attributes on the signal server.");
+        subparser.addArgument("-n", "--device-name").help("Specify a name to describe this device.");
     }
 
     @Override
     public void handleCommand(
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
     }
 
     @Override
     public void handleCommand(
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
+        var deviceName = ns.getString("device-name");
         try {
         try {
-            m.updateAccountAttributes();
+            m.updateAccountAttributes(deviceName);
         } catch (IOException e) {
             throw new IOErrorException("UpdateAccount error: " + e.getMessage());
         }
         } catch (IOException e) {
             throw new IOErrorException("UpdateAccount error: " + e.getMessage());
         }