From 3b50b8f40ba2305d5c383ac91e86c0e43b27284f Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Fri, 29 Jan 2021 11:08:48 +1100 Subject: [PATCH] fix closed groups & clean --- .../attachments/AttachmentServer.java | 2 +- .../securesms/audio/AudioRecorder.java | 2 +- .../conversation/ConversationItem.java | 2 +- .../securesms/crypto/DatabaseSecret.java | 2 +- .../securesms/crypto/MasterCipher.java | 2 +- .../securesms/crypto/PublicKey.java | 2 +- .../securesms/database/GroupDatabase.java | 2 +- .../securesms/groups/GroupManager.java | 4 +- .../securesms/jobs/AttachmentDownloadJob.java | 2 +- .../securesms/jobs/AvatarDownloadJob.java | 2 +- .../securesms/jobs/MmsSendJob.java | 2 +- .../securesms/jobs/PushDecryptJob.java | 4 +- .../securesms/jobs/PushSendJob.java | 3 +- .../securesms/jobs/StickerDownloadJob.java | 2 +- .../jobs/StickerPackDownloadJob.java | 2 +- .../securesms/jobs/UpdateApkJob.java | 2 +- .../linkpreview/LinkPreviewRepository.java | 7 +-- .../activities/CreateClosedGroupActivity.kt | 2 +- .../RecoveryPhraseRestoreActivity.kt | 2 +- .../securesms/loki/api/SessionProtocolImpl.kt | 4 +- .../loki/database/LokiAPIDatabase.kt | 2 +- .../loki/database/SharedSenderKeysDatabase.kt | 2 +- .../ClosedGroupUpdateMessageSendJob.kt | 3 +- .../ClosedGroupUpdateMessageSendJobV2.kt | 3 +- .../loki/protocol/ClosedGroupsMigration.kt | 2 +- .../loki/protocol/ClosedGroupsProtocol.kt | 14 +---- .../loki/protocol/ClosedGroupsProtocolV2.kt | 21 ++++--- .../loki/utilities/KeyPairUtilities.kt | 2 +- .../loki/utilities/OpenGroupUtilities.kt | 2 +- .../service/UpdateApkReadyListener.java | 2 +- .../StickerPackPreviewRepository.java | 2 +- .../stickers/StickerRemoteUriFetcher.java | 2 +- .../messaging/fileserver/FileServerAPI.kt | 4 -- .../messaging/messages/Destination.kt | 2 +- .../messaging/opengroups/OpenGroupAPI.kt | 2 +- .../MessageReceiverHandler.kt | 11 ++-- .../MessageSenderClosedGroup.kt | 10 ++- .../MessageSenderEncryption.kt | 45 -------------- .../pollers/OpenGroupPoller.kt | 2 +- .../libsession/messaging/threads/Address.kt | 10 ++- .../libsession/snode/OnionRequestAPI.kt | 2 +- .../snode/OnionRequestEncryption.kt | 2 +- .../org/session/libsession/snode/SnodeAPI.kt | 2 +- .../session/libsession/utilities/AESGCM.kt | 1 - .../libsession/utilities/DelimiterUtil.kt | 6 +- .../session/libsession/utilities/GroupUtil.kt | 61 +++++-------------- .../session/libsession/utilities}/Hex.java | 2 +- .../libsession/utilities/PromiseUtilities.kt | 1 + .../libsession/utilities/ThreadUtils.kt | 26 -------- .../session/libsignal/libsignal/util/Hex.java | 1 - .../service/loki/utilities/ThreadUtils.kt | 14 ++++- 51 files changed, 96 insertions(+), 217 deletions(-) rename {app/src/main/java/org/thoughtcrime/securesms/util => libsession/src/main/java/org/session/libsession/utilities}/Hex.java (98%) delete mode 100644 libsession/src/main/java/org/session/libsession/utilities/ThreadUtils.kt diff --git a/app/src/main/java/org/thoughtcrime/securesms/attachments/AttachmentServer.java b/app/src/main/java/org/thoughtcrime/securesms/attachments/AttachmentServer.java index 3e0dd8d45c..86329a9704 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/attachments/AttachmentServer.java +++ b/app/src/main/java/org/thoughtcrime/securesms/attachments/AttachmentServer.java @@ -7,7 +7,7 @@ import androidx.annotation.NonNull; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.PartAuthority; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.thoughtcrime.securesms.util.Util; import org.session.libsession.messaging.sending_receiving.attachments.Attachment; diff --git a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java index 04ed137b3f..7e94f3cdb8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java +++ b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java @@ -12,7 +12,7 @@ import android.util.Pair; import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.util.MediaUtil; -import org.session.libsession.utilities.ThreadUtils; +import org.session.libsignal.service.loki.utilities.ThreadUtils; import org.session.libsession.utilities.Util; import org.session.libsession.utilities.concurrent.ListenableFuture; import org.session.libsession.utilities.concurrent.SettableFuture; diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java index e9b3cf8ddc..b8759a7177 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -901,7 +901,7 @@ public class ConversationItem extends LinearLayout // Show custom display names for group chats String displayName = recipient.toShortString(); try { - String serverId = GroupUtil.getDecodedGroupID(conversationRecipient.getAddress().serialize().getBytes()); + String serverId = GroupUtil.getDecodedGroupID(conversationRecipient.getAddress().serialize()); String senderDisplayName = DatabaseFactory.getLokiUserDatabase(context).getServerDisplayName(serverId, recipient.getAddress().serialize()); if (senderDisplayName != null) { displayName = senderDisplayName; } } catch (Exception e) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecret.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecret.java index bdd425e0c8..d406211aff 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecret.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/DatabaseSecret.java @@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.crypto; import androidx.annotation.NonNull; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import java.io.IOException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/MasterCipher.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/MasterCipher.java index a66c22fed2..255acbdb44 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/MasterCipher.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/MasterCipher.java @@ -25,7 +25,7 @@ import org.session.libsignal.libsignal.ecc.ECPrivateKey; import org.thoughtcrime.securesms.logging.Log; import org.session.libsession.utilities.Base64; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import java.io.IOException; import java.security.GeneralSecurityException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/PublicKey.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/PublicKey.java index ef7b786203..d9f97c8590 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/PublicKey.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/PublicKey.java @@ -18,7 +18,7 @@ package org.thoughtcrime.securesms.crypto; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.thoughtcrime.securesms.util.Util; import org.session.libsignal.libsignal.InvalidKeyException; import org.session.libsignal.libsignal.ecc.Curve; diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java index cfece9f090..ea100d2a55 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/GroupDatabase.java @@ -205,7 +205,7 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt contentValues.put(AVATAR_RELAY, relay); contentValues.put(TIMESTAMP, System.currentTimeMillis()); contentValues.put(ACTIVE, 1); - contentValues.put(MMS, GroupUtil.INSTANCE.isMmsGroup(groupId)); + contentValues.put(MMS, GroupUtil.isMmsGroup(groupId)); if (admins != null) { contentValues.put(ADMINS, Address.Companion.toSerializedList(admins, ',')); diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java index 36d9a8e745..cae7cbf180 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java @@ -40,7 +40,7 @@ import java.util.Set; public class GroupManager { public static long getOpenGroupThreadID(String id, @NonNull Context context) { - final String groupID = GroupUtil.getEncodedOpenGroupID(id); + final String groupID = GroupUtil.getEncodedOpenGroupID(id.getBytes()); return getThreadIDFromGroupID(groupID, context); } @@ -90,7 +90,7 @@ public class GroupManager { @Nullable Bitmap avatar, @Nullable String name) { - final String groupID = GroupUtil.getEncodedOpenGroupID(id); + final String groupID = GroupUtil.getEncodedOpenGroupID(id.getBytes()); return createLokiGroup(groupID, context, avatar, name); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java index 42f2444d1a..dda32ad82c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/AttachmentDownloadJob.java @@ -28,7 +28,7 @@ import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.MmsException; import org.thoughtcrime.securesms.util.AttachmentUtil; import org.session.libsession.utilities.Base64; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.session.libsession.utilities.Util; import java.io.File; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/AvatarDownloadJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/AvatarDownloadJob.java index 1262586f64..5ef7ec7af9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/AvatarDownloadJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/AvatarDownloadJob.java @@ -14,7 +14,7 @@ import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.AttachmentStreamUriLoader.AttachmentModel; import org.thoughtcrime.securesms.util.BitmapDecodingException; import org.thoughtcrime.securesms.util.BitmapUtil; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.SignalServiceMessageReceiver; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsSendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsSendJob.java index cab50e3603..bcf8906914 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsSendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/MmsSendJob.java @@ -39,7 +39,7 @@ import org.thoughtcrime.securesms.mms.PartAuthority; import org.session.libsession.messaging.threads.recipients.Recipient; import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException; import org.thoughtcrime.securesms.transport.UndeliverableMessageException; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.session.libsession.utilities.NumberUtil; import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.Util; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 995093254f..1eb655472d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -97,7 +97,7 @@ import org.thoughtcrime.securesms.sms.IncomingTextMessage; import org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage; import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage; import org.thoughtcrime.securesms.sms.OutgoingTextMessage; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.loki.SessionResetProtocol; @@ -1268,7 +1268,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { private Recipient getMessageDestination(SignalServiceContent content, SignalServiceDataMessage message) { if (message.getGroupInfo().isPresent()) { - return Recipient.from(context, Address.Companion.fromExternal(context, GroupUtil.getEncodedId(message.getGroupInfo().get())), false); + return Recipient.from(context, Address.Companion.fromExternal(context, GroupUtil.getEncodedClosedGroupID(message.getGroupInfo().get().getGroupId())), false); } else { return Recipient.from(context, Address.Companion.fromExternal(context, content.getSender()), false); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java index 02e7f47dae..142b6f7587 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java @@ -16,7 +16,6 @@ import org.session.libsession.utilities.Util; import org.greenrobot.eventbus.EventBus; import org.thoughtcrime.securesms.ApplicationContext; -import org.thoughtcrime.securesms.TextSecureExpiredException; import org.thoughtcrime.securesms.contactshare.ContactModelMapper; import org.thoughtcrime.securesms.crypto.ProfileKeyUtil; import org.session.libsession.messaging.threads.Address; @@ -31,7 +30,7 @@ import org.thoughtcrime.securesms.mms.PartAuthority; import org.session.libsession.messaging.threads.recipients.Recipient; import org.thoughtcrime.securesms.util.BitmapDecodingException; import org.thoughtcrime.securesms.util.BitmapUtil; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.service.api.crypto.UnidentifiedAccessPair; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/StickerDownloadJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/StickerDownloadJob.java index 05cd51872c..fc6372abb1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/StickerDownloadJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/StickerDownloadJob.java @@ -10,7 +10,7 @@ import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.session.libsignal.service.api.SignalServiceMessageReceiver; import org.session.libsignal.service.api.push.exceptions.PushNetworkException; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/StickerPackDownloadJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/StickerPackDownloadJob.java index 7430b67ce6..a486d5b8bc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/StickerPackDownloadJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/StickerPackDownloadJob.java @@ -12,7 +12,7 @@ import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.JobManager; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.service.api.SignalServiceMessageReceiver; import org.session.libsignal.service.api.messages.SignalServiceStickerManifest; diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/UpdateApkJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/UpdateApkJob.java index 2d222fa064..26c30124fa 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/UpdateApkJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/UpdateApkJob.java @@ -19,7 +19,7 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.service.UpdateApkReadyListener; import org.thoughtcrime.securesms.util.FileUtils; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.session.libsession.utilities.JsonUtils; import org.session.libsession.utilities.TextSecurePreferences; diff --git a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java index cb5d7d875d..90df94adb4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java @@ -6,8 +6,6 @@ import android.graphics.BitmapFactory; import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import android.text.Html; -import android.text.TextUtils; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.google.android.gms.common.util.IOUtils; @@ -25,7 +23,7 @@ import org.thoughtcrime.securesms.net.RequestController; import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.stickers.StickerRemoteUri; import org.thoughtcrime.securesms.stickers.StickerUrl; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.util.Pair; @@ -43,10 +41,7 @@ import org.session.libsession.utilities.concurrent.SignalExecutors; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import javax.inject.Inject; diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt index ffab859f12..41e54fe055 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/CreateClosedGroupActivity.kt @@ -118,7 +118,7 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), LoaderM loaderContainer.fadeOut() isLoading = false val threadID = DatabaseFactory.getThreadDatabase(this).getOrCreateThreadIdFor(Recipient.from(this, Address.fromSerialized(groupID), false)) - if (!isFinishing) { + if (!isFinishing) { openConversationActivity(this, threadID, Recipient.from(this, Address.fromSerialized(groupID), false)) finish() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt index b9c8175d7a..52c42cfbba 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/RecoveryPhraseRestoreActivity.kt @@ -18,7 +18,7 @@ import org.thoughtcrime.securesms.loki.utilities.KeyPairUtilities import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities import org.thoughtcrime.securesms.loki.utilities.push import org.thoughtcrime.securesms.loki.utilities.setUpActionBarSessionLogo -import org.thoughtcrime.securesms.util.Hex +import org.session.libsession.utilities.Hex import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.libsignal.util.KeyHelper import org.session.libsignal.service.loki.crypto.MnemonicCodec diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/SessionProtocolImpl.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/SessionProtocolImpl.kt index 58015344bb..d817960a30 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/SessionProtocolImpl.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/SessionProtocolImpl.kt @@ -6,8 +6,10 @@ import com.goterl.lazycode.lazysodium.LazySodiumAndroid import com.goterl.lazycode.lazysodium.SodiumAndroid import com.goterl.lazycode.lazysodium.interfaces.Box import com.goterl.lazycode.lazysodium.interfaces.Sign + +import org.session.libsession.utilities.Hex + import org.session.libsignal.libsignal.ecc.ECKeyPair -import org.session.libsignal.libsignal.util.Hex import org.session.libsignal.service.loki.api.crypto.SessionProtocol import org.session.libsignal.service.loki.utilities.hexEncodedPublicKey import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt index de7fac74d1..6a5e7ea447 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiAPIDatabase.kt @@ -15,7 +15,7 @@ import org.session.libsignal.service.loki.protocol.shelved.multidevice.DeviceLin import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded import org.session.libsignal.service.loki.utilities.toHexString import org.thoughtcrime.securesms.crypto.IdentityKeyUtil -import org.thoughtcrime.securesms.util.Hex +import org.session.libsession.utilities.Hex import org.session.libsession.utilities.TextSecurePreferences import java.util.* diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt index b9de6a25c9..271ae1a724 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SharedSenderKeysDatabase.kt @@ -5,7 +5,7 @@ import android.content.Context import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.thoughtcrime.securesms.loki.utilities.* -import org.thoughtcrime.securesms.util.Hex +import org.session.libsession.utilities.Hex import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupRatchet import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupRatchetCollectionType import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJob.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJob.kt index 92209bb8d2..25a5887973 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJob.kt @@ -9,8 +9,7 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint import org.thoughtcrime.securesms.jobs.BaseJob import org.thoughtcrime.securesms.logging.Log import org.thoughtcrime.securesms.loki.utilities.recipient -import org.thoughtcrime.securesms.util.Hex -import org.session.libsignal.libsignal.SignalProtocolAddress +import org.session.libsession.utilities.Hex import org.session.libsignal.service.api.push.SignalServiceAddress import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJobV2.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJobV2.kt index f64745046d..06c818910d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJobV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupUpdateMessageSendJobV2.kt @@ -16,13 +16,12 @@ import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded import org.session.libsignal.service.loki.utilities.toHexString import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil -import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl import org.thoughtcrime.securesms.jobmanager.Job import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint import org.thoughtcrime.securesms.jobs.BaseJob import org.thoughtcrime.securesms.logging.Log import org.thoughtcrime.securesms.loki.utilities.recipient -import org.thoughtcrime.securesms.util.Hex +import org.session.libsession.utilities.Hex import java.util.* import java.util.concurrent.TimeUnit diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsMigration.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsMigration.kt index 16cc8c4b77..3ca7bc7188 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsMigration.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsMigration.kt @@ -7,7 +7,7 @@ import org.thoughtcrime.securesms.loki.utilities.get import org.thoughtcrime.securesms.loki.utilities.getAll import org.thoughtcrime.securesms.loki.utilities.getString import org.thoughtcrime.securesms.loki.utilities.insertOrUpdate -import org.thoughtcrime.securesms.util.Hex +import org.session.libsession.utilities.Hex import org.session.libsignal.libsignal.ecc.DjbECPrivateKey import org.session.libsignal.libsignal.ecc.DjbECPublicKey import org.session.libsignal.libsignal.ecc.ECKeyPair diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt index 9f5120e71e..c2d03c5f82 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocol.kt @@ -9,18 +9,10 @@ import org.session.libsession.messaging.threads.Address import org.session.libsession.messaging.threads.recipients.Recipient import org.session.libsession.utilities.GroupUtil import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.libsignal.ecc.Curve -import org.session.libsignal.libsignal.util.guava.Optional -import org.session.libsignal.service.api.messages.SignalServiceGroup -import org.session.libsignal.service.api.messages.SignalServiceGroup.GroupType -import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos.GroupContext -import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupRatchet import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupRatchetCollectionType import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey import org.session.libsignal.service.loki.protocol.closedgroups.SharedSenderKeysImplementation -import org.session.libsignal.service.loki.utilities.hexEncodedPrivateKey -import org.session.libsignal.service.loki.utilities.hexEncodedPublicKey import org.session.libsignal.service.loki.utilities.toHexString import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.database.DatabaseFactory @@ -29,10 +21,8 @@ import org.thoughtcrime.securesms.loki.api.LokiPushNotificationManager import org.thoughtcrime.securesms.loki.api.LokiPushNotificationManager.ClosedGroupOperation import org.thoughtcrime.securesms.loki.utilities.recipient import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage -import org.thoughtcrime.securesms.sms.IncomingGroupMessage -import org.thoughtcrime.securesms.sms.IncomingTextMessage import org.thoughtcrime.securesms.sms.MessageSender -import org.thoughtcrime.securesms.util.Hex +import org.session.libsession.utilities.Hex import java.io.IOException import java.util.* @@ -306,7 +296,7 @@ object ClosedGroupsProtocol { @JvmStatic @Throws(IOException::class) fun doubleEncodeGroupID(groupPublicKey: String): String { - return GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(groupPublicKey)) + return GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(Hex.fromStringCondensed(groupPublicKey)).toByteArray()) } @JvmStatic diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocolV2.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocolV2.kt index 28031a1def..7b064d88d2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocolV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/protocol/ClosedGroupsProtocolV2.kt @@ -23,12 +23,13 @@ import org.thoughtcrime.securesms.loki.api.SessionProtocolImpl import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage import org.thoughtcrime.securesms.sms.IncomingGroupMessage import org.thoughtcrime.securesms.sms.IncomingTextMessage -import org.thoughtcrime.securesms.util.Hex +import org.session.libsession.utilities.Hex import org.session.libsession.messaging.threads.Address import org.session.libsession.messaging.threads.recipients.Recipient import org.session.libsession.utilities.GroupUtil import org.session.libsession.utilities.TextSecurePreferences +import org.session.libsignal.service.loki.utilities.ThreadUtils import java.io.IOException import java.util.* @@ -45,7 +46,7 @@ object ClosedGroupsProtocolV2 { public fun createClosedGroup(context: Context, name: String, members: Collection): Promise { val deferred = deferred() - Thread { + ThreadUtils.queue { // Prepare val userPublicKey = TextSecurePreferences.getLocalNumber(context)!! val membersAsData = members.map { Hex.fromStringCondensed(it) } @@ -80,7 +81,7 @@ object ClosedGroupsProtocolV2 { LokiPushNotificationManager.performOperation(context, ClosedGroupOperation.Subscribe, groupPublicKey, userPublicKey) // Fulfill the promise deferred.resolve(groupID) - }.start() + } // Return return deferred.promise } @@ -109,7 +110,7 @@ object ClosedGroupsProtocolV2 { public fun update(context: Context, groupPublicKey: String, members: Collection, name: String): Promise { val deferred = deferred() - Thread { + ThreadUtils.queue { val userPublicKey = TextSecurePreferences.getLocalNumber(context)!! val apiDB = DatabaseFactory.getLokiAPIDatabase(context) val groupDB = DatabaseFactory.getGroupDatabase(context) @@ -117,7 +118,7 @@ object ClosedGroupsProtocolV2 { val group = groupDB.getGroup(groupID).orNull() if (group == null) { Log.d("Loki", "Can't update nonexistent closed group.") - return@Thread deferred.reject(Error.NoThread) + return@queue deferred.reject(Error.NoThread) } val oldMembers = group.members.map { it.serialize() }.toSet() val newMembers = members.minus(oldMembers) @@ -127,18 +128,18 @@ object ClosedGroupsProtocolV2 { val encryptionKeyPair = apiDB.getLatestClosedGroupEncryptionKeyPair(groupPublicKey) if (encryptionKeyPair == null) { Log.d("Loki", "Couldn't get encryption key pair for closed group.") - return@Thread deferred.reject(Error.NoKeyPair) + return@queue deferred.reject(Error.NoKeyPair) } val removedMembers = oldMembers.minus(members) if (removedMembers.contains(admins.first()) && members.isNotEmpty()) { Log.d("Loki", "Can't remove admin from closed group unless the group is destroyed entirely.") - return@Thread deferred.reject(Error.InvalidUpdate) + return@queue deferred.reject(Error.InvalidUpdate) } val isUserLeaving = removedMembers.contains(userPublicKey) if (isUserLeaving && members.isNotEmpty()) { if (removedMembers.count() != 1 || newMembers.isNotEmpty()) { Log.d("Loki", "Can't remove self and add or remove others simultaneously.") - return@Thread deferred.reject(Error.InvalidUpdate) + return@queue deferred.reject(Error.InvalidUpdate) } } // Send the update to the group @@ -184,7 +185,7 @@ object ClosedGroupsProtocolV2 { val threadID = DatabaseFactory.getThreadDatabase(context).getOrCreateThreadIdFor(Recipient.from(context, Address.fromSerialized(groupID), false)) insertOutgoingInfoMessage(context, groupID, infoType, name, members, admins, threadID) deferred.resolve(Unit) - }.start() + } return deferred.promise } @@ -407,7 +408,7 @@ object ClosedGroupsProtocolV2 { @JvmStatic @Throws(IOException::class) public fun doubleEncodeGroupID(groupPublicKey: String): String { - return GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(groupPublicKey)) + return GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(Hex.fromStringCondensed(groupPublicKey)).toByteArray()) } @JvmStatic diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/KeyPairUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/KeyPairUtilities.kt index 2000102a05..3c2992d9af 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/KeyPairUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/KeyPairUtilities.kt @@ -7,7 +7,7 @@ import com.goterl.lazycode.lazysodium.utils.Key import com.goterl.lazycode.lazysodium.utils.KeyPair import org.thoughtcrime.securesms.crypto.IdentityKeyUtil import org.session.libsession.utilities.Base64 -import org.thoughtcrime.securesms.util.Hex +import org.session.libsession.utilities.Hex import org.session.libsignal.libsignal.ecc.DjbECPrivateKey import org.session.libsignal.libsignal.ecc.DjbECPublicKey import org.session.libsignal.libsignal.ecc.ECKeyPair diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt index c6a27be6f8..f965f370c4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt @@ -62,7 +62,7 @@ object OpenGroupUtilities { ?: throw IllegalStateException("Public chat API is not initialized!") // Check if open group has a related DB record. - val groupId = GroupUtil.getEncodedOpenGroupID(PublicChat.getId(channel, url)) + val groupId = GroupUtil.getEncodedOpenGroupID(PublicChat.getId(channel, url).toByteArray()) if (!DatabaseFactory.getGroupDatabase(context).hasGroup(groupId)) { throw IllegalStateException("Attempt to update open group info for non-existent DB record: $groupId") } diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java b/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java index 0fdc198bef..a3f6580d95 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java @@ -18,7 +18,7 @@ import network.loki.messenger.R; import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.util.FileProviderUtil; import org.thoughtcrime.securesms.util.FileUtils; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.thoughtcrime.securesms.util.ServiceUtil; import org.session.libsession.utilities.TextSecurePreferences; diff --git a/app/src/main/java/org/thoughtcrime/securesms/stickers/StickerPackPreviewRepository.java b/app/src/main/java/org/thoughtcrime/securesms/stickers/StickerPackPreviewRepository.java index 560e545b44..f1ba56b2de 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/stickers/StickerPackPreviewRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/stickers/StickerPackPreviewRepository.java @@ -14,7 +14,7 @@ import org.thoughtcrime.securesms.database.model.StickerPackRecord; import org.thoughtcrime.securesms.database.model.StickerRecord; import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.session.libsession.utilities.concurrent.SignalExecutors; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.util.guava.Optional; diff --git a/app/src/main/java/org/thoughtcrime/securesms/stickers/StickerRemoteUriFetcher.java b/app/src/main/java/org/thoughtcrime/securesms/stickers/StickerRemoteUriFetcher.java index 078a34297f..e54af7e967 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/stickers/StickerRemoteUriFetcher.java +++ b/app/src/main/java/org/thoughtcrime/securesms/stickers/StickerRemoteUriFetcher.java @@ -7,7 +7,7 @@ import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.data.DataFetcher; import org.thoughtcrime.securesms.logging.Log; -import org.thoughtcrime.securesms.util.Hex; +import org.session.libsession.utilities.Hex; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.service.api.SignalServiceMessageReceiver; diff --git a/libsession/src/main/java/org/session/libsession/messaging/fileserver/FileServerAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/fileserver/FileServerAPI.kt index 750a10824f..a2aa9e2218 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/fileserver/FileServerAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/fileserver/FileServerAPI.kt @@ -1,22 +1,18 @@ package org.session.libsession.messaging.fileserver import nl.komponents.kovenant.Promise -import nl.komponents.kovenant.functional.bind import nl.komponents.kovenant.functional.map import okhttp3.Request import org.session.libsession.messaging.utilities.DotNetAPI import org.session.libsignal.libsignal.logging.Log -import org.session.libsignal.libsignal.util.Hex import org.session.libsignal.service.internal.util.Base64 import org.session.libsignal.service.internal.util.JsonUtil -import org.session.libsignal.service.loki.api.SnodeAPI import org.session.libsignal.service.loki.api.onionrequests.OnionRequestAPI import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol import org.session.libsignal.service.loki.protocol.shelved.multidevice.DeviceLink import org.session.libsignal.service.loki.utilities.* import java.net.URL import java.util.concurrent.ConcurrentHashMap -import kotlin.collections.set class FileServerAPI(public val server: String, userPublicKey: String, userPrivateKey: ByteArray, private val database: LokiAPIDatabaseProtocol) : DotNetAPI() { diff --git a/libsession/src/main/java/org/session/libsession/messaging/messages/Destination.kt b/libsession/src/main/java/org/session/libsession/messaging/messages/Destination.kt index 9036ce47b5..03fb189203 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/messages/Destination.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/messages/Destination.kt @@ -15,7 +15,7 @@ sealed class Destination { if (address.isContact) { return Contact(address.contactIdentifier()) } else if (address.isClosedGroup) { - val groupID = address.contactIdentifier().toByteArray() + val groupID = address.contactIdentifier() val groupPublicKey = GroupUtil.getDecodedGroupID(groupID) return ClosedGroup(groupPublicKey) } else if (address.isOpenGroup) { diff --git a/libsession/src/main/java/org/session/libsession/messaging/opengroups/OpenGroupAPI.kt b/libsession/src/main/java/org/session/libsession/messaging/opengroups/OpenGroupAPI.kt index a271ca2de3..9d0d03750c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/opengroups/OpenGroupAPI.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/opengroups/OpenGroupAPI.kt @@ -9,7 +9,7 @@ import org.session.libsession.messaging.MessagingConfiguration import org.session.libsession.messaging.utilities.DotNetAPI import org.session.libsession.messaging.fileserver.FileServerAPI -import org.session.libsession.utilities.ThreadUtils +import org.session.libsignal.service.loki.utilities.ThreadUtils import org.session.libsession.utilities.createContext import org.session.libsignal.libsignal.logging.Log diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiverHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiverHandler.kt index be294b8246..c28de22a20 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiverHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiverHandler.kt @@ -1,9 +1,6 @@ package org.session.libsession.messaging.sending_receiving import android.text.TextUtils -import com.annimon.stream.Collectors -import com.annimon.stream.Stream -import com.annimon.stream.function.Function import org.session.libsession.messaging.MessagingConfiguration import org.session.libsession.messaging.jobs.AttachmentDownloadJob import org.session.libsession.messaging.jobs.JobQueue @@ -22,10 +19,10 @@ import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel import org.session.libsession.messaging.threads.Address import org.session.libsession.messaging.threads.recipients.Recipient import org.session.libsession.utilities.GroupUtil +import org.session.libsession.utilities.Hex import org.session.libsession.utilities.SSKEnvironment import org.session.libsession.utilities.TextSecurePreferences import org.session.libsignal.libsignal.logging.Log -import org.session.libsignal.libsignal.util.Hex import org.session.libsignal.libsignal.util.guava.Optional import org.session.libsignal.service.api.messages.SignalServiceGroup import org.session.libsignal.service.internal.push.SignalServiceProtos @@ -236,7 +233,7 @@ private fun MessageReceiver.handleNewGroup(message: ClosedGroupUpdate) { MessageSender.requestSenderKey(groupPublicKey, publicKey) } // Create the group - val groupID = GroupUtil.getEncodedClosedGroupID(groupPublicKey) + val groupID = GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(Hex.fromStringCondensed(groupPublicKey)).toByteArray()) //double encoded if (storage.getGroup(groupID) != null) { // Update the group storage.updateTitle(groupID, name) @@ -266,7 +263,7 @@ private fun MessageReceiver.handleGroupUpdate(message: ClosedGroupUpdate) { val members = kind.members.map { it.toHexString() } val admins = kind.admins.map { it.toHexString() } // Get the group - val groupID = GroupUtil.getEncodedClosedGroupID(groupPublicKey) + val groupID = GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(Hex.fromStringCondensed(groupPublicKey)).toByteArray()) //double encoded val group = storage.getGroup(groupID) ?: return Log.d("Loki", "Ignoring closed group info message for nonexistent group.") // Check that the sender is a member of the group (before the update) if (!group.members.contains(Address.fromSerialized(message.sender!!))) { return Log.d("Loki", "Ignoring closed group info message from non-member.") } @@ -326,7 +323,7 @@ private fun MessageReceiver.handleSenderKeyRequest(message: ClosedGroupUpdate) { val sskDatabase = MessagingConfiguration.shared.sskDatabase val userPublicKey = storage.getUserPublicKey()!! val groupPublicKey = kind.groupPublicKey.toHexString() - val groupID = GroupUtil.getEncodedClosedGroupID(groupPublicKey) + val groupID = GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(Hex.fromStringCondensed(groupPublicKey)).toByteArray()) //double encoded val group = storage.getGroup(groupID) if (group == null) { Log.d("Loki", "Ignoring closed group sender key request for nonexistent group.") diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroup.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroup.kt index 08ee03d2c2..23e0d2761f 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroup.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroup.kt @@ -12,11 +12,9 @@ import org.session.libsession.messaging.sending_receiving.notifications.PushNoti import org.session.libsession.messaging.sending_receiving.MessageSender.Error import org.session.libsession.messaging.threads.Address import org.session.libsession.utilities.GroupUtil -import org.session.libsession.utilities.SSKEnvironment - +import org.session.libsession.utilities.Hex import org.session.libsignal.libsignal.ecc.Curve -import org.session.libsignal.libsignal.util.Hex import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupRatchetCollectionType import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey @@ -45,7 +43,7 @@ fun MessageSender.createClosedGroup(name: String, members: Collection): // Create the group val admins = setOf( userPublicKey ) val adminsAsData = admins.map { Hex.fromStringCondensed(it) } - val groupID = GroupUtil.getEncodedClosedGroupID(groupPublicKey) + val groupID = GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(Hex.fromStringCondensed(groupPublicKey)).toByteArray()) //double encoded storage.createGroup(groupID, name, LinkedList(members.map { Address.fromSerialized(it) }), null, null, LinkedList(admins.map { Address.fromSerialized(it) })) storage.setProfileSharing(Address.fromSerialized(groupID), true) // Send a closed group update message to all members using established channels @@ -79,7 +77,7 @@ fun MessageSender.update(groupPublicKey: String, members: Collection, na val storage = MessagingConfiguration.shared.storage val userPublicKey = storage.getUserPublicKey()!! val sskDatabase = MessagingConfiguration.shared.sskDatabase - val groupID = GroupUtil.getEncodedClosedGroupID(groupPublicKey) + val groupID = GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(Hex.fromStringCondensed(groupPublicKey)).toByteArray()) // double encoded val group = storage.getGroup(groupID) if (group == null) { Log.d("Loki", "Can't update nonexistent closed group.") @@ -206,7 +204,7 @@ fun MessageSender.update(groupPublicKey: String, members: Collection, na fun MessageSender.leave(groupPublicKey: String) { val storage = MessagingConfiguration.shared.storage val userPublicKey = storage.getUserPublicKey()!! - val groupID = GroupUtil.getEncodedClosedGroupID(groupPublicKey) + val groupID = GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(Hex.fromStringCondensed(groupPublicKey)).toByteArray()) // double encoded val group = storage.getGroup(groupID) if (group == null) { Log.d("Loki", "Can't leave nonexistent closed group.") diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderEncryption.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderEncryption.kt index 7ee8a47f8a..43a61a0d25 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderEncryption.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderEncryption.kt @@ -1,56 +1,11 @@ package org.session.libsession.messaging.sending_receiving -import com.google.protobuf.ByteString import org.session.libsession.messaging.MessagingConfiguration -import org.session.libsession.messaging.messages.Message -import org.session.libsession.messaging.sending_receiving.MessageSender.Error -import org.session.libsession.messaging.utilities.UnidentifiedAccessUtil -import org.session.libsession.utilities.AESGCM - -import org.session.libsignal.libsignal.SignalProtocolAddress -import org.session.libsignal.libsignal.loki.ClosedGroupCiphertextMessage -import org.session.libsignal.libsignal.util.Hex -import org.session.libsignal.libsignal.util.guava.Optional -import org.session.libsignal.service.api.crypto.SignalServiceCipher -import org.session.libsignal.service.api.push.SignalServiceAddress -import org.session.libsignal.service.internal.push.SignalServiceProtos -import org.session.libsignal.service.internal.util.Base64 -import org.session.libsignal.service.loki.protocol.closedgroups.SharedSenderKeysImplementation -import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded object MessageSenderEncryption { - /*internal fun encryptWithSignalProtocol(plaintext: ByteArray, message: Message, recipientPublicKey: String): ByteArray{ - val storage = MessagingConfiguration.shared.signalStorage - val sskDatabase = MessagingConfiguration.shared.sskDatabase - val sessionResetImp = MessagingConfiguration.shared.sessionResetImp - val localAddress = SignalServiceAddress(recipientPublicKey) - val certificateValidator = MessagingConfiguration.shared.certificateValidator - val cipher = SignalServiceCipher(localAddress, storage, sskDatabase, sessionResetImp, certificateValidator) - val signalProtocolAddress = SignalProtocolAddress(recipientPublicKey, 1) - val unidentifiedAccessPair = UnidentifiedAccessUtil.getAccessFor(recipientPublicKey) - val unidentifiedAccess = if (unidentifiedAccessPair != null) unidentifiedAccessPair.targetUnidentifiedAccess else Optional.absent() - val encryptedMessage = cipher.encrypt(signalProtocolAddress, unidentifiedAccess, plaintext) - return Base64.decode(encryptedMessage.content) - }*/ - internal fun encryptWithSessionProtocol(plaintext: ByteArray, recipientPublicKey: String): ByteArray{ return MessagingConfiguration.shared.sessionProtocol.encrypt(plaintext, recipientPublicKey) } - /*internal fun encryptWithSharedSenderKeys(plaintext: ByteArray, groupPublicKey: String): ByteArray { - // 1. ) Encrypt the data with the user's sender key - val userPublicKey = MessagingConfiguration.shared.storage.getUserPublicKey() ?: throw Error.NoUserPublicKey - val ciphertextAndKeyIndex = SharedSenderKeysImplementation.shared.encrypt(plaintext, groupPublicKey, userPublicKey) - val ivAndCiphertext = ciphertextAndKeyIndex.first - val keyIndex = ciphertextAndKeyIndex.second - val encryptedMessage = ClosedGroupCiphertextMessage(ivAndCiphertext, Hex.fromStringCondensed(userPublicKey), keyIndex); - // 2. ) Encrypt the result for the group's public key to hide the sender public key and key index - val intermediate = AESGCM.encrypt(encryptedMessage.serialize(), groupPublicKey.removing05PrefixIfNeeded()) - // 3. ) Wrap the result - return SignalServiceProtos.ClosedGroupCiphertextMessageWrapper.newBuilder() - .setCiphertext(ByteString.copyFrom(intermediate.ciphertext)) - .setEphemeralPublicKey(ByteString.copyFrom(intermediate.ephemeralPublicKey)) - .build().toByteArray() - }*/ } \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt index 6ce52dd8fe..1f618801de 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt @@ -111,7 +111,7 @@ class OpenGroupPoller(private val openGroup: OpenGroup) { return "${rawDisplayName} (${senderPublicKey.takeLast(8)})" } val senderDisplayName = MessagingConfiguration.shared.storage.getOpenGroupDisplayName(senderPublicKey, openGroup.channel, openGroup.server) ?: generateDisplayName("Anonymous") - val id = GroupUtil.getEncodedOpenGroupIDAsData(openGroup.id) + val id = openGroup.id.toByteArray() // Main message val dataMessageProto = DataMessage.newBuilder() val body = if (message.body == message.timestamp.toString()) { "" } else { message.body } diff --git a/libsession/src/main/java/org/session/libsession/messaging/threads/Address.kt b/libsession/src/main/java/org/session/libsession/messaging/threads/Address.kt index 249cc50350..72291a8a2c 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/threads/Address.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/threads/Address.kt @@ -5,9 +5,7 @@ import android.os.Parcel import android.os.Parcelable import android.util.Pair import androidx.annotation.VisibleForTesting -import org.session.libsession.utilities.DelimiterUtil.escape -import org.session.libsession.utilities.DelimiterUtil.split -import org.session.libsession.utilities.DelimiterUtil.unescape +import org.session.libsession.utilities.DelimiterUtil import org.session.libsession.utilities.GroupUtil import org.session.libsignal.libsignal.util.guava.Optional import org.session.libsignal.service.internal.util.Util @@ -163,10 +161,10 @@ class Address private constructor(address: String) : Parcelable, Comparable { - val escapedAddresses = split(serialized, delimiter) + val escapedAddresses = DelimiterUtil.split(serialized, delimiter) val addresses: MutableList
= LinkedList() for (escapedAddress in escapedAddresses) { - addresses.add(fromSerialized(unescape(escapedAddress, delimiter))) + addresses.add(fromSerialized(DelimiterUtil.unescape(escapedAddress, delimiter))) } return addresses } @@ -175,7 +173,7 @@ class Address private constructor(address: String) : Parcelable, Comparable = LinkedList() for (address in addresses) { - escapedAddresses.add(escape(address.serialize(), delimiter)) + escapedAddresses.add(DelimiterUtil.escape(address.serialize(), delimiter)) } return Util.join(escapedAddresses, delimiter.toString() + "") } diff --git a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt index 48a9b71bcb..46e270e362 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt @@ -14,7 +14,7 @@ import org.session.libsignal.service.loki.api.* import org.session.libsignal.service.loki.api.fileserver.FileServerAPI import org.session.libsignal.service.loki.api.utilities.* import org.session.libsession.utilities.AESGCM.EncryptionResult -import org.session.libsession.utilities.ThreadUtils +import org.session.libsignal.service.loki.utilities.ThreadUtils import org.session.libsession.utilities.getBodyForOnionRequest import org.session.libsession.utilities.getHeadersForOnionRequest import org.session.libsignal.service.loki.utilities.* diff --git a/libsession/src/main/java/org/session/libsession/snode/OnionRequestEncryption.kt b/libsession/src/main/java/org/session/libsession/snode/OnionRequestEncryption.kt index b9fe4f57e0..6cf4f47111 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestEncryption.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestEncryption.kt @@ -5,7 +5,7 @@ import nl.komponents.kovenant.deferred import org.session.libsignal.service.internal.util.JsonUtil import org.session.libsession.utilities.AESGCM.EncryptionResult import org.session.libsession.utilities.AESGCM -import org.session.libsession.utilities.ThreadUtils +import org.session.libsignal.service.loki.utilities.ThreadUtils import org.session.libsignal.service.loki.utilities.toHexString import java.nio.Buffer import java.nio.ByteBuffer diff --git a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt index 85c40e51d2..2973931c70 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -7,7 +7,7 @@ import nl.komponents.kovenant.functional.bind import nl.komponents.kovenant.functional.map import org.session.libsession.snode.utilities.getRandomElement -import org.session.libsession.utilities.ThreadUtils +import org.session.libsignal.service.loki.utilities.ThreadUtils import org.session.libsession.utilities.createContext import org.session.libsignal.libsignal.logging.Log diff --git a/libsession/src/main/java/org/session/libsession/utilities/AESGCM.kt b/libsession/src/main/java/org/session/libsession/utilities/AESGCM.kt index 7d2c616c23..666ee50591 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/AESGCM.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/AESGCM.kt @@ -2,7 +2,6 @@ package org.session.libsession.utilities import org.whispersystems.curve25519.Curve25519 import org.session.libsignal.libsignal.util.ByteUtil -import org.session.libsignal.libsignal.util.Hex import org.session.libsignal.service.internal.util.Util import javax.crypto.Cipher import javax.crypto.Mac diff --git a/libsession/src/main/java/org/session/libsession/utilities/DelimiterUtil.kt b/libsession/src/main/java/org/session/libsession/utilities/DelimiterUtil.kt index 24ae265757..7511874faf 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/DelimiterUtil.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/DelimiterUtil.kt @@ -14,8 +14,8 @@ object DelimiterUtil { } @JvmStatic - fun split(value: String, delimiter: Char): Array { - val regex = "(? { + val regex = Regex("(? 1) { + return groupID.split("!", limit = 2)[1] + } + return groupID } @JvmStatic fun getDecodedGroupID(groupID: String): String { - if (groupID.split("!").count() > 1) { - return groupID.split("!")[1] - } - return groupID.split("!")[0] - } - - @JvmStatic - fun getDecodedGroupID(groupID: ByteArray): String { - val encodedGroupID = Hex.toStringCondensed(groupID) - return getDecodedGroupID(encodedGroupID) + return String(getDecodedGroupIDAsData(groupID)) } @JvmStatic fun getDecodedGroupIDAsData(groupID: String): ByteArray { - return Hex.fromStringCondensed(getDecodedGroupID(groupID)) + return Hex.fromStringCondensed(splitEncodedGroupID(groupID)) } fun isEncodedGroup(groupId: String): Boolean { diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/Hex.java b/libsession/src/main/java/org/session/libsession/utilities/Hex.java similarity index 98% rename from app/src/main/java/org/thoughtcrime/securesms/util/Hex.java rename to libsession/src/main/java/org/session/libsession/utilities/Hex.java index a2142fbbf5..a731b506fd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/Hex.java +++ b/libsession/src/main/java/org/session/libsession/utilities/Hex.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.thoughtcrime.securesms.util; +package org.session.libsession.utilities; import java.io.IOException; diff --git a/libsession/src/main/java/org/session/libsession/utilities/PromiseUtilities.kt b/libsession/src/main/java/org/session/libsession/utilities/PromiseUtilities.kt index 225611d8b3..b3c5cd9180 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/PromiseUtilities.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/PromiseUtilities.kt @@ -7,6 +7,7 @@ import nl.komponents.kovenant.Promise import nl.komponents.kovenant.deferred import nl.komponents.kovenant.jvm.asDispatcher import org.session.libsignal.libsignal.logging.Log +import org.session.libsignal.service.loki.utilities.ThreadUtils import java.util.concurrent.Executors import java.util.concurrent.TimeoutException diff --git a/libsession/src/main/java/org/session/libsession/utilities/ThreadUtils.kt b/libsession/src/main/java/org/session/libsession/utilities/ThreadUtils.kt deleted file mode 100644 index e952d76008..0000000000 --- a/libsession/src/main/java/org/session/libsession/utilities/ThreadUtils.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.session.libsession.utilities - -import java.util.concurrent.* - -object ThreadUtils { - - internal val executorPool = Executors.newCachedThreadPool() - - @JvmStatic - fun queue(target: Runnable) { - executorPool.execute(target) - } - - fun queue(target: () -> Unit) { - executorPool.execute(target) - } - - @JvmStatic - fun newDynamicSingleThreadedExecutor(): ExecutorService { - val executor = ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, - LinkedBlockingQueue()) - executor.allowCoreThreadTimeOut(true) - return executor - } - -} \ No newline at end of file diff --git a/libsignal/src/main/java/org/session/libsignal/libsignal/util/Hex.java b/libsignal/src/main/java/org/session/libsignal/libsignal/util/Hex.java index 7d75a2ea4a..fd1fad075f 100644 --- a/libsignal/src/main/java/org/session/libsignal/libsignal/util/Hex.java +++ b/libsignal/src/main/java/org/session/libsignal/libsignal/util/Hex.java @@ -59,7 +59,6 @@ public class Hex { } private static void appendHexChar(StringBuffer buf, int b) { - buf.append("(byte)0x"); buf.append(HEX_DIGITS[(b >> 4) & 0xf]); buf.append(HEX_DIGITS[b & 0xf]); } diff --git a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/ThreadUtils.kt b/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/ThreadUtils.kt index 8d102afd74..a7c56008e0 100644 --- a/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/ThreadUtils.kt +++ b/libsignal/src/main/java/org/session/libsignal/service/loki/utilities/ThreadUtils.kt @@ -1,18 +1,26 @@ package org.session.libsignal.service.loki.utilities -import java.util.concurrent.Executors +import java.util.concurrent.* object ThreadUtils { - internal val executorPool = Executors.newCachedThreadPool() + val executorPool = Executors.newCachedThreadPool() @JvmStatic fun queue(target: Runnable) { executorPool.execute(target) } - fun queue(target: ()->Unit) { + fun queue(target: () -> Unit) { executorPool.execute(target) } + @JvmStatic + fun newDynamicSingleThreadedExecutor(): ExecutorService { + val executor = ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, + LinkedBlockingQueue()) + executor.allowCoreThreadTimeOut(true) + return executor + } + } \ No newline at end of file