Rework isDatabasePasswordAccessible.
This commit is contained in:
parent
62be08027d
commit
5c19d29140
@ -170,6 +170,11 @@ static NSTimeInterval launchStartedAt;
|
||||
return SSKEnvironment.shared.syncManager;
|
||||
}
|
||||
|
||||
- (StorageCoordinator *)storageCoordinator
|
||||
{
|
||||
return SSKEnvironment.shared.storageCoordinator;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application
|
||||
@ -333,7 +338,7 @@ static NSTimeInterval launchStartedAt;
|
||||
|
||||
// GRDB TODO: We should consult YDB and GRDB. This should be done via storage coordinator,
|
||||
// which knows which checks we need to do.
|
||||
if (![OWSPrimaryStorage isDatabasePasswordAccessible]) {
|
||||
if (![self.storageCoordinator isDatabasePasswordAccessible]) {
|
||||
OWSLogInfo(@"exiting because we are in the background and the database password is not accessible.");
|
||||
|
||||
UILocalNotification *notification = [UILocalNotification new];
|
||||
|
||||
@ -149,6 +149,7 @@ public class SDSDatabaseStorage: SDSTransactable {
|
||||
Logger.error("storageMode: \(FeatureFlags.storageMode).")
|
||||
Logger.error(
|
||||
"StorageCoordinatorState: \(storageCoordinatorStateDescription).")
|
||||
|
||||
switch FeatureFlags.storageModeStrictness {
|
||||
case .fail:
|
||||
owsFail("Unexpected YDB load.")
|
||||
@ -679,8 +680,20 @@ public class GRDBDatabaseStorageAdapter: NSObject {
|
||||
|
||||
private let databaseUrl: URL
|
||||
|
||||
private let keyServiceName: String = "TSKeyChainService"
|
||||
private let keyName: String = "OWSDatabaseCipherKeySpec"
|
||||
private static let keyServiceName: String = "TSKeyChainService"
|
||||
private static let keyName: String = "OWSDatabaseCipherKeySpec"
|
||||
private static var keyspec: GRDBKeySpecSource {
|
||||
return GRDBKeySpecSource(keyServiceName: keyServiceName, keyName: keyName)
|
||||
}
|
||||
@objc
|
||||
public static var isKeyAccessible: Bool {
|
||||
do {
|
||||
return try keyspec.fetchString().count > 0
|
||||
} catch {
|
||||
owsFailDebug("Key not accessible: \(error)")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
private let storage: GRDBStorage
|
||||
|
||||
@ -691,7 +704,7 @@ public class GRDBDatabaseStorageAdapter: NSObject {
|
||||
init(baseDir: URL) throws {
|
||||
databaseUrl = GRDBDatabaseStorageAdapter.databaseFileUrl(baseDir: baseDir)
|
||||
|
||||
storage = try GRDBStorage(dbURL: databaseUrl, keyServiceName: keyServiceName, keyName: keyName)
|
||||
storage = try GRDBStorage(dbURL: databaseUrl, keyspec: GRDBDatabaseStorageAdapter.keyspec)
|
||||
|
||||
super.init()
|
||||
|
||||
@ -1083,9 +1096,8 @@ private struct GRDBStorage {
|
||||
private let dbURL: URL
|
||||
private let configuration: Configuration
|
||||
|
||||
init(dbURL: URL, keyServiceName: String, keyName: String) throws {
|
||||
init(dbURL: URL, keyspec: GRDBKeySpecSource) throws {
|
||||
self.dbURL = dbURL
|
||||
let keyspec = GRDBKeySpecSource(keyServiceName: keyServiceName, keyName: keyName)
|
||||
|
||||
var configuration = Configuration()
|
||||
configuration.readonly = false
|
||||
|
||||
@ -28,6 +28,8 @@ NSString *NSStringFromStorageCoordinatorState(StorageCoordinatorState value);
|
||||
- (void)migrationYDBToGRDBWillBegin;
|
||||
- (void)migrationYDBToGRDBDidComplete;
|
||||
|
||||
- (BOOL)isDatabasePasswordAccessible;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@ -132,6 +132,21 @@ NSString *NSStringFromStorageCoordinatorState(StorageCoordinatorState value)
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isDatabasePasswordAccessible
|
||||
{
|
||||
if (self.databaseStorage.canLoadYdb) {
|
||||
if (![OWSPrimaryStorage isDatabasePasswordAccessible]) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
if (self.databaseStorage.canLoadGrdb) {
|
||||
if (![GRDBDatabaseStorageAdapter isKeyAccessible]) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
Loading…
Reference in New Issue
Block a user