Randomize identity database name
This commit is contained in:
parent
0082360692
commit
ca49611df5
|
@ -19,7 +19,9 @@ public struct IdentityDatabase {
|
||||||
databaseWriter = DatabaseQueue()
|
databaseWriter = DatabaseQueue()
|
||||||
try Self.migrator.migrate(databaseWriter)
|
try Self.migrator.migrate(databaseWriter)
|
||||||
} else {
|
} else {
|
||||||
let url = try FileManager.default.databaseDirectoryURL(name: Self.name, appGroup: appGroup)
|
let url = try FileManager.default.databaseDirectoryURL(
|
||||||
|
name: Secrets.identityDatabaseName(keychain: keychain),
|
||||||
|
appGroup: appGroup)
|
||||||
|
|
||||||
databaseWriter = try DatabasePool.withFileCoordinator(url: url, migrator: Self.migrator) {
|
databaseWriter = try DatabasePool.withFileCoordinator(url: url, migrator: Self.migrator) {
|
||||||
try Secrets.databaseKey(identityId: nil, keychain: keychain)
|
try Secrets.databaseKey(identityId: nil, keychain: keychain)
|
||||||
|
@ -224,8 +226,6 @@ public extension IdentityDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension IdentityDatabase {
|
private extension IdentityDatabase {
|
||||||
static let name = "identity"
|
|
||||||
|
|
||||||
static func writePreferences(_ preferences: Identity.Preferences, id: Identity.Id) -> (Database) throws -> Void {
|
static func writePreferences(_ preferences: Identity.Preferences, id: Identity.Id) -> (Database) throws -> Void {
|
||||||
{
|
{
|
||||||
let data = try IdentityRecord.databaseJSONEncoder(
|
let data = try IdentityRecord.databaseJSONEncoder(
|
||||||
|
|
|
@ -32,6 +32,7 @@ public extension Secrets {
|
||||||
case pushKey
|
case pushKey
|
||||||
case pushAuth
|
case pushAuth
|
||||||
case databaseKey
|
case databaseKey
|
||||||
|
case identityDatabaseName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +56,18 @@ extension Secrets.Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension Secrets {
|
public extension Secrets {
|
||||||
|
static func identityDatabaseName(keychain: Keychain.Type) throws -> String {
|
||||||
|
do {
|
||||||
|
return try unscopedItem(.identityDatabaseName, keychain: keychain)
|
||||||
|
} catch SecretsError.itemAbsent {
|
||||||
|
let identityDatabaseName = UUID().uuidString
|
||||||
|
|
||||||
|
try setUnscoped(identityDatabaseName, forItem: .identityDatabaseName, keychain: keychain)
|
||||||
|
|
||||||
|
return identityDatabaseName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
|
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
|
||||||
static func databaseKey(identityId: UUID?, keychain: Keychain.Type) throws -> String {
|
static func databaseKey(identityId: UUID?, keychain: Keychain.Type) throws -> String {
|
||||||
let passphraseData: Data
|
let passphraseData: Data
|
||||||
|
|
Loading…
Reference in New Issue