diff options
m--------- | modules | 0 | ||||
-rw-r--r-- | src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp | 3 | ||||
-rw-r--r-- | src/sdk/GFSDKGpg.cpp | 52 | ||||
-rw-r--r-- | src/sdk/GFSDKGpg.h | 4 | ||||
-rw-r--r-- | src/ui/main_window/MainWindow.h | 9 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 263 |
6 files changed, 128 insertions, 203 deletions
diff --git a/modules b/modules -Subproject e7948aa6c061d6398448f81cd666ea6c2d1c6b1 +Subproject 024df3ab4316143b02c742f3acc67320972b83d diff --git a/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp b/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp index e569dc3f..6e948705 100644 --- a/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgDecryptResultAnalyse.cpp @@ -80,9 +80,6 @@ void GpgFrontend::GpgDecryptResultAnalyse::doAnalyse() { << Qt::endl; } - stream_ << "- " << tr("German Encryption Standards") << ": " - << (result->is_de_vs == 0 ? tr("false") : tr("true")) << Qt::endl; - stream_ << Qt::endl << Qt::endl; auto *recipient = result->recipients; diff --git a/src/sdk/GFSDKGpg.cpp b/src/sdk/GFSDKGpg.cpp index 4dd23417..52ea0520 100644 --- a/src/sdk/GFSDKGpg.cpp +++ b/src/sdk/GFSDKGpg.cpp @@ -68,7 +68,14 @@ auto GPGFRONTEND_MODULE_SDK_EXPORT GFGpgSignData(int channel, char** key_ids, GpgFrontend::GpgBasicOperator::GetInstance(channel).SignSync( signer_keys, in_buffer, gpg_sign_mode, ascii != 0); - if (GpgFrontend::CheckGpgError(err) != GPG_ERR_NO_ERROR) return -1; + *ps = + static_cast<GFGpgSignResult*>(GFAllocateMemory(sizeof(GFGpgSignResult))); + auto* s = *ps; + + if (GpgFrontend::CheckGpgError(err) != GPG_ERR_NO_ERROR) { + s->error_string = GFStrDup(GpgFrontend::DescribeGpgErrCode(err).second); + return -1; + } auto result = GpgFrontend::ExtractParams<GpgFrontend::GpgSignResult>(data_object, 0); @@ -78,12 +85,10 @@ auto GPGFRONTEND_MODULE_SDK_EXPORT GFGpgSignData(int channel, char** key_ids, auto capsule_id = GpgFrontend::UI::UIModuleManager::GetInstance().MakeCapsule(result); - *ps = - static_cast<GFGpgSignResult*>(GFAllocateMemory(sizeof(GFGpgSignResult))); - auto* s = *ps; s->signature = GFStrDup(out_buffer.ConvertToQByteArray()); s->hash_algo = GFStrDup(result.HashAlgo()); s->capsule_id = GFStrDup(capsule_id); + s->error_string = GFStrDup(GpgFrontend::DescribeGpgErrCode(err).second); return 0; } @@ -142,7 +147,14 @@ GFGpgEncryptData(int channel, char** key_ids, int key_ids_size, char* data, GpgFrontend::GpgBasicOperator::GetInstance(channel).EncryptSync( encrypt_keys, in_buffer, ascii != 0); - if (GpgFrontend::CheckGpgError(err) != GPG_ERR_NO_ERROR) return -1; + *ps = static_cast<GFGpgEncryptionResult*>( + GFAllocateMemory(sizeof(GFGpgEncryptionResult))); + auto* s = *ps; + + if (GpgFrontend::CheckGpgError(err) != GPG_ERR_NO_ERROR) { + s->error_string = GFStrDup(GpgFrontend::DescribeGpgErrCode(err).second); + return -1; + } auto result = GpgFrontend::ExtractParams<GpgFrontend::GpgEncryptResult>(data_object, 0); @@ -152,11 +164,9 @@ GFGpgEncryptData(int channel, char** key_ids, int key_ids_size, char* data, auto capsule_id = GpgFrontend::UI::UIModuleManager::GetInstance().MakeCapsule(result); - *ps = static_cast<GFGpgEncryptionResult*>( - GFAllocateMemory(sizeof(GFGpgEncryptionResult))); - auto* s = *ps; s->encrypted_data = GFStrDup(out_buffer.ConvertToQByteArray()); s->capsule_id = GFStrDup(capsule_id); + s->error_string = GFStrDup(GpgFrontend::DescribeGpgErrCode(err).second); return 0; } @@ -168,7 +178,14 @@ GFGpgDecryptData(int channel, char* data, GFGpgDecryptResult** ps) -> int { GpgFrontend::GpgBasicOperator::GetInstance(channel).DecryptSync( in_buffer); - if (GpgFrontend::CheckGpgError(err) != GPG_ERR_NO_ERROR) return -1; + *ps = static_cast<GFGpgDecryptResult*>( + GFAllocateMemory(sizeof(GFGpgDecryptResult))); + auto* s = *ps; + + if (GpgFrontend::CheckGpgError(err) != GPG_ERR_NO_ERROR) { + s->error_string = GFStrDup(GpgFrontend::DescribeGpgErrCode(err).second); + return -1; + } auto result = GpgFrontend::ExtractParams<GpgFrontend::GpgDecryptResult>(data_object, 0); @@ -178,11 +195,9 @@ GFGpgDecryptData(int channel, char* data, GFGpgDecryptResult** ps) -> int { auto capsule_id = GpgFrontend::UI::UIModuleManager::GetInstance().MakeCapsule(result); - *ps = static_cast<GFGpgDecryptResult*>( - GFAllocateMemory(sizeof(GFGpgDecryptResult))); - auto* s = *ps; s->decrypted_data = GFStrDup(out_buffer.ConvertToQByteArray()); s->capsule_id = GFStrDup(capsule_id); + s->error_string = GFStrDup(GpgFrontend::DescribeGpgErrCode(err).second); return 0; } @@ -195,6 +210,15 @@ auto GPGFRONTEND_MODULE_SDK_EXPORT GFGpgVerifyData( GpgFrontend::GpgBasicOperator::GetInstance(channel).VerifySync( in_buffer, sig_buffer); + *ps = static_cast<GFGpgVerifyResult*>( + GFAllocateMemory(sizeof(GFGpgVerifyResult))); + auto* s = *ps; + + if (GpgFrontend::CheckGpgError(err) != GPG_ERR_NO_ERROR) { + s->error_string = GFStrDup(GpgFrontend::DescribeGpgErrCode(err).second); + return -1; + } + if (GpgFrontend::CheckGpgError(err) != GPG_ERR_NO_ERROR) return -1; auto result = @@ -203,9 +227,7 @@ auto GPGFRONTEND_MODULE_SDK_EXPORT GFGpgVerifyData( auto capsule_id = GpgFrontend::UI::UIModuleManager::GetInstance().MakeCapsule(result); - *ps = static_cast<GFGpgVerifyResult*>( - GFAllocateMemory(sizeof(GFGpgVerifyResult))); - auto* s = *ps; s->capsule_id = GFStrDup(capsule_id); + s->error_string = GFStrDup(GpgFrontend::DescribeGpgErrCode(err).second); return 0; } diff --git a/src/sdk/GFSDKGpg.h b/src/sdk/GFSDKGpg.h index ac166a54..8977a975 100644 --- a/src/sdk/GFSDKGpg.h +++ b/src/sdk/GFSDKGpg.h @@ -36,20 +36,24 @@ struct GFGpgSignResult { char* signature; char* hash_algo; char* capsule_id; + char* error_string; }; struct GFGpgEncryptionResult { char* encrypted_data; char* capsule_id; + char* error_string; }; struct GFGpgDecryptResult { char* decrypted_data; char* capsule_id; + char* error_string; }; struct GFGpgVerifyResult { char* capsule_id; + char* error_string; }; struct GFGpgKeyUID { diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h index 49fe7a1a..40dd5862 100644 --- a/src/ui/main_window/MainWindow.h +++ b/src/ui/main_window/MainWindow.h @@ -543,6 +543,15 @@ class MainWindow : public GeneralMainWindow { void slot_decrypt_email_by_eml_data_result_helper( const QMap<QString, QString>& p); + /** + * @brief + * + * @param err_code + * @param error_string + * @return QString + */ + auto slot_handle_module_error(const QMap<QString, QString>& p) -> bool; + private: /** * @details Create actions for the main-menu and the context-menu of the diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 25a02ba5..ea772b3e 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -372,50 +372,14 @@ void MainWindow::slot_verify_email_by_eml_data(const QByteArray& buffer) { // end waiting dialog hd(); - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to verify email, " - << "error message: " << p["err"]; - - if (p["ret"] == "-2") { - QString detailed_error = p["err"]; - - QString info = - tr("# EML Data Error\n\n" - "The provided EML data does not conform to the " - "structure described in RFC 3156 and cannot be " - "validated.\n\n" - "Details: %1\n\n" - "What is EML Data?\n" - "EML is a file format used to represent email " - "messages. " - "It typically contains the entire contents of an " - "email, " - "including headers, " - "body text, attachments, and metadata. In order to " - "validate " - "the email properly, it is necessary to provide the " - "complete, original EML " - "data.\n\n" - "For more information about the expected EML " - "structure, " - "please refer to the RFC 3156 standard:\n" - "%2\n\n" - "Please ensure the EML data follows the standard and " - "try " - "again.") - .arg(detailed_error) - .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); - slot_refresh_info_board(-2, info); - } - - return; - } + // check if error occurred + if (slot_handle_module_error(p)) return -1; if (p.contains("signature") && p.contains("mime")) { slot_verify_email_by_eml_data_result_helper(p); } - LOG_E() << "mime or signature data is missing"; + return 0; }); }); } @@ -431,45 +395,15 @@ void MainWindow::slot_decrypt_email_by_eml_data(const QByteArray& buffer) { [=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei, Module::Event::Params p) { LOG_D() << "EMAIL_DECRYPT_EML_DATA callback: " << i << ei; - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to decrypt email, " - << "error message: " << p["err"]; - - if (p["ret"] == "-2") { - QString detailed_error = p["err"]; - - QString info = - tr("# EML Data Error\n\n" - "The provided EML data does not conform to the " - "structure described in RFC 3156 and cannot be " - "validated.\n\n" - "Details: %1\n\n" - "What is EML Data?\n" - "EML is a file format used to represent email messages. " - "It typically contains the entire contents of an email, " - "including headers, " - "body text, attachments, and metadata. In order to validate " - "the email properly, it is necessary to provide the " - "complete, original EML " - "data.\n\n" - "For more information about the expected EML structure, " - "please refer to the RFC 3156 standard:\n" - "%2\n\n" - "Please ensure the EML data follows the standard and try " - "again.") - .arg(detailed_error) - .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); - slot_refresh_info_board(-2, info); - } - - return; - } + + // check if error occurred + if (slot_handle_module_error(p)) return -1; if (p.contains("eml_data")) { slot_decrypt_email_by_eml_data_result_helper(p); } - LOG_E() << "mime or signature data is missing"; + return 0; }); } @@ -773,41 +707,8 @@ void MainWindow::SlotSignEML() { // close waiting dialog hd(); - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to decrypt email, " - << "error message: " << p["err"]; - - return; - } - - if (p["ret"] == "-2") { - QString detailed_error = p["err"]; - - QString info = - tr("# EML Data Error\n\n" - "The provided EML data does not conform to the " - "structure described in RFC 3156 and cannot be " - "validated.\n\n" - "Details: %1\n\n" - "What is EML Data?\n" - "EML is a file format used to represent email messages. " - "It typically contains the entire contents of an email, " - "including headers, " - "body text, attachments, and metadata. In order to " - "validate " - "the email properly, it is necessary to provide the " - "complete, original EML " - "data.\n\n" - "For more information about the expected EML structure, " - "please refer to the RFC 3156 standard:\n" - "%2\n\n" - "Please ensure the EML data follows the standard and " - "try " - "again.") - .arg(detailed_error) - .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); - slot_refresh_info_board(-2, info); - } + // check if error occurred + if (slot_handle_module_error(p)) return -1; if (!p["eml_data"].isEmpty()) { edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); @@ -831,7 +732,7 @@ void MainWindow::SlotSignEML() { } } - LOG_E() << "mime or signature data is missing"; + return 0; }); }); } @@ -890,45 +791,8 @@ void MainWindow::SlotEncryptSignEML() { // close waiting dialog hd(); - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to decrypt email, " - << "error message: " << p["err"]; - - return; - } - - if (p["ret"] == "-2") { - QString detailed_error = p["err"]; - - QString info = - tr("# EML Data Error\n\n" - "The provided EML data does not conform to the " - "structure described in RFC 3156 and cannot be " - "validated.\n\n" - "Details: %1\n\n" - "What is EML Data?\n" - "EML is a file format used to represent email messages. " - "It typically contains the entire contents of an email, " - "including headers, " - "body text, attachments, and metadata. In order to " - "validate " - "the email properly, it is necessary to provide the " - "complete, original EML " - "data.\n\n" - "For more information about the expected EML structure, " - "please refer to the RFC 3156 standard:\n" - "%2\n\n" - "Please ensure the EML data follows the standard and " - "try " - "again.") - .arg(detailed_error) - .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); - slot_refresh_info_board(-2, info); - } - - if (!p["eml_data"].isEmpty()) { - edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); - } + // check if error occurred + if (slot_handle_module_error(p)) return -1; if (!p["sign_capsule_id"].isEmpty() && !p["encr_capsule_id"].isEmpty()) { @@ -958,7 +822,7 @@ void MainWindow::SlotEncryptSignEML() { } } - LOG_E() << "mime or signature data is missing"; + return 0; }); }); } @@ -985,41 +849,8 @@ void MainWindow::SlotDecryptVerifyEML() { // close waiting dialog hd(); - if (p["ret"] != "0" || !p["err"].isEmpty()) { - LOG_E() << "An error occurred trying to decrypt email, " - << "error message: " << p["err"]; - - return; - } - - if (p["ret"] == "-2") { - QString detailed_error = p["err"]; - - QString info = - tr("# EML Data Error\n\n" - "The provided EML data does not conform to the " - "structure described in RFC 3156 and cannot be " - "validated.\n\n" - "Details: %1\n\n" - "What is EML Data?\n" - "EML is a file format used to represent email messages. " - "It typically contains the entire contents of an email, " - "including headers, " - "body text, attachments, and metadata. In order to " - "validate " - "the email properly, it is necessary to provide the " - "complete, original EML " - "data.\n\n" - "For more information about the expected EML structure, " - "please refer to the RFC 3156 standard:\n" - "%2\n\n" - "Please ensure the EML data follows the standard and " - "try " - "again.") - .arg(detailed_error) - .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); - slot_refresh_info_board(-2, info); - } + // check if error occurred + if (slot_handle_module_error(p)) return -1; edit_->SlotSetText2CurEMailPage(p.value("eml_data", "")); @@ -1098,9 +929,71 @@ void MainWindow::SlotDecryptVerifyEML() { } } - LOG_E() << "mime or signature data is missing"; + return 0; }); }); } +auto MainWindow::slot_handle_module_error(const QMap<QString, QString>& p) + -> bool { + if (p["ret"] == "-2") { + QString detailed_error = p["err"]; + + QString info = + tr("# EML Data Error\n\n" + "The provided EML data does not conform to RFC 3156 standards and " + "cannot be processed.\n\n" + "**Details:** %1\n\n" + "### What is EML Data?\n" + "EML is a file format for representing email messages, typically " + "including headers, body text, attachments, and metadata. " + "Complete and properly structured EML data is required for " + "validation.\n\n" + "### Suggested Solutions\n" + "1. Verify the EML data is complete and matches the structure " + "outlined in RFC 3156.\n" + "2. Refer to the official documentation for the EML structure: " + "%2\n\n" + "After correcting the EML data, try the operation again.") + .arg(detailed_error) + .arg("https://www.rfc-editor.org/rfc/rfc3156.txt"); + slot_refresh_info_board(-2, info); + return true; + } + + if (p["ret"] != "0" || !p["err"].isEmpty()) { + LOG_E() << "An error occurred trying to operate email, " + << "error message: " << p["err"]; + + QString error_message = + tr("# Email Operation Error\n\n" + "An error occurred during the email operation. The process " + "could not be completed.\n\n" + "**Details:**\n" + "- **Error Code:** %1\n" + "- **Error Message:** %2\n\n" + "### Possible Causes\n" + "1. The email data may be incomplete or corrupted.\n" + "2. The selected GPG key does not have the necessary " + "permissions.\n" + "3. Issues in the GPG environment or configuration.\n\n" + "### Suggested Solutions\n" + "1. Ensure the email data is complete and follows the expected " + "format.\n" + "2. Verify the GPG key has the required access permissions.\n" + "3. Check your GPG environment and configuration settings.\n" + "4. Review the error details above or application logs for " + "further troubleshooting.\n\n" + "If the issue persists, consider seeking technical support or " + "consulting the documentation.") + .arg(p["ret"]) + .arg(p["err"]); + + slot_refresh_info_board(-1, error_message); + return true; + } + + return false; +} + } // namespace GpgFrontend::UI |