From 98c5bb40d139fcb7a7600bdeb1f28d4f94b9f49a Mon Sep 17 00:00:00 2001 From: Saturneric Date: Tue, 10 Aug 2021 23:24:07 +0800 Subject: Split some source files that are too large. --- .../main_window/MainWindowServerSlotFunction.cpp | 185 +++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 src/ui/main_window/MainWindowServerSlotFunction.cpp (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp new file mode 100644 index 00000000..c9d89fac --- /dev/null +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -0,0 +1,185 @@ +/** + * 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 . + * + * 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 starting on May 12, 2021. + * + */ + +#include "MainWindow.h" +#include "server/ComUtils.h" +#include "ui/ShowCopyDialog.h" + +#include "rapidjson/document.h" +#include "rapidjson/prettywriter.h" + +/** + * get full size crypt text from server using short crypto text + * @param shortenCryptoText short crypto text([GpgFrontend_ShortCrypto]://) + * @return + */ +QString MainWindow::getCryptText(const QString &shortenCryptoText) { + auto host = settings.value("general/currentGpgfrontendServer", + "service.gpgfrontend.pub").toString(); + + QString ownKeyId = settings.value("general/ownKeyId").toString(); + + 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.")); + return {}; + } + + QString serviceToken = settings.value("general/serviceToken").toString(); + if (serviceToken.isEmpty()) { + QMessageBox::critical(this, tr("Error"), + tr("Please obtain a Service Token from the server in the settings.")); + return {}; + } + + QUrl reqUrl("http://127.0.0.1:9048/text/get"); + QNetworkRequest request(reqUrl); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + + // Sign Shorten Text + QVector keys{key}; + QByteArray outSignText; + mCtx->sign(keys, shortenCryptoText.toUtf8(), &outSignText, GPGME_SIG_MODE_NORMAL); + auto outSignTextBase64 = outSignText.toBase64(); + + rapidjson::Document doc; + doc.SetObject(); + + rapidjson::Value s, t; + + // Signature + s.SetString(outSignTextBase64.constData(), outSignTextBase64.count()); + // Service Token + const auto t_byte_array = serviceToken.toUtf8(); + t.SetString(t_byte_array.constData(), t_byte_array.count()); + + doc.AddMember("signature", s, doc.GetAllocator()); + doc.AddMember("serviceToken", t, doc.GetAllocator()); + + rapidjson::StringBuffer sb; + rapidjson::PrettyWriter writer(sb); + doc.Accept(writer); + + QByteArray postData(sb.GetString()); + qDebug() << "postData" << QString::fromUtf8(postData); + + QNetworkReply *reply = networkAccessManager->post(request, postData); + + auto dialog = new WaitingDialog("Getting Crypt Text From Server", this); + dialog->show(); + + while (reply->isRunning()) { + QApplication::processEvents(); + } + + dialog->close(); + + QByteArray replyData = reply->readAll().constData(); + auto comUtils = new ComUtils(this); + if (comUtils->checkServerReply(replyData)) { + //TODO Logic + } else QMessageBox::critical(this, tr("Error"), tr("Unknown Error")); + + return {}; +} + +void MainWindow::shortenCryptText() { + + QString serviceToken = settings.value("general/serviceToken").toString(); + QString ownKeyId = settings.value("general/ownKeyId").toString(); + + QByteArray cryptoText = edit->curTextPage()->toPlainText().toUtf8(); + + QUrl reqUrl("http://127.0.0.1:9048/text/new"); + QNetworkRequest request(reqUrl); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + + 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.")); + return; + } + + QCryptographicHash ch(QCryptographicHash::Md5); + ch.addData(cryptoText); + QString md5 = ch.result().toHex(); + + qDebug() << "md5" << md5; + + QByteArray signText = QString("[%1][%2]").arg(serviceToken, md5).toUtf8(); + + QCryptographicHash sha(QCryptographicHash::Sha256); + sha.addData(signText); + QString shaText = sha.result().toHex(); + + qDebug() << "shaText" << shaText; + + QVector keys{key}; + QByteArray outSignText; + mCtx->sign(keys, signText, &outSignText, GPGME_SIG_MODE_NORMAL); + QByteArray outSignTextBase64 = outSignText.toBase64(); + + rapidjson::Value c, s, m, t; + + rapidjson::Document doc; + doc.SetObject(); + + c.SetString(cryptoText.constData(), cryptoText.count()); + auto m_byte_array = shaText.toUtf8(); + m.SetString(m_byte_array.constData(), m_byte_array.count()); + s.SetString(outSignTextBase64.constData(), outSignTextBase64.count()); + auto t_byte_array = serviceToken.toUtf8(); + t.SetString(t_byte_array.constData(), t_byte_array.count()); + + doc.AddMember("cryptoText", c, doc.GetAllocator()); + doc.AddMember("sha", m, doc.GetAllocator()); + doc.AddMember("sign", s, doc.GetAllocator()); + doc.AddMember("serviceToken", t, doc.GetAllocator()); + + rapidjson::StringBuffer sb; + rapidjson::PrettyWriter writer(sb); + doc.Accept(writer); + + QByteArray postData(sb.GetString()); + qDebug() << "postData" << QString::fromUtf8(postData); + + QNetworkReply *reply = networkAccessManager->post(request, postData); + + while (reply->isRunning()) { + QApplication::processEvents(); + } + + if (reply->error() == QNetworkReply::NoError) { + rapidjson::Document docReply; + docReply.Parse(reply->readAll().constData()); + QString shortenText = docReply["shortenText"].GetString(); + auto *dialog = new ShowCopyDialog(shortenText, this); + dialog->show(); + } else { + QMessageBox::critical(this, tr("Error"), reply->errorString()); + } + + +} + -- cgit v1.2.3 From a5cf56e93e4e6a856b2f21730c7bfbfa413410ff Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 11 Aug 2021 13:21:57 +0800 Subject: Continue to improve functions. Split source files that are too long. --- .../main_window/MainWindowServerSlotFunction.cpp | 102 +++++++++++++++------ 1 file changed, 76 insertions(+), 26 deletions(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index c9d89fac..fec60063 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -35,8 +35,7 @@ * @return */ QString MainWindow::getCryptText(const QString &shortenCryptoText) { - auto host = settings.value("general/currentGpgfrontendServer", - "service.gpgfrontend.pub").toString(); + QString ownKeyId = settings.value("general/ownKeyId").toString(); @@ -46,14 +45,16 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { return {}; } + auto utils = new ComUtils(this); + QString serviceToken = settings.value("general/serviceToken").toString(); - if (serviceToken.isEmpty()) { + if (serviceToken.isEmpty() || !utils->checkServiceTokenFormat(serviceToken)) { QMessageBox::critical(this, tr("Error"), tr("Please obtain a Service Token from the server in the settings.")); return {}; } - QUrl reqUrl("http://127.0.0.1:9048/text/get"); + QUrl reqUrl(utils->getUrl(ComUtils::GetFullCryptText)); QNetworkRequest request(reqUrl); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); @@ -89,29 +90,63 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { auto dialog = new WaitingDialog("Getting Crypt Text From Server", this); dialog->show(); - while (reply->isRunning()) { - QApplication::processEvents(); - } + while (reply->isRunning()) QApplication::processEvents(); dialog->close(); QByteArray replyData = reply->readAll().constData(); - auto comUtils = new ComUtils(this); - if (comUtils->checkServerReply(replyData)) { - //TODO Logic - } else QMessageBox::critical(this, tr("Error"), tr("Unknown Error")); + if (utils->checkServerReply(replyData)) { + /** + * { + * "cryptoText" : ... + * "sha": ... + * "serviceToken": ... + * "date": ... + * } + */ + + if (!utils->checkDataValue("cryptoText") + || !utils->checkDataValue("sha") + || !utils->checkDataValue("serviceToken")) { + QMessageBox::critical(this, tr("Error"), + tr("The communication content with the server does not meet the requirements")); + return {}; + } + + auto cryptoText = utils->getDataValue("cryptoText"); + auto sha = utils->getDataValue("sha"); + auto serviceTokenFromServer = utils->getDataValue("serviceToken"); + + QCryptographicHash sha_generator(QCryptographicHash::Sha256); + sha_generator.addData(cryptoText.toUtf8()); + + if (serviceTokenFromServer == serviceToken && + sha_generator.result().toHex() == sha) { + return cryptoText; + } else QMessageBox::critical(this, tr("Error"), tr("Invalid short ciphertext")); + + return {}; + } return {}; } void MainWindow::shortenCryptText() { + // gather information QString serviceToken = settings.value("general/serviceToken").toString(); QString ownKeyId = settings.value("general/ownKeyId").toString(); - QByteArray cryptoText = edit->curTextPage()->toPlainText().toUtf8(); - QUrl reqUrl("http://127.0.0.1:9048/text/new"); + auto utils = new ComUtils(this); + + if (serviceToken.isEmpty() || !utils->checkServiceTokenFormat(serviceToken)) { + QMessageBox::critical(this, tr("Invalid Service Token"), + tr("Please go to the setting interface to get a ServiceToken.")); + return; + } + + QUrl reqUrl(utils->getUrl(ComUtils::ShortenCryptText)); QNetworkRequest request(reqUrl); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); @@ -166,20 +201,35 @@ void MainWindow::shortenCryptText() { QNetworkReply *reply = networkAccessManager->post(request, postData); - while (reply->isRunning()) { - QApplication::processEvents(); + while (reply->isRunning()) QApplication::processEvents(); + + if (utils->checkServerReply(reply->readAll().constData())) { + + /** + * { + * "shortenText" : ... + * "md5": ... + * } + */ + + if (!utils->checkDataValue("shortenText") || !utils->checkDataValue("md5")) { + QMessageBox::critical(this, tr("Error"), + tr("The communication content with the server does not meet the requirements")); + return; + } + + QString shortenText = utils->getDataValue("shortenText"); + + QCryptographicHash md5_generator(QCryptographicHash::Md5); + md5_generator.addData(shortenText.toUtf8()); + if (md5_generator.result().toHex() == utils->getDataValue("md5")) { + auto *dialog = new ShowCopyDialog(shortenText, this); + dialog->show(); + } else { + QMessageBox::critical(this, tr("Error"), tr("There is a problem with the communication with the server")); + return; + } } - if (reply->error() == QNetworkReply::NoError) { - rapidjson::Document docReply; - docReply.Parse(reply->readAll().constData()); - QString shortenText = docReply["shortenText"].GetString(); - auto *dialog = new ShowCopyDialog(shortenText, this); - dialog->show(); - } else { - QMessageBox::critical(this, tr("Error"), reply->errorString()); - } - - } -- cgit v1.2.3 From 67778c92257fac129f02b1def0f384a9fb9b910e Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 11 Aug 2021 15:05:35 +0800 Subject: Fix Compile Issue --- src/ui/main_window/MainWindowServerSlotFunction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index fec60063..12f1453b 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -59,7 +59,7 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); // Sign Shorten Text - QVector keys{key}; + QVector keys{key}; QByteArray outSignText; mCtx->sign(keys, shortenCryptoText.toUtf8(), &outSignText, GPGME_SIG_MODE_NORMAL); auto outSignTextBase64 = outSignText.toBase64(); -- cgit v1.2.3 From 158f1e2e4e863f6cbc9064efbb8449cdaedc9ad4 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 11 Aug 2021 16:23:03 +0800 Subject: Continue to fix Compile Issue --- src/ui/main_window/MainWindowServerSlotFunction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index 12f1453b..d845e25d 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -170,7 +170,7 @@ void MainWindow::shortenCryptText() { qDebug() << "shaText" << shaText; - QVector keys{key}; + QVector keys{key}; QByteArray outSignText; mCtx->sign(keys, signText, &outSignText, GPGME_SIG_MODE_NORMAL); QByteArray outSignTextBase64 = outSignText.toBase64(); -- cgit v1.2.3 From 2029d17896edac2e86bff0a12e69f7d1cf9e3eb5 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Thu, 12 Aug 2021 13:09:37 +0800 Subject: Beautify UI --- src/ui/main_window/MainWindowServerSlotFunction.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index d845e25d..e7dfab03 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -36,7 +36,6 @@ */ QString MainWindow::getCryptText(const QString &shortenCryptoText) { - QString ownKeyId = settings.value("general/ownKeyId").toString(); GpgKey key = mCtx->getKeyById(ownKeyId); -- cgit v1.2.3 From 805f8b2f36007317a750cf6aecb633ad6ad2d4e4 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sun, 15 Aug 2021 23:00:19 +0800 Subject: Bugs Fixed; Improve Functions; --- src/ui/main_window/MainWindowServerSlotFunction.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index e7dfab03..da52871b 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -86,7 +86,7 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { QNetworkReply *reply = networkAccessManager->post(request, postData); - auto dialog = new WaitingDialog("Getting Crypt Text From Server", this); + auto dialog = new WaitingDialog(tr("Getting Cpt From Server"), this); dialog->show(); while (reply->isRunning()) QApplication::processEvents(); @@ -200,8 +200,13 @@ void MainWindow::shortenCryptText() { QNetworkReply *reply = networkAccessManager->post(request, postData); + auto dialog = new WaitingDialog(tr("Getting Scpt From Server"), this); + dialog->show(); + while (reply->isRunning()) QApplication::processEvents(); + dialog->close(); + if (utils->checkServerReply(reply->readAll().constData())) { /** @@ -222,7 +227,7 @@ void MainWindow::shortenCryptText() { QCryptographicHash md5_generator(QCryptographicHash::Md5); md5_generator.addData(shortenText.toUtf8()); if (md5_generator.result().toHex() == utils->getDataValue("md5")) { - auto *dialog = new ShowCopyDialog(shortenText, 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")); -- cgit v1.2.3 From 3977f4d024fdbf676f14d51a6977d9f7e67965ee Mon Sep 17 00:00:00 2001 From: Saturneric Date: Thu, 19 Aug 2021 17:31:17 +0800 Subject: Bugs Fixed; Code Modified; --- src/ui/main_window/MainWindowServerSlotFunction.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index da52871b..ed660621 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -119,8 +119,7 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { QCryptographicHash sha_generator(QCryptographicHash::Sha256); sha_generator.addData(cryptoText.toUtf8()); - if (serviceTokenFromServer == serviceToken && - sha_generator.result().toHex() == sha) { + if (sha_generator.result().toHex() == sha) { return cryptoText; } else QMessageBox::critical(this, tr("Error"), tr("Invalid short ciphertext")); @@ -200,11 +199,9 @@ void MainWindow::shortenCryptText() { QNetworkReply *reply = networkAccessManager->post(request, postData); - auto dialog = new WaitingDialog(tr("Getting Scpt From Server"), this); + auto *dialog = new WaitingDialog(tr("Getting Scpt From Server"), this); dialog->show(); - while (reply->isRunning()) QApplication::processEvents(); - dialog->close(); if (utils->checkServerReply(reply->readAll().constData())) { -- cgit v1.2.3 From 2e27baf284fde00c5fc1d81e1f8bc891b8163766 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Fri, 20 Aug 2021 19:47:45 +0800 Subject: Improve Functions; Bugs Fixed; --- .../main_window/MainWindowServerSlotFunction.cpp | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index ed660621..c2300818 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -74,8 +74,10 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { const auto t_byte_array = serviceToken.toUtf8(); t.SetString(t_byte_array.constData(), t_byte_array.count()); - doc.AddMember("signature", s, doc.GetAllocator()); - doc.AddMember("serviceToken", t, doc.GetAllocator()); + rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); + + doc.AddMember("signature", s, allocator); + doc.AddMember("serviceToken", t, allocator); rapidjson::StringBuffer sb; rapidjson::PrettyWriter writer(sb); @@ -84,7 +86,7 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { QByteArray postData(sb.GetString()); qDebug() << "postData" << QString::fromUtf8(postData); - QNetworkReply *reply = networkAccessManager->post(request, postData); + QNetworkReply *reply = utils->getNetworkManager()->post(request, postData); auto dialog = new WaitingDialog(tr("Getting Cpt From Server"), this); dialog->show(); @@ -104,17 +106,17 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { * } */ - if (!utils->checkDataValue("cryptoText") - || !utils->checkDataValue("sha") - || !utils->checkDataValue("serviceToken")) { + if (!utils->checkDataValueStr("cryptoText") + || !utils->checkDataValueStr("sha") + || !utils->checkDataValueStr("serviceToken")) { QMessageBox::critical(this, tr("Error"), tr("The communication content with the server does not meet the requirements")); return {}; } - auto cryptoText = utils->getDataValue("cryptoText"); - auto sha = utils->getDataValue("sha"); - auto serviceTokenFromServer = utils->getDataValue("serviceToken"); + auto cryptoText = utils->getDataValueStr("cryptoText"); + auto sha = utils->getDataValueStr("sha"); + auto serviceTokenFromServer = utils->getDataValueStr("serviceToken"); QCryptographicHash sha_generator(QCryptographicHash::Sha256); sha_generator.addData(cryptoText.toUtf8()); @@ -168,10 +170,7 @@ void MainWindow::shortenCryptText() { qDebug() << "shaText" << shaText; - QVector keys{key}; - QByteArray outSignText; - mCtx->sign(keys, signText, &outSignText, GPGME_SIG_MODE_NORMAL); - QByteArray outSignTextBase64 = outSignText.toBase64(); + QByteArray outSignTextBase64 = ComUtils::getSignStringBase64(mCtx, signText, key); rapidjson::Value c, s, m, t; @@ -185,10 +184,12 @@ void MainWindow::shortenCryptText() { auto t_byte_array = serviceToken.toUtf8(); t.SetString(t_byte_array.constData(), t_byte_array.count()); - doc.AddMember("cryptoText", c, doc.GetAllocator()); - doc.AddMember("sha", m, doc.GetAllocator()); - doc.AddMember("sign", s, doc.GetAllocator()); - doc.AddMember("serviceToken", t, doc.GetAllocator()); + rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); + + doc.AddMember("cryptoText", c, allocator); + doc.AddMember("sha", m, allocator); + doc.AddMember("sign", s, allocator); + doc.AddMember("serviceToken", t, allocator); rapidjson::StringBuffer sb; rapidjson::PrettyWriter writer(sb); @@ -213,17 +214,17 @@ void MainWindow::shortenCryptText() { * } */ - if (!utils->checkDataValue("shortenText") || !utils->checkDataValue("md5")) { + if (!utils->checkDataValueStr("shortenText") || !utils->checkDataValueStr("md5")) { QMessageBox::critical(this, tr("Error"), tr("The communication content with the server does not meet the requirements")); return; } - QString shortenText = utils->getDataValue("shortenText"); + QString shortenText = utils->getDataValueStr("shortenText"); QCryptographicHash md5_generator(QCryptographicHash::Md5); md5_generator.addData(shortenText.toUtf8()); - if (md5_generator.result().toHex() == utils->getDataValue("md5")) { + 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); dialog->show(); } else { -- cgit v1.2.3 From 05bccf40df525c8b3753750a34ff4b75e96d2f6e Mon Sep 17 00:00:00 2001 From: Saturneric Date: Fri, 20 Aug 2021 22:50:57 +0800 Subject: Fixed. --- src/ui/main_window/MainWindowServerSlotFunction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index c2300818..011cfd28 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -86,7 +86,7 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { QByteArray postData(sb.GetString()); qDebug() << "postData" << QString::fromUtf8(postData); - QNetworkReply *reply = utils->getNetworkManager()->post(request, postData); + QNetworkReply *reply = utils->getNetworkManager().post(request, postData); auto dialog = new WaitingDialog(tr("Getting Cpt From Server"), this); dialog->show(); -- cgit v1.2.3 From 03d37859e3e6c644085fb56c86c126536525d721 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Mon, 23 Aug 2021 17:48:21 +0800 Subject: Fix some problems; Ready to release a BETA version --- src/ui/main_window/MainWindowServerSlotFunction.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') 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 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")); -- cgit v1.2.3 From 420db34b0b9fa3af987342d504eb61767eb31d4d Mon Sep 17 00:00:00 2001 From: Saturneric Date: Mon, 23 Aug 2021 18:24:23 +0800 Subject: Reduced issues. --- src/ui/main_window/MainWindowServerSlotFunction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/main_window/MainWindowServerSlotFunction.cpp') diff --git a/src/ui/main_window/MainWindowServerSlotFunction.cpp b/src/ui/main_window/MainWindowServerSlotFunction.cpp index 13dc6af3..3a7e9f71 100644 --- a/src/ui/main_window/MainWindowServerSlotFunction.cpp +++ b/src/ui/main_window/MainWindowServerSlotFunction.cpp @@ -120,7 +120,7 @@ QString MainWindow::getCryptText(const QString &shortenCryptoText) { QCryptographicHash sha_generator(QCryptographicHash::Sha256); sha_generator.addData(cryptoText.toUtf8()); - if (sha_generator.result().toHex() == sha) { + if (sha_generator.result().toHex() == sha && serviceToken == serviceTokenFromServer) { return cryptoText; } else QMessageBox::critical(this, tr("Error"), tr("Invalid short ciphertext")); -- cgit v1.2.3