Skip to content

Commit

Permalink
openssl3 depreciated warnings fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Teredic committed Dec 13, 2023
1 parent 1234136 commit 740cb12
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
47 changes: 36 additions & 11 deletions src/base/net/tls/TlsContext.cpp
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
Expand All @@ -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"
Expand Down Expand Up @@ -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[] = {
Expand Down Expand Up @@ -103,6 +97,8 @@ static DH *get_dh2048()

return dh;
}
#endif


} // namespace xmrig

Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand All @@ -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;
}
Expand Down
20 changes: 6 additions & 14 deletions src/base/net/tls/TlsContext.h
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
Expand All @@ -30,9 +24,6 @@
#include "base/tools/Object.h"


#include <cstdint>


using SSL_CTX = struct ssl_ctx_st;


Expand Down Expand Up @@ -66,6 +57,7 @@ class TlsContext
};


} /* namespace xmrig */
} // namespace xmrig


#endif /* XMRIG_TLSCONTEXT_H */
#endif // XMRIG_TLSCONTEXT_H
11 changes: 8 additions & 3 deletions src/base/net/tls/TlsGen.cpp
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
Expand All @@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "base/net/tls/TlsGen.h"


Expand All @@ -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);
Expand All @@ -52,6 +54,9 @@ static EVP_PKEY *generate_pkey()
BN_free(exponent);

return pkey;
# else
return EVP_RSA_gen(2048);
# endif
}


Expand Down
8 changes: 4 additions & 4 deletions src/base/net/tls/TlsGen.h
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
Expand Down Expand Up @@ -55,7 +55,7 @@ class TlsGen
};


} /* namespace xmrig */
} // namespace xmrig


#endif /* XMRIG_TLSGEN_H */
#endif // XMRIG_TLSGEN_H

0 comments on commit 740cb12

Please sign in to comment.