From ca25e257ef1c8a37814a1c0cb2910be3ab193abd Mon Sep 17 00:00:00 2001 From: pokamest Date: Sun, 17 Oct 2021 07:00:00 -0700 Subject: [PATCH] OpenSSL libs added for Linux --- client/client.pro | 5 ++++ client/configurators/openvpn_configurator.cpp | 28 +++++++++++-------- .../configurators/wireguard_configurator.cpp | 2 +- client/core/defs.h | 2 +- client/core/errorstrings.cpp | 2 +- client/debug.cpp | 5 ++-- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/client/client.pro b/client/client.pro index b0e78f19..0c627ff3 100644 --- a/client/client.pro +++ b/client/client.pro @@ -186,6 +186,11 @@ macx { LIBS += -framework Cocoa -framework ApplicationServices -framework CoreServices -framework Foundation -framework AppKit -framework Security } +linux:!android { + LIBS += /usr/lib/x86_64-linux-gnu/libcrypto.a + LIBS += /usr/lib/x86_64-linux-gnu/libssl.a +} + android { QT += androidextras diff --git a/client/configurators/openvpn_configurator.cpp b/client/configurators/openvpn_configurator.cpp index 722cfc59..3ebfefcc 100644 --- a/client/configurators/openvpn_configurator.cpp +++ b/client/configurators/openvpn_configurator.cpp @@ -23,7 +23,7 @@ OpenVpnConfigurator::ConnectionData OpenVpnConfigurator::prepareOpenVpnConfig(co connData.host = credentials.hostName; if (connData.privKey.isEmpty() || connData.request.isEmpty()) { - if (errorCode) *errorCode = ErrorCode::EasyRsaExecutableMissing; + if (errorCode) *errorCode = ErrorCode::OpenSslFailed; return connData; } @@ -188,7 +188,9 @@ OpenVpnConfigurator::ConnectionData OpenVpnConfigurator::createCertRequest() ret = X509_REQ_set_version(x509_req, nVersion); if (ret != 1) { qWarning() << "Could not get X509!"; - goto free_all; + X509_REQ_free(x509_req); + EVP_PKEY_free(pKey); + return connData; } // 3. set subject of x509 req @@ -205,14 +207,18 @@ OpenVpnConfigurator::ConnectionData OpenVpnConfigurator::createCertRequest() ret = X509_REQ_set_pubkey(x509_req, pKey); if (ret != 1){ qWarning() << "Could not set pubkey!"; - goto free_all; + X509_REQ_free(x509_req); + EVP_PKEY_free(pKey); + return connData; } // 5. set sign key of x509 req ret = X509_REQ_sign(x509_req, pKey, EVP_sha256()); // return x509_req->signature->length if (ret <= 0){ qWarning() << "Could not sign request!"; - goto free_all; + X509_REQ_free(x509_req); + EVP_PKEY_free(pKey); + return connData; } // save private key @@ -220,9 +226,11 @@ OpenVpnConfigurator::ConnectionData OpenVpnConfigurator::createCertRequest() q_check_ptr(bp_private); if (PEM_write_bio_PrivateKey(bp_private, pKey, nullptr, nullptr, 0, nullptr, nullptr) != 1) { + qFatal("PEM_write_bio_PrivateKey"); EVP_PKEY_free(pKey); BIO_free_all(bp_private); - qFatal("PEM_write_bio_PrivateKey"); + X509_REQ_free(x509_req); + return connData; } const char * buffer = nullptr; @@ -231,6 +239,10 @@ OpenVpnConfigurator::ConnectionData OpenVpnConfigurator::createCertRequest() connData.privKey = QByteArray(buffer, size); if (connData.privKey.isEmpty()) { qFatal("Failed to generate a random private key"); + EVP_PKEY_free(pKey); + BIO_free_all(bp_private); + X509_REQ_free(x509_req); + return connData; } BIO_free_all(bp_private); @@ -246,11 +258,5 @@ OpenVpnConfigurator::ConnectionData OpenVpnConfigurator::createCertRequest() EVP_PKEY_free(pKey); // this will also free the rsa key - return connData; - -free_all: - X509_REQ_free(x509_req); - EVP_PKEY_free(pKey); - return connData; } diff --git a/client/configurators/wireguard_configurator.cpp b/client/configurators/wireguard_configurator.cpp index 2f63e5dd..7e7e5bda 100644 --- a/client/configurators/wireguard_configurator.cpp +++ b/client/configurators/wireguard_configurator.cpp @@ -89,7 +89,7 @@ WireguardConfigurator::ConnectionData WireguardConfigurator::prepareWireguardCon connData.host = credentials.hostName; if (connData.clientPrivKey.isEmpty() || connData.clientPubKey.isEmpty()) { - if (errorCode) *errorCode = ErrorCode::EasyRsaExecutableMissing; + if (errorCode) *errorCode = ErrorCode::InternalError; return connData; } diff --git a/client/core/defs.h b/client/core/defs.h index 6df97d31..ec04e840 100644 --- a/client/core/defs.h +++ b/client/core/defs.h @@ -49,7 +49,6 @@ enum ErrorCode // Distro errors OpenVpnExecutableMissing, - EasyRsaExecutableMissing, ShadowSocksExecutableMissing, CloakExecutableMissing, AmneziaServiceConnectionFailed, @@ -61,6 +60,7 @@ enum ErrorCode OpenVpnTapAdapterError, // 3rd party utils errors + OpenSslFailed, OpenVpnExecutableCrashed, ShadowSocksExecutableCrashed, CloakExecutableCrashed diff --git a/client/core/errorstrings.cpp b/client/core/errorstrings.cpp index bbf5cea4..ceeb47ab 100644 --- a/client/core/errorstrings.cpp +++ b/client/core/errorstrings.cpp @@ -39,8 +39,8 @@ QString errorString(ErrorCode code){ // Distro errors case (OpenVpnExecutableMissing): return QObject::tr("OpenVPN executable missing"); - case (EasyRsaExecutableMissing): return QObject::tr("EasyRsa executable missing"); case (AmneziaServiceConnectionFailed): return QObject::tr("Amnezia helper service error"); + case (OpenSslFailed): return QObject::tr("OpenSSL failed"); // VPN errors case (OpenVpnAdaptersInUseError): return QObject::tr("Can't connect: another VPN connection is active"); diff --git a/client/debug.cpp b/client/debug.cpp index 466c226f..c9315ae7 100644 --- a/client/debug.cpp +++ b/client/debug.cpp @@ -3,12 +3,12 @@ #include #include #include -#include #include #include "debug.h" #include "defines.h" +#include "utils.h" QFile Debug::m_file; QTextStream Debug::m_textStream; @@ -34,7 +34,6 @@ bool Debug::init() { qSetMessagePattern("%{time yyyy-MM-dd hh:mm:ss} %{type} %{message}"); -#ifndef QT_DEBUG QString path = userLogsDir(); QDir appDir(path); if (!appDir.mkpath(path)) { @@ -51,6 +50,8 @@ bool Debug::init() } m_file.setTextModeEnabled(true); m_textStream.setDevice(&m_file); + +#ifndef QT_DEBUG qInstallMessageHandler(debugMessageHandler); #endif