diff options
| author | saturneric <[email protected]> | 2026-05-09 16:04:02 +0200 |
|---|---|---|
| committer | saturneric <[email protected]> | 2026-05-09 16:04:02 +0200 |
| commit | 7fd7445abbc250679d20040aecc2c54fe290c42a (patch) | |
| tree | 6109d6678f82ff4f9f4ae883b6c547800c083515 /src | |
| parent | fix(ver-check): avoid menu action use-after-free (diff) | |
| download | modules-7fd7445abbc250679d20040aecc2c54fe290c42a.tar.gz modules-7fd7445abbc250679d20040aecc2c54fe290c42a.zip | |
feat(key-server-sync): add fingerprint search flow
* Add an event-driven entry point to open the key search dialog with a
preset fingerprint, improving UX when starting from key details
* Normalize preset fingerprints (strip `0x` prefix and whitespace) and
auto-select the fingerprint search type
* Add SSL diagnostics logging to help troubleshoot HTTPS keyserver
connectivity
* Force fingerprint/keyid lookups to use Ubuntu’s keyserver for more
consistent results across server URLs
* Bump module version to 1.2.0
Diffstat (limited to 'src')
| -rw-r--r-- | src/m_key_server_sync/KeyServerSyncModule.cpp | 38 | ||||
| -rw-r--r-- | src/m_key_server_sync/PKSInterface.cpp | 13 | ||||
| -rw-r--r-- | src/m_key_server_sync/SearchKeyDialog.cpp | 36 | ||||
| -rw-r--r-- | src/m_key_server_sync/SearchKeyDialog.h | 43 |
4 files changed, 92 insertions, 38 deletions
diff --git a/src/m_key_server_sync/KeyServerSyncModule.cpp b/src/m_key_server_sync/KeyServerSyncModule.cpp index c5b7918..1a12592 100644 --- a/src/m_key_server_sync/KeyServerSyncModule.cpp +++ b/src/m_key_server_sync/KeyServerSyncModule.cpp @@ -38,7 +38,7 @@ #include "VKSInterface.h" GF_MODULE_API_DEFINE_V2("com.bktus.gpgfrontend.module.key_server_sync", - "KeyServerSync", "1.1.0", + "KeyServerSync", "1.2.0", "Sync Information From Trusted Key Server.", "Saturneric") @@ -52,6 +52,7 @@ auto GFActiveModule() -> int { LISTEN("REQUEST_GET_PUBLIC_KEY_BY_FINGERPRINT"); LISTEN("REQUEST_GET_PUBLIC_KEY_BY_KEY_ID"); LISTEN("REQUEST_UPLOAD_PUBLIC_KEY"); + LISTEN("REQUEST_SEARCH_PUBLIC_KEY_BY_FINGERPRINT"); LISTEN("MAINWINDOW_MENU_MOUNTED"); LISTEN("KEY_PAIR_OPERA_MENU_CREATED"); return 0; @@ -395,6 +396,41 @@ REGISTER_EVENT_HANDLER( return 0; }); +REGISTER_EVENT_HANDLER( + REQUEST_SEARCH_PUBLIC_KEY_BY_FINGERPRINT, [](const MEvent& event) -> int { + auto fingerprint = event["fingerprint"].trimmed(); + if (fingerprint.isEmpty()) { + CB_ERR(event, -1, "fingerprint is empty"); + } + + QWidget* parent = nullptr; + + if (event.contains("parent")) { + parent = GFUIGetGUIObjectAs<QWidget>(event["parent"]); + } + + if (parent == nullptr) { + parent = QApplication::activeWindow(); + } + + FLOG_DEBUG("open key server search dialog with fingerprint: %1", + fingerprint); + + QMetaObject::invokeMethod( + QApplication::instance(), + [parent, fingerprint]() { + auto* dialog = new SearchKeyDialog(parent); + dialog->SetPresetFingerprint(fingerprint); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); + dialog->raise(); + dialog->activateWindow(); + }, + Qt::QueuedConnection); + + CB_SUCC(event); + }); + auto GFDeactivateModule() -> int { return 0; } auto GFUnregisterModule() -> int { diff --git a/src/m_key_server_sync/PKSInterface.cpp b/src/m_key_server_sync/PKSInterface.cpp index 0d49339..be0fd87 100644 --- a/src/m_key_server_sync/PKSInterface.cpp +++ b/src/m_key_server_sync/PKSInterface.cpp @@ -165,9 +165,18 @@ auto PKSInterface::Search(const QString& url, const QString& type, url + "/pks/lookup?search=" + QUrl::toPercentEncoding(value) + "&op=index&options=mr"; + FLOG_DEBUG("SSL supported: %1", QSslSocket::supportsSsl()); + FLOG_DEBUG("SSL build version: %1", + QSslSocket::sslLibraryBuildVersionString()); + FLOG_DEBUG("SSL runtime version: %1", QSslSocket::sslLibraryVersionString()); + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + FLOG_DEBUG("SSL active backend: %1", QSslSocket::activeBackend()); +#endif + if (type == "fpr" || type == "keyid") { - url_from_remote = - url + "/pks/lookup?search=0x" + value + "&op=index&options=mr"; + url_from_remote = QString("http://keyserver.ubuntu.com") + + "/pks/lookup?search=0x" + value + "&op=index&options=mr"; } auto request = QNetworkRequest(url_from_remote); diff --git a/src/m_key_server_sync/SearchKeyDialog.cpp b/src/m_key_server_sync/SearchKeyDialog.cpp index 09da06b..ac0af95 100644 --- a/src/m_key_server_sync/SearchKeyDialog.cpp +++ b/src/m_key_server_sync/SearchKeyDialog.cpp @@ -39,7 +39,17 @@ #include "ui_SearchKeyDialog.h" SearchKeyDialog::SearchKeyDialog(QWidget* parent) - : ui_(SecureCreateSharedObject<Ui_SearchKeyDialog>()) { + : QDialog(parent), ui_(SecureCreateSharedObject<Ui_SearchKeyDialog>()) { + init_ui(); +} + +SearchKeyDialog::SearchKeyDialog(const QString& fingerprint, QWidget* parent) + : QDialog(parent), ui_(SecureCreateSharedObject<Ui_SearchKeyDialog>()) { + init_ui(); + SetPresetFingerprint(fingerprint); +} + +void SearchKeyDialog::init_ui() { ui_->setupUi(this); connect(ui_->searchButton, &QPushButton::clicked, this, @@ -69,6 +79,30 @@ SearchKeyDialog::SearchKeyDialog(QWidget* parent) ui_->keyServerComboBox->setCurrentIndex(0); } +void SearchKeyDialog::SetPresetFingerprint(const QString& fingerprint) { + auto fpr = fingerprint.trimmed(); + + if (fpr.startsWith("0x", Qt::CaseInsensitive)) { + fpr = fpr.mid(2); + } + + fpr.remove(QRegularExpression(R"(\s+)")); + + set_search_type("fpr"); + ui_->searchEdit->setText(fpr); + ui_->searchEdit->selectAll(); + ui_->searchEdit->setFocus(); + + slot_set_error_message(""); +} + +void SearchKeyDialog::set_search_type(const QString& type) { + const auto index = ui_->searchTypeComboBox->findData(type); + if (index >= 0) { + ui_->searchTypeComboBox->setCurrentIndex(index); + } +} + void SearchKeyDialog::slot_search() { if (ui_->searchEdit->text().isEmpty()) { slot_set_error_message(tr("Search value is empty.")); diff --git a/src/m_key_server_sync/SearchKeyDialog.h b/src/m_key_server_sync/SearchKeyDialog.h index 00491e4..d493d5f 100644 --- a/src/m_key_server_sync/SearchKeyDialog.h +++ b/src/m_key_server_sync/SearchKeyDialog.h @@ -39,55 +39,30 @@ class SearchKeyDialog : public QDialog { public: explicit SearchKeyDialog(QWidget* parent = nullptr); - private slots: + explicit SearchKeyDialog(const QString& fingerprint, + QWidget* parent = nullptr); - /** - * @brief - * - */ - void slot_search(); + void SetPresetFingerprint(const QString& fingerprint); - /** - * @brief - * - * @param message - */ + private slots: + void slot_search(); void slot_set_error_message(const QString& message); - - /** - * @brief - * - * @param loading - */ void slot_set_loading(bool loading); - /** - * @brief - * - * @param error - * @param error_string - * @param keys - */ void slot_search_finished_pks(QNetworkReply::NetworkError error, const QString& error_string, const QList<KeyServerKeyInfo>& keys); - /** - * @brief - * - * @param error - * @param error_string - * @param key_data - */ void slot_lookup_finished_pks(QNetworkReply::NetworkError error, const QString& error_string, const QByteArray& key_data); - /** - * @brief - */ void slot_import(int row, int column); private: + void init_ui(); + void set_search_type(const QString& type); + + private: std::shared_ptr<Ui_SearchKeyDialog> ui_; }; |
