refactor: add basic support for blinded v2 prefixes

This commit is contained in:
0x330a 2023-07-14 16:44:19 +10:00
parent a40acfb92a
commit 25bfa3c303
9 changed files with 16 additions and 20 deletions

View File

@ -167,6 +167,7 @@ class VisibleMessageView : LinearLayout {
if (thread.isOpenGroupRecipient) {
val openGroup = lokiThreadDb.getOpenGroupChat(threadID)
if (IdPrefix.fromValue(senderSessionID) == IdPrefix.BLINDED && openGroup?.canWrite == true) {
// TODO: support v2 soon
val intent = Intent(context, ConversationActivityV2::class.java)
intent.putExtra(ConversationActivityV2.FROM_GROUP_THREAD_ID, threadID)
intent.putExtra(ConversationActivityV2.ADDRESS, Address.fromSerialized(senderSessionID))
@ -180,7 +181,7 @@ class VisibleMessageView : LinearLayout {
val openGroup = lokiThreadDb.getOpenGroupChat(threadID) ?: return
var standardPublicKey = ""
var blindedPublicKey: String? = null
if (IdPrefix.fromValue(senderSessionID) == IdPrefix.BLINDED) {
if (IdPrefix.fromValue(senderSessionID)?.isBlinded() == true) {
blindedPublicKey = senderSessionID
} else {
standardPublicKey = senderSessionID

View File

@ -1134,7 +1134,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
val mappingDb = DatabaseComponent.get(context).blindedIdMappingDatabase()
val moreContacts = contacts.filter { contact ->
val id = SessionId(contact.id)
id.prefix != IdPrefix.BLINDED || mappingDb.getBlindedIdMapping(contact.id).none { it.sessionId != null }
id.prefix?.isBlinded() == false || mappingDb.getBlindedIdMapping(contact.id).none { it.sessionId != null }
}
val profileManager = SSKEnvironment.shared.profileManager
moreContacts.forEach { contact ->

View File

@ -592,8 +592,6 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
db.execSQL(ConfigDatabase.CREATE_CONFIG_TABLE_COMMAND);
db.execSQL(ConfigurationMessageUtilities.DELETE_INACTIVE_GROUPS);
db.execSQL(ConfigurationMessageUtilities.DELETE_INACTIVE_ONE_TO_ONES);
// TODO: remove this for release
TextSecurePreferences.setForceNewConfig(context);
}
if (oldVersion < lokiV42) {

View File

@ -26,7 +26,6 @@ import org.session.libsignal.utilities.IdPrefix
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
import org.thoughtcrime.securesms.database.ThreadDatabase
import org.thoughtcrime.securesms.mms.GlideApp
import org.thoughtcrime.securesms.util.UiModeUtilities
import javax.inject.Inject
@AndroidEntryPoint
@ -94,7 +93,7 @@ class UserDetailsBottomSheet: BottomSheetDialogFragment() {
publicKeyTextView.isVisible = !threadRecipient.isOpenGroupRecipient
&& !threadRecipient.isOpenGroupInboxRecipient
&& !threadRecipient.isOpenGroupOutboxRecipient
messageButton.isVisible = !threadRecipient.isOpenGroupRecipient || IdPrefix.fromValue(publicKey) == IdPrefix.BLINDED
messageButton.isVisible = !threadRecipient.isOpenGroupRecipient || IdPrefix.fromValue(publicKey)?.isBlinded() == true
publicKeyTextView.text = publicKey
publicKeyTextView.setOnLongClickListener {
val clipboard =

View File

@ -81,6 +81,9 @@ class Contacts(pointer: Long) : ConfigBase(pointer) {
} else if (sessionId.startsWith(IdPrefix.UN_BLINDED.value)) {
Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix")
return
} else if (sessionId.startsWith(IdPrefix.BLINDEDV2.value)) {
Log.w("Loki", "Trying to create a contact with a blindedv2 ID prefix")
return
}
val contact = getOrConstruct(sessionId)
updateFunction(contact)
@ -98,6 +101,9 @@ class Contacts(pointer: Long) : ConfigBase(pointer) {
} else if (sessionId.startsWith(IdPrefix.UN_BLINDED.value)) {
Log.w("Loki", "Trying to create a contact with an un-blinded ID prefix")
return
} else if (sessionId.startsWith(IdPrefix.BLINDEDV2.value)) {
Log.w("Loki", "Trying to create a contact with a blindedv2 ID prefix")
return
}
val contact = get(sessionId) ?: return
updateFunction(contact)

View File

@ -73,7 +73,7 @@ object MessageReceiver {
} else {
when (envelope.type) {
SignalServiceProtos.Envelope.Type.SESSION_MESSAGE -> {
if (IdPrefix.fromValue(envelope.source) == IdPrefix.BLINDED) {
if (IdPrefix.fromValue(envelope.source)?.isBlinded() == true) {
openGroupPublicKey ?: throw Error.InvalidGroupPublicKey
otherBlindedPublicKey ?: throw Error.DecryptionFailed
val decryptionResult = MessageDecrypter.decryptBlinded(

View File

@ -28,7 +28,7 @@ class Address private constructor(address: String) : Parcelable, Comparable<Addr
val isOpenGroupInbox: Boolean
get() = GroupUtil.isOpenGroupInbox(address)
val isOpenGroupOutbox: Boolean
get() = address.startsWith(IdPrefix.BLINDED.value)
get() = address.startsWith(IdPrefix.BLINDED.value) || address.startsWith(IdPrefix.BLINDEDV2.value)
val isContact: Boolean
get() = !(isGroup || isOpenGroupInbox)

View File

@ -12,7 +12,6 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import org.session.libsession.BuildConfig
import org.session.libsession.R
import org.session.libsession.utilities.TextSecurePreferences.Companion.AUTOPLAY_AUDIO_MESSAGES
import org.session.libsession.utilities.TextSecurePreferences.Companion.CALL_NOTIFICATIONS_ENABLED
@ -180,7 +179,6 @@ interface TextSecurePreferences {
fun setThemeStyle(themeStyle: String)
fun setFollowSystemSettings(followSystemSettings: Boolean)
fun autoplayAudioMessages(): Boolean
fun setForceNewConfig()
fun hasForcedNewConfig(): Boolean
fun hasPreference(key: String): Boolean
fun clearAll()
@ -814,11 +812,6 @@ interface TextSecurePreferences {
setIntegerPreference(context, NOTIFICATION_MESSAGES_CHANNEL_VERSION, version)
}
@JvmStatic
fun setForceNewConfig(context: Context) {
setBooleanPreference(context, HAS_FORCED_NEW_CONFIG, true)
}
@JvmStatic
fun hasForcedNewConfig(context: Context): Boolean {
return getBooleanPreference(context, HAS_FORCED_NEW_CONFIG, false)
@ -1460,10 +1453,6 @@ class AppTextSecurePreferences @Inject constructor(
setIntegerPreference(TextSecurePreferences.NOTIFICATION_MESSAGES_CHANNEL_VERSION, version)
}
override fun setForceNewConfig() {
setBooleanPreference(TextSecurePreferences.HAS_FORCED_NEW_CONFIG, true)
}
override fun hasForcedNewConfig(): Boolean =
getBooleanPreference(TextSecurePreferences.HAS_FORCED_NEW_CONFIG, false)

View File

@ -1,12 +1,15 @@
package org.session.libsignal.utilities
enum class IdPrefix(val value: String) {
STANDARD("05"), BLINDED("15"), UN_BLINDED("00");
STANDARD("05"), BLINDED("15"), UN_BLINDED("00"), BLINDEDV2("25");
fun isBlinded() = value == BLINDED.value || value == BLINDEDV2.value
companion object {
fun fromValue(rawValue: String): IdPrefix? = when(rawValue.take(2)) {
STANDARD.value -> STANDARD
BLINDED.value -> BLINDED
BLINDEDV2.value -> BLINDEDV2
UN_BLINDED.value -> UN_BLINDED
else -> null
}