diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MainWindow.cpp | 123 | ||||
-rw-r--r-- | src/gpg/GpgContext.cpp | 244 | ||||
-rw-r--r-- | src/gpg/result_analyse/DecryptResultAnalyse.cpp | 37 | ||||
-rw-r--r-- | src/gpg/result_analyse/EncryptResultAnalyse.cpp | 24 | ||||
-rw-r--r-- | src/gpg/result_analyse/SignResultAnalyse.cpp | 67 | ||||
-rw-r--r-- | src/gpg/result_analyse/VerifyResultAnalyse.cpp | 198 | ||||
-rwxr-xr-x | src/ui/KeyMgmt.cpp | 7 | ||||
-rw-r--r-- | src/ui/KeyServerImportDialog.cpp | 8 |
8 files changed, 379 insertions, 329 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 3d17b9ad..665ee2ca 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -287,10 +287,10 @@ void MainWindow::createActions() { encryptAct->setToolTip(tr("Encrypt Message")); connect(encryptAct, SIGNAL(triggered()), this, SLOT(slotEncrypt())); - encryptSignAct = new QAction(tr("&Encrypt Sign"), this); + encryptSignAct = new QAction(tr("&Encrypt &Sign"), this); encryptSignAct->setIcon(QIcon(":encrypted_signed.png")); - encryptSignAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E + Qt::Key_S)); - encryptSignAct->setToolTip(tr("Encrypt And Sign Message")); + encryptSignAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_E)); + encryptSignAct->setToolTip(tr("Encrypt and Sign Message")); connect(encryptSignAct, SIGNAL(triggered()), this, SLOT(slotEncryptSign())); decryptAct = new QAction(tr("&Decrypt"), this); @@ -299,6 +299,12 @@ void MainWindow::createActions() { decryptAct->setToolTip(tr("Decrypt Message")); connect(decryptAct, SIGNAL(triggered()), this, SLOT(slotDecrypt())); + decryptVerifyAct = new QAction(tr("&Decrypt &Verify"), this); + decryptVerifyAct->setIcon(QIcon(":decrypted_verified.png")); + decryptVerifyAct->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D)); + decryptVerifyAct->setToolTip(tr("Decrypt and Verify Message")); + connect(decryptVerifyAct, SIGNAL(triggered()), this, SLOT(slotDecryptVerify())); + /* * File encryption submenu */ @@ -485,6 +491,7 @@ void MainWindow::createMenus() { cryptMenu->addAction(encryptAct); cryptMenu->addAction(encryptSignAct); cryptMenu->addAction(decryptAct); + cryptMenu->addAction(decryptVerifyAct); cryptMenu->addSeparator(); cryptMenu->addAction(signAct); cryptMenu->addAction(verifyAct); @@ -537,6 +544,7 @@ void MainWindow::createToolBars() { cryptToolBar->addAction(encryptAct); cryptToolBar->addAction(encryptSignAct); cryptToolBar->addAction(decryptAct); + cryptToolBar->addAction(decryptVerifyAct); cryptToolBar->addAction(signAct); cryptToolBar->addAction(verifyAct); //cryptToolBar->addAction(fileEncryptionAct); @@ -695,42 +703,6 @@ void MainWindow::slotStartWizard() { wizard->setModal(true); } -/* - * if this is mime, split text and attachments... - * message contains only text afterwards - */ -void MainWindow::parseMime(QByteArray *message) { - /*if (! Mime::isMultipart(message)) { - qDebug() << "no multipart"; - return; - }*/ - //qDebug() << "multipart"; - - QString pText; - bool showmadock = false; - - Mime *mime = new Mime(message); - foreach(MimePart tmp, mime->parts()) { - if (tmp.header.getValue("Content-Type") == "text/plain" - && tmp.header.getValue("Content-Transfer-Encoding") != "base64") { - - QByteArray body; - if (tmp.header.getValue("Content-Transfer-Encoding") == "quoted-printable") { - Mime::quotedPrintableDecode(tmp.body, body); - } else { - body = tmp.body; - } - pText.append(QString(body)); - } else { - (mAttachments->addMimePart(&tmp)); - showmadock = true; - } - } - *message = pText.toUtf8(); - if (showmadock) { - attachmentDock->show(); - } -} void MainWindow::slotCheckAttachmentFolder() { // TODO: always check? @@ -811,6 +783,8 @@ void MainWindow::slotEncrypt() { infoBoard->slotRefresh(reportText, INFO_ERROR_OK); else infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + delete resultAnalyse; } void MainWindow::slotSign() { @@ -854,6 +828,8 @@ void MainWindow::slotSign() { infoBoard->slotRefresh(reportText, INFO_ERROR_OK); else infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + delete resultAnalyse; } void MainWindow::slotDecrypt() { @@ -870,28 +846,8 @@ void MainWindow::slotDecrypt() { auto error = mCtx->decrypt(text, decrypted, &result); infoBoard->associateTextEdit(edit->curTextPage()); - /* - * 1) is it mime (content-type:) - * 2) parse header - * 2) choose action depending on content-type - */ - if (Mime::isMime(decrypted)) { - Header header = Mime::getHeader(decrypted); - // is it multipart, is multipart-parsing enabled - if (header.getValue("Content-Type") == "multipart/mixed" - && settings.value("mime/parseMime").toBool()) { - parseMime(decrypted); - } else if (header.getValue("Content-Type") == "text/plain" - && settings.value("mime/parseQP").toBool()) { - if (header.getValue("Content-Transfer-Encoding") == "quoted-printable") { - auto *decoded = new QByteArray(); - Mime::quotedPrintableDecode(*decrypted, *decoded); - //TODO: remove header - decrypted = decoded; - } - } - } - edit->slotFillTextEditWithText(QString::fromUtf8(*decrypted)); + if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) + edit->slotFillTextEditWithText(QString::fromUtf8(*decrypted)); auto resultAnalyse = new DecryptResultAnalyse(mCtx, error, result); @@ -902,6 +858,8 @@ void MainWindow::slotDecrypt() { infoBoard->slotRefresh(reportText, INFO_ERROR_OK); else infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + + delete resultAnalyse; } void MainWindow::slotFind() { @@ -950,6 +908,7 @@ void MainWindow::slotVerify() { }); } + delete resultAnalyse; } /* @@ -1171,5 +1130,47 @@ void MainWindow::slotEncryptSign() { else infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + delete resultAnalyseEncr; + delete resultAnalyseSign; +} +void MainWindow::slotDecryptVerify() { + + if (edit->tabCount() == 0 || edit->slotCurPage() == nullptr) { + return; + } + + auto *decrypted = new QByteArray(); + QByteArray text = edit->curTextPage()->toPlainText().toUtf8(); + GpgME::GpgContext::preventNoDataErr(&text); + + gpgme_decrypt_result_t d_result = nullptr; + gpgme_verify_result_t v_result = nullptr; + // try decrypt, if fail do nothing, especially don't replace text + auto error = mCtx->decryptVerify(text, decrypted, &d_result, &v_result); + infoBoard->associateTextEdit(edit->curTextPage()); + + if(gpgme_err_code(error) == GPG_ERR_NO_ERROR) + edit->slotFillTextEditWithText(QString::fromUtf8(*decrypted)); + + auto resultAnalyseDecrypt = new DecryptResultAnalyse(mCtx, error, d_result); + auto resultAnalyseVerify = new VerifyResultAnalyse(mCtx, error, v_result); + + int status = std::min(resultAnalyseDecrypt->getStatus(), resultAnalyseVerify->getStatus()); + auto &reportText = resultAnalyseDecrypt->getResultReport() + resultAnalyseVerify->getResultReport(); + 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); + + if (resultAnalyseVerify->getStatus() >= 0) { + infoBoard->resetOptionActionsMenu(); + infoBoard->addOptionalAction("Show Verify Details", [this, error, v_result]() { + VerifyDetailsDialog(this, mCtx, mKeyList, error, v_result); + }); + } + delete resultAnalyseDecrypt; + delete resultAnalyseVerify; } diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index bd1aa013..a6be9c3c 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -26,6 +26,7 @@ #include "ui/keygen/KeygenThread.h" #include <unistd.h> /* contains read/write */ +#include <Mime.h> #ifdef _WIN32 #include <windows.h> @@ -381,7 +382,7 @@ namespace GpgME { gpgme_key_t recipients[keys.count() + 1]; int index = 0; - for(const auto& key : keys) { + for (const auto &key : keys) { recipients[index++] = key.key_refer; } @@ -412,12 +413,43 @@ namespace GpgME { gpgme_data_release(dataOut); } - if(result != nullptr) { + if (result != nullptr) { *result = gpgme_op_encrypt_result(mCtx); } return err; } + + /** + * if this is mime, split text and attachments... + * message contains only text afterwards + */ + void parseMime(QByteArray *message) { + + QString pText; + bool show_ma_dock = false; + + Mime *mime = new Mime(message); + for(MimePart tmp : mime->parts()) { + if (tmp.header.getValue("Content-Type") == "text/plain" && tmp.header.getValue("Content-Transfer-Encoding") != "base64") { + QByteArray body; + if (tmp.header.getValue("Content-Transfer-Encoding") == "quoted-printable") { + Mime::quotedPrintableDecode(tmp.body, body); + } else { + body = tmp.body; + } + pText.append(QString(body)); + } else { + // TODO + show_ma_dock = true; + } + } + *message = pText.toUtf8(); + if (show_ma_dock) { + // TODO + } + } + /** Decrypt QByteAarray, return QByteArray * mainly from http://basket.kde.org/ (kgpgme.cpp) */ @@ -425,47 +457,21 @@ namespace GpgME { GpgContext::decrypt(const QByteArray &inBuffer, QByteArray *outBuffer, gpgme_decrypt_result_t *result) { gpgme_data_t dataIn = nullptr, dataOut = nullptr; gpgme_decrypt_result_t m_result = nullptr; - QString errorString; outBuffer->resize(0); - if (mCtx) { + if (mCtx != nullptr) { err = gpgme_data_new_from_mem(&dataIn, inBuffer.data(), inBuffer.size(), 1); - checkErr(err); - if (!err) { + if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { err = gpgme_data_new(&dataOut); - checkErr(err); - if (!err) { + if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { err = gpgme_op_decrypt(mCtx, dataIn, dataOut); - checkErr(err); - - if (gpg_err_code(err) == GPG_ERR_DECRYPT_FAILED) { - errorString.append(gpgErrString(err)).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( - m_result->recipients->keyid)); - } else { - errorString.append(gpgErrString(err)).append("<br>"); - } - - if (!err) { - 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); - } + m_result = gpgme_op_decrypt_result(mCtx); + if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { + err = readToBuffer(dataOut, outBuffer); } } } } - if (gpg_err_code(err) != GPG_ERR_NO_ERROR && gpg_err_code(err) != GPG_ERR_CANCELED) { - QMessageBox::critical(nullptr, tr("Error decrypting:"), errorString); - return false; - } if (!settings.value("general/rememberPassword").toBool()) { clearPasswordCache(); @@ -478,7 +484,29 @@ namespace GpgME { gpgme_data_release(dataOut); } - if(result != nullptr) { + /* + * 1) is it mime (content-type:) + * 2) parse header + * 2) choose action depending on content-type + */ + if (Mime::isMime(outBuffer)) { + Header header = Mime::getHeader(outBuffer); + // is it multipart, is multipart-parsing enabled + if (header.getValue("Content-Type") == "multipart/mixed" + && settings.value("mime/parseMime").toBool()) { + parseMime(outBuffer); + } else if (header.getValue("Content-Type") == "text/plain" + && settings.value("mime/parseQP").toBool()) { + if (header.getValue("Content-Transfer-Encoding") == "quoted-printable") { + auto *decoded = new QByteArray(); + Mime::quotedPrintableDecode(*outBuffer, *decoded); + //TODO: remove header + outBuffer = decoded; + } + } + } + + if (result != nullptr) { *result = m_result; } return err; @@ -682,7 +710,7 @@ namespace GpgME { m_result = gpgme_op_verify_result(mCtx); - if(result != nullptr) { + if (result != nullptr) { *result = m_result; } @@ -709,7 +737,9 @@ namespace GpgME { verify_result = gpgme_op_verify_result (mCtx); */ //} - gpg_error_t GpgContext::sign(const QVector<GpgKey>& keys, const QByteArray &inBuffer, QByteArray *outBuffer, bool detached, gpgme_sign_result_t *result) { + 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; @@ -763,7 +793,7 @@ namespace GpgME { m_result = gpgme_op_sign_result(mCtx); - if(result != nullptr) { + if (result != nullptr) { *result = m_result; } @@ -835,8 +865,8 @@ namespace GpgME { if (key.fpr == fpr) { return key; } else { - for(auto &subkey : key.subKeys) { - if(subkey.fpr == fpr) { + for (auto &subkey : key.subKeys) { + if (subkey.fpr == fpr) { return key; } } @@ -848,9 +878,9 @@ namespace GpgME { /** * note: is_private_key status is not returned */ - const GpgKey & GpgContext::getKeyById(const QString &id) { + const GpgKey &GpgContext::getKeyById(const QString &id) { - for(const auto &key : mKeyList) { + for (const auto &key : mKeyList) { if (key.id == id) { return key; } else { @@ -884,7 +914,7 @@ namespace GpgME { auto gpgmeError = gpgme_op_keysign(mCtx, target.key_refer, uid.toUtf8().constData(), expires_time_t, flags); - if(gpgmeError == GPG_ERR_NO_ERROR) { + if (gpgmeError == GPG_ERR_NO_ERROR) { emit signalKeyUpdated(target.id); return true; } else { @@ -923,22 +953,22 @@ namespace GpgME { } } - void GpgContext::slotUpdateKeyList(QString key_id) { + void GpgContext::slotUpdateKeyList(const QString &key_id) { auto it = mKeyMap.find(key_id); if (it != mKeyMap.end()) { gpgme_key_t new_key_refer; auto gpgmeErr = gpgme_get_key(mCtx, key_id.toUtf8().constData(), &new_key_refer, 0); - if(gpgme_err_code(gpgmeErr) == GPG_ERR_EOF) { + if (gpgme_err_code(gpgmeErr) == GPG_ERR_EOF) { gpgmeErr = gpgme_get_key(mCtx, key_id.toUtf8().constData(), &new_key_refer, 1); - if(gpgme_err_code(gpgmeErr) == GPG_ERR_EOF) { + if (gpgme_err_code(gpgmeErr) == GPG_ERR_EOF) { throw std::runtime_error("key_id not found in key database"); } } - if(new_key_refer != nullptr) { + if (new_key_refer != nullptr) { it.value()->swapKeyRefer(new_key_refer); emit signalKeyInfoChanged(); } @@ -949,11 +979,10 @@ namespace GpgME { bool GpgContext::addUID(const GpgKey &key, const GpgUID &uid) { QString userid = QString("%1 (%3) <%2>").arg(uid.name, uid.email, uid.comment); auto gpgmeError = gpgme_op_adduid(mCtx, key.key_refer, userid.toUtf8().constData(), 0); - if(gpgmeError == GPG_ERR_NO_ERROR) { + if (gpgmeError == GPG_ERR_NO_ERROR) { emit signalKeyUpdated(key.id); return true; - } - else { + } else { checkErr(gpgmeError); return false; } @@ -962,11 +991,10 @@ namespace GpgME { bool GpgContext::revUID(const GpgKey &key, const GpgUID &uid) { auto gpgmeError = gpgme_op_revuid(mCtx, key.key_refer, uid.uid.toUtf8().constData(), 0); - if(gpgmeError == GPG_ERR_NO_ERROR) { + if (gpgmeError == GPG_ERR_NO_ERROR) { emit signalKeyUpdated(key.id); return true; - } - else { + } else { checkErr(gpgmeError); return false; } @@ -975,11 +1003,10 @@ namespace GpgME { bool GpgContext::setPrimaryUID(const GpgKey &key, const GpgUID &uid) { auto gpgmeError = gpgme_op_set_uid_flag(mCtx, key.key_refer, uid.uid.toUtf8().constData(), "primary", nullptr); - if(gpgmeError == GPG_ERR_NO_ERROR) { + if (gpgmeError == GPG_ERR_NO_ERROR) { emit signalKeyUpdated(key.id); return true; - } - else { + } else { checkErr(gpgmeError); return false; } @@ -990,13 +1017,12 @@ namespace GpgME { auto signing_key = getKeyById(signature.keyid); auto gpgmeError = gpgme_op_revsig(mCtx, key.key_refer, - signing_key.key_refer, - signature.uid.toUtf8().constData(), 0); - if(gpg_err_code(gpgmeError) == GPG_ERR_NO_ERROR) { + signing_key.key_refer, + signature.uid.toUtf8().constData(), 0); + if (gpg_err_code(gpgmeError) == GPG_ERR_NO_ERROR) { emit signalKeyUpdated(key.id); return true; - } - else { + } else { checkErr(gpgmeError); return false; } @@ -1004,7 +1030,7 @@ namespace GpgME { bool GpgContext::generateSubkey(const GpgKey &key, GenKeyInfo *params) { - if(!params->isSubKey()) { + if (!params->isSubKey()) { return false; } @@ -1038,11 +1064,10 @@ namespace GpgME { auto gpgmeError = gpgme_op_createsubkey(mCtx, key.key_refer, algo, 0, expires, flags); - if(gpgmeError == GPG_ERR_NO_ERROR) { + if (gpgmeError == GPG_ERR_NO_ERROR) { emit signalKeyUpdated(key.id); return true; - } - else { + } else { checkErr(gpgmeError); return false; } @@ -1050,33 +1075,33 @@ namespace GpgME { bool GpgContext::setExpire(const GpgKey &key, const GpgSubKey *subkey, QDateTime *expires) { unsigned long expires_time = 0; - if(expires != nullptr) { + if (expires != nullptr) { qDebug() << "Expire Datetime" << expires->toString(); expires_time = QDateTime::currentDateTime().secsTo(*expires); } const char *subfprs = nullptr; - if(subkey != nullptr) { + if (subkey != nullptr) { subfprs = subkey->fpr.toUtf8().constData(); } auto gpgmeError = gpgme_op_setexpire(mCtx, key.key_refer, expires_time, subfprs, 0); - if(gpgmeError == GPG_ERR_NO_ERROR) { + if (gpgmeError == GPG_ERR_NO_ERROR) { emit signalKeyUpdated(key.id); return true; - } - else { + } else { checkErr(gpgmeError); return false; } } bool GpgContext::checkIfKeyCanSign(const GpgKey &key) { - if(std::any_of(key.subKeys.begin(), key.subKeys.end(), [] (const GpgSubKey &subkey) -> bool { + if (std::any_of(key.subKeys.begin(), key.subKeys.end(), [](const GpgSubKey &subkey) -> bool { return subkey.secret && subkey.can_sign && !subkey.disabled && !subkey.revoked && !subkey.expired; - })) return true; + })) + return true; return false; } @@ -1085,16 +1110,18 @@ namespace GpgME { } bool GpgContext::checkIfKeyCanAuth(const GpgKey &key) { - if(std::any_of(key.subKeys.begin(), key.subKeys.end(), [] (const GpgSubKey &subkey) -> bool { + if (std::any_of(key.subKeys.begin(), key.subKeys.end(), [](const GpgSubKey &subkey) -> bool { return subkey.secret && subkey.can_authenticate && !subkey.disabled && !subkey.revoked && !subkey.expired; - })) return true; + })) + return true; return false; } bool GpgContext::checkIfKeyCanEncr(const GpgKey &key) { - if(std::any_of(key.subKeys.begin(), key.subKeys.end(), [] (const GpgSubKey &subkey) -> bool { + if (std::any_of(key.subKeys.begin(), key.subKeys.end(), [](const GpgSubKey &subkey) -> bool { return subkey.can_encrypt && !subkey.disabled && !subkey.revoked && !subkey.expired; - })) return true; + })) + return true; return false; } @@ -1103,11 +1130,6 @@ namespace GpgME { gpgme_data_t dataIn = nullptr, dataOut = nullptr; outBuffer->resize(0); - if (keys.count() == 0) { - QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected")); - return false; - } - setSigners(keys); //gpgme_encrypt_result_t e_result; @@ -1115,25 +1137,25 @@ namespace GpgME { /* set key for user */ int index = 0; - for(const auto &key : keys) { + for (const auto &key : keys) { recipients[index++] = key.key_refer; } //Last entry dataIn array has to be nullptr recipients[keys.count()] = nullptr; //If the last parameter isnt 0, a private copy of data is made - if (mCtx) { + if (mCtx != nullptr) { err = gpgme_data_new_from_mem(&dataIn, inBuffer.data(), inBuffer.size(), 1); - checkErr(err); - if (!err) { + if (gpg_err_code(err) == GPG_ERR_NO_ERROR) { err = gpgme_data_new(&dataOut); - checkErr(err); - if (!err) { + if (gpg_err_code(err) == GPG_ERR_NO_ERROR) { err = gpgme_op_encrypt_sign(mCtx, recipients, GPGME_ENCRYPT_ALWAYS_TRUST, dataIn, dataOut); - checkErr(err); - if (!err) { + if (encr_result != nullptr) + *encr_result = gpgme_op_encrypt_result(mCtx); + if (sign_result != nullptr) + *sign_result = gpgme_op_sign_result(mCtx); + if (gpg_err_code(err) == GPG_ERR_NO_ERROR) { err = readToBuffer(dataOut, outBuffer); - checkErr(err); } } } @@ -1145,19 +1167,43 @@ namespace GpgME { gpgme_data_release(dataOut); } - if(encr_result != nullptr) { - *encr_result = gpgme_op_encrypt_result(mCtx); - } - if(sign_result != nullptr) { - *sign_result = gpgme_op_sign_result(mCtx); - } - return err; } -} - + gpgme_error_t + GpgContext::decryptVerify(const QByteArray &inBuffer, QByteArray *outBuffer, gpgme_decrypt_result_t *decrypt_result, + gpgme_verify_result_t *verify_result) { + gpgme_data_t dataIn = nullptr, dataOut = nullptr; + outBuffer->resize(0); + if (mCtx != nullptr) { + err = gpgme_data_new_from_mem(&dataIn, inBuffer.data(), inBuffer.size(), 1); + if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { + err = gpgme_data_new(&dataOut); + if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { + err = gpgme_op_decrypt_verify(mCtx, dataIn, dataOut); + if (decrypt_result != nullptr) + *decrypt_result = gpgme_op_decrypt_result(mCtx); + if (verify_result != nullptr) + *verify_result = gpgme_op_verify_result(mCtx); + if (gpgme_err_code(err) == GPG_ERR_NO_ERROR) { + err = readToBuffer(dataOut, outBuffer); + } + } + } + } + if (!settings.value("general/rememberPassword").toBool()) { + clearPasswordCache(); + } + if (dataIn) { + gpgme_data_release(dataIn); + } + if (dataOut) { + gpgme_data_release(dataOut); + } + return err; + } +}
\ No newline at end of file diff --git a/src/gpg/result_analyse/DecryptResultAnalyse.cpp b/src/gpg/result_analyse/DecryptResultAnalyse.cpp index 79c6bc51..d0f3ae99 100644 --- a/src/gpg/result_analyse/DecryptResultAnalyse.cpp +++ b/src/gpg/result_analyse/DecryptResultAnalyse.cpp @@ -7,36 +7,33 @@ 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) { + setStatus(-1); + stream << "Status: " << gpgme_strerror(error) << endl; + + if (result != nullptr && result->unsupported_algorithm != nullptr) stream << "Unsupported algo: " << result->unsupported_algorithm << endl; - } } - if (result->file_name != nullptr) { - stream << "File name: " << result->file_name << endl; + if(result != nullptr) { + 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; + } } - stream << endl; - - auto reci = result->recipients; - - if (reci != nullptr) { - stream << "Recipient(s): " << endl; - } - while (reci != nullptr) { - printReci(stream, reci); - reci = reci->next; - } + stream << "-----" << endl << endl; } diff --git a/src/gpg/result_analyse/EncryptResultAnalyse.cpp b/src/gpg/result_analyse/EncryptResultAnalyse.cpp index f41b88a5..8cdd7750 100644 --- a/src/gpg/result_analyse/EncryptResultAnalyse.cpp +++ b/src/gpg/result_analyse/EncryptResultAnalyse.cpp @@ -6,10 +6,6 @@ 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) { @@ -17,15 +13,17 @@ EncryptResultAnalyse::EncryptResultAnalyse(gpgme_error_t error, gpgme_encrypt_re } 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; + setStatus(-1); + if (result != nullptr) { + stream << "Invalid Recipients: " << endl; + 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; + } } } diff --git a/src/gpg/result_analyse/SignResultAnalyse.cpp b/src/gpg/result_analyse/SignResultAnalyse.cpp index eda95ff1..15d6ddf5 100644 --- a/src/gpg/result_analyse/SignResultAnalyse.cpp +++ b/src/gpg/result_analyse/SignResultAnalyse.cpp @@ -26,53 +26,56 @@ 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; + if(gpg_err_code(error) != GPG_ERR_NO_ERROR) { + setStatus(-1); + } - while(new_sign != nullptr) { - stream << "> A New Signature: " << endl; + if(result != nullptr) { - 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"; + auto new_sign = result->signatures; - stream << endl; + while (new_sign != nullptr) { + stream << "> A New Signature: " << 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 << "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 << endl; - new_sign = new_sign->next; - } + 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; - auto invalid_signer = result->invalid_signers; + if (invalid_signer != nullptr) + stream << "Invalid Signers: " << endl; - 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; - 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; + } - invalid_signer = invalid_signer->next; } - stream << "-----" << endl; - stream << endl; + stream << "-----" << endl << endl; } diff --git a/src/gpg/result_analyse/VerifyResultAnalyse.cpp b/src/gpg/result_analyse/VerifyResultAnalyse.cpp index bb88b7e7..898d62e1 100644 --- a/src/gpg/result_analyse/VerifyResultAnalyse.cpp +++ b/src/gpg/result_analyse/VerifyResultAnalyse.cpp @@ -8,113 +8,115 @@ VerifyResultAnalyse::VerifyResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error, gpgme_verify_result_t result) : mCtx(ctx) { - if(result == nullptr) { - return; - } - stream << "# Verify Report: " << endl << "-----" << endl; stream << "Status: " << gpgme_strerror(error) << endl; - auto sign = result->signatures; + if(result != nullptr) { - if (sign == nullptr){ - stream << "> Not Signature Found" << endl; - status = -1; - return; - } + auto sign = result->signatures; + + if (sign == nullptr) { + stream << "> Not Signature Found" << endl; + setStatus(-1); + return; + } + + + stream << "> It was Signed ON " << QDateTime::fromTime_t(sign->timestamp).toString() << endl; + stream << endl << "> It Contains:" << endl; - stream << "> It was Signed ON " << QDateTime::fromTime_t(sign->timestamp).toString() << endl; - - stream << endl << "> It Contains:" << 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.") << 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.") << endl; - } else { - stream << QApplication::tr("Signature NOT Fully Valid.") << endl; - } - - if(!(sign->status & GPGME_SIGSUM_KEY_MISSING)) { - if(!printSigner(stream, sign)) { + 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.") << 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.") << endl; + } else { + stream << QApplication::tr("Signature NOT Fully Valid.") << 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) << 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); } - } else { - stream << QApplication::tr("Key is NOT present with ID 0x") << QString(sign->fpr) << 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); + 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 << endl; + sign = sign->next; } - stream << endl; - sign = sign->next; } stream << "-----" << endl; diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp index e32a1092..76c98601 100755 --- a/src/ui/KeyMgmt.cpp +++ b/src/ui/KeyMgmt.cpp @@ -119,7 +119,7 @@ void KeyMgmt::createActions() deleteCheckedKeysAct = new QAction(tr("Delete Checked Key(s)"), this); deleteCheckedKeysAct->setToolTip(tr("Delete the Checked keys")); - deleteCheckedKeysAct->setIcon(QIcon(":button_cancel.png")); + deleteCheckedKeysAct->setIcon(QIcon(":button_delete.png")); connect(deleteCheckedKeysAct, SIGNAL(triggered()), this, SLOT(slotDeleteCheckedKeys())); showKeyDetailsAct = new QAction(tr("Show Keydetails"), this); @@ -269,6 +269,7 @@ void KeyMgmt::slotExportKeyToFile() { auto *keyArray = new QByteArray(); if (!mCtx->exportKeys(mKeyList->getChecked(), keyArray)) { + delete keyArray; return; } auto &key = mCtx->getKeyById(mKeyList->getSelected()->first()); @@ -276,8 +277,10 @@ void KeyMgmt::slotExportKeyToFile() QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), fileString, tr("Key Files") + " (*.asc *.txt);;All Files (*)"); QFile file(fileName); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + delete keyArray; return; + } QTextStream stream(&file); stream << *keyArray; file.close(); diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp index a0775acc..789e194d 100644 --- a/src/ui/KeyServerImportDialog.cpp +++ b/src/ui/KeyServerImportDialog.cpp @@ -132,7 +132,7 @@ void KeyServerImportDialog::setMessage(const QString &text, bool error) { } void KeyServerImportDialog::slotSearch() { - QUrl urlFromRemote = keyServerComboBox->currentText() + ":11371/pks/lookup?search=" + searchLineEdit->text() + + QUrl urlFromRemote = keyServerComboBox->currentText() + "/pks/lookup?search=" + searchLineEdit->text() + "&op=index&options=mr"; qnam = new QNetworkAccessManager(this); QNetworkReply *reply = qnam->get(QNetworkRequest(urlFromRemote)); @@ -175,10 +175,10 @@ void KeyServerImportDialog::slotSearchFinished() { } } else { int row = 0; - char buff[1024]; bool strikeout = false; - while (reply->readLine(buff, sizeof(buff)) != -1) { - QString decoded = QString::fromUtf8(QByteArray::fromPercentEncoding(buff)); + while (reply->canReadLine()) { + auto line_buff = reply->readLine().trimmed(); + QString decoded = QString::fromUtf8(line_buff.constData(), line_buff.size()); QStringList line = decoded.split(":"); //TODO: have a look at two following pub lines |