Add possibility to update the device name

This commit is contained in:
AsamK 2021-09-05 11:41:38 +02:00
parent 5a2e37a6e2
commit 299671480f
5 changed files with 24 additions and 6 deletions

View file

@ -10,6 +10,7 @@
### 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

View file

@ -311,7 +311,7 @@ public class Manager implements Closeable {
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()
.setAccountAttributes(account.getEncryptedDeviceName(),
.setAccountAttributes(encryptedDeviceName,
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(),

View file

@ -818,6 +818,11 @@ public class SignalAccount implements Closeable {
return encryptedDeviceName;
}
public void setEncryptedDeviceName(final String encryptedDeviceName) {
this.encryptedDeviceName = encryptedDeviceName;
save();
}
public int getDeviceId() {
return deviceId;
}

View 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.
*-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.

View 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.");
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 {
var deviceName = ns.getString("device-name");
try {
m.updateAccountAttributes();
m.updateAccountAttributes(deviceName);
} catch (IOException e) {
throw new IOErrorException("UpdateAccount error: " + e.getMessage());
}