Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Resolve local database access issues #1202

Merged
merged 3 commits into from
Apr 8, 2020
Merged

Conversation

kaylagalway
Copy link
Contributor

@kaylagalway kaylagalway commented Apr 3, 2020

Fixes #1201

Database salt and plain text header migration failed for certain users with the update of 1.7.2, which left their app in an unusable state as the database was not accessible. This PR resolves those issues and resets the local database without deleting any user sync data.

@kaylagalway kaylagalway requested a review from a team as a code owner April 3, 2020 23:56
@kaylagalway
Copy link
Contributor Author

Build currently failing because new certificates need to be uploaded to buddybuild. Resolving on Monday.

Copy link

@eliserichards eliserichards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Shared/Store/BaseDataStore.swift Outdated Show resolved Hide resolved
Shared/Store/BaseDataStore.swift Outdated Show resolved Hide resolved
Comment on lines +530 to +533
enum DatabaseError: Error {
case issueDeletingDatabase(description: String)
case issueCreatingDatabase(description: String)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

}

private func createNewDatabase() throws {
guard let encryptionKey = loginsKey else { throw DatabaseError.issueCreatingDatabase(description: "logins database key is nil") }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Copy link
Contributor

@jhugman jhugman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I'd be even happier if we had a minimal AlertDialog shown if and only if out error recovery errored or detected something we weren't able to recover from (i.e. returned nil).

Well done for fixing this long standing bug!

@@ -487,19 +491,59 @@ extension BaseDataStore {
guard let db = loginsStorage as? LoginsStorage else {
return createRandomSalt()
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: whitespace


do {
try loginsStorage.ensureUnlockedWithKeyAndSalt(key: loginsKey, salt: salt)
self.storageStateSubject.onNext(.Unlocked)
} catch let error as LoginsStoreError {
pushError(error)
// If we can not access database with current salt and key, need to delete local database and migrate to replacement salt
// This only deletes the local database file, does not delete the user's sync data
_ = handleDatabaseAccessFailure(databasePath: loginsDatabasePath, encryptionKey: loginsKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we fail in this method, what happens? e.g. if we throw an unexpected runtime exception, or if the app can't continue, perhaps we could fail more loudly (e.g. alert) than a crash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails - maybe I could fire off a reset action from within the handleDatabaseAccessFailure function? I actually changed this so that handleDatabaseAccessFailure doesn't return, as it didn't need to since the salt gets stored locally in the keychain.

@kaylagalway kaylagalway merged commit f501428 into master Apr 8, 2020
@kaylagalway kaylagalway mentioned this pull request Apr 8, 2020
@kaylagalway kaylagalway changed the title Resolves database access issues if locally stored salt or key is incorrect Resolve database access issues if locally stored salt or key is incorrect Apr 9, 2020
@kaylagalway kaylagalway changed the title Resolve database access issues if locally stored salt or key is incorrect Resolve database access issues Apr 9, 2020
@kaylagalway kaylagalway changed the title Resolve database access issues Resolve local database access issues Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lockwise block on purple screen during launch
3 participants