X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/ce7aa580b6f0580cdcf7fd68fcc8efba737d21ed..782f96b580b2e659539027d7bf4be159c8622029:/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java diff --git a/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java b/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java index fe26e9b4..022915a7 100644 --- a/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java +++ b/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java @@ -20,7 +20,10 @@ import org.asamk.signal.manager.actions.HandleAction; import org.asamk.signal.manager.api.Device; import org.asamk.signal.manager.api.Group; 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.Message; +import org.asamk.signal.manager.api.Pair; import org.asamk.signal.manager.api.RecipientIdentifier; import org.asamk.signal.manager.api.SendGroupMessageResults; import org.asamk.signal.manager.api.SendMessageResults; @@ -64,10 +67,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.whispersystems.libsignal.InvalidKeyException; import org.whispersystems.libsignal.ecc.ECPublicKey; -import org.whispersystems.libsignal.util.Pair; import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.signalservice.api.SignalSessionLock; -import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException; import org.whispersystems.signalservice.api.messages.SendMessageResult; import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId; import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage; @@ -75,7 +76,6 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope; import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage; import org.whispersystems.signalservice.api.messages.SignalServiceTypingMessage; import org.whispersystems.signalservice.api.push.SignalServiceAddress; -import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException; import org.whispersystems.signalservice.api.util.DeviceNameUtil; import org.whispersystems.signalservice.api.util.InvalidNumberException; import org.whispersystems.signalservice.api.util.PhoneNumberFormatter; @@ -358,9 +358,13 @@ public class ManagerImpl implements Manager { */ @Override public void setProfile( - String givenName, final String familyName, String about, String aboutEmoji, Optional avatar + String givenName, final String familyName, String about, String aboutEmoji, java.util.Optional avatar ) throws IOException { - profileHelper.setProfile(givenName, familyName, about, aboutEmoji, avatar); + profileHelper.setProfile(givenName, + familyName, + about, + aboutEmoji, + avatar == null ? null : Optional.fromNullable(avatar.orElse(null))); syncHelper.sendSyncFetchProfileMessage(); } @@ -423,27 +427,33 @@ public class ManagerImpl implements Manager { } @Override - public void addDeviceLink(URI linkUri) throws IOException, InvalidKeyException { + public void addDeviceLink(URI linkUri) throws IOException, InvalidDeviceLinkException { var info = DeviceLinkInfo.parseDeviceLinkUri(linkUri); addDevice(info.deviceIdentifier(), info.deviceKey()); } - private void addDevice(String deviceIdentifier, ECPublicKey deviceKey) throws IOException, InvalidKeyException { + private void addDevice( + String deviceIdentifier, ECPublicKey deviceKey + ) throws IOException, InvalidDeviceLinkException { var identityKeyPair = account.getIdentityKeyPair(); var verificationCode = dependencies.getAccountManager().getNewDeviceVerificationCode(); - dependencies.getAccountManager() - .addDevice(deviceIdentifier, - deviceKey, - identityKeyPair, - Optional.of(account.getProfileKey().serialize()), - verificationCode); + try { + dependencies.getAccountManager() + .addDevice(deviceIdentifier, + deviceKey, + identityKeyPair, + Optional.of(account.getProfileKey().serialize()), + verificationCode); + } catch (InvalidKeyException e) { + throw new InvalidDeviceLinkException("Invalid device link", e); + } account.setMultiDevice(true); } @Override - public void setRegistrationLockPin(Optional pin) throws IOException, UnauthenticatedResponseException { + public void setRegistrationLockPin(java.util.Optional pin) throws IOException, UnauthenticatedResponseException { if (!account.isMasterDevice()) { throw new RuntimeException("Only master device can set a PIN"); } @@ -468,7 +478,7 @@ public class ManagerImpl implements Manager { } @Override - public Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws UnregisteredUserException { + public Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws IOException { return profileHelper.getRecipientProfile(resolveRecipient(recipient)); } @@ -558,7 +568,7 @@ public class ManagerImpl implements Manager { @Override public Pair joinGroup( GroupInviteLinkUrl inviteLinkUrl - ) throws IOException, GroupLinkNotActiveException { + ) throws IOException, InactiveGroupLinkException { return groupHelper.joinGroup(inviteLinkUrl); } @@ -695,7 +705,7 @@ public class ManagerImpl implements Manager { @Override public void setContactName( RecipientIdentifier.Single recipient, String name - ) throws NotMasterDeviceException, UnregisteredUserException { + ) throws NotMasterDeviceException, IOException { if (!account.isMasterDevice()) { throw new NotMasterDeviceException(); } @@ -802,11 +812,11 @@ public class ManagerImpl implements Manager { try { uuidMap = getRegisteredUsers(Set.of(number)); } catch (NumberFormatException e) { - throw new UnregisteredUserException(number, e); + throw new IOException(number, e); } final var uuid = uuidMap.get(number); if (uuid == null) { - throw new UnregisteredUserException(number, null); + throw new IOException(number, null); } return uuid; } @@ -1123,7 +1133,7 @@ public class ManagerImpl implements Manager { final RecipientId recipientId; try { recipientId = resolveRecipient(recipient); - } catch (UnregisteredUserException e) { + } catch (IOException e) { return false; } return contactHelper.isContactBlocked(recipientId); @@ -1153,7 +1163,7 @@ public class ManagerImpl implements Manager { final RecipientId recipientId; try { recipientId = resolveRecipient(recipient); - } catch (UnregisteredUserException e) { + } catch (IOException e) { return null; } @@ -1209,7 +1219,7 @@ public class ManagerImpl implements Manager { IdentityInfo identity; try { identity = account.getIdentityKeyStore().getIdentity(resolveRecipient(recipient)); - } catch (UnregisteredUserException e) { + } catch (IOException e) { identity = null; } return identity == null ? List.of() : List.of(toIdentity(identity)); @@ -1226,7 +1236,7 @@ public class ManagerImpl implements Manager { RecipientId recipientId; try { recipientId = resolveRecipient(recipient); - } catch (UnregisteredUserException e) { + } catch (IOException e) { return false; } return identityHelper.trustIdentityVerified(recipientId, fingerprint); @@ -1243,7 +1253,7 @@ public class ManagerImpl implements Manager { RecipientId recipientId; try { recipientId = resolveRecipient(recipient); - } catch (UnregisteredUserException e) { + } catch (IOException e) { return false; } return identityHelper.trustIdentityVerifiedSafetyNumber(recipientId, safetyNumber); @@ -1260,7 +1270,7 @@ public class ManagerImpl implements Manager { RecipientId recipientId; try { recipientId = resolveRecipient(recipient); - } catch (UnregisteredUserException e) { + } catch (IOException e) { return false; } return identityHelper.trustIdentityVerifiedSafetyNumber(recipientId, safetyNumber); @@ -1276,7 +1286,7 @@ public class ManagerImpl implements Manager { RecipientId recipientId; try { recipientId = resolveRecipient(recipient); - } catch (UnregisteredUserException e) { + } catch (IOException e) { return false; } return identityHelper.trustIdentityAllKeys(recipientId); @@ -1313,7 +1323,7 @@ public class ManagerImpl implements Manager { return resolveSignalServiceAddress(account.getRecipientStore().resolveRecipient(uuid)); } - private Set resolveRecipients(Collection recipients) throws UnregisteredUserException { + private Set resolveRecipients(Collection recipients) throws IOException { final var recipientIds = new HashSet(recipients.size()); for (var number : recipients) { final var recipientId = resolveRecipient(number); @@ -1322,7 +1332,7 @@ public class ManagerImpl implements Manager { return recipientIds; } - private RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws UnregisteredUserException { + private RecipientId resolveRecipient(final RecipientIdentifier.Single recipient) throws IOException { if (recipient instanceof RecipientIdentifier.Uuid) { return account.getRecipientStore().resolveRecipient(((RecipientIdentifier.Uuid) recipient).uuid); } else {