diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MainWindow.cpp | 151 | ||||
-rw-r--r-- | src/gpg/GpgContext.cpp | 113 | ||||
-rw-r--r-- | src/gpg/result_analyse/DecryptResultAnalyse.cpp | 62 | ||||
-rw-r--r-- | src/gpg/result_analyse/EncryptResultAnalyse.cpp | 35 | ||||
-rw-r--r-- | src/gpg/result_analyse/ResultAnalyse.cpp | 18 | ||||
-rw-r--r-- | src/gpg/result_analyse/SignResultAnalyse.cpp | 47 | ||||
-rw-r--r-- | src/gpg/result_analyse/VerifyResultAnalyse.cpp | 84 | ||||
-rwxr-xr-x | src/ui/FileEncryptionDialog.cpp | 18 | ||||
-rw-r--r-- | src/ui/VerifyDetailsDialog.cpp | 8 |
9 files changed, 396 insertions, 140 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index f173fa81..3d17b9ad 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -37,10 +37,11 @@ MainWindow::MainWindow() { /* the list of Keys available*/ mKeyList = new KeyList(mCtx, KeyListRow::SECRET_OR_PUBLIC_KEY, - KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage | KeyListColumn::Validity, + KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | + KeyListColumn::Usage | KeyListColumn::Validity, this); mKeyList->setFilter([](const GpgKey &key) -> bool { - if(key.revoked || key.disabled || key.expired) return false; + if (key.revoked || key.disabled || key.expired) return false; else return true; }); mKeyList->slotRefresh(); @@ -613,7 +614,7 @@ void MainWindow::createDockWindows() { infoBoardDock->setAllowedAreas(Qt::BottomDockWidgetArea); addDockWidget(Qt::BottomDockWidgetArea, infoBoardDock); infoBoardDock->setWidget(infoBoard); - infoBoardDock->widget()->layout()->setContentsMargins(0,0,0,0); + infoBoardDock->widget()->layout()->setContentsMargins(0, 0, 0, 0); viewMenu->addAction(infoBoardDock->toggleViewAction()); /* Attachments-Dockwindow @@ -773,13 +774,43 @@ void MainWindow::slotEncrypt() { return; } - QStringList *uidList = mKeyList->getChecked(); + QVector<GpgKey> keys; + mKeyList->getCheckedKeys(keys); - auto *tmp = new QByteArray(); - if (mCtx->encrypt(uidList, edit->curTextPage()->toPlainText().toUtf8(), tmp)) { - auto *tmp2 = new QString(*tmp); - edit->slotFillTextEditWithText(*tmp2); + if (keys.count() == 0) { + QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); + return; } + + for (const auto &key : keys) { + if (!GpgME::GpgContext::checkIfKeyCanEncr(key)) { + QMessageBox::information(nullptr, + tr("Invalid Operation"), + tr("The selected key contains a key that does not actually have a encrypt function.<br/>") + + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); + return; + + } + } + + auto *tmp = new QByteArray(); + + gpgme_encrypt_result_t result = nullptr; + auto error = mCtx->encrypt(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &result); + + auto resultAnalyse = new EncryptResultAnalyse(error, result); + auto &reportText = resultAnalyse->getResultReport(); + + auto *tmp2 = new QString(*tmp); + edit->slotFillTextEditWithText(*tmp2); + infoBoard->associateTextEdit(edit->curTextPage()); + + if (resultAnalyse->getStatus() < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (resultAnalyse->getStatus() > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); } void MainWindow::slotSign() { @@ -787,14 +818,17 @@ void MainWindow::slotSign() { return; } - QStringList *uidList = mKeyList->getPrivateChecked(); - QVector<GpgKey> keys; mKeyList->getPrivateCheckedKeys(keys); - for(const auto &key : keys) { - if(!GpgME::GpgContext::checkIfKeyCanSign(key)) { + if (keys.isEmpty()) { + QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); + return; + } + + for (const auto &key : keys) { + if (!GpgME::GpgContext::checkIfKeyCanSign(key)) { QMessageBox::information(nullptr, tr("Invalid Operation"), tr("The selected key contains a key that does not actually have a signature function.<br/>") @@ -805,13 +839,25 @@ void MainWindow::slotSign() { auto *tmp = new QByteArray(); - if (mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp)) { - edit->slotFillTextEditWithText(QString::fromUtf8(*tmp)); - } + gpgme_sign_result_t result = nullptr; + + auto error = mCtx->sign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, false, &result); + infoBoard->associateTextEdit(edit->curTextPage()); + edit->slotFillTextEditWithText(QString::fromUtf8(*tmp)); + + auto resultAnalyse = new SignResultAnalyse(error, result); + + auto &reportText = resultAnalyse->getResultReport(); + if (resultAnalyse->getStatus() < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (resultAnalyse->getStatus() > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); } void MainWindow::slotDecrypt() { - if (edit->tabCount() == 0 || edit->slotCurPage() == 0) { + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { return; } @@ -819,10 +865,10 @@ void MainWindow::slotDecrypt() { QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); GpgME::GpgContext::preventNoDataErr(&text); + gpgme_decrypt_result_t result = nullptr; // try decrypt, if fail do nothing, especially don't replace text - if (!mCtx->decrypt(text, decrypted)) { - return; - } + auto error = mCtx->decrypt(text, decrypted, &result); + infoBoard->associateTextEdit(edit->curTextPage()); /* * 1) is it mime (content-type:) @@ -846,6 +892,16 @@ void MainWindow::slotDecrypt() { } } edit->slotFillTextEditWithText(QString::fromUtf8(*decrypted)); + + auto resultAnalyse = new DecryptResultAnalyse(mCtx, error, result); + + auto &reportText = resultAnalyse->getResultReport(); + if (resultAnalyse->getStatus() < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (resultAnalyse->getStatus() > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); } void MainWindow::slotFind() { @@ -866,31 +922,31 @@ void MainWindow::slotVerify() { return; } - // At first close verifynotification, if existing - // edit->slotCurPage()->closeNoteByClass("infoBoard"); - // If an unknown key is found, enable the importfromkeyserveraction QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); GpgME::GpgContext::preventNoDataErr(&text); - gpgme_signature_t sign = mCtx->verify(&text); - auto verify = new VerifyResultAnalyse(mCtx, sign); + gpgme_verify_result_t result; + + auto error = mCtx->verify(&text, nullptr, &result); + + auto resultAnalyse = new VerifyResultAnalyse(mCtx, error, result); infoBoard->associateTextEdit(edit->curTextPage()); - auto &reportText = verify->getResultReport(); - if(verify->getStatus() < 0) + auto &reportText = resultAnalyse->getResultReport(); + if (resultAnalyse->getStatus() < 0) infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); - else if(verify->getStatus() > 0) + else if (resultAnalyse->getStatus() > 0) infoBoard->slotRefresh(reportText, INFO_ERROR_OK); else infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); - if(verify->getStatus() >= 0) { + if (resultAnalyse->getStatus() >= 0) { infoBoard->resetOptionActionsMenu(); - infoBoard->addOptionalAction("Show Verify Details", [this, sign]() { - VerifyDetailsDialog(this, mCtx, mKeyList, sign); + infoBoard->addOptionalAction("Show Verify Details", [this, error, result]() { + VerifyDetailsDialog(this, mCtx, mKeyList, error, result); }); } @@ -1078,8 +1134,13 @@ void MainWindow::slotEncryptSign() { QVector<GpgKey> keys; mKeyList->getCheckedKeys(keys); - for(const auto &key : keys) { - if(!GpgME::GpgContext::checkIfKeyCanSign(key) || !GpgME::GpgContext::checkIfKeyCanEncr(key)) { + if (keys.empty()) { + QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); + return; + } + + for (const auto &key : keys) { + if (!GpgME::GpgContext::checkIfKeyCanSign(key) || !GpgME::GpgContext::checkIfKeyCanEncr(key)) { QMessageBox::information(nullptr, tr("Invalid Operation"), tr("The selected key cannot be used for signing and encryption at the same time.<br/>") @@ -1089,8 +1150,26 @@ void MainWindow::slotEncryptSign() { } auto *tmp = new QByteArray(); - if (mCtx->encryptSign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp)) { - auto *tmp2 = new QString(*tmp); - edit->slotFillTextEditWithText(*tmp2); - } + gpgme_encrypt_result_t encr_result = nullptr; + gpgme_sign_result_t sign_result = nullptr; + + auto error = mCtx->encryptSign(keys, edit->curTextPage()->toPlainText().toUtf8(), tmp, &encr_result, &sign_result); + auto *tmp2 = new QString(*tmp); + edit->slotFillTextEditWithText(*tmp2); + + auto resultAnalyseEncr = new EncryptResultAnalyse(error, encr_result); + auto resultAnalyseSign = new SignResultAnalyse(error, sign_result); + int status = std::min(resultAnalyseEncr->getStatus(), resultAnalyseSign->getStatus()); + auto reportText = resultAnalyseEncr->getResultReport() + resultAnalyseSign->getResultReport(); + + infoBoard->associateTextEdit(edit->curTextPage()); + + if (status < 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_CRITICAL); + else if (status > 0) + infoBoard->slotRefresh(reportText, INFO_ERROR_OK); + else + infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + } diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index be6e19d4..bd1aa013 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -371,28 +371,22 @@ namespace GpgME { /** Encrypt inBuffer for reciepients-uids, write * result to outBuffer */ - bool GpgContext::encrypt(QStringList *uidList, const QByteArray &inBuffer, QByteArray *outBuffer) { + gpg_error_t GpgContext::encrypt(QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, + gpgme_encrypt_result_t *result) { gpgme_data_t dataIn = nullptr, dataOut = nullptr; outBuffer->resize(0); - if (uidList->count() == 0) { - QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); - return false; - } - //gpgme_encrypt_result_t e_result; - gpgme_key_t recipients[uidList->count() + 1]; + gpgme_key_t recipients[keys.count() + 1]; - /* get key for user */ - for (int i = 0; i < uidList->count(); i++) { - // the last 0 is for public keys, 1 would return private keys - gpgme_op_keylist_start(mCtx, uidList->at(i).toUtf8().constData(), 0); - gpgme_op_keylist_next(mCtx, &recipients[i]); - gpgme_op_keylist_end(mCtx); + int index = 0; + for(const auto& key : keys) { + recipients[index++] = key.key_refer; } + //Last entry dataIn array has to be nullptr - recipients[uidList->count()] = nullptr; + recipients[keys.count()] = nullptr; //If the last parameter isnt 0, a private copy of data is made if (mCtx) { @@ -411,25 +405,26 @@ namespace GpgME { } } } - /* unref all keys */ - for (int i = 0; i <= uidList->count(); i++) { - gpgme_key_unref(recipients[i]); - } if (dataIn) { gpgme_data_release(dataIn); } if (dataOut) { gpgme_data_release(dataOut); } - return (err == GPG_ERR_NO_ERROR); + + if(result != nullptr) { + *result = gpgme_op_encrypt_result(mCtx); + } + return err; } /** Decrypt QByteAarray, return QByteArray * mainly from http://basket.kde.org/ (kgpgme.cpp) */ - bool GpgContext::decrypt(const QByteArray &inBuffer, QByteArray *outBuffer) { + gpgme_error_t + GpgContext::decrypt(const QByteArray &inBuffer, QByteArray *outBuffer, gpgme_decrypt_result_t *result) { gpgme_data_t dataIn = nullptr, dataOut = nullptr; - gpgme_decrypt_result_t result = nullptr; + gpgme_decrypt_result_t m_result = nullptr; QString errorString; outBuffer->resize(0); @@ -445,20 +440,20 @@ namespace GpgME { if (gpg_err_code(err) == GPG_ERR_DECRYPT_FAILED) { errorString.append(gpgErrString(err)).append("<br>"); - result = gpgme_op_decrypt_result(mCtx); - checkErr(result->recipients->status); - errorString.append(gpgErrString(result->recipients->status)).append("<br>"); + m_result = gpgme_op_decrypt_result(mCtx); + checkErr(m_result->recipients->status); + errorString.append(gpgErrString(m_result->recipients->status)).append("<br>"); errorString.append( tr("<br>No private key with id %1 present dataIn keyring").arg( - result->recipients->keyid)); + m_result->recipients->keyid)); } else { errorString.append(gpgErrString(err)).append("<br>"); } if (!err) { - result = gpgme_op_decrypt_result(mCtx); - if (result->unsupported_algorithm) { - QMessageBox::critical(0, tr("Unsupported algorithm"), result->unsupported_algorithm); + m_result = gpgme_op_decrypt_result(mCtx); + if (m_result->unsupported_algorithm) { + QMessageBox::critical(0, tr("Unsupported algorithm"), m_result->unsupported_algorithm); } else { err = readToBuffer(dataOut, outBuffer); checkErr(err); @@ -482,7 +477,11 @@ namespace GpgME { if (dataOut) { gpgme_data_release(dataOut); } - return (err == GPG_ERR_NO_ERROR); + + if(result != nullptr) { + *result = m_result; + } + return err; } /** Read gpgme-Data to QByteArray @@ -660,12 +659,12 @@ namespace GpgME { * -> valid * -> errors */ - gpgme_signature_t GpgContext::verify(QByteArray *inBuffer, QByteArray *sigBuffer) { + gpgme_error_t GpgContext::verify(QByteArray *inBuffer, QByteArray *sigBuffer, gpgme_verify_result_t *result) { gpgme_data_t dataIn; gpgme_error_t gpgmeError; gpgme_signature_t sign; - gpgme_verify_result_t result; + gpgme_verify_result_t m_result; gpgmeError = gpgme_data_new_from_mem(&dataIn, inBuffer->data(), inBuffer->size(), 1); checkErr(gpgmeError); @@ -681,13 +680,13 @@ namespace GpgME { checkErr(gpgmeError); - if (gpgmeError != 0) { - return nullptr; + m_result = gpgme_op_verify_result(mCtx); + + if(result != nullptr) { + *result = m_result; } - result = gpgme_op_verify_result(mCtx); - sign = result->signatures; - return sign; + return gpgmeError; } /*** @@ -710,11 +709,11 @@ namespace GpgME { verify_result = gpgme_op_verify_result (mCtx); */ //} - bool GpgContext::sign(QVector<GpgKey> keys, const QByteArray &inBuffer, QByteArray *outBuffer, bool detached) { + gpg_error_t GpgContext::sign(const QVector<GpgKey>& keys, const QByteArray &inBuffer, QByteArray *outBuffer, bool detached, gpgme_sign_result_t *result) { gpgme_error_t gpgmeError; gpgme_data_t dataIn, dataOut; - gpgme_sign_result_t result; + gpgme_sign_result_t m_result; gpgme_sig_mode_t mode; if (keys.isEmpty()) { @@ -762,9 +761,11 @@ namespace GpgME { return false; } - result = gpgme_op_sign_result(mCtx); + m_result = gpgme_op_sign_result(mCtx); - // TODO Handle the result + if(result != nullptr) { + *result = m_result; + } gpgmeError = readToBuffer(dataOut, outBuffer); checkErr(gpgmeError); @@ -776,7 +777,7 @@ namespace GpgME { clearPasswordCache(); } - return (gpgmeError == GPG_ERR_NO_ERROR); + return gpgmeError; } /* @@ -847,12 +848,19 @@ namespace GpgME { /** * note: is_private_key status is not returned */ - const GpgKey &GpgContext::getKeyById(const QString &id) { - - auto it = mKeyMap.find(id); + const GpgKey & GpgContext::getKeyById(const QString &id) { - if(it != mKeyMap.end()) { - return *(it.value()); + for(const auto &key : mKeyList) { + if (key.id == id) { + return key; + } else { + auto subkeys = key.subKeys; + for (const auto &subkey : subkeys) { + if (subkey.id == id) { + return key; + } + } + } } throw std::runtime_error("key not found"); @@ -1090,7 +1098,8 @@ namespace GpgME { return false; } - bool GpgContext::encryptSign(QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer) { + gpgme_error_t GpgContext::encryptSign(QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, + gpgme_encrypt_result_t *encr_result, gpgme_sign_result_t *sign_result) { gpgme_data_t dataIn = nullptr, dataOut = nullptr; outBuffer->resize(0); @@ -1135,7 +1144,15 @@ namespace GpgME { if (dataOut) { gpgme_data_release(dataOut); } - return (err == GPG_ERR_NO_ERROR); + + if(encr_result != nullptr) { + *encr_result = gpgme_op_encrypt_result(mCtx); + } + if(sign_result != nullptr) { + *sign_result = gpgme_op_sign_result(mCtx); + } + + return err; } } diff --git a/src/gpg/result_analyse/DecryptResultAnalyse.cpp b/src/gpg/result_analyse/DecryptResultAnalyse.cpp new file mode 100644 index 00000000..729d5b59 --- /dev/null +++ b/src/gpg/result_analyse/DecryptResultAnalyse.cpp @@ -0,0 +1,62 @@ +// +// Created by eric on 2021/6/9. +// + +#include "gpg/result_analyse/DecryptResultAnalyse.h" + +DecryptResultAnalyse::DecryptResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_decrypt_result_t result) + : mCtx(ctx) { + + if(result == nullptr) { + return; + } + + stream << "Decrypt Report: " << endl << "-----" << endl; + + if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) { + stream << "Status: Success" << endl; + } else { + stream << "Status" << gpgme_strerror(error) << endl; + if (result->unsupported_algorithm != nullptr) { + stream << "Unsupported algo: " << result->unsupported_algorithm << endl; + } + } + + if (result->file_name != nullptr) { + stream << "File name: " << result->file_name << endl; + } + + stream << endl; + + auto reci = result->recipients; + + if (reci != nullptr) { + stream << "Recipient(s): " << endl; + } + while (reci != nullptr) { + printReci(stream, reci); + reci = reci->next; + } + +} + +bool DecryptResultAnalyse::printReci(QTextStream &stream, gpgme_recipient_t reci) { + bool keyFound = true; + stream << QApplication::tr("Signed By: "); + + try { + auto key = mCtx->getKeyById(reci->keyid); + stream << key.name; + if (!key.email.isEmpty()) { + stream << "<" << key.email << ">"; + } + } catch(std::runtime_error &ignored) { + stream << "<Unknown>"; + setStatus(0); + keyFound = false; + } + stream << endl; + + stream << "Public algo: " << gpgme_pubkey_algo_name(reci->pubkey_algo) << endl; + return keyFound; +} diff --git a/src/gpg/result_analyse/EncryptResultAnalyse.cpp b/src/gpg/result_analyse/EncryptResultAnalyse.cpp new file mode 100644 index 00000000..f41b88a5 --- /dev/null +++ b/src/gpg/result_analyse/EncryptResultAnalyse.cpp @@ -0,0 +1,35 @@ +// +// Created by eric on 2021/6/9. +// + +#include "gpg/result_analyse/EncryptResultAnalyse.h" + +EncryptResultAnalyse::EncryptResultAnalyse(gpgme_error_t error, gpgme_encrypt_result_t result) { + + if(result == nullptr) { + return; + } + + stream << "# Encrypt Report: " << endl << "-----" << endl; + + if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) { + stream << "Status: Encrypt Success" << endl; + } + else { + stream << "Status:" << gpgme_strerror(error) << endl; + stream << "Invalid Recipients: " << endl; + setStatus(0); + auto inv_reci = result->invalid_recipients; + while(inv_reci != nullptr) { + stream << "Fingerprint: " << inv_reci->fpr << endl; + stream << "Reason: " << gpgme_strerror(inv_reci->reason) << endl; + stream << endl; + + inv_reci = inv_reci->next; + } + } + + stream << "-----" << endl; + stream << endl; + +} diff --git a/src/gpg/result_analyse/ResultAnalyse.cpp b/src/gpg/result_analyse/ResultAnalyse.cpp new file mode 100644 index 00000000..960c24cd --- /dev/null +++ b/src/gpg/result_analyse/ResultAnalyse.cpp @@ -0,0 +1,18 @@ +// +// Created by eric on 2021/6/8. +// + +#include "gpg/result_analyse/ResultAnalyse.h" + +const QString &ResultAnalyse::getResultReport() const{ + return resultText; +} + +int ResultAnalyse::getStatus() const { + return status; +} + +void ResultAnalyse::setStatus(int mStatus) { + if(mStatus < status) + status = mStatus; +} diff --git a/src/gpg/result_analyse/SignResultAnalyse.cpp b/src/gpg/result_analyse/SignResultAnalyse.cpp index 51ab5a46..9ef9dfec 100644 --- a/src/gpg/result_analyse/SignResultAnalyse.cpp +++ b/src/gpg/result_analyse/SignResultAnalyse.cpp @@ -24,12 +24,55 @@ #include "gpg/result_analyse/SignResultAnalyse.h" -SignResultAnalyse::SignResultAnalyse(gpgme_sign_result_t result) { - stream << "Sign Report: " << Qt::endl; +SignResultAnalyse::SignResultAnalyse(gpgme_error_t error, gpgme_sign_result_t result) { + + if(result == nullptr) { + return; + } + + stream << "# Sign Report: " << endl + << "-----" << endl; + stream << "Status: " << gpgme_strerror(error) << endl << endl; auto new_sign = result->signatures; while(new_sign != nullptr) { + stream << "> A New Signature: " << endl; + + stream << "Sign mode: "; + if(new_sign->type & GPGME_SIG_MODE_NORMAL) + stream << "Normal"; + else if(new_sign->type & GPGME_SIG_MODE_CLEAR) + stream << "Clear"; + else if(new_sign->type & GPGME_SIG_MODE_DETACH) + stream << "Detach"; + + stream << endl; + + stream << "Public key algo: " << gpgme_pubkey_algo_name(new_sign->pubkey_algo) << endl; + stream << "Hash algo: " << gpgme_hash_algo_name(new_sign->hash_algo) << endl; + stream << "Date of signature: " << QDateTime::fromTime_t(new_sign->timestamp).toString() << endl; + + stream << endl; + new_sign = new_sign->next; } + + auto invalid_signer = result->invalid_signers; + + if(invalid_signer!= nullptr) + stream << "Invalid Signers: " << endl; + + while(invalid_signer != nullptr) { + setStatus(0); + stream << "Fingerprint: " << invalid_signer->fpr << endl; + stream << "Reason: " << gpgme_strerror(invalid_signer->reason) << endl; + stream << endl; + + invalid_signer = invalid_signer->next; + } + + stream << "-----" << endl; + stream << endl; + } diff --git a/src/gpg/result_analyse/VerifyResultAnalyse.cpp b/src/gpg/result_analyse/VerifyResultAnalyse.cpp index 44f4a3af..bb88b7e7 100644 --- a/src/gpg/result_analyse/VerifyResultAnalyse.cpp +++ b/src/gpg/result_analyse/VerifyResultAnalyse.cpp @@ -5,20 +5,28 @@ #include "GpgFrontend.h" #include "gpg/result_analyse/VerifyResultAnalyse.h" -VerifyResultAnalyse::VerifyResultAnalyse(GpgME::GpgContext *ctx, gpgme_signature_t sign) : mCtx(ctx) { +VerifyResultAnalyse::VerifyResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_verify_result_t result) + : mCtx(ctx) { - textSteam << "Verify Report: " << endl; + if(result == nullptr) { + return; + } + + stream << "# Verify Report: " << endl << "-----" << endl; + stream << "Status: " << gpgme_strerror(error) << endl; + + auto sign = result->signatures; if (sign == nullptr){ - textSteam << "> Not Signature Found" << endl; + stream << "> Not Signature Found" << endl; status = -1; return; } - textSteam << "> It was Signed ON " << QDateTime::fromTime_t(sign->timestamp).toString() << endl; + stream << "> It was Signed ON " << QDateTime::fromTime_t(sign->timestamp).toString() << endl; - textSteam << endl << "> It Contains:" << endl; + stream << endl << "> It Contains:" << endl; bool canContinue = true; @@ -26,88 +34,91 @@ VerifyResultAnalyse::VerifyResultAnalyse(GpgME::GpgContext *ctx, gpgme_signature switch (gpg_err_code(sign->status)) { case GPG_ERR_BAD_SIGNATURE: - textSteam << QApplication::tr("One or More Bad Signatures.") << endl; + stream << QApplication::tr("One or More Bad Signatures.") << endl; canContinue = false; setStatus(-1); break; case GPG_ERR_NO_ERROR: - textSteam << QApplication::tr("A "); + stream << QApplication::tr("A "); if(sign->summary & GPGME_SIGSUM_GREEN) { - textSteam << QApplication::tr("Good "); + stream << QApplication::tr("Good "); } if(sign->summary & GPGME_SIGSUM_RED) { - textSteam << QApplication::tr("Bad "); + stream << QApplication::tr("Bad "); } if(sign->summary & GPGME_SIGSUM_SIG_EXPIRED) { - textSteam << QApplication::tr("Expired "); + stream << QApplication::tr("Expired "); } if(sign->summary & GPGME_SIGSUM_KEY_MISSING) { - textSteam << QApplication::tr("Missing Key's "); + stream << QApplication::tr("Missing Key's "); } if(sign->summary & GPGME_SIGSUM_KEY_REVOKED) { - textSteam << QApplication::tr("Revoked Key's "); + stream << QApplication::tr("Revoked Key's "); } if(sign->summary & GPGME_SIGSUM_KEY_EXPIRED) { - textSteam << QApplication::tr("Expired Key's "); + stream << QApplication::tr("Expired Key's "); } if(sign->summary & GPGME_SIGSUM_CRL_MISSING) { - textSteam << QApplication::tr("Missing CRL's "); + stream << QApplication::tr("Missing CRL's "); } if(sign->summary & GPGME_SIGSUM_VALID) { - textSteam << QApplication::tr("Signature Fully Valid.") << endl; + stream << QApplication::tr("Signature Fully Valid.") << endl; } else { - textSteam << QApplication::tr("Signature NOT Fully Valid.") << endl; + stream << QApplication::tr("Signature NOT Fully Valid.") << endl; } if(!(sign->status & GPGME_SIGSUM_KEY_MISSING)) { - if(!printSigner(textSteam, sign)) { + if(!printSigner(stream, sign)) { setStatus(0); } } else { - textSteam << QApplication::tr("Key is NOT present with ID 0x") << QString(sign->fpr) << endl; + stream << QApplication::tr("Key is NOT present with ID 0x") << QString(sign->fpr) << endl; } setStatus(1); break; case GPG_ERR_NO_PUBKEY: - textSteam << QApplication::tr("A signature could NOT be verified due to a Missing Key\n"); + stream << QApplication::tr("A signature could NOT be verified due to a Missing Key\n"); setStatus(-1); break; case GPG_ERR_CERT_REVOKED: - textSteam << QApplication::tr("A signature is valid but the key used to verify the signature has been revoked\n"); - if(!printSigner(textSteam, sign)) { + 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: - textSteam << QApplication::tr("A signature is valid but expired\n"); - if(!printSigner(textSteam, sign)) { + stream << QApplication::tr("A signature is valid but expired\n"); + if(!printSigner(stream, sign)) { setStatus(0); } setStatus(-1); break; case GPG_ERR_KEY_EXPIRED: - textSteam << QApplication::tr("A signature is valid but the key used to verify the signature has expired.\n"); - if(!printSigner(textSteam, sign)) { + 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: - textSteam << QApplication::tr("There was some other error which prevented the signature verification.\n"); + stream << QApplication::tr("There was some other error which prevented the signature verification.\n"); status = -1; canContinue = false; break; default: - textSteam << QApplication::tr("Error for key with fingerprint ") << - GpgME::GpgContext::beautifyFingerprint(QString(sign->fpr)); + stream << QApplication::tr("Error for key with fingerprint ") << + GpgME::GpgContext::beautifyFingerprint(QString(sign->fpr)); setStatus(-1); } - textSteam << endl; + stream << endl; sign = sign->next; } + + stream << "-----" << endl; + stream << endl; } bool VerifyResultAnalyse::printSigner(QTextStream &stream, gpgme_signature_t sign) { @@ -126,17 +137,4 @@ bool VerifyResultAnalyse::printSigner(QTextStream &stream, gpgme_signature_t sig stream << endl; return keyFound; -} - -const QString &VerifyResultAnalyse::getResultReport() const{ - return verifyLabelText; -} - -int VerifyResultAnalyse::getStatus() const { - return status; -} - -void VerifyResultAnalyse::setStatus(int mStatus) { - if(mStatus < status) - status = mStatus; -} +}
\ No newline at end of file diff --git a/src/ui/FileEncryptionDialog.cpp b/src/ui/FileEncryptionDialog.cpp index 813b9278..9cb7b00a 100755 --- a/src/ui/FileEncryptionDialog.cpp +++ b/src/ui/FileEncryptionDialog.cpp @@ -199,19 +199,20 @@ void FileEncryptionDialog::slotExecuteAction() { QByteArray inBuffer = infile.readAll(); auto *outBuffer = new QByteArray(); infile.close(); + + QVector<GpgKey> keys; + mKeyList->getCheckedKeys(keys); + if (mAction == Encrypt) { - if (!mCtx->encrypt(mKeyList->getChecked(), inBuffer, outBuffer)) return; + if (!mCtx->encrypt(keys, inBuffer, outBuffer, nullptr)) return; } if (mAction == Decrypt) { - if (!mCtx->decrypt(inBuffer, outBuffer)) return; + if (!mCtx->decrypt(inBuffer, outBuffer, nullptr)) return; } if (mAction == Sign) { - QVector<GpgKey> keys; - mKeyList->getCheckedKeys(keys); - if (!mCtx->sign(keys, inBuffer, outBuffer, true)) return; - + if (gpgme_err_code(mCtx->sign(keys, inBuffer, outBuffer, true)) != GPG_ERR_NO_ERROR) return; } if (mAction == Verify) { @@ -223,8 +224,9 @@ void FileEncryptionDialog::slotExecuteAction() { return; } auto signBuffer = signfile.readAll(); - gpgme_signature_t sign = mCtx->verify(&inBuffer, &signBuffer); - new VerifyDetailsDialog(this, mCtx, mKeyList, sign); + gpgme_verify_result_t result; + auto error = mCtx->verify(&inBuffer, &signBuffer, &result); + new VerifyDetailsDialog(this, mCtx, mKeyList, error, result); return; } diff --git a/src/ui/VerifyDetailsDialog.cpp b/src/ui/VerifyDetailsDialog.cpp index fe193aa0..9c6ad014 100644 --- a/src/ui/VerifyDetailsDialog.cpp +++ b/src/ui/VerifyDetailsDialog.cpp @@ -24,9 +24,9 @@ #include "ui/VerifyDetailsDialog.h" -VerifyDetailsDialog::VerifyDetailsDialog(QWidget *parent, GpgME::GpgContext *ctx, KeyList *keyList, - gpgme_signature_t signature) : - QDialog(parent), mCtx(ctx), mKeyList(keyList), sign(signature) { +VerifyDetailsDialog::VerifyDetailsDialog(QWidget *parent, GpgME::GpgContext *ctx, KeyList *keyList, gpg_error_t error, + gpgme_verify_result_t result) : + QDialog(parent), mCtx(ctx), mKeyList(keyList), sign(result->signatures), error(error) { this->setWindowTitle(tr("Signature Details")); @@ -50,6 +50,8 @@ void VerifyDetailsDialog::slotRefresh() { buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); + mVboxLayout->addWidget(new QLabel(tr("Status: ") + gpgme_strerror(error))); + if (sign == nullptr) { mVboxLayout->addWidget(new QLabel(tr("No valid input found"))); mVboxLayout->addWidget(buttonBox); |