summaryrefslogtreecommitdiff
path: root/src/remoteauth/remoteauthclient.hpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2023-07-13 07:19:37 +0000
committerGitHub <noreply@github.com>2023-07-13 07:19:37 +0000
commit337a3d5811b55994ca7db97fea94f6b96dfaf57c (patch)
tree9ae7c7c0cc4dcab669fad94546dc7b12e0eda681 /src/remoteauth/remoteauthclient.hpp
parent9a3f6b472d4995c0d5619edc185836f7abb3bc15 (diff)
parent5bf5cc75eb8cffb3aed44a6743f1bb87a7b2b00d (diff)
downloadabaddon-portaudio-337a3d5811b55994ca7db97fea94f6b96dfaf57c.tar.gz
abaddon-portaudio-337a3d5811b55994ca7db97fea94f6b96dfaf57c.zip
Merge pull request #185 from uowuo/remoteauth
Login with QR code/remote auth
Diffstat (limited to 'src/remoteauth/remoteauthclient.hpp')
-rw-r--r--src/remoteauth/remoteauthclient.hpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/remoteauth/remoteauthclient.hpp b/src/remoteauth/remoteauthclient.hpp
new file mode 100644
index 0000000..6ab6dbb
--- /dev/null
+++ b/src/remoteauth/remoteauthclient.hpp
@@ -0,0 +1,95 @@
+#pragma once
+
+#ifdef WITH_QRLOGIN
+
+// clang-format off
+
+#include <string>
+#include <queue>
+#include <spdlog/logger.h>
+#include "ssl.hpp"
+#include "discord/waiter.hpp"
+#include "discord/websocket.hpp"
+
+// clang-format on
+
+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 HandleGatewayPendingLogin(const nlohmann::json &j);
+ void HandleGatewayCancel(const nlohmann::json &j);
+
+ void OnRemoteAuthLoginResponse(const std::optional<std::string> &encrypted_token, DiscordError err);
+
+ 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();
+
+ bool OnTimeout();
+ sigc::connection m_timeout_conn;
+
+ 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_hello = sigc::signal<void()>;
+ using type_signal_fingerprint = sigc::signal<void(std::string)>;
+ using type_signal_pending_ticket = sigc::signal<void(Snowflake, std::string, std::string, std::string)>;
+ using type_signal_pending_login = sigc::signal<void()>;
+ using type_signal_token = sigc::signal<void(std::string)>;
+ using type_signal_error = sigc::signal<void(std::string)>;
+ type_signal_hello signal_hello();
+ type_signal_fingerprint signal_fingerprint();
+ type_signal_pending_ticket signal_pending_ticket();
+ type_signal_pending_login signal_pending_login();
+ type_signal_token signal_token();
+ type_signal_error signal_error();
+
+private:
+ type_signal_hello m_signal_hello;
+ type_signal_fingerprint m_signal_fingerprint;
+ type_signal_pending_ticket m_signal_pending_ticket;
+ type_signal_pending_login m_signal_pending_login;
+ type_signal_token m_signal_token;
+ type_signal_error m_signal_error;
+};
+
+#endif