Remove indirection for some methods
This commit is contained in:
parent
6e45f851f2
commit
3a3ffde3dd
@ -25,6 +25,7 @@ class ProvisioningCoordinatorImpl: ProvisioningCoordinator {
|
||||
private let signalService: OWSSignalServiceProtocol
|
||||
private let storageServiceManager: StorageServiceManager
|
||||
private let svr: SecureValueRecovery
|
||||
private let svrLocalStorage: SVRLocalStorage
|
||||
private let syncManager: SyncManagerProtocol
|
||||
private let threadStore: ThreadStore
|
||||
private let tsAccountManager: TSAccountManager
|
||||
@ -47,6 +48,7 @@ class ProvisioningCoordinatorImpl: ProvisioningCoordinator {
|
||||
signalService: OWSSignalServiceProtocol,
|
||||
storageServiceManager: StorageServiceManager,
|
||||
svr: SecureValueRecovery,
|
||||
svrLocalStorage: SVRLocalStorage,
|
||||
syncManager: SyncManagerProtocol,
|
||||
threadStore: ThreadStore,
|
||||
tsAccountManager: TSAccountManager,
|
||||
@ -68,6 +70,7 @@ class ProvisioningCoordinatorImpl: ProvisioningCoordinator {
|
||||
self.signalService = signalService
|
||||
self.storageServiceManager = storageServiceManager
|
||||
self.svr = svr
|
||||
self.svrLocalStorage = svrLocalStorage
|
||||
self.syncManager = syncManager
|
||||
self.threadStore = threadStore
|
||||
self.tsAccountManager = tsAccountManager
|
||||
@ -479,7 +482,7 @@ class ProvisioningCoordinatorImpl: ProvisioningCoordinator {
|
||||
didLinkNSync: Bool,
|
||||
) async throws(CompleteProvisioningError) {
|
||||
let hasBackedUpMasterKey = self.db.read { tx in
|
||||
self.svr.hasBackedUpMasterKey(transaction: tx)
|
||||
self.svrLocalStorage.isMasterKeyBackedUp(tx: tx)
|
||||
}
|
||||
let capabilities = AccountAttributes.Capabilities(hasSVRBackups: hasBackedUpMasterKey)
|
||||
do {
|
||||
@ -702,7 +705,7 @@ class ProvisioningCoordinatorImpl: ProvisioningCoordinator {
|
||||
|
||||
let phoneNumberDiscoverability = tsAccountManager.phoneNumberDiscoverability(tx: tx)
|
||||
|
||||
let hasSVRBackups = svr.hasBackedUpMasterKey(transaction: tx)
|
||||
let hasSVRBackups = svrLocalStorage.isMasterKeyBackedUp(tx: tx)
|
||||
|
||||
return AccountAttributes(
|
||||
isManualMessageFetchEnabled: isManualMessageFetchEnabled,
|
||||
|
||||
@ -51,6 +51,7 @@ class ProvisioningController: NSObject {
|
||||
signalService: SSKEnvironment.shared.signalServiceRef,
|
||||
storageServiceManager: SSKEnvironment.shared.storageServiceManagerRef,
|
||||
svr: DependenciesBridge.shared.svr,
|
||||
svrLocalStorage: DependenciesBridge.shared.svrLocalStorage,
|
||||
syncManager: SSKEnvironment.shared.syncManagerRef,
|
||||
threadStore: ThreadStoreImpl(),
|
||||
tsAccountManager: DependenciesBridge.shared.tsAccountManager,
|
||||
|
||||
@ -41,6 +41,7 @@ public struct RegistrationCoordinatorDependencies {
|
||||
public let signalService: OWSSignalServiceProtocol
|
||||
public let storageServiceManager: RegistrationCoordinatorImpl.Shims.StorageServiceManager
|
||||
public let svr: SecureValueRecovery
|
||||
public let svrLocalStorage: SVRLocalStorage
|
||||
public let svrAuthCredentialStore: SVRAuthCredentialStorage
|
||||
public let timeoutProvider: RegistrationCoordinatorImpl.Shims.TimeoutProvider
|
||||
public let tsAccountManager: TSAccountManager
|
||||
@ -88,6 +89,7 @@ public struct RegistrationCoordinatorDependencies {
|
||||
signalService: SSKEnvironment.shared.signalServiceRef,
|
||||
storageServiceManager: RegistrationCoordinatorImpl.Wrappers.StorageServiceManager(SSKEnvironment.shared.storageServiceManagerRef),
|
||||
svr: DependenciesBridge.shared.svr,
|
||||
svrLocalStorage: DependenciesBridge.shared.svrLocalStorage,
|
||||
svrAuthCredentialStore: DependenciesBridge.shared.svrCredentialStorage,
|
||||
timeoutProvider: RegistrationCoordinatorImpl.Wrappers.TimeoutProvider(),
|
||||
tsAccountManager: DependenciesBridge.shared.tsAccountManager,
|
||||
|
||||
@ -2313,7 +2313,7 @@ public class RegistrationCoordinatorImpl: RegistrationCoordinator {
|
||||
// If we have a local master key, theres no need to restore after registration.
|
||||
// (we will still back up though)
|
||||
inMemoryState.shouldRestoreSVRMasterKeyAfterRegistration = localMasterKey == nil
|
||||
inMemoryState.didHaveSVRBackupsPriorToReg = deps.svr.hasBackedUpMasterKey(transaction: tx)
|
||||
inMemoryState.didHaveSVRBackupsPriorToReg = deps.svrLocalStorage.isMasterKeyBackedUp(tx: tx)
|
||||
}
|
||||
|
||||
// MARK: - SVR Auth Credential Candidates Pathway
|
||||
|
||||
@ -90,6 +90,7 @@ public class ProvisioningCoordinatorTest: XCTestCase {
|
||||
signalService: signalServiceMock,
|
||||
storageServiceManager: storageServiceManagerMock,
|
||||
svr: svrMock,
|
||||
svrLocalStorage: SVRLocalStorage(),
|
||||
syncManager: syncManagerMock,
|
||||
threadStore: threadStoreMock,
|
||||
tsAccountManager: tsAccountManagerMock,
|
||||
|
||||
@ -160,6 +160,7 @@ public class RegistrationCoordinatorTest {
|
||||
signalService: mockSignalService,
|
||||
storageServiceManager: storageServiceManagerMock,
|
||||
svr: svr,
|
||||
svrLocalStorage: SVRLocalStorage(),
|
||||
svrAuthCredentialStore: svrAuthCredentialStore,
|
||||
timeoutProvider: timeoutProviderMock,
|
||||
tsAccountManager: tsAccountManagerMock,
|
||||
|
||||
@ -80,7 +80,9 @@ class MasterKeySyncManagerImpl: MasterKeySyncManager {
|
||||
}
|
||||
|
||||
private func runStartupJobsForLinkedDevice(tx: DBWriteTransaction) {
|
||||
if svr.hasMasterKey(transaction: tx) {
|
||||
let accountKeyStore = DependenciesBridge.shared.accountKeyStore
|
||||
|
||||
if accountKeyStore.getMasterKey(tx: tx) != nil {
|
||||
// No need to sync; we have the master key.
|
||||
return
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ public class DependenciesBridge {
|
||||
public let storyRecipientManager: StoryRecipientManager
|
||||
public let storyRecipientStore: StoryRecipientStore
|
||||
public let subscriptionConfigManager: SubscriptionConfigManager
|
||||
let svrLocalStorage: SVRLocalStorage
|
||||
public let svrLocalStorage: SVRLocalStorage
|
||||
public let threadAssociatedDataStore: ThreadAssociatedDataStore
|
||||
public let threadRemover: ThreadRemover
|
||||
public let threadReplyInfoStore: ThreadReplyInfoStore
|
||||
|
||||
@ -530,10 +530,13 @@ public enum ExperienceUpgradeManifest: Codable, Equatable, Hashable {
|
||||
|
||||
public static func checkPreconditionsForIntroducingPins(transaction: DBReadTransaction) -> Bool {
|
||||
// The PIN setup flow requires an internet connection and you to not already have a PIN
|
||||
let accountKeyStore = DependenciesBridge.shared.accountKeyStore
|
||||
let tsAccountManager = DependenciesBridge.shared.tsAccountManager
|
||||
let reachabilityManager = SSKEnvironment.shared.reachabilityManagerRef
|
||||
if
|
||||
SSKEnvironment.shared.reachabilityManagerRef.isReachable,
|
||||
DependenciesBridge.shared.tsAccountManager.registrationState(tx: transaction).isRegisteredPrimaryDevice,
|
||||
!DependenciesBridge.shared.svr.hasMasterKey(transaction: transaction)
|
||||
reachabilityManager.isReachable,
|
||||
tsAccountManager.registrationState(tx: transaction).isRegisteredPrimaryDevice,
|
||||
accountKeyStore.getMasterKey(tx: transaction) == nil
|
||||
{
|
||||
return true
|
||||
}
|
||||
|
||||
@ -17,16 +17,6 @@ public class SecureValueRecoveryMock: SecureValueRecovery {
|
||||
public func refreshCredentialsIfNecessary() async throws {
|
||||
}
|
||||
|
||||
public var hasBackedUpMasterKey: Bool = false
|
||||
|
||||
public func hasBackedUpMasterKey(transaction: DBReadTransaction) -> Bool {
|
||||
return hasBackedUpMasterKey
|
||||
}
|
||||
|
||||
public func hasMasterKey(transaction: DBReadTransaction) -> Bool {
|
||||
return SVRLocalStorage().getIsMasterKeyBackedUp(transaction)
|
||||
}
|
||||
|
||||
public var reglockToken: String?
|
||||
|
||||
public var backupMasterKeyMock: ((_ pin: String, _ masterKey: MasterKey, _ force: Bool, _ authMethod: SVR.AuthMethod) -> Promise<Void>)?
|
||||
|
||||
@ -140,7 +140,7 @@ public class AccountAttributesUpdaterImpl: AccountAttributesUpdater {
|
||||
}
|
||||
|
||||
// has non-nil value if isRegistered is true.
|
||||
let hasBackedUpMasterKey = self.svrLocalStorage.getIsMasterKeyBackedUp(tx)
|
||||
let hasBackedUpMasterKey = self.svrLocalStorage.isMasterKeyBackedUp(tx: tx)
|
||||
let capabilities = AccountAttributes.Capabilities(hasSVRBackups: hasBackedUpMasterKey)
|
||||
let lastAttributeRequestToken = self.kvStore.getData(Keys.latestUpdateRequestToken, transaction: tx)
|
||||
|
||||
|
||||
@ -6,10 +6,10 @@
|
||||
import Foundation
|
||||
|
||||
/// Stores state related to SVR; e.g. do we have backups at all, etc.
|
||||
struct SVRLocalStorage {
|
||||
public struct SVRLocalStorage {
|
||||
let completedBackupStore = KeyValueStore(collection: "SVR.Completed")
|
||||
|
||||
func getIsMasterKeyBackedUp(_ transaction: DBReadTransaction) -> Bool {
|
||||
return !completedBackupStore.allKeys(transaction: transaction).isEmpty
|
||||
public func isMasterKeyBackedUp(tx: DBReadTransaction) -> Bool {
|
||||
return !completedBackupStore.allKeys(transaction: tx).isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,12 +103,6 @@ public protocol SecureValueRecovery {
|
||||
/// Performs periodic credential refresh to help with re-registration.
|
||||
func refreshCredentialsIfNecessary() async throws
|
||||
|
||||
/// Indicates whether or not we have a master key locally
|
||||
func hasMasterKey(transaction: DBReadTransaction) -> Bool
|
||||
|
||||
/// Indicates whether or not we have a master key stored in SVR
|
||||
func hasBackedUpMasterKey(transaction: DBReadTransaction) -> Bool
|
||||
|
||||
/// Loads the users key, if any, from the SVR into the database.
|
||||
func restoreKeys(pin: String, authMethod: SVR.AuthMethod) async -> SVR.RestoreKeysResult
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ public class SecureValueRecovery2Impl: SecureValueRecovery {
|
||||
// MARK: - Periodic Backups
|
||||
|
||||
public func refreshCredentialsIfNecessary() async throws {
|
||||
let hasBackedUp = self.db.read { tx in self.hasBackedUpMasterKey(transaction: tx) }
|
||||
let hasBackedUp = self.db.read { tx in self.localStorage.isMasterKeyBackedUp(tx: tx) }
|
||||
guard hasBackedUp else {
|
||||
// If we've never backed up, don't refresh periodically. (If we eventually
|
||||
// perform a backup, we'll cache those credential after fetching them.)
|
||||
@ -61,16 +61,6 @@ public class SecureValueRecovery2Impl: SecureValueRecovery {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Key Existence
|
||||
|
||||
public func hasMasterKey(transaction: DBReadTransaction) -> Bool {
|
||||
return accountKeyStore.getMasterKey(tx: transaction) != nil
|
||||
}
|
||||
|
||||
public func hasBackedUpMasterKey(transaction: DBReadTransaction) -> Bool {
|
||||
return localStorage.getIsMasterKeyBackedUp(transaction)
|
||||
}
|
||||
|
||||
// MARK: - Key Management
|
||||
|
||||
private let backupQueue = ConcurrentTaskQueue(concurrentLimit: 1)
|
||||
|
||||
@ -5181,7 +5181,8 @@ public class GRDBSchemaMigrator {
|
||||
// migration, we want the crash logs reflect where it occurred.
|
||||
|
||||
migrator.registerMigration(.dataMigration_enableV2RegistrationLockIfNecessary) { transaction in
|
||||
if DependenciesBridge.shared.svr.hasMasterKey(transaction: transaction) {
|
||||
let accountKeyStore = DependenciesBridge.shared.accountKeyStore
|
||||
if accountKeyStore.getMasterKey(tx: transaction) != nil {
|
||||
KeyValueStore(collection: "kOWS2FAManager_Collection")
|
||||
.setBool(true, key: "isRegistrationLockV2Enabled", transaction: transaction)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user