feat: track error string of gpg basic operation
This commit is contained in:
parent
799ec5c9b2
commit
024df3ab43
@ -54,18 +54,17 @@ auto EncryptPlainText(int channel, const QStringList& keys,
|
|||||||
auto ret = GFGpgEncryptData(channel, QListToCharArray(keys), keys.size(),
|
auto ret = GFGpgEncryptData(channel, QListToCharArray(keys), keys.size(),
|
||||||
QDUP(body_data), 1, &s);
|
QDUP(body_data), 1, &s);
|
||||||
|
|
||||||
if (ret != 0) {
|
|
||||||
eml_data = "Encryption Failed";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto encrypted_data = UDUP(s->encrypted_data);
|
auto encrypted_data = UDUP(s->encrypted_data);
|
||||||
|
auto gpg_error_string = UDUP(s->error_string);
|
||||||
capsule_id = UDUP(s->capsule_id);
|
capsule_id = UDUP(s->capsule_id);
|
||||||
FLOG_DEBUG("got capsule id: %1", capsule_id);
|
|
||||||
|
|
||||||
GFFreeMemory(s);
|
GFFreeMemory(s);
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
eml_data = "Encryption Failed: " + gpg_error_string;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
vmime::messageBuilder msg_builder;
|
vmime::messageBuilder msg_builder;
|
||||||
|
|
||||||
if (ParseEmailString(from, name, email)) {
|
if (ParseEmailString(from, name, email)) {
|
||||||
@ -191,7 +190,7 @@ auto EncryptPlainText(int channel, const QStringList& keys,
|
|||||||
|
|
||||||
} catch (const vmime::exception& e) {
|
} catch (const vmime::exception& e) {
|
||||||
eml_data = QString("VMIME Error: %1").arg(e.what());
|
eml_data = QString("VMIME Error: %1").arg(e.what());
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
eml_data = QString("Unknown Error: %1");
|
eml_data = QString("Unknown Error: %1");
|
||||||
@ -234,8 +233,10 @@ auto EncryptEMLData(int channel, const QStringList& keys,
|
|||||||
std::static_pointer_cast<vmime::headerField>(backup_to_field_component);
|
std::static_pointer_cast<vmime::headerField>(backup_to_field_component);
|
||||||
|
|
||||||
auto backup_message_id_field_component =
|
auto backup_message_id_field_component =
|
||||||
header->getField<vmime::headerField>(vmime::fields::MESSAGE_ID)
|
header->hasField(vmime::fields::MESSAGE_ID)
|
||||||
->clone();
|
? header->getField<vmime::headerField>(vmime::fields::MESSAGE_ID)
|
||||||
|
->clone()
|
||||||
|
: nullptr;
|
||||||
|
|
||||||
std::shared_ptr<vmime::headerField> backup_message_id_field =
|
std::shared_ptr<vmime::headerField> backup_message_id_field =
|
||||||
std::static_pointer_cast<vmime::headerField>(
|
std::static_pointer_cast<vmime::headerField>(
|
||||||
@ -254,7 +255,9 @@ auto EncryptEMLData(int channel, const QStringList& keys,
|
|||||||
plain_part_header->appendField(backup_subject_field);
|
plain_part_header->appendField(backup_subject_field);
|
||||||
plain_part_header->appendField(backup_from_field);
|
plain_part_header->appendField(backup_from_field);
|
||||||
plain_part_header->appendField(backup_to_field);
|
plain_part_header->appendField(backup_to_field);
|
||||||
|
if (backup_message_id_field != nullptr) {
|
||||||
plain_part_header->appendField(backup_message_id_field);
|
plain_part_header->appendField(backup_message_id_field);
|
||||||
|
}
|
||||||
|
|
||||||
auto plain_header_raw_data =
|
auto plain_header_raw_data =
|
||||||
Q_SC(plain_part_header->generate(vmime::lineLengthLimits::convenient));
|
Q_SC(plain_part_header->generate(vmime::lineLengthLimits::convenient));
|
||||||
@ -265,22 +268,21 @@ auto EncryptEMLData(int channel, const QStringList& keys,
|
|||||||
plain_raw_data.replace("\r\n", "\n");
|
plain_raw_data.replace("\r\n", "\n");
|
||||||
plain_raw_data.replace("\n", "\r\n");
|
plain_raw_data.replace("\n", "\r\n");
|
||||||
|
|
||||||
GFGpgEncryptionResult* enc_result = nullptr;
|
GFGpgEncryptionResult* s = nullptr;
|
||||||
auto ret = GFGpgEncryptData(channel, QListToCharArray(keys), keys.size(),
|
auto ret = GFGpgEncryptData(channel, QListToCharArray(keys), keys.size(),
|
||||||
QDUP(plain_raw_data), 1, &enc_result);
|
QDUP(plain_raw_data), 1, &s);
|
||||||
|
|
||||||
|
auto encrypted_data = UDUP(s->encrypted_data);
|
||||||
|
capsule_id = UDUP(s->capsule_id);
|
||||||
|
auto gpg_error_string = UDUP(s->error_string);
|
||||||
|
|
||||||
|
GFFreeMemory(s);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
eml_data = "Encryption Failed";
|
eml_data = "Encryption Failed: " + gpg_error_string;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto encrypted_data = UDUP(enc_result->encrypted_data);
|
|
||||||
|
|
||||||
capsule_id = UDUP(enc_result->capsule_id);
|
|
||||||
FLOG_DEBUG("got capsule id: %1", capsule_id);
|
|
||||||
|
|
||||||
GFFreeMemory(enc_result);
|
|
||||||
|
|
||||||
// no Content-Transfer-Encoding
|
// no Content-Transfer-Encoding
|
||||||
header->removeField(
|
header->removeField(
|
||||||
header->getField(vmime::fields::CONTENT_TRANSFER_ENCODING));
|
header->getField(vmime::fields::CONTENT_TRANSFER_ENCODING));
|
||||||
@ -359,7 +361,7 @@ auto EncryptEMLData(int channel, const QStringList& keys,
|
|||||||
|
|
||||||
} catch (const vmime::exception& e) {
|
} catch (const vmime::exception& e) {
|
||||||
eml_data = QString("VMIME Error: %1").arg(e.what());
|
eml_data = QString("VMIME Error: %1").arg(e.what());
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
eml_data = QString("Unknown Error: %1");
|
eml_data = QString("Unknown Error: %1");
|
||||||
@ -555,7 +557,7 @@ auto SignPlainText(int channel, const QString& key,
|
|||||||
auto mime_part_part_body = mime_part->getBody();
|
auto mime_part_part_body = mime_part->getBody();
|
||||||
auto mime_part_body_content =
|
auto mime_part_body_content =
|
||||||
vmime::make_shared<vmime::stringContentHandler>();
|
vmime::make_shared<vmime::stringContentHandler>();
|
||||||
mime_part_body_content->setData(body_data.toBase64().toStdString());
|
mime_part_body_content->setData(body_data.toStdString());
|
||||||
mime_part_part_body->setContents(mime_part_body_content);
|
mime_part_part_body->setContents(mime_part_body_content);
|
||||||
|
|
||||||
auto container_raw_data =
|
auto container_raw_data =
|
||||||
@ -573,19 +575,18 @@ auto SignPlainText(int channel, const QString& key,
|
|||||||
auto ret = GFGpgSignData(channel, QListToCharArray({key}), 1,
|
auto ret = GFGpgSignData(channel, QListToCharArray({key}), 1,
|
||||||
QDUP(container_raw_data), 1, 1, &s);
|
QDUP(container_raw_data), 1, 1, &s);
|
||||||
|
|
||||||
if (ret != 0) {
|
|
||||||
eml_data = "Sign Failed";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto signature = UDUP(s->signature);
|
auto signature = UDUP(s->signature);
|
||||||
auto hash_algo = UDUP(s->hash_algo);
|
auto hash_algo = UDUP(s->hash_algo);
|
||||||
|
|
||||||
capsule_id = UDUP(s->capsule_id);
|
capsule_id = UDUP(s->capsule_id);
|
||||||
FLOG_DEBUG("got capsule id: %1", capsule_id);
|
auto gpg_error_string = UDUP(s->error_string);
|
||||||
|
|
||||||
GFFreeMemory(s);
|
GFFreeMemory(s);
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
eml_data = "Sign Failed: " + gpg_error_string;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
FLOG_DEBUG("Hash Algo: %1 Signature Data: %2", hash_algo, signature);
|
FLOG_DEBUG("Hash Algo: %1 Signature Data: %2", hash_algo, signature);
|
||||||
content_type_header_field->appendParameter(
|
content_type_header_field->appendParameter(
|
||||||
vmime::make_shared<vmime::parameter>(
|
vmime::make_shared<vmime::parameter>(
|
||||||
@ -606,7 +607,7 @@ auto SignPlainText(int channel, const QString& key,
|
|||||||
|
|
||||||
} catch (const vmime::exception& e) {
|
} catch (const vmime::exception& e) {
|
||||||
eml_data = QString("VMIME Error: %1").arg(e.what());
|
eml_data = QString("VMIME Error: %1").arg(e.what());
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
eml_data = QString("Unknown Error: %1");
|
eml_data = QString("Unknown Error: %1");
|
||||||
@ -791,19 +792,18 @@ auto SignEMLData(int channel, const QString& key,
|
|||||||
auto ret = GFGpgSignData(channel, QListToCharArray({key}), 1,
|
auto ret = GFGpgSignData(channel, QListToCharArray({key}), 1,
|
||||||
QDUP(container_raw_data), 1, 1, &s);
|
QDUP(container_raw_data), 1, 1, &s);
|
||||||
|
|
||||||
if (ret != 0) {
|
capsule_id = UDUP(s->capsule_id);
|
||||||
eml_data = "Sign Failed";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto signature = UDUP(s->signature);
|
auto signature = UDUP(s->signature);
|
||||||
auto hash_algo = UDUP(s->hash_algo);
|
auto hash_algo = UDUP(s->hash_algo);
|
||||||
|
auto gpg_error_string = UDUP(s->error_string);
|
||||||
capsule_id = UDUP(s->capsule_id);
|
|
||||||
FLOG_DEBUG("got capsule id: %1", capsule_id);
|
|
||||||
|
|
||||||
GFFreeMemory(s);
|
GFFreeMemory(s);
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
eml_data = "Sign Failed: " + gpg_error_string;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
FLOG_DEBUG("Hash Algo: %1 Signature Data: %2", hash_algo, signature);
|
FLOG_DEBUG("Hash Algo: %1 Signature Data: %2", hash_algo, signature);
|
||||||
content_type_header_field->appendParameter(
|
content_type_header_field->appendParameter(
|
||||||
vmime::make_shared<vmime::parameter>(
|
vmime::make_shared<vmime::parameter>(
|
||||||
@ -824,7 +824,7 @@ auto SignEMLData(int channel, const QString& key,
|
|||||||
|
|
||||||
} catch (const vmime::exception& e) {
|
} catch (const vmime::exception& e) {
|
||||||
eml_data = QString("VMIME Error: %1").arg(e.what());
|
eml_data = QString("VMIME Error: %1").arg(e.what());
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
eml_data = QString("Unknown Error: %1");
|
eml_data = QString("Unknown Error: %1");
|
||||||
@ -1018,16 +1018,16 @@ auto VerifyEMLData(int channel, const QByteArray& data,
|
|||||||
auto ret = GFGpgVerifyData(channel, QDUP(part_mime_content_text),
|
auto ret = GFGpgVerifyData(channel, QDUP(part_mime_content_text),
|
||||||
QDUP(part_sign_body_content), &s);
|
QDUP(part_sign_body_content), &s);
|
||||||
|
|
||||||
if (ret != 0) {
|
|
||||||
error_string = "Verify Failed";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
capsule_id = UDUP(s->capsule_id);
|
capsule_id = UDUP(s->capsule_id);
|
||||||
FLOG_DEBUG("got capsule id: %1", capsule_id);
|
auto gpg_error_string = UDUP(s->error_string);
|
||||||
|
|
||||||
GFFreeMemory(s);
|
GFFreeMemory(s);
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
error_string = "Verify Failed: " + gpg_error_string;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
meta_data.from = from_field_value_text;
|
meta_data.from = from_field_value_text;
|
||||||
meta_data.to = to_field_value_text.split(',');
|
meta_data.to = to_field_value_text.split(',');
|
||||||
meta_data.cc = cc_field_value_text.split(',');
|
meta_data.cc = cc_field_value_text.split(',');
|
||||||
@ -1189,18 +1189,17 @@ auto DecryptEMLData(int channel, const QByteArray& data,
|
|||||||
GFGpgDecryptResult* s;
|
GFGpgDecryptResult* s;
|
||||||
auto ret = GFGpgDecryptData(channel, QDUP(part_encr_body_content), &s);
|
auto ret = GFGpgDecryptData(channel, QDUP(part_encr_body_content), &s);
|
||||||
|
|
||||||
if (ret != 0) {
|
|
||||||
eml_data = "Ddecrypt Failed";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
eml_data = UDUP(s->decrypted_data);
|
eml_data = UDUP(s->decrypted_data);
|
||||||
|
|
||||||
capsule_id = UDUP(s->capsule_id);
|
capsule_id = UDUP(s->capsule_id);
|
||||||
FLOG_DEBUG("got capsule id: %1", capsule_id);
|
auto gpg_error_string = UDUP(s->error_string);
|
||||||
|
|
||||||
GFFreeMemory(s);
|
GFFreeMemory(s);
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
eml_data = "Decrypt Failed: " + gpg_error_string;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// callback
|
// callback
|
||||||
meta_data.from = from_field_value_text;
|
meta_data.from = from_field_value_text;
|
||||||
meta_data.to = to_field_value_text.split(',');
|
meta_data.to = to_field_value_text.split(',');
|
||||||
|
Loading…
Reference in New Issue
Block a user