From ce51534c3aa341e311ca4a080b06c4017f819fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20V=C3=A4nttinen?= Date: Sun, 29 Jan 2023 17:32:24 +0200 Subject: [PATCH] Remove KeePassHTTP attribute conversion (#8007) Co-authored-by: varjolintu --- share/translations/keepassxc_en.ts | 63 ------- src/browser/BrowserService.cpp | 159 +----------------- src/browser/BrowserService.h | 9 +- .../DatabaseSettingsWidgetBrowser.cpp | 22 +-- .../DatabaseSettingsWidgetBrowser.h | 3 +- .../DatabaseSettingsWidgetBrowser.ui | 43 ++--- 6 files changed, 19 insertions(+), 280 deletions(-) diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index 919ef36e5..0587c115a 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -892,52 +892,6 @@ Do you want to delete the entry? - - Converting attributes to custom data… - - - - Abort - - - - KeePassXC: Converted KeePassHTTP attributes - - - - Successfully converted attributes from %1 entry(s). -Moved %2 keys to custom data. - - - - Successfully moved %n keys to custom data. - - - - - - - KeePassXC: No entry with KeePassHTTP attributes found! - - - - The active database does not contain an entry with KeePassHTTP attributes. - - - - Don't show this warning again - - - - KeePassXC: Legacy browser integration settings detected - - - - Your KeePassXC-Browser settings need to be moved into the database settings. -This is necessary to maintain your current browser connections. -Would you like to migrate your existing settings now? - - BrowserSettingsWidget @@ -1646,14 +1600,6 @@ If you do not have a key file, please leave the field empty. KeePassXC-Browser settings - - Convert KeePassHTTP data - - - - Convert legacy KeePassHTTP attributes to KeePassXC-Browser compatible custom data - - Refresh database root group ID @@ -1763,15 +1709,6 @@ Permissions to access entries will be revoked. The active database does not contain an entry with permissions. - - Move KeePassHTTP attributes to custom data - - - - Do you really want to convert all legacy browser integration data to the latest standard? -This is necessary to maintain compatibility with the browser plugin. - - Refresh database ID diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 2953cf582..f054f75b9 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -1,6 +1,7 @@ /* - * Copyright (C) 2013 Francois Ferrand * Copyright (C) 2022 KeePassXC Team + * Copyright (C) 2017 Sami Vänttinen + * Copyright (C) 2013 Francois Ferrand * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -781,79 +782,6 @@ BrowserService::searchEntries(const QString& siteUrl, const QString& formUrl, co return entries; } -void BrowserService::convertAttributesToCustomData(QSharedPointer db) -{ - if (!db) { - return; - } - - QList entries = db->rootGroup()->entriesRecursive(); - QProgressDialog progress(tr("Converting attributes to custom data…"), tr("Abort"), 0, entries.count()); - progress.setWindowModality(Qt::WindowModal); - - int counter = 0; - int keyCounter = 0; - for (auto* entry : entries) { - if (progress.wasCanceled()) { - return; - } - - if (moveSettingsToCustomData(entry, KEEPASSHTTP_NAME)) { - ++counter; - } - - if (moveSettingsToCustomData(entry, KEEPASSXCBROWSER_OLD_NAME)) { - ++counter; - } - - if (moveSettingsToCustomData(entry, KEEPASSXCBROWSER_NAME)) { - ++counter; - } - - if (entry->title() == KEEPASSHTTP_NAME || entry->title().contains(KEEPASSXCBROWSER_NAME, Qt::CaseInsensitive)) { - keyCounter += moveKeysToCustomData(entry, db); - db->recycleEntry(entry); - } - - progress.setValue(progress.value() + 1); - } - progress.reset(); - - if (counter > 0) { - MessageBox::information(nullptr, - tr("KeePassXC: Converted KeePassHTTP attributes"), - tr("Successfully converted attributes from %1 entry(s).\n" - "Moved %2 keys to custom data.", - "") - .arg(counter) - .arg(keyCounter), - MessageBox::Ok); - } else if (counter == 0 && keyCounter > 0) { - MessageBox::information(nullptr, - tr("KeePassXC: Converted KeePassHTTP attributes"), - tr("Successfully moved %n keys to custom data.", "", keyCounter), - MessageBox::Ok); - } else { - MessageBox::information(nullptr, - tr("KeePassXC: No entry with KeePassHTTP attributes found!"), - tr("The active database does not contain an entry with KeePassHTTP attributes."), - MessageBox::Ok); - } - - // Rename password groupName - Group* rootGroup = db->rootGroup(); - if (!rootGroup) { - return; - } - - for (auto* g : rootGroup->groupsRecursive(true)) { - if (g->name() == KEEPASSHTTP_GROUP_NAME) { - g->setName(KEEPASSXCBROWSER_GROUP_NAME); - break; - } - } -} - void BrowserService::requestGlobalAutoType(const QString& search) { emit osUtils->globalShortcutTriggered("autotype", search); @@ -1264,84 +1192,6 @@ QSharedPointer BrowserService::selectedDatabase() return getDatabase(); } -bool BrowserService::moveSettingsToCustomData(Entry* entry, const QString& name) -{ - if (entry->attributes()->contains(name)) { - QString attr = entry->attributes()->value(name); - entry->beginUpdate(); - if (!attr.isEmpty()) { - entry->customData()->set(KEEPASSXCBROWSER_NAME, attr); - } - entry->attributes()->remove(name); - entry->endUpdate(); - return true; - } - return false; -} - -int BrowserService::moveKeysToCustomData(Entry* entry, QSharedPointer db) -{ - int keyCounter = 0; - for (const auto& key : entry->attributes()->keys()) { - if (key.contains(CustomData::BrowserLegacyKeyPrefix)) { - QString publicKey = key; - publicKey.remove(CustomData::BrowserLegacyKeyPrefix); - - // Add key to database custom data - if (db && !db->metadata()->customData()->contains(CustomData::BrowserKeyPrefix + publicKey)) { - db->metadata()->customData()->set(CustomData::BrowserKeyPrefix + publicKey, - entry->attributes()->value(key)); - ++keyCounter; - } - } - } - - return keyCounter; -} - -bool BrowserService::checkLegacySettings(QSharedPointer db) -{ - if (!db || !browserSettings()->isEnabled() || browserSettings()->noMigrationPrompt()) { - return false; - } - - bool legacySettingsFound = false; - QList entries = db->rootGroup()->entriesRecursive(); - for (const auto& e : entries) { - if (e->isRecycled()) { - continue; - } - - if ((e->attributes()->contains(KEEPASSHTTP_NAME) || e->attributes()->contains(KEEPASSXCBROWSER_NAME)) - || (e->title() == KEEPASSHTTP_NAME || e->title().contains(KEEPASSXCBROWSER_NAME, Qt::CaseInsensitive))) { - legacySettingsFound = true; - break; - } - } - - if (!legacySettingsFound) { - return false; - } - - auto* checkbox = new QCheckBox(tr("Don't show this warning again")); - QObject::connect(checkbox, &QCheckBox::stateChanged, [&](int state) { - browserSettings()->setNoMigrationPrompt(static_cast(state) == Qt::CheckState::Checked); - }); - - auto dialogResult = - MessageBox::warning(nullptr, - tr("KeePassXC: Legacy browser integration settings detected"), - tr("Your KeePassXC-Browser settings need to be moved into the database settings.\n" - "This is necessary to maintain your current browser connections.\n" - "Would you like to migrate your existing settings now?"), - MessageBox::Yes | MessageBox::No, - MessageBox::NoButton, - MessageBox::Raise, - checkbox); - - return dialogResult == MessageBox::Yes; -} - QStringList BrowserService::getEntryURLs(const Entry* entry) { QStringList urlList; @@ -1440,11 +1290,6 @@ void BrowserService::databaseUnlocked(DatabaseWidget* dbWidget) QJsonObject msg; msg["action"] = QString("database-unlocked"); m_browserHost->broadcastClientMessage(msg); - - auto db = dbWidget->database(); - if (checkLegacySettings(db)) { - convertAttributesToCustomData(db); - } } } diff --git a/src/browser/BrowserService.h b/src/browser/BrowserService.h index b9e153248..c9fc83b75 100644 --- a/src/browser/BrowserService.h +++ b/src/browser/BrowserService.h @@ -1,6 +1,7 @@ /* - * Copyright (C) 2013 Francois Ferrand * Copyright (C) 2022 KeePassXC Team + * Copyright (C) 2017 Sami Vänttinen + * Copyright (C) 2013 Francois Ferrand * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -88,7 +89,6 @@ public: const StringPairList& keyList, const bool httpAuth = false); void requestGlobalAutoType(const QString& search); - static void convertAttributesToCustomData(QSharedPointer db); static const QString KEEPASSXCBROWSER_NAME; static const QString KEEPASSXCBROWSER_OLD_NAME; @@ -157,16 +157,11 @@ private: QSharedPointer selectedDatabase(); QString getDatabaseRootUuid(); QString getDatabaseRecycleBinUuid(); - bool checkLegacySettings(QSharedPointer db); QStringList getEntryURLs(const Entry* entry); void hideWindow() const; void raiseWindow(const bool force = false); - void updateWindowState(); - static bool moveSettingsToCustomData(Entry* entry, const QString& name); - static int moveKeysToCustomData(Entry* entry, QSharedPointer db); - QPointer m_browserHost; QHash> m_browserClients; diff --git a/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.cpp b/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.cpp index aa91fa451..cbfdb0dcb 100644 --- a/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.cpp +++ b/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2022 KeePassXC Team * Copyright (C) 2018 Sami Vänttinen * * This program is free software: you can redistribute it and/or modify @@ -48,8 +48,6 @@ DatabaseSettingsWidgetBrowser::DatabaseSettingsWidgetBrowser(QWidget* parent) // clang-format on connect(m_ui->removeCustomDataButton, SIGNAL(clicked()), SLOT(removeSelectedKey())); - connect(m_ui->convertToCustomData, SIGNAL(clicked()), this, SLOT(convertAttributesToCustomData())); - connect(m_ui->convertToCustomData, SIGNAL(clicked()), this, SLOT(updateSharedKeyList())); connect(m_ui->removeSharedEncryptionKeys, SIGNAL(clicked()), this, SLOT(removeSharedEncryptionKeys())); connect(m_ui->removeSharedEncryptionKeys, SIGNAL(clicked()), this, SLOT(updateSharedKeyList())); connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SLOT(removeStoredPermissions())); @@ -141,7 +139,6 @@ void DatabaseSettingsWidgetBrowser::updateModel() void DatabaseSettingsWidgetBrowser::settingsWarning() { if (!browserSettings()->isEnabled()) { - m_ui->convertToCustomData->setEnabled(false); m_ui->removeSharedEncryptionKeys->setEnabled(false); m_ui->removeStoredPermissions->setEnabled(false); m_ui->customDataTable->setEnabled(false); @@ -150,7 +147,6 @@ void DatabaseSettingsWidgetBrowser::settingsWarning() m_ui->warningWidget->setCloseButtonVisible(false); m_ui->warningWidget->setAutoHideTimeout(-1); } else { - m_ui->convertToCustomData->setEnabled(true); m_ui->removeSharedEncryptionKeys->setEnabled(true); m_ui->removeStoredPermissions->setEnabled(true); m_ui->customDataTable->setEnabled(true); @@ -242,22 +238,6 @@ void DatabaseSettingsWidgetBrowser::removeStoredPermissions() } } -void DatabaseSettingsWidgetBrowser::convertAttributesToCustomData() -{ - if (MessageBox::Yes - != MessageBox::question( - this, - tr("Move KeePassHTTP attributes to custom data"), - tr("Do you really want to convert all legacy browser integration data to the latest standard?\n" - "This is necessary to maintain compatibility with the browser plugin."), - MessageBox::Yes | MessageBox::Cancel, - MessageBox::Cancel)) { - return; - } - - BrowserService::convertAttributesToCustomData(m_db); -} - void DatabaseSettingsWidgetBrowser::refreshDatabaseID() { if (MessageBox::Yes diff --git a/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.h b/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.h index 9beb40466..149cd3a6a 100644 --- a/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.h +++ b/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 KeePassXC Team + * Copyright (C) 2022 KeePassXC Team * Copyright (C) 2018 Sami Vänttinen * * This program is free software: you can redistribute it and/or modify @@ -59,7 +59,6 @@ private slots: void updateSharedKeyList(); void removeSharedEncryptionKeys(); void removeStoredPermissions(); - void convertAttributesToCustomData(); void refreshDatabaseID(); void editIndex(const QModelIndex& index); void editFinished(QStandardItem* item); diff --git a/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.ui b/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.ui index 7d6dc00d2..a62d0d786 100644 --- a/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.ui +++ b/src/gui/dbsettings/DatabaseSettingsWidgetBrowser.ui @@ -51,35 +51,6 @@ KeePassXC-Browser settings - - - - - 0 - 0 - - - - Convert KeePassHTTP data - - - Convert legacy KeePassHTTP attributes to KeePassXC-Browser compatible custom data - - - - - - - - 0 - 0 - - - - Refresh database root group ID - - - @@ -106,6 +77,19 @@ + + + + + 0 + 0 + + + + Refresh database root group ID + + + @@ -186,7 +170,6 @@ removeSharedEncryptionKeys removeStoredPermissions - convertToCustomData refreshDatabaseID customDataTable removeCustomDataButton