diff options
Diffstat (limited to 'src/gpg/result_analyse/VerifyResultAnalyse.cpp')
-rw-r--r-- | src/gpg/result_analyse/VerifyResultAnalyse.cpp | 291 |
1 files changed, 158 insertions, 133 deletions
diff --git a/src/gpg/result_analyse/VerifyResultAnalyse.cpp b/src/gpg/result_analyse/VerifyResultAnalyse.cpp index 75e07d33..55e50f38 100644 --- a/src/gpg/result_analyse/VerifyResultAnalyse.cpp +++ b/src/gpg/result_analyse/VerifyResultAnalyse.cpp @@ -1,7 +1,7 @@ /** - * This file is part of GPGFrontend. + * This file is part of GpgFrontend. * - * GPGFrontend is free software: you can redistribute it and/or modify + * GpgFrontend is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -22,147 +22,172 @@ * */ -#include "GpgFrontend.h" #include "gpg/result_analyse/VerifyResultAnalyse.h" -VerifyResultAnalyse::VerifyResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_verify_result_t result) - : mCtx(ctx) { +#include "GpgFrontend.h" +#include "gpg/GpgConstants.h" +#include "gpg/function/GpgKeyGetter.h" - qDebug() << "Verify Result Analyse Started"; +GpgFrontend::VerifyResultAnalyse::VerifyResultAnalyse(GpgError error, + GpgVerifyResult result) + : error(error), result(std::move(result)) {} - stream << tr("[#] Verify Operation "); +void GpgFrontend::VerifyResultAnalyse::do_analyse() { + LOG(INFO) << _("Verify Result Analyse Started"); - if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) - stream << tr("[Success]") << Qt::endl; - else { - stream << tr("[Failed] ") << gpgme_strerror(error) << Qt::endl; - setStatus(-1); - } + stream << "[#] " << _("Verify Operation") << " "; + if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) + stream << "[" << _("Success") << "]" << std::endl; + else { + stream << "[" << _("Failed") << "] " << gpgme_strerror(error) << std::endl; + setStatus(-1); + } - if (result != nullptr && result->signatures) { - stream << "------------>" << Qt::endl; - auto sign = result->signatures; + if (result != nullptr && result->signatures) { + stream << "------------>" << std::endl; + auto sign = result->signatures; - if (sign == nullptr) { - stream << "[>] Not Signature Found" << Qt::endl; + if (sign == nullptr) { + stream << "[>] " << _("Not Signature Found") << std::endl; + setStatus(0); + return; + } + + stream << "[>] " << _("Signed On") << " " + << boost::posix_time::to_iso_string( + boost::posix_time::from_time_t(sign->timestamp)) + << std::endl; + + stream << std::endl << "[>] " << _("Signatures") << ":" << std::endl; + + bool canContinue = true; + + while (sign && canContinue) { + switch (gpg_err_code(sign->status)) { + case GPG_ERR_BAD_SIGNATURE: + stream << _("One or More Bad Signatures.") << std::endl; + canContinue = false; + setStatus(-1); + break; + case GPG_ERR_NO_ERROR: + stream << _("A") << " "; + if (sign->summary & GPGME_SIGSUM_GREEN) { + stream << _("Good") << " "; + } + if (sign->summary & GPGME_SIGSUM_RED) { + stream << _("Bad") << " "; + } + if (sign->summary & GPGME_SIGSUM_SIG_EXPIRED) { + stream << _("Expired") << " "; + } + if (sign->summary & GPGME_SIGSUM_KEY_MISSING) { + stream << _("Missing Key's") << " "; + } + if (sign->summary & GPGME_SIGSUM_KEY_REVOKED) { + stream << _("Revoked Key's") << " "; + } + if (sign->summary & GPGME_SIGSUM_KEY_EXPIRED) { + stream << _("Expired Key's") << " "; + } + if (sign->summary & GPGME_SIGSUM_CRL_MISSING) { + stream << _("Missing CRL's") << " "; + } + + if (sign->summary & GPGME_SIGSUM_VALID) { + stream << _("Signature Fully Valid.") << std::endl; + } else { + stream << _("Signature Not Fully Valid.") << std::endl; + } + + if (!(sign->status & GPGME_SIGSUM_KEY_MISSING)) { + if (!print_signer(stream, sign)) setStatus(0); + } else { + stream << _("Key is NOT present with ID 0x") << sign->fpr + << std::endl; + } + + setStatus(1); + + break; + case GPG_ERR_NO_PUBKEY: + stream << _("A signature could NOT be verified due to a Missing Key") + << std::endl; + setStatus(-2); + break; + case GPG_ERR_CERT_REVOKED: + stream << _("A signature is valid but the key used to verify the " + "signature has been revoked") + << std::endl; + if (!print_signer(stream, sign)) { + setStatus(0); + } + setStatus(-1); + break; + case GPG_ERR_SIG_EXPIRED: + stream << _("A signature is valid but expired") << std::endl; + if (!print_signer(stream, sign)) { setStatus(0); - return; - } - - stream << "[>] Signed On " << QDateTime::fromTime_t(sign->timestamp).toString() << Qt::endl; - - stream << Qt::endl << "[>] Signatures:" << Qt::endl; - - bool canContinue = true; - - while (sign && canContinue) { - - switch (gpg_err_code(sign->status)) { - case GPG_ERR_BAD_SIGNATURE: - stream << QApplication::tr("One or More Bad Signatures.") << Qt::endl; - canContinue = false; - setStatus(-1); - break; - case GPG_ERR_NO_ERROR: - stream << QApplication::tr("A "); - if (sign->summary & GPGME_SIGSUM_GREEN) { - stream << QApplication::tr("Good "); - } - if (sign->summary & GPGME_SIGSUM_RED) { - stream << QApplication::tr("Bad "); - } - if (sign->summary & GPGME_SIGSUM_SIG_EXPIRED) { - stream << QApplication::tr("Expired "); - } - if (sign->summary & GPGME_SIGSUM_KEY_MISSING) { - stream << QApplication::tr("Missing Key's "); - } - if (sign->summary & GPGME_SIGSUM_KEY_REVOKED) { - stream << QApplication::tr("Revoked Key's "); - } - if (sign->summary & GPGME_SIGSUM_KEY_EXPIRED) { - stream << QApplication::tr("Expired Key's "); - } - if (sign->summary & GPGME_SIGSUM_CRL_MISSING) { - stream << QApplication::tr("Missing CRL's "); - } - - if (sign->summary & GPGME_SIGSUM_VALID) { - stream << QApplication::tr("Signature Fully Valid.") << Qt::endl; - } else { - stream << QApplication::tr("Signature Not Fully Valid.") << Qt::endl; - } - - if (!(sign->status & GPGME_SIGSUM_KEY_MISSING)) { - if (!printSigner(stream, sign)) setStatus(0); - } else { - stream << QApplication::tr("Key is NOT present with ID 0x") << QString(sign->fpr) << Qt::endl; - } - - setStatus(1); - - break; - case GPG_ERR_NO_PUBKEY: - stream << QApplication::tr("A signature could NOT be verified due to a Missing Key\n"); - setStatus(-1); - break; - case GPG_ERR_CERT_REVOKED: - stream << QApplication::tr( - "A signature is valid but the key used to verify the signature has been revoked\n"); - if (!printSigner(stream, sign)) { - setStatus(0); - } - setStatus(-1); - break; - case GPG_ERR_SIG_EXPIRED: - stream << QApplication::tr("A signature is valid but expired\n"); - if (!printSigner(stream, sign)) { - setStatus(0); - } - setStatus(-1); - break; - case GPG_ERR_KEY_EXPIRED: - stream << QApplication::tr( - "A signature is valid but the key used to verify the signature has expired.\n"); - if (!printSigner(stream, sign)) { - setStatus(0); - } - break; - case GPG_ERR_GENERAL: - stream << QApplication::tr( - "There was some other error which prevented the signature verification.\n"); - status = -1; - canContinue = false; - break; - default: - stream << QApplication::tr("Error for key with fingerprint ") << - GpgME::GpgContext::beautifyFingerprint(QString(sign->fpr)); - setStatus(-1); - } - stream << Qt::endl; - sign = sign->next; - } - stream << "<------------" << Qt::endl; + } + setStatus(-1); + break; + case GPG_ERR_KEY_EXPIRED: + stream << _("A signature is valid but the key used to " + "verify the signature has expired.") + << std::endl; + if (!print_signer(stream, sign)) { + setStatus(0); + } + break; + case GPG_ERR_GENERAL: + stream << _("There was some other error which prevented " + "the signature verification.") + << std::endl; + status = -1; + canContinue = false; + break; + default: + auto fpr = std::string(sign->fpr); + stream << _("Error for key with fingerprint") << " " + << GpgFrontend::beautify_fingerprint(fpr); + setStatus(-1); + } + stream << std::endl; + sign = sign->next; } + stream << "<------------" << std::endl; + } } -bool VerifyResultAnalyse::printSigner(QTextStream &stream, gpgme_signature_t sign) { - bool keyFound = true; - auto key = mCtx->getKeyByFpr(sign->fpr); - - key = mCtx->getKeyByFpr(sign->fpr); +bool GpgFrontend::VerifyResultAnalyse::print_signer(std::stringstream &stream, + gpgme_signature_t sign) { + bool keyFound = true; + auto key = GpgFrontend::GpgKeyGetter::GetInstance().GetKey(sign->fpr); + + if (!key.good()) { + stream << " " << _("Signed By") << ": " + << "<" << _("Unknown") << ">" << std::endl; + setStatus(0); + keyFound = false; + } else { + stream << " " << _("Signed By") << ": " << key.uids()->front().uid() + << std::endl; + } + stream << " " << _("Public Key Algo") << ": " + << gpgme_pubkey_algo_name(sign->pubkey_algo) << std::endl; + stream << " " << _("Hash Algo") << ": " + << gpgme_hash_algo_name(sign->hash_algo) << std::endl; + stream << " " << _("Date & Time") << ": " + << boost::posix_time::to_iso_string( + boost::posix_time::from_time_t(sign->timestamp)) + << std::endl; + stream << std::endl; + return keyFound; +} - if (!key.good) { - stream << tr(" Signed By: ") << tr("<unknown>") << Qt::endl; - setStatus(0); - keyFound = false; - } else { - stream << tr(" Signed By: ") << key.uids.first().uid << Qt::endl; - } - stream << tr(" Public Key Algo: ") << gpgme_pubkey_algo_name(sign->pubkey_algo) << Qt::endl; - stream << tr(" Hash Algo: ") << gpgme_hash_algo_name(sign->hash_algo) << Qt::endl; - stream << tr(" Date & Time: ") << QDateTime::fromTime_t(sign->timestamp).toString() << Qt::endl; - stream << Qt::endl; - return keyFound; -}
\ No newline at end of file +gpgme_signature_t GpgFrontend::VerifyResultAnalyse::GetSignatures() { + if (result) + return result->signatures; + else + return nullptr; +} |