send errors to community server from prepare transaction

This commit is contained in:
Dario 2020-08-21 17:02:17 +02:00
parent 76350d5038
commit de11450c90
3 changed files with 59 additions and 6 deletions

View File

@ -640,7 +640,12 @@ bool Session::startProcessingTransaction(const std::string& proto_message_base64
return false;
}
Poco::AutoPtr<ProcessingTransaction> processorTask(new ProcessingTransaction(proto_message_base64, DRMakeStringHash(mSessionUser->getEmail())));
Poco::AutoPtr<ProcessingTransaction> processorTask(
new ProcessingTransaction(
proto_message_base64,
DRMakeStringHash(mSessionUser->getEmail()),
mSessionUser->getLanguage())
);
processorTask->scheduleTask(processorTask);
mProcessingTransactions.push_back(processorTask);
unlock();

View File

@ -1,4 +1,4 @@
#include "ProcessingTransaction.h"
#include "ProcessingTransaction.h"
#include <sodium.h>
#include "../model/TransactionCreation.h"
@ -6,8 +6,12 @@
#include "../SingletonManager/SingletonTaskObserver.h"
ProcessingTransaction::ProcessingTransaction(const std::string& proto_message_base64, DHASH userEmailHash)
: mType(TRANSACTION_NONE), mProtoMessageBase64(proto_message_base64), mTransactionSpecific(nullptr), mUserEmailHash(userEmailHash)
#include "../lib/DataTypeConverter.h"
#include "../lib/JsonRequest.h"
ProcessingTransaction::ProcessingTransaction(const std::string& proto_message_base64, DHASH userEmailHash, Languages lang)
: mType(TRANSACTION_NONE), mProtoMessageBase64(proto_message_base64), mTransactionSpecific(nullptr), mUserEmailHash(userEmailHash),
mLang(lang)
{
mHashMutex.lock();
mHash = calculateHash(proto_message_base64);
@ -39,6 +43,37 @@ HASH ProcessingTransaction::calculateHash(const std::string& proto_message_base6
return DRMakeStringHash(proto_message_base64.data(), proto_message_base64.size());
}
std::string ProcessingTransaction::calculateGenericHash(const std::string& protoMessageBase64)
{
auto mm = MemoryManager::getInstance();
auto hash = mm->getFreeMemory(crypto_generichash_BYTES);
crypto_generichash(*hash, sizeof(DHASH), (const unsigned char*)protoMessageBase64.data(), protoMessageBase64.size(), NULL, 0);
std::string base64HashString = DataTypeConverter::binToBase64(hash);
mm->releaseMemory(hash);
return base64HashString;
}
void ProcessingTransaction::reportErrorToCommunityServer(std::string error, std::string errorDetails, std::string created)
{
auto transaction_hash = calculateGenericHash(mProtoMessageBase64);
JsonRequest phpServerRequest(ServerConfig::g_php_serverHost, ServerConfig::g_phpServerPort);
Poco::Net::NameValueCollection payload;
payload.set("created", created);
payload.set("transactionGenericHash", transaction_hash);
payload.set("error", error);
payload.set("errorMessage", errorDetails);
auto ret = phpServerRequest.request("errorInTransaction", payload);
if (ret == JSON_REQUEST_RETURN_ERROR) {
addError(new Error("ProcessingTransaction::reportErrorToCommunityServer", "php server error"));
getErrors(&phpServerRequest);
sendErrorsAsEmail();
}
}
int ProcessingTransaction::run()
{
lock();
@ -46,6 +81,9 @@ int ProcessingTransaction::run()
unsigned char* binBuffer = (unsigned char*)malloc(mProtoMessageBase64.size());
size_t resultingBinSize = 0;
size_t base64_size = mProtoMessageBase64.size();
auto langM = LanguageManager::getInstance();
auto catalog = langM->getFreeCatalog(mLang);
if (sodium_base642bin(
binBuffer, base64_size,
mProtoMessageBase64.data(), base64_size,
@ -54,6 +92,7 @@ int ProcessingTransaction::run()
{
free(binBuffer);
addError(new Error("ProcessingTransaction", "error decoding base64"));
reportErrorToCommunityServer(catalog->gettext("decoding error"), catalog->gettext("Error decoding base64 string"), "-1");
unlock();
return -1;
}
@ -61,6 +100,7 @@ int ProcessingTransaction::run()
free(binBuffer);
if (!mTransactionBody.ParseFromString(binString)) {
addError(new Error("ProcessingTransaction", "error creating Transaction from binary Message"));
reportErrorToCommunityServer(catalog->gettext("decoding error"), catalog->gettext("Error by parsing to protobuf message"), "-1");
unlock();
return -2;
}
@ -78,6 +118,7 @@ int ProcessingTransaction::run()
if (mTransactionSpecific->prepare()) {
getErrors(mTransactionSpecific);
addError(new Error("ProcessingTransaction", "error preparing"));
reportErrorToCommunityServer(catalog->gettext("format error"), catalog->gettext("format of specific transaction not known, wrong proto version?"), std::to_string(mTransactionBody.created().seconds()));
unlock();
return -3;
}

View File

@ -9,6 +9,8 @@
#include "../proto/gradido/TransactionBody.pb.h"
#include "../SingletonManager/LanguageManager.h"
/*
* @author: Dario Rekowski
*
@ -30,7 +32,8 @@ class ProcessingTransaction : public UniLib::controller::CPUTask, public ErrorLi
{
friend SigningTransaction;
public:
ProcessingTransaction(const std::string& proto_message_base64, DHASH userEmailHash);
//! \param lang for error messages in user language
ProcessingTransaction(const std::string& proto_message_base64, DHASH userEmailHash, Languages lang);
virtual ~ProcessingTransaction();
int run();
@ -48,11 +51,15 @@ public:
TransactionTransfer* getTransferTransaction();
static HASH calculateHash(const std::string& proto_message_base64);
static std::string calculateGenericHash(const std::string& protoMessageBase64);
inline HASH getHash() { mHashMutex.lock(); HASH hs = mHash; mHashMutex.unlock(); return hs; }
std::string getBodyBytes();
protected:
void reportErrorToCommunityServer(std::string error, std::string errorDetails, std::string created);
TransactionType mType;
std::string mProtoMessageBase64;
@ -61,7 +68,7 @@ protected:
HASH mHash;
DHASH mUserEmailHash;
Languages mLang;
Poco::Mutex mHashMutex;
private: