2020-12-07 05:22:02 +01:00
|
|
|
package org.session.libsession.messaging.sending_receiving
|
|
|
|
|
2020-12-10 05:33:57 +01:00
|
|
|
import org.session.libsession.messaging.MessagingConfiguration
|
2020-12-18 06:48:45 +01:00
|
|
|
import org.session.libsession.messaging.jobs.AttachmentDownloadJob
|
2021-01-08 01:13:05 +01:00
|
|
|
import org.session.libsession.messaging.jobs.JobQueue
|
2020-12-07 05:22:02 +01:00
|
|
|
import org.session.libsession.messaging.messages.Destination
|
|
|
|
import org.session.libsession.messaging.messages.Message
|
|
|
|
import org.session.libsession.messaging.messages.control.ClosedGroupUpdate
|
|
|
|
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
|
|
|
import org.session.libsession.messaging.messages.control.ReadReceipt
|
|
|
|
import org.session.libsession.messaging.messages.control.TypingIndicator
|
2020-12-18 06:48:45 +01:00
|
|
|
import org.session.libsession.messaging.messages.visible.Attachment
|
2020-12-07 05:22:02 +01:00
|
|
|
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
|
|
|
import org.session.libsession.messaging.sending_receiving.notifications.PushNotificationAPI
|
2020-12-10 05:33:57 +01:00
|
|
|
import org.session.libsession.messaging.threads.Address
|
2021-01-08 01:13:05 +01:00
|
|
|
import org.session.libsession.messaging.threads.recipients.Recipient
|
2020-12-10 05:33:57 +01:00
|
|
|
import org.session.libsession.utilities.GroupUtil
|
2021-01-08 01:13:05 +01:00
|
|
|
import org.session.libsession.utilities.SSKEnvironment
|
|
|
|
import org.session.libsession.utilities.TextSecurePreferences
|
2020-12-18 06:48:45 +01:00
|
|
|
import org.session.libsignal.libsignal.logging.Log
|
2020-12-07 05:22:02 +01:00
|
|
|
import org.session.libsignal.libsignal.util.Hex
|
|
|
|
|
|
|
|
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
|
|
|
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.toHexString
|
2021-01-08 01:13:05 +01:00
|
|
|
import java.security.MessageDigest
|
2020-12-07 05:22:02 +01:00
|
|
|
import java.util.*
|
2020-12-18 06:48:45 +01:00
|
|
|
import kotlin.collections.ArrayList
|
2020-12-07 05:22:02 +01:00
|
|
|
|
|
|
|
internal fun MessageReceiver.isBlock(publicKey: String): Boolean {
|
2021-01-08 01:13:05 +01:00
|
|
|
return SSKEnvironment.shared.blockManager.isRecipientIdBlocked(publicKey)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content, openGroupID: String?) {
|
|
|
|
when (message) {
|
|
|
|
is ReadReceipt -> handleReadReceipt(message)
|
|
|
|
is TypingIndicator -> handleTypingIndicator(message)
|
|
|
|
is ClosedGroupUpdate -> handleClosedGroupUpdate(message)
|
|
|
|
is ExpirationTimerUpdate -> handleExpirationTimerUpdate(message)
|
|
|
|
is VisibleMessage -> handleVisibleMessage(message, proto, openGroupID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleReadReceipt(message: ReadReceipt) {
|
2021-01-08 01:13:05 +01:00
|
|
|
SSKEnvironment.shared.readReceiptManager.processReadReceipts(message.sender!!, message.timestamps!!.asList(), message.receivedTimestamp!!)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleTypingIndicator(message: TypingIndicator) {
|
|
|
|
when (message.kind!!) {
|
|
|
|
TypingIndicator.Kind.STARTED -> showTypingIndicatorIfNeeded(message.sender!!)
|
|
|
|
TypingIndicator.Kind.STOPPED -> hideTypingIndicatorIfNeeded(message.sender!!)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.showTypingIndicatorIfNeeded(senderPublicKey: String) {
|
2021-01-08 01:13:05 +01:00
|
|
|
val context = MessagingConfiguration.shared.context
|
|
|
|
val address = Address.fromSerialized(senderPublicKey)
|
|
|
|
val threadID = MessagingConfiguration.shared.storage.getThreadIdFor(address) ?: return
|
|
|
|
SSKEnvironment.shared.typingIndicators.didReceiveTypingStartedMessage(context, threadID.toLong(), address, 1)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.hideTypingIndicatorIfNeeded(senderPublicKey: String) {
|
2021-01-08 01:13:05 +01:00
|
|
|
val context = MessagingConfiguration.shared.context
|
|
|
|
val address = Address.fromSerialized(senderPublicKey)
|
|
|
|
val threadID = MessagingConfiguration.shared.storage.getThreadIdFor(address) ?: return
|
|
|
|
SSKEnvironment.shared.typingIndicators.didReceiveTypingStoppedMessage(context, threadID.toLong(), address, 1, false)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.cancelTypingIndicatorsIfNeeded(senderPublicKey: String) {
|
2021-01-08 01:13:05 +01:00
|
|
|
val context = MessagingConfiguration.shared.context
|
|
|
|
val address = Address.fromSerialized(senderPublicKey)
|
|
|
|
val threadID = MessagingConfiguration.shared.storage.getThreadIdFor(address) ?: return
|
|
|
|
SSKEnvironment.shared.typingIndicators.didReceiveIncomingMessage(context, threadID.toLong(), address, 1)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleExpirationTimerUpdate(message: ExpirationTimerUpdate) {
|
|
|
|
if (message.duration!! > 0) {
|
|
|
|
setExpirationTimer(message.duration!!, message.sender!!, message.groupPublicKey)
|
|
|
|
} else {
|
|
|
|
disableExpirationTimer(message.sender!!, message.groupPublicKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.setExpirationTimer(duration: Int, senderPublicKey: String, groupPublicKey: String?) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.disableExpirationTimer(senderPublicKey: String, groupPublicKey: String?) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fun MessageReceiver.handleVisibleMessage(message: VisibleMessage, proto: SignalServiceProtos.Content, openGroupID: String?) {
|
2020-12-18 06:48:45 +01:00
|
|
|
val storage = MessagingConfiguration.shared.storage
|
2021-01-08 01:13:05 +01:00
|
|
|
val context = MessagingConfiguration.shared.context
|
2020-12-18 06:48:45 +01:00
|
|
|
// Parse & persist attachments
|
|
|
|
val attachments = proto.dataMessage.attachmentsList.mapNotNull { proto ->
|
|
|
|
val attachment = Attachment.fromProto(proto)
|
|
|
|
if (attachment == null || !attachment.isValid()) {
|
|
|
|
return@mapNotNull null
|
|
|
|
} else {
|
|
|
|
return@mapNotNull attachment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val attachmentIDs = storage.persist(attachments)
|
2020-12-18 06:59:37 +01:00
|
|
|
message.attachmentIDs = attachmentIDs as ArrayList<Long>
|
2020-12-18 06:48:45 +01:00
|
|
|
var attachmentsToDownload = attachmentIDs
|
|
|
|
// Update profile if needed
|
|
|
|
val newProfile = message.profile
|
|
|
|
if (newProfile != null) {
|
2021-01-08 01:13:05 +01:00
|
|
|
val profileManager = SSKEnvironment.shared.profileManager
|
|
|
|
val recipient = Recipient.from(context, Address.fromSerialized(message.sender!!), false)
|
|
|
|
val displayName = newProfile.displayName!!
|
|
|
|
val userPublicKey = storage.getUserPublicKey()
|
|
|
|
if (userPublicKey == message.sender) {
|
|
|
|
// Update the user's local name if the message came from their master device
|
|
|
|
TextSecurePreferences.setProfileName(context, displayName)
|
|
|
|
}
|
|
|
|
profileManager.setDisplayName(recipient, displayName)
|
|
|
|
if (recipient.profileKey == null || !MessageDigest.isEqual(recipient.profileKey, newProfile.profileKey)) {
|
|
|
|
profileManager.setProfileKey(recipient, newProfile.profileKey!!)
|
|
|
|
profileManager.setUnidentifiedAccessMode(recipient, Recipient.UnidentifiedAccessMode.UNKNOWN)
|
|
|
|
val url = newProfile.profilePictureURL.orEmpty()
|
|
|
|
profileManager.setProfilePictureURL(recipient, url)
|
|
|
|
if (userPublicKey == message.sender) {
|
|
|
|
profileManager.updateOpenGroupProfilePicturesIfNeeded()
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 06:48:45 +01:00
|
|
|
}
|
|
|
|
// Get or create thread
|
|
|
|
val threadID = storage.getOrCreateThreadIdFor(message.sender!!, message.groupPublicKey, openGroupID) ?: throw MessageSender.Error.NoThread
|
|
|
|
// Parse quote if needed
|
|
|
|
if (message.quote != null && proto.dataMessage.hasQuote()) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
// Parse link preview if needed
|
|
|
|
if (message.linkPreview != null && proto.dataMessage.previewCount > 0) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
// Persist the message
|
|
|
|
message.threadID = threadID
|
|
|
|
// Start attachment downloads if needed
|
|
|
|
attachmentsToDownload.forEach { attachmentID ->
|
|
|
|
val downloadJob = AttachmentDownloadJob()
|
|
|
|
}
|
|
|
|
// TODO finish this process
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleClosedGroupUpdate(message: ClosedGroupUpdate) {
|
|
|
|
when (message.kind!!) {
|
|
|
|
is ClosedGroupUpdate.Kind.New -> handleNewGroup(message)
|
|
|
|
is ClosedGroupUpdate.Kind.Info -> handleGroupUpdate(message)
|
|
|
|
is ClosedGroupUpdate.Kind.SenderKeyRequest -> handleSenderKeyRequest(message)
|
|
|
|
is ClosedGroupUpdate.Kind.SenderKey -> handleSenderKey(message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleNewGroup(message: ClosedGroupUpdate) {
|
2020-12-10 05:33:57 +01:00
|
|
|
val storage = MessagingConfiguration.shared.storage
|
|
|
|
val sskDatabase = MessagingConfiguration.shared.sskDatabase
|
2020-12-18 06:48:45 +01:00
|
|
|
if (message.kind !is ClosedGroupUpdate.Kind.New) { return }
|
2020-12-07 05:22:02 +01:00
|
|
|
val kind = message.kind!! as ClosedGroupUpdate.Kind.New
|
|
|
|
val groupPublicKey = kind.groupPublicKey.toHexString()
|
|
|
|
val name = kind.name
|
|
|
|
val groupPrivateKey = kind.groupPrivateKey
|
|
|
|
val senderKeys = kind.senderKeys
|
|
|
|
val members = kind.members.map { it.toHexString() }
|
|
|
|
val admins = kind.admins.map { it.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) })
|
|
|
|
val userPublicKey = storage.getUserPublicKey()!!
|
|
|
|
if (missingSenderKeys.contains(userPublicKey)) {
|
|
|
|
val userRatchet = SharedSenderKeysImplementation.shared.generateRatchet(groupPublicKey, userPublicKey)
|
|
|
|
val userSenderKey = ClosedGroupSenderKey(Hex.fromStringCondensed(userRatchet.chainKey), userRatchet.keyIndex, Hex.fromStringCondensed(userPublicKey))
|
|
|
|
members.forEach { member ->
|
|
|
|
if (member == userPublicKey) return@forEach
|
|
|
|
val closedGroupUpdateKind = ClosedGroupUpdate.Kind.SenderKey(groupPublicKey.toByteArray(), userSenderKey)
|
|
|
|
val closedGroupUpdate = ClosedGroupUpdate()
|
|
|
|
closedGroupUpdate.kind = closedGroupUpdateKind
|
|
|
|
MessageSender.send(closedGroupUpdate, Destination.ClosedGroup(groupPublicKey))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
missingSenderKeys.minus(userPublicKey).forEach { publicKey ->
|
|
|
|
MessageSender.requestSenderKey(groupPublicKey, publicKey)
|
|
|
|
}
|
|
|
|
// Create the group
|
2020-12-10 05:33:57 +01:00
|
|
|
val groupID = GroupUtil.getEncodedClosedGroupID(groupPublicKey)
|
|
|
|
if (storage.getGroup(groupID) != null) {
|
2020-12-07 05:22:02 +01:00
|
|
|
// Update the group
|
2020-12-10 05:33:57 +01:00
|
|
|
storage.updateTitle(groupID, name)
|
|
|
|
storage.updateMembers(groupID, members.map { Address.fromSerialized(it) })
|
2020-12-07 05:22:02 +01:00
|
|
|
} else {
|
2020-12-10 05:33:57 +01:00
|
|
|
storage.createGroup(groupID, name, LinkedList(members.map { Address.fromSerialized(it) }),
|
|
|
|
null, null, LinkedList(admins.map { Address.fromSerialized(it) }))
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
2020-12-10 05:33:57 +01:00
|
|
|
storage.setProfileSharing(Address.fromSerialized(groupID), true)
|
2020-12-07 05:22:02 +01:00
|
|
|
// Add the group to the user's set of public keys to poll for
|
|
|
|
sskDatabase.setClosedGroupPrivateKey(groupPublicKey, groupPrivateKey.toHexString())
|
|
|
|
// Notify the PN server
|
2020-12-10 05:33:57 +01:00
|
|
|
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, groupPublicKey, userPublicKey)
|
2020-12-07 05:22:02 +01:00
|
|
|
// Notify the user
|
2020-12-10 05:33:57 +01:00
|
|
|
/* TODO
|
2020-12-07 05:22:02 +01:00
|
|
|
insertIncomingInfoMessage(context, senderPublicKey, groupID, SignalServiceProtos.GroupContext.Type.UPDATE, SignalServiceGroup.Type.UPDATE, name, members, admins)
|
2020-12-10 05:33:57 +01:00
|
|
|
*/
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleGroupUpdate(message: ClosedGroupUpdate) {
|
2020-12-18 06:48:45 +01:00
|
|
|
val storage = MessagingConfiguration.shared.storage
|
|
|
|
val sskDatabase = MessagingConfiguration.shared.sskDatabase
|
|
|
|
if (message.kind !is ClosedGroupUpdate.Kind.Info) { return }
|
|
|
|
val kind = message.kind!! as ClosedGroupUpdate.Kind.Info
|
|
|
|
val groupPublicKey = kind.groupPublicKey.toHexString()
|
|
|
|
val name = kind.name
|
|
|
|
val senderKeys = kind.senderKeys
|
|
|
|
val members = kind.members.map { it.toHexString() }
|
|
|
|
val admins = kind.admins.map { it.toHexString() }
|
|
|
|
// Get the group
|
|
|
|
val groupID = GroupUtil.getEncodedClosedGroupID(groupPublicKey)
|
|
|
|
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.") }
|
|
|
|
// 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 oldMembers = group.members.map { it.serialize() }.toSet()
|
|
|
|
val userPublicKey = storage.getUserPublicKey()!!
|
|
|
|
val wasUserRemoved = !members.contains(userPublicKey)
|
|
|
|
if (members.toSet().intersect(oldMembers) != oldMembers.toSet()) {
|
|
|
|
val allOldRatchets = sskDatabase.getAllClosedGroupRatchets(groupPublicKey, ClosedGroupRatchetCollectionType.Current)
|
|
|
|
for (pair in allOldRatchets) {
|
|
|
|
val senderPublicKey = pair.first
|
|
|
|
val ratchet = pair.second
|
|
|
|
val collection = ClosedGroupRatchetCollectionType.Old
|
|
|
|
sskDatabase.setClosedGroupRatchet(groupPublicKey, senderPublicKey, ratchet, collection)
|
|
|
|
}
|
|
|
|
sskDatabase.removeAllClosedGroupRatchets(groupPublicKey, ClosedGroupRatchetCollectionType.Current)
|
|
|
|
if (wasUserRemoved) {
|
|
|
|
sskDatabase.removeClosedGroupPrivateKey(groupPublicKey)
|
|
|
|
storage.setActive(groupID, false)
|
|
|
|
storage.removeMember(groupID, Address.fromSerialized(userPublicKey))
|
|
|
|
// Notify the PN server
|
|
|
|
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Unsubscribe, groupPublicKey, userPublicKey)
|
|
|
|
} else {
|
|
|
|
val userRatchet = SharedSenderKeysImplementation.shared.generateRatchet(groupPublicKey, userPublicKey)
|
|
|
|
val userSenderKey = ClosedGroupSenderKey(Hex.fromStringCondensed(userRatchet.chainKey), userRatchet.keyIndex, Hex.fromStringCondensed(userPublicKey))
|
|
|
|
members.forEach { member ->
|
|
|
|
if (member == userPublicKey) return@forEach
|
|
|
|
val address = Address.fromSerialized(member)
|
|
|
|
val closedGroupUpdateKind = ClosedGroupUpdate.Kind.SenderKey(Hex.fromStringCondensed(groupPublicKey), userSenderKey)
|
|
|
|
val closedGroupUpdate = ClosedGroupUpdate()
|
|
|
|
closedGroupUpdate.kind = closedGroupUpdateKind
|
|
|
|
MessageSender.send(closedGroupUpdate, address)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Update the group
|
|
|
|
storage.updateTitle(groupID, name)
|
|
|
|
storage.updateMembers(groupID, members.map { Address.fromSerialized(it) })
|
|
|
|
// Notify the user if needed
|
|
|
|
val infoType = if (wasUserRemoved) SignalServiceProtos.GroupContext.Type.QUIT else SignalServiceProtos.GroupContext.Type.UPDATE
|
|
|
|
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
|
|
|
// TODO insertOutgoingInfoMessage(context, groupID, infoType, name, members, admins, threadID)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleSenderKeyRequest(message: ClosedGroupUpdate) {
|
2021-01-08 01:13:05 +01:00
|
|
|
if (message.kind !is ClosedGroupUpdate.Kind.SenderKeyRequest) { return }
|
|
|
|
val kind = message.kind!! as ClosedGroupUpdate.Kind.SenderKeyRequest
|
|
|
|
val storage = MessagingConfiguration.shared.storage
|
|
|
|
val sskDatabase = MessagingConfiguration.shared.sskDatabase
|
|
|
|
val userPublicKey = storage.getUserPublicKey()!!
|
|
|
|
val groupPublicKey = kind.groupPublicKey.toHexString()
|
|
|
|
val groupID = GroupUtil.getEncodedClosedGroupID(groupPublicKey)
|
|
|
|
val group = storage.getGroup(groupID)
|
|
|
|
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(message.sender!!)) {
|
|
|
|
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: ${message.sender!!}.")
|
|
|
|
val userRatchet = sskDatabase.getClosedGroupRatchet(groupPublicKey, userPublicKey, ClosedGroupRatchetCollectionType.Current)
|
|
|
|
?: SharedSenderKeysImplementation.shared.generateRatchet(groupPublicKey, userPublicKey)
|
|
|
|
val userSenderKey = ClosedGroupSenderKey(Hex.fromStringCondensed(userRatchet.chainKey), userRatchet.keyIndex, Hex.fromStringCondensed(userPublicKey))
|
|
|
|
val closedGroupUpdateKind = ClosedGroupUpdate.Kind.SenderKey(Hex.fromStringCondensed(groupPublicKey), userSenderKey)
|
|
|
|
val closedGroupUpdate = ClosedGroupUpdate()
|
|
|
|
closedGroupUpdate.kind = closedGroupUpdateKind
|
|
|
|
MessageSender.send(closedGroupUpdate, Address.fromSerialized(groupID))
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun MessageReceiver.handleSenderKey(message: ClosedGroupUpdate) {
|
2021-01-08 01:13:05 +01:00
|
|
|
if (message.kind !is ClosedGroupUpdate.Kind.SenderKey) { return }
|
|
|
|
val kind = message.kind!! as ClosedGroupUpdate.Kind.SenderKey
|
|
|
|
val groupPublicKey = kind.groupPublicKey.toHexString()
|
|
|
|
val senderKey = kind.senderKey
|
|
|
|
if (senderKey.publicKey.toHexString() != message.sender!!) {
|
|
|
|
Log.d("Loki", "Ignoring invalid closed group sender key.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
Log.d("Loki", "Received a sender key from: ${message.sender!!}.")
|
|
|
|
val ratchet = ClosedGroupRatchet(senderKey.chainKey.toHexString(), senderKey.keyIndex, listOf())
|
|
|
|
MessagingConfiguration.shared.sskDatabase.setClosedGroupRatchet(groupPublicKey, senderKey.publicKey.toHexString(), ratchet, ClosedGroupRatchetCollectionType.Current)
|
2020-12-07 05:22:02 +01:00
|
|
|
}
|