From 6f504e4f915f928e42b8574ca3f93eea5038984b Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 17 Apr 2025 19:44:04 +0200 Subject: feat: check scd version --- TRANSLATORS | 4 +- resource/lfs/locale/ts/GpgFrontend.de_DE.ts | 213 +++++++++++---------- resource/lfs/locale/ts/GpgFrontend.en_US.ts | 213 +++++++++++---------- resource/lfs/locale/ts/GpgFrontend.fr_FR.ts | 213 +++++++++++---------- resource/lfs/locale/ts/GpgFrontend.it_IT.ts | 213 +++++++++++---------- resource/lfs/locale/ts/GpgFrontend.zh_CN.ts | 213 +++++++++++---------- resource/lfs/locale/ts/GpgFrontend.zh_TW.ts | 213 +++++++++++---------- src/core/function/gpg/GpgAssuanHelper.cpp | 34 ++++ src/core/function/gpg/GpgAssuanHelper.h | 10 + src/core/function/gpg/GpgSmartCardManager.cpp | 12 ++ src/core/function/gpg/GpgSmartCardManager.h | 8 + .../controller/SmartCardControllerDialog.cpp | 15 +- .../dialog/controller/SmartCardControllerDialog.h | 1 + 13 files changed, 734 insertions(+), 628 deletions(-) diff --git a/TRANSLATORS b/TRANSLATORS index d3646cde..ce53a633 100644 --- a/TRANSLATORS +++ b/TRANSLATORS @@ -5,7 +5,5 @@ Zi Jiaxu (zh_CN) Oliver Leitner (de_DE) James (zh_TW) Salvatore Scirè (it_IT) -Google Translation Machine - -Reviewers: Saturneric (zh_CN, de_DE) +Google Translation Machine diff --git a/resource/lfs/locale/ts/GpgFrontend.de_DE.ts b/resource/lfs/locale/ts/GpgFrontend.de_DE.ts index 813bfd0d..973d3fbf 100644 --- a/resource/lfs/locale/ts/GpgFrontend.de_DE.ts +++ b/resource/lfs/locale/ts/GpgFrontend.de_DE.ts @@ -5934,460 +5934,465 @@ Wenn das Problem weiterhin besteht, wenden Sie sich an den technischen Support o GpgFrontend::UI::SmartCardControllerDialog - + Smart Card(s): - + Key Stub(s) in Key Database(s): - + Change Name - + Change Language - + Change Gender - + Change Login Data - + Change Public Key URL - + Change PIN - + Change Admin PIN - + Change Reset Code - + Fetch - + Restart All Gpg-Agents - + Generate Card Keys - + Refresh Aktualisierung - + Operations Aktivieren - + Successful Operation Erfolgreiche Durchführung - + Restart all the GnuPG's components successfully Alle Komponenten von GnuPG erfolgreich neu gestartet - + Failed Operation Fehlgeschlagener Vorgang - + Failed to restart all or one of the GnuPG's component(s) Neustart aller oder einer GnuPG-Komponente(n) fehlgeschlagen - + Generate card key failed. - + Smart Card Controller - + OpenPGP Card Information - + Basic Information - + Reader - + Serial Number - + Card Type - + Card Version - + App Type - + App Version - + Manufacturer ID - + Manufacturer - + Card Holder - + Language Sprache - + Sex - + Signature Counter - + CHV1 Cached - + CHV Max Length - + CHV Retry Left - + KDF Status - + UIF - + Sign Unterschreiben - + Enabled - + Disabled - + Encrypt Verschlüsseln - + Authenticate - + Status Indicator - + Male - + Female - + Select sex to store in '%1' - + Enter new value for attribute '%1' - + Status Status - + Not enabled - + Enabled (no protection) - + Enabled with salt protection - + Unknown Unbekannt - + Key Information - + No key information available. - + No. - + Fingerprint Fingerabdruck - + Created - + Grip - + Type Typ - + Algorithm Algorithmus - + Usage Verwendungszweck - + Curve - + Extended Capabilities - + Key Info (ki): %1 - - - - + + + + Yes Ja - - - - + + + + No Nein - + Additional Auth (aac): %1 - + Biometric Terminal (bt): %1 - + KDF Supported: %1 - + Additional Info - + No OpenPGP Smart Card Found - + No OpenPGP-compatible smart card has been detected. - + An OpenPGP Smart Card is a physical device that securely stores your private cryptographic keys and can be used for digital signing, encryption, and authentication. Popular examples include YubiKey, Nitrokey, and other GnuPG-compatible tokens. - + Make sure your card is inserted and properly recognized by the system. You can also try reconnecting the card or restarting the application. - + + Note: Smart card support of GpgFrontend requires GnuPG version 2.3.0 or later. + + + + Read the GnuPG Smart Card HOWTO: - - + + Modify Card Attribute - + Failed - + Failed to set attribute '%1'. Reason: %2. - - + + Success - + Attribute operation completed successfully. - + Failed to change Admin PIN. - + Failed to set the Reset Code. - + Failed to change PIN. - + Reason: - - + + Error Fehler - + PIN operation completed successfully. @@ -7171,32 +7176,32 @@ Wenn das Problem weiterhin besteht, wenden Sie sich an den technischen Support o QObject - + Cardholder's Surname - + Please enter your surname (e.g., Lee): - + Cardholder's Given Name - + Please enter your given name (e.g., Chris): - + Too Long - + Combined name too long (max 39 characters). diff --git a/resource/lfs/locale/ts/GpgFrontend.en_US.ts b/resource/lfs/locale/ts/GpgFrontend.en_US.ts index 5bb0aab8..fca628e4 100644 --- a/resource/lfs/locale/ts/GpgFrontend.en_US.ts +++ b/resource/lfs/locale/ts/GpgFrontend.en_US.ts @@ -5874,460 +5874,465 @@ If the issue persists, consider seeking technical support or consulting the docu GpgFrontend::UI::SmartCardControllerDialog - + Smart Card(s): - + Key Stub(s) in Key Database(s): - + Change Name - + Change Language - + Change Gender - + Change Login Data - + Change Public Key URL - + Change PIN - + Change Admin PIN - + Change Reset Code - + Fetch - + Restart All Gpg-Agents - + Generate Card Keys - + Refresh - + Operations - + Successful Operation - + Restart all the GnuPG's components successfully - + Failed Operation - + Failed to restart all or one of the GnuPG's component(s) - + Generate card key failed. - + Smart Card Controller - + OpenPGP Card Information - + Basic Information - + Reader - + Serial Number - + Card Type - + Card Version - + App Type - + App Version - + Manufacturer ID - + Manufacturer - + Card Holder - + Language - + Sex - + Signature Counter - + CHV1 Cached - + CHV Max Length - + CHV Retry Left - + KDF Status - + UIF - + Sign - + Enabled - + Disabled - + Encrypt - + Authenticate - + Status Indicator - + Male - + Female - + Select sex to store in '%1' - + Enter new value for attribute '%1' - + Status - + Not enabled - + Enabled (no protection) - + Enabled with salt protection - + Unknown - + Key Information - + No key information available. - + No. - + Fingerprint - + Created - + Grip - + Type - + Algorithm - + Usage - + Curve - + Extended Capabilities - + Key Info (ki): %1 - - - - + + + + Yes - - - - + + + + No - + Additional Auth (aac): %1 - + Biometric Terminal (bt): %1 - + KDF Supported: %1 - + Additional Info - + No OpenPGP Smart Card Found - + No OpenPGP-compatible smart card has been detected. - + An OpenPGP Smart Card is a physical device that securely stores your private cryptographic keys and can be used for digital signing, encryption, and authentication. Popular examples include YubiKey, Nitrokey, and other GnuPG-compatible tokens. - + Make sure your card is inserted and properly recognized by the system. You can also try reconnecting the card or restarting the application. - + + Note: Smart card support of GpgFrontend requires GnuPG version 2.3.0 or later. + + + + Read the GnuPG Smart Card HOWTO: - - + + Modify Card Attribute - + Failed - + Failed to set attribute '%1'. Reason: %2. - - + + Success - + Attribute operation completed successfully. - + Failed to change Admin PIN. - + Failed to set the Reset Code. - + Failed to change PIN. - + Reason: - - + + Error - + PIN operation completed successfully. @@ -7109,32 +7114,32 @@ If the issue persists, consider seeking technical support or consulting the docu QObject - + Cardholder's Surname - + Please enter your surname (e.g., Lee): - + Cardholder's Given Name - + Please enter your given name (e.g., Chris): - + Too Long - + Combined name too long (max 39 characters). diff --git a/resource/lfs/locale/ts/GpgFrontend.fr_FR.ts b/resource/lfs/locale/ts/GpgFrontend.fr_FR.ts index 20a458bb..6606f47b 100644 --- a/resource/lfs/locale/ts/GpgFrontend.fr_FR.ts +++ b/resource/lfs/locale/ts/GpgFrontend.fr_FR.ts @@ -5878,460 +5878,465 @@ If the issue persists, consider seeking technical support or consulting the docu GpgFrontend::UI::SmartCardControllerDialog - + Smart Card(s): - + Key Stub(s) in Key Database(s): - + Change Name - + Change Language - + Change Gender - + Change Login Data - + Change Public Key URL - + Change PIN - + Change Admin PIN - + Change Reset Code - + Fetch - + Restart All Gpg-Agents - + Generate Card Keys - + Refresh Rafraîchir - + Operations Opérations - + Successful Operation Opération réussie - + Restart all the GnuPG's components successfully Redémarrez tous les composants de GnuPG avec succès - + Failed Operation Échec de l'opération - + Failed to restart all or one of the GnuPG's component(s) Échec du redémarrage de tout ou partie des composants de GnuPG - + Generate card key failed. - + Smart Card Controller - + OpenPGP Card Information - + Basic Information - + Reader - + Serial Number - + Card Type - + Card Version - + App Type - + App Version - + Manufacturer ID - + Manufacturer - + Card Holder - + Language Langue - + Sex - + Signature Counter - + CHV1 Cached - + CHV Max Length - + CHV Retry Left - + KDF Status - + UIF - + Sign Signer - + Enabled - + Disabled - + Encrypt Chiffrer - + Authenticate - + Status Indicator - + Male - + Female - + Select sex to store in '%1' - + Enter new value for attribute '%1' - + Status Statut - + Not enabled - + Enabled (no protection) - + Enabled with salt protection - + Unknown Inconnu - + Key Information - + No key information available. - + No. - + Fingerprint Empreinte digitale - + Created - + Grip - + Type Taper - + Algorithm Algorithme - + Usage Usage - + Curve - + Extended Capabilities - + Key Info (ki): %1 - - - - + + + + Yes Oui - - - - + + + + No Non - + Additional Auth (aac): %1 - + Biometric Terminal (bt): %1 - + KDF Supported: %1 - + Additional Info - + No OpenPGP Smart Card Found - + No OpenPGP-compatible smart card has been detected. - + An OpenPGP Smart Card is a physical device that securely stores your private cryptographic keys and can be used for digital signing, encryption, and authentication. Popular examples include YubiKey, Nitrokey, and other GnuPG-compatible tokens. - + Make sure your card is inserted and properly recognized by the system. You can also try reconnecting the card or restarting the application. - + + Note: Smart card support of GpgFrontend requires GnuPG version 2.3.0 or later. + + + + Read the GnuPG Smart Card HOWTO: - - + + Modify Card Attribute - + Failed Échoué - + Failed to set attribute '%1'. Reason: %2. - - + + Success Succès - + Attribute operation completed successfully. - + Failed to change Admin PIN. - + Failed to set the Reset Code. - + Failed to change PIN. - + Reason: - - + + Error Erreur - + PIN operation completed successfully. @@ -7115,32 +7120,32 @@ If the issue persists, consider seeking technical support or consulting the docu QObject - + Cardholder's Surname - + Please enter your surname (e.g., Lee): - + Cardholder's Given Name - + Please enter your given name (e.g., Chris): - + Too Long - + Combined name too long (max 39 characters). diff --git a/resource/lfs/locale/ts/GpgFrontend.it_IT.ts b/resource/lfs/locale/ts/GpgFrontend.it_IT.ts index 12258f65..5de3c858 100644 --- a/resource/lfs/locale/ts/GpgFrontend.it_IT.ts +++ b/resource/lfs/locale/ts/GpgFrontend.it_IT.ts @@ -5942,460 +5942,465 @@ Se il problema persiste, prendere in considerazione la possibilità di richieder GpgFrontend::UI::SmartCardControllerDialog - + Smart Card(s): - + Key Stub(s) in Key Database(s): - + Change Name - + Change Language - + Change Gender - + Change Login Data - + Change Public Key URL - + Change PIN - + Change Admin PIN - + Change Reset Code - + Fetch - + Restart All Gpg-Agents - + Generate Card Keys - + Refresh Ricaricare - + Operations Operazioni - + Successful Operation Operazione riuscita - + Restart all the GnuPG's components successfully Riavvia correttamente tutti i componenti di GnuPG - + Failed Operation Operazione fallita - + Failed to restart all or one of the GnuPG's component(s) Impossibile riavviare tutti o uno dei componenti di GnuPG - + Generate card key failed. - + Smart Card Controller - + OpenPGP Card Information - + Basic Information - + Reader - + Serial Number - + Card Type - + Card Version - + App Type - + App Version - + Manufacturer ID - + Manufacturer - + Card Holder - + Language Lingua - + Sex - + Signature Counter - + CHV1 Cached - + CHV Max Length - + CHV Retry Left - + KDF Status - + UIF - + Sign Firma - + Enabled - + Disabled - + Encrypt Cifra - + Authenticate - + Status Indicator - + Male - + Female - + Select sex to store in '%1' - + Enter new value for attribute '%1' - + Status Stato - + Not enabled - + Enabled (no protection) - + Enabled with salt protection - + Unknown Sconosciuto - + Key Information - + No key information available. - + No. - + Fingerprint Impronta digitale - + Created - + Grip - + Type Tipo - + Algorithm Algoritmo - + Usage Utilizzo - + Curve - + Extended Capabilities - + Key Info (ki): %1 - - - - + + + + Yes - - - - + + + + No No - + Additional Auth (aac): %1 - + Biometric Terminal (bt): %1 - + KDF Supported: %1 - + Additional Info - + No OpenPGP Smart Card Found - + No OpenPGP-compatible smart card has been detected. - + An OpenPGP Smart Card is a physical device that securely stores your private cryptographic keys and can be used for digital signing, encryption, and authentication. Popular examples include YubiKey, Nitrokey, and other GnuPG-compatible tokens. - + Make sure your card is inserted and properly recognized by the system. You can also try reconnecting the card or restarting the application. - + + Note: Smart card support of GpgFrontend requires GnuPG version 2.3.0 or later. + + + + Read the GnuPG Smart Card HOWTO: - - + + Modify Card Attribute - + Failed Fallito - + Failed to set attribute '%1'. Reason: %2. - - + + Success Successo - + Attribute operation completed successfully. - + Failed to change Admin PIN. - + Failed to set the Reset Code. - + Failed to change PIN. - + Reason: - - + + Error Errore - + PIN operation completed successfully. @@ -7179,32 +7184,32 @@ Se il problema persiste, prendere in considerazione la possibilità di richieder QObject - + Cardholder's Surname - + Please enter your surname (e.g., Lee): - + Cardholder's Given Name - + Please enter your given name (e.g., Chris): - + Too Long - + Combined name too long (max 39 characters). diff --git a/resource/lfs/locale/ts/GpgFrontend.zh_CN.ts b/resource/lfs/locale/ts/GpgFrontend.zh_CN.ts index 8d69b915..02366ed3 100644 --- a/resource/lfs/locale/ts/GpgFrontend.zh_CN.ts +++ b/resource/lfs/locale/ts/GpgFrontend.zh_CN.ts @@ -5939,460 +5939,465 @@ If the issue persists, consider seeking technical support or consulting the docu GpgFrontend::UI::SmartCardControllerDialog - + Smart Card(s): 智能卡: - + Key Stub(s) in Key Database(s): 在密钥数据库中的密钥桩: - + Change Name 修改姓名 - + Change Language 修改语言 - + Change Gender 修改性别 - + Change Login Data 修改登录信息 - + Change Public Key URL 修改公钥链接 - + Change PIN 修改PIN - + Change Admin PIN 修改管理员PIN - + Change Reset Code 修改重置代码 - + Fetch 同步密钥信息 - + Restart All Gpg-Agents 重启所有Gpg-Agents - + Generate Card Keys 生成智能卡密钥 - + Refresh 刷新 - + Operations 操作 - + Successful Operation 操作成功 - + Restart all the GnuPG's components successfully 成功重启所有 GnuPG 组件 - + Failed Operation 操作失败 - + Failed to restart all or one of the GnuPG's component(s) 无法重新启动所有或其中一个 GnuPG 组件 - + Generate card key failed. 生成智能卡密钥失败。 - + Smart Card Controller 智能卡控制器 - + OpenPGP Card Information OpenPGP智能卡信息 - + Basic Information 基本信息 - + Reader 读卡器 - + Serial Number 序列号 - + Card Type 卡片类型 - + Card Version 卡片版本 - + App Type 应用类型 - + App Version 应用版本 - + Manufacturer ID 制造商ID - + Manufacturer 制造商 - + Card Holder 持卡人 - + Language 语言 - + Sex 性别 - + Signature Counter 签名计数器 - + CHV1 Cached 已缓存普通PIN - + CHV Max Length PIN最大长度 - + CHV Retry Left PIN剩余重试次数 - + KDF Status 密钥派生函数状态 - + UIF 用户交互标志 - + Sign 签名 - + Enabled 已启用 - + Disabled 已禁用 - + Encrypt 加密 - + Authenticate 验证 - + Status Indicator 状态指示器 - + Male - + Female - + Select sex to store in '%1' 选择存储在 '%1' 中的性别 - + Enter new value for attribute '%1' 请输入 '%1' 的新值 - + Status 状态 - + Not enabled 未启用 - + Enabled (no protection) 启用 (无保护) - + Enabled with salt protection 启用并开启加盐保护 - + Unknown 未知 - + Key Information 密钥信息 - + No key information available. 未发现可用密钥信息 - + No. 序号 - + Fingerprint 指纹 - + Created 已生成 - + Grip Grip - + Type 类型 - + Algorithm 算法 - + Usage 用法 - + Curve 密钥曲线 - + Extended Capabilities 扩展能力 - + Key Info (ki): %1 密钥信息 (ki): %1 - - - - + + + + Yes - - - - + + + + No - + Additional Auth (aac): %1 额外验证 (aac): %1 - + Biometric Terminal (bt): %1 生物终端: %1 - + KDF Supported: %1 密钥派生函数支持: %1 - + Additional Info 额外信息 - + No OpenPGP Smart Card Found 未发现OpenPGP智能卡 - + No OpenPGP-compatible smart card has been detected. 未检测到兼容 OpenPGP 的智能卡。 - + An OpenPGP Smart Card is a physical device that securely stores your private cryptographic keys and can be used for digital signing, encryption, and authentication. Popular examples include YubiKey, Nitrokey, and other GnuPG-compatible tokens. OpenPGP 智能卡是一种物理设备,可以安全地存储你的私人加密密钥,并可用于数字签名、加密和身份验证。流行的例子包括 YubiKey、Nitrokey 和其他 GnuPG 兼容令牌。 - + Make sure your card is inserted and properly recognized by the system. You can also try reconnecting the card or restarting the application. 确保您的卡已插入并被系统正确识别。您也可以尝试重新连接卡或重启应用程序。 - + + Note: Smart card support of GpgFrontend requires GnuPG version 2.3.0 or later. + 注意:GpgFrontend 的智能卡支持需要 GnuPG 2.3.0 或更高版本。 + + + Read the GnuPG Smart Card HOWTO: 阅读 GnuPG 智能卡帮助文档 - - + + Modify Card Attribute 修改智能卡属性 - + Failed 失败 - + Failed to set attribute '%1'. Reason: %2. 修改属性 '%1' 失败。 原因: %2。 - - + + Success 成功 - + Attribute operation completed successfully. 属性操作成功完成。 - + Failed to change Admin PIN. 修改管理员PIN失败。 - + Failed to set the Reset Code. 修改重置代码失败。 - + Failed to change PIN. 修改PIN失败。 - + Reason: 原因: - - + + Error 错误 - + PIN operation completed successfully. PIN操作成功完成。 @@ -7176,32 +7181,32 @@ If the issue persists, consider seeking technical support or consulting the docu QObject - + Cardholder's Surname 持卡人的姓氏 - + Please enter your surname (e.g., Lee): 请输入您的姓氏 (如: 李): - + Cardholder's Given Name 持卡人的名字 - + Please enter your given name (e.g., Chris): 请输入您的名字 (如: 四): - + Too Long 太长 - + Combined name too long (max 39 characters). 姓名合并后太长 (最长39个字符)。 diff --git a/resource/lfs/locale/ts/GpgFrontend.zh_TW.ts b/resource/lfs/locale/ts/GpgFrontend.zh_TW.ts index 9a8ce2a4..1d1d0245 100644 --- a/resource/lfs/locale/ts/GpgFrontend.zh_TW.ts +++ b/resource/lfs/locale/ts/GpgFrontend.zh_TW.ts @@ -5874,460 +5874,465 @@ If the issue persists, consider seeking technical support or consulting the docu GpgFrontend::UI::SmartCardControllerDialog - + Smart Card(s): - + Key Stub(s) in Key Database(s): - + Change Name - + Change Language - + Change Gender - + Change Login Data - + Change Public Key URL - + Change PIN - + Change Admin PIN - + Change Reset Code - + Fetch - + Restart All Gpg-Agents - + Generate Card Keys - + Refresh 刷新 - + Operations 運作中 - + Successful Operation 成功運作 - + Restart all the GnuPG's components successfully 成功重啟所有 GnuPG 組件 - + Failed Operation 操作失敗 - + Failed to restart all or one of the GnuPG's component(s) 無法重新啟動所有或其中一個 GnuPG 組件 - + Generate card key failed. - + Smart Card Controller - + OpenPGP Card Information - + Basic Information - + Reader - + Serial Number - + Card Type - + Card Version - + App Type - + App Version - + Manufacturer ID - + Manufacturer - + Card Holder - + Language - + Sex - + Signature Counter - + CHV1 Cached - + CHV Max Length - + CHV Retry Left - + KDF Status - + UIF - + Sign 標誌 - + Enabled - + Disabled - + Encrypt 加密 - + Authenticate - + Status Indicator - + Male - + Female - + Select sex to store in '%1' - + Enter new value for attribute '%1' - + Status 狀態 - + Not enabled - + Enabled (no protection) - + Enabled with salt protection - + Unknown 未知 - + Key Information - + No key information available. - + No. - + Fingerprint 指紋 - + Created - + Grip - + Type 類型 - + Algorithm 算法 - + Usage 用法 - + Curve - + Extended Capabilities - + Key Info (ki): %1 - - - - + + + + Yes 是的 - - - - + + + + No - + Additional Auth (aac): %1 - + Biometric Terminal (bt): %1 - + KDF Supported: %1 - + Additional Info - + No OpenPGP Smart Card Found - + No OpenPGP-compatible smart card has been detected. - + An OpenPGP Smart Card is a physical device that securely stores your private cryptographic keys and can be used for digital signing, encryption, and authentication. Popular examples include YubiKey, Nitrokey, and other GnuPG-compatible tokens. - + Make sure your card is inserted and properly recognized by the system. You can also try reconnecting the card or restarting the application. - + + Note: Smart card support of GpgFrontend requires GnuPG version 2.3.0 or later. + + + + Read the GnuPG Smart Card HOWTO: - - + + Modify Card Attribute - + Failed 失敗 - + Failed to set attribute '%1'. Reason: %2. - - + + Success 成功 - + Attribute operation completed successfully. - + Failed to change Admin PIN. - + Failed to set the Reset Code. - + Failed to change PIN. - + Reason: - - + + Error 錯誤 - + PIN operation completed successfully. @@ -7111,32 +7116,32 @@ If the issue persists, consider seeking technical support or consulting the docu QObject - + Cardholder's Surname - + Please enter your surname (e.g., Lee): - + Cardholder's Given Name - + Please enter your given name (e.g., Chris): - + Too Long - + Combined name too long (max 39 characters). 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 { + QStringList data_lines; + GpgAssuanHelper::DataCallback d_cb = + [&](const QSharedPointer& 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& ctx) + -> gpg_error_t { + LOG_D() << "inquery callback of command: " << command << ": " + << ctx->inquery; + + return 0; + }; + + GpgAssuanHelper::StatusCallback s_cb = + [&](const QSharedPointer& 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*>(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; + /** + * @brief + * + * @param type + * @param command + * @return auto + */ + auto SendDataCommand(GpgComponentType type, + const QString& command) -> std::tuple; + 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; + /** + * @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::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.") << "

"; + out << "

" + << tr("Note: Smart card support of GpgFrontend requires GnuPG version " + "2.3.0 or later.") + << "

"; + out << "

" << tr("Read the GnuPG Smart Card HOWTO: ") << "https://gnupg.org/howtos/card-howto/en/" << "

"; @@ -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 -- cgit v1.2.3