Skip to content

[WIP] Tidy up push registration #976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: release/1.21.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
import org.thoughtcrime.securesms.notifications.BackgroundPollManager;
import org.thoughtcrime.securesms.notifications.BackgroundPollWorker;
import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.notifications.PushRegistrationHandler;
import org.thoughtcrime.securesms.notifications.PushRegistrationManager;
import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
import org.thoughtcrime.securesms.service.KeyCachingService;
Expand Down Expand Up @@ -160,7 +160,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
@Inject ConfigFactory configFactory;
@Inject LastSentTimestampCache lastSentTimestampCache;
@Inject VersionDataFetcher versionDataFetcher;
@Inject PushRegistrationHandler pushRegistrationHandler;
@Inject PushRegistrationManager pushRegistrationManager; // Exists here only to start upon app starts
@Inject TokenFetcher tokenFetcher;
@Inject GroupManagerV2 groupManagerV2;
@Inject SSKEnvironment.ProfileManagerProtocol profileManager;
Expand Down Expand Up @@ -299,7 +299,6 @@ public void onCreate() {
HTTP.INSTANCE.setConnectedToNetwork(networkConstraint::isMet);

snodeClock.start();
pushRegistrationHandler.run();
configUploader.start();
removeGroupMemberHandler.start();
destroyedGroupSync.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import network.loki.messenger.libsession_util.MutableContacts
import network.loki.messenger.libsession_util.MutableConversationVolatileConfig
import network.loki.messenger.libsession_util.MutableUserGroupsConfig
import network.loki.messenger.libsession_util.MutableUserProfile
import network.loki.messenger.libsession_util.ReadableGroupKeysConfig
import network.loki.messenger.libsession_util.UserGroupsConfig
import network.loki.messenger.libsession_util.UserProfile
import network.loki.messenger.libsession_util.util.BaseCommunityInfo
Expand Down Expand Up @@ -299,6 +300,20 @@ class ConfigFactory @Inject constructor(
}
}

override fun snapshotGroupAuth(groupId: AccountId): SwarmAuth? {
val group = getGroup(groupId) ?: return null
if (group.hasAdminKey()) {
return OwnedSwarmAuth.ofClosedGroup(groupId, group.adminKey!!)
}

val token = group.authData ?: return null
val keyAccess = StaticGroupKeyAccess(withGroupConfigs(groupId) {
it.groupKeys.copy()
})

return GroupSubAccountSwarmAuth(groupId, keyAccess, token)
}

override fun decryptForUser(
encoded: ByteArray,
domain: String,
Expand Down Expand Up @@ -466,7 +481,7 @@ class ConfigFactory @Inject constructor(
return if (group.adminKey != null) {
OwnedSwarmAuth.ofClosedGroup(groupId, group.adminKey!!)
} else if (group.authData != null) {
GroupSubAccountSwarmAuth(groupId, this, group.authData!!)
GroupSubAccountSwarmAuth(groupId, ConfigFactoryGroupKeyAccess(groupId), group.authData!!)
} else {
null
}
Expand All @@ -482,17 +497,38 @@ class ConfigFactory @Inject constructor(
}
}

// Provides access to the group keys
private interface GroupKeysAccess {
fun <T> accessKeys(cb: (ReadableGroupKeysConfig) -> T): T
}

// Provides access to the group keys for a specific group from the ConfigFactory
private inner class ConfigFactoryGroupKeyAccess(val groupId: AccountId) : GroupKeysAccess {
override fun <T> accessKeys(cb: (ReadableGroupKeysConfig) -> T): T {
return withGroupConfigs(groupId) {
cb(it.groupKeys)
}
}
}

// Provides access to a group key config directly
private class StaticGroupKeyAccess(val groupKeysConfig: ReadableGroupKeysConfig) : GroupKeysAccess {
override fun <T> accessKeys(cb: (ReadableGroupKeysConfig) -> T): T {
return cb(groupKeysConfig)
}
}

private class GroupSubAccountSwarmAuth(
override val accountId: AccountId,
val factory: ConfigFactory,
private val keyAccess: GroupKeysAccess,
val authData: ByteArray,
) : SwarmAuth {
override val ed25519PublicKeyHex: String?
get() = null

override fun sign(data: ByteArray): Map<String, String> {
return factory.withGroupConfigs(accountId) {
val auth = it.groupKeys.subAccountSign(data, authData)
return keyAccess.accessKeys {
val auth = it.subAccountSign(data, authData)
buildMap {
put("subaccount", auth.subAccount)
put("subaccount_sig", auth.subAccountSig)
Expand All @@ -502,8 +538,8 @@ class ConfigFactory @Inject constructor(
}

override fun signForPushRegistry(data: ByteArray): Map<String, String> {
return factory.withGroupConfigs(accountId) {
val auth = it.groupKeys.subAccountSign(data, authData)
return keyAccess.accessKeys {
val auth = it.subAccountSign(data, authData)
buildMap {
put("subkey_tag", auth.subAccount)
put("signature", auth.signature)
Expand Down

This file was deleted.

Loading