Improve check for self.

This commit is contained in:
Greyson Parrelli
2026-07-10 10:50:54 -04:00
parent 12af41174a
commit 8f4b4aa160
2 changed files with 9 additions and 6 deletions
@@ -1,19 +1,18 @@
package org.thoughtcrime.securesms.messages.protocol
import org.signal.core.models.ServiceId
import org.signal.libsignal.protocol.IdentityKey
import org.signal.libsignal.protocol.IdentityKeyPair
import org.signal.libsignal.protocol.SignalProtocolAddress
import org.signal.libsignal.protocol.state.IdentityKeyStore
import org.signal.libsignal.protocol.state.IdentityKeyStore.IdentityChange
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.whispersystems.signalservice.api.SignalServiceAccountDataStore
/**
* An in-memory identity key store that is intended to be used temporarily while decrypting messages.
*/
class BufferedIdentityKeyStore(
private val selfServiceId: ServiceId,
private val selfIdentityKeyPair: IdentityKeyPair,
private val selfRegistrationId: Int
) : IdentityKeyStore {
@@ -45,8 +44,12 @@ class BufferedIdentityKeyStore(
}
override fun isTrustedIdentity(address: SignalProtocolAddress, identityKey: IdentityKey, direction: IdentityKeyStore.Direction): Boolean {
if (address.name == selfServiceId.toString()) {
return identityKey == selfIdentityKeyPair.publicKey
val isSelf = address.name == SignalStore.account.aci?.toString() ||
address.name == SignalStore.account.pni?.toString() ||
address.name == SignalStore.account.e164
if (isSelf) {
return identityKey == SignalStore.account.aciIdentityKey.publicKey
}
return when (direction) {
@@ -26,9 +26,9 @@ import java.util.UUID
class BufferedSignalServiceAccountDataStore(selfServiceId: ServiceId) : SignalServiceAccountDataStore {
private val identityStore: BufferedIdentityKeyStore = if (selfServiceId == SignalStore.account.pni) {
BufferedIdentityKeyStore(selfServiceId, SignalStore.account.pniIdentityKey, SignalStore.account.pniRegistrationId)
BufferedIdentityKeyStore(SignalStore.account.pniIdentityKey, SignalStore.account.pniRegistrationId)
} else {
BufferedIdentityKeyStore(selfServiceId, SignalStore.account.aciIdentityKey, SignalStore.account.registrationId)
BufferedIdentityKeyStore(SignalStore.account.aciIdentityKey, SignalStore.account.registrationId)
}
private val oneTimePreKeyStore: BufferedOneTimePreKeyStore = BufferedOneTimePreKeyStore(selfServiceId)