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

Prompt for Primary Password for FF Key3.db logins #2066

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ final class FirefoxEncryptionKeyReader: FirefoxEncryptionKeyReading {
primaryPassword: primaryPassword)

// Part 2: Take the decrypted ASN1 data, parse it, and extract the key.
operationType = .key3readerStage2
let decryptedASNData = try ASN1Parser.parse(data: decryptedData)
let extractedASNData = try extractKey3DecryptedASNData(from: decryptedASNData)
do {
operationType = .key3readerStage2
let decryptedASNData = try ASN1Parser.parse(data: decryptedData)
let extractedASNData = try extractKey3DecryptedASNData(from: decryptedASNData)

operationType = .key3readerStage3
let keyContainerASNData = try ASN1Parser.parse(data: extractedASNData)
let key = try extractKey3Key(from: keyContainerASNData)

operationType = .key3readerStage3
let keyContainerASNData = try ASN1Parser.parse(data: extractedASNData)
let key = try extractKey3Key(from: keyContainerASNData)
return key

return key
} catch let error as ASN1Parser.ParserError {
throw FirefoxLoginReader.ImportError(type: .requiresPrimaryPassword, underlyingError: error)
}
}

func getEncryptionKey(key4DatabaseURL: URL, primaryPassword: String) -> DataImportResult<Data> {
Expand Down
3 changes: 3 additions & 0 deletions DuckDuckGo/DataImport/Model/DataImportViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ struct DataImportViewModel {

// firefox passwords db is master-password protected: request password
case let error as FirefoxLoginReader.ImportError where error.type == .requiresPrimaryPassword:
if error.underlyingError != nil {
Pixel.fire(.dataImportFailed(source: importSource, sourceVersion: importSource.installedAppsMajorVersionDescription(selectedProfile: selectedProfile), error: error))
}

log("primary password required")
// stay on the same screen but request password synchronously
Expand Down
31 changes: 26 additions & 5 deletions DuckDuckGo/DataImport/View/DataImportProfilePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,29 @@ struct DataImportProfilePicker: View {

private let profiles: [DataImport.BrowserProfile]
@Binding private var selectedProfile: DataImport.BrowserProfile?
private let shouldDisplayFolderName: Bool

private enum ProfileSubtitle {
case none
case parentFolderName
case profileFolderName
}
private let profileSubtitle: ProfileSubtitle

init(profileList: DataImport.BrowserProfileList?, selectedProfile: Binding<DataImport.BrowserProfile?>) {
self.profiles = profileList?.validImportableProfiles ?? []
self._selectedProfile = selectedProfile
shouldDisplayFolderName = Set(self.profiles.map {
// display parent folder name as a subtitle if there are multiple
// browser build profile folders (Chrome, Chrome Dev, Canary...)
if Set(profiles.map {
$0.profileURL.deletingLastPathComponent()
}).count > 1
}).count > 1 {
profileSubtitle = .parentFolderName
} else if Set(profiles.map(\.profileName)).count != profiles.count {
// when there‘re repeated profile names display profile folder names
profileSubtitle = .profileFolderName
} else {
profileSubtitle = .none
}
}

var body: some View {
Expand All @@ -44,13 +59,19 @@ struct DataImportProfilePicker: View {
}) {
ForEach(profiles.indices, id: \.self) { idx in
// display profiles folder name if multiple profiles folders are present (Chrome, Chrome Canary…)
if shouldDisplayFolderName {
switch profileSubtitle {
case .parentFolderName:
Text(profiles[idx].profileName + " ")
+ Text(profiles[idx].profileURL
.deletingLastPathComponent().lastPathComponent)
.font(.system(size: 10))
.fontWeight(.light)
} else {
case .profileFolderName:
Text(profiles[idx].profileName + " ")
+ Text(profiles[idx].profileURL.lastPathComponent)
.font(.system(size: 10))
.fontWeight(.light)
case .none:
Text(profiles[idx].profileName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/DataImport/FirefoxKeyReaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FirefoxKeyReaderTests: XCTestCase {

switch result {
case .failure(let error as FirefoxLoginReader.ImportError):
XCTAssertEqual(error.type, .key3readerStage2)
XCTAssertEqual(error.type, .requiresPrimaryPassword)
XCTAssertTrue(error.underlyingError is ASN1Parser.ParserError)
default:
XCTFail("Received unexpected \(result)")
Expand Down
Loading