-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
/* XMRig | ||
* Copyright 2010 Jeff Garzik <[email protected]> | ||
* Copyright 2012-2014 pooler <[email protected]> | ||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> | ||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> | ||
* Copyright 2016 Jay D Dee <[email protected]> | ||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> | ||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> | ||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh> | ||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd> | ||
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh> | ||
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -23,7 +17,6 @@ | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#include "base/net/tls/TlsContext.h" | ||
#include "base/io/Env.h" | ||
#include "base/io/log/Log.h" | ||
|
@@ -52,6 +45,7 @@ namespace xmrig { | |
|
||
|
||
// https://wiki.openssl.org/index.php/Diffie-Hellman_parameters | ||
#if OPENSSL_VERSION_NUMBER < 0x30000000L || defined(LIBRESSL_VERSION_NUMBER) | ||
static DH *get_dh2048() | ||
{ | ||
static unsigned char dhp_2048[] = { | ||
|
@@ -103,6 +97,8 @@ static DH *get_dh2048() | |
|
||
return dh; | ||
} | ||
#endif | ||
|
||
|
||
} // namespace xmrig | ||
|
||
|
@@ -198,6 +194,7 @@ bool xmrig::TlsContext::setCipherSuites(const char *ciphersuites) | |
|
||
bool xmrig::TlsContext::setDH(const char *dhparam) | ||
{ | ||
# if OPENSSL_VERSION_NUMBER < 0x30000000L || defined(LIBRESSL_VERSION_NUMBER) | ||
DH *dh = nullptr; | ||
|
||
if (dhparam != nullptr) { | ||
|
@@ -223,7 +220,7 @@ bool xmrig::TlsContext::setDH(const char *dhparam) | |
dh = get_dh2048(); | ||
} | ||
|
||
const int rc = SSL_CTX_set_tmp_dh(m_ctx, dh); | ||
const int rc = SSL_CTX_set_tmp_dh(m_ctx, dh); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast) | ||
|
||
DH_free(dh); | ||
|
||
|
@@ -232,6 +229,34 @@ bool xmrig::TlsContext::setDH(const char *dhparam) | |
|
||
return false; | ||
} | ||
# else | ||
if (dhparam != nullptr) { | ||
EVP_PKEY *dh = nullptr; | ||
BIO *bio = BIO_new_file(Env::expand(dhparam), "r"); | ||
|
||
if (bio) { | ||
dh = PEM_read_bio_Parameters(bio, nullptr); | ||
BIO_free(bio); | ||
} | ||
|
||
if (!dh) { | ||
LOG_ERR("PEM_read_bio_Parameters(\"%s\") failed.", dhparam); | ||
|
||
return false; | ||
} | ||
|
||
if (SSL_CTX_set0_tmp_dh_pkey(m_ctx, dh) != 1) { | ||
EVP_PKEY_free(dh); | ||
|
||
LOG_ERR("SSL_CTX_set0_tmp_dh_pkey(\"%s\") failed.", dhparam); | ||
|
||
return false; | ||
} | ||
} | ||
else { | ||
SSL_CTX_set_dh_auto(m_ctx, 1); | ||
} | ||
# endif | ||
|
||
return true; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
/* XMRig | ||
* Copyright 2010 Jeff Garzik <[email protected]> | ||
* Copyright 2012-2014 pooler <[email protected]> | ||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> | ||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> | ||
* Copyright 2016 Jay D Dee <[email protected]> | ||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> | ||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> | ||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh> | ||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd> | ||
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh> | ||
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -30,9 +24,6 @@ | |
#include "base/tools/Object.h" | ||
|
||
|
||
#include <cstdint> | ||
|
||
|
||
using SSL_CTX = struct ssl_ctx_st; | ||
|
||
|
||
|
@@ -66,6 +57,7 @@ class TlsContext | |
}; | ||
|
||
|
||
} /* namespace xmrig */ | ||
} // namespace xmrig | ||
|
||
|
||
#endif /* XMRIG_TLSCONTEXT_H */ | ||
#endif // XMRIG_TLSCONTEXT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* XMRig | ||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh> | ||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh> | ||
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -16,7 +16,6 @@ | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#include "base/net/tls/TlsGen.h" | ||
|
||
|
||
|
@@ -34,13 +33,16 @@ static const char *kLocalhost = "localhost"; | |
|
||
static EVP_PKEY *generate_pkey() | ||
{ | ||
# if OPENSSL_VERSION_NUMBER < 0x30000000L || defined(LIBRESSL_VERSION_NUMBER) | ||
auto pkey = EVP_PKEY_new(); | ||
if (!pkey) { | ||
return nullptr; | ||
} | ||
|
||
auto exponent = BN_new(); | ||
auto rsa = RSA_new(); | ||
|
||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast) | ||
if (!exponent || !rsa || !BN_set_word(exponent, RSA_F4) || !RSA_generate_key_ex(rsa, 2048, exponent, nullptr) || !EVP_PKEY_assign_RSA(pkey, rsa)) { | ||
EVP_PKEY_free(pkey); | ||
BN_free(exponent); | ||
|
@@ -52,6 +54,9 @@ static EVP_PKEY *generate_pkey() | |
BN_free(exponent); | ||
|
||
return pkey; | ||
# else | ||
return EVP_RSA_gen(2048); | ||
# endif | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* XMRig | ||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh> | ||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh> | ||
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -55,7 +55,7 @@ class TlsGen | |
}; | ||
|
||
|
||
} /* namespace xmrig */ | ||
} // namespace xmrig | ||
|
||
|
||
#endif /* XMRIG_TLSGEN_H */ | ||
#endif // XMRIG_TLSGEN_H |