From b285768fcef4a8d8b5e483622b11c58c3c85ecdb Mon Sep 17 00:00:00 2001 From: Dario Date: Mon, 8 Jun 2020 13:40:21 +0200 Subject: [PATCH] add AuthenticatedEncryptionCreateKeyTask for running password creation in background --- .../AuthenticatedEncryptionCreateKeyTask.cpp | 33 +++++++++++++++++++ .../AuthenticatedEncryptionCreateKeyTask.h | 20 +++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.cpp create mode 100644 src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.h diff --git a/src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.cpp b/src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.cpp new file mode 100644 index 000000000..6f17d8894 --- /dev/null +++ b/src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.cpp @@ -0,0 +1,33 @@ +#include "AuthenticatedEncryptionCreateKeyTask.h" + +#include "../ServerConfig.h" +#include "../SingletonManager/SingletonTaskObserver.h" +#include "../SingletonManager/ErrorManager.h" + +AuthenticatedEncryptionCreateKeyTask::AuthenticatedEncryptionCreateKeyTask(Poco::AutoPtr user, const std::string& passwd) + : UniLib::controller::CPUTask(ServerConfig::g_CryptoCPUScheduler), mUser(user), mPassword(passwd) +{ + SingletonTaskObserver::getInstance()->addTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION); +} + +AuthenticatedEncryptionCreateKeyTask::~AuthenticatedEncryptionCreateKeyTask() +{ + SingletonTaskObserver::getInstance()->removeTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION); +} + +int AuthenticatedEncryptionCreateKeyTask::run() +{ + auto em = ErrorManager::getInstance(); + const static char* function_name = "AuthenticatedEncryptionCreateKeyTask::run"; + auto authenticated_encryption = new AuthenticatedEncryption; + if (AuthenticatedEncryption::AUTH_ENCRYPT_OK != authenticated_encryption->createKey(mUser->getModel()->getEmail(), mPassword)) { + em->addError(new Error(function_name, "error creating key")); + em->addError(new ParamError(function_name, "for email", mUser->getModel()->getEmail())); + em->addError(new ParamError(function_name, "strerror: ", strerror(errno))); + em->sendErrorsAsEmail(); + return -1; + } + mUser->setPassword(authenticated_encryption); + + return 0; +} \ No newline at end of file diff --git a/src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.h b/src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.h new file mode 100644 index 000000000..198403a71 --- /dev/null +++ b/src/cpp/tasks/AuthenticatedEncryptionCreateKeyTask.h @@ -0,0 +1,20 @@ +#ifndef __GRADIDO_LOGIN_SERVER_TASKS_AUTHENTICATED_ENCRYPTION_CREATE_KEY_TASK_H +#define __GRADIDO_LOGIN_SERVER_TASKS_AUTHENTICATED_ENCRYPTION_CREATE_KEY_TASK_H + +#include "CPUTask.h" +#include "../controller/User.h" + +class AuthenticatedEncryptionCreateKeyTask : public UniLib::controller::CPUTask +{ +public: + AuthenticatedEncryptionCreateKeyTask(Poco::AutoPtr user, const std::string& passwd); + virtual ~AuthenticatedEncryptionCreateKeyTask(); + + int run(); + const char* getResourceType() const { return "AuthenticatedEncryptionCreateKeyTask"; }; +protected: + Poco::AutoPtr mUser; + std::string mPassword; +}; + +#endif //__GRADIDO_LOGIN_SERVER_TASKS_AUTHENTICATED_ENCRYPTION_CREATE_KEY_TASK_H \ No newline at end of file