From 5ee4b90c01f521df6ac2160de58e1329beb5c836 Mon Sep 17 00:00:00 2001 From: Adimarantis Date: Sun, 23 Apr 2023 21:41:28 +0200 Subject: [PATCH 1/6] Dbus Identities and Trust --- src/main/java/org/asamk/Signal.java | 42 ++++++ .../org/asamk/signal/dbus/DbusSignalImpl.java | 132 ++++++++++++++++++ 2 files changed, 174 insertions(+) diff --git a/src/main/java/org/asamk/Signal.java b/src/main/java/org/asamk/Signal.java index bc8bf74e47..9b5e3f4bfc 100644 --- a/src/main/java/org/asamk/Signal.java +++ b/src/main/java/org/asamk/Signal.java @@ -551,6 +551,48 @@ interface Group extends DBusInterface, Properties { void enableLink(boolean requiresApproval) throws Error.Failure; } + class StructIdentity extends Struct { + + @Position(0) + DBusPath objectPath; + + @Position(1) + String id; + + @Position(2) + String name; + + public StructIdentity(final DBusPath objectPath, final String id, final String name) { + this.objectPath = objectPath; + this.id = id; + this.name = name; + } + + public DBusPath getObjectPath() { + return objectPath; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + } + + @DBusProperty(name = "id", type = String.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "fingerprint", type = Byte[].class, access = DBusProperty.Access.READ) + @DBusProperty(name = "safetyNumber", type = String.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "trustLevel", type = String.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "addedDate", type = Integer.class, access = DBusProperty.Access.READ) + interface Identity extends DBusInterface, Properties { + + void trust(String number) throws Error.Failure; + + void trustWithKey(String number,String safetyNumber) throws Error.Failure; + } + interface Error { class AttachmentInvalid extends DBusExecutionException { diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index b1d648869e..dd764d55d3 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -11,6 +11,7 @@ import org.asamk.signal.manager.api.GroupNotFoundException; import org.asamk.signal.manager.api.GroupPermission; import org.asamk.signal.manager.api.GroupSendingNotAllowedException; +import org.asamk.signal.manager.api.Identity; import org.asamk.signal.manager.api.InactiveGroupLinkException; import org.asamk.signal.manager.api.InvalidDeviceLinkException; import org.asamk.signal.manager.api.InvalidNumberException; @@ -50,6 +51,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -58,6 +60,9 @@ import static org.asamk.signal.dbus.DbusUtils.makeValidObjectPathElement; +import org.asamk.signal.util.CommandUtil; +import org.asamk.signal.util.Hex; + public class DbusSignalImpl implements Signal { private final Manager m; @@ -68,6 +73,7 @@ public class DbusSignalImpl implements Signal { private DBusPath thisDevice; private final List devices = new ArrayList<>(); private final List groups = new ArrayList<>(); + private final List identities = new ArrayList<>(); private DbusReceiveMessageHandler dbusMessageHandler; private int subscriberCount; @@ -100,6 +106,7 @@ private void exportObjects() { updateDevices(); updateGroups(); updateConfiguration(); + updateIdentities(); } public void close() { @@ -114,6 +121,7 @@ private void unExportObjects() { unExportDevices(); unExportGroups(); unExportConfiguration(); + unExportIdentities(); connection.unExportObject(this.objectPath); } @@ -1029,6 +1037,130 @@ private void exportObject(final DBusInterface object) { } } + private void updateIdentities() { + List identities; + identities = m.getIdentities(); + + unExportIdentities(); + + identities.forEach(i -> { + final var object = new DbusSignalIdentityImpl(i); + exportObject(object); + this.identities.add(new StructIdentity(new DBusPath(object.getObjectPath()), + i.recipient().getLegacyIdentifier(), + emptyIfNull(i.recipient().getIdentifier()))); + }); + } + + private static String getIdentityObjectPath(String basePath, String id) { + return basePath + "/Identities/" + + id + .replace("+", "_") + .replace("/", "_") + .replace("=", "_"); + } + + private void unExportIdentities() { + this.identities.stream().map(StructIdentity::getObjectPath).map(DBusPath::getPath).forEach(connection::unExportObject); + this.identities.clear(); + } + + public class DbusSignalIdentityImpl extends DbusProperties implements Signal.Identity { + + private final org.asamk.signal.manager.api.Identity identity; + //private final org.asamk.signal.manager.api.Recipient recipient; + //private final org.asamk.signal.manager.storage.recipients.Contact contact; + //private final List rlist; + + public DbusSignalIdentityImpl(final org.asamk.signal.manager.api.Identity identity) { + this.identity=identity; + super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity", + List.of(new DbusProperty<>("id", () -> identity.recipient().getLegacyIdentifier()), + new DbusProperty<>("fingerprint", () -> identity.getFingerprint()), + new DbusProperty<>("safetyNumber", identity::safetyNumber), + new DbusProperty<>("trustLevel", identity::trustLevel), + new DbusProperty<>("addedDate", identity::dateAddedTimestamp) + ))); + } + + @Override + public String getObjectPath() { + return getIdentityObjectPath(objectPath, identity.recipient().getLegacyIdentifier()); + } + + @Override + public void trust(String number) throws Error.Failure { + trustWithKey(number,null); + }; + + @Override + public void trustWithKey(String number,String safetyNumber) throws Error.Failure { + try { + var recipient = CommandUtil.getSingleRecipientIdentifier(number, m.getSelfNumber()); + if (safetyNumber != null) { + safetyNumber = safetyNumber.replaceAll(" ", ""); + if (safetyNumber.length() == 66) { + byte[] fingerprintBytes; + try { + fingerprintBytes = Hex.toByteArray(safetyNumber.toLowerCase(Locale.ROOT)); + } catch (Exception e) { + throw new Error.Failure( + "Failed to parse the fingerprint, make sure the fingerprint is a correctly encoded hex string without additional characters."); + } + boolean res; + try { + res = m.trustIdentityVerified(recipient, fingerprintBytes); + } catch (UnregisteredRecipientException e) { + throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered."); + } + if (!res) { + throw new Error.Failure( + "Failed to set the trust for the fingerprint of this number, make sure the number and the fingerprint are correct."); + } + } else if (safetyNumber.length() == 60) { + boolean res; + try { + res = m.trustIdentityVerifiedSafetyNumber(recipient, safetyNumber); + } catch (UnregisteredRecipientException e) { + throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered."); + } + if (!res) { + throw new Error.Failure( + "Failed to set the trust for the safety number of this phone number, make sure the phone number and the safety number are correct."); + } + } else { + final byte[] scannableSafetyNumber; + try { + scannableSafetyNumber = Base64.getDecoder().decode(safetyNumber); + } catch (IllegalArgumentException e) { + throw new Error.Failure( + "Safety number has invalid format, either specify the old hex fingerprint or the new safety number"); + } + boolean res; + try { + res = m.trustIdentityVerifiedSafetyNumber(recipient, scannableSafetyNumber); + } catch (UnregisteredRecipientException e) { + throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered."); + } + if (!res) { + throw new Error.Failure( + "Failed to set the trust for the safety number of this phone number, make sure the phone number and the safety number are correct."); + } + } + } else { + try { + m.trustIdentityAllKeys(recipient); + } catch (Exception e) { + throw new Error.Failure( + "Unregistered recipient"); + } + } + } catch (Exception e) { + throw new Error.Failure(e.getMessage()); + } + } + } + public class DbusSignalDeviceImpl extends DbusProperties implements Signal.Device { private final org.asamk.signal.manager.api.Device device; From 6e19ae0231fdbf6122e07ed3f1afae62d9098e7a Mon Sep 17 00:00:00 2001 From: AsamK Date: Fri, 2 Jun 2023 21:29:58 +0200 Subject: [PATCH 2/6] Add helper method to create valid dbus object path --- src/main/java/org/asamk/Signal.java | 12 +- .../org/asamk/signal/dbus/DbusSignalImpl.java | 133 +++++++----------- 2 files changed, 63 insertions(+), 82 deletions(-) diff --git a/src/main/java/org/asamk/Signal.java b/src/main/java/org/asamk/Signal.java index 9b5e3f4bfc..22234c4b18 100644 --- a/src/main/java/org/asamk/Signal.java +++ b/src/main/java/org/asamk/Signal.java @@ -138,6 +138,10 @@ byte[] updateGroup( DBusPath getDevice(long deviceId); + public DBusPath getIdentity(String number); + + public List listIdentities(); + List listDevices() throws Error.Failure; DBusPath getThisDevice(); @@ -581,16 +585,18 @@ public String getName() { } } - @DBusProperty(name = "id", type = String.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "number", type = String.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "uuid", type = String.class, access = DBusProperty.Access.READ) @DBusProperty(name = "fingerprint", type = Byte[].class, access = DBusProperty.Access.READ) @DBusProperty(name = "safetyNumber", type = String.class, access = DBusProperty.Access.READ) @DBusProperty(name = "trustLevel", type = String.class, access = DBusProperty.Access.READ) @DBusProperty(name = "addedDate", type = Integer.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "scannableSafetyNumber", type = Byte[].class, access = DBusProperty.Access.READ) interface Identity extends DBusInterface, Properties { - void trust(String number) throws Error.Failure; + void trust() throws Error.Failure; - void trustWithKey(String number,String safetyNumber) throws Error.Failure; + void trustVerified(String safetyNumber) throws Error.Failure; } interface Error { diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index dd764d55d3..f9f98a2f47 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -11,7 +11,6 @@ import org.asamk.signal.manager.api.GroupNotFoundException; import org.asamk.signal.manager.api.GroupPermission; import org.asamk.signal.manager.api.GroupSendingNotAllowedException; -import org.asamk.signal.manager.api.Identity; import org.asamk.signal.manager.api.InactiveGroupLinkException; import org.asamk.signal.manager.api.InvalidDeviceLinkException; import org.asamk.signal.manager.api.InvalidNumberException; @@ -31,6 +30,7 @@ import org.asamk.signal.manager.api.UpdateGroup; import org.asamk.signal.manager.api.UpdateProfile; import org.asamk.signal.manager.api.UserStatus; +import org.asamk.signal.manager.api.IdentityVerificationCode; import org.asamk.signal.util.SendMessageResultUtils; import org.freedesktop.dbus.DBusPath; import org.freedesktop.dbus.connections.impl.DBusConnection; @@ -51,7 +51,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -60,9 +59,6 @@ import static org.asamk.signal.dbus.DbusUtils.makeValidObjectPathElement; -import org.asamk.signal.util.CommandUtil; -import org.asamk.signal.util.Hex; - public class DbusSignalImpl implements Signal { private final Manager m; @@ -1047,17 +1043,13 @@ private void updateIdentities() { final var object = new DbusSignalIdentityImpl(i); exportObject(object); this.identities.add(new StructIdentity(new DBusPath(object.getObjectPath()), - i.recipient().getLegacyIdentifier(), - emptyIfNull(i.recipient().getIdentifier()))); + emptyIfNull(i.recipient().getIdentifier()), + i.recipient().getLegacyIdentifier())); }); } private static String getIdentityObjectPath(String basePath, String id) { - return basePath + "/Identities/" + - id - .replace("+", "_") - .replace("/", "_") - .replace("=", "_"); + return basePath + "/Identities/" + makeValidObjectPathElement(id); } private void unExportIdentities() { @@ -1065,19 +1057,37 @@ private void unExportIdentities() { this.identities.clear(); } + @Override + public DBusPath getIdentity(String number) throws Error.Failure { + + final var found = identities.stream() + .filter(identity -> identity.getName().equals(number)) + .findFirst(); + + if (found.isEmpty()) { + throw new Error.Failure("Identity for " + number + " unkown"); + } + return found.get().getObjectPath(); + } + + @Override + public List listIdentities() { + updateIdentities(); + return this.identities; + } + public class DbusSignalIdentityImpl extends DbusProperties implements Signal.Identity { private final org.asamk.signal.manager.api.Identity identity; - //private final org.asamk.signal.manager.api.Recipient recipient; - //private final org.asamk.signal.manager.storage.recipients.Contact contact; - //private final List rlist; public DbusSignalIdentityImpl(final org.asamk.signal.manager.api.Identity identity) { this.identity=identity; super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity", - List.of(new DbusProperty<>("id", () -> identity.recipient().getLegacyIdentifier()), + List.of(new DbusProperty<>("number", () -> identity.recipient().getLegacyIdentifier()), + new DbusProperty<>("uuid", () -> identity.recipient().getIdentifier()), new DbusProperty<>("fingerprint", () -> identity.getFingerprint()), new DbusProperty<>("safetyNumber", identity::safetyNumber), + new DbusProperty<>("scannableSafetyNumber", identity::scannableSafetyNumber), new DbusProperty<>("trustLevel", identity::trustLevel), new DbusProperty<>("addedDate", identity::dateAddedTimestamp) ))); @@ -1089,74 +1099,39 @@ public String getObjectPath() { } @Override - public void trust(String number) throws Error.Failure { - trustWithKey(number,null); + public void trust() throws Error.Failure { + var recipient=RecipientIdentifier.Single.fromAddress(identity.recipient()); + try { + m.trustIdentityAllKeys(recipient); + } catch (UnregisteredRecipientException e) { + throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered."); + } }; @Override - public void trustWithKey(String number,String safetyNumber) throws Error.Failure { + public void trustVerified(String safetyNumber) throws Error.Failure { + var recipient = RecipientIdentifier.Single.fromAddress(identity.recipient()); + + if (safetyNumber == null) { + throw new Error.Failure( + "You need to specify a fingerprint/safety number"); + } + final IdentityVerificationCode verificationCode; try { - var recipient = CommandUtil.getSingleRecipientIdentifier(number, m.getSelfNumber()); - if (safetyNumber != null) { - safetyNumber = safetyNumber.replaceAll(" ", ""); - if (safetyNumber.length() == 66) { - byte[] fingerprintBytes; - try { - fingerprintBytes = Hex.toByteArray(safetyNumber.toLowerCase(Locale.ROOT)); - } catch (Exception e) { - throw new Error.Failure( - "Failed to parse the fingerprint, make sure the fingerprint is a correctly encoded hex string without additional characters."); - } - boolean res; - try { - res = m.trustIdentityVerified(recipient, fingerprintBytes); - } catch (UnregisteredRecipientException e) { - throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered."); - } - if (!res) { - throw new Error.Failure( - "Failed to set the trust for the fingerprint of this number, make sure the number and the fingerprint are correct."); - } - } else if (safetyNumber.length() == 60) { - boolean res; - try { - res = m.trustIdentityVerifiedSafetyNumber(recipient, safetyNumber); - } catch (UnregisteredRecipientException e) { - throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered."); - } - if (!res) { - throw new Error.Failure( - "Failed to set the trust for the safety number of this phone number, make sure the phone number and the safety number are correct."); - } - } else { - final byte[] scannableSafetyNumber; - try { - scannableSafetyNumber = Base64.getDecoder().decode(safetyNumber); - } catch (IllegalArgumentException e) { - throw new Error.Failure( - "Safety number has invalid format, either specify the old hex fingerprint or the new safety number"); - } - boolean res; - try { - res = m.trustIdentityVerifiedSafetyNumber(recipient, scannableSafetyNumber); - } catch (UnregisteredRecipientException e) { - throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered."); - } - if (!res) { - throw new Error.Failure( - "Failed to set the trust for the safety number of this phone number, make sure the phone number and the safety number are correct."); - } - } - } else { - try { - m.trustIdentityAllKeys(recipient); - } catch (Exception e) { - throw new Error.Failure( - "Unregistered recipient"); - } - } + verificationCode = IdentityVerificationCode.parse(safetyNumber); } catch (Exception e) { - throw new Error.Failure(e.getMessage()); + throw new Error.Failure( + "Safety number has invalid format, either specify the old hex fingerprint or the new safety number"); + } + + try { + final var res = m.trustIdentityVerified(recipient, verificationCode); + if (!res) { + throw new Error.Failure( + "Failed to set the trust for this number, make sure the number and the fingerprint/safety number are correct."); + } + } catch (UnregisteredRecipientException e) { + throw new Error.Failure("The user " + e.getSender().getIdentifier() + " is not registered."); } } } From bf3e944d193a1472b0f8554d77414df0fcc1602e Mon Sep 17 00:00:00 2001 From: Adimarantis Date: Mon, 5 Jun 2023 07:31:22 +0200 Subject: [PATCH 3/6] Update src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java Co-authored-by: Sebastian Scheibner --- src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index f9f98a2f47..0d189aef41 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -1083,8 +1083,8 @@ public class DbusSignalIdentityImpl extends DbusProperties implements Signal.Ide public DbusSignalIdentityImpl(final org.asamk.signal.manager.api.Identity identity) { this.identity=identity; super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity", - List.of(new DbusProperty<>("number", () -> identity.recipient().getLegacyIdentifier()), - new DbusProperty<>("uuid", () -> identity.recipient().getIdentifier()), + List.of(new DbusProperty<>("number", () -> identity.recipient().number().orElse("")), + new DbusProperty<>("uuid", () -> identity.recipient().uuid().map(UUID::toString).orElse("")), new DbusProperty<>("fingerprint", () -> identity.getFingerprint()), new DbusProperty<>("safetyNumber", identity::safetyNumber), new DbusProperty<>("scannableSafetyNumber", identity::scannableSafetyNumber), From 1bf4fd688b8244ba93744ef9d61b8bd3fc31a1f8 Mon Sep 17 00:00:00 2001 From: Adimarantis Date: Mon, 5 Jun 2023 08:48:52 +0200 Subject: [PATCH 4/6] PR feedback updates --- src/main/java/org/asamk/Signal.java | 10 +++++----- .../java/org/asamk/signal/dbus/DbusSignalImpl.java | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/asamk/Signal.java b/src/main/java/org/asamk/Signal.java index 22234c4b18..777ca62f65 100644 --- a/src/main/java/org/asamk/Signal.java +++ b/src/main/java/org/asamk/Signal.java @@ -561,14 +561,14 @@ class StructIdentity extends Struct { DBusPath objectPath; @Position(1) - String id; + String uuid; @Position(2) String name; - public StructIdentity(final DBusPath objectPath, final String id, final String name) { + public StructIdentity(final DBusPath objectPath, final String uuid, final String name) { this.objectPath = objectPath; - this.id = id; + this.uuid = uuid; this.name = name; } @@ -576,8 +576,8 @@ public DBusPath getObjectPath() { return objectPath; } - public String getId() { - return id; + public String getUuid() { + return uuid; } public String getName() { diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index 0d189aef41..4c0fb115c9 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -56,6 +56,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.UUID; import static org.asamk.signal.dbus.DbusUtils.makeValidObjectPathElement; From de32a7db2fed09da4d0a5203708ba9a14911a1e7 Mon Sep 17 00:00:00 2001 From: Adimarantis Date: Mon, 5 Jun 2023 09:16:21 +0200 Subject: [PATCH 5/6] Documentation and consistent case sensitivity --- man/signal-cli-dbus.5.adoc | 36 +++++++++++++++++++ src/main/java/org/asamk/Signal.java | 14 ++++---- .../org/asamk/signal/dbus/DbusSignalImpl.java | 16 ++++----- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/man/signal-cli-dbus.5.adoc b/man/signal-cli-dbus.5.adoc index 46b11734d2..a2df1674cc 100644 --- a/man/signal-cli-dbus.5.adoc +++ b/man/signal-cli-dbus.5.adoc @@ -531,6 +531,42 @@ removeDevice() -> <>:: Exceptions: Failure +=== Signal.Identity interface + +The following methods listen to the Identities object path, which is constructed as follows: + + + "/Identities/" + identity + +identity : Either the phone number of a contact with underscore (_) replacing plus (+) , or if not known its uuid + +Identities have the following (case-sensitive) properties: + +* Number (read-only) : Phone number of the contact +* Uuid (read-only) : Internal uuid representing the contact +* Fingerprint (read-only) : Byte array representing the fingerprint +* SafetyNumber (read-only) : String representation of the safety number used to verify trust +* TrustLevel (read-only) : Current trust level (UNSTRUSTED, TRUSTED_UNVERIFIED, TRUSTED_VERIFIED) +* AddedDate (read-only) : Long representing the number of milliseconds since the Unix epoch +* ScannableSafetyNumber (read-only) : Byte array representation of the safety number + +To get a property, use (replacing `--session` with `--system` if needed): +`dbus-send --session --dest=org.asamk.Signal --print-reply $OBJECT_PATH org.freedesktop.DBus.Properties.Get string:org.asamk.Signal.Identity string:$PROPERTY_NAME` + +To get all properties, use: +`dbus-send --session --dest=org.asamk.Signal --print-reply $OBJECT_PATH org.freedesktop.DBus.Properties.GetAll string:org.asamk.Signal.Identity` + +trust() -> <>:: + +Establish trust with the given identity. TrustLevel will become TRUSTED_UNVERFIED + +Exceptions: Failure + +trustVerified(SafetyNumber) -> <>:: + +Establish trust with the given identity using their safety number. TrustLevel will become TRUSTED_VERIFIED + +Exceptions: Failure + === Signal.Configuration interface The configuration's object path, which exists only for primary devices, is constructed as follows: diff --git a/src/main/java/org/asamk/Signal.java b/src/main/java/org/asamk/Signal.java index 777ca62f65..2ca23dfbc8 100644 --- a/src/main/java/org/asamk/Signal.java +++ b/src/main/java/org/asamk/Signal.java @@ -585,13 +585,13 @@ public String getName() { } } - @DBusProperty(name = "number", type = String.class, access = DBusProperty.Access.READ) - @DBusProperty(name = "uuid", type = String.class, access = DBusProperty.Access.READ) - @DBusProperty(name = "fingerprint", type = Byte[].class, access = DBusProperty.Access.READ) - @DBusProperty(name = "safetyNumber", type = String.class, access = DBusProperty.Access.READ) - @DBusProperty(name = "trustLevel", type = String.class, access = DBusProperty.Access.READ) - @DBusProperty(name = "addedDate", type = Integer.class, access = DBusProperty.Access.READ) - @DBusProperty(name = "scannableSafetyNumber", type = Byte[].class, access = DBusProperty.Access.READ) + @DBusProperty(name = "Number", type = String.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "Uuid", type = String.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "Fingerprint", type = Byte[].class, access = DBusProperty.Access.READ) + @DBusProperty(name = "SafetyNumber", type = String.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "TrustLevel", type = String.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "AddedDate", type = Integer.class, access = DBusProperty.Access.READ) + @DBusProperty(name = "ScannableSafetyNumber", type = Byte[].class, access = DBusProperty.Access.READ) interface Identity extends DBusInterface, Properties { void trust() throws Error.Failure; diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index 4c0fb115c9..6a44ff979c 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -1045,7 +1045,7 @@ private void updateIdentities() { exportObject(object); this.identities.add(new StructIdentity(new DBusPath(object.getObjectPath()), emptyIfNull(i.recipient().getIdentifier()), - i.recipient().getLegacyIdentifier())); + i.recipient().getLegacyIdentifier())); }); } @@ -1084,13 +1084,13 @@ public class DbusSignalIdentityImpl extends DbusProperties implements Signal.Ide public DbusSignalIdentityImpl(final org.asamk.signal.manager.api.Identity identity) { this.identity=identity; super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Identity", - List.of(new DbusProperty<>("number", () -> identity.recipient().number().orElse("")), - new DbusProperty<>("uuid", () -> identity.recipient().uuid().map(UUID::toString).orElse("")), - new DbusProperty<>("fingerprint", () -> identity.getFingerprint()), - new DbusProperty<>("safetyNumber", identity::safetyNumber), - new DbusProperty<>("scannableSafetyNumber", identity::scannableSafetyNumber), - new DbusProperty<>("trustLevel", identity::trustLevel), - new DbusProperty<>("addedDate", identity::dateAddedTimestamp) + List.of(new DbusProperty<>("Number", () -> identity.recipient().number().orElse("")), + new DbusProperty<>("Uuid", () -> identity.recipient().uuid().map(UUID::toString).orElse("")), + new DbusProperty<>("Fingerprint", () -> identity.getFingerprint()), + new DbusProperty<>("SafetyNumber", identity::safetyNumber), + new DbusProperty<>("ScannableSafetyNumber", identity::scannableSafetyNumber), + new DbusProperty<>("TrustLevel", identity::trustLevel), + new DbusProperty<>("AddedDate", identity::dateAddedTimestamp) ))); } From eca3fc811d06b5b8ea364ff173b6cf635c333f72 Mon Sep 17 00:00:00 2001 From: Adimarantis Date: Mon, 5 Jun 2023 11:25:25 +0200 Subject: [PATCH 6/6] doc for listIdentities and getIdentity --- man/signal-cli-dbus.5.adoc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/man/signal-cli-dbus.5.adoc b/man/signal-cli-dbus.5.adoc index a2df1674cc..0f11ef9d4c 100644 --- a/man/signal-cli-dbus.5.adoc +++ b/man/signal-cli-dbus.5.adoc @@ -416,6 +416,24 @@ Only works if sent from a secondary device. Exceptions: Failure +==== Identity related methods + +listIdentities() -> identities:: +* identities : Array of structs (objectPath, id, name) +** objectPath : DBusPath representing the identity object path +** uuid : Internal uuid of the identity +** number : Phone number of the identity (or uuid if not known) + +Lists all know identities + +getIdentity(Number) -> identityPath:: +* Number : Phone number +* identityPath : DBusPath object for the identity + +Gets the identity Dbus path for a given phone number + +Exceptions: Failure + === Signal.Group interface The following methods listen to the group's object path, which can be obtained from the listGroups() method and is constructed as follows: