From eb3fe7ae6f3beb9733d992ef5f313f2d5d515ba4 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 21 Apr 2023 16:47:50 +0200 Subject: [PATCH] Prepare openssl key export --- src/client/component/discord.cpp | 6 ++++-- src/common/utils/cryptography.cpp | 15 ++++++++++++++- src/common/utils/cryptography.hpp | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/client/component/discord.cpp b/src/client/component/discord.cpp index 421fe889..e8cabdf1 100644 --- a/src/client/component/discord.cpp +++ b/src/client/component/discord.cpp @@ -9,9 +9,11 @@ namespace discord { namespace { - void ready(const DiscordUser* /*request*/) + void ready(const DiscordUser* request) { - printf("Discord: Ready\n"); + SetEnvironmentVariableA("discord_user", request->userId); + + printf("Discord: Ready: %s - %s\n", request->userId, request->username); DiscordRichPresence discord_presence{}; ZeroMemory(&discord_presence, sizeof(discord_presence)); diff --git a/src/common/utils/cryptography.cpp b/src/common/utils/cryptography.cpp index 98f61550..824cb9a7 100644 --- a/src/common/utils/cryptography.cpp +++ b/src/common/utils/cryptography.cpp @@ -229,7 +229,20 @@ namespace utils::cryptography if (ecc_export(buffer, &length, type, &this->key_storage_) == CRYPT_OK) { - return std::string(cs(buffer), length); + return {cs(buffer), length}; + } + + return ""; + } + + std::string ecc::key::get_openssl() const + { + uint8_t buffer[4096] = {0}; + unsigned long length = sizeof(buffer); + + if (ecc_export_openssl(buffer, &length, PK_PUBLIC, &this->key_storage_) == CRYPT_OK) + { + return {cs(buffer), length}; } return ""; diff --git a/src/common/utils/cryptography.hpp b/src/common/utils/cryptography.hpp index 9538c5eb..456a950b 100644 --- a/src/common/utils/cryptography.hpp +++ b/src/common/utils/cryptography.hpp @@ -31,6 +31,8 @@ namespace utils::cryptography std::string serialize(int type = PK_PRIVATE) const; + std::string get_openssl() const; + void free(); bool operator==(key& key) const;