diff --git a/client/crypt.h b/client/crypt.h index cd30422..57041b3 100644 --- a/client/crypt.h +++ b/client/crypt.h @@ -1 +1,7 @@ -namespace pupes_message_client_lib {} \ No newline at end of file +#ifndef PM_CRYPT_H +#define PM_CRYPT_H +#include +namespace pupes_message_client_lib { +EVP_PKEY *generate_keypair(); +} +#endif \ No newline at end of file diff --git a/client/flow_help.cpp b/client/flow_help.cpp index 4d0f186..1911c5a 100644 --- a/client/flow_help.cpp +++ b/client/flow_help.cpp @@ -1,14 +1,13 @@ #include "../common/color.h" +#include "crypt.h" #include #include #include #include -#include #include #include #include #include -# namespace pupes_message_client_lib { void error(std::string msg) { @@ -51,8 +50,7 @@ EVP_PKEY *SaveOrGetKeypair(EVP_PKEY *keypair = nullptr) { std::clog << BLUE "[LOG]" RESET " Private key file not found. Generating a new keypair.\n"; - - return nullptr; + return generate_keypair(); } error("Failed to open private key file for reading.\n"); } diff --git a/client/global_vars.h b/client/global_vars.h index 94c98f6..e87121a 100644 --- a/client/global_vars.h +++ b/client/global_vars.h @@ -6,4 +6,5 @@ extern void (*receive_callback)(std::vector, std::string); extern SSL_CTX *ctx_global; extern SSL *ssl_global; extern int sockfd_global; +extern EVP_PKEY *keypair_global; #endif \ No newline at end of file diff --git a/client/init.cpp b/client/init.cpp index da7b422..77a1e83 100644 --- a/client/init.cpp +++ b/client/init.cpp @@ -1,10 +1,14 @@ #include "init.h" +#include "crypt.h" +#include "flow_help.h" #include "global_vars.h" #include "ssl.h" #include "tcp.h" #include "types.h" #include +EVP_PKEY *keypair_global; + void (*receive_callback)(std::vector, std::string) = nullptr; SSL_CTX *ctx_global = nullptr; SSL *ssl_global = nullptr; @@ -14,6 +18,7 @@ namespace pupes_message_client_lib { void init(const char *hostname, const char *port) { OpenSSL_add_all_algorithms(); + keypair_global = pupes_message_client_lib::SaveOrGetKeypair(); ctx_global = pupes_message_client_lib::InitTLS();