mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 01:31:02 +00:00
Randomize identity database name
This commit is contained in:
parent
0082360692
commit
ca49611df5
2 changed files with 16 additions and 3 deletions
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue