mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-24 12:21:27 +00:00
Kick handling
This commit is contained in:
parent
afb7cc1485
commit
f794458cba
@ -1,11 +1,9 @@
|
|||||||
package network.loki.messenger.libsession_util.util
|
package network.loki.messenger.libsession_util.util
|
||||||
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
|
|
||||||
object Sodium {
|
object Sodium {
|
||||||
|
|
||||||
const val KICKED_DOMAIN = "SessionGroupKickedMessage"
|
const val KICKED_DOMAIN = "SessionGroupKickedMessage"
|
||||||
val KICKED_REGEX: Pattern = Pattern.compile("^(05[a-zA-Z0-9]{64})(\\d+)$")
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
System.loadLibrary("session_util")
|
System.loadLibrary("session_util")
|
||||||
|
@ -216,7 +216,8 @@ class RemoveGroupMemberHandler @Inject constructor(
|
|||||||
data = Base64.encodeBytes(
|
data = Base64.encodeBytes(
|
||||||
Sodium.encryptForMultipleSimple(
|
Sodium.encryptForMultipleSimple(
|
||||||
messages = Array(pendingRemovals.size) {
|
messages = Array(pendingRemovals.size) {
|
||||||
"${pendingRemovals[it].sessionId}${keys.currentGeneration()}".encodeToByteArray()
|
AccountId(pendingRemovals[it].sessionId).pubKeyBytes
|
||||||
|
.plus(keys.currentGeneration().toString().toByteArray())
|
||||||
},
|
},
|
||||||
recipients = Array(pendingRemovals.size) {
|
recipients = Array(pendingRemovals.size) {
|
||||||
AccountId(pendingRemovals[it].sessionId).pubKeyBytes
|
AccountId(pendingRemovals[it].sessionId).pubKeyBytes
|
||||||
|
@ -29,6 +29,7 @@ import org.session.libsession.utilities.getClosedGroup
|
|||||||
import org.session.libsignal.database.LokiAPIDatabaseProtocol
|
import org.session.libsignal.database.LokiAPIDatabaseProtocol
|
||||||
import org.session.libsignal.exceptions.NonRetryableException
|
import org.session.libsignal.exceptions.NonRetryableException
|
||||||
import org.session.libsignal.utilities.AccountId
|
import org.session.libsignal.utilities.AccountId
|
||||||
|
import org.session.libsignal.utilities.IdPrefix
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
import org.session.libsignal.utilities.Namespace
|
import org.session.libsignal.utilities.Namespace
|
||||||
import org.session.libsignal.utilities.Snode
|
import org.session.libsignal.utilities.Snode
|
||||||
@ -299,24 +300,30 @@ class ClosedGroupPoller(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (decoded != null) {
|
if (decoded != null) {
|
||||||
val message = decoded.decodeToString()
|
// The message should be in the format of "<sessionIdPubKeyBinary><messageGenerationASCII>",
|
||||||
val matcher = Sodium.KICKED_REGEX.matcher(message)
|
// where the pub key is 32 bytes, so we need to have at least 33 bytes of data
|
||||||
if (matcher.matches()) {
|
if (decoded.size < 33) {
|
||||||
val sessionId = matcher.group(1)
|
Log.w(TAG, "Received an invalid kicked message, expecting at least 33 bytes, got ${decoded.size}")
|
||||||
val messageGeneration = matcher.group(2)!!.toInt()
|
return@forEach
|
||||||
|
}
|
||||||
|
|
||||||
|
val sessionId = AccountId(IdPrefix.STANDARD, decoded.copyOfRange(0, 32))
|
||||||
|
val messageGeneration = decoded.copyOfRange(32, decoded.size).decodeToString().toIntOrNull()
|
||||||
|
if (messageGeneration == null) {
|
||||||
|
Log.w(TAG, "Received an invalid kicked message: missing message generation")
|
||||||
|
return@forEach
|
||||||
|
}
|
||||||
|
|
||||||
val currentKeysGeneration = configFactoryProtocol.withGroupConfigs(closedGroupSessionId) {
|
val currentKeysGeneration = configFactoryProtocol.withGroupConfigs(closedGroupSessionId) {
|
||||||
it.groupKeys.currentGeneration()
|
it.groupKeys.currentGeneration()
|
||||||
}
|
}
|
||||||
|
|
||||||
val isForMe = sessionId == storage.getUserPublicKey()
|
val isForMe = sessionId.hexString == storage.getUserPublicKey()
|
||||||
Log.d(TAG, "Received kicked message, for us? ${sessionId == storage.getUserPublicKey()}, message key generation = $messageGeneration, our key generation = $currentKeysGeneration")
|
Log.d(TAG, "Received kicked message, for us? ${isForMe}, message key generation = $messageGeneration, our key generation = $currentKeysGeneration")
|
||||||
|
|
||||||
if (isForMe && messageGeneration >= currentKeysGeneration) {
|
if (isForMe && messageGeneration >= currentKeysGeneration) {
|
||||||
groupManagerV2.handleKicked(closedGroupSessionId)
|
groupManagerV2.handleKicked(closedGroupSessionId)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Log.w(TAG, "Received an invalid kicked message")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user