Skip to content

Commit

Permalink
Import passwords from Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrett Robinson committed Mar 30, 2018
1 parent ebec0c5 commit 2f9b051
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/importer/chrome_importer_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ bool ChromeImporterCanImport(const base::FilePath& profile,
profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("Bookmarks")));
base::FilePath history =
profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("History")));
base::FilePath passwords =
profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("Login Data")));

if (base::PathExists(bookmarks))
*services_supported |= importer::FAVORITES;
if (base::PathExists(history))
*services_supported |= importer::HISTORY;
if (base::PathExists(passwords))
*services_supported |= importer::PASSWORDS;

return *services_supported != importer::NONE;
}
96 changes: 96 additions & 0 deletions utility/importer/chrome_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ void ChromeImporter::StartImport(const importer::SourceProfile& source_profile,
bridge_->NotifyItemEnded(importer::FAVORITES);
}

if ((items & importer::PASSWORDS) && !cancelled()) {
bridge_->NotifyItemStarted(importer::PASSWORDS);
ImportPasswords();
bridge_->NotifyItemEnded(importer::PASSWORDS);
}

bridge_->NotifyEnded();
}

Expand Down Expand Up @@ -265,3 +271,93 @@ void ChromeImporter::RecursiveReadBookmarksFolder(
double ChromeImporter::chromeTimeToDouble(int64_t time) {
return ((time * 10 - 0x19DB1DED53E8000) / 10000) / 1000;
}

void ChromeImporter::ImportPasswords() {
#if !defined(USE_X11)
base::FilePath passwords_path =
source_path_.Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Login Data")));

password_manager::LoginDatabase database(passwords_path);
if (!database.Init()) {
LOG(ERROR) << "LoginDatabase Init() failed";
return;
}

std::vector<std::unique_ptr<autofill::PasswordForm>> forms;
bool success = database.GetAutofillableLogins(&forms);
if (success) {
for (size_t i = 0; i < forms.size(); ++i) {
bridge_->SetPasswordForm(*forms[i].get());
}
}
std::vector<std::unique_ptr<autofill::PasswordForm>> blacklist;
success = database.GetBlacklistLogins(&blacklist);
if (success) {
for (size_t i = 0; i < blacklist.size(); ++i) {
bridge_->SetPasswordForm(*blacklist[i].get());
}
}
#else
base::FilePath prefs_path =
source_path_.Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Preferences")));
const base::Value *value;
scoped_refptr<JsonPrefStore> prefs = new JsonPrefStore(prefs_path);
int local_profile_id;
if (prefs->ReadPrefs() != PersistentPrefStore::PREF_READ_ERROR_NONE) {
return;
}
if (!prefs->GetValue(password_manager::prefs::kLocalProfileId, &value)) {
return;
}
if (!value->GetAsInteger(&local_profile_id)) {
return;
}

std::unique_ptr<PasswordStoreX::NativeBackend> backend;
base::nix::DesktopEnvironment desktop_env = GetDesktopEnvironment();

// WIP proper kEnableEncryptionSelection
os_crypt::SelectedLinuxBackend selected_backend =
os_crypt::SelectBackend(std::string(), true, desktop_env);
if (!backend &&
(selected_backend == os_crypt::SelectedLinuxBackend::KWALLET ||
selected_backend == os_crypt::SelectedLinuxBackend::KWALLET5)) {
base::nix::DesktopEnvironment used_desktop_env =
selected_backend == os_crypt::SelectedLinuxBackend::KWALLET
? base::nix::DESKTOP_ENVIRONMENT_KDE4
: base::nix::DESKTOP_ENVIRONMENT_KDE5;
backend.reset(new NativeBackendKWallet(local_profile_id,
used_desktop_env));
} else if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY ||
selected_backend ==
os_crypt::SelectedLinuxBackend::GNOME_KEYRING ||
selected_backend ==
os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) {
#if defined(USE_LIBSECRET)
if (!backend &&
(selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY ||
selected_backend == os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET)) {
backend.reset(new NativeBackendLibsecret(local_profile_id));
}
#endif
}
if (backend && backend->Init()) {
std::vector<std::unique_ptr<autofill::PasswordForm>> forms;
bool success = backend->GetAutofillableLogins(&forms);
if (success) {
for (size_t i = 0; i < forms.size(); ++i) {
bridge_->SetPasswordForm(*forms[i].get());
}
}
std::vector<std::unique_ptr<autofill::PasswordForm>> blacklist;
success = backend->GetBlacklistLogins(&blacklist);
if (success) {
for (size_t i = 0; i < blacklist.size(); ++i) {
bridge_->SetPasswordForm(*blacklist[i].get());
}
}
}
#endif
}
1 change: 1 addition & 0 deletions utility/importer/chrome_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ChromeImporter : public Importer {

void ImportBookmarks();
void ImportHistory();
void ImportPasswords();

// Multiple URLs can share the same favicon; this is a map
// of URLs -> IconIDs that we load as a temporary step before
Expand Down

0 comments on commit 2f9b051

Please sign in to comment.