summaryrefslogtreecommitdiff
path: root/src/remoteauth/remoteauthclient.hpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2023-06-30 20:43:08 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2023-06-30 20:43:08 -0400
commit3b206e11216b383fae0e860e0092f71301fd4425 (patch)
tree857c4fbd120ffe37bef5a108dcbe5e322a45ae14 /src/remoteauth/remoteauthclient.hpp
parentec6f18ff1204889afd63f08f255d00ae3a1ef12b (diff)
downloadabaddon-portaudio-3b206e11216b383fae0e860e0092f71301fd4425.tar.gz
abaddon-portaudio-3b206e11216b383fae0e860e0092f71301fd4425.zip
remote auth impl. up to QR code display
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;
+};