Randomize identity database name

This commit is contained in:
Justin Mazzocchi 2021-01-16 13:46:07 -08:00
parent 0082360692
commit ca49611df5
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
2 changed files with 16 additions and 3 deletions

View File

@ -19,7 +19,9 @@ public struct IdentityDatabase {
databaseWriter = DatabaseQueue()
try Self.migrator.migrate(databaseWriter)
} 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) {
try Secrets.databaseKey(identityId: nil, keychain: keychain)
@ -224,8 +226,6 @@ public extension IdentityDatabase {
}
private extension IdentityDatabase {
static let name = "identity"
static func writePreferences(_ preferences: Identity.Preferences, id: Identity.Id) -> (Database) throws -> Void {
{
let data = try IdentityRecord.databaseJSONEncoder(

View File

@ -32,6 +32,7 @@ public extension Secrets {
case pushKey
case pushAuth
case databaseKey
case identityDatabaseName
}
}
@ -55,6 +56,18 @@ extension Secrets.Item {
}
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
static func databaseKey(identityId: UUID?, keychain: Keychain.Type) throws -> String {
let passphraseData: Data