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 ### Added
- New global parameter `--trust-new-identities=always` to allow trusting any new identity key without verification - 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 ## [0.8.5] - 2021-08-07
### Added ### Added

View file

@ -311,7 +311,7 @@ public class Manager implements Closeable {
if (account.getUuid() == null) { if (account.getUuid() == null) {
account.setUuid(dependencies.getAccountManager().getOwnUuid()); 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, null,
account.getLocalRegistrationId(), account.getLocalRegistrationId(),
true, true,
// set legacy pin only if no KBS master key is set null,
account.getPinMasterKey() == null ? account.getRegistrationLockPin() : null,
account.getPinMasterKey() == null ? null : account.getPinMasterKey().deriveRegistrationLock(), account.getPinMasterKey() == null ? null : account.getPinMasterKey().deriveRegistrationLock(),
account.getSelfUnidentifiedAccessKey(), account.getSelfUnidentifiedAccessKey(),
account.isUnrestrictedUnidentifiedAccess(), account.isUnrestrictedUnidentifiedAccess(),

View 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() { public int getDeviceId() {
return deviceId; 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. Update the account attributes on the signal server.
Can fix problems with receiving messages. Can fix problems with receiving messages.
*-n* NAME, *--device-name* NAME::
Set a new device name for the main or linked device
=== setPin === setPin
Set a registration lock pin, to prevent others from registering this number. Set a registration lock pin, to prevent others from registering this number.

View file

@ -20,14 +20,16 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
@Override @Override
public void attachToSubparser(final Subparser subparser) { public void attachToSubparser(final Subparser subparser) {
subparser.help("Update the account attributes on the signal server."); subparser.help("Update the account attributes on the signal server.");
subparser.addArgument("-n", "--device-name").help("Specify a name to describe this device.");
} }
@Override @Override
public void handleCommand( public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException { ) throws CommandException {
var deviceName = ns.getString("device-name");
try { try {
m.updateAccountAttributes(); m.updateAccountAttributes(deviceName);
} catch (IOException e) { } catch (IOException e) {
throw new IOErrorException("UpdateAccount error: " + e.getMessage()); throw new IOErrorException("UpdateAccount error: " + e.getMessage());
} }