aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-09-04 07:18:45 +0000
committerSaturneric <[email protected]>2021-09-04 07:18:45 +0000
commit4d9024347b0780afb955f0dbbda5d38907fe5200 (patch)
tree268022cbb9be8d7ca21b8dc7ae5f7834bd3f03ac /src
parentModified VerifyResultAnalyse (diff)
downloadGpgFrontend-4d9024347b0780afb955f0dbbda5d38907fe5200.tar.gz
GpgFrontend-4d9024347b0780afb955f0dbbda5d38907fe5200.zip
Modified ResultAnalyse.
Add Test.
Diffstat (limited to 'src')
-rw-r--r--src/gpg/function/GpgCommandExecutor.cpp45
-rw-r--r--src/gpg/gpg_context/GpgContext.cpp29
-rw-r--r--src/gpg/result_analyse/DecryptResultAnalyse.cpp22
-rw-r--r--src/gpg/result_analyse/EncryptResultAnalyse.cpp4
-rw-r--r--src/gpg/result_analyse/ResultAnalyse.cpp18
-rw-r--r--src/gpg/result_analyse/SignResultAnalyse.cpp15
-rw-r--r--src/gpg/result_analyse/VerifyResultAnalyse.cpp159
7 files changed, 164 insertions, 128 deletions
diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp
new file mode 100644
index 00000000..98743ed4
--- /dev/null
+++ b/src/gpg/function/GpgCommandExecutor.cpp
@@ -0,0 +1,45 @@
+/**
+ * This file is part of GPGFrontend.
+ *
+ * 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.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
+#include "gpg/function/GpgCommandExecutor.h"
+
+
+void GpgFrontend::GpgCommandExecutor::execute(const QStringList &arguments,
+ const std::function<void(QProcess *)> &interactFunc) {
+ QEventLoop looper;
+ auto *gpgProcess = new QProcess(&looper);
+ gpgProcess->setProcessChannelMode(QProcess::MergedChannels);
+ connect(gpgProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), &looper, &QEventLoop::quit);
+ connect(gpgProcess, &QProcess::errorOccurred, []() -> void { qDebug("Error in Process"); });
+ connect(gpgProcess, &QProcess::errorOccurred, &looper, &QEventLoop::quit);
+ connect(gpgProcess, &QProcess::started, []() -> void { qDebug() << "Gpg Process Started Success"; });
+ connect(gpgProcess, &QProcess::readyReadStandardOutput, [interactFunc, gpgProcess]() {
+ qDebug() << "Function Called";
+ interactFunc(gpgProcess);
+ });
+ gpgProcess->setProgram(ctx.getInfo().appPath);
+ gpgProcess->setArguments(arguments);
+ gpgProcess->start();
+ looper.exec();
+
+}
diff --git a/src/gpg/gpg_context/GpgContext.cpp b/src/gpg/gpg_context/GpgContext.cpp
index eaaac640..a892603c 100644
--- a/src/gpg/gpg_context/GpgContext.cpp
+++ b/src/gpg/gpg_context/GpgContext.cpp
@@ -131,7 +131,7 @@ namespace GpgFrontend {
#endif
if (last_was_bad) {
- passwordDialogMessage += "<i>" + tr("Wrong password") + ".</i><br><br>\n\n";
+ passwordDialogMessage += "<i> Wrong password. </i><br><br>\n\n";
clearPasswordCache();
}
@@ -139,11 +139,11 @@ namespace GpgFrontend {
if (!gpgHint.isEmpty()) {
// remove UID, leave only username & email
gpgHint.remove(0, gpgHint.indexOf(" "));
- passwordDialogMessage += "<b>" + tr("Enter Password for") + "</b><br>" + gpgHint + "<br>";
+ passwordDialogMessage += "<b> Enter Password for </b><br>" + gpgHint + "<br>";
}
if (mPasswordCache.isEmpty()) {
- QString password = QInputDialog::getText(QApplication::activeWindow(), tr("Enter Password"),
+ QString password = QInputDialog::getText(QApplication::activeWindow(), "Enter Password",
passwordDialogMessage, QLineEdit::Password,
"", &result);
@@ -200,30 +200,7 @@ namespace GpgFrontend {
}
/** return type should be gpgme_error_t*/
- void
- GpgContext::executeGpgCommand(const QStringList &arguments, const std::function<void(QProcess *)> &interactFunc) {
- QEventLoop looper;
- auto dialog = new WaitingDialog(tr("Processing"), nullptr);
- dialog->show();
- auto *gpgProcess = new QProcess(&looper);
- gpgProcess->setProcessChannelMode(QProcess::MergedChannels);
- connect(gpgProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), &looper, &QEventLoop::quit);
- connect(gpgProcess, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), dialog,
- &WaitingDialog::deleteLater);
- connect(gpgProcess, &QProcess::errorOccurred, []() -> void { qDebug("Error in Process"); });
- connect(gpgProcess, &QProcess::errorOccurred, &looper, &QEventLoop::quit);
- connect(gpgProcess, &QProcess::started, []() -> void { qDebug() << "Gpg Process Started Success"; });
- connect(gpgProcess, &QProcess::readyReadStandardOutput, [interactFunc, gpgProcess]() {
- qDebug() << "Function Called";
- interactFunc(gpgProcess);
- });
- gpgProcess->setProgram(info.appPath);
- gpgProcess->setArguments(arguments);
- gpgProcess->start();
- looper.exec();
- dialog->close();
- }
/*
diff --git a/src/gpg/result_analyse/DecryptResultAnalyse.cpp b/src/gpg/result_analyse/DecryptResultAnalyse.cpp
index 7c91e6b2..351045c9 100644
--- a/src/gpg/result_analyse/DecryptResultAnalyse.cpp
+++ b/src/gpg/result_analyse/DecryptResultAnalyse.cpp
@@ -22,11 +22,12 @@
*
*/
+#include "gpg/function/GpgKeyGetter.h"
#include "gpg/result_analyse/DecryptResultAnalyse.h"
-DecryptResultAnalyse::DecryptResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_decrypt_result_t result)
- : mCtx(ctx) {
+GpgFrontend::DecryptResultAnalyse::DecryptResultAnalyse(GpgError error, GpgDecrResult result) : error(error), result(std::move(result)) {}
+void GpgFrontend::DecryptResultAnalyse::do_analyse() {
stream << tr("[#] Decrypt Operation ");
if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) {
@@ -51,25 +52,24 @@ DecryptResultAnalyse::DecryptResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_e
if (reci != nullptr)
stream << tr("Recipient(s): ") << Qt::endl;
while (reci != nullptr) {
- printReci(stream, reci);
+ print_reci(stream, reci);
reci = reci->next;
}
stream << "<------------" << Qt::endl;
}
stream << Qt::endl;
-
}
-bool DecryptResultAnalyse::printReci(QTextStream &stream, gpgme_recipient_t reci) {
+bool GpgFrontend::DecryptResultAnalyse::print_reci(QTextStream &stream, gpgme_recipient_t reci) {
bool keyFound = true;
stream << QApplication::tr(" {>} Recipient: ");
- auto key = mCtx->getKeyRefById(reci->keyid);
- if(key.good) {
- stream << key.name;
- if (!key.email.isEmpty()) {
- stream << "<" << key.email << ">";
+ auto key = GpgFrontend::GpgKeyGetter::getInstance().getKey(reci->keyid);
+ if(key.good()) {
+ stream << key.name().c_str();
+ if (!key.email().empty()) {
+ stream << "<" << key.email().c_str() << ">";
}
} else {
stream << "<Unknown>";
@@ -79,7 +79,7 @@ bool DecryptResultAnalyse::printReci(QTextStream &stream, gpgme_recipient_t reci
stream << Qt::endl;
- stream << tr(" Keu ID: ") << reci->keyid << Qt::endl;
+ stream << tr(" Keu ID: ") << key.id().c_str() << Qt::endl;
stream << tr(" Public Algo: ") << gpgme_pubkey_algo_name(reci->pubkey_algo) << Qt::endl;
return keyFound;
diff --git a/src/gpg/result_analyse/EncryptResultAnalyse.cpp b/src/gpg/result_analyse/EncryptResultAnalyse.cpp
index 1ba685c9..fd7faf59 100644
--- a/src/gpg/result_analyse/EncryptResultAnalyse.cpp
+++ b/src/gpg/result_analyse/EncryptResultAnalyse.cpp
@@ -24,8 +24,9 @@
#include "gpg/result_analyse/EncryptResultAnalyse.h"
-EncryptResultAnalyse::EncryptResultAnalyse(gpgme_error_t error, gpgme_encrypt_result_t result) {
+GpgFrontend::EncryptResultAnalyse::EncryptResultAnalyse(GpgError error, GpgEncrResult result) : error(error), result(std::move(result)) {}
+void GpgFrontend::EncryptResultAnalyse::do_analyse() {
qDebug() << "Start Encrypt Result Analyse";
stream << "[#] Encrypt Operation ";
@@ -54,5 +55,4 @@ EncryptResultAnalyse::EncryptResultAnalyse(gpgme_error_t error, gpgme_encrypt_re
}
stream << Qt::endl;
-
}
diff --git a/src/gpg/result_analyse/ResultAnalyse.cpp b/src/gpg/result_analyse/ResultAnalyse.cpp
index 7186d21a..b1f2cef9 100644
--- a/src/gpg/result_analyse/ResultAnalyse.cpp
+++ b/src/gpg/result_analyse/ResultAnalyse.cpp
@@ -24,15 +24,23 @@
#include "gpg/result_analyse/ResultAnalyse.h"
-const QString &ResultAnalyse::getResultReport() const{
+const QString &GpgFrontend::ResultAnalyse::getResultReport() {
+ if(!analysed_) do_analyse();
return resultText;
}
-int ResultAnalyse::getStatus() const {
+int GpgFrontend::ResultAnalyse::getStatus() {
+ if(!analysed_) do_analyse();
return status;
}
-void ResultAnalyse::setStatus(int mStatus) {
- if(mStatus < status)
- status = mStatus;
+void GpgFrontend::ResultAnalyse::setStatus(int mStatus) {
+ if(mStatus < status) status = mStatus;
+}
+
+void GpgFrontend::ResultAnalyse::analyse() {
+ if(!analysed_){
+ do_analyse();
+ analysed_ = true;
+ }
}
diff --git a/src/gpg/result_analyse/SignResultAnalyse.cpp b/src/gpg/result_analyse/SignResultAnalyse.cpp
index efbbb4db..ff7cd029 100644
--- a/src/gpg/result_analyse/SignResultAnalyse.cpp
+++ b/src/gpg/result_analyse/SignResultAnalyse.cpp
@@ -22,10 +22,14 @@
*
*/
+#include "gpg/function/GpgKeyGetter.h"
#include "gpg/result_analyse/SignResultAnalyse.h"
-SignResultAnalyse::SignResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t error, gpgme_sign_result_t result) {
+GpgFrontend::SignResultAnalyse::SignResultAnalyse(GpgError error, GpgSignResult result) : error(error),
+ result(std::move(result)) {}
+
+void GpgFrontend::SignResultAnalyse::do_analyse() {
qDebug() << "Start Sign Result Analyse";
stream << tr("[#] Sign Operation ");
@@ -58,9 +62,9 @@ SignResultAnalyse::SignResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t
stream << Qt::endl;
- GpgKey singerKey = ctx->getKeyRefByFpr(new_sign->fpr);
- if(singerKey.good) {
- stream << tr(" Signer: ") << singerKey.uids.first().uid << Qt::endl;
+ auto singerKey = GpgFrontend::GpgKeyGetter::getInstance().getKey(new_sign->fpr);
+ if (singerKey.good()) {
+ stream << tr(" Signer: ") << singerKey.uids()->front().uid() << Qt::endl;
} else {
stream << tr(" Signer: ") << tr("<unknown>") << Qt::endl;
}
@@ -92,5 +96,4 @@ SignResultAnalyse::SignResultAnalyse(GpgFrontend::GpgContext *ctx, gpgme_error_t
stream << "<------------" << Qt::endl;
}
-
-}
+} \ No newline at end of file
diff --git a/src/gpg/result_analyse/VerifyResultAnalyse.cpp b/src/gpg/result_analyse/VerifyResultAnalyse.cpp
index e7c3276a..f794b31c 100644
--- a/src/gpg/result_analyse/VerifyResultAnalyse.cpp
+++ b/src/gpg/result_analyse/VerifyResultAnalyse.cpp
@@ -26,8 +26,9 @@
#include "gpg/function/GpgKeyGetter.h"
#include "gpg/result_analyse/VerifyResultAnalyse.h"
-GpgFrontend::VerifyResultAnalyse::VerifyResultAnalyse(gpgme_error_t error, gpgme_verify_result_t result) {
+GpgFrontend::VerifyResultAnalyse::VerifyResultAnalyse(GpgError error, GpgVerifyResult result) : error(errror), result(std::move(result)) {}
+void GpgFrontend::VerifyResultAnalyse::do_analyse() {
qDebug() << "Verify Result Analyse Started";
stream << tr("[#] Verify Operation ");
@@ -64,81 +65,81 @@ GpgFrontend::VerifyResultAnalyse::VerifyResultAnalyse(gpgme_error_t error, gpgme
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 ") <<
- GpgFrontend::GpgContext::beautifyFingerprint(QString(sign->fpr));
- setStatus(-1);
+ 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 (!print_signer(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 (!print_signer(stream, sign)) {
+ setStatus(0);
+ }
+ setStatus(-1);
+ break;
+ case GPG_ERR_SIG_EXPIRED:
+ stream << QApplication::tr("A signature is valid but expired\n");
+ if (!print_signer(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 (!print_signer(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 ") <<
+ GpgFrontend::GpgContext::beautifyFingerprint(QString(sign->fpr));
+ setStatus(-1);
}
stream << Qt::endl;
sign = sign->next;
@@ -147,7 +148,8 @@ GpgFrontend::VerifyResultAnalyse::VerifyResultAnalyse(gpgme_error_t error, gpgme
}
}
-bool GpgFrontend::VerifyResultAnalyse::printSigner(QTextStream &stream, gpgme_signature_t sign) {
+
+bool GpgFrontend::VerifyResultAnalyse::print_signer(QTextStream &stream, gpgme_signature_t sign) {
bool keyFound = true;
auto key = GpgFrontend::GpgKeyGetter::getInstance().getKey(sign->fpr);
@@ -163,4 +165,5 @@ bool GpgFrontend::VerifyResultAnalyse::printSigner(QTextStream &stream, gpgme_si
stream << tr(" Date & Time: ") << QDateTime::fromTime_t(sign->timestamp).toString() << Qt::endl;
stream << Qt::endl;
return keyFound;
-} \ No newline at end of file
+}
+