diff options
Diffstat (limited to '')
-rw-r--r-- | include/gpg/GpgContext.h | 3 | ||||
-rw-r--r-- | include/server/BaseAPI.h | 6 | ||||
-rw-r--r-- | src/gpg/gpg_context/GpgContextBasicOpera.cpp | 17 | ||||
-rw-r--r-- | src/gpg/result_analyse/SignResultAnalyse.cpp | 4 | ||||
-rw-r--r-- | src/server/ComUtils.cpp | 2 | ||||
-rw-r--r-- | src/server/api/PubkeyUploader.cpp | 5 | ||||
-rwxr-xr-x | src/ui/FileEncryptionDialog.cpp | 2 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowServerSlotFunction.cpp | 17 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 40 | ||||
-rw-r--r-- | src/ui/settings/SettingsGeneral.cpp | 3 |
10 files changed, 51 insertions, 48 deletions
diff --git a/include/gpg/GpgContext.h b/include/gpg/GpgContext.h index e6e81626..75949f25 100644 --- a/include/gpg/GpgContext.h +++ b/include/gpg/GpgContext.h @@ -122,8 +122,7 @@ namespace GpgME { gpg_error_t sign(const QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, - gpgme_sig_mode_t mode = GPGME_SIG_MODE_NORMAL, - gpgme_sign_result_t *result = nullptr); + gpgme_sig_mode_t mode, gpgme_sign_result_t *result = nullptr, bool default_ctx = true); bool addUID(const GpgKey &key, const GpgUID &uid); diff --git a/include/server/BaseAPI.h b/include/server/BaseAPI.h index 4843413d..36836d81 100644 --- a/include/server/BaseAPI.h +++ b/include/server/BaseAPI.h @@ -30,7 +30,7 @@ #include "rapidjson/document.h" -class BaseAPI : QObject { +class BaseAPI : public QObject { Q_OBJECT public: @@ -52,12 +52,12 @@ private: QNetworkRequest request; - bool good = false; - QNetworkReply *send_json_data(); protected: + bool good = false; + rapidjson::Document document; const ComUtils &getUtils() { return *utils; }; diff --git a/src/gpg/gpg_context/GpgContextBasicOpera.cpp b/src/gpg/gpg_context/GpgContextBasicOpera.cpp index 8872acfe..d9bf0bdb 100644 --- a/src/gpg/gpg_context/GpgContextBasicOpera.cpp +++ b/src/gpg/gpg_context/GpgContextBasicOpera.cpp @@ -154,19 +154,24 @@ gpgme_error_t GpgME::GpgContext::verify(QByteArray *inBuffer, QByteArray *sigBuf * @return */ gpg_error_t GpgME::GpgContext::sign(const QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer, - gpgme_sig_mode_t mode, gpgme_sign_result_t *result) { + gpgme_sig_mode_t mode, gpgme_sign_result_t *result, bool default_ctx) { gpgme_error_t gpgmeError; gpgme_data_t dataIn, dataOut; gpgme_sign_result_t m_result; + auto _ctx = mCtx; + + if(!default_ctx) + _ctx = create_ctx(); + if (keys.isEmpty()) { QMessageBox::critical(nullptr, tr("Key Selection"), tr("No Private Key Selected")); return false; } // Set Singers of this opera - setSigners(keys, mCtx); + setSigners(keys, _ctx); gpgmeError = gpgme_data_new_from_mem(&dataIn, inBuffer.data(), inBuffer.size(), 1); checkErr(gpgmeError); @@ -186,7 +191,7 @@ gpg_error_t GpgME::GpgContext::sign(const QVector<GpgKey> &keys, const QByteArra mode settings of the context are ignored. */ - gpgmeError = gpgme_op_sign(mCtx, dataIn, dataOut, mode); + gpgmeError = gpgme_op_sign(_ctx, dataIn, dataOut, mode); checkErr(gpgmeError); if (gpgmeError == GPG_ERR_CANCELED) return false; @@ -196,10 +201,14 @@ gpg_error_t GpgME::GpgContext::sign(const QVector<GpgKey> &keys, const QByteArra return false; } - m_result = gpgme_op_sign_result(mCtx); + if(default_ctx) + m_result = gpgme_op_sign_result(_ctx); + else m_result = nullptr; if (result != nullptr) *result = m_result; + if(!default_ctx) gpgme_release(_ctx); + gpgmeError = readToBuffer(dataOut, outBuffer); checkErr(gpgmeError); diff --git a/src/gpg/result_analyse/SignResultAnalyse.cpp b/src/gpg/result_analyse/SignResultAnalyse.cpp index bac16021..10d76678 100644 --- a/src/gpg/result_analyse/SignResultAnalyse.cpp +++ b/src/gpg/result_analyse/SignResultAnalyse.cpp @@ -38,6 +38,8 @@ SignResultAnalyse::SignResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error } if (result != nullptr && (result->signatures != nullptr || result->invalid_signers != nullptr)) { + + qDebug() << "Sign Result Analyse Getting Result"; stream << "------------>" << Qt::endl; auto new_sign = result->signatures; @@ -71,6 +73,8 @@ SignResultAnalyse::SignResultAnalyse(GpgME::GpgContext *ctx, gpgme_error_t error new_sign = new_sign->next; } + qDebug() << "Sign Result Analyse Getting Invalid Signer"; + auto invalid_signer = result->invalid_signers; if (invalid_signer != nullptr) diff --git a/src/server/ComUtils.cpp b/src/server/ComUtils.cpp index 6fce493f..01be4ea7 100644 --- a/src/server/ComUtils.cpp +++ b/src/server/ComUtils.cpp @@ -164,7 +164,7 @@ QByteArray ComUtils::getSignStringBase64(GpgME::GpgContext *ctx, const QString & // The use of multi-threading brings an improvement in UI smoothness gpgme_error_t error; auto thread = QThread::create([&]() { - error = ctx->sign(keys, signData, &outSignText, GPGME_SIG_MODE_NORMAL); + error = ctx->sign(keys, signData, &outSignText, GPGME_SIG_MODE_NORMAL, nullptr, false); }); thread->start(); while (thread->isRunning()) QApplication::processEvents(); diff --git a/src/server/api/PubkeyUploader.cpp b/src/server/api/PubkeyUploader.cpp index e1c62aeb..c6101c65 100644 --- a/src/server/api/PubkeyUploader.cpp +++ b/src/server/api/PubkeyUploader.cpp @@ -98,10 +98,9 @@ void PubkeyUploader::deal_reply() { auto &strings = utils.getDataValue("strings"); qDebug() << "Pubkey Uploader" << strings.IsArray() << strings.GetArray().Size(); if (strings.IsArray() && strings.GetArray().Size() == mKeys.size()) { - + good = true; } else { - QMessageBox::warning(nullptr, tr("Warning"), - tr("Partial failure of automatic pubkey exchange")); + good = false; } } } diff --git a/src/ui/FileEncryptionDialog.cpp b/src/ui/FileEncryptionDialog.cpp index d9bc7ce2..23ec0b2a 100755 --- a/src/ui/FileEncryptionDialog.cpp +++ b/src/ui/FileEncryptionDialog.cpp @@ -229,7 +229,7 @@ void FileEncryptionDialog::slotExecuteAction() { if (mAction == Sign) { qDebug() << "Action Sign"; - gpgme_error_t err = mCtx->sign(keys, inBuffer, outBuffer, GPGME_SIG_MODE_DETACH); + gpgme_error_t err = mCtx->sign(keys, inBuffer, outBuffer, GPGME_SIG_MODE_DETACH, nullptr); if (gpgme_err_code(err) != GPG_ERR_NO_ERROR) { qDebug() << "Error" << gpgme_strerror(err); QMessageBox::warning(this, tr("Error"), diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index 011cfd28..13dc6af3 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -40,7 +40,9 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { GpgKey key = mCtx->getKeyById(ownKeyId); if (!key.good) { - QMessageBox::critical(this, tr("Invalid Own Key"), tr("Own Key can not be use to do any operation.")); + QMessageBox::critical(this, tr("Invalid Own Key"), + tr("Own Key can not be use to do any operation. " + "Please go to the setting interface to select an OwnKey and get a ServiceToken.")); return {}; } @@ -58,10 +60,7 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); // Sign Shorten Text - QVector<GpgKey> keys{key}; - QByteArray outSignText; - mCtx->sign(keys, shortenCryptoText.toUtf8(), &outSignText, GPGME_SIG_MODE_NORMAL); - auto outSignTextBase64 = outSignText.toBase64(); + auto outSignTextBase64 = ComUtils::getSignStringBase64(mCtx, shortenCryptoText, key); rapidjson::Document doc; doc.SetObject(); @@ -74,7 +73,7 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { const auto t_byte_array = serviceToken.toUtf8(); t.SetString(t_byte_array.constData(), t_byte_array.count()); - rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); + rapidjson::Document::AllocatorType &allocator = doc.GetAllocator(); doc.AddMember("signature", s, allocator); doc.AddMember("serviceToken", t, allocator); @@ -184,7 +183,7 @@ void MainWindow::shortenCryptText() { auto t_byte_array = serviceToken.toUtf8(); t.SetString(t_byte_array.constData(), t_byte_array.count()); - rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); + rapidjson::Document::AllocatorType &allocator = doc.GetAllocator(); doc.AddMember("cryptoText", c, allocator); doc.AddMember("sha", m, allocator); @@ -225,7 +224,9 @@ void MainWindow::shortenCryptText() { QCryptographicHash md5_generator(QCryptographicHash::Md5); md5_generator.addData(shortenText.toUtf8()); if (md5_generator.result().toHex() == utils->getDataValueStr("md5")) { - auto *dialog = new ShowCopyDialog(shortenText, tr("Notice: Use Decrypt & Verify operation to decrypt this short crypto text."), this); + auto *dialog = new ShowCopyDialog(shortenText, + tr("Notice: Use Decrypt & Verify operation to decrypt this short crypto text."), + this); dialog->show(); } else { QMessageBox::critical(this, tr("Error"), tr("There is a problem with the communication with the server")); diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 7c740595..915c69f7 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -302,32 +302,16 @@ void MainWindow::slotEncryptSign() { bool can_sign = false, can_encr = false; for (const auto &key : keys) { - bool key_can_sign = GpgME::GpgContext::checkIfKeyCanSign(key); bool key_can_encr = GpgME::GpgContext::checkIfKeyCanEncr(key); - if (!key_can_sign && !key_can_encr) { + if (!key_can_encr) { QMessageBox::critical(nullptr, tr("Invalid KeyPair"), - tr("The selected keypair cannot be used for signing and encryption at the same time.<br/>") + tr("The selected keypair cannot be used for encryption.<br/>") + tr("<br/>For example the Following Key: <br/>") + key.uids.first().uid); return; } - if (key_can_sign) can_sign = true; - if (key_can_encr) can_encr = true; - } - - if (!can_encr) { - QMessageBox::critical(nullptr, - tr("Incomplete Operation"), - tr("None of the selected key pairs can provide the encryption function.")); - return; - } - - if (!can_sign) { - QMessageBox::warning(nullptr, - tr("Incomplete Operation"), - tr("None of the selected key pairs can provide the signature function.")); } QVector<GpgKey> signerKeys; @@ -335,16 +319,16 @@ void MainWindow::slotEncryptSign() { auto signersPicker = new SignersPicker(mCtx, this); QEventLoop loop; - connect(signersPicker, SIGNAL(accepted()), &loop, SLOT(quit())); + connect(signersPicker, SIGNAL(finished(int)), &loop, SLOT(quit())); loop.exec(); signersPicker->getCheckedSigners(signerKeys); - for(const auto &key : keys) { + for (const auto &key : keys) { qDebug() << "Keys " << key.email; } - for(const auto &signer : signerKeys) { + for (const auto &signer : signerKeys) { qDebug() << "Signers " << signer.email; } @@ -370,8 +354,12 @@ void MainWindow::slotEncryptSign() { if (settings.value("advanced/autoPubkeyExchange").toBool()) { auto pubkeyUploader = PubkeyUploader(mCtx, signerKeys); pubkeyUploader.start(); - if(!pubkeyUploader.result()) { - + if (!pubkeyUploader.result()) { + QMessageBox::warning(nullptr, + tr("Automatic Key Exchange Warning"), + tr("Part of the automatic key exchange failed, which may be related to your key.") + + + tr("If possible, try to use the RSA algorithm compatible with the server for signing.")); } } @@ -398,6 +386,8 @@ void MainWindow::slotEncryptSign() { else infoBoard->slotRefresh(reportText, INFO_ERROR_WARN); + qDebug() << "End Analyse Result"; + if (status >= 0) { infoBoard->resetOptionActionsMenu(); infoBoard->addOptionalAction("Send Mail", [this]() { @@ -454,14 +444,14 @@ void MainWindow::slotDecryptVerify() { auto *dialog = new WaitingDialog(tr("Decrypting and Verifying"), this); // Automatically import public keys that are not stored locally - if(settings.value("advanced/autoPubkeyExchange").toBool()) { + if (settings.value("advanced/autoPubkeyExchange").toBool()) { gpgme_verify_result_t tmp_v_result = nullptr; auto thread = QThread::create([&]() { mCtx->verify(&text, nullptr, &tmp_v_result); }); thread->start(); while (thread->isRunning()) QApplication::processEvents(); - auto* checker = new UnknownSignersChecker(mCtx, tmp_v_result); + auto *checker = new UnknownSignersChecker(mCtx, tmp_v_result); checker->start(); checker->deleteLater(); } diff --git a/src/ui/settings/SettingsGeneral.cpp b/src/ui/settings/SettingsGeneral.cpp index b4372506..bec66154 100644 --- a/src/ui/settings/SettingsGeneral.cpp +++ b/src/ui/settings/SettingsGeneral.cpp @@ -95,6 +95,7 @@ GeneralTab::GeneralTab(GpgME::GpgContext *ctx, QWidget *parent) ownKeySelectBox = new QComboBox; getServiceTokenButton = new QPushButton(tr("Get Service Token")); serviceTokenLabel = new QLabel(tr("No Service Token Found")); + serviceTokenLabel->setAlignment(Qt::AlignCenter); ownKeyBox->setLayout(ownKeyBoxLayout); mKeyList = new KeyList(mCtx); @@ -158,7 +159,7 @@ void GeneralTab::setSettings() { for (const auto &s : serverList) serverSelectBox->addItem(s); - qDebug() << "currentGpgfrontendServer" << settings.value("general/currentGpgfrontendServer").toString(); + qDebug() << "Current Gpgfrontend Server" << settings.value("general/currentGpgfrontendServer").toString(); serverSelectBox->setCurrentText(settings.value("general/currentGpgfrontendServer", "service.gpgfrontend.pub").toString()); |