|
|
|
@ -37,8 +37,6 @@ import java.io.IOException
|
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
object ClosedGroupsProtocol {
|
|
|
|
|
val isSharedSenderKeysEnabled = true
|
|
|
|
|
val groupSizeLimit = 20
|
|
|
|
|
|
|
|
|
|
sealed class Error(val description: String) : Exception() {
|
|
|
|
|
object NoThread : Error("Couldn't find a thread associated with the given group public key")
|
|
|
|
@ -46,54 +44,8 @@ object ClosedGroupsProtocol {
|
|
|
|
|
object InvalidUpdate : Error("Invalid group update.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public fun createClosedGroup(context: Context, name: String, members: Collection<String>): Promise<String, Exception> {
|
|
|
|
|
val deferred = deferred<String, Exception>()
|
|
|
|
|
Thread {
|
|
|
|
|
// Prepare
|
|
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
|
|
|
|
// Generate a key pair for the group
|
|
|
|
|
val groupKeyPair = Curve.generateKeyPair()
|
|
|
|
|
val groupPublicKey = groupKeyPair.hexEncodedPublicKey // Includes the "05" prefix
|
|
|
|
|
val membersAsData = members.map { Hex.fromStringCondensed(it) }
|
|
|
|
|
// Create ratchets for all members
|
|
|
|
|
val senderKeys: List<ClosedGroupSenderKey> = members.map { publicKey ->
|
|
|
|
|
val ratchet = SharedSenderKeysImplementation.shared.generateRatchet(groupPublicKey, publicKey)
|
|
|
|
|
ClosedGroupSenderKey(Hex.fromStringCondensed(ratchet.chainKey), ratchet.keyIndex, Hex.fromStringCondensed(publicKey))
|
|
|
|
|
}
|
|
|
|
|
// Create the group
|
|
|
|
|
val groupID = doubleEncodeGroupID(groupPublicKey)
|
|
|
|
|
val admins = setOf(userPublicKey)
|
|
|
|
|
DatabaseFactory.getGroupDatabase(context).create(groupID, name, LinkedList<Address>(members.map { Address.fromSerialized(it) }),
|
|
|
|
|
null, null, LinkedList<Address>(admins.map { Address.fromSerialized(it) }))
|
|
|
|
|
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(Recipient.from(context, Address.fromSerialized(groupID), false), true)
|
|
|
|
|
// Establish sessions if needed
|
|
|
|
|
establishSessionsWithMembersIfNeeded(context, members)
|
|
|
|
|
// Send a closed group update message to all members using established channels
|
|
|
|
|
val adminsAsData = admins.map { Hex.fromStringCondensed(it) }
|
|
|
|
|
val closedGroupUpdateKind = ClosedGroupUpdateMessageSendJob.Kind.New(Hex.fromStringCondensed(groupPublicKey), name, groupKeyPair.privateKey.serialize(),
|
|
|
|
|
senderKeys, membersAsData, adminsAsData)
|
|
|
|
|
for (member in members) {
|
|
|
|
|
if (member == userPublicKey) { continue }
|
|
|
|
|
val job = ClosedGroupUpdateMessageSendJob(member, closedGroupUpdateKind)
|
|
|
|
|
job.setContext(context)
|
|
|
|
|
job.onRun() // Run the job immediately to make all of this sync
|
|
|
|
|
}
|
|
|
|
|
// Add the group to the user's set of public keys to poll for
|
|
|
|
|
DatabaseFactory.getSSKDatabase(context).setClosedGroupPrivateKey(groupPublicKey, groupKeyPair.hexEncodedPrivateKey)
|
|
|
|
|
// Notify the user
|
|
|
|
|
val threadID = DatabaseFactory.getThreadDatabase(context).getOrCreateThreadIdFor(Recipient.from(context, Address.fromSerialized(groupID), false))
|
|
|
|
|
insertOutgoingInfoMessage(context, groupID, GroupContext.Type.UPDATE, name, members, admins, threadID)
|
|
|
|
|
// Notify the PN server
|
|
|
|
|
LokiPushNotificationManager.performOperation(context, ClosedGroupOperation.Subscribe, groupPublicKey, userPublicKey)
|
|
|
|
|
// Fulfill the promise
|
|
|
|
|
deferred.resolve(groupID)
|
|
|
|
|
}.start()
|
|
|
|
|
// Return
|
|
|
|
|
return deferred.promise
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
|
public fun leave(context: Context, groupPublicKey: String) {
|
|
|
|
|
fun leave(context: Context, groupPublicKey: String) {
|
|
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
|
|
|
|
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
|
|
|
|
val groupID = doubleEncodeGroupID(groupPublicKey)
|
|
|
|
@ -108,7 +60,7 @@ object ClosedGroupsProtocol {
|
|
|
|
|
return update(context, groupPublicKey, newMembers, name).get()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public fun update(context: Context, groupPublicKey: String, members: Collection<String>, name: String): Promise<Unit, Exception> {
|
|
|
|
|
fun update(context: Context, groupPublicKey: String, members: Collection<String>, name: String): Promise<Unit, Exception> {
|
|
|
|
|
val deferred = deferred<Unit, Exception>()
|
|
|
|
|
Thread {
|
|
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
|
|
|
@ -237,7 +189,7 @@ object ClosedGroupsProtocol {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
|
public fun requestSenderKey(context: Context, groupPublicKey: String, senderPublicKey: String) {
|
|
|
|
|
fun requestSenderKey(context: Context, groupPublicKey: String, senderPublicKey: String) {
|
|
|
|
|
Log.d("Loki", "Requesting sender key for group public key: $groupPublicKey, sender public key: $senderPublicKey.")
|
|
|
|
|
// Establish session if needed
|
|
|
|
|
ApplicationContext.getInstance(context).sendSessionRequestIfNeeded(senderPublicKey)
|
|
|
|
@ -247,218 +199,6 @@ object ClosedGroupsProtocol {
|
|
|
|
|
ApplicationContext.getInstance(context).jobManager.add(job)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
|
public fun handleSharedSenderKeysUpdate(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) {
|
|
|
|
|
if (!isValid(closedGroupUpdate)) { return; }
|
|
|
|
|
when (closedGroupUpdate.type) {
|
|
|
|
|
SignalServiceProtos.ClosedGroupUpdate.Type.NEW -> handleNewClosedGroup(context, closedGroupUpdate, senderPublicKey)
|
|
|
|
|
SignalServiceProtos.ClosedGroupUpdate.Type.INFO -> handleClosedGroupUpdate(context, closedGroupUpdate, senderPublicKey)
|
|
|
|
|
SignalServiceProtos.ClosedGroupUpdate.Type.SENDER_KEY_REQUEST -> handleSenderKeyRequest(context, closedGroupUpdate, senderPublicKey)
|
|
|
|
|
SignalServiceProtos.ClosedGroupUpdate.Type.SENDER_KEY -> handleSenderKey(context, closedGroupUpdate, senderPublicKey)
|
|
|
|
|
else -> {
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun isValid(closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate): Boolean {
|
|
|
|
|
if (closedGroupUpdate.groupPublicKey.isEmpty) { return false }
|
|
|
|
|
when (closedGroupUpdate.type) {
|
|
|
|
|
SignalServiceProtos.ClosedGroupUpdate.Type.NEW -> {
|
|
|
|
|
return !closedGroupUpdate.name.isNullOrEmpty() && !(closedGroupUpdate.groupPrivateKey
|
|
|
|
|
?: ByteString.copyFrom(ByteArray(0))).isEmpty
|
|
|
|
|
&& closedGroupUpdate.membersCount > 0 && closedGroupUpdate.adminsCount > 0 // senderKeys may be empty
|
|
|
|
|
}
|
|
|
|
|
SignalServiceProtos.ClosedGroupUpdate.Type.INFO -> {
|
|
|
|
|
return !closedGroupUpdate.name.isNullOrEmpty() && closedGroupUpdate.membersCount > 0 && closedGroupUpdate.adminsCount > 0 // senderKeys may be empty
|
|
|
|
|
}
|
|
|
|
|
SignalServiceProtos.ClosedGroupUpdate.Type.SENDER_KEY_REQUEST -> return true
|
|
|
|
|
SignalServiceProtos.ClosedGroupUpdate.Type.SENDER_KEY -> return closedGroupUpdate.senderKeysCount > 0
|
|
|
|
|
else -> return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public fun handleNewClosedGroup(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) {
|
|
|
|
|
// Prepare
|
|
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
|
|
|
|
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
|
|
|
|
// Unwrap the message
|
|
|
|
|
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
|
|
|
|
val name = closedGroupUpdate.name
|
|
|
|
|
val groupPrivateKey = closedGroupUpdate.groupPrivateKey.toByteArray()
|
|
|
|
|
val senderKeys = closedGroupUpdate.senderKeysList.map {
|
|
|
|
|
ClosedGroupSenderKey(it.chainKey.toByteArray(), it.keyIndex, it.publicKey.toByteArray())
|
|
|
|
|
}
|
|
|
|
|
val members = closedGroupUpdate.membersList.map { it.toByteArray().toHexString() }
|
|
|
|
|
val admins = closedGroupUpdate.adminsList.map { it.toByteArray().toHexString() }
|
|
|
|
|
// Persist the ratchets
|
|
|
|
|
senderKeys.forEach { senderKey ->
|
|
|
|
|
if (!members.contains(senderKey.publicKey.toHexString())) { return@forEach }
|
|
|
|
|
val ratchet = ClosedGroupRatchet(senderKey.chainKey.toHexString(), senderKey.keyIndex, listOf())
|
|
|
|
|
sskDatabase.setClosedGroupRatchet(groupPublicKey, senderKey.publicKey.toHexString(), ratchet, ClosedGroupRatchetCollectionType.Current)
|
|
|
|
|
}
|
|
|
|
|
// Sort out any discrepancies between the provided sender keys and what's required
|
|
|
|
|
val missingSenderKeys = members.toSet().subtract(senderKeys.map { Hex.toStringCondensed(it.publicKey) })
|
|
|
|
|
if (missingSenderKeys.contains(userPublicKey)) {
|
|
|
|
|
establishSessionsWithMembersIfNeeded(context, members)
|
|
|
|
|
val userRatchet = SharedSenderKeysImplementation.shared.generateRatchet(groupPublicKey, userPublicKey)
|
|
|
|
|
val userSenderKey = ClosedGroupSenderKey(Hex.fromStringCondensed(userRatchet.chainKey), userRatchet.keyIndex, Hex.fromStringCondensed(userPublicKey))
|
|
|
|
|
for (member in members) {
|
|
|
|
|
if (member == userPublicKey) { continue }
|
|
|
|
|
@Suppress("NAME_SHADOWING")
|
|
|
|
|
val closedGroupUpdateKind = ClosedGroupUpdateMessageSendJob.Kind.SenderKey(Hex.fromStringCondensed(groupPublicKey), userSenderKey)
|
|
|
|
|
@Suppress("NAME_SHADOWING")
|
|
|
|
|
val job = ClosedGroupUpdateMessageSendJob(member, closedGroupUpdateKind)
|
|
|
|
|
ApplicationContext.getInstance(context).jobManager.add(job)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (publicKey in missingSenderKeys.minus(userPublicKey)) {
|
|
|
|
|
requestSenderKey(context, groupPublicKey, publicKey)
|
|
|
|
|
}
|
|
|
|
|
// Create the group
|
|
|
|
|
val groupID = doubleEncodeGroupID(groupPublicKey)
|
|
|
|
|
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
|
|
|
|
if (groupDB.getGroup(groupID).orNull() != null) {
|
|
|
|
|
// Update the group
|
|
|
|
|
groupDB.updateTitle(groupID, name)
|
|
|
|
|
groupDB.updateMembers(groupID, members.map { Address.fromSerialized(it) })
|
|
|
|
|
} else {
|
|
|
|
|
groupDB.create(groupID, name, LinkedList<Address>(members.map { Address.fromSerialized(it) }),
|
|
|
|
|
null, null, LinkedList<Address>(admins.map { Address.fromSerialized(it) }))
|
|
|
|
|
}
|
|
|
|
|
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(Recipient.from(context, Address.fromSerialized(groupID), false), true)
|
|
|
|
|
// Add the group to the user's set of public keys to poll for
|
|
|
|
|
sskDatabase.setClosedGroupPrivateKey(groupPublicKey, groupPrivateKey.toHexString())
|
|
|
|
|
// Notify the user
|
|
|
|
|
insertIncomingInfoMessage(context, senderPublicKey, groupID, GroupContext.Type.UPDATE, SignalServiceGroup.Type.UPDATE, name, members, admins)
|
|
|
|
|
// Establish sessions if needed
|
|
|
|
|
establishSessionsWithMembersIfNeeded(context, members)
|
|
|
|
|
// Notify the PN server
|
|
|
|
|
LokiPushNotificationManager.performOperation(context, ClosedGroupOperation.Subscribe, groupPublicKey, userPublicKey)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public fun handleClosedGroupUpdate(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) {
|
|
|
|
|
// Prepare
|
|
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
|
|
|
|
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
|
|
|
|
// Unwrap the message
|
|
|
|
|
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
|
|
|
|
val name = closedGroupUpdate.name
|
|
|
|
|
val senderKeys = closedGroupUpdate.senderKeysList.map {
|
|
|
|
|
ClosedGroupSenderKey(it.chainKey.toByteArray(), it.keyIndex, it.publicKey.toByteArray())
|
|
|
|
|
}
|
|
|
|
|
val members = closedGroupUpdate.membersList.map { it.toByteArray().toHexString() }
|
|
|
|
|
val admins = closedGroupUpdate.adminsList.map { it.toByteArray().toHexString() }
|
|
|
|
|
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
|
|
|
|
val groupID = doubleEncodeGroupID(groupPublicKey)
|
|
|
|
|
val group = groupDB.getGroup(groupID).orNull()
|
|
|
|
|
if (group == null) {
|
|
|
|
|
Log.d("Loki", "Ignoring closed group info message for nonexistent group.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
val oldMembers = group.members.map { it.serialize() }
|
|
|
|
|
// Check that the sender is a member of the group (before the update)
|
|
|
|
|
if (!oldMembers.contains(senderPublicKey)) {
|
|
|
|
|
Log.d("Loki", "Ignoring closed group info message from non-member.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// Store the ratchets for any new members (it's important that this happens before the code below)
|
|
|
|
|
senderKeys.forEach { senderKey ->
|
|
|
|
|
val ratchet = ClosedGroupRatchet(senderKey.chainKey.toHexString(), senderKey.keyIndex, listOf())
|
|
|
|
|
sskDatabase.setClosedGroupRatchet(groupPublicKey, senderKey.publicKey.toHexString(), ratchet, ClosedGroupRatchetCollectionType.Current)
|
|
|
|
|
}
|
|
|
|
|
// Delete all ratchets and either:
|
|
|
|
|
// • Send out the user's new ratchet using established channels if other members of the group left or were removed
|
|
|
|
|
// • Remove the group from the user's set of public keys to poll for if the current user was among the members that were removed
|
|
|
|
|
val wasCurrentUserRemoved = !members.contains(userPublicKey)
|
|
|
|
|
val wasAnyUserRemoved = members.toSet().intersect(oldMembers) != oldMembers.toSet()
|
|
|
|
|
val wasSenderRemoved = !members.contains(senderPublicKey)
|
|
|
|
|
if (wasAnyUserRemoved) {
|
|
|
|
|
val allOldRatchets = sskDatabase.getAllClosedGroupRatchets(groupPublicKey, ClosedGroupRatchetCollectionType.Current)
|
|
|
|
|
for (pair in allOldRatchets) {
|
|
|
|
|
@Suppress("NAME_SHADOWING") val senderPublicKey = pair.first
|
|
|
|
|
val ratchet = pair.second
|
|
|
|
|
val collection = ClosedGroupRatchetCollectionType.Old
|
|
|
|
|
sskDatabase.setClosedGroupRatchet(groupPublicKey, senderPublicKey, ratchet, collection)
|
|
|
|
|
}
|
|
|
|
|
sskDatabase.removeAllClosedGroupRatchets(groupPublicKey, ClosedGroupRatchetCollectionType.Current)
|
|
|
|
|
if (wasCurrentUserRemoved) {
|
|
|
|
|
sskDatabase.removeClosedGroupPrivateKey(groupPublicKey)
|
|
|
|
|
groupDB.setActive(groupID, false)
|
|
|
|
|
groupDB.removeMember(groupID, Address.fromSerialized(userPublicKey))
|
|
|
|
|
// Notify the PN server
|
|
|
|
|
LokiPushNotificationManager.performOperation(context, ClosedGroupOperation.Unsubscribe, groupPublicKey, userPublicKey)
|
|
|
|
|
} else {
|
|
|
|
|
establishSessionsWithMembersIfNeeded(context, members)
|
|
|
|
|
val userRatchet = SharedSenderKeysImplementation.shared.generateRatchet(groupPublicKey, userPublicKey)
|
|
|
|
|
val userSenderKey = ClosedGroupSenderKey(Hex.fromStringCondensed(userRatchet.chainKey), userRatchet.keyIndex, Hex.fromStringCondensed(userPublicKey))
|
|
|
|
|
for (member in members) {
|
|
|
|
|
if (member == userPublicKey) { continue }
|
|
|
|
|
val closedGroupUpdateKind = ClosedGroupUpdateMessageSendJob.Kind.SenderKey(Hex.fromStringCondensed(groupPublicKey), userSenderKey)
|
|
|
|
|
val job = ClosedGroupUpdateMessageSendJob(member, closedGroupUpdateKind)
|
|
|
|
|
ApplicationContext.getInstance(context).jobManager.add(job)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Update the group
|
|
|
|
|
groupDB.updateTitle(groupID, name)
|
|
|
|
|
if (!wasCurrentUserRemoved) {
|
|
|
|
|
// The call below sets isActive to true, so if the user is leaving we have to use groupDB.remove(...) instead
|
|
|
|
|
groupDB.updateMembers(groupID, members.map { Address.fromSerialized(it) })
|
|
|
|
|
}
|
|
|
|
|
// Notify the user
|
|
|
|
|
val type0 = if (wasSenderRemoved) GroupContext.Type.QUIT else GroupContext.Type.UPDATE
|
|
|
|
|
val type1 = if (wasSenderRemoved) SignalServiceGroup.Type.QUIT else SignalServiceGroup.Type.UPDATE
|
|
|
|
|
insertIncomingInfoMessage(context, senderPublicKey, groupID, type0, type1, name, members, admins)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public fun handleSenderKeyRequest(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) {
|
|
|
|
|
// Prepare
|
|
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
|
|
|
|
|
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
|
|
|
|
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
|
|
|
|
val groupID = doubleEncodeGroupID(groupPublicKey)
|
|
|
|
|
val group = groupDB.getGroup(groupID).orNull()
|
|
|
|
|
if (group == null) {
|
|
|
|
|
Log.d("Loki", "Ignoring closed group sender key request for nonexistent group.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// Check that the requesting user is a member of the group
|
|
|
|
|
if (!group.members.map { it.serialize() }.contains(senderPublicKey)) {
|
|
|
|
|
Log.d("Loki", "Ignoring closed group sender key request from non-member.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// Respond to the request
|
|
|
|
|
Log.d("Loki", "Responding to sender key request from: $senderPublicKey.")
|
|
|
|
|
ApplicationContext.getInstance(context).sendSessionRequestIfNeeded(senderPublicKey)
|
|
|
|
|
val userRatchet = DatabaseFactory.getSSKDatabase(context).getClosedGroupRatchet(groupPublicKey, userPublicKey, ClosedGroupRatchetCollectionType.Current)
|
|
|
|
|
?: SharedSenderKeysImplementation.shared.generateRatchet(groupPublicKey, userPublicKey)
|
|
|
|
|
val userSenderKey = ClosedGroupSenderKey(Hex.fromStringCondensed(userRatchet.chainKey), userRatchet.keyIndex, Hex.fromStringCondensed(userPublicKey))
|
|
|
|
|
val closedGroupUpdateKind = ClosedGroupUpdateMessageSendJob.Kind.SenderKey(Hex.fromStringCondensed(groupPublicKey), userSenderKey)
|
|
|
|
|
val job = ClosedGroupUpdateMessageSendJob(senderPublicKey, closedGroupUpdateKind)
|
|
|
|
|
ApplicationContext.getInstance(context).jobManager.add(job)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public fun handleSenderKey(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) {
|
|
|
|
|
// Prepare
|
|
|
|
|
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
|
|
|
|
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
|
|
|
|
val senderKeyProto = closedGroupUpdate.senderKeysList.firstOrNull()
|
|
|
|
|
if (senderKeyProto == null) {
|
|
|
|
|
Log.d("Loki", "Ignoring invalid closed group sender key.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
val senderKey = ClosedGroupSenderKey(senderKeyProto.chainKey.toByteArray(), senderKeyProto.keyIndex, senderKeyProto.publicKey.toByteArray())
|
|
|
|
|
if (senderKeyProto.publicKey.toByteArray().toHexString() != senderPublicKey) {
|
|
|
|
|
Log.d("Loki", "Ignoring invalid closed group sender key.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// Store the sender key
|
|
|
|
|
Log.d("Loki", "Received a sender key from: $senderPublicKey.")
|
|
|
|
|
val ratchet = ClosedGroupRatchet(senderKey.chainKey.toHexString(), senderKey.keyIndex, listOf())
|
|
|
|
|
sskDatabase.setClosedGroupRatchet(groupPublicKey, senderPublicKey, ratchet, ClosedGroupRatchetCollectionType.Current)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
|
fun shouldIgnoreContentMessage(context: Context, address: Address, groupID: String?, senderPublicKey: String): Boolean {
|
|
|
|
|
if (!address.isClosedGroup || groupID == null) { return false }
|
|
|
|
@ -546,21 +286,6 @@ object ClosedGroupsProtocol {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun insertIncomingInfoMessage(context: Context, senderPublicKey: String, groupID: String, type0: GroupContext.Type, type1: SignalServiceGroup.Type,
|
|
|
|
|
name: String, members: Collection<String>, admins: Collection<String>) {
|
|
|
|
|
val groupContextBuilder = GroupContext.newBuilder()
|
|
|
|
|
.setId(ByteString.copyFrom(GroupUtil.getDecodedGroupIDAsData(groupID)))
|
|
|
|
|
.setType(type0)
|
|
|
|
|
.setName(name)
|
|
|
|
|
.addAllMembers(members)
|
|
|
|
|
.addAllAdmins(admins)
|
|
|
|
|
val group = SignalServiceGroup(type1, GroupUtil.getDecodedGroupIDAsData(groupID), GroupType.SIGNAL, name, members.toList(), null, admins.toList())
|
|
|
|
|
val m = IncomingTextMessage(Address.fromSerialized(senderPublicKey), 1, System.currentTimeMillis(), "", Optional.of(group), 0, true)
|
|
|
|
|
val infoMessage = IncomingGroupMessage(m, groupContextBuilder.build(), "")
|
|
|
|
|
val smsDB = DatabaseFactory.getSmsDatabase(context)
|
|
|
|
|
smsDB.insertMessageInbox(infoMessage)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun insertOutgoingInfoMessage(context: Context, groupID: String, type: GroupContext.Type, name: String,
|
|
|
|
|
members: Collection<String>, admins: Collection<String>, threadID: Long) {
|
|
|
|
|
val recipient = Recipient.from(context, Address.fromSerialized(groupID), false)
|
|
|
|
@ -580,13 +305,13 @@ object ClosedGroupsProtocol {
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
|
@Throws(IOException::class)
|
|
|
|
|
public fun doubleEncodeGroupID(groupPublicKey: String): String {
|
|
|
|
|
fun doubleEncodeGroupID(groupPublicKey: String): String {
|
|
|
|
|
return GroupUtil.getEncodedClosedGroupID(GroupUtil.getEncodedClosedGroupID(groupPublicKey))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
|
@Throws(IOException::class)
|
|
|
|
|
public fun doubleDecodeGroupID(groupID: String): ByteArray {
|
|
|
|
|
fun doubleDecodeGroupID(groupID: String): ByteArray {
|
|
|
|
|
return GroupUtil.getDecodedGroupIDAsData(GroupUtil.getDecodedGroupID(groupID))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|