summaryrefslogtreecommitdiff
path: root/src/remoteauth/remoteauthclient.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/remoteauth/remoteauthclient.hpp')
-rw-r--r--src/remoteauth/remoteauthclient.hpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/remoteauth/remoteauthclient.hpp b/src/remoteauth/remoteauthclient.hpp
new file mode 100644
index 0000000..178e10a
--- /dev/null
+++ b/src/remoteauth/remoteauthclient.hpp
@@ -0,0 +1,64 @@
+#pragma once
+#include <string>
+#include <queue>
+#include <spdlog/logger.h>
+#include "ssl.hpp"
+#include "discord/waiter.hpp"
+#include "discord/websocket.hpp"
+
+class RemoteAuthClient {
+public:
+ RemoteAuthClient();
+ ~RemoteAuthClient();
+
+ void Start();
+ void Stop();
+
+ [[nodiscard]] bool IsConnected() const noexcept;
+
+private:
+ void OnGatewayMessage(const std::string &str);
+ void HandleGatewayHello(const nlohmann::json &j);
+ void HandleGatewayNonceProof(const nlohmann::json &j);
+ void HandleGatewayPendingRemoteInit(const nlohmann::json &j);
+ void HandleGatewayPendingTicket(const nlohmann::json &j);
+
+ void Init();
+
+ void GenerateKey();
+ std::string GetEncodedPublicKey() const;
+
+ std::vector<uint8_t> Decrypt(const unsigned char *in, size_t inlen) const;
+
+ void OnWebsocketOpen();
+ void OnWebsocketClose(const ix::WebSocketCloseInfo &info);
+ void OnWebsocketMessage(const std::string &str);
+
+ void HeartbeatThread();
+
+ int m_heartbeat_msec;
+ Waiter m_heartbeat_waiter;
+ std::thread m_heartbeat_thread;
+
+ Glib::Dispatcher m_dispatcher;
+ std::queue<std::string> m_dispatch_queue;
+ std::mutex m_dispatch_mutex;
+
+ void OnDispatch();
+
+ Websocket m_ws;
+ bool m_connected = false;
+
+ std::shared_ptr<spdlog::logger> m_log;
+
+ EVP_PKEY_CTX_ptr m_pkey_ctx;
+ EVP_PKEY_CTX_ptr m_dec_ctx;
+ EVP_PKEY_ptr m_pkey;
+
+public:
+ using type_signal_fingerprint = sigc::signal<void(std::string)>;
+ type_signal_fingerprint signal_fingerprint();
+
+private:
+ type_signal_fingerprint m_signal_fingerprint;
+};