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

Refactor FXIOS-10788 [Logins] Apply necessary adjustments for A-S EncryptorDecryptor update #24108

Merged
merged 14 commits into from
Jan 23, 2025
6 changes: 5 additions & 1 deletion firefox-ios/Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,7 @@
B2FEA68F2B460D9E0058E616 /* AddressAutofillSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2FEA68E2B460D9E0058E616 /* AddressAutofillSettingsViewModel.swift */; };
B2FEA6912B4661BE0058E616 /* AddressAutofillToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2FEA6902B4661BE0058E616 /* AddressAutofillToggle.swift */; };
B640467E29B9B58200C5C7B6 /* TabLocationViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B640467D29B9B58200C5C7B6 /* TabLocationViewTests.swift */; };
BA03AE592D41715900C7FA7B /* MockMZKeychainWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03AE582D41714B00C7FA7B /* MockMZKeychainWrapper.swift */; };
BA1C68BA2B7E9EA0000D9397 /* WKFrameInfoExtensionsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1C68B92B7E9EA0000D9397 /* WKFrameInfoExtensionsTest.swift */; };
BA1C68BC2B7ED153000D9397 /* MockWebKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1C68BB2B7ED153000D9397 /* MockWebKit.swift */; };
BA7A14842C2CCEB3008DF1D9 /* EditAddressWebViewManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA7A14832C2CCEB3008DF1D9 /* EditAddressWebViewManager.swift */; };
Expand Down Expand Up @@ -8443,6 +8444,7 @@
B9CF4F8ABA948EB090A67608 /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/ClearPrivateDataConfirm.strings; sourceTree = "<group>"; };
B9D74DA988462CC14EF29D8B /* fil */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fil; path = fil.lproj/Menu.strings; sourceTree = "<group>"; };
B9F246E38F80F257C59CEC4A /* ast */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ast; path = ast.lproj/HistoryPanel.strings; sourceTree = "<group>"; };
BA03AE582D41714B00C7FA7B /* MockMZKeychainWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockMZKeychainWrapper.swift; sourceTree = "<group>"; };
BA05405089CFDC6097258640 /* en-CA */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-CA"; path = "en-CA.lproj/3DTouchActions.strings"; sourceTree = "<group>"; };
BA1C68B92B7E9EA0000D9397 /* WKFrameInfoExtensionsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKFrameInfoExtensionsTest.swift; sourceTree = "<group>"; };
BA1C68BB2B7ED153000D9397 /* MockWebKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockWebKit.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -10643,6 +10645,7 @@
2FCAE21B1ABB51F800877008 /* Storage */ = {
isa = PBXGroup;
children = (
BA03AE582D41714B00C7FA7B /* MockMZKeychainWrapper.swift */,
D37DE2821CA2047500A5EC69 /* CertStore.swift */,
28C4AB711AD42D4300D9ACE3 /* Clients.swift */,
2FCAE2411ABB531100877008 /* Cursor.swift */,
Expand Down Expand Up @@ -16023,6 +16026,7 @@
B2999FED2B044A5900F0FEC1 /* UnencryptedCreditCardFields.swift in Sources */,
15DE98FD27FCED4F00F1ECDB /* RustRemoteTabs.swift in Sources */,
285D3B901B4386520035FD22 /* SQLiteQueue.swift in Sources */,
BA03AE592D41715900C7FA7B /* MockMZKeychainWrapper.swift in Sources */,
394CF6CF1BAA493C00906917 /* DefaultSuggestedSites.swift in Sources */,
B2999FEF2B044B4E00F0FEC1 /* RustAutofillEncryptionKeys.swift in Sources */,
2FCAE2781ABB531100877008 /* Visit.swift in Sources */,
Expand Down Expand Up @@ -26512,7 +26516,7 @@
repositoryURL = "https://github.com/mozilla/rust-components-swift.git";
requirement = {
kind = exactVersion;
version = 136.0.20250118050318;
version = 136.0.20250121100536;
};
};
435C85EE2788F4D00072B526 /* XCRemoteSwiftPackageReference "glean-swift" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mozilla/rust-components-swift.git",
"state" : {
"revision" : "d2ca7ce2969635c105d098ba3807ce85f38990f5",
"version" : "136.0.20250118050318"
"revision" : "b8abdbca96c8ef90566bb3058a8ebb1ac784842d",
"version" : "136.0.20250121100536"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ class CredentialAutofillCoordinator: BaseCoordinator {
logger: logger,
onLoginCellTap: { [weak self] login in
guard let self else { return }
let rustLoginsEncryption = RustLoginEncryptionKeys()

guard let currentTab = self.tabManager.selectedTab,
let decryptLogin = rustLoginsEncryption.decryptSecureFields(login: login)
else {
guard let currentTab = self.tabManager.selectedTab else {
router.dismiss(animated: true)
parentCoordinator?.didFinish(from: self)
return
Expand All @@ -148,9 +144,9 @@ class CredentialAutofillCoordinator: BaseCoordinator {
loginData: LoginInjectionData(
requestId: currentRequestId,
logins: [LoginItem(
username: decryptLogin.secFields.username,
password: decryptLogin.secFields.password,
hostname: decryptLogin.fields.origin
username: login.username,
password: login.password,
hostname: login.origin
)]
)
)
Expand Down
10 changes: 5 additions & 5 deletions firefox-ios/Client/Frontend/Autofill/LoginCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import SwiftUI
import Common

import struct MozillaAppServices.EncryptedLogin
import struct MozillaAppServices.Login

/// A view representing a cell displaying login information.
struct LoginCellView: View {
Expand All @@ -19,7 +19,7 @@ struct LoginCellView: View {
@Environment(\.themeManager)
var themeManager

private(set) var login: EncryptedLogin
private(set) var login: Login
private(set) var onTap: () -> Void

// MARK: - Body
Expand All @@ -37,8 +37,8 @@ struct LoginCellView: View {
.alignmentGuide(.midIconAndLabel) { $0[VerticalAlignment.center] }
.accessibilityHidden(true)
VStack(alignment: .leading) {
Text(login.decryptedUsername.isEmpty ? String.PasswordAutofill.LoginListCellNoUsername
: login.decryptedUsername)
Text(login.username.isEmpty ? String.PasswordAutofill.LoginListCellNoUsername
: login.username)
.font(.body)
.foregroundColor(textColor)
.alignmentGuide(.midIconAndLabel) { $0[VerticalAlignment.center] }
Expand Down Expand Up @@ -95,7 +95,7 @@ struct LoginButtonStyle: ButtonStyle {
struct LoginCellView_Previews: PreviewProvider {
static var previews: some View {
// Create a sample login item
let loginRecord = EncryptedLogin(
let loginRecord = Login(
credentials: URLCredential(
user: "test",
password: "doubletest",
Expand Down
10 changes: 5 additions & 5 deletions firefox-ios/Client/Frontend/Autofill/LoginListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import Common
import Foundation

import struct MozillaAppServices.EncryptedLogin
import struct MozillaAppServices.Login

@MainActor
class LoginListViewModel: ObservableObject {
@Published var logins: [EncryptedLogin] = []
@Published var logins: [Login] = []

private let tabURL: URL
private let field: FocusFieldType
private let loginStorage: LoginStorage
private let logger: Logger
let onLoginCellTap: (EncryptedLogin) -> Void
let onLoginCellTap: (Login) -> Void
let manageLoginInfoAction: () -> Void

var shortDisplayString: String {
Expand All @@ -27,7 +27,7 @@ class LoginListViewModel: ObservableObject {
field: FocusFieldType,
loginStorage: LoginStorage,
logger: Logger,
onLoginCellTap: @escaping (EncryptedLogin) -> Void,
onLoginCellTap: @escaping (Login) -> Void,
manageLoginInfoAction: @escaping () -> Void
) {
self.tabURL = tabURL
Expand All @@ -42,7 +42,7 @@ class LoginListViewModel: ObservableObject {
do {
let logins = try await loginStorage.listLogins()
self.logins = logins.filter { login in
if field == FocusFieldType.username && login.decryptedUsername.isEmpty { return false }
if field == FocusFieldType.username && login.username.isEmpty { return false }
guard let recordHostnameURL = URL(string: login.hostname) else { return false }
return recordHostnameURL.baseDomain == tabURL.baseDomain
}
Expand Down
14 changes: 7 additions & 7 deletions firefox-ios/Client/Frontend/Autofill/LoginStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import Storage

import struct MozillaAppServices.EncryptedLogin
import struct MozillaAppServices.Login

protocol LoginStorage {
func listLogins() async throws -> [EncryptedLogin]
func listLogins() async throws -> [Login]
}

extension RustLogins: LoginStorage {
func listLogins() async throws -> [EncryptedLogin] {
func listLogins() async throws -> [Login] {
return try await withCheckedThrowingContinuation { continuation in
self.listLogins().upon { result in
switch result {
Expand All @@ -27,7 +27,7 @@ extension RustLogins: LoginStorage {

class MockLoginStorage: LoginStorage {
var shouldThrowError = false
func listLogins() async throws -> [EncryptedLogin] {
func listLogins() async throws -> [Login] {
if shouldThrowError {
struct StorageError: Error {}
throw StorageError()
Expand All @@ -36,16 +36,16 @@ class MockLoginStorage: LoginStorage {
try await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC) // 0.5 seconds

// Return mock login data
let mockLogins: [EncryptedLogin] = [
EncryptedLogin(
let mockLogins: [Login] = [
Login(
credentials: URLCredential(
user: "test",
password: "doubletest",
persistence: .permanent
),
protectionSpace: URLProtectionSpace.fromOrigin("https://test.com")
),
EncryptedLogin(
Login(
credentials: URLCredential(
user: "test",
password: "doubletest",
Expand Down
8 changes: 4 additions & 4 deletions firefox-ios/Client/Frontend/Browser/Authenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Storage
import Common

import struct MozillaAppServices.LoginEntry
import struct MozillaAppServices.EncryptedLogin
import struct MozillaAppServices.Login

class Authenticator {
fileprivate static let MaxAuthenticationAttempts = 3
Expand Down Expand Up @@ -141,14 +141,14 @@ class Authenticator {
}
}

private static func filterHttpAuthLogins(logins: [EncryptedLogin]) -> [EncryptedLogin] {
private static func filterHttpAuthLogins(logins: [Login]) -> [Login] {
return logins.compactMap {
// HTTP Auth must have nil formSubmitUrl and a non-nil httpRealm.
return $0.formSubmitUrl == nil && $0.httpRealm != nil ? $0 : nil
}
}

private static func handleDuplicatedEntries(logins: [EncryptedLogin],
private static func handleDuplicatedEntries(logins: [Login],
challenge: URLAuthenticationChallenge,
loginsProvider: RustLogins) -> URLCredential? {
let credentials = (logins.first(where: { login in
Expand All @@ -167,7 +167,7 @@ class Authenticator {
return credentials
}

private static func handleUnmatchedSchemes(logins: [EncryptedLogin],
private static func handleUnmatchedSchemes(logins: [Login],
challenge: URLAuthenticationChallenge,
loginsProvider: RustLogins,
completionHandler: @escaping (Result<URLCredential?, Error>) -> Void) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ToolbarKit

import class MozillaAppServices.BookmarkFolderData
import class MozillaAppServices.BookmarkItemData
import struct MozillaAppServices.EncryptedLogin
import struct MozillaAppServices.Login
import enum MozillaAppServices.BookmarkRoots
import enum MozillaAppServices.VisitType

Expand Down Expand Up @@ -3577,11 +3577,11 @@ extension BrowserViewController: LegacyTabDelegate {
tab.addContentScript(FocusHelper(tab: tab), name: FocusHelper.name())
}

private func filterLoginsForCurrentTab(logins: [EncryptedLogin],
private func filterLoginsForCurrentTab(logins: [Login],
tabURL: URL,
field: FocusFieldType) -> [EncryptedLogin] {
field: FocusFieldType) -> [Login] {
return logins.filter { login in
if field == FocusFieldType.username && login.decryptedUsername.isEmpty { return false }
if field == FocusFieldType.username && login.username.isEmpty { return false }
guard let recordHostnameURL = URL(string: login.hostname) else { return false }
return recordHostnameURL.baseDomain == tabURL.baseDomain
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,15 @@ class AddCredentialViewController: UIViewController, Themeable {
}

dismiss(animated: true) {
let entry = LoginEntryFlattened(
id: "",
hostname: hostname,
password: password,
username: username,
self.didSaveAction(LoginEntry(
origin: hostname,
httpRealm: nil,
formSubmitUrl: hostname,
formActionOrigin: hostname,
usernameField: "",
passwordField: ""
passwordField: "",
password: password,
username: username)
)
self.didSaveAction(LoginEntry(fromLoginEntryFlattened: entry))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class LoginDataSource: NSObject, UITableViewDataSource {
} else if let cell = tableView.dequeueReusableCell(withIdentifier: PasswordManagerTableViewCell.cellIdentifier,
for: indexPath) as? PasswordManagerTableViewCell {
guard let login = viewModel.loginAtIndexPath(indexPath) else { return cell }
let username = login.decryptedUsername
let username = login.username
cell.hostnameLabel.text = login.hostname
cell.usernameLabel.text = username.isEmpty ? "(no username)" : username
if let breaches = viewModel.userBreaches, breaches.contains(login) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Storage
protocol LoginProvider: AnyObject {
func searchLoginsWithQuery(
_ query: String?,
completionHandler: @escaping (Result<[EncryptedLogin], Error>) -> Void)
func addLogin(login: LoginEntry, completionHandler: @escaping (Result<EncryptedLogin?, Error>) -> Void)
completionHandler: @escaping (Result<[Login], Error>) -> Void)
func addLogin(login: LoginEntry, completionHandler: @escaping (Result<Login?, Error>) -> Void)
}

extension RustLogins: LoginProvider {}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ class PasswordManagerSelectionHelper {
}

private func getKeyFromLoginRecord(_ loginRecord: LoginRecord) -> String {
"\(loginRecord.hostname)\(loginRecord.decryptedUsername)"
"\(loginRecord.hostname)\(loginRecord.username)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Foundation
import Storage
import Shared

import struct MozillaAppServices.EncryptedLogin
import struct MozillaAppServices.Login
import struct MozillaAppServices.LoginEntry

struct NewSearchInProgressError: MaybeErrorType {
Expand Down Expand Up @@ -78,7 +78,7 @@ final class PasswordManagerViewModel {

/// Searches SQLite database for logins that match query.
/// Wraps the SQLiteLogins method to allow us to cancel it from our end.
func queryLogins(_ query: String, completion: @escaping ([EncryptedLogin]) -> Void) {
func queryLogins(_ query: String, completion: @escaping ([Login]) -> Void) {
loginProvider.searchLoginsWithQuery(query) { result in
ensureMainThread {
switch result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ extension PasswordDetailViewController: UITableViewDataSource {
}
let cellModel = LoginDetailTableViewCellModel(
title: .LoginDetailUsername,
description: viewModel.login.decryptedUsername,
description: viewModel.login.username,
keyboardType: .emailAddress,
returnKeyType: .next,
a11yId: AccessibilityIdentifiers.Settings.Passwords.usernameField,
Expand All @@ -191,7 +191,7 @@ extension PasswordDetailViewController: UITableViewDataSource {
}
let cellModel = LoginDetailTableViewCellModel(
title: .LoginDetailPassword,
description: viewModel.login.decryptedPassword,
description: viewModel.login.password,
displayDescriptionAsPassword: true,
a11yId: AccessibilityIdentifiers.Settings.Passwords.passwordField,
isEditingFieldData: isEditingFieldData)
Expand Down Expand Up @@ -399,22 +399,19 @@ extension PasswordDetailViewController {
return
}

guard username != viewModel.login.decryptedUsername || password != viewModel.login.decryptedPassword else {
guard username != viewModel.login.username || password != viewModel.login.password else {
self.tableView.reloadData()
return
}

let updatedLogin = LoginEntry(
fromLoginEntryFlattened: LoginEntryFlattened(
id: viewModel.login.id,
hostname: viewModel.login.hostname,
password: password,
username: username,
origin: viewModel.login.hostname,
httpRealm: viewModel.login.httpRealm,
formSubmitUrl: viewModel.login.formSubmitUrl,
formActionOrigin: viewModel.login.formSubmitUrl,
usernameField: viewModel.login.usernameField,
passwordField: viewModel.login.passwordField
)
passwordField: viewModel.login.passwordField,
password: password,
username: username
)

if updatedLogin.isValid.isSuccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class LoginsHelper: TabContentScript, FeatureFlaggable {
switch res {
case .success(let successValue):
for saved in successValue {
if saved.decryptedPassword == login.password {
if saved.password == login.password {
self.profile.logins.use(login: saved, completionHandler: { _ in })
return
}
Expand Down
Loading