From 93395c3ff4a7c19750b3ba03e05209bbd0016835 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Tue, 12 Sep 2017 22:49:30 -0700 Subject: [PATCH] Include own profile key in normal contact sync // FREEBIE --- .../thoughtcrime/securesms/crypto/ProfileKeyUtil.java | 4 ++++ .../securesms/jobs/MultiDeviceContactUpdateJob.java | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/org/thoughtcrime/securesms/crypto/ProfileKeyUtil.java b/src/org/thoughtcrime/securesms/crypto/ProfileKeyUtil.java index 0f2baffb9e..0b10de6b51 100644 --- a/src/org/thoughtcrime/securesms/crypto/ProfileKeyUtil.java +++ b/src/org/thoughtcrime/securesms/crypto/ProfileKeyUtil.java @@ -12,6 +12,10 @@ import java.io.IOException; public class ProfileKeyUtil { + public static synchronized boolean hasProfileKey(@NonNull Context context) { + return TextSecurePreferences.getProfileKey(context) != null; + } + public static synchronized @NonNull byte[] getProfileKey(@NonNull Context context) { try { String encodedProfileKey = TextSecurePreferences.getProfileKey(context); diff --git a/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java b/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java index c976d5c5ee..f3ea85cb1d 100644 --- a/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java +++ b/src/org/thoughtcrime/securesms/jobs/MultiDeviceContactUpdateJob.java @@ -13,6 +13,7 @@ import android.util.Log; import org.thoughtcrime.securesms.contacts.ContactAccessor; import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData; import org.thoughtcrime.securesms.crypto.MasterSecret; +import org.thoughtcrime.securesms.crypto.ProfileKeyUtil; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.IdentityDatabase; @@ -20,6 +21,7 @@ import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.dependencies.SignalCommunicationModule.SignalMessageSenderFactory; import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement; import org.thoughtcrime.securesms.recipients.Recipient; +import org.thoughtcrime.securesms.util.Base64; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.whispersystems.jobqueue.JobParameters; import org.whispersystems.jobqueue.requirements.NetworkRequirement; @@ -137,6 +139,13 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje out.write(new DeviceContact(address.toPhoneString(), name, getAvatar(contactUri), color, verified, profileKey)); } + if (ProfileKeyUtil.hasProfileKey(context)) { + out.write(new DeviceContact(TextSecurePreferences.getLocalNumber(context), + Optional.absent(), Optional.absent(), + Optional.absent(), Optional.absent(), + Optional.of(ProfileKeyUtil.getProfileKey(context)))); + } + out.close(); sendUpdate(messageSender, contactDataFile, true); } catch(InvalidNumberException e) {