mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
fix closed groups & clean
This commit is contained in:
parent
13f94c2cfd
commit
3b50b8f40b
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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, ','));
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.*
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<String>): Promise<String, Exception> {
|
||||
val deferred = deferred<String, Exception>()
|
||||
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<String>, name: String): Promise<Unit, Exception> {
|
||||
val deferred = deferred<Unit, Exception>()
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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() {
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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.")
|
||||
|
@ -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<String>):
|
||||
// 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<String>, 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<String>, 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.")
|
||||
|
@ -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()
|
||||
}*/
|
||||
}
|
@ -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 }
|
||||
|
@ -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<Addr
|
||||
}
|
||||
|
||||
fun fromSerializedList(serialized: String, delimiter: Char): List<Address> {
|
||||
val escapedAddresses = split(serialized, delimiter)
|
||||
val escapedAddresses = DelimiterUtil.split(serialized, delimiter)
|
||||
val addresses: MutableList<Address> = 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<Addr
|
||||
Collections.sort(addresses)
|
||||
val escapedAddresses: MutableList<String> = LinkedList()
|
||||
for (address in addresses) {
|
||||
escapedAddresses.add(escape(address.serialize(), delimiter))
|
||||
escapedAddresses.add(DelimiterUtil.escape(address.serialize(), delimiter))
|
||||
}
|
||||
return Util.join(escapedAddresses, delimiter.toString() + "")
|
||||
}
|
||||
|
@ -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.*
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -14,8 +14,8 @@ object DelimiterUtil {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun split(value: String, delimiter: Char): Array<String> {
|
||||
val regex = "(?<!\\\\)" + Pattern.quote(delimiter.toString() + "")
|
||||
return value.split(regex).toTypedArray()
|
||||
fun split(value: String, delimiter: Char): List<String> {
|
||||
val regex = Regex("(?<!\\\\)" + Pattern.quote(delimiter + ""))
|
||||
return value.split(regex)
|
||||
}
|
||||
}
|
@ -1,15 +1,6 @@
|
||||
package org.session.libsession.utilities
|
||||
|
||||
import android.content.Context
|
||||
import org.session.libsession.messaging.threads.Address.Companion.fromSerialized
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient
|
||||
import org.session.libsession.messaging.threads.recipients.RecipientModifiedListener
|
||||
import org.session.libsignal.libsignal.logging.Log
|
||||
import org.session.libsignal.libsignal.util.Hex
|
||||
import org.session.libsignal.service.api.messages.SignalServiceGroup
|
||||
import org.session.libsignal.service.internal.push.SignalServiceProtos.GroupContext
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
object GroupUtil {
|
||||
const val CLOSED_GROUP_PREFIX = "__textsecure_group__!"
|
||||
@ -17,66 +8,44 @@ object GroupUtil {
|
||||
const val OPEN_GROUP_PREFIX = "__loki_public_chat_group__!"
|
||||
|
||||
@JvmStatic
|
||||
fun getEncodedOpenGroupID(groupID: String): String {
|
||||
return OPEN_GROUP_PREFIX + groupID
|
||||
}
|
||||
|
||||
fun getEncodedOpenGroupIDAsData(groupID: String): ByteArray {
|
||||
return Hex.fromStringCondensed(getEncodedOpenGroupID(groupID))
|
||||
fun getEncodedOpenGroupID(groupID: ByteArray): String {
|
||||
return OPEN_GROUP_PREFIX + Hex.toStringCondensed(groupID)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getEncodedClosedGroupID(groupID: ByteArray): String {
|
||||
return getEncodedClosedGroupID(Hex.toStringCondensed(groupID))
|
||||
}
|
||||
|
||||
fun getEncodedClosedGroupID(groupID: String): String {
|
||||
return CLOSED_GROUP_PREFIX + groupID
|
||||
}
|
||||
|
||||
fun getEncodedClosedGroupIDAsData(groupID: String): ByteArray {
|
||||
return Hex.fromStringCondensed(getEncodedClosedGroupID(groupID))
|
||||
return CLOSED_GROUP_PREFIX + Hex.toStringCondensed(groupID)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getEncodedMMSGroupID(groupID: ByteArray): String {
|
||||
return getEncodedMMSGroupID(Hex.toStringCondensed(groupID))
|
||||
}
|
||||
|
||||
fun getEncodedMMSGroupID(groupID: String): String {
|
||||
return MMS_GROUP_PREFIX + groupID
|
||||
}
|
||||
|
||||
fun getEncodedMMSGroupIDAsData(groupID: String): ByteArray {
|
||||
return (MMS_GROUP_PREFIX + groupID).toByteArray()
|
||||
return MMS_GROUP_PREFIX + Hex.toStringCondensed(groupID)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getEncodedId(group: SignalServiceGroup): String {
|
||||
val groupId = group.groupId
|
||||
if (group.groupType == SignalServiceGroup.GroupType.PUBLIC_CHAT) {
|
||||
return getEncodedOpenGroupID(String(groupId))
|
||||
return getEncodedOpenGroupID(groupId)
|
||||
}
|
||||
return getEncodedClosedGroupID(Hex.toStringCondensed(groupId))
|
||||
return getEncodedClosedGroupID(groupId)
|
||||
}
|
||||
|
||||
private fun splitEncodedGroupID(groupID: String): String {
|
||||
if (groupID.split("!").count() > 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 {
|
||||
|
@ -14,7 +14,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.util;
|
||||
package org.session.libsession.utilities;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
@ -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]);
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user