diff options
author | saturneric <[email protected]> | 2025-04-17 17:44:04 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2025-04-17 17:44:04 +0000 |
commit | 6f504e4f915f928e42b8574ca3f93eea5038984b (patch) | |
tree | d5542b5cfad3d597038f7621e9975447efd7d9e6 /src | |
parent | chore: update and check translations (diff) | |
download | GpgFrontend-6f504e4f915f928e42b8574ca3f93eea5038984b.tar.gz GpgFrontend-6f504e4f915f928e42b8574ca3f93eea5038984b.zip |
feat: check scd version
Diffstat (limited to 'src')
-rw-r--r-- | src/core/function/gpg/GpgAssuanHelper.cpp | 34 | ||||
-rw-r--r-- | src/core/function/gpg/GpgAssuanHelper.h | 10 | ||||
-rw-r--r-- | src/core/function/gpg/GpgSmartCardManager.cpp | 12 | ||||
-rw-r--r-- | src/core/function/gpg/GpgSmartCardManager.h | 8 | ||||
-rw-r--r-- | src/ui/dialog/controller/SmartCardControllerDialog.cpp | 15 | ||||
-rw-r--r-- | src/ui/dialog/controller/SmartCardControllerDialog.h | 1 |
6 files changed, 79 insertions, 1 deletions
diff --git a/src/core/function/gpg/GpgAssuanHelper.cpp b/src/core/function/gpg/GpgAssuanHelper.cpp index 2fa836e5..0d1b9cdc 100644 --- a/src/core/function/gpg/GpgAssuanHelper.cpp +++ b/src/core/function/gpg/GpgAssuanHelper.cpp @@ -161,6 +161,40 @@ auto GpgAssuanHelper::SendStatusCommand(GpgComponentType type, return {ret, status_lines}; } +auto GpgAssuanHelper::SendDataCommand(GpgComponentType type, + const QString& command) + -> std::tuple<bool, QStringList> { + QStringList data_lines; + GpgAssuanHelper::DataCallback d_cb = + [&](const QSharedPointer<GpgAssuanHelper::AssuanCallbackContext>& ctx) + -> gpg_error_t { + LOG_D() << "data callback of command " << command << ": " << ctx->buffer; + data_lines.push_back(QString::fromUtf8(ctx->buffer)); + return 0; + }; + + GpgAssuanHelper::InqueryCallback i_cb = + [=](const QSharedPointer<GpgAssuanHelper::AssuanCallbackContext>& ctx) + -> gpg_error_t { + LOG_D() << "inquery callback of command: " << command << ": " + << ctx->inquery; + + return 0; + }; + + GpgAssuanHelper::StatusCallback s_cb = + [&](const QSharedPointer<GpgAssuanHelper::AssuanCallbackContext>& ctx) + -> gpg_error_t { + LOG_D() << "status callback of command: " << command << ": " + << ctx->status; + + return 0; + }; + + auto ret = SendCommand(type, command, d_cb, i_cb, s_cb); + return {ret, data_lines}; +} + auto GpgAssuanHelper::default_data_callback(void* opaque, const void* buffer, size_t length) -> gpgme_error_t { auto ctx = *static_cast<QSharedPointer<AssuanCallbackContext>*>(opaque); diff --git a/src/core/function/gpg/GpgAssuanHelper.h b/src/core/function/gpg/GpgAssuanHelper.h index a0c45d7a..294d33e0 100644 --- a/src/core/function/gpg/GpgAssuanHelper.h +++ b/src/core/function/gpg/GpgAssuanHelper.h @@ -108,6 +108,16 @@ class GPGFRONTEND_CORE_EXPORT GpgAssuanHelper auto SendStatusCommand(GpgComponentType type, const QString& command) -> std::tuple<bool, QStringList>; + /** + * @brief + * + * @param type + * @param command + * @return auto + */ + auto SendDataCommand(GpgComponentType type, + const QString& command) -> std::tuple<bool, QStringList>; + private: GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); diff --git a/src/core/function/gpg/GpgSmartCardManager.cpp b/src/core/function/gpg/GpgSmartCardManager.cpp index 422f0b20..cc7f8ab3 100644 --- a/src/core/function/gpg/GpgSmartCardManager.cpp +++ b/src/core/function/gpg/GpgSmartCardManager.cpp @@ -29,6 +29,7 @@ #include "GpgSmartCardManager.h" #include "core/function/gpg/GpgAutomatonHandler.h" +#include "core/utils/CommonUtils.h" namespace GpgFrontend { @@ -81,6 +82,17 @@ auto GpgSmartCardManager::Fetch(const QString& serial_number) -> bool { .DoCardInteract(serial_number, next_state_handler, action_handler); } +auto GpgSmartCardManager::IsSCDVersionSupported() -> bool { + auto [r, s] = assuan_.SendDataCommand(GpgComponentType::kGPG_AGENT, + "SCD GETINFO version"); + if (s.isEmpty()) { + LOG_D() << "invalid response of SCD GETINFO version: " << s; + return false; + } + + return GFCompareSoftwareVersion(s.front(), "2.3.0") > 0; +} + auto GpgSmartCardManager::GetSerialNumbers() -> QStringList { auto [r, s] = assuan_.SendStatusCommand(GpgComponentType::kGPG_AGENT, "SCD SERIALNO --all"); diff --git a/src/core/function/gpg/GpgSmartCardManager.h b/src/core/function/gpg/GpgSmartCardManager.h index 78c21bc0..2fe194f3 100644 --- a/src/core/function/gpg/GpgSmartCardManager.h +++ b/src/core/function/gpg/GpgSmartCardManager.h @@ -109,6 +109,14 @@ class GPGFRONTEND_CORE_EXPORT GpgSmartCardManager const QDateTime& expire, bool non_expire) -> std::tuple<bool, QString>; + /** + * @brief + * + * @return true + * @return false + */ + auto IsSCDVersionSupported() -> bool; + private: GpgContext& ctx_ = GpgContext::GetInstance(SingletonFunctionObject::GetChannel()); ///< diff --git a/src/ui/dialog/controller/SmartCardControllerDialog.cpp b/src/ui/dialog/controller/SmartCardControllerDialog.cpp index 450f1a35..254ed83c 100644 --- a/src/ui/dialog/controller/SmartCardControllerDialog.cpp +++ b/src/ui/dialog/controller/SmartCardControllerDialog.cpp @@ -42,7 +42,9 @@ namespace GpgFrontend::UI { SmartCardControllerDialog::SmartCardControllerDialog(QWidget* parent) : GeneralDialog("SmartCardControllerDialog", parent), ui_(QSharedPointer<Ui_SmartCardControllerDialog>::create()), - channel_(kGpgFrontendDefaultChannel) { + channel_(kGpgFrontendDefaultChannel), + scd_version_supported_( + GpgSmartCardManager::GetInstance(channel_).IsSCDVersionSupported()) { ui_->setupUi(this); ui_->smartCardLabel->setText(tr("Smart Card(s):")); @@ -384,6 +386,11 @@ void SmartCardControllerDialog::reset_status() { "restarting the application.") << "</p>"; + out << "<p><b>" + << tr("Note: Smart card support of GpgFrontend requires GnuPG version " + "2.3.0 or later.") + << "</b></p>"; + out << "<p>" << tr("Read the GnuPG Smart Card HOWTO: ") << "https://gnupg.org/howtos/card-howto/en/" << "</p>"; @@ -391,6 +398,12 @@ void SmartCardControllerDialog::reset_status() { } void SmartCardControllerDialog::slot_listen_smart_card_changes() { + if (!scd_version_supported_) { + LOG_D() << "scd version is not suppored"; + reset_status(); + return; + } + auto serial_numbers = GpgSmartCardManager::GetInstance(channel_).GetSerialNumbers(); diff --git a/src/ui/dialog/controller/SmartCardControllerDialog.h b/src/ui/dialog/controller/SmartCardControllerDialog.h index affe01a8..69b1d723 100644 --- a/src/ui/dialog/controller/SmartCardControllerDialog.h +++ b/src/ui/dialog/controller/SmartCardControllerDialog.h @@ -78,6 +78,7 @@ class SmartCardControllerDialog : public GeneralDialog { GpgOpenPGPCard card_info_; QString cached_status_hash_; QTimer* timer_; + bool scd_version_supported_; /** * @brief Get the smart card serial number object |