feat: support encrypting email
This commit is contained in:
parent
a83c6e28a1
commit
af6abea577
2
modules
2
modules
@ -1 +1 @@
|
|||||||
Subproject commit 4b846455b7c232b7db63f95c6a1943ccbc7ce15b
|
Subproject commit da105c4ae189f63b74e4f2df96031caffba68afc
|
@ -33,6 +33,7 @@
|
|||||||
#include "core/function/gpg/GpgKeyGetter.h"
|
#include "core/function/gpg/GpgKeyGetter.h"
|
||||||
#include "core/function/gpg/GpgKeyImportExporter.h"
|
#include "core/function/gpg/GpgKeyImportExporter.h"
|
||||||
#include "core/model/DataObject.h"
|
#include "core/model/DataObject.h"
|
||||||
|
#include "core/model/GpgEncryptResult.h"
|
||||||
#include "core/model/GpgSignResult.h"
|
#include "core/model/GpgSignResult.h"
|
||||||
#include "core/typedef/GpgTypedef.h"
|
#include "core/typedef/GpgTypedef.h"
|
||||||
|
|
||||||
@ -113,3 +114,37 @@ auto GPGFRONTEND_MODULE_SDK_EXPORT GFGpgKeyPrimaryUID(int channel, char* key_id,
|
|||||||
s->comment = GFStrDup(primary_uid.GetComment());
|
s->comment = GFStrDup(primary_uid.GetComment());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto GPGFRONTEND_MODULE_SDK_EXPORT
|
||||||
|
GFGpgEncryptData(int channel, char** key_ids, int key_ids_size, char* data,
|
||||||
|
int ascii, GFGpgEncryptionResult** ps) -> int {
|
||||||
|
auto encrypt_key_ids = CharArrayToQList(key_ids, key_ids_size);
|
||||||
|
|
||||||
|
GpgFrontend::KeyArgsList encrypt_keys;
|
||||||
|
for (const auto& encrypt_key_id : encrypt_key_ids) {
|
||||||
|
auto key =
|
||||||
|
GpgFrontend::GpgKeyGetter::GetInstance(channel).GetKey(encrypt_key_id);
|
||||||
|
if (key.IsGood()) encrypt_keys.push_back(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (encrypt_keys.empty()) return -1;
|
||||||
|
|
||||||
|
auto in_buffer = GpgFrontend::GFBuffer(GFUnStrDup(data).toUtf8());
|
||||||
|
|
||||||
|
auto [err, data_object] =
|
||||||
|
GpgFrontend::GpgBasicOperator::GetInstance(channel).EncryptSync(
|
||||||
|
encrypt_keys, in_buffer, ascii != 0);
|
||||||
|
|
||||||
|
if (GpgFrontend::CheckGpgError(err) != GPG_ERR_NO_ERROR) return -1;
|
||||||
|
|
||||||
|
auto result =
|
||||||
|
GpgFrontend::ExtractParams<GpgFrontend::GpgEncryptResult>(data_object, 0);
|
||||||
|
auto out_buffer =
|
||||||
|
GpgFrontend::ExtractParams<GpgFrontend::GFBuffer>(data_object, 1);
|
||||||
|
|
||||||
|
*ps = static_cast<GFGpgEncryptionResult*>(
|
||||||
|
GFAllocateMemory(sizeof(GFGpgEncryptionResult)));
|
||||||
|
auto* s = *ps;
|
||||||
|
s->encrypted_data = GFStrDup(out_buffer.ConvertToQByteArray());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -37,6 +37,10 @@ struct GFGpgSignResult {
|
|||||||
char* hash_algo;
|
char* hash_algo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GFGpgEncryptionResult {
|
||||||
|
char* encrypted_data;
|
||||||
|
};
|
||||||
|
|
||||||
struct GFGpgKeyUID {
|
struct GFGpgKeyUID {
|
||||||
char* name;
|
char* name;
|
||||||
char* email;
|
char* email;
|
||||||
@ -56,6 +60,20 @@ auto GPGFRONTEND_MODULE_SDK_EXPORT GFGpgSignData(int channel, char** key_ids,
|
|||||||
int sign_mode, int ascii,
|
int sign_mode, int ascii,
|
||||||
GFGpgSignResult**) -> int;
|
GFGpgSignResult**) -> int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param channel
|
||||||
|
* @param key_ids
|
||||||
|
* @param key_ids_size
|
||||||
|
* @param data
|
||||||
|
* @param ascii
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
auto GPGFRONTEND_MODULE_SDK_EXPORT
|
||||||
|
GFGpgEncryptData(int channel, char** key_ids, int key_ids_size, char* data,
|
||||||
|
int ascii, GFGpgEncryptionResult**) -> int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
*
|
*
|
||||||
|
@ -182,6 +182,12 @@ class MainWindow : public GeneralMainWindow {
|
|||||||
*/
|
*/
|
||||||
void SlotSignEML();
|
void SlotSignEML();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void SlotEncryptEML();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @details decrypt and verify the text of currently active textedit-page
|
* @details decrypt and verify the text of currently active textedit-page
|
||||||
* with the currently checked keys
|
* with the currently checked keys
|
||||||
|
@ -689,19 +689,68 @@ void MainWindow::slot_decrypt_email_by_eml_data_result_helper(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::SlotSignEML() {
|
void MainWindow::SlotEncryptEML() {
|
||||||
if (edit_->TabCount() == 0 || edit_->CurEMailPage() == nullptr) return;
|
if (edit_->TabCount() == 0 || edit_->CurEMailPage() == nullptr) return;
|
||||||
if (m_key_list_->GetCheckedKeys().isEmpty()) return;
|
auto checked_keys = m_key_list_->GetCheckedKeys();
|
||||||
|
|
||||||
|
if (checked_keys.isEmpty()) {
|
||||||
|
QMessageBox::warning(this, tr("No Key Selected"),
|
||||||
|
tr("Please select a key for encrypt the EML."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto buffer = edit_->CurPlainText().toUtf8();
|
auto buffer = edit_->CurPlainText().toUtf8();
|
||||||
|
|
||||||
Module::TriggerEvent(
|
Module::TriggerEvent(
|
||||||
"EMAIL_EXPORT_EML_DATA",
|
"EMAIL_ENCRYPT_EML_DATA",
|
||||||
{
|
{
|
||||||
{"body_data", QString::fromLatin1(buffer.toBase64())},
|
{"body_data", QString::fromLatin1(buffer.toBase64())},
|
||||||
{"channel",
|
{"channel",
|
||||||
QString::number(m_key_list_->GetCurrentGpgContextChannel())},
|
QString::number(m_key_list_->GetCurrentGpgContextChannel())},
|
||||||
{"sign_key", m_key_list_->GetCheckedKeys().front()},
|
{"encrypt_keys", checked_keys.join(';')},
|
||||||
|
},
|
||||||
|
[=](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"];
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p["eml_data"].isEmpty()) {
|
||||||
|
edit_->SlotSetText2CurEMailPage(p.value("eml_data", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_E() << "mime or signature data is missing";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::SlotSignEML() {
|
||||||
|
if (edit_->TabCount() == 0 || edit_->CurEMailPage() == nullptr) return;
|
||||||
|
auto checked_keys = m_key_list_->GetCheckedKeys();
|
||||||
|
|
||||||
|
if (checked_keys.isEmpty()) {
|
||||||
|
QMessageBox::warning(this, tr("No Key Selected"),
|
||||||
|
tr("Please select a key for signing the EML."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checked_keys.size() > 1) {
|
||||||
|
QMessageBox::warning(this, tr("Multiple Keys Selected"),
|
||||||
|
tr("Please select only one key to sign the EML."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto buffer = edit_->CurPlainText().toUtf8();
|
||||||
|
|
||||||
|
Module::TriggerEvent(
|
||||||
|
"EMAIL_SIGN_EML_DATA",
|
||||||
|
{
|
||||||
|
{"body_data", QString::fromLatin1(buffer.toBase64())},
|
||||||
|
{"channel",
|
||||||
|
QString::number(m_key_list_->GetCurrentGpgContextChannel())},
|
||||||
|
{"sign_key", checked_keys.front()},
|
||||||
},
|
},
|
||||||
[=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei,
|
[=](Module::EventIdentifier i, Module::Event::ListenerIdentifier ei,
|
||||||
Module::Event::Params p) {
|
Module::Event::Params p) {
|
||||||
|
@ -217,6 +217,12 @@ void MainWindow::SlotGeneralEncrypt(bool) {
|
|||||||
this->SlotDirectoryEncrypt(path);
|
this->SlotDirectoryEncrypt(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (edit_->CurEMailPage() != nullptr) {
|
||||||
|
this->SlotEncryptEML();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (edit_->SlotCurPageTextEdit() != nullptr) {
|
if (edit_->SlotCurPageTextEdit() != nullptr) {
|
||||||
this->SlotEncrypt();
|
this->SlotEncrypt();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user