Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up backport of v121 #17963

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 0 additions & 57 deletions Storage/Rust/RustLogins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,6 @@ public class RustLogins {
}
}

<<<<<<< HEAD:Storage/Rust/RustLogins.swift
private func deleteSQLCipherDBIfExists(sqlCipherDatabasePath: String) {
// If the sqlCipherDatabasePath is valid, we should delete it
do {
Expand All @@ -816,31 +815,7 @@ public class RustLogins {
keychain.removeObject(forKey: rustKeys.loginsSaltKeychainKey, withAccessibility: .afterFirstUnlock)
}

private func resetLoginsAndKey(rustKeys: RustLoginEncryptionKeys,
completion: @escaping (Result<String, NSError>) -> Void) {
self.wipeLocalEngine().upon { result in
guard result.isSuccess else {
completion(.failure(result.failureValue! as NSError))
return
}

do {
let key = try rustKeys.createAndStoreKey()
completion(.success(key))
} catch let error as NSError {
self.logger.log("Error creating logins encryption key",
level: .warning,
category: .storage,
description: error.localizedDescription)
completion(.failure(error))
}
}
}

public func getStoredKey(completion: @escaping (Result<String, NSError>) -> Void) {
=======
public func getStoredKey() throws -> String {
>>>>>>> bc7f27a9f (Revert logins key logic updates (#17954)):firefox-ios/Storage/Rust/RustLogins.swift
let rustKeys = RustLoginEncryptionKeys()
let key = rustKeys.keychain.string(forKey: rustKeys.loginPerFieldKeychainKey)
let encryptedCanaryPhrase = rustKeys.keychain.string(forKey: rustKeys.canaryPhraseKey)
Expand Down Expand Up @@ -897,43 +872,11 @@ public class RustLogins {
throw error
}
case (.none, .none):
<<<<<<< HEAD:Storage/Rust/RustLogins.swift
// We didn't expect the key to be present, which either means this is a first-time
// call or the key data has been cleared from the keychain.

self.hasSyncedLogins().upon { result in
guard result.failureValue == nil else {
completion(.failure(result.failureValue! as NSError))
return
}

guard let hasLogins = result.successValue else {
let msg = "Failed to verify logins count before attempting to reset key"
completion(.failure(LoginEncryptionKeyError.dbRecordCountVerificationError(msg) as NSError))
return
}

if hasLogins {
// Since the key data isn't present and we have login records in
// the database, we both clear the databbase and the reset the key.
self.resetLoginsAndKey(rustKeys: rustKeys, completion: completion)
} else {
// There are no records in the database so we don't need to wipe any
// existing login records. We just need to create a new key.
do {
let key = try rustKeys.createAndStoreKey()
completion(.success(key))
} catch let error as NSError {
completion(.failure(error))
}
}
=======
// We didn't expect the key to be present, and it's not (which is the case for first-time calls).
do {
return try rustKeys.createAndStoreKey()
} catch let error as NSError {
throw error
>>>>>>> bc7f27a9f (Revert logins key logic updates (#17954)):firefox-ios/Storage/Rust/RustLogins.swift
}
default:
// If none of the above cases apply, we're in a state that shouldn't be possible but is disallowed nonetheless
Expand Down
54 changes: 1 addition & 53 deletions firefox-ios/Tests/StorageTests/RustLoginsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,66 +22,14 @@ class RustLoginsTests: XCTestCase {
let databasePath = URL(fileURLWithPath: rootDirectory, isDirectory: true).appendingPathComponent("testLoginsPerField.db").path
try? files.remove("testLoginsPerField.db")

<<<<<<< HEAD:firefox-ios/Tests/StorageTests/RustLoginsTests.swift
logins = RustLogins(sqlCipherDatabasePath: sqlCipherDatabasePath, databasePath: databasePath)
_ = logins.reopenIfClosed()

mockLogins = MockRustLogins(sqlCipherDatabasePath: sqlCipherDatabasePath, databasePath: databasePath)

self.keychain.removeObject(forKey: self.canaryPhraseKey, withAccessibility: .afterFirstUnlock)
self.keychain.removeObject(forKey: self.loginKeychainKey, withAccessibility: .afterFirstUnlock)
} else {
XCTFail("Could not retrieve root directory")
}
}

override func tearDown() {
super.tearDown()
self.keychain.removeObject(forKey: self.canaryPhraseKey, withAccessibility: .afterFirstUnlock)
self.keychain.removeObject(forKey: self.loginKeychainKey, withAccessibility: .afterFirstUnlock)
}

func setUpMockListLoginsFailure() {
files = MockFiles()

if let rootDirectory = try? files.getAndEnsureDirectory() {
let sqlCipherDatabasePath = URL(fileURLWithPath: rootDirectory, isDirectory: true).appendingPathComponent("testlogins.db").path
try? files.remove("testlogins.db")

let databasePath = URL(fileURLWithPath: rootDirectory, isDirectory: true).appendingPathComponent("testLoginsPerField.db").path
try? files.remove("testLoginsPerField.db")

mockListLoginsFailure = MockListLoginsFailure(sqlCipherDatabasePath: sqlCipherDatabasePath,
databasePath: databasePath)
_ = mockListLoginsFailure.reopenIfClosed()
} else {
XCTFail("Could not retrieve root directory")
}
}

func setUpMockListLoginsEmpty() {
files = MockFiles()

if let rootDirectory = try? files.getAndEnsureDirectory() {
let sqlCipherDatabasePath = URL(fileURLWithPath: rootDirectory, isDirectory: true).appendingPathComponent("testlogins.db").path
try? files.remove("testlogins.db")

let databasePath = URL(fileURLWithPath: rootDirectory, isDirectory: true).appendingPathComponent("testLoginsPerField.db").path
try? files.remove("testLoginsPerField.db")

mockListLoginsEmpty = MockListLoginsEmpty(sqlCipherDatabasePath: sqlCipherDatabasePath,
databasePath: databasePath)
_ = mockListLoginsEmpty.reopenIfClosed()
=======
if let key = try? createKey() {
encryptionKey = key
} else {
XCTFail("Encryption key wasn't created")
}

logins = RustLogins(databasePath: databasePath)
logins = RustLogins(sqlCipherDatabasePath: sqlCipherDatabasePath, databasePath: databasePath)
_ = logins.reopenIfClosed()
>>>>>>> bc7f27a9f (Revert logins key logic updates (#17954)):firefox-ios/firefox-ios-tests/Tests/StorageTests/RustLoginsTests.swift
} else {
XCTFail("Could not retrieve root directory")
}
Expand Down
Loading