import org.asamk.signal.manager.api.SendGroupMessageResults;
import org.asamk.signal.manager.api.SendMessageResults;
import org.asamk.signal.manager.api.TypingAction;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.config.ServiceConfig;
import org.asamk.signal.manager.config.ServiceEnvironment;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
-import java.util.concurrent.TimeUnit;
public interface Manager extends Closeable {
void setRegistrationLockPin(Optional<String> pin) throws IOException;
- Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws IOException;
+ Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException;
List<Group> getGroups();
SendGroupMessageResults quitGroup(
GroupId groupId, Set<RecipientIdentifier.Single> groupAdmins
- ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException;
+ ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException, UnregisteredRecipientException;
void deleteGroup(GroupId groupId) throws IOException;
Pair<GroupId, SendGroupMessageResults> createGroup(
String name, Set<RecipientIdentifier.Single> members, File avatarFile
- ) throws IOException, AttachmentInvalidException;
+ ) throws IOException, AttachmentInvalidException, UnregisteredRecipientException;
SendGroupMessageResults updateGroup(
final GroupId groupId, final UpdateGroup updateGroup
- ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException;
+ ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException, UnregisteredRecipientException;
Pair<GroupId, SendGroupMessageResults> joinGroup(
GroupInviteLinkUrl inviteLinkUrl
SendMessageResults sendMessage(
Message message, Set<RecipientIdentifier> recipients
- ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
+ ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException;
SendMessageResults sendRemoteDeleteMessage(
long targetSentTimestamp, Set<RecipientIdentifier> recipients
RecipientIdentifier.Single targetAuthor,
long targetSentTimestamp,
Set<RecipientIdentifier> recipients
- ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
+ ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException;
SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
- void deleteRecipient(RecipientIdentifier.Single recipient) throws IOException;
+ void deleteRecipient(RecipientIdentifier.Single recipient);
- void deleteContact(RecipientIdentifier.Single recipient) throws IOException;
+ void deleteContact(RecipientIdentifier.Single recipient);
void setContactName(
RecipientIdentifier.Single recipient, String name
- ) throws NotMasterDeviceException, IOException;
+ ) throws NotMasterDeviceException, IOException, UnregisteredRecipientException;
void setContactBlocked(
RecipientIdentifier.Single recipient, boolean blocked
- ) throws NotMasterDeviceException, IOException;
+ ) throws NotMasterDeviceException, IOException, UnregisteredRecipientException;
void setGroupBlocked(
GroupId groupId, boolean blocked
void setExpirationTimer(
RecipientIdentifier.Single recipient, int messageExpirationTimer
- ) throws IOException;
+ ) throws IOException, UnregisteredRecipientException;
URI uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
List<Identity> getIdentities(RecipientIdentifier.Single recipient);
- boolean trustIdentityVerified(RecipientIdentifier.Single recipient, byte[] fingerprint);
+ boolean trustIdentityVerified(
+ RecipientIdentifier.Single recipient, byte[] fingerprint
+ ) throws UnregisteredRecipientException;
- boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, String safetyNumber);
+ boolean trustIdentityVerifiedSafetyNumber(
+ RecipientIdentifier.Single recipient, String safetyNumber
+ ) throws UnregisteredRecipientException;
- boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, byte[] safetyNumber);
+ boolean trustIdentityVerifiedSafetyNumber(
+ RecipientIdentifier.Single recipient, byte[] safetyNumber
+ ) throws UnregisteredRecipientException;
- boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient);
+ boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) throws UnregisteredRecipientException;
void addClosedListener(Runnable listener);
import org.asamk.signal.manager.api.SendMessageResult;
import org.asamk.signal.manager.api.SendMessageResults;
import org.asamk.signal.manager.api.TypingAction;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
import org.asamk.signal.manager.groups.GroupId;
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage;
import org.whispersystems.signalservice.api.push.ACI;
-import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException;
import org.whispersystems.signalservice.api.util.DeviceNameUtil;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
}
@Override
- public Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws IOException {
+ public Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException {
return profileHelper.getRecipientProfile(recipientHelper.resolveRecipient(recipient));
}
@Override
public SendGroupMessageResults quitGroup(
GroupId groupId, Set<RecipientIdentifier.Single> groupAdmins
- ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException {
+ ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException, UnregisteredRecipientException {
final var newAdmins = recipientHelper.resolveRecipients(groupAdmins);
return groupHelper.quitGroup(groupId, newAdmins);
}
@Override
public Pair<GroupId, SendGroupMessageResults> createGroup(
String name, Set<RecipientIdentifier.Single> members, File avatarFile
- ) throws IOException, AttachmentInvalidException {
+ ) throws IOException, AttachmentInvalidException, UnregisteredRecipientException {
return groupHelper.createGroup(name,
members == null ? null : recipientHelper.resolveRecipients(members),
avatarFile);
@Override
public SendGroupMessageResults updateGroup(
final GroupId groupId, final UpdateGroup updateGroup
- ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException {
+ ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException, UnregisteredRecipientException {
return groupHelper.updateGroup(groupId,
updateGroup.getName(),
updateGroup.getDescription(),
messageBuilder.withTimestamp(timestamp);
for (final var recipient : recipients) {
if (recipient instanceof RecipientIdentifier.Single single) {
- final var recipientId = recipientHelper.resolveRecipient(single);
- final var result = sendHelper.sendMessage(messageBuilder, recipientId);
- results.put(recipient,
- List.of(SendMessageResult.from(result,
- account.getRecipientStore(),
- account.getRecipientStore()::resolveRecipientAddress)));
+ try {
+ final var recipientId = recipientHelper.resolveRecipient(single);
+ final var result = sendHelper.sendMessage(messageBuilder, recipientId);
+ results.put(recipient,
+ List.of(SendMessageResult.from(result,
+ account.getRecipientStore(),
+ account.getRecipientStore()::resolveRecipientAddress)));
+ } catch (UnregisteredRecipientException e) {
+ results.put(recipient,
+ List.of(SendMessageResult.unregisteredFailure(single.toPartialRecipientAddress())));
+ }
} else if (recipient instanceof RecipientIdentifier.NoteToSelf) {
final var result = sendHelper.sendSelfMessage(messageBuilder);
results.put(recipient,
var results = new HashMap<RecipientIdentifier, List<SendMessageResult>>();
final var timestamp = System.currentTimeMillis();
for (var recipient : recipients) {
- if (recipient instanceof RecipientIdentifier.Single) {
+ if (recipient instanceof RecipientIdentifier.Single single) {
final var message = new SignalServiceTypingMessage(action, timestamp, Optional.absent());
- final var recipientId = recipientHelper.resolveRecipient((RecipientIdentifier.Single) recipient);
- final var result = sendHelper.sendTypingMessage(message, recipientId);
- results.put(recipient,
- List.of(SendMessageResult.from(result,
- account.getRecipientStore(),
- account.getRecipientStore()::resolveRecipientAddress)));
+ try {
+ final var recipientId = recipientHelper.resolveRecipient(single);
+ final var result = sendHelper.sendTypingMessage(message, recipientId);
+ results.put(recipient,
+ List.of(SendMessageResult.from(result,
+ account.getRecipientStore(),
+ account.getRecipientStore()::resolveRecipientAddress)));
+ } catch (UnregisteredRecipientException e) {
+ results.put(recipient,
+ List.of(SendMessageResult.unregisteredFailure(single.toPartialRecipientAddress())));
+ }
} else if (recipient instanceof RecipientIdentifier.Group) {
final var groupId = ((RecipientIdentifier.Group) recipient).groupId();
final var message = new SignalServiceTypingMessage(action, timestamp, Optional.of(groupId.serialize()));
messageIds,
timestamp);
- final var result = sendHelper.sendReceiptMessage(receiptMessage, recipientHelper.resolveRecipient(sender));
- return new SendMessageResults(timestamp,
- Map.of(sender,
- List.of(SendMessageResult.from(result,
- account.getRecipientStore(),
- account.getRecipientStore()::resolveRecipientAddress))));
+ return sendReceiptMessage(sender, timestamp, receiptMessage);
}
@Override
messageIds,
timestamp);
- final var result = sendHelper.sendReceiptMessage(receiptMessage, recipientHelper.resolveRecipient(sender));
- return new SendMessageResults(timestamp,
- Map.of(sender,
- List.of(SendMessageResult.from(result,
- account.getRecipientStore(),
- account.getRecipientStore()::resolveRecipientAddress))));
+ return sendReceiptMessage(sender, timestamp, receiptMessage);
+ }
+
+ private SendMessageResults sendReceiptMessage(
+ final RecipientIdentifier.Single sender,
+ final long timestamp,
+ final SignalServiceReceiptMessage receiptMessage
+ ) throws IOException {
+ try {
+ final var result = sendHelper.sendReceiptMessage(receiptMessage, recipientHelper.resolveRecipient(sender));
+ return new SendMessageResults(timestamp,
+ Map.of(sender,
+ List.of(SendMessageResult.from(result,
+ account.getRecipientStore(),
+ account.getRecipientStore()::resolveRecipientAddress))));
+ } catch (UnregisteredRecipientException e) {
+ return new SendMessageResults(timestamp,
+ Map.of(sender, List.of(SendMessageResult.unregisteredFailure(sender.toPartialRecipientAddress()))));
+ }
}
@Override
public SendMessageResults sendMessage(
Message message, Set<RecipientIdentifier> recipients
- ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException {
+ ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException {
final var messageBuilder = SignalServiceDataMessage.newBuilder();
applyMessage(messageBuilder, message);
return sendMessage(messageBuilder, recipients);
private void applyMessage(
final SignalServiceDataMessage.Builder messageBuilder, final Message message
- ) throws AttachmentInvalidException, IOException {
+ ) throws AttachmentInvalidException, IOException, UnregisteredRecipientException {
messageBuilder.withBody(message.messageText());
final var attachments = message.attachments();
if (attachments != null) {
}
}
- private ArrayList<SignalServiceDataMessage.Mention> resolveMentions(final List<Message.Mention> mentionList) throws IOException {
+ private ArrayList<SignalServiceDataMessage.Mention> resolveMentions(final List<Message.Mention> mentionList) throws IOException, UnregisteredRecipientException {
final var mentions = new ArrayList<SignalServiceDataMessage.Mention>();
for (final var m : mentionList) {
final var recipientId = recipientHelper.resolveRecipient(m.recipient());
RecipientIdentifier.Single targetAuthor,
long targetSentTimestamp,
Set<RecipientIdentifier> recipients
- ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException {
+ ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException {
var targetAuthorRecipientId = recipientHelper.resolveRecipient(targetAuthor);
var reaction = new SignalServiceDataMessage.Reaction(emoji,
remove,
throw new AssertionError(e);
} finally {
for (var recipient : recipients) {
- final var recipientId = recipientHelper.resolveRecipient(recipient);
+ final RecipientId recipientId;
+ try {
+ recipientId = recipientHelper.resolveRecipient(recipient);
+ } catch (UnregisteredRecipientException e) {
+ continue;
+ }
account.getSessionStore().deleteAllSessions(recipientId);
}
}
}
@Override
- public void deleteRecipient(final RecipientIdentifier.Single recipient) throws IOException {
- account.removeRecipient(recipientHelper.resolveRecipient(recipient));
+ public void deleteRecipient(final RecipientIdentifier.Single recipient) {
+ account.removeRecipient(account.getRecipientStore().resolveRecipient(recipient.toPartialRecipientAddress()));
}
@Override
- public void deleteContact(final RecipientIdentifier.Single recipient) throws IOException {
- account.getContactStore().deleteContact(recipientHelper.resolveRecipient(recipient));
+ public void deleteContact(final RecipientIdentifier.Single recipient) {
+ account.getContactStore()
+ .deleteContact(account.getRecipientStore().resolveRecipient(recipient.toPartialRecipientAddress()));
}
@Override
public void setContactName(
RecipientIdentifier.Single recipient, String name
- ) throws NotMasterDeviceException, IOException {
+ ) throws NotMasterDeviceException, IOException, UnregisteredRecipientException {
if (!account.isMasterDevice()) {
throw new NotMasterDeviceException();
}
@Override
public void setContactBlocked(
RecipientIdentifier.Single recipient, boolean blocked
- ) throws NotMasterDeviceException, IOException {
+ ) throws NotMasterDeviceException, IOException, UnregisteredRecipientException {
if (!account.isMasterDevice()) {
throw new NotMasterDeviceException();
}
contactHelper.setContactBlocked(recipientHelper.resolveRecipient(recipient), blocked);
- // TODO cycle our profile key
+ // TODO cycle our profile key, if we're not together in a group with recipient
syncHelper.sendBlockedList();
}
@Override
public void setExpirationTimer(
RecipientIdentifier.Single recipient, int messageExpirationTimer
- ) throws IOException {
+ ) throws IOException, UnregisteredRecipientException {
var recipientId = recipientHelper.resolveRecipient(recipient);
contactHelper.setExpirationTimer(recipientId, messageExpirationTimer);
final var messageBuilder = SignalServiceDataMessage.newBuilder().asExpirationUpdate();
logger.debug("Checking for new message from server");
try {
var result = signalWebSocket.readOrEmpty(timeout.toMillis(), envelope1 -> {
- final var recipientId = envelope1.hasSourceUuid()
- ? resolveRecipient(envelope1.getSourceAddress())
- : null;
+ final var recipientId = envelope1.hasSourceUuid() ? account.getRecipientStore()
+ .resolveRecipient(envelope1.getSourceAddress()) : null;
// store message on disk, before acknowledging receipt to the server
cachedMessage[0] = account.getMessageCache().cacheMessage(envelope1, recipientId);
});
final RecipientId recipientId;
try {
recipientId = recipientHelper.resolveRecipient(recipient);
- } catch (IOException e) {
+ } catch (IOException | UnregisteredRecipientException e) {
return false;
}
return contactHelper.isContactBlocked(recipientId);
final RecipientId recipientId;
try {
recipientId = recipientHelper.resolveRecipient(recipient);
- } catch (IOException e) {
+ } catch (IOException | UnregisteredRecipientException e) {
return null;
}
return contact.getName();
}
- final var profile = getRecipientProfile(recipientId);
+ final var profile = profileHelper.getRecipientProfile(recipientId);
if (profile != null) {
return profile.getDisplayName();
}
IdentityInfo identity;
try {
identity = account.getIdentityKeyStore().getIdentity(recipientHelper.resolveRecipient(recipient));
- } catch (IOException e) {
+ } catch (IOException | UnregisteredRecipientException e) {
identity = null;
}
return identity == null ? List.of() : List.of(toIdentity(identity));
* @param fingerprint Fingerprint
*/
@Override
- public boolean trustIdentityVerified(RecipientIdentifier.Single recipient, byte[] fingerprint) {
+ public boolean trustIdentityVerified(
+ RecipientIdentifier.Single recipient, byte[] fingerprint
+ ) throws UnregisteredRecipientException {
RecipientId recipientId;
try {
recipientId = recipientHelper.resolveRecipient(recipient);
* @param safetyNumber Safety number
*/
@Override
- public boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, String safetyNumber) {
+ public boolean trustIdentityVerifiedSafetyNumber(
+ RecipientIdentifier.Single recipient, String safetyNumber
+ ) throws UnregisteredRecipientException {
RecipientId recipientId;
try {
recipientId = recipientHelper.resolveRecipient(recipient);
* @param safetyNumber Scannable safety number
*/
@Override
- public boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, byte[] safetyNumber) {
+ public boolean trustIdentityVerifiedSafetyNumber(
+ RecipientIdentifier.Single recipient, byte[] safetyNumber
+ ) throws UnregisteredRecipientException {
RecipientId recipientId;
try {
recipientId = recipientHelper.resolveRecipient(recipient);
* @param recipient account of the identity
*/
@Override
- public boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) {
+ public boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) throws UnregisteredRecipientException {
RecipientId recipientId;
try {
recipientId = recipientHelper.resolveRecipient(recipient);
this.identityHelper.handleIdentityFailure(recipientId, identityFailure);
}
- private RecipientId resolveRecipient(SignalServiceAddress address) {
- return account.getRecipientStore().resolveRecipient(address);
- }
-
@Override
public void close() throws IOException {
Thread thread;
}
throw new AssertionError("RecipientAddress without identifier");
}
+
+ RecipientAddress toPartialRecipientAddress();
}
record Uuid(UUID uuid) implements Single {
public String getIdentifier() {
return uuid.toString();
}
+
+ @Override
+ public RecipientAddress toPartialRecipientAddress() {
+ return new RecipientAddress(uuid);
+ }
}
record Number(String number) implements Single {
public String getIdentifier() {
return number;
}
+
+ @Override
+ public RecipientAddress toPartialRecipientAddress() {
+ return new RecipientAddress(null, number);
+ }
}
record Group(GroupId groupId) implements RecipientIdentifier {
--- /dev/null
+package org.asamk.signal.manager.api;
+
+import org.asamk.signal.manager.storage.recipients.RecipientAddress;
+
+public class UnregisteredRecipientException extends Exception {
+
+ private final RecipientAddress sender;
+
+ public UnregisteredRecipientException(final RecipientAddress sender) {
+ super("Unregistered user: " + sender.getIdentifier());
+ this.sender = sender;
+ }
+
+ public RecipientAddress getSender() {
+ return sender;
+ }
+}
import org.asamk.signal.manager.SignalDependencies;
import org.asamk.signal.manager.api.RecipientIdentifier;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.config.ServiceConfig;
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
import org.asamk.signal.manager.storage.SignalAccount;
+import org.asamk.signal.manager.storage.recipients.RecipientAddress;
import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
-import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
import org.whispersystems.signalservice.internal.contacts.crypto.Quote;
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedQuoteException;
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
final ACI aci;
try {
aci = getRegisteredUser(number);
- } catch (IOException e) {
+ } catch (UnregisteredRecipientException | IOException e) {
logger.warn("Failed to get uuid for e164 number: {}", number, e);
// Return SignalServiceAddress with unknown UUID
return address.toSignalServiceAddress();
.toSignalServiceAddress();
}
- public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single> recipients) throws IOException {
+ public Set<RecipientId> resolveRecipients(Collection<RecipientIdentifier.Single> recipients) throws IOException, UnregisteredRecipientException {
final var recipientIds = new HashSet<RecipientId>(recipients.size());
for (var number : recipients) {
final var recipientId = resolveRecipient(number);
return recipientIds;
}
- public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws IOException {
+ public RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException {
if (recipient instanceof RecipientIdentifier.Uuid uuidRecipient) {
return account.getRecipientStore().resolveRecipient(ACI.from(uuidRecipient.uuid()));
} else {
return account.getRecipientStore().resolveRecipient(number, () -> {
try {
return getRegisteredUser(number);
- } catch (IOException e) {
+ } catch (Exception e) {
return null;
}
});
}
}
- public RecipientId refreshRegisteredUser(RecipientId recipientId) throws IOException {
+ public RecipientId refreshRegisteredUser(RecipientId recipientId) throws IOException, UnregisteredRecipientException {
final var address = resolveSignalServiceAddress(recipientId);
if (!address.getNumber().isPresent()) {
return recipientId;
return registeredUsers;
}
- private ACI getRegisteredUser(final String number) throws IOException {
+ private ACI getRegisteredUser(final String number) throws IOException, UnregisteredRecipientException {
final Map<String, ACI> aciMap;
try {
aciMap = getRegisteredUsers(Set.of(number));
} catch (NumberFormatException e) {
- throw new UnregisteredUserException(number, e);
+ throw new UnregisteredRecipientException(new RecipientAddress(null, number));
}
final var uuid = aciMap.get(number);
if (uuid == null) {
- throw new UnregisteredUserException(number, null);
+ throw new UnregisteredRecipientException(new RecipientAddress(null, number));
}
return uuid;
}
package org.asamk.signal.manager.helper;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.storage.recipients.RecipientId;
import java.io.IOException;
public interface RecipientRegistrationRefresher {
- RecipientId refreshRecipientRegistration(RecipientId recipientId) throws IOException;
+ RecipientId refreshRecipientRegistration(RecipientId recipientId) throws IOException, UnregisteredRecipientException;
}
package org.asamk.signal.manager.helper;
import org.asamk.signal.manager.SignalDependencies;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
try {
return s.send(messageSender, address, unidentifiedAccessHelper.getAccessFor(recipientId));
} catch (UnregisteredUserException e) {
- final var newRecipientId = recipientRegistrationRefresher.refreshRecipientRegistration(recipientId);
+ final RecipientId newRecipientId;
+ try {
+ newRecipientId = recipientRegistrationRefresher.refreshRecipientRegistration(recipientId);
+ } catch (UnregisteredRecipientException ex) {
+ return SendMessageResult.unregisteredFailure(address);
+ }
address = addressResolver.resolveSignalServiceAddress(newRecipientId);
return s.send(messageSender, address, unidentifiedAccessHelper.getAccessFor(newRecipientId));
}
import com.fasterxml.jackson.databind.ObjectMapper;
import org.asamk.signal.manager.api.Pair;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.storage.Utils;
import org.asamk.signal.manager.storage.contacts.ContactsStore;
import org.asamk.signal.manager.storage.profiles.ProfileStore;
import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
-import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
import org.whispersystems.signalservice.api.util.UuidUtil;
import java.io.ByteArrayInputStream;
@Override
public RecipientId resolveRecipient(ACI aci) {
- return resolveRecipient(new RecipientAddress(aci == null ? null : aci.uuid()), false);
+ return resolveRecipient(new RecipientAddress(aci.uuid()), false);
}
@Override
public RecipientId resolveRecipient(
final String number, Supplier<ACI> aciSupplier
- ) throws UnregisteredUserException {
+ ) throws UnregisteredRecipientException {
final Optional<Recipient> byNumber;
synchronized (recipients) {
byNumber = findByNumberLocked(number);
if (byNumber.isEmpty() || byNumber.get().getAddress().uuid().isEmpty()) {
final var aci = aciSupplier.get();
if (aci == null) {
- throw new UnregisteredUserException(number, null);
+ throw new UnregisteredRecipientException(new RecipientAddress(null, number));
}
return resolveRecipient(new RecipientAddress(aci.uuid(), number), false);
super("Untrusted identity: " + message);
}
}
+
+ class UnregisteredRecipient extends DBusExecutionException {
+
+ public UnregisteredRecipient(final String message) {
+ super("Unregistered recipient: " + message);
+ }
+ }
}
}
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.NotMasterDeviceException;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.CommandUtil;
throw new UserErrorException("This command doesn't work on linked devices.");
} catch (IOException e) {
throw new UnexpectedErrorException("Failed to sync block to linked devices: " + e.getMessage(), e);
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
}
}
import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.LastGroupAdminException;
import org.asamk.signal.manager.groups.NotAGroupMemberException;
throw new UserErrorException("Failed to send to group: " + e.getMessage());
} catch (LastGroupAdminException e) {
throw new UserErrorException("You need to specify a new admin with --admin: " + e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
}
}
}
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.commands.exceptions.CommandException;
-import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.CommandUtil;
-import java.io.IOException;
-
public class RemoveContactCommand implements JsonRpcLocalCommand {
@Override
var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getSelfNumber());
var forget = Boolean.TRUE == ns.getBoolean("forget");
- try {
- if (forget) {
- m.deleteRecipient(recipient);
- } else {
- m.deleteContact(recipient);
- }
- } catch (IOException e) {
- throw new IOErrorException("Remove contact error: " + e.getMessage(), e);
+ if (forget) {
+ m.deleteRecipient(recipient);
+ } else {
+ m.deleteContact(recipient);
}
}
}
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.Message;
import org.asamk.signal.manager.api.RecipientIdentifier;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
import org.asamk.signal.manager.groups.NotAGroupMemberException;
.getSimpleName() + ")", e);
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new UserErrorException(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
}
}
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
import org.asamk.signal.manager.groups.NotAGroupMemberException;
} catch (IOException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
.getSimpleName() + ")", e);
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
}
}
}
import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.CommandUtil;
import org.asamk.signal.util.Hex;
var recipentString = ns.getString("recipient");
var recipient = CommandUtil.getSingleRecipientIdentifier(recipentString, m.getSelfNumber());
if (Boolean.TRUE.equals(ns.getBoolean("trust-all-known-keys"))) {
- boolean res = m.trustIdentityAllKeys(recipient);
+ boolean res;
+ try {
+ res = m.trustIdentityAllKeys(recipient);
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
+ }
if (!res) {
throw new UserErrorException("Failed to set the trust for this number, make sure the number is correct.");
}
throw new UserErrorException(
"Failed to parse the fingerprint, make sure the fingerprint is a correctly encoded hex string without additional characters.");
}
- boolean res = m.trustIdentityVerified(recipient, fingerprintBytes);
+ boolean res;
+ try {
+ res = m.trustIdentityVerified(recipient, fingerprintBytes);
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
+ }
if (!res) {
throw new UserErrorException(
"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 = m.trustIdentityVerifiedSafetyNumber(recipient, safetyNumber);
+ boolean res;
+ try {
+ res = m.trustIdentityVerifiedSafetyNumber(recipient, safetyNumber);
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
+ }
if (!res) {
throw new UserErrorException(
"Failed to set the trust for the safety number of this phone number, make sure the phone number and the safety number are correct.");
throw new UserErrorException(
"Safety number has invalid format, either specify the old hex fingerprint or the new safety number");
}
- boolean res = m.trustIdentityVerifiedSafetyNumber(recipient, scannableSafetyNumber);
+ boolean res;
+ try {
+ res = m.trustIdentityVerifiedSafetyNumber(recipient, scannableSafetyNumber);
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
+ }
if (!res) {
throw new UserErrorException(
"Failed to set the trust for the safety number of this phone number, make sure the phone number and the safety number are correct.");
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.NotMasterDeviceException;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.groups.GroupNotFoundException;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.CommandUtil;
throw new UserErrorException("This command doesn't work on linked devices.");
} catch (IOException e) {
throw new UnexpectedErrorException("Failed to sync unblock to linked devices: " + e.getMessage(), e);
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
}
}
import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.NotMasterDeviceException;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.CommandUtil;
throw new IOErrorException("Update contact error: " + e.getMessage(), e);
} catch (NotMasterDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices.");
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
}
}
}
import org.asamk.signal.manager.AttachmentInvalidException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.SendGroupMessageResults;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupLinkState;
throw new UserErrorException("Failed to add avatar attachment for group\": " + e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new UserErrorException(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
} catch (IOException e) {
throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
.getSimpleName() + ")", e);
}
@Override
- public void deleteRecipient(final RecipientIdentifier.Single recipient) throws IOException {
+ public void deleteRecipient(final RecipientIdentifier.Single recipient) {
signal.deleteRecipient(recipient.getIdentifier());
}
@Override
- public void deleteContact(final RecipientIdentifier.Single recipient) throws IOException {
+ public void deleteContact(final RecipientIdentifier.Single recipient) {
signal.deleteContact(recipient.getIdentifier());
}
import org.asamk.signal.manager.api.SendMessageResult;
import org.asamk.signal.manager.api.SendMessageResults;
import org.asamk.signal.manager.api.TypingAction;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
throw new Error.Failure(e);
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new Error.GroupNotFound(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
throw new Error.Failure(e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new Error.GroupNotFound(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
throw new Error.Failure(e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new Error.GroupNotFound(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
@Override
public void deleteRecipient(final String recipient) throws Error.Failure {
- try {
- m.deleteRecipient(getSingleRecipientIdentifier(recipient, m.getSelfNumber()));
- } catch (IOException e) {
- throw new Error.Failure("Recipient not found");
- }
+ m.deleteRecipient(getSingleRecipientIdentifier(recipient, m.getSelfNumber()));
}
@Override
public void deleteContact(final String recipient) throws Error.Failure {
- try {
- m.deleteContact(getSingleRecipientIdentifier(recipient, m.getSelfNumber()));
- } catch (IOException e) {
- throw new Error.Failure("Contact not found");
- }
+ m.deleteContact(getSingleRecipientIdentifier(recipient, m.getSelfNumber()));
}
@Override
throw new Error.GroupNotFound(e.getMessage());
} catch (AttachmentInvalidException e) {
throw new Error.AttachmentInvalid(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
throw new Error.Failure(e.getMessage());
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
throw new Error.GroupNotFound(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
throw new Error.Failure("This command doesn't work on linked devices.");
} catch (IOException e) {
throw new Error.Failure("Contact is not registered.");
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
m.setExpirationTimer(getSingleRecipientIdentifier(number, m.getSelfNumber()), expiration);
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
throw new Error.Failure("This command doesn't work on linked devices.");
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
throw new Error.GroupNotFound(e.getMessage());
} catch (AttachmentInvalidException e) {
throw new Error.AttachmentInvalid(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
Profile profile = null;
try {
profile = m.getRecipientProfile(RecipientIdentifier.Single.fromAddress(address));
- } catch (IOException ignored) {
+ } catch (IOException | UnregisteredRecipientException ignored) {
}
if (profile != null && profile.getDisplayName().equals(name)) {
numbers.add(number);
throw new Error.GroupNotFound(e.getMessage());
} catch (IOException | LastGroupAdminException e) {
throw new Error.Failure(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
throw new Error.Failure(e.getMessage());
} catch (LastGroupAdminException e) {
throw new Error.LastGroupAdmin(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
throw new Error.GroupNotFound(e.getMessage());
} catch (AttachmentInvalidException e) {
throw new Error.AttachmentInvalid(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new Error.UntrustedIdentity(e.getSender().getIdentifier() + " is not registered.");
}
}
}