Commit 55bd65d7 authored by Benoit Marty's avatar Benoit Marty
Browse files

Create Manager to inject directly instead of service

Cleanup the Service from app point of view
parent b2a4b0c2
......@@ -77,9 +77,4 @@ interface CrossSigningService {
fun checkDeviceTrust(otherUserId: String,
otherDeviceId: String,
locallyTrusted: Boolean?): DeviceTrustResult
// FIXME Those method do not have to be in the service
fun onSecretMSKGossip(mskPrivateKey: String)
fun onSecretSSKGossip(sskPrivateKey: String)
fun onSecretUSKGossip(uskPrivateKey: String)
}
......@@ -173,8 +173,6 @@ interface KeysBackupService {
password: String,
callback: MatrixCallback<Unit>)
fun onSecretKeyGossip(secret: String)
/**
* Restore a backup with a recovery key from a given backup version stored on the homeserver.
*
......
......@@ -16,7 +16,6 @@
package org.matrix.android.sdk.api.session.crypto.verification
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.LocalEcho
/**
......@@ -137,6 +136,4 @@ interface VerificationService {
return age in tooInThePast..tooInTheFuture
}
}
fun onPotentiallyInterestingEventRoomFailToDecrypt(event: Event)
}
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.crypto
import org.matrix.android.sdk.api.session.events.model.Event
internal interface CryptoDecryptor {
fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult
}
......@@ -57,9 +57,10 @@ import org.matrix.android.sdk.internal.crypto.algorithms.IMXGroupEncryption
import org.matrix.android.sdk.internal.crypto.algorithms.IMXWithHeldExtension
import org.matrix.android.sdk.internal.crypto.algorithms.megolm.MXMegolmEncryptionFactory
import org.matrix.android.sdk.internal.crypto.algorithms.olm.MXOlmEncryptionFactory
import org.matrix.android.sdk.internal.crypto.crosssigning.DefaultCrossSigningService
import org.matrix.android.sdk.internal.crypto.crosssigning.CrossSigningManagerInput
import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustLevel
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
import org.matrix.android.sdk.internal.crypto.keysbackup.KeysBackupManager
import org.matrix.android.sdk.internal.crypto.keysbackup.KeysBackupManagerInput
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.internal.crypto.model.ImportRoomKeysResult
import org.matrix.android.sdk.internal.crypto.model.MXDeviceInfo
......@@ -80,7 +81,6 @@ import org.matrix.android.sdk.internal.crypto.tasks.GetDeviceInfoTask
import org.matrix.android.sdk.internal.crypto.tasks.GetDevicesTask
import org.matrix.android.sdk.internal.crypto.tasks.SetDeviceNameTask
import org.matrix.android.sdk.internal.crypto.tasks.UploadKeysTask
import org.matrix.android.sdk.internal.crypto.verification.DefaultVerificationService
import org.matrix.android.sdk.internal.di.DeviceId
import org.matrix.android.sdk.internal.di.MoshiProvider
import org.matrix.android.sdk.internal.di.UserId
......@@ -101,14 +101,7 @@ import javax.inject.Inject
import kotlin.math.max
/**
* A `CryptoService` class instance manages the end-to-end crypto for a session.
*
*
* Messages posted by the user are automatically redirected to CryptoService in order to be encrypted
* before sending.
* In the other hand, received events goes through CryptoService for decrypting.
* CryptoService maintains all necessary keys and their sharing with other devices required for the crypto.
* Specially, it tracks all room membership changes events in order to do keys updates.
*/
@SessionScope
internal class CryptoManager @Inject constructor(
......@@ -129,18 +122,15 @@ internal class CryptoManager @Inject constructor(
private val mxCryptoConfig: MXCryptoConfig,
// Device list manager
private val deviceListManager: DeviceListManager,
// The key backup service.
private val keysBackupService: DefaultKeysBackupService,
private val keysBackupManager: KeysBackupManager,
private val keysBackupManagerInput: KeysBackupManagerInput,
//
private val objectSigner: ObjectSigner,
//
private val oneTimeKeysUploader: OneTimeKeysUploader,
//
private val roomDecryptorProvider: RoomDecryptorProvider,
// The verification service.
private val verificationService: DefaultVerificationService,
private val crossSigningService: DefaultCrossSigningService,
private val crossSigningManagerInput: CrossSigningManagerInput,
//
private val incomingGossipingRequestManager: IncomingGossipingRequestManager,
//
......@@ -164,12 +154,15 @@ internal class CryptoManager @Inject constructor(
private val taskExecutor: TaskExecutor,
private val cryptoCoroutineScope: CoroutineScope,
private val eventDecryptor: EventDecryptor
) : CryptoService {
) : CryptoService,
CryptoManagerInput,
CryptoDecryptor,
CryptoSyncInput {
private val isStarting = AtomicBoolean(false)
private val isStarted = AtomicBoolean(false)
fun onStateEvent(roomId: String, event: Event) {
override fun onStateEvent(roomId: String, event: Event) {
when (event.getClearType()) {
EventType.STATE_ROOM_ENCRYPTION -> onRoomEncryptionEvent(roomId, event)
EventType.STATE_ROOM_MEMBER -> onRoomMembershipEvent(roomId, event)
......@@ -177,7 +170,7 @@ internal class CryptoManager @Inject constructor(
}
}
fun onLiveEvent(roomId: String, event: Event) {
override fun onLiveEvent(roomId: String, event: Event) {
when (event.getClearType()) {
EventType.STATE_ROOM_ENCRYPTION -> onRoomEncryptionEvent(roomId, event)
EventType.STATE_ROOM_MEMBER -> onRoomMembershipEvent(roomId, event)
......@@ -185,7 +178,7 @@ internal class CryptoManager @Inject constructor(
}
}
val gossipingBuffer = mutableListOf<Event>()
private val gossipingBuffer = mutableListOf<Event>()
override fun setDeviceName(deviceId: String, deviceName: String, callback: MatrixCallback<Unit>) {
setDeviceNameTask
......@@ -322,12 +315,12 @@ internal class CryptoManager @Inject constructor(
oneTimeKeysUploader.maybeUploadOneTimeKeys()
// this can throw if no backup
tryOrNull {
keysBackupService.checkAndStartKeysBackup()
keysBackupManager.checkAndStartKeysBackup()
}
}
}
fun onSyncWillProcess(isInitialSync: Boolean) {
override fun onSyncWillProcess(isInitialSync: Boolean) {
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
if (isInitialSync) {
try {
......@@ -391,24 +384,18 @@ internal class CryptoManager @Inject constructor(
// Always enabled on Matrix Android SDK2
override fun isCryptoEnabled() = true
/**
* @return the Keys backup Service
*/
override fun keysBackupService() = keysBackupService
override fun keysBackupService() = error("Dev error")
/**
* @return the VerificationService
*/
override fun verificationService() = verificationService
override fun verificationService() = error("Dev error")
override fun crossSigningService() = crossSigningService
override fun crossSigningService() = error("Dev error")
/**
* A sync response has been received
*
* @param syncResponse the syncResponse
*/
fun onSyncCompleted(syncResponse: SyncResponse) {
override fun onSyncCompleted(syncResponse: SyncResponse) {
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
runCatching {
if (syncResponse.deviceLists != null) {
......@@ -685,7 +672,7 @@ internal class CryptoManager @Inject constructor(
*/
@Throws(MXCryptoError::class)
override fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
return internalDecryptEvent(event, timeline)
return eventDecryptor.decryptEvent(event, timeline)
}
/**
......@@ -699,18 +686,6 @@ internal class CryptoManager @Inject constructor(
eventDecryptor.decryptEventAsync(event, timeline, callback)
}
/**
* Decrypt an event
*
* @param event the raw event.
* @param timeline the id of the timeline where the event is decrypted. It is used to prevent replay attack.
* @return the MXEventDecryptionResult data, or null in case of error
*/
@Throws(MXCryptoError::class)
private fun internalDecryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
return eventDecryptor.decryptEvent(event, timeline)
}
/**
* Reset replay attack data for the given timeline.
*
......@@ -725,7 +700,7 @@ internal class CryptoManager @Inject constructor(
*
* @param event the event
*/
fun onToDeviceEvent(event: Event) {
override fun onToDeviceEvent(event: Event) {
// event have already been decrypted
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
when (event.getClearType()) {
......@@ -772,7 +747,10 @@ internal class CryptoManager @Inject constructor(
Timber.e("## CRYPTO | GOSSIP onRoomKeyEvent() : Unable to handle keys for ${roomKeyContent.algorithm}")
return
}
alg.onRoomKeyEvent(event, keysBackupService)
val doKeyBackup = alg.onRoomKeyEvent(event)
if (doKeyBackup) {
keysBackupManager.maybeBackupKeys()
}
}
private fun onKeyWithHeldReceived(event: Event) {
......@@ -825,19 +803,19 @@ internal class CryptoManager @Inject constructor(
private fun handleSDKLevelGossip(secretName: String?, secretValue: String): Boolean {
return when (secretName) {
MASTER_KEY_SSSS_NAME -> {
crossSigningService.onSecretMSKGossip(secretValue)
crossSigningManagerInput.onSecretMSKGossip(secretValue)
true
}
SELF_SIGNING_KEY_SSSS_NAME -> {
crossSigningService.onSecretSSKGossip(secretValue)
crossSigningManagerInput.onSecretSSKGossip(secretValue)
true
}
USER_SIGNING_KEY_SSSS_NAME -> {
crossSigningService.onSecretUSKGossip(secretValue)
crossSigningManagerInput.onSecretUSKGossip(secretValue)
true
}
KEYBACKUP_SECRET_SSSS_NAME -> {
keysBackupService.onSecretKeyGossip(secretValue)
keysBackupManagerInput.onSecretKeyGossip(secretValue)
true
}
else -> false
......
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.crypto
import org.matrix.android.sdk.api.session.events.model.Event
internal interface CryptoManagerInput {
fun onSyncWillProcess(isInitialSync: Boolean)
fun onStateEvent(roomId: String, event: Event)
fun onLiveEvent(roomId: String, event: Event)
}
......@@ -96,6 +96,14 @@ import org.matrix.android.sdk.internal.session.cache.RealmClearCacheTask
import io.realm.RealmConfiguration
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupService
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
import org.matrix.android.sdk.internal.crypto.crosssigning.CrossSigningManager
import org.matrix.android.sdk.internal.crypto.crosssigning.CrossSigningManagerInput
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
import org.matrix.android.sdk.internal.crypto.keysbackup.KeysBackupManager
import org.matrix.android.sdk.internal.crypto.keysbackup.KeysBackupManagerInput
import org.matrix.android.sdk.internal.crypto.verification.DefaultVerificationService
import retrofit2.Retrofit
import java.io.File
......@@ -160,6 +168,21 @@ internal abstract class CryptoModule {
@Binds
abstract fun bindCryptoService(service: DefaultCryptoService): CryptoService
@Binds
abstract fun bindKeysBackupService(service: DefaultKeysBackupService): KeysBackupService
@Binds
abstract fun bindVerificationService(service: DefaultVerificationService): VerificationService
@Binds
abstract fun bindCryptoManagerInput(manager: CryptoManager): CryptoManagerInput
@Binds
abstract fun bindKeysBackupManagerInput(manager: KeysBackupManager): KeysBackupManagerInput
@Binds
abstract fun bindCrossSigningManagerInput(manager: CrossSigningManager): CrossSigningManagerInput
@Binds
abstract fun bindDeleteDeviceTask(task: DefaultDeleteDeviceTask): DeleteDeviceTask
......
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.crypto
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.internal.session.sync.model.SyncResponse
internal interface CryptoSyncInput {
fun onToDeviceEvent(event: Event)
fun onSyncCompleted(syncResponse: SyncResponse)
}
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.crypto
import androidx.annotation.VisibleForTesting
import org.matrix.android.sdk.api.session.crypto.CryptoService
import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningService
import org.matrix.android.sdk.api.session.crypto.keysbackup.KeysBackupService
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService
import javax.inject.Inject
/**
* A `CryptoService` class instance manages the end-to-end crypto for a session.
*
* Messages posted by the user are automatically redirected to CryptoService in order to be encrypted
* before sending.
* In the other hand, received events goes through CryptoService for decrypting.
* CryptoService maintains all necessary keys and their sharing with other devices required for the crypto.
* Specially, it tracks all room membership changes events in order to do keys updates.
*
* Implementation is basically a wrapper for [CryptoManager]
*/
internal class DefaultCryptoService @Inject constructor(
private val cryptoManager: CryptoManager,
private val keysBackupService: KeysBackupService,
private val verificationService: VerificationService,
private val crossSigningService: CrossSigningService,
) : CryptoService by cryptoManager {
override fun keysBackupService() = keysBackupService
override fun verificationService() = verificationService
override fun crossSigningService() = crossSigningService
/* ==========================================================================================
* For test only
* ========================================================================================== */
@VisibleForTesting
val cryptoStoreForTesting = cryptoManager.cryptoStoreForTesting
}
......@@ -44,10 +44,6 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM
coroutineDispatchers: MatrixCoroutineDispatchers,
private val taskExecutor: TaskExecutor) {
interface UserDevicesUpdateListener {
fun onUsersDeviceUpdate(userIds: List<String>)
}
private val deviceChangeListeners = mutableListOf<UserDevicesUpdateListener>()
fun addListener(listener: UserDevicesUpdateListener) {
......
......@@ -136,7 +136,7 @@ internal class EventDecryptor @Inject constructor(
val lastForcedDate = lastNewSessionForcedDates.getObject(senderId, deviceKey) ?: 0
val now = System.currentTimeMillis()
if (now - lastForcedDate < DefaultCryptoService.CRYPTO_MIN_FORCE_SESSION_PERIOD_MILLIS) {
if (now - lastForcedDate < CryptoManager.CRYPTO_MIN_FORCE_SESSION_PERIOD_MILLIS) {
Timber.w("## CRYPTO | markOlmSessionForUnwedging: New session already forced with device at $lastForcedDate. Not forcing another")
return
}
......
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.crypto
internal interface UserDevicesUpdateListener {
fun onUsersDeviceUpdate(userIds: List<String>)
}
......@@ -17,7 +17,7 @@
package org.matrix.android.sdk.internal.crypto.actions
import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustLevel
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
import org.matrix.android.sdk.internal.crypto.keysbackup.KeysBackupManager
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
import org.matrix.android.sdk.internal.di.UserId
import timber.log.Timber
......@@ -26,7 +26,8 @@ import javax.inject.Inject
internal class SetDeviceVerificationAction @Inject constructor(
private val cryptoStore: IMXCryptoStore,
@UserId private val userId: String,
private val defaultKeysBackupService: DefaultKeysBackupService) {
private val keysBackupManager: KeysBackupManager
) {
fun handle(trustLevel: DeviceTrustLevel, userId: String, deviceId: String) {
val device = cryptoStore.getUserDevice(userId, deviceId)
......@@ -42,7 +43,7 @@ internal class SetDeviceVerificationAction @Inject constructor(
// If one of the user's own devices is being marked as verified / unverified,
// check the key backup status, since whether or not we use this depends on
// whether it has a signature from a verified device
defaultKeysBackupService.checkAndStartKeysBackup()
keysBackupManager.checkAndStartKeysBackup()
}
}
......
......@@ -21,7 +21,6 @@ import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.internal.crypto.IncomingRoomKeyRequest
import org.matrix.android.sdk.internal.crypto.IncomingSecretShareRequest
import org.matrix.android.sdk.internal.crypto.MXEventDecryptionResult
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
/**
* An interface for decrypting data
......@@ -42,8 +41,9 @@ internal interface IMXDecrypting {
* Handle a key event.
*
* @param event the key event.
* @return true if the key should be backed up
*/
fun onRoomKeyEvent(event: Event, defaultKeysBackupService: DefaultKeysBackupService) {}
fun onRoomKeyEvent(event: Event): Boolean = false
/**
* Check if the some messages can be decrypted with a new session
......
......@@ -30,7 +30,6 @@ import org.matrix.android.sdk.internal.crypto.actions.EnsureOlmSessionsForDevice
import org.matrix.android.sdk.internal.crypto.actions.MessageEncrypter
import org.matrix.android.sdk.internal.crypto.algorithms.IMXDecrypting
import org.matrix.android.sdk.internal.crypto.algorithms.IMXWithHeldExtension
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.internal.crypto.model.event.EncryptedEventContent
import org.matrix.android.sdk.internal.crypto.model.event.RoomKeyContent
......@@ -229,10 +228,10 @@ internal class MXMegolmDecryption(private val userId: String,
*
* @param event the key event.
*/
override fun onRoomKeyEvent(event: Event, defaultKeysBackupService: DefaultKeysBackupService) {
override fun onRoomKeyEvent(event: Event): Boolean {
Timber.v("## CRYPTO | onRoomKeyEvent()")
var exportFormat = false
val roomKeyContent = event.getClearContent().toModel<RoomKeyContent>() ?: return
val roomKeyContent = event.getClearContent().toModel<RoomKeyContent>() ?: return false
var senderKey: String? = event.getSenderKey()
var keysClaimed: MutableMap<String, String> = HashMap()
......@@ -240,12 +239,12 @@ internal class MXMegolmDecryption(private val userId: String,
if (roomKeyContent.roomId.isNullOrEmpty() || roomKeyContent.sessionId.isNullOrEmpty() || roomKeyContent.sessionKey.isNullOrEmpty()) {
Timber.e("## CRYPTO | onRoomKeyEvent() : Key event is missing fields")
return
return false
}
if (event.getClearType() == EventType.FORWARDED_ROOM_KEY) {
Timber.i("## CRYPTO | onRoomKeyEvent(), forward adding key : ${roomKeyContent.roomId}|${roomKeyContent.sessionId}")
val forwardedRoomKeyContent = event.getClearContent().toModel<ForwardedRoomKeyContent>()
?: return
?: return false
forwardedRoomKeyContent.forwardingCurve25519KeyChain?.let {
forwardingCurve25519KeyChain.addAll(it)
......@@ -253,7 +252,7 @@ internal class MXMegolmDecryption(private val userId: String,
if (senderKey == null) {
Timber.e("## CRYPTO | onRoomKeyEvent() : event is missing sender_key field")
return
return false
}
forwardingCurve25519KeyChain.add(senderKey)
......@@ -262,12 +261,12 @@ internal class MXMegolmDecryption(private val userId: String,
senderKey = forwardedRoomKeyContent.senderKey
if (null == senderKey) {
Timber.e("## CRYPTO | onRoomKeyEvent() : forwarded_room_key event is missing sender_key field")
return
return false
}
if (null == forwardedRoomKeyContent.senderClaimedEd25519Key) {
Timber.e("## CRYPTO | forwarded_room_key_event is missing sender_claimed_ed25519_key field")
return
return false
}
keysClaimed["ed25519"] = forwardedRoomKeyContent.senderClaimedEd25519Key
......@@ -275,7 +274,7 @@ internal class MXMegolmDecryption(private val userId: String,
Timber.i("## CRYPTO | onRoomKeyEvent(), Adding key : ${roomKeyContent.roomId}|${roomKeyContent.sessionId}")
if (null == senderKey) {
Timber.e("## onRoomKeyEvent() : key event has no sender key (not encrypted?)")
return
return false
}
// inherit the claimed ed25519 key from the setup message
......@@ -292,8 +291,6 @@ internal class MXMegolmDecryption(private val userId: String,
exportFormat)
if (added) {
defaultKeysBackupService.maybeBackupKeys()
val content = RoomKeyRequestBody(
algorithm = roomKeyContent.algorithm,
roomId = roomKeyContent.roomId,
......@@ -305,6 +302,8 @@ internal class MXMegolmDecryption(private val userId: String,
onNewSession(senderKey, roomKeyContent.sessionId)
}
return added
}
/**
......
......@@ -29,7 +29,7 @@ import org.matrix.android.sdk.internal.crypto.actions.EnsureOlmSessionsForDevice
import org.matrix.android.sdk.internal.crypto.actions.MessageEncrypter
import org.matrix.android.sdk.internal.crypto.algorithms.IMXEncrypting
import org.matrix.android.sdk.internal.crypto.algorithms.IMXGroupEncryption
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
import org.matrix.android.sdk.internal.crypto.keysbackup.KeysBackupManager
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.internal.crypto.model.event.RoomKeyWithHeldContent
......@@ -47,7 +47,7 @@ internal class MXMegolmEncryption(
// The id of the room we will be sending to.
private val roomId: String,
private val olmDevice: MXOlmDevice,
private val defaultKeysBackupService: DefaultKeysBackupService,
private val keysBackupManager: KeysBackupManager,
private val cryptoStore: IMXCryptoStore,
private val deviceListManager: DeviceListManager,
private val ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction,
......@@ -142,7 +142,7 @@ internal class MXMegolmEncryption(
olmDevice.addInboundGroupSession(sessionId!!, olmDevice.getSessionKey(sessionId)!!, roomId, olmDevice.deviceCurve25519Key!!,
emptyList(), keysClaimedMap, false)
defaultKeysBackupService.maybeBackupKeys()
keysBackupManager.maybeBackupKeys()
return MXOutboundSessionInfo(sessionId, SharedWithHelper(roomId, sessionId, cryptoStore))
}
......
......@@ -21,7 +21,7 @@ import org.matrix.android.sdk.internal.crypto.DeviceListManager
import org.matrix.android.sdk.internal.crypto.MXOlmDevice
import org.matrix.android.sdk.internal.crypto.actions.EnsureOlmSessionsForDevicesAction
import org.matrix.android.sdk.internal.crypto.actions.MessageEncrypter
import org.matrix.android.sdk.internal.crypto.keysbackup.DefaultKeysBackupService
import org.matrix.android.sdk.internal.crypto.keysbackup.KeysBackupManager
import org.matrix.android.sdk.internal.crypto.repository.WarnOnUnknownDeviceRepository
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
import org.matrix.android.sdk.internal.crypto.tasks.SendToDeviceTask
......@@ -32,7 +32,7 @@ import javax.inject.Inject
internal class MXMegolmEncryptionFactory @Inject constructor(
private val olmDevice: MXOlmDevice,
private val defaultKeysBackupService: DefaultKeysBackupService,
private val keysBackupManager: KeysBackupManager,
private val cryptoStore: IMXCryptoStore,
private val deviceListManager: DeviceListManager,
private val ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction,
......@@ -48,7 +48,7 @@ internal class MXMegolmEncryptionFactory @Inject constructor(
return MXMegolmEncryption(
roomId = roomId,
olmDevice = olmDevice,
defaultKeysBackupService = defaultKeysBackupService,
keysBackupManager = keysBackupManager,
cryptoStore = cryptoStore,
deviceListManager = deviceListManager,
ensureOlmSessionsForDevicesAction = ensureOlmSessionsForDevicesAction,
......
......@@ -28,6 +28,7 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningServic
import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.crypto.DeviceListManager
import org.matrix.android.sdk.internal.crypto.UserDevicesUpdateListener
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.internal.crypto.model.rest.UploadSignatureQueryBuilder
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
......@@ -65,7 +66,8 @@ internal class CrossSigningManager @Inject constructor(
private val workManagerProvider: WorkManagerProvider,
private val updateTrustWorkerDataRepository: UpdateTrustWorkerDataRepository
) : CrossSigningService,
DeviceListManager.UserDevicesUpdateListener {
CrossSigningManagerInput,
UserDevicesUpdateListener {
private var olmUtility: OlmUtility? = null
......
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.crypto.crosssigning
internal interface CrossSigningManagerInput {
fun onSecretMSKGossip(mskPrivateKey: String)
fun onSecretSSKGossip(sskPrivateKey: String)
fun onSecretUSKGossip(uskPrivateKey: String)
}
/*
* Copyright 2020 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.crypto.crosssigning
import org.matrix.android.sdk.api.session.crypto.crosssigning.CrossSigningService
import javax.inject.Inject
internal class DefaultCrossSigningService @Inject constructor(
crossSigningManager: CrossSigningManager
) : CrossSigningService by crossSigningManager
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment