diff options
author | saturneric <[email protected]> | 2024-01-25 17:23:46 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-25 17:23:46 +0000 |
commit | 06fcf7034d0ddb7444b57a1f9fe898eed7baafed (patch) | |
tree | 5547361afdae66c776150ea41a474daaebe7773a | |
parent | feat: load buddled qt and qtbase translations (diff) | |
download | GpgFrontend-06fcf7034d0ddb7444b57a1f9fe898eed7baafed.tar.gz GpgFrontend-06fcf7034d0ddb7444b57a1f9fe898eed7baafed.zip |
feat: enhance analysed results of verification and signing
4 files changed, 97 insertions, 39 deletions
diff --git a/src/core/function/result_analyse/GpgSignResultAnalyse.cpp b/src/core/function/result_analyse/GpgSignResultAnalyse.cpp index bf429f38..6e3e5cf4 100644 --- a/src/core/function/result_analyse/GpgSignResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgSignResultAnalyse.cpp @@ -71,13 +71,32 @@ void GpgSignResultAnalyse::doAnalyse() { stream_ << Qt::endl; - auto singer_key = GpgKeyGetter::GetInstance().GetKey(new_sign->fpr); + QString fpr = new_sign->fpr == nullptr ? "" : new_sign->fpr; + auto singer_key = GpgKeyGetter::GetInstance().GetKey(fpr); if (singer_key.IsGood()) { - stream_ << "- " << tr("Signer") << ": " + stream_ << "- " << tr("Signed By") << ": " << singer_key.GetUIDs()->front().GetUID() << Qt::endl; + + auto subkeys = singer_key.GetSubKeys(); + auto it = std::find_if( + subkeys->begin(), subkeys->end(), + [fpr](const GpgSubKey &k) { return k.GetFingerprint() == fpr; }); + + if (it != subkeys->end()) { + auto &subkey = *it; + if (subkey.GetFingerprint() != singer_key.GetFingerprint()) { + stream_ << "- " << tr("Key ID") << ": " << singer_key.GetId() + << " (" << tr("Subkey") << ")" << Qt::endl; + } else { + stream_ << "- " << tr("Key ID") << ": " << singer_key.GetId() + << " (" << tr("Primary Key") << ")" << Qt::endl; + } + stream_ << "- " << tr("Key Create Date") << ": " + << QLocale().toString(subkey.GetCreateTime()) << Qt::endl; + } } else { - stream_ << "- " << tr("Signer") << ": " - << "<unknown>" << Qt::endl; + stream_ << "- " << tr("Signed By") << "(" << tr("Fingerprint") << ")" + << ": " << (fpr.isEmpty() ? tr("<unknown>") : fpr) << Qt::endl; } stream_ << "- " << tr("Public Key Algo") << ": " << gpgme_pubkey_algo_name(new_sign->pubkey_algo) << Qt::endl; diff --git a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp index 618275f9..bde5fea4 100644 --- a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp @@ -28,7 +28,6 @@ #include "GpgVerifyResultAnalyse.h" -#include "GpgFrontend.h" #include "core/GpgModel.h" #include "core/function/gpg/GpgKeyGetter.h" #include "core/utils/CommonUtils.h" @@ -74,7 +73,7 @@ void GpgFrontend::GpgVerifyResultAnalyse::doAnalyse() { switch (gpg_err_code(sign->status)) { case GPG_ERR_BAD_SIGNATURE: stream_ << tr("A Bad Signature.") << Qt::endl; - print_signer(stream_, sign); + print_signer(stream_, GpgSignature(sign)); stream_ << tr("This Signature is invalid.") << Qt::endl; can_continue = false; setStatus(-1); @@ -107,12 +106,13 @@ void GpgFrontend::GpgVerifyResultAnalyse::doAnalyse() { stream_ << tr("Signature Fully Valid.") << Qt::endl; } else { stream_ << tr("Signature Not Fully Valid.") << Qt::endl; - stream_ << tr("(Adjust Trust Level to make it Fully Vaild)") + stream_ << "- " << tr("Tips") << ": " + << tr("Adjust Trust Level to make it Fully Vaild") << Qt::endl; } if ((sign->status & GPGME_SIGSUM_KEY_MISSING) == 0U) { - if (!print_signer(stream_, sign)) setStatus(0); + if (!print_signer(stream_, GpgSignature(sign))) setStatus(0); } else { stream_ << tr("Key is NOT present with ID 0x") << sign->fpr << Qt::endl; @@ -126,19 +126,20 @@ void GpgFrontend::GpgVerifyResultAnalyse::doAnalyse() { << tr("A signature could NOT be verified due to a Missing Key") << Qt::endl; setStatus(-2); + print_signer_without_key(stream_, GpgSignature(sign)); break; case GPG_ERR_CERT_REVOKED: stream_ << tr("A signature is valid but the key used to verify the " "signature has been revoked") << Qt::endl; - if (!print_signer(stream_, sign)) { + if (!print_signer(stream_, GpgSignature(sign))) { setStatus(0); } setStatus(-1); break; case GPG_ERR_SIG_EXPIRED: stream_ << tr("A signature is valid but expired") << Qt::endl; - if (!print_signer(stream_, sign)) { + if (!print_signer(stream_, GpgSignature(sign))) { setStatus(0); } setStatus(-1); @@ -147,7 +148,7 @@ void GpgFrontend::GpgVerifyResultAnalyse::doAnalyse() { stream_ << tr("A signature is valid but the key used to " "verify the signature has expired.") << Qt::endl; - if (!print_signer(stream_, sign)) { + if (!print_signer(stream_, GpgSignature(sign))) { setStatus(0); } break; @@ -178,39 +179,67 @@ void GpgFrontend::GpgVerifyResultAnalyse::doAnalyse() { } } +auto GpgFrontend::GpgVerifyResultAnalyse::print_signer_without_key( + QTextStream &stream, GpgSignature sign) -> bool { + stream_ << "- " << tr("Signed By") << "(" << tr("Fingerprint") << ")" + << ": " + << (sign.GetFingerprint().isEmpty() ? tr("<unknown>") + : sign.GetFingerprint()) + << Qt::endl; + stream << "- " << tr("Public Key Algo") << ": " << sign.GetPubkeyAlgo() + << Qt::endl; + stream << "- " << tr("Hash Algo") << ": " << sign.GetHashAlgo() << Qt::endl; + stream << "- " << tr("Sign Date") << "(" << tr("UTC") << ")" + << ": " << sign.GetCreateTime().toString() << Qt::endl; + stream << "- " << tr("SignDate") << "(" << tr("Localized") << ")" + << ": " << QLocale().toString(sign.GetCreateTime()) << Qt::endl; + return true; +} + auto GpgFrontend::GpgVerifyResultAnalyse::print_signer(QTextStream &stream, - gpgme_signature_t sign) + GpgSignature sign) -> bool { - bool key_found = true; - auto key = GpgFrontend::GpgKeyGetter::GetInstance().GetKey(sign->fpr); - - if (!key.IsGood()) { - stream << "- " << tr("Signed By") << ": " - << "<" << tr("Unknown") << ">" << Qt::endl; - setStatus(0); - key_found = false; - } else { + auto fingerprint = sign.GetFingerprint(); + auto key = GpgFrontend::GpgKeyGetter::GetInstance().GetKey(fingerprint); + if (key.IsGood()) { stream << "- " << tr("Signed By") << ": " << key.GetUIDs()->front().GetUID() << Qt::endl; - } - if (sign->pubkey_algo != 0U) { - stream << "- " << tr("Public Key Algo") << ": " - << gpgme_pubkey_algo_name(sign->pubkey_algo) << Qt::endl; - } - if (sign->hash_algo != 0U) { - stream << "- " << tr("Hash Algo") << ": " - << gpgme_hash_algo_name(sign->hash_algo) << Qt::endl; - } - if (sign->timestamp != 0U) { - stream << "- " << tr("Date") << "(" << tr("UTC") << ")" - << ": " << QDateTime::fromSecsSinceEpoch(sign->timestamp).toString() - << Qt::endl; - stream << "- " << tr("Date") << "(" << tr("Localized") << ")" - << ": " << GetFormatedDateByTimestamp(sign->timestamp) << Qt::endl; + auto subkeys = key.GetSubKeys(); + auto it = std::find_if(subkeys->begin(), subkeys->end(), + [fingerprint](const GpgSubKey &k) { + return k.GetFingerprint() == fingerprint; + }); + + if (it != subkeys->end()) { + auto &subkey = *it; + if (subkey.GetFingerprint() != key.GetFingerprint()) { + stream << "- " << tr("Key ID") << ": " << key.GetId() << " (" + << tr("Subkey") << ")" << Qt::endl; + } else { + stream << "- " << tr("Key ID") << ": " << key.GetId() << " (" + << tr("Primary Key") << ")" << Qt::endl; + } + stream << "- " << tr("Key Create Date") << ": " + << QLocale().toString(subkey.GetCreateTime()) << Qt::endl; + } + + } else { + stream_ << "- " << tr("Signed By") << "(" << tr("Fingerprint") << ")" + << ": " << (fingerprint.isEmpty() ? tr("<unknown>") : fingerprint) + << Qt::endl; + setStatus(0); } + + stream << "- " << tr("Public Key Algo") << ": " << sign.GetPubkeyAlgo() + << Qt::endl; + stream << "- " << tr("Hash Algo") << ": " << sign.GetHashAlgo() << Qt::endl; + stream << "- " << tr("Sign Date") << "(" << tr("UTC") << ")" + << ": " << sign.GetCreateTime().toString() << Qt::endl; + stream << "- " << tr("Sign Date") << "(" << tr("Localized") << ")" + << ": " << QLocale().toString(sign.GetCreateTime()) << Qt::endl; stream << Qt::endl; - return key_found; + return key.IsGood(); } auto GpgFrontend::GpgVerifyResultAnalyse::GetSignatures() const diff --git a/src/core/function/result_analyse/GpgVerifyResultAnalyse.h b/src/core/function/result_analyse/GpgVerifyResultAnalyse.h index 8aa2e41f..7b846f5e 100644 --- a/src/core/function/result_analyse/GpgVerifyResultAnalyse.h +++ b/src/core/function/result_analyse/GpgVerifyResultAnalyse.h @@ -77,7 +77,17 @@ class GPGFRONTEND_CORE_EXPORT GpgVerifyResultAnalyse : public GpgResultAnalyse { * @return true * @return false */ - auto print_signer(QTextStream &stream, gpgme_signature_t sign) -> bool; + auto print_signer(QTextStream &stream, GpgSignature sign) -> bool; + + /** + * @brief + * + * @param stream + * @param sign + * @return true + * @return false + */ + auto print_signer_without_key(QTextStream &stream, GpgSignature sign) -> bool; GpgError error_; ///< GpgVerifyResult result_; ///< diff --git a/src/core/model/GpgSignature.cpp b/src/core/model/GpgSignature.cpp index e2cb7e4b..e2671165 100644 --- a/src/core/model/GpgSignature.cpp +++ b/src/core/model/GpgSignature.cpp @@ -121,7 +121,7 @@ auto GpgSignature::GetExpireTime() const -> QDateTime { * @return QString */ auto GpgSignature::GetFingerprint() const -> QString { - return signature_ref_->fpr; + return signature_ref_->fpr != nullptr ? signature_ref_->fpr : ""; } /** |