Page MenuHomePhabricator

D3245.diff
No OneTemporary

D3245.diff

diff --git a/services/backup/docker-server/contents/server/CMakeLists.txt b/services/backup/docker-server/contents/server/CMakeLists.txt
--- a/services/backup/docker-server/contents/server/CMakeLists.txt
+++ b/services/backup/docker-server/contents/server/CMakeLists.txt
@@ -51,6 +51,7 @@
include_directories(
./src
./src/DatabaseEntities
+ ./src/Authentication
./_generated
${FOLLY_INCLUDES}
./lib/double-conversion
diff --git a/services/backup/docker-server/contents/server/src/Authentication/AuthenticationHandlerBase.h b/services/backup/docker-server/contents/server/src/Authentication/AuthenticationHandlerBase.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Authentication/AuthenticationHandlerBase.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "../_generated/backup.pb.h"
+
+#include <google/protobuf/message.h>
+
+#include <memory>
+#include <string>
+
+namespace comm {
+namespace network {
+namespace auth {
+
+enum class AuthenticationType {
+ PAKE = 1,
+ WALLET = 2,
+};
+
+/**
+ * every state resources have to be synchronized
+ * the threads that will access them will be executed sequentially but we still
+ * need to synchronize
+ * https://stackoverflow.com/questions/22798873/visibility-in-concurrent-c-programs
+ */
+class AuthenticationHandlerBase {
+public:
+ virtual backup::FullAuthenticationResponseData*
+ processRequest(const backup::FullAuthenticationRequestData &request) = 0;
+ virtual AuthenticationType getAuthenticationType() const = 0;
+};
+
+} // namespace auth
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/Authentication/AuthenticationManager.h b/services/backup/docker-server/contents/server/src/Authentication/AuthenticationManager.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Authentication/AuthenticationManager.h
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "AuthenticationHandlerBase.h"
+
+#include "../_generated/backup.pb.h"
+
+#include <atomic>
+#include <memory>
+
+namespace comm {
+namespace network {
+namespace auth {
+
+enum class AuthenticationState {
+ IN_PROGRESS = 1,
+ SUCCESS = 2,
+ FAIL = 3,
+};
+
+class AuthenticationManager {
+ std::atomic<AuthenticationState> state = AuthenticationState::IN_PROGRESS;
+ std::unique_ptr<AuthenticationHandlerBase> authenticationHandler;
+
+ AuthenticationType getAuthenticationTypeForRequest(
+ const backup::FullAuthenticationRequestData &request) const;
+
+public:
+ AuthenticationState getState() const;
+ backup::FullAuthenticationResponseData*
+ processRequest(const backup::FullAuthenticationRequestData &request);
+};
+
+} // namespace auth
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/Authentication/AuthenticationManager.cpp b/services/backup/docker-server/contents/server/src/Authentication/AuthenticationManager.cpp
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Authentication/AuthenticationManager.cpp
@@ -0,0 +1,47 @@
+#include "AuthenticationManager.h"
+
+#include "PakeAuthenticationHandler.h"
+#include "WalletAuthenticationHandler.h"
+
+namespace comm {
+namespace network {
+namespace auth {
+
+AuthenticationState AuthenticationManager::getState() const {
+ return this->state;
+}
+
+AuthenticationType AuthenticationManager::getAuthenticationTypeForRequest(
+ const backup::FullAuthenticationRequestData &request) const {
+ if (request.has_pakeauthenticationrequestdata()) {
+ return AuthenticationType::PAKE;
+ } else if (request.has_walletauthenticationrequestdata()) {
+ return AuthenticationType::WALLET;
+ }
+ throw std::runtime_error("invalid authentication type detected");
+}
+
+backup::FullAuthenticationResponseData* AuthenticationManager::processRequest(
+ const backup::FullAuthenticationRequestData &request) {
+ if (this->authenticationHandler == nullptr) {
+ AuthenticationType authenticationType =
+ this->getAuthenticationTypeForRequest(request);
+ if (authenticationType == AuthenticationType::PAKE) {
+ this->authenticationHandler =
+ std::make_unique<PakeAuthenticationHandler>(authenticationType);
+ } else if (authenticationType == AuthenticationType::WALLET) {
+ this->authenticationHandler =
+ std::make_unique<WalletAuthenticationHandler>(authenticationType);
+ }
+ } else if (
+ this->authenticationHandler->getAuthenticationType() !=
+ this->getAuthenticationTypeForRequest(request)) {
+ throw std::runtime_error("inconsistent authentication detected");
+ }
+
+ return this->authenticationHandler->processRequest(request);
+}
+
+} // namespace auth
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/Authentication/PakeAuthenticationHandler.h b/services/backup/docker-server/contents/server/src/Authentication/PakeAuthenticationHandler.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Authentication/PakeAuthenticationHandler.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "AuthenticationHandlerBase.h"
+
+#include <string>
+
+namespace comm {
+namespace network {
+namespace auth {
+
+class PakeAuthenticationHandler : public AuthenticationHandlerBase {
+ const AuthenticationType authenticationType;
+
+public:
+ PakeAuthenticationHandler(AuthenticationType authenticationType);
+
+ backup::FullAuthenticationResponseData*
+ processRequest(const backup::FullAuthenticationRequestData &request) override;
+ AuthenticationType getAuthenticationType() const override;
+};
+
+} // namespace auth
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/Authentication/PakeAuthenticationHandler.cpp b/services/backup/docker-server/contents/server/src/Authentication/PakeAuthenticationHandler.cpp
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Authentication/PakeAuthenticationHandler.cpp
@@ -0,0 +1,23 @@
+#include "PakeAuthenticationHandler.h"
+
+namespace comm {
+namespace network {
+namespace auth {
+
+PakeAuthenticationHandler::PakeAuthenticationHandler(
+ AuthenticationType authenticationType) : authenticationType(authenticationType) {}
+
+backup::FullAuthenticationResponseData*
+PakeAuthenticationHandler::processRequest(
+ const backup::FullAuthenticationRequestData &request) {
+ return new backup::FullAuthenticationResponseData();
+}
+
+AuthenticationType
+PakeAuthenticationHandler::getAuthenticationType() const {
+ return this->authenticationType;
+}
+
+} // namespace auth
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/Authentication/WalletAuthenticationHandler.h b/services/backup/docker-server/contents/server/src/Authentication/WalletAuthenticationHandler.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Authentication/WalletAuthenticationHandler.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "AuthenticationHandlerBase.h"
+
+#include <string>
+
+namespace comm {
+namespace network {
+namespace auth {
+
+class WalletAuthenticationHandler : public AuthenticationHandlerBase {
+ const AuthenticationType authenticationType;
+
+public:
+ WalletAuthenticationHandler(AuthenticationType authenticationType);
+
+ backup::FullAuthenticationResponseData*
+ processRequest(const backup::FullAuthenticationRequestData &request) override;
+ AuthenticationType getAuthenticationType() const override;
+};
+
+} // namespace auth
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/Authentication/WalletAuthenticationHandler.cpp b/services/backup/docker-server/contents/server/src/Authentication/WalletAuthenticationHandler.cpp
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Authentication/WalletAuthenticationHandler.cpp
@@ -0,0 +1,24 @@
+#include "WalletAuthenticationHandler.h"
+
+namespace comm {
+namespace network {
+namespace auth {
+
+WalletAuthenticationHandler::WalletAuthenticationHandler(
+ AuthenticationType authenticationType)
+ : authenticationType(authenticationType) {
+}
+
+backup::FullAuthenticationResponseData*
+WalletAuthenticationHandler::processRequest(
+ const backup::FullAuthenticationRequestData &request) {
+ return new backup::FullAuthenticationResponseData();
+}
+
+AuthenticationType WalletAuthenticationHandler::getAuthenticationType() const {
+ return this->authenticationType;
+}
+
+} // namespace auth
+} // namespace network
+} // namespace comm

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 12:32 PM (21 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2575580
Default Alt Text
D3245.diff (8 KB)

Event Timeline