mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
refactor: move ProfileKeyUtil from app/ to libsession/ module and implement new config message sends
This commit is contained in:
parent
62db34de59
commit
71e48b9024
@ -50,7 +50,7 @@ import org.thoughtcrime.securesms.sskenvironment.TypingStatusRepository;
|
|||||||
import org.thoughtcrime.securesms.components.TypingStatusSender;
|
import org.thoughtcrime.securesms.components.TypingStatusSender;
|
||||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
|
import org.session.libsession.utilities.preferences.ProfileKeyUtil;
|
||||||
import org.session.libsession.messaging.threads.Address;
|
import org.session.libsession.messaging.threads.Address;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||||
|
@ -6,6 +6,7 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
|
import org.session.libsession.utilities.preferences.ProfileKeyUtil;
|
||||||
import org.session.libsignal.metadata.SignalProtos;
|
import org.session.libsignal.metadata.SignalProtos;
|
||||||
import org.session.libsignal.metadata.certificate.CertificateValidator;
|
import org.session.libsignal.metadata.certificate.CertificateValidator;
|
||||||
import org.session.libsignal.metadata.certificate.InvalidCertificateException;
|
import org.session.libsignal.metadata.certificate.InvalidCertificateException;
|
||||||
|
@ -18,7 +18,7 @@ import org.session.libsession.utilities.Util;
|
|||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.thoughtcrime.securesms.ApplicationContext;
|
import org.thoughtcrime.securesms.ApplicationContext;
|
||||||
import org.thoughtcrime.securesms.contactshare.ContactModelMapper;
|
import org.thoughtcrime.securesms.contactshare.ContactModelMapper;
|
||||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
|
import org.session.libsession.utilities.preferences.ProfileKeyUtil;
|
||||||
import org.session.libsession.messaging.threads.Address;
|
import org.session.libsession.messaging.threads.Address;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.events.PartProgressEvent;
|
import org.thoughtcrime.securesms.events.PartProgressEvent;
|
||||||
|
@ -27,7 +27,7 @@ import nl.komponents.kovenant.ui.alwaysUi
|
|||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
import org.thoughtcrime.securesms.avatar.AvatarSelection
|
import org.thoughtcrime.securesms.avatar.AvatarSelection
|
||||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil
|
import org.session.libsession.utilities.preferences.ProfileKeyUtil
|
||||||
import org.session.libsession.messaging.threads.Address
|
import org.session.libsession.messaging.threads.Address
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
import org.thoughtcrime.securesms.loki.dialogs.ChangeUiModeDialog
|
import org.thoughtcrime.securesms.loki.dialogs.ChangeUiModeDialog
|
||||||
|
@ -4,7 +4,7 @@ import android.content.Context
|
|||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.thoughtcrime.securesms.ApplicationContext
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil
|
import org.session.libsession.utilities.preferences.ProfileKeyUtil
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
import org.thoughtcrime.securesms.groups.GroupManager
|
import org.thoughtcrime.securesms.groups.GroupManager
|
||||||
import org.session.libsession.utilities.GroupUtil
|
import org.session.libsession.utilities.GroupUtil
|
||||||
|
@ -4,6 +4,8 @@ import com.google.protobuf.ByteString
|
|||||||
import org.session.libsession.messaging.MessagingConfiguration
|
import org.session.libsession.messaging.MessagingConfiguration
|
||||||
import org.session.libsession.messaging.threads.Address
|
import org.session.libsession.messaging.threads.Address
|
||||||
import org.session.libsession.utilities.GroupUtil
|
import org.session.libsession.utilities.GroupUtil
|
||||||
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
|
import org.session.libsession.utilities.preferences.ProfileKeyUtil
|
||||||
import org.session.libsignal.libsignal.ecc.DjbECPrivateKey
|
import org.session.libsignal.libsignal.ecc.DjbECPrivateKey
|
||||||
import org.session.libsignal.libsignal.ecc.DjbECPublicKey
|
import org.session.libsignal.libsignal.ecc.DjbECPublicKey
|
||||||
import org.session.libsignal.libsignal.ecc.ECKeyPair
|
import org.session.libsignal.libsignal.ecc.ECKeyPair
|
||||||
@ -12,7 +14,7 @@ import org.session.libsignal.service.loki.utilities.removing05PrefixIfNeeded
|
|||||||
import org.session.libsignal.service.loki.utilities.toHexString
|
import org.session.libsignal.service.loki.utilities.toHexString
|
||||||
import org.session.libsignal.utilities.Hex
|
import org.session.libsignal.utilities.Hex
|
||||||
|
|
||||||
class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups: List<String>): ControlMessage() {
|
class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups: List<String>, val displayName: String, val profilePicture: String?, val profileKey: ByteArray): ControlMessage() {
|
||||||
|
|
||||||
class ClosedGroup(val publicKey: String, val name: String, val encryptionKeyPair: ECKeyPair, val members: List<String>, val admins: List<String>) {
|
class ClosedGroup(val publicKey: String, val name: String, val encryptionKeyPair: ECKeyPair, val members: List<String>, val admins: List<String>) {
|
||||||
val isValid: Boolean get() = members.isNotEmpty() && admins.isNotEmpty()
|
val isValid: Boolean get() = members.isNotEmpty() && admins.isNotEmpty()
|
||||||
@ -57,7 +59,12 @@ class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups:
|
|||||||
fun getCurrent(): ConfigurationMessage {
|
fun getCurrent(): ConfigurationMessage {
|
||||||
val closedGroups = mutableListOf<ClosedGroup>()
|
val closedGroups = mutableListOf<ClosedGroup>()
|
||||||
val openGroups = mutableListOf<String>()
|
val openGroups = mutableListOf<String>()
|
||||||
val storage = MessagingConfiguration.shared.storage
|
val sharedConfig = MessagingConfiguration.shared
|
||||||
|
val storage = sharedConfig.storage
|
||||||
|
val context = sharedConfig.context
|
||||||
|
val displayName = TextSecurePreferences.getProfileName(context)!!
|
||||||
|
val profilePicture = TextSecurePreferences.getProfilePictureURL(context)
|
||||||
|
val profileKey = ProfileKeyUtil.getProfileKey(context)
|
||||||
val groups = storage.getAllGroups()
|
val groups = storage.getAllGroups()
|
||||||
for (groupRecord in groups) {
|
for (groupRecord in groups) {
|
||||||
if (groupRecord.isClosedGroup) {
|
if (groupRecord.isClosedGroup) {
|
||||||
@ -74,7 +81,8 @@ class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups:
|
|||||||
openGroups.add(openGroup.server)
|
openGroups.add(openGroup.server)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ConfigurationMessage(closedGroups, openGroups)
|
|
||||||
|
return ConfigurationMessage(closedGroups, openGroups, displayName, profilePicture, profileKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fromProto(proto: SignalServiceProtos.Content): ConfigurationMessage? {
|
fun fromProto(proto: SignalServiceProtos.Content): ConfigurationMessage? {
|
||||||
@ -82,7 +90,10 @@ class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups:
|
|||||||
val configurationProto = proto.configurationMessage
|
val configurationProto = proto.configurationMessage
|
||||||
val closedGroups = configurationProto.closedGroupsList.mapNotNull { ClosedGroup.fromProto(it) }
|
val closedGroups = configurationProto.closedGroupsList.mapNotNull { ClosedGroup.fromProto(it) }
|
||||||
val openGroups = configurationProto.openGroupsList
|
val openGroups = configurationProto.openGroupsList
|
||||||
return ConfigurationMessage(closedGroups, openGroups)
|
val displayName = configurationProto.displayName
|
||||||
|
val profilePicture = configurationProto.profilePicture
|
||||||
|
val profileKey = configurationProto.profileKey
|
||||||
|
return ConfigurationMessage(closedGroups, openGroups, displayName, profilePicture, profileKey.toByteArray())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +101,9 @@ class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups:
|
|||||||
val configurationProto = SignalServiceProtos.ConfigurationMessage.newBuilder()
|
val configurationProto = SignalServiceProtos.ConfigurationMessage.newBuilder()
|
||||||
configurationProto.addAllClosedGroups(closedGroups.mapNotNull { it.toProto() })
|
configurationProto.addAllClosedGroups(closedGroups.mapNotNull { it.toProto() })
|
||||||
configurationProto.addAllOpenGroups(openGroups)
|
configurationProto.addAllOpenGroups(openGroups)
|
||||||
|
configurationProto.displayName = displayName
|
||||||
|
configurationProto.profilePicture = profilePicture
|
||||||
|
configurationProto.profileKey = ByteString.copyFrom(profileKey)
|
||||||
val contentProto = SignalServiceProtos.Content.newBuilder()
|
val contentProto = SignalServiceProtos.Content.newBuilder()
|
||||||
contentProto.configurationMessage = configurationProto.build()
|
contentProto.configurationMessage = configurationProto.build()
|
||||||
return contentProto.build()
|
return contentProto.build()
|
||||||
@ -100,6 +114,9 @@ class ConfigurationMessage(val closedGroups: List<ClosedGroup>, val openGroups:
|
|||||||
ConfigurationMessage(
|
ConfigurationMessage(
|
||||||
closedGroups: ${(closedGroups)}
|
closedGroups: ${(closedGroups)}
|
||||||
openGroups: ${(openGroups)}
|
openGroups: ${(openGroups)}
|
||||||
|
displayName: $displayName
|
||||||
|
profilePicture: $profilePicture
|
||||||
|
profileKey: $profileKey
|
||||||
)
|
)
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,7 @@ private fun MessageReceiver.handleConfigurationMessage(message: ConfigurationMes
|
|||||||
if (allOpenGroups.contains(openGroup)) continue
|
if (allOpenGroups.contains(openGroup)) continue
|
||||||
storage.addOpenGroup(openGroup, 1)
|
storage.addOpenGroup(openGroup, 1)
|
||||||
}
|
}
|
||||||
|
// TODO: in future handle the latest in config messages
|
||||||
TextSecurePreferences.setConfigurationMessageSynced(context, true)
|
TextSecurePreferences.setConfigurationMessageSynced(context, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package org.thoughtcrime.securesms.crypto;
|
package org.session.libsession.utilities.preferences;
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
Loading…
x
Reference in New Issue
Block a user