X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/20bf605e36be0892d05b3ae11954aa7dd0784e23..286070c054d617f376c88a9b24efa9c5cffaef6a:/src/main/java/org/asamk/signal/manager/Manager.java diff --git a/src/main/java/org/asamk/signal/manager/Manager.java b/src/main/java/org/asamk/signal/manager/Manager.java index 90e981c2..b418d310 100644 --- a/src/main/java/org/asamk/signal/manager/Manager.java +++ b/src/main/java/org/asamk/signal/manager/Manager.java @@ -99,7 +99,6 @@ import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage import org.whispersystems.signalservice.api.profiles.SignalServiceProfile; import org.whispersystems.signalservice.api.push.ContactTokenDetails; import org.whispersystems.signalservice.api.push.SignalServiceAddress; -import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException; import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions; import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException; import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException; @@ -215,20 +214,15 @@ public class Manager implements Signal { migrateLegacyConfigs(); accountManager = getSignalServiceAccountManager(); - try { - if (account.isRegistered()) { - if (accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) { - refreshPreKeys(); - account.save(); - } - if (account.getUuid() == null) { - account.setUuid(accountManager.getOwnUuid()); - account.save(); - } + if (account.isRegistered()) { + if (accountManager.getPreKeysCount() < BaseConfig.PREKEY_MINIMUM_COUNT) { + refreshPreKeys(); + account.save(); + } + if (account.getUuid() == null) { + account.setUuid(accountManager.getOwnUuid()); + account.save(); } - } catch (AuthorizationFailedException e) { - System.err.println("Authorization failed, was the number registered elsewhere?"); - throw e; } } @@ -264,6 +258,8 @@ public class Manager implements Signal { if (username == null) { account = SignalAccount.createTemporaryAccount(identityKey, registrationId); } else { + account.getSignalProtocolStore().saveIdentity(username, identityKey.getPublicKey(), TrustLevel.TRUSTED_VERIFIED); + ProfileKey profileKey = KeyUtils.createProfileKey(); account = SignalAccount.create(dataPath, username, identityKey, registrationId, profileKey); account.save(); @@ -279,6 +275,7 @@ public class Manager implements Signal { createNewIdentity(); } account.setPassword(KeyUtils.createPassword()); + account.setUuid(null); accountManager = getSignalServiceAccountManager(); if (voiceVerification) { @@ -548,8 +545,7 @@ public class Manager implements Signal { throws IOException, EncapsulatedExceptions, AttachmentInvalidException { SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, targetAuthor, targetSentTimestamp); final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder() - .withReaction(reaction) - .withProfileKey(account.getProfileKey().serialize()); + .withReaction(reaction); if (groupId != null) { SignalServiceGroup group = SignalServiceGroup.newBuilder(SignalServiceGroup.Type.DELIVER) .withId(groupId) @@ -714,7 +710,6 @@ public class Manager implements Signal { messageBuilder.withAttachments(attachmentPointers); } - messageBuilder.withProfileKey(account.getProfileKey().serialize()); sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients)); } @@ -723,8 +718,7 @@ public class Manager implements Signal { throws IOException, EncapsulatedExceptions, AttachmentInvalidException, InvalidNumberException { SignalServiceDataMessage.Reaction reaction = new SignalServiceDataMessage.Reaction(emoji, remove, targetAuthor, targetSentTimestamp); final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder() - .withReaction(reaction) - .withProfileKey(account.getProfileKey().serialize()); + .withReaction(reaction); sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients)); } @@ -1003,7 +997,9 @@ public class Manager implements Signal { } private byte[] getSenderCertificate() throws IOException { - byte[] certificate = accountManager.getSenderCertificate(); + // TODO support UUID capable sender certificates + // byte[] certificate = accountManager.getSenderCertificate(); + byte[] certificate = accountManager.getSenderCertificateLegacy(); // TODO cache for a day return certificate; } @@ -1141,8 +1137,11 @@ public class Manager implements Signal { if (canonicalizedNumber.equals(username)) { signalServiceAddresses.add(account.getSelfAddress()); } else { - // TODO get corresponding uuid - signalServiceAddresses.add(new SignalServiceAddress(null, canonicalizedNumber)); + SignalServiceAddress address = new SignalServiceAddress(null, canonicalizedNumber); + ContactInfo contact = account.getContactStore().getContact(address); + signalServiceAddresses.add(contact == null + ? address + : contact.getAddress()); } } return signalServiceAddresses; @@ -1201,8 +1200,10 @@ public class Manager implements Signal { ContactInfo contact = account.getContactStore().getContact(address); if (contact != null) { messageBuilder.withExpiration(contact.messageExpirationTime); + messageBuilder.withProfileKey(account.getProfileKey().serialize()); } else { messageBuilder.withExpiration(0); + messageBuilder.withProfileKey(null); } message = messageBuilder.build(); try {