Canonicalize number when listing identities

This commit is contained in:
AsamK 2020-01-21 22:09:21 +01:00
parent cfd1e5544d
commit 7f9379f78b
2 changed files with 13 additions and 4 deletions

View file

@ -7,6 +7,8 @@ import org.asamk.signal.manager.Manager;
import org.asamk.signal.storage.protocol.JsonIdentityKeyStore; import org.asamk.signal.storage.protocol.JsonIdentityKeyStore;
import org.asamk.signal.util.Hex; import org.asamk.signal.util.Hex;
import org.asamk.signal.util.Util; import org.asamk.signal.util.Util;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -39,8 +41,13 @@ public class ListIdentitiesCommand implements LocalCommand {
} }
} else { } else {
String number = ns.getString("number"); String number = ns.getString("number");
for (JsonIdentityKeyStore.Identity id : m.getIdentities(number)) { try {
printIdentityFingerprint(m, number, id); Pair<String, List<JsonIdentityKeyStore.Identity>> key = m.getIdentities(number);
for (JsonIdentityKeyStore.Identity id : key.second()) {
printIdentityFingerprint(m, key.first(), id);
}
} catch (InvalidNumberException e) {
System.out.println("Invalid number: " + e.getMessage());
} }
} }
return 0; return 0;

View file

@ -53,6 +53,7 @@ import org.whispersystems.libsignal.state.PreKeyRecord;
import org.whispersystems.libsignal.state.SignedPreKeyRecord; import org.whispersystems.libsignal.state.SignedPreKeyRecord;
import org.whispersystems.libsignal.util.KeyHelper; import org.whispersystems.libsignal.util.KeyHelper;
import org.whispersystems.libsignal.util.Medium; import org.whispersystems.libsignal.util.Medium;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalServiceAccountManager; import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.SignalServiceMessagePipe; import org.whispersystems.signalservice.api.SignalServiceMessagePipe;
@ -1545,8 +1546,9 @@ public class Manager implements Signal {
return account.getSignalProtocolStore().getIdentities(); return account.getSignalProtocolStore().getIdentities();
} }
public List<JsonIdentityKeyStore.Identity> getIdentities(String number) { public Pair<String, List<JsonIdentityKeyStore.Identity>> getIdentities(String number) throws InvalidNumberException {
return account.getSignalProtocolStore().getIdentities(number); String canonicalizedNumber = Utils.canonicalizeNumber(number, username);
return new Pair<>(canonicalizedNumber, account.getSignalProtocolStore().getIdentities(canonicalizedNumber));
} }
/** /**