fix(sync): запретил зашифрованные storage в группах и перевёл резолв storages на FindStorageUseCase
This commit is contained in:
@@ -14,6 +14,7 @@ sealed interface AddStorageToSyncGroupResult {
|
||||
data object Added : AddStorageToSyncGroupResult
|
||||
data object GroupNotFound : AddStorageToSyncGroupResult
|
||||
data object AlreadyInGroup : AddStorageToSyncGroupResult
|
||||
data object EncryptedStorageNotAllowed : AddStorageToSyncGroupResult
|
||||
data object IncompatibleEncryption : AddStorageToSyncGroupResult
|
||||
data object MissingEncryptionSecret : AddStorageToSyncGroupResult
|
||||
}
|
||||
@@ -56,14 +57,12 @@ class ManageStorageSyncGroupsUseCase(
|
||||
if (storageUuid in current.storageUuids) {
|
||||
return AddStorageToSyncGroupResult.AlreadyInGroup
|
||||
}
|
||||
|
||||
val encryptedSecret = compatibility.encryptionSecret?.takeIf { it.isNotBlank() }
|
||||
val effectiveEncryption = when {
|
||||
!compatibility.isEncrypted -> StorageSyncGroupEncryptionKind.NONE to null
|
||||
encryptedSecret == null -> return AddStorageToSyncGroupResult.MissingEncryptionSecret
|
||||
else -> StorageSyncGroupEncryptionKind.PASSWORD to encryptedSecret
|
||||
if (compatibility.isEncrypted) {
|
||||
return AddStorageToSyncGroupResult.EncryptedStorageNotAllowed
|
||||
}
|
||||
|
||||
val effectiveEncryption = StorageSyncGroupEncryptionKind.NONE to null
|
||||
|
||||
val (nextKind, nextSecret) = when (current.encryptionKind) {
|
||||
StorageSyncGroupEncryptionKind.UNSET -> effectiveEncryption
|
||||
StorageSyncGroupEncryptionKind.NONE -> {
|
||||
@@ -74,13 +73,7 @@ class ManageStorageSyncGroupsUseCase(
|
||||
}
|
||||
|
||||
StorageSyncGroupEncryptionKind.PASSWORD -> {
|
||||
if (
|
||||
effectiveEncryption.first != StorageSyncGroupEncryptionKind.PASSWORD ||
|
||||
current.encryptionSecret != effectiveEncryption.second
|
||||
) {
|
||||
return AddStorageToSyncGroupResult.IncompatibleEncryption
|
||||
}
|
||||
StorageSyncGroupEncryptionKind.PASSWORD to current.encryptionSecret
|
||||
return AddStorageToSyncGroupResult.IncompatibleEncryption
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,13 @@ fun isStorageCompatibleWithGroup(
|
||||
group: StorageSyncGroup,
|
||||
resolveStorageKey: (UUID) -> EncryptKey?,
|
||||
): Boolean {
|
||||
// Режим упрощён: в sync-группах допускаются только незашифрованные storage.
|
||||
if (storage.metaInfo.value.encInfo != null) {
|
||||
return false
|
||||
}
|
||||
return when (group.encryptionKind) {
|
||||
StorageSyncGroupEncryptionKind.UNSET -> true
|
||||
StorageSyncGroupEncryptionKind.NONE -> storage.metaInfo.value.encInfo == null
|
||||
StorageSyncGroupEncryptionKind.PASSWORD -> {
|
||||
val groupSecret = group.encryptionSecret ?: return false
|
||||
if (storage.metaInfo.value.encInfo == null) {
|
||||
return false
|
||||
}
|
||||
val currentSecret = resolveStorageKey(storage.uuid)?.let(::storageEncryptionSecret)
|
||||
currentSecret != null && currentSecret == groupSecret
|
||||
}
|
||||
StorageSyncGroupEncryptionKind.NONE -> true
|
||||
StorageSyncGroupEncryptionKind.PASSWORD -> false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.concurrent.atomic.AtomicLong
|
||||
class StorageSyncEngine(
|
||||
private val vaultsManager: IVaultsManager,
|
||||
private val groupStore: IStorageSyncGroupStore,
|
||||
private val findStorageUseCase: FindStorageUseCase,
|
||||
) : IStorageSyncEngine {
|
||||
private val holderId: String = UUID.randomUUID().toString()
|
||||
private val groupMutexes = ConcurrentHashMap<String, Mutex>()
|
||||
@@ -207,8 +208,7 @@ class StorageSyncEngine(
|
||||
}
|
||||
|
||||
private fun resolveStorages(uuids: Set<UUID>): List<IStorage> {
|
||||
val byUuid = vaultsManager.allStorages.value.associateBy { it.uuid }
|
||||
return uuids.mapNotNull { byUuid[it] }
|
||||
return uuids.mapNotNull(findStorageUseCase::find)
|
||||
}
|
||||
|
||||
private fun latestByPath(entries: List<StorageSyncJournalEntry>): Map<String, StorageSyncJournalEntry> {
|
||||
|
||||
Reference in New Issue
Block a user