diff --git a/Storage/Rust/RustLogins.swift b/Storage/Rust/RustLogins.swift index f83be263c9f7..695f52b447ca 100644 --- a/Storage/Rust/RustLogins.swift +++ b/Storage/Rust/RustLogins.swift @@ -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 { @@ -816,31 +815,7 @@ public class RustLogins { keychain.removeObject(forKey: rustKeys.loginsSaltKeychainKey, withAccessibility: .afterFirstUnlock) } - private func resetLoginsAndKey(rustKeys: RustLoginEncryptionKeys, - completion: @escaping (Result) -> 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) -> 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) @@ -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 diff --git a/firefox-ios/Tests/StorageTests/RustLoginsTests.swift b/firefox-ios/Tests/StorageTests/RustLoginsTests.swift index 84a19e8a84ff..265e7d36687d 100644 --- a/firefox-ios/Tests/StorageTests/RustLoginsTests.swift +++ b/firefox-ios/Tests/StorageTests/RustLoginsTests.swift @@ -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") }