mirror of
https://github.com/xmrig/xmrig.git
synced 2025-02-02 03:06:30 +00:00
Merge branch 'dev'
This commit is contained in:
commit
53ac6f7ee7
134 changed files with 2932 additions and 608 deletions
|
@ -1,3 +1,12 @@
|
|||
# v5.10.0
|
||||
- [#1590](https://github.com/xmrig/xmrig/pull/1590) MSR mod automatically deactivated after switching from RandomX algorithms.
|
||||
- [#1592](https://github.com/xmrig/xmrig/pull/1592) Added AVX2 optimized code for AstroBWT algorithm.
|
||||
- Added new config option `astrobwt-avx2` in `cpu` object and command line option `--astrobwt-avx2`.
|
||||
- [#1596](https://github.com/xmrig/xmrig/issues/1596) Major TLS (Transport Layer Security) subsystem update.
|
||||
- Added new TLS options, please check [xmrig-proxy documentation](https://xmrig.com/docs/proxy/tls) for details.
|
||||
- `cn/gpu` algorithm now disabled by default and will be removed in next major (v6.x.x) release, no ETA for it right now.
|
||||
- Added command line option `--data-dir`.
|
||||
|
||||
# v5.9.0
|
||||
- [#1578](https://github.com/xmrig/xmrig/pull/1578) Added new RandomKEVA algorithm for upcoming Kevacoin fork, as `"algo": "rx/keva"` or `"coin": "keva"`.
|
||||
- [#1584](https://github.com/xmrig/xmrig/pull/1584) Fixed invalid AstroBWT hashes after algorithm switching.
|
||||
|
|
|
@ -6,7 +6,7 @@ option(WITH_HWLOC "Enable hwloc support" ON)
|
|||
option(WITH_CN_LITE "Enable CryptoNight-Lite algorithms family" ON)
|
||||
option(WITH_CN_HEAVY "Enable CryptoNight-Heavy algorithms family" ON)
|
||||
option(WITH_CN_PICO "Enable CryptoNight-Pico algorithm" ON)
|
||||
option(WITH_CN_GPU "Enable CryptoNight-GPU algorithm" ON)
|
||||
option(WITH_CN_GPU "Enable CryptoNight-GPU algorithm" OFF)
|
||||
option(WITH_RANDOMX "Enable RandomX algorithms family" ON)
|
||||
option(WITH_ARGON2 "Enable Argon2 algorithms family" ON)
|
||||
option(WITH_ASTROBWT "Enable AstroBWT algorithms family" ON)
|
||||
|
@ -67,7 +67,6 @@ set(HEADERS_CRYPTO
|
|||
src/crypto/cn/c_groestl.h
|
||||
src/crypto/cn/c_jh.h
|
||||
src/crypto/cn/c_skein.h
|
||||
src/crypto/cn/CnAlgo.h
|
||||
src/crypto/cn/CnCtx.h
|
||||
src/crypto/cn/CnHash.h
|
||||
src/crypto/cn/CryptoNight_monero.h
|
||||
|
@ -77,10 +76,7 @@ set(HEADERS_CRYPTO
|
|||
src/crypto/cn/hash.h
|
||||
src/crypto/cn/skein_port.h
|
||||
src/crypto/cn/soft_aes.h
|
||||
src/crypto/common/Algorithm.h
|
||||
src/crypto/common/Coin.h
|
||||
src/crypto/common/HugePagesInfo.h
|
||||
src/crypto/common/keccak.h
|
||||
src/crypto/common/MemoryPool.h
|
||||
src/crypto/common/Nonce.h
|
||||
src/crypto/common/portable/mm_malloc.h
|
||||
|
@ -116,10 +112,7 @@ set(SOURCES_CRYPTO
|
|||
src/crypto/cn/c_skein.c
|
||||
src/crypto/cn/CnCtx.cpp
|
||||
src/crypto/cn/CnHash.cpp
|
||||
src/crypto/common/Algorithm.cpp
|
||||
src/crypto/common/Coin.cpp
|
||||
src/crypto/common/HugePagesInfo.cpp
|
||||
src/crypto/common/keccak.cpp
|
||||
src/crypto/common/MemoryPool.cpp
|
||||
src/crypto/common/Nonce.cpp
|
||||
src/crypto/common/VirtualMemory.cpp
|
||||
|
|
10
README.md
10
README.md
|
@ -68,6 +68,7 @@ CPU backend:
|
|||
--randomx-wrmsr=N write custom value (0-15) to Intel MSR register 0x1a4 or disable MSR mod (-1)
|
||||
--randomx-no-rdmsr disable reverting initial MSR values on exit
|
||||
--astrobwt-max-size=N skip hashes with large stage 2 size, default: 550, min: 400, max: 1200
|
||||
--astrobwt-avx2 enable AVX2 optimizations for AstroBWT algorithm
|
||||
|
||||
API:
|
||||
--api-worker-id=ID custom worker-id for API
|
||||
|
@ -93,6 +94,15 @@ CUDA backend:
|
|||
--cuda-bsleep-hint=N bsleep hint for autoconfig
|
||||
--no-nvml disable NVML (NVIDIA Management Library) support
|
||||
|
||||
TLS:
|
||||
--tls-gen=HOSTNAME generate TLS certificate for specific hostname
|
||||
--tls-cert=FILE load TLS certificate chain from a file in the PEM format
|
||||
--tls-cert-key=FILE load TLS certificate private key from a file in the PEM format
|
||||
--tls-dhparam=FILE load DH parameters for DHE ciphers from a file in the PEM format
|
||||
--tls-protocols=N enable specified TLS protocols, example: "TLSv1 TLSv1.1 TLSv1.2 TLSv1.3"
|
||||
--tls-ciphers=S set list of available ciphers (TLSv1.2 and below)
|
||||
--tls-ciphersuites=S set list of available TLSv1.3 ciphersuites
|
||||
|
||||
Logging:
|
||||
-S, --syslog use system log for output messages
|
||||
-l, --log-file=FILE log all output to a file
|
||||
|
|
|
@ -13,11 +13,30 @@ if (WITH_TLS)
|
|||
find_package(OpenSSL)
|
||||
|
||||
if (OPENSSL_FOUND)
|
||||
set(TLS_SOURCES src/base/net/stratum/Tls.h src/base/net/stratum/Tls.cpp)
|
||||
set(TLS_SOURCES
|
||||
src/base/net/stratum/Tls.cpp
|
||||
src/base/net/stratum/Tls.h
|
||||
src/base/net/tls/ServerTls.cpp
|
||||
src/base/net/tls/ServerTls.h
|
||||
src/base/net/tls/TlsConfig.cpp
|
||||
src/base/net/tls/TlsConfig.h
|
||||
src/base/net/tls/TlsContext.cpp
|
||||
src/base/net/tls/TlsContext.h
|
||||
src/base/net/tls/TlsGen.cpp
|
||||
src/base/net/tls/TlsGen.h
|
||||
)
|
||||
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
|
||||
if (WITH_HTTP)
|
||||
set(TLS_SOURCES ${TLS_SOURCES} src/base/net/http/HttpsClient.h src/base/net/http/HttpsClient.cpp)
|
||||
set(TLS_SOURCES ${TLS_SOURCES}
|
||||
src/base/net/https/HttpsClient.cpp
|
||||
src/base/net/https/HttpsClient.h
|
||||
src/base/net/https/HttpsContext.cpp
|
||||
src/base/net/https/HttpsContext.h
|
||||
src/base/net/https/HttpsServer.cpp
|
||||
src/base/net/https/HttpsServer.h
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support")
|
||||
|
@ -29,5 +48,12 @@ else()
|
|||
set(OPENSSL_LIBRARIES "")
|
||||
remove_definitions(/DXMRIG_FEATURE_TLS)
|
||||
|
||||
if (WITH_HTTP)
|
||||
set(TLS_SOURCES ${TLS_SOURCES}
|
||||
src/base/net/http/HttpServer.cpp
|
||||
src/base/net/http/HttpServer.h
|
||||
)
|
||||
endif()
|
||||
|
||||
set(CMAKE_PROJECT_NAME "${CMAKE_PROJECT_NAME}-notls")
|
||||
endif()
|
||||
|
|
|
@ -23,6 +23,16 @@ if (WITH_ASTROBWT)
|
|||
src/crypto/astrobwt/salsa20_ref/salsa20.c
|
||||
)
|
||||
else()
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
enable_language(ASM_MASM)
|
||||
add_definitions(/DASTROBWT_AVX2)
|
||||
if (CMAKE_C_COMPILER_ID MATCHES MSVC)
|
||||
list(APPEND SOURCES_CRYPTO src/crypto/astrobwt/sha3_256_avx2.asm)
|
||||
else()
|
||||
list(APPEND SOURCES_CRYPTO src/crypto/astrobwt/sha3_256_avx2.S)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(APPEND HEADERS_CRYPTO
|
||||
src/crypto/astrobwt/Salsa20.hpp
|
||||
)
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "backend/common/Threads.h"
|
||||
#include "backend/cpu/CpuThreads.h"
|
||||
#include "crypto/cn/CnAlgo.h"
|
||||
#include "base/crypto/CnAlgo.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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,8 +30,8 @@
|
|||
#include <set>
|
||||
|
||||
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ static const char *kArgon2Impl = "argon2-impl";
|
|||
|
||||
#ifdef XMRIG_ALGO_ASTROBWT
|
||||
static const char* kAstroBWTMaxSize = "astrobwt-max-size";
|
||||
static const char* kAstroBWTAVX2 = "astrobwt-avx2";
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -93,7 +94,8 @@ rapidjson::Value xmrig::CpuConfig::toJSON(rapidjson::Document &doc) const
|
|||
# endif
|
||||
|
||||
# ifdef XMRIG_ALGO_ASTROBWT
|
||||
obj.AddMember(StringRef(kAstroBWTMaxSize), m_astrobwtMaxSize, allocator);
|
||||
obj.AddMember(StringRef(kAstroBWTMaxSize), m_astrobwtMaxSize, allocator);
|
||||
obj.AddMember(StringRef(kAstroBWTAVX2), m_astrobwtAVX2, allocator);
|
||||
# endif
|
||||
|
||||
m_threads.toJSON(obj, doc);
|
||||
|
@ -148,12 +150,20 @@ void xmrig::CpuConfig::read(const rapidjson::Value &value)
|
|||
# endif
|
||||
|
||||
# ifdef XMRIG_ALGO_ASTROBWT
|
||||
const auto& obj = Json::getValue(value, kAstroBWTMaxSize);
|
||||
if (obj.IsNull() || !obj.IsInt()) {
|
||||
const auto& astroBWTMaxSize = Json::getValue(value, kAstroBWTMaxSize);
|
||||
if (astroBWTMaxSize.IsNull() || !astroBWTMaxSize.IsInt()) {
|
||||
m_shouldSave = true;
|
||||
}
|
||||
else {
|
||||
m_astrobwtMaxSize = std::min(std::max(obj.GetInt(), 400), 1200);
|
||||
m_astrobwtMaxSize = std::min(std::max(astroBWTMaxSize.GetInt(), 400), 1200);
|
||||
}
|
||||
|
||||
const auto& astroBWTAVX2 = Json::getValue(value, kAstroBWTAVX2);
|
||||
if (astroBWTAVX2.IsNull() || !astroBWTAVX2.IsBool()) {
|
||||
m_shouldSave = true;
|
||||
}
|
||||
else {
|
||||
m_astrobwtAVX2 = astroBWTAVX2.GetBool();
|
||||
}
|
||||
# endif
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
inline const String &argon2Impl() const { return m_argon2Impl; }
|
||||
inline const Threads<CpuThreads> &threads() const { return m_threads; }
|
||||
inline int astrobwtMaxSize() const { return m_astrobwtMaxSize; }
|
||||
inline bool astrobwtAVX2() const { return m_astrobwtAVX2; }
|
||||
inline int priority() const { return m_priority; }
|
||||
inline uint32_t limit() const { return m_limit; }
|
||||
|
||||
|
@ -72,6 +73,7 @@ private:
|
|||
|
||||
AesMode m_aes = AES_AUTO;
|
||||
Assembly m_assembly;
|
||||
bool m_astrobwtAVX2 = false;
|
||||
bool m_enabled = true;
|
||||
bool m_hugePages = true;
|
||||
bool m_shouldSave = false;
|
||||
|
|
|
@ -35,10 +35,11 @@
|
|||
xmrig::CpuLaunchData::CpuLaunchData(const Miner *miner, const Algorithm &algorithm, const CpuConfig &config, const CpuThread &thread) :
|
||||
algorithm(algorithm),
|
||||
assembly(config.assembly()),
|
||||
astrobwtAVX2(config.astrobwtAVX2()),
|
||||
hugePages(config.isHugePages()),
|
||||
hwAES(config.isHwAES()),
|
||||
yield(config.isYield()),
|
||||
astrobwtMaxSize(config.astrobwtMaxSize()),
|
||||
astrobwtMaxSize(config.astrobwtMaxSize()),
|
||||
priority(config.priority()),
|
||||
affinity(thread.affinity()),
|
||||
miner(miner),
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
#define XMRIG_CPULAUNCHDATA_H
|
||||
|
||||
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "crypto/cn/CnHash.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "crypto/common/Assembly.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
|
||||
|
@ -58,6 +58,7 @@ public:
|
|||
|
||||
const Algorithm algorithm;
|
||||
const Assembly assembly;
|
||||
const bool astrobwtAVX2;
|
||||
const bool hugePages;
|
||||
const bool hwAES;
|
||||
const bool yield;
|
||||
|
|
|
@ -77,6 +77,7 @@ xmrig::CpuWorker<N>::CpuWorker(size_t id, const CpuLaunchData &data) :
|
|||
Worker(id, data.affinity, data.priority),
|
||||
m_algorithm(data.algorithm),
|
||||
m_assembly(data.assembly),
|
||||
m_astrobwtAVX2(data.astrobwtAVX2),
|
||||
m_hwAES(data.hwAES),
|
||||
m_yield(data.yield),
|
||||
m_av(data.av()),
|
||||
|
@ -262,7 +263,7 @@ void xmrig::CpuWorker<N>::start()
|
|||
{
|
||||
# ifdef XMRIG_ALGO_ASTROBWT
|
||||
if (job.algorithm().family() == Algorithm::ASTROBWT) {
|
||||
if (!astrobwt::astrobwt_dero(m_job.blob(), job.size(), m_ctx[0]->memory, m_hash, m_astrobwtMaxSize))
|
||||
if (!astrobwt::astrobwt_dero(m_job.blob(), job.size(), m_ctx[0]->memory, m_hash, m_astrobwtMaxSize, m_astrobwtAVX2))
|
||||
valid = false;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -70,6 +70,7 @@ private:
|
|||
|
||||
const Algorithm m_algorithm;
|
||||
const Assembly m_assembly;
|
||||
const bool m_astrobwtAVX2;
|
||||
const bool m_hwAES;
|
||||
const bool m_yield;
|
||||
const CnHash::AlgoVariant m_av;
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
|
||||
|
||||
#include "backend/cpu/CpuThreads.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "crypto/common/Assembly.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
|
||||
#include "backend/cuda/CudaThread.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -29,7 +29,6 @@
|
|||
using nvid_ctx = struct nvid_ctx;
|
||||
|
||||
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -26,8 +26,8 @@
|
|||
#include "backend/cuda/wrappers/CudaDevice.h"
|
||||
#include "backend/cuda/CudaThreads.h"
|
||||
#include "backend/cuda/wrappers/CudaLib.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
#ifdef XMRIG_FEATURE_NVML
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -31,7 +31,6 @@ using nvid_ctx = struct nvid_ctx;
|
|||
|
||||
#include "backend/cuda/wrappers/CudaDevice.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -29,15 +29,15 @@
|
|||
#include <sstream>
|
||||
|
||||
|
||||
#include "backend/opencl/OclCache.h"
|
||||
#include "3rdparty/base32/base32.h"
|
||||
#include "backend/common/Tags.h"
|
||||
#include "backend/opencl/interfaces/IOclRunner.h"
|
||||
#include "backend/opencl/OclCache.h"
|
||||
#include "backend/opencl/OclLaunchData.h"
|
||||
#include "backend/opencl/wrappers/OclLib.h"
|
||||
#include "base/crypto/keccak.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "crypto/common/keccak.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -31,7 +31,7 @@
|
|||
#include "backend/opencl/runners/tools/OclSharedData.h"
|
||||
#include "backend/opencl/wrappers/OclDevice.h"
|
||||
#include "backend/opencl/wrappers/OclPlatform.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "crypto/common/Nonce.h"
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -24,7 +24,6 @@
|
|||
|
||||
|
||||
#include "backend/opencl/OclThread.h"
|
||||
|
||||
#include "base/io/json/Json.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -26,7 +26,6 @@
|
|||
#define XMRIG_OCLTHREAD_H
|
||||
|
||||
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -24,9 +24,8 @@
|
|||
|
||||
|
||||
#include "backend/opencl/cl/OclSource.h"
|
||||
|
||||
#include "backend/opencl/cl/cn/cryptonight_cl.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_ALGO_CN_GPU
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -26,8 +26,8 @@
|
|||
|
||||
#include "backend/opencl/OclThreads.h"
|
||||
#include "backend/opencl/wrappers/OclDevice.h"
|
||||
#include "crypto/cn/CnAlgo.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "base/crypto/CnAlgo.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include "backend/opencl/OclThreads.h"
|
||||
#include "backend/opencl/wrappers/OclDevice.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include "backend/opencl/OclThreads.h"
|
||||
#include "backend/opencl/wrappers/OclDevice.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "crypto/randomx/randomx.h"
|
||||
#include "crypto/rx/RxAlgo.h"
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
|
||||
#include "backend/opencl/OclThreads.h"
|
||||
#include "backend/opencl/wrappers/OclDevice.h"
|
||||
#include "crypto/cn/CnAlgo.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "base/crypto/CnAlgo.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "backend/opencl/kernels/rx/RxRunKernel.h"
|
||||
#include "backend/opencl/wrappers/OclLib.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "crypto/randomx/randomx.h"
|
||||
#include "crypto/rx/RxAlgo.h"
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include "3rdparty/cl.h"
|
||||
#include "backend/opencl/interfaces/IOclRunner.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -24,7 +24,6 @@
|
|||
|
||||
|
||||
#include "backend/opencl/runners/OclCnRunner.h"
|
||||
|
||||
#include "backend/opencl/kernels/Cn0Kernel.h"
|
||||
#include "backend/opencl/kernels/Cn1Kernel.h"
|
||||
#include "backend/opencl/kernels/Cn2Kernel.h"
|
||||
|
@ -32,9 +31,9 @@
|
|||
#include "backend/opencl/OclLaunchData.h"
|
||||
#include "backend/opencl/runners/tools/OclCnR.h"
|
||||
#include "backend/opencl/wrappers/OclLib.h"
|
||||
#include "base/crypto/CnAlgo.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "crypto/cn/CnAlgo.h"
|
||||
|
||||
|
||||
xmrig::OclCnRunner::OclCnRunner(size_t index, const OclLaunchData &data) : OclBaseRunner(index, data)
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -24,7 +24,6 @@
|
|||
|
||||
|
||||
#include "backend/opencl/runners/OclRyoRunner.h"
|
||||
|
||||
#include "backend/opencl/kernels/Cn00RyoKernel.h"
|
||||
#include "backend/opencl/kernels/Cn0Kernel.h"
|
||||
#include "backend/opencl/kernels/Cn1RyoKernel.h"
|
||||
|
@ -32,9 +31,9 @@
|
|||
#include "backend/opencl/kernels/CnBranchKernel.h"
|
||||
#include "backend/opencl/OclLaunchData.h"
|
||||
#include "backend/opencl/wrappers/OclLib.h"
|
||||
#include "base/crypto/CnAlgo.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "crypto/cn/CnAlgo.h"
|
||||
|
||||
|
||||
xmrig::OclRyoRunner::OclRyoRunner(size_t index, const OclLaunchData &data) : OclBaseRunner(index, data)
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -28,8 +28,6 @@
|
|||
#include "backend/opencl/OclThreads.h"
|
||||
#include "backend/opencl/wrappers/OclLib.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "crypto/cn/CnAlgo.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
#ifdef XMRIG_FEATURE_ADL
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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,6 +30,7 @@
|
|||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/api/interfaces/IApiListener.h"
|
||||
#include "base/api/requests/HttpApiRequest.h"
|
||||
#include "base/crypto/keccak.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/kernel/Base.h"
|
||||
#include "base/kernel/Env.h"
|
||||
|
@ -37,7 +38,6 @@
|
|||
#include "base/tools/Chrono.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "crypto/common/keccak.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
|
|
|
@ -29,12 +29,18 @@
|
|||
#include "base/io/log/Log.h"
|
||||
#include "base/net/http/HttpApiResponse.h"
|
||||
#include "base/net/http/HttpData.h"
|
||||
#include "base/net/http/HttpServer.h"
|
||||
#include "base/net/tools/TcpServer.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# include "base/net/https/HttpsServer.h"
|
||||
#else
|
||||
# include "base/net/http/HttpServer.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
static const char *kAuthorization = "authorization";
|
||||
|
@ -48,10 +54,7 @@ static size_t faviconSize = 0;
|
|||
|
||||
|
||||
xmrig::Httpd::Httpd(Base *base) :
|
||||
m_base(base),
|
||||
m_http(nullptr),
|
||||
m_server(nullptr),
|
||||
m_port(0)
|
||||
m_base(base)
|
||||
{
|
||||
m_httpListener = std::make_shared<HttpListener>(this);
|
||||
|
||||
|
@ -64,18 +67,27 @@ xmrig::Httpd::~Httpd() = default;
|
|||
|
||||
bool xmrig::Httpd::start()
|
||||
{
|
||||
const Http &config = m_base->config()->http();
|
||||
const auto &config = m_base->config()->http();
|
||||
|
||||
if (!config.isEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
m_http = new HttpServer(m_httpListener);
|
||||
bool tls = false;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
m_http = new HttpsServer(m_httpListener);
|
||||
tls = m_http->setTls(m_base->config()->tls());
|
||||
# else
|
||||
m_http = new HttpServer(m_httpListener);
|
||||
# endif
|
||||
|
||||
m_server = new TcpServer(config.host(), config.port(), m_http);
|
||||
|
||||
const int rc = m_server->bind();
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") BLUE_BOLD("%s:%d") " " RED_BOLD("%s"),
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CSI "1;%dm%s:%d" " " RED_BOLD("%s"),
|
||||
"HTTP API",
|
||||
tls ? 32 : 36,
|
||||
config.host().data(),
|
||||
rc < 0 ? config.port() : rc,
|
||||
rc < 0 ? uv_strerror(rc) : ""
|
||||
|
@ -143,7 +155,7 @@ void xmrig::Httpd::onHttpData(const HttpData &data)
|
|||
}
|
||||
# endif
|
||||
|
||||
return HttpResponse(data.id(), 404).end();
|
||||
return HttpResponse(data.id(), HTTP_STATUS_NOT_FOUND).end();
|
||||
}
|
||||
|
||||
if (data.method > 4) {
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace xmrig {
|
|||
|
||||
class Base;
|
||||
class HttpServer;
|
||||
class HttpsServer;
|
||||
class TcpServer;
|
||||
|
||||
|
||||
|
@ -61,11 +62,16 @@ protected:
|
|||
private:
|
||||
int auth(const HttpData &req) const;
|
||||
|
||||
Base *m_base;
|
||||
HttpServer *m_http;
|
||||
const Base *m_base;
|
||||
std::shared_ptr<IHttpListener> m_httpListener;
|
||||
TcpServer *m_server;
|
||||
uint16_t m_port;
|
||||
TcpServer *m_server = nullptr;
|
||||
uint16_t m_port = 0;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
HttpsServer *m_http = nullptr;
|
||||
# else
|
||||
HttpServer *m_http = nullptr;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
set(HEADERS_BASE
|
||||
src/base/api/interfaces/IApiListener.h
|
||||
src/base/crypto/Algorithm.h
|
||||
src/base/crypto/CnAlgo.h
|
||||
src/base/crypto/Coin.h
|
||||
src/base/crypto/keccak.h
|
||||
src/base/io/Console.h
|
||||
src/base/io/json/Json.h
|
||||
src/base/io/json/JsonChain.h
|
||||
|
@ -49,7 +53,9 @@ set(HEADERS_BASE
|
|||
src/base/net/stratum/strategies/StrategyProxy.h
|
||||
src/base/net/stratum/SubmitResult.h
|
||||
src/base/net/stratum/Url.h
|
||||
src/base/net/tools/RecvBuf.h
|
||||
src/base/net/tools/LineReader.h
|
||||
src/base/net/tools/MemPool.h
|
||||
src/base/net/tools/NetBuffer.h
|
||||
src/base/net/tools/Storage.h
|
||||
src/base/tools/Arguments.h
|
||||
src/base/tools/Baton.h
|
||||
|
@ -61,6 +67,9 @@ set(HEADERS_BASE
|
|||
)
|
||||
|
||||
set(SOURCES_BASE
|
||||
src/base/crypto/Algorithm.cpp
|
||||
src/base/crypto/Coin.cpp
|
||||
src/base/crypto/keccak.cpp
|
||||
src/base/io/Console.cpp
|
||||
src/base/io/json/Json.cpp
|
||||
src/base/io/json/JsonChain.cpp
|
||||
|
@ -92,6 +101,8 @@ set(SOURCES_BASE
|
|||
src/base/net/stratum/strategies/FailoverStrategy.cpp
|
||||
src/base/net/stratum/strategies/SinglePoolStrategy.cpp
|
||||
src/base/net/stratum/Url.cpp
|
||||
src/base/net/tools/LineReader.cpp
|
||||
src/base/net/tools/NetBuffer.cpp
|
||||
src/base/tools/Arguments.cpp
|
||||
src/base/tools/Buffer.cpp
|
||||
src/base/tools/String.cpp
|
||||
|
@ -150,7 +161,6 @@ if (WITH_HTTP)
|
|||
src/base/net/http/HttpContext.h
|
||||
src/base/net/http/HttpData.h
|
||||
src/base/net/http/HttpResponse.h
|
||||
src/base/net/http/HttpServer.h
|
||||
src/base/net/stratum/DaemonClient.h
|
||||
src/base/net/stratum/SelfSelectClient.h
|
||||
src/base/net/tools/TcpServer.h
|
||||
|
@ -169,7 +179,6 @@ if (WITH_HTTP)
|
|||
src/base/net/http/HttpData.cpp
|
||||
src/base/net/http/HttpListener.cpp
|
||||
src/base/net/http/HttpResponse.cpp
|
||||
src/base/net/http/HttpServer.cpp
|
||||
src/base/net/stratum/DaemonClient.cpp
|
||||
src/base/net/stratum/SelfSelectClient.cpp
|
||||
src/base/net/tools/TcpServer.cpp
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "crypto/cn/CnAlgo.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "base/crypto/CnAlgo.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
|
@ -6,8 +6,8 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -31,7 +31,7 @@
|
|||
#include <cstdint>
|
||||
|
||||
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
|
||||
|
||||
namespace xmrig
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "crypto/common/Coin.h"
|
||||
#include "base/crypto/Coin.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
#define XMRIG_COIN_H
|
||||
|
||||
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
|
@ -6,7 +6,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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,11 +24,10 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
|
||||
|
||||
#include "crypto/common/keccak.h"
|
||||
#include "base/crypto/keccak.h"
|
||||
|
||||
|
||||
#define HASH_DATA_AREA 136
|
|
@ -6,7 +6,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -26,8 +27,8 @@
|
|||
#ifndef XMRIG_KECCAK_H
|
||||
#define XMRIG_KECCAK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace xmrig {
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -27,16 +27,17 @@
|
|||
#include <memory>
|
||||
|
||||
|
||||
#include "base/kernel/Base.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/json/JsonChain.h"
|
||||
#include "base/io/log/backends/ConsoleLog.h"
|
||||
#include "base/io/log/backends/FileLog.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/io/Watcher.h"
|
||||
#include "base/kernel/Base.h"
|
||||
#include "base/kernel/interfaces/IBaseListener.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/config/ConfigTransform.h"
|
||||
|
||||
|
@ -84,6 +85,8 @@ public:
|
|||
|
||||
delete config;
|
||||
delete watcher;
|
||||
|
||||
NetBuffer::destroy();
|
||||
}
|
||||
|
||||
|
||||
|
@ -127,7 +130,7 @@ private:
|
|||
return config.release();
|
||||
}
|
||||
|
||||
chain.addFile(Process::location(Process::ExeLocation, "config.json"));
|
||||
chain.addFile(Process::location(Process::DataLocation, "config.json"));
|
||||
|
||||
if (read(chain, config)) {
|
||||
return config.release();
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -56,9 +56,13 @@ static std::map<String, String> variables;
|
|||
|
||||
static void createVariables()
|
||||
{
|
||||
variables.insert({ "XMRIG_VERSION", APP_VERSION });
|
||||
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation, "") });
|
||||
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation, "") });
|
||||
variables.insert({ "XMRIG_VERSION", APP_VERSION });
|
||||
variables.insert({ "XMRIG_EXE", Process::exepath() });
|
||||
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) });
|
||||
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) });
|
||||
variables.insert({ "XMRIG_HOME_DIR", Process::location(Process::HomeLocation) });
|
||||
variables.insert({ "XMRIG_TEMP_DIR", Process::location(Process::TempLocation) });
|
||||
variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) });
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -24,6 +24,7 @@
|
|||
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
|
@ -34,20 +35,75 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
static size_t getLocation(Process::Location location, char *buf, size_t max)
|
||||
{
|
||||
using namespace xmrig;
|
||||
static char pathBuf[520];
|
||||
static std::string dataDir;
|
||||
|
||||
|
||||
static std::string getPath(Process::Location location)
|
||||
{
|
||||
size_t size = sizeof(pathBuf);
|
||||
|
||||
if (location == Process::DataLocation) {
|
||||
if (!dataDir.empty()) {
|
||||
return dataDir;
|
||||
}
|
||||
|
||||
location = Process::ExeLocation;
|
||||
}
|
||||
|
||||
if (location == Process::HomeLocation) {
|
||||
# if UV_VERSION_HEX >= 0x010600
|
||||
return uv_os_homedir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
|
||||
# else
|
||||
location = Process::ExeLocation;
|
||||
# endif
|
||||
}
|
||||
|
||||
if (location == Process::TempLocation) {
|
||||
# if UV_VERSION_HEX >= 0x010900
|
||||
return uv_os_tmpdir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
|
||||
# else
|
||||
location = Process::ExeLocation;
|
||||
# endif
|
||||
}
|
||||
|
||||
size_t size = max;
|
||||
if (location == Process::ExeLocation) {
|
||||
return uv_exepath(buf, &size) < 0 ? 0 : size;
|
||||
if (uv_exepath(pathBuf, &size) < 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto path = std::string(pathBuf, size);
|
||||
const auto pos = path.rfind(Process::kDirSeparator);
|
||||
|
||||
if (pos != std::string::npos) {
|
||||
return path.substr(0, pos);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
if (location == Process::CwdLocation) {
|
||||
return uv_cwd(buf, &size) < 0 ? 0 : size;
|
||||
return uv_cwd(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
static void setDataDir(const char *path)
|
||||
{
|
||||
if (path == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string dir = path;
|
||||
if (!dir.empty() && (dir.back() == '/' || dir.back() == '\\')) {
|
||||
dir.pop_back();
|
||||
}
|
||||
|
||||
if (!dir.empty() && uv_chdir(dir.c_str()) == 0) {
|
||||
dataDir = dir;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,46 +114,25 @@ xmrig::Process::Process(int argc, char **argv) :
|
|||
m_arguments(argc, argv)
|
||||
{
|
||||
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
|
||||
|
||||
setDataDir(m_arguments.value("--data-dir"));
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Process::exepath()
|
||||
{
|
||||
size_t size = sizeof(pathBuf);
|
||||
|
||||
return uv_exepath(pathBuf, &size) < 0 ? "" : String(pathBuf, size);
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Process::location(Location location, const char *fileName)
|
||||
{
|
||||
constexpr const size_t max = 520;
|
||||
|
||||
char *buf = new char[max]();
|
||||
size_t size = getLocation(location, buf, max);
|
||||
|
||||
if (size == 0) {
|
||||
delete [] buf;
|
||||
|
||||
return String();
|
||||
auto path = getPath(location);
|
||||
if (path.empty() || fileName == nullptr) {
|
||||
return path.c_str();
|
||||
}
|
||||
|
||||
if (fileName == nullptr) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
if (location == ExeLocation) {
|
||||
char *p = strrchr(buf, kDirSeparator);
|
||||
|
||||
if (p == nullptr) {
|
||||
delete [] buf;
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
size = static_cast<size_t>(p - buf);
|
||||
}
|
||||
|
||||
if ((size + strlen(fileName) + 2) >= max) {
|
||||
delete [] buf;
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
buf[size] = kDirSeparator;
|
||||
strcpy(buf + size + 1, fileName);
|
||||
|
||||
return buf;
|
||||
return (path + kDirSeparator + fileName).c_str();
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -37,7 +37,10 @@ class Process
|
|||
public:
|
||||
enum Location {
|
||||
ExeLocation,
|
||||
CwdLocation
|
||||
CwdLocation,
|
||||
DataLocation,
|
||||
HomeLocation,
|
||||
TempLocation
|
||||
};
|
||||
|
||||
# ifdef WIN32
|
||||
|
@ -48,6 +51,7 @@ public:
|
|||
|
||||
Process(int argc, char **argv);
|
||||
|
||||
static String exepath();
|
||||
static String location(Location location, const char *fileName = nullptr);
|
||||
|
||||
inline const Arguments &arguments() const { return m_arguments; }
|
||||
|
|
|
@ -66,6 +66,11 @@ const char *BaseConfig::kVerbose = "verbose";
|
|||
const char *BaseConfig::kWatch = "watch";
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
const char *BaseConfig::kTls = "tls";
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
@ -85,11 +90,15 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
|
|||
m_logFile = reader.getString(kLogFile);
|
||||
m_userAgent = reader.getString(kUserAgent);
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
m_tls = reader.getValue(kTls);
|
||||
# endif
|
||||
|
||||
Log::setColors(reader.getBool(kColors, Log::isColors()));
|
||||
setPrintTime(reader.getUint(kPrintTime, 60));
|
||||
setVerbose(reader.getValue(kVerbose));
|
||||
|
||||
const rapidjson::Value &api = reader.getObject(kApi);
|
||||
const auto &api = reader.getObject(kApi);
|
||||
if (api.IsObject()) {
|
||||
m_apiId = Json::getString(api, kApiId);
|
||||
m_apiWorkerId = Json::getString(api, kApiWorkerId);
|
||||
|
|
|
@ -31,6 +31,11 @@
|
|||
#include "base/net/stratum/Pools.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# include "base/net/tls/TlsConfig.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
|
@ -55,23 +60,31 @@ public:
|
|||
static const char *kVerbose;
|
||||
static const char *kWatch;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
static const char *kTls;
|
||||
# endif
|
||||
|
||||
BaseConfig() = default;
|
||||
|
||||
inline bool isAutoSave() const { return m_autoSave; }
|
||||
inline bool isBackground() const { return m_background; }
|
||||
inline bool isDryRun() const { return m_dryRun; }
|
||||
inline bool isSyslog() const { return m_syslog; }
|
||||
inline const char *logFile() const { return m_logFile.data(); }
|
||||
inline const char *userAgent() const { return m_userAgent.data(); }
|
||||
inline const Http &http() const { return m_http; }
|
||||
inline const Pools &pools() const { return m_pools; }
|
||||
inline const String &apiId() const { return m_apiId; }
|
||||
inline const String &apiWorkerId() const { return m_apiWorkerId; }
|
||||
inline uint32_t printTime() const { return m_printTime; }
|
||||
inline bool isAutoSave() const { return m_autoSave; }
|
||||
inline bool isBackground() const { return m_background; }
|
||||
inline bool isDryRun() const { return m_dryRun; }
|
||||
inline bool isSyslog() const { return m_syslog; }
|
||||
inline const char *logFile() const { return m_logFile.data(); }
|
||||
inline const char *userAgent() const { return m_userAgent.data(); }
|
||||
inline const Http &http() const { return m_http; }
|
||||
inline const Pools &pools() const { return m_pools; }
|
||||
inline const String &apiId() const { return m_apiId; }
|
||||
inline const String &apiWorkerId() const { return m_apiWorkerId; }
|
||||
inline uint32_t printTime() const { return m_printTime; }
|
||||
|
||||
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
|
||||
inline const String &fileName() const override { return m_fileName; }
|
||||
inline void setFileName(const char *fileName) override { m_fileName = fileName; }
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
inline const TlsConfig &tls() const { return m_tls; }
|
||||
# endif
|
||||
|
||||
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
|
||||
inline const String &fileName() const override { return m_fileName; }
|
||||
inline void setFileName(const char *fileName) override { m_fileName = fileName; }
|
||||
|
||||
bool read(const IJsonReader &reader, const char *fileName) override;
|
||||
bool save() override;
|
||||
|
@ -94,6 +107,10 @@ protected:
|
|||
String m_userAgent;
|
||||
uint32_t m_printTime = 60;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
TlsConfig m_tls;
|
||||
# endif
|
||||
|
||||
private:
|
||||
inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } }
|
||||
|
||||
|
|
|
@ -44,6 +44,11 @@
|
|||
#include "core/config/Config_platform.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# include "base/net/tls/TlsConfig.h"
|
||||
#endif
|
||||
|
||||
|
||||
void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTransform &transform)
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
@ -199,6 +204,29 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
|
|||
case IConfig::UserAgentKey: /* --user-agent */
|
||||
return set(doc, BaseConfig::kUserAgent, arg);
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
case IConfig::TlsCertKey: /* --tls-cert */
|
||||
return set(doc, BaseConfig::kTls, TlsConfig::kCert, arg);
|
||||
|
||||
case IConfig::TlsCertKeyKey: /* --tls-cert-key */
|
||||
return set(doc, BaseConfig::kTls, TlsConfig::kCertKey, arg);
|
||||
|
||||
case IConfig::TlsDHparamKey: /* --tls-dhparam */
|
||||
return set(doc, BaseConfig::kTls, TlsConfig::kDhparam, arg);
|
||||
|
||||
case IConfig::TlsCiphersKey: /* --tls-ciphers */
|
||||
return set(doc, BaseConfig::kTls, TlsConfig::kCiphers, arg);
|
||||
|
||||
case IConfig::TlsCipherSuitesKey: /* --tls-ciphersuites */
|
||||
return set(doc, BaseConfig::kTls, TlsConfig::kCipherSuites, arg);
|
||||
|
||||
case IConfig::TlsProtocolsKey: /* --tls-protocols */
|
||||
return set(doc, BaseConfig::kTls, TlsConfig::kProtocols, arg);
|
||||
|
||||
case IConfig::TlsGenKey: /* --tls-gen */
|
||||
return set(doc, BaseConfig::kTls, TlsConfig::kGen, arg);
|
||||
# endif
|
||||
|
||||
case IConfig::RetriesKey: /* --retries */
|
||||
case IConfig::RetryPauseKey: /* --retry-pause */
|
||||
case IConfig::PrintTimeKey: /* --print-time */
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
#define XMRIG_BASETRANSFORM_H
|
||||
|
||||
|
||||
#include "base/crypto/Coin.h"
|
||||
#include "base/kernel/interfaces/IConfigTransform.h"
|
||||
#include "crypto/common/Coin.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#define XMRIG_ICONFIG_H
|
||||
|
||||
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
|
@ -74,6 +73,7 @@ public:
|
|||
DaemonKey = 1018,
|
||||
DaemonPollKey = 1019,
|
||||
SelfSelectKey = 1028,
|
||||
DataDirKey = 1035,
|
||||
|
||||
// xmrig common
|
||||
CPUPriorityKey = 1021,
|
||||
|
@ -98,6 +98,7 @@ public:
|
|||
MemoryPoolKey = 1027,
|
||||
YieldKey = 1030,
|
||||
AstroBWTMaxSizeKey = 1034,
|
||||
AstroBWTAVX2Key = 1036,
|
||||
|
||||
// xmrig amd
|
||||
OclPlatformKey = 1400,
|
||||
|
@ -131,6 +132,7 @@ public:
|
|||
TlsCiphersKey = 1112,
|
||||
TlsCipherSuitesKey = 1113,
|
||||
TlsProtocolsKey = 1114,
|
||||
TlsGenKey = 1117,
|
||||
AlgoExtKey = 1115,
|
||||
ProxyPasswordKey = 1116,
|
||||
LoginFileKey = 'L',
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -26,7 +26,6 @@
|
|||
#define XMRIG_ICONFIGTRANSFORM_H
|
||||
|
||||
|
||||
#include "crypto/common/Algorithm.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -26,15 +26,12 @@
|
|||
#define XMRIG_ILINELISTENER_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class String;
|
||||
|
||||
|
||||
class ILineListener
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# include "base/net/http/HttpsClient.h"
|
||||
# include "base/net/https/HttpsClient.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/net/dns/Dns.h"
|
||||
#include "base/tools/Baton.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
|
||||
|
||||
#include <sstream>
|
||||
|
@ -41,31 +41,6 @@ namespace xmrig {
|
|||
static const char *kCRLF = "\r\n";
|
||||
|
||||
|
||||
class HttpClientWriteBaton : public Baton<uv_write_t>
|
||||
{
|
||||
public:
|
||||
inline HttpClientWriteBaton(const std::string &header, std::string &&body) :
|
||||
m_body(std::move(body)),
|
||||
m_header(header)
|
||||
{
|
||||
m_bufs[0] = uv_buf_init(const_cast<char *>(m_header.c_str()), m_header.size());
|
||||
m_bufs[1] = m_body.empty() ? uv_buf_init(nullptr, 0) : uv_buf_init(const_cast<char *>(m_body.c_str()), m_body.size());
|
||||
}
|
||||
|
||||
void write(uv_stream_t *stream)
|
||||
{
|
||||
uv_write(&req, stream, m_bufs, nbufs(), [](uv_write_t *req, int) { delete reinterpret_cast<HttpClientWriteBaton *>(req->data); });
|
||||
}
|
||||
|
||||
private:
|
||||
inline size_t nbufs() const { return m_bufs[1].len > 0 ? 2 : 1; }
|
||||
|
||||
std::string m_body;
|
||||
std::string m_header;
|
||||
uv_buf_t m_bufs[2]{};
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
@ -137,7 +112,8 @@ void xmrig::HttpClient::handshake()
|
|||
|
||||
headers.clear();
|
||||
|
||||
write(ss.str());
|
||||
body.insert(0, ss.str());
|
||||
write(std::move(body), false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,13 +125,6 @@ void xmrig::HttpClient::read(const char *data, size_t size)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::HttpClient::write(const std::string &header)
|
||||
{
|
||||
auto baton = new HttpClientWriteBaton(header, std::move(body));
|
||||
baton->write(stream());
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
|
||||
{
|
||||
auto client = static_cast<HttpClient *>(req->data);
|
||||
|
@ -174,12 +143,7 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
|
|||
return;
|
||||
}
|
||||
|
||||
uv_read_start(client->stream(),
|
||||
[](uv_handle_t *, size_t suggested_size, uv_buf_t *buf)
|
||||
{
|
||||
buf->base = new char[suggested_size];
|
||||
buf->len = suggested_size;
|
||||
},
|
||||
uv_read_start(client->stream(), NetBuffer::onAlloc,
|
||||
[](uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf)
|
||||
{
|
||||
auto client = static_cast<HttpClient*>(tcp->data);
|
||||
|
@ -194,7 +158,7 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
|
|||
client->close(static_cast<int>(nread));
|
||||
}
|
||||
|
||||
delete [] buf->base;
|
||||
NetBuffer::release(buf);
|
||||
});
|
||||
|
||||
client->handshake();
|
||||
|
|
|
@ -59,7 +59,6 @@ protected:
|
|||
|
||||
virtual void handshake();
|
||||
virtual void read(const char *data, size_t size);
|
||||
virtual void write(const std::string &header);
|
||||
|
||||
protected:
|
||||
inline const FetchRequest &req() const { return m_req; }
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "base/net/http/HttpContext.h"
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/tools/Baton.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
|
||||
|
||||
|
@ -42,6 +43,37 @@ static std::map<uint64_t, HttpContext *> storage;
|
|||
static uint64_t SEQUENCE = 0;
|
||||
|
||||
|
||||
class HttpWriteBaton : public Baton<uv_write_t>
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpWriteBaton)
|
||||
|
||||
inline HttpWriteBaton(std::string &&body, HttpContext *ctx) :
|
||||
m_ctx(ctx),
|
||||
m_body(std::move(body))
|
||||
{
|
||||
m_buf = uv_buf_init(const_cast<char *>(m_body.c_str()), m_body.size());
|
||||
}
|
||||
|
||||
inline ~HttpWriteBaton()
|
||||
{
|
||||
if (m_ctx) {
|
||||
m_ctx->close();
|
||||
}
|
||||
}
|
||||
|
||||
void write(uv_stream_t *stream)
|
||||
{
|
||||
uv_write(&req, stream, &m_buf, 1, [](uv_write_t *req, int) { delete reinterpret_cast<HttpWriteBaton *>(req->data); });
|
||||
}
|
||||
|
||||
private:
|
||||
HttpContext *m_ctx;
|
||||
std::string m_body;
|
||||
uv_buf_t m_buf{};
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
@ -75,6 +107,17 @@ xmrig::HttpContext::~HttpContext()
|
|||
}
|
||||
|
||||
|
||||
void xmrig::HttpContext::write(std::string &&data, bool close)
|
||||
{
|
||||
if (uv_is_writable(stream()) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto baton = new HttpWriteBaton(std::move(data), close ? this : nullptr);
|
||||
baton->write(stream());
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::HttpContext::isRequest() const
|
||||
{
|
||||
return m_parser->type == HTTP_REQUEST;
|
||||
|
|
|
@ -65,6 +65,8 @@ public:
|
|||
inline const char *tlsVersion() const override { return nullptr; }
|
||||
inline uint16_t port() const override { return 0; }
|
||||
|
||||
void write(std::string &&data, bool close) override;
|
||||
|
||||
bool isRequest() const override;
|
||||
size_t parse(const char *data, size_t size);
|
||||
std::string ip() const override;
|
||||
|
|
|
@ -53,12 +53,13 @@ public:
|
|||
|
||||
inline uint64_t id() const { return m_id; }
|
||||
|
||||
virtual bool isRequest() const = 0;
|
||||
virtual const char *host() const = 0;
|
||||
virtual const char *tlsFingerprint() const = 0;
|
||||
virtual const char *tlsVersion() const = 0;
|
||||
virtual std::string ip() const = 0;
|
||||
virtual uint16_t port() const = 0;
|
||||
virtual bool isRequest() const = 0;
|
||||
virtual const char *host() const = 0;
|
||||
virtual const char *tlsFingerprint() const = 0;
|
||||
virtual const char *tlsVersion() const = 0;
|
||||
virtual std::string ip() const = 0;
|
||||
virtual uint16_t port() const = 0;
|
||||
virtual void write(std::string &&data, bool close) = 0;
|
||||
|
||||
int method = 0;
|
||||
int status = 0;
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -28,8 +28,6 @@
|
|||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/http/HttpContext.h"
|
||||
#include "base/tools/Baton.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <cinttypes>
|
||||
|
@ -45,52 +43,6 @@ static const char *kCRLF = "\r\n";
|
|||
static const char *kUserAgent = "user-agent";
|
||||
|
||||
|
||||
class WriteBaton : public Baton<uv_write_t>
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(WriteBaton)
|
||||
|
||||
inline WriteBaton(const std::stringstream &ss, const char *data, size_t size, HttpContext *ctx) :
|
||||
m_ctx(ctx),
|
||||
m_header(ss.str())
|
||||
{
|
||||
bufs[0].len = m_header.size();
|
||||
bufs[0].base = const_cast<char *>(m_header.c_str());
|
||||
|
||||
if (data) {
|
||||
bufs[1].len = size;
|
||||
bufs[1].base = new char[size];
|
||||
memcpy(bufs[1].base, data, size);
|
||||
}
|
||||
else {
|
||||
bufs[1].base = nullptr;
|
||||
bufs[1].len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline ~WriteBaton()
|
||||
{
|
||||
if (count() == 2) {
|
||||
delete [] bufs[1].base;
|
||||
}
|
||||
|
||||
m_ctx->close();
|
||||
}
|
||||
|
||||
|
||||
inline size_t count() const { return bufs[1].base == nullptr ? 1 : 2; }
|
||||
inline size_t size() const { return bufs[0].len + bufs[1].len; }
|
||||
inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast<WriteBaton *>(req->data); }
|
||||
|
||||
|
||||
uv_buf_t bufs[2]{};
|
||||
|
||||
private:
|
||||
HttpContext *m_ctx;
|
||||
std::string m_header;
|
||||
};
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
@ -134,8 +86,8 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
|||
|
||||
ss << kCRLF;
|
||||
|
||||
auto ctx = HttpContext::get(m_id);
|
||||
auto baton = new WriteBaton(ss, data, size, ctx);
|
||||
auto ctx = HttpContext::get(m_id);
|
||||
std::string body = data ? (ss.str() + std::string(data, size)) : ss.str();
|
||||
|
||||
# ifndef APP_DEBUG
|
||||
if (statusCode() >= 400)
|
||||
|
@ -149,11 +101,11 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
|||
ctx->url.c_str(),
|
||||
err ? 31 : 32,
|
||||
statusCode(),
|
||||
baton->size(),
|
||||
body.size(),
|
||||
ctx->elapsed(),
|
||||
ctx->headers.count(kUserAgent) ? ctx->headers.at(kUserAgent).c_str() : nullptr
|
||||
);
|
||||
}
|
||||
|
||||
uv_write(&baton->req, ctx->stream(), baton->bufs, baton->count(), WriteBaton::onWrite);
|
||||
ctx->write(std::move(body), true);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -28,11 +28,10 @@
|
|||
#include <uv.h>
|
||||
|
||||
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/net/http/HttpContext.h"
|
||||
#include "base/net/http/HttpResponse.h"
|
||||
#include "base/net/http/HttpServer.h"
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/net/http/HttpContext.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
|
||||
|
||||
xmrig::HttpServer::HttpServer(const std::shared_ptr<IHttpListener> &listener) :
|
||||
|
@ -52,17 +51,7 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
|
|||
auto ctx = new HttpContext(HTTP_REQUEST, m_listener);
|
||||
uv_accept(stream, ctx->stream());
|
||||
|
||||
uv_read_start(ctx->stream(),
|
||||
[](uv_handle_t *, size_t suggested_size, uv_buf_t *buf)
|
||||
{
|
||||
buf->base = new char[suggested_size];
|
||||
|
||||
# ifdef _WIN32
|
||||
buf->len = static_cast<unsigned int>(suggested_size);
|
||||
# else
|
||||
buf->len = suggested_size;
|
||||
# endif
|
||||
},
|
||||
uv_read_start(ctx->stream(), NetBuffer::onAlloc,
|
||||
[](uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf)
|
||||
{
|
||||
auto ctx = static_cast<HttpContext*>(tcp->data);
|
||||
|
@ -78,6 +67,6 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
|
|||
ctx->close();
|
||||
}
|
||||
|
||||
delete [] buf->base;
|
||||
NetBuffer::release(buf);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <uv.h>
|
||||
|
||||
|
||||
#include "base/net/http/HttpsClient.h"
|
||||
#include "base/net/https/HttpsClient.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
|
||||
|
@ -49,8 +49,8 @@ xmrig::HttpsClient::HttpsClient(FetchRequest &&req, const std::weak_ptr<IHttpLis
|
|||
return;
|
||||
}
|
||||
|
||||
m_writeBio = BIO_new(BIO_s_mem());
|
||||
m_readBio = BIO_new(BIO_s_mem());
|
||||
m_write = BIO_new(BIO_s_mem());
|
||||
m_read = BIO_new(BIO_s_mem());
|
||||
SSL_CTX_set_options(m_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
|
||||
}
|
||||
|
||||
|
@ -89,24 +89,24 @@ void xmrig::HttpsClient::handshake()
|
|||
}
|
||||
|
||||
SSL_set_connect_state(m_ssl);
|
||||
SSL_set_bio(m_ssl, m_readBio, m_writeBio);
|
||||
SSL_set_bio(m_ssl, m_read, m_write);
|
||||
SSL_set_tlsext_host_name(m_ssl, host());
|
||||
|
||||
SSL_do_handshake(m_ssl);
|
||||
|
||||
flush();
|
||||
flush(false);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpsClient::read(const char *data, size_t size)
|
||||
{
|
||||
BIO_write(m_readBio, data, size);
|
||||
BIO_write(m_read, data, size);
|
||||
|
||||
if (!SSL_is_init_finished(m_ssl)) {
|
||||
const int rc = SSL_connect(m_ssl);
|
||||
|
||||
if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) {
|
||||
flush();
|
||||
flush(false);
|
||||
} else if (rc == 1) {
|
||||
X509 *cert = SSL_get_peer_certificate(m_ssl);
|
||||
if (!verify(cert)) {
|
||||
|
@ -123,19 +123,25 @@ void xmrig::HttpsClient::read(const char *data, size_t size)
|
|||
return;
|
||||
}
|
||||
|
||||
int bytes_read = 0;
|
||||
while ((bytes_read = SSL_read(m_ssl, m_buf, sizeof(m_buf))) > 0) {
|
||||
HttpClient::read(m_buf, static_cast<size_t>(bytes_read));
|
||||
static char buf[16384]{};
|
||||
|
||||
int rc = 0;
|
||||
while ((rc = SSL_read(m_ssl, buf, sizeof(buf))) > 0) {
|
||||
HttpClient::read(buf, static_cast<size_t>(rc));
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
close(UV_EOF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpsClient::write(const std::string &header)
|
||||
void xmrig::HttpsClient::write(std::string &&data, bool close)
|
||||
{
|
||||
SSL_write(m_ssl, (header + body).c_str(), header.size() + body.size());
|
||||
body.clear();
|
||||
const std::string body = std::move(data);
|
||||
SSL_write(m_ssl, body.data(), body.size());
|
||||
|
||||
flush();
|
||||
flush(close);
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,23 +188,17 @@ bool xmrig::HttpsClient::verifyFingerprint(X509 *cert)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::HttpsClient::flush()
|
||||
void xmrig::HttpsClient::flush(bool close)
|
||||
{
|
||||
uv_buf_t buf;
|
||||
buf.len = BIO_get_mem_data(m_writeBio, &buf.base);
|
||||
|
||||
if (buf.len == 0) {
|
||||
if (uv_is_writable(stream()) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
if (uv_is_writable(stream())) {
|
||||
result = uv_try_write(stream(), &buf, 1) == static_cast<int>(buf.len);
|
||||
char *data = nullptr;
|
||||
const size_t size = BIO_get_mem_data(m_write, &data);
|
||||
std::string body(data, size);
|
||||
|
||||
if (!result) {
|
||||
close(UV_EIO);
|
||||
}
|
||||
}
|
||||
(void) BIO_reset(m_write);
|
||||
|
||||
(void) BIO_reset(m_writeBio);
|
||||
HttpContext::write(std::move(body), close);
|
||||
}
|
|
@ -55,17 +55,17 @@ public:
|
|||
protected:
|
||||
void handshake() override;
|
||||
void read(const char *data, size_t size) override;
|
||||
void write(const std::string &header) override;
|
||||
|
||||
private:
|
||||
void write(std::string &&data, bool close) override;
|
||||
|
||||
bool verify(X509 *cert);
|
||||
bool verifyFingerprint(X509 *cert);
|
||||
void flush();
|
||||
void flush(bool close);
|
||||
|
||||
BIO *m_readBio = nullptr;
|
||||
BIO *m_writeBio = nullptr;
|
||||
BIO *m_read = nullptr;
|
||||
BIO *m_write = nullptr;
|
||||
bool m_ready = false;
|
||||
char m_buf[1024 * 2]{};
|
||||
char m_fingerprint[32 * 2 + 8]{};
|
||||
SSL *m_ssl = nullptr;
|
||||
SSL_CTX *m_ctx = nullptr;
|
99
src/base/net/https/HttpsContext.cpp
Normal file
99
src/base/net/https/HttpsContext.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/https/HttpsContext.h"
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/net/tls/TlsContext.h"
|
||||
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
xmrig::HttpsContext::HttpsContext(TlsContext *tls, const std::weak_ptr<IHttpListener> &listener) :
|
||||
HttpContext(HTTP_REQUEST, listener),
|
||||
ServerTls(tls ? tls->ctx() : nullptr)
|
||||
{
|
||||
if (!tls) {
|
||||
m_mode = TLS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xmrig::HttpsContext::~HttpsContext() = default;
|
||||
|
||||
|
||||
void xmrig::HttpsContext::append(char *data, size_t size)
|
||||
{
|
||||
if (m_mode == TLS_AUTO) {
|
||||
m_mode = isTLS(data, size) ? TLS_ON : TLS_OFF;
|
||||
}
|
||||
|
||||
if (m_mode == TLS_ON) {
|
||||
read(data, size);
|
||||
}
|
||||
else {
|
||||
parse(data, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::HttpsContext::write(BIO *bio)
|
||||
{
|
||||
if (uv_is_writable(stream()) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char *data = nullptr;
|
||||
const size_t size = BIO_get_mem_data(bio, &data);
|
||||
std::string body(data, size);
|
||||
|
||||
(void) BIO_reset(bio);
|
||||
|
||||
HttpContext::write(std::move(body), m_close);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpsContext::parse(char *data, size_t size)
|
||||
{
|
||||
if (HttpContext::parse(data, size) < size) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpsContext::shutdown()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpsContext::write(std::string &&data, bool close)
|
||||
{
|
||||
m_close = close;
|
||||
|
||||
if (m_mode == TLS_ON) {
|
||||
send(data.data(), data.size());
|
||||
}
|
||||
else {
|
||||
HttpContext::write(std::move(data), close);
|
||||
}
|
||||
}
|
73
src/base/net/https/HttpsContext.h
Normal file
73
src/base/net/https/HttpsContext.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTPSCONTEXT_H
|
||||
#define XMRIG_HTTPSCONTEXT_H
|
||||
|
||||
|
||||
using BIO = struct bio_st;
|
||||
using SSL = struct ssl_st;
|
||||
|
||||
|
||||
#include "base/net/http/HttpContext.h"
|
||||
#include "base/net/tls/ServerTls.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class TlsContext;
|
||||
|
||||
|
||||
class HttpsContext : public HttpContext, public ServerTls
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpsContext)
|
||||
|
||||
HttpsContext(TlsContext *tls, const std::weak_ptr<IHttpListener> &listener);
|
||||
~HttpsContext() override;
|
||||
|
||||
void append(char *data, size_t size);
|
||||
|
||||
protected:
|
||||
// ServerTls
|
||||
bool write(BIO *bio) override;
|
||||
void parse(char *data, size_t size) override;
|
||||
void shutdown() override;
|
||||
|
||||
// HttpContext
|
||||
void write(std::string &&data, bool close) override;
|
||||
|
||||
private:
|
||||
enum TlsMode : uint32_t {
|
||||
TLS_AUTO,
|
||||
TLS_OFF,
|
||||
TLS_ON
|
||||
};
|
||||
|
||||
bool m_close = false;
|
||||
TlsMode m_mode = TLS_AUTO;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif // XMRIG_HTTPSCONTEXT_H
|
||||
|
71
src/base/net/https/HttpsServer.cpp
Normal file
71
src/base/net/https/HttpsServer.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "base/net/https/HttpsServer.h"
|
||||
#include "base/net/https/HttpsContext.h"
|
||||
#include "base/net/tls/TlsContext.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
|
||||
|
||||
xmrig::HttpsServer::HttpsServer(const std::shared_ptr<IHttpListener> &listener) :
|
||||
m_listener(listener)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::HttpsServer::~HttpsServer()
|
||||
{
|
||||
HttpContext::closeAll();
|
||||
|
||||
delete m_tls;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::HttpsServer::setTls(const TlsConfig &config)
|
||||
{
|
||||
m_tls = TlsContext::create(config);
|
||||
|
||||
return m_tls != nullptr;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpsServer::onConnection(uv_stream_t *stream, uint16_t)
|
||||
{
|
||||
auto ctx = new HttpsContext(m_tls, m_listener);
|
||||
uv_accept(stream, ctx->stream());
|
||||
|
||||
uv_read_start(ctx->stream(), NetBuffer::onAlloc, onRead);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpsServer::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
||||
{
|
||||
auto ctx = static_cast<HttpsContext*>(stream->data);
|
||||
if (nread >= 0) {
|
||||
ctx->append(buf->base, static_cast<size_t>(nread));
|
||||
}
|
||||
else {
|
||||
ctx->close();
|
||||
}
|
||||
|
||||
NetBuffer::release(buf);
|
||||
}
|
72
src/base/net/https/HttpsServer.h
Normal file
72
src/base/net/https/HttpsServer.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTPSSERVER_H
|
||||
#define XMRIG_HTTPSSERVER_H
|
||||
|
||||
|
||||
using uv_tcp_t = struct uv_tcp_s;
|
||||
|
||||
struct http_parser;
|
||||
struct http_parser_settings;
|
||||
struct uv_buf_t;
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/ITcpServerListener.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IHttpListener;
|
||||
class TlsContext;
|
||||
class TlsConfig;
|
||||
|
||||
|
||||
class HttpsServer : public ITcpServerListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpsServer)
|
||||
|
||||
HttpsServer(const std::shared_ptr<IHttpListener> &listener);
|
||||
~HttpsServer() override;
|
||||
|
||||
bool setTls(const TlsConfig &config);
|
||||
|
||||
protected:
|
||||
void onConnection(uv_stream_t *stream, uint16_t port) override;
|
||||
|
||||
private:
|
||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||
|
||||
std::weak_ptr<IHttpListener> m_listener;
|
||||
TlsContext *m_tls = nullptr;
|
||||
uv_tcp_t *m_tcp = nullptr;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif // XMRIG_HTTPSSERVER_H
|
||||
|
|
@ -38,13 +38,14 @@
|
|||
#endif
|
||||
|
||||
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/json/JsonRequest.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/interfaces/IClientListener.h"
|
||||
#include "base/net/dns/Dns.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/net/stratum/Socks5.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "net/JobResult.h"
|
||||
|
@ -83,6 +84,7 @@ xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
|
|||
m_agent(agent),
|
||||
m_sendBuf(1024)
|
||||
{
|
||||
m_reader.setListener(this);
|
||||
m_key = m_storage.add(this);
|
||||
m_dns = new Dns(this);
|
||||
}
|
||||
|
@ -542,7 +544,7 @@ int xmrig::Client::resolve(const String &host)
|
|||
{
|
||||
setState(HostLookupState);
|
||||
|
||||
m_recvBuf.reset();
|
||||
m_reader.reset();
|
||||
|
||||
if (m_failures == -1) {
|
||||
m_failures = 0;
|
||||
|
@ -837,14 +839,10 @@ void xmrig::Client::ping()
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Client::read(ssize_t nread)
|
||||
void xmrig::Client::read(ssize_t nread, const uv_buf_t *buf)
|
||||
{
|
||||
const auto size = static_cast<size_t>(nread);
|
||||
|
||||
if (nread > 0 && size > m_recvBuf.available()) {
|
||||
nread = UV_ENOBUFS;
|
||||
}
|
||||
|
||||
if (nread < 0) {
|
||||
if (!isQuiet()) {
|
||||
LOG_ERR("[%s] read error: \"%s\"", url(), uv_strerror(static_cast<int>(nread)));
|
||||
|
@ -859,12 +857,8 @@ void xmrig::Client::read(ssize_t nread)
|
|||
return reconnect();
|
||||
}
|
||||
|
||||
m_recvBuf.nread(size);
|
||||
|
||||
if (m_socks5) {
|
||||
if (m_socks5->read(m_recvBuf.base(), m_recvBuf.pos())) {
|
||||
m_recvBuf.reset();
|
||||
}
|
||||
m_socks5->read(buf->base, size);
|
||||
|
||||
if (m_socks5->isReady()) {
|
||||
delete m_socks5;
|
||||
|
@ -886,13 +880,12 @@ void xmrig::Client::read(ssize_t nread)
|
|||
if (isTLS()) {
|
||||
LOG_DEBUG("[%s] TLS received (%d bytes)", url(), static_cast<int>(nread));
|
||||
|
||||
m_tls->read(m_recvBuf.base(), m_recvBuf.pos());
|
||||
m_recvBuf.reset();
|
||||
m_tls->read(buf->base, size);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
m_recvBuf.getline(this);
|
||||
m_reader.parse(buf->base, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -959,23 +952,6 @@ void xmrig::Client::startTimeout()
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Client::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf)
|
||||
{
|
||||
auto client = getClient(handle->data);
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
buf->base = client->m_recvBuf.current();
|
||||
|
||||
# ifdef _WIN32
|
||||
buf->len = static_cast<ULONG>(client->m_recvBuf.available());
|
||||
# else
|
||||
buf->len = client->m_recvBuf.available();
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Client::onClose(uv_handle_t *handle)
|
||||
{
|
||||
auto client = getClient(handle->data);
|
||||
|
@ -1027,17 +1003,19 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status)
|
|||
client->m_stream->data = req->data;
|
||||
client->setState(ConnectedState);
|
||||
|
||||
uv_read_start(client->m_stream, onAllocBuffer, onRead);
|
||||
uv_read_start(client->m_stream, NetBuffer::onAlloc, onRead);
|
||||
delete req;
|
||||
|
||||
client->handshake();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *)
|
||||
void xmrig::Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
||||
{
|
||||
auto client = getClient(stream->data);
|
||||
if (client) {
|
||||
client->read(nread);
|
||||
client->read(nread, buf);
|
||||
}
|
||||
|
||||
NetBuffer::release(buf);
|
||||
}
|
||||
|
|
|
@ -39,10 +39,9 @@
|
|||
#include "base/net/stratum/Job.h"
|
||||
#include "base/net/stratum/Pool.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
#include "base/net/tools/RecvBuf.h"
|
||||
#include "base/net/tools/LineReader.h"
|
||||
#include "base/net/tools/Storage.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
|
||||
|
||||
using BIO = struct bio_st;
|
||||
|
@ -62,7 +61,6 @@ public:
|
|||
|
||||
constexpr static uint64_t kConnectTimeout = 20 * 1000;
|
||||
constexpr static uint64_t kResponseTimeout = 20 * 1000;
|
||||
constexpr static size_t kInputBufferSize = 1024 * 16;
|
||||
constexpr static size_t kMaxSendBufferSize = 1024 * 16;
|
||||
|
||||
Client(int id, const char *agent, IClientListener *listener);
|
||||
|
@ -109,7 +107,7 @@ private:
|
|||
void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error);
|
||||
void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error);
|
||||
void ping();
|
||||
void read(ssize_t nread);
|
||||
void read(ssize_t nread, const uv_buf_t *buf);
|
||||
void reconnect();
|
||||
void setState(SocketState state);
|
||||
void startTimeout();
|
||||
|
@ -119,7 +117,6 @@ private:
|
|||
inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); }
|
||||
template<Extension ext> inline bool has() const noexcept { return m_extensions.test(ext); }
|
||||
|
||||
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||
static void onClose(uv_handle_t *handle);
|
||||
static void onConnect(uv_connect_t *req, int status);
|
||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||
|
@ -128,7 +125,7 @@ private:
|
|||
|
||||
const char *m_agent;
|
||||
Dns *m_dns;
|
||||
RecvBuf<kInputBufferSize> m_recvBuf;
|
||||
LineReader m_reader;
|
||||
Socks5 *m_socks5 = nullptr;
|
||||
std::bitset<EXT_MAX> m_extensions;
|
||||
std::vector<char> m_sendBuf;
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2019 Howard Chu <https://github.com/hyc>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -32,9 +32,9 @@
|
|||
#include <cstdint>
|
||||
|
||||
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
#define XMRIG_NETWORKSTATE_H
|
||||
|
||||
|
||||
#include "base/crypto/Algorithm.h"
|
||||
#include "base/net/stratum/strategies/StrategyProxy.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
|
||||
|
||||
#include <array>
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
#include "base/crypto/Coin.h"
|
||||
#include "base/net/stratum/ProxyUrl.h"
|
||||
#include "crypto/common/Coin.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ void xmrig::Client::Socks5::connect()
|
|||
|
||||
const auto &host = m_client->pool().host();
|
||||
std::vector<uint8_t> buf;
|
||||
sockaddr_storage addr;
|
||||
sockaddr_storage addr{};
|
||||
|
||||
if (isIPv4(host, &addr)) {
|
||||
buf.resize(10);
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -24,12 +24,9 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#include "base/net/stratum/Tls.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/net/stratum/Tls.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
|
||||
|
||||
|
@ -38,12 +35,12 @@
|
|||
#endif
|
||||
|
||||
|
||||
#include <cassert>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
|
||||
xmrig::Client::Tls::Tls(Client *client) :
|
||||
m_ready(false),
|
||||
m_buf(),
|
||||
m_fingerprint(),
|
||||
m_client(client),
|
||||
m_ssl(nullptr)
|
||||
m_client(client)
|
||||
{
|
||||
m_ctx = SSL_CTX_new(SSLv23_method());
|
||||
assert(m_ctx != nullptr);
|
||||
|
@ -52,8 +49,8 @@ xmrig::Client::Tls::Tls(Client *client) :
|
|||
return;
|
||||
}
|
||||
|
||||
m_writeBio = BIO_new(BIO_s_mem());
|
||||
m_readBio = BIO_new(BIO_s_mem());
|
||||
m_write = BIO_new(BIO_s_mem());
|
||||
m_read = BIO_new(BIO_s_mem());
|
||||
SSL_CTX_set_options(m_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
|
||||
}
|
||||
|
||||
|
@ -80,7 +77,7 @@ bool xmrig::Client::Tls::handshake()
|
|||
}
|
||||
|
||||
SSL_set_connect_state(m_ssl);
|
||||
SSL_set_bio(m_ssl, m_readBio, m_writeBio);
|
||||
SSL_set_bio(m_ssl, m_read, m_write);
|
||||
SSL_do_handshake(m_ssl);
|
||||
|
||||
return send();
|
||||
|
@ -109,7 +106,7 @@ const char *xmrig::Client::Tls::version() const
|
|||
|
||||
void xmrig::Client::Tls::read(const char *data, size_t size)
|
||||
{
|
||||
BIO_write(m_readBio, data, size);
|
||||
BIO_write(m_read, data, size);
|
||||
|
||||
if (!SSL_is_init_finished(m_ssl)) {
|
||||
const int rc = SSL_connect(m_ssl);
|
||||
|
@ -133,17 +130,18 @@ void xmrig::Client::Tls::read(const char *data, size_t size)
|
|||
return;
|
||||
}
|
||||
|
||||
static char buf[16384]{};
|
||||
int bytes_read = 0;
|
||||
while ((bytes_read = SSL_read(m_ssl, m_buf, sizeof(m_buf))) > 0) {
|
||||
m_buf[bytes_read - 1] = '\0';
|
||||
m_client->parse(m_buf, static_cast<size_t>(bytes_read));
|
||||
|
||||
while ((bytes_read = SSL_read(m_ssl, buf, sizeof(buf))) > 0) {
|
||||
m_client->m_reader.parse(buf, static_cast<size_t>(bytes_read));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Client::Tls::send()
|
||||
{
|
||||
return m_client->send(m_writeBio);
|
||||
return m_client->send(m_write);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -26,10 +26,14 @@
|
|||
#define XMRIG_CLIENT_TLS_H
|
||||
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
using BIO = struct bio_st;
|
||||
using SSL = struct ssl_st;
|
||||
using SSL_CTX = struct ssl_ctx_st;
|
||||
using X509 = struct x509_st;
|
||||
|
||||
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -38,6 +42,8 @@ namespace xmrig {
|
|||
class Client::Tls
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Tls)
|
||||
|
||||
Tls(Client *client);
|
||||
~Tls();
|
||||
|
||||
|
@ -52,13 +58,12 @@ private:
|
|||
bool verify(X509 *cert);
|
||||
bool verifyFingerprint(X509 *cert);
|
||||
|
||||
BIO *m_readBio;
|
||||
BIO *m_writeBio;
|
||||
bool m_ready;
|
||||
char m_buf[1024 * 2];
|
||||
char m_fingerprint[32 * 2 + 8];
|
||||
BIO *m_read = nullptr;
|
||||
BIO *m_write = nullptr;
|
||||
bool m_ready = false;
|
||||
char m_fingerprint[32 * 2 + 8]{};
|
||||
Client *m_client;
|
||||
SSL *m_ssl;
|
||||
SSL *m_ssl = nullptr;
|
||||
SSL_CTX *m_ctx;
|
||||
};
|
||||
|
||||
|
|
103
src/base/net/tls/ServerTls.cpp
Normal file
103
src/base/net/tls/ServerTls.cpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/tls/ServerTls.h"
|
||||
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
|
||||
xmrig::ServerTls::ServerTls(SSL_CTX *ctx) :
|
||||
m_ctx(ctx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::ServerTls::~ServerTls()
|
||||
{
|
||||
if (m_ssl) {
|
||||
SSL_free(m_ssl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::ServerTls::isTLS(const char *data, size_t size)
|
||||
{
|
||||
static const uint8_t test[3] = { 0x16, 0x03, 0x01 };
|
||||
|
||||
return size >= sizeof(test) && memcmp(data, test, sizeof(test)) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::ServerTls::send(const char *data, size_t size)
|
||||
{
|
||||
SSL_write(m_ssl, data, size);
|
||||
|
||||
return write(m_write);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ServerTls::read(const char *data, size_t size)
|
||||
{
|
||||
if (!m_ssl) {
|
||||
m_ssl = SSL_new(m_ctx);
|
||||
|
||||
m_write = BIO_new(BIO_s_mem());
|
||||
m_read = BIO_new(BIO_s_mem());
|
||||
|
||||
SSL_set_accept_state(m_ssl);
|
||||
SSL_set_bio(m_ssl, m_read, m_write);
|
||||
}
|
||||
|
||||
|
||||
BIO_write(m_read, data, size);
|
||||
|
||||
if (!SSL_is_init_finished(m_ssl)) {
|
||||
const int rc = SSL_do_handshake(m_ssl);
|
||||
|
||||
if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) {
|
||||
write(m_write);
|
||||
} else if (rc == 1) {
|
||||
write(m_write);
|
||||
|
||||
m_ready = true;
|
||||
read();
|
||||
}
|
||||
else {
|
||||
shutdown();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
read();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ServerTls::read()
|
||||
{
|
||||
static char buf[16384]{};
|
||||
|
||||
int bytes_read = 0;
|
||||
while ((bytes_read = SSL_read(m_ssl, buf, sizeof(buf))) > 0) {
|
||||
parse(buf, bytes_read);
|
||||
}
|
||||
}
|
68
src/base/net/tls/ServerTls.h
Normal file
68
src/base/net/tls/ServerTls.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_SERVERTLS_H
|
||||
#define XMRIG_SERVERTLS_H
|
||||
|
||||
|
||||
using BIO = struct bio_st;
|
||||
using SSL = struct ssl_st;
|
||||
using SSL_CTX = struct ssl_ctx_st;
|
||||
|
||||
|
||||
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ServerTls
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(ServerTls)
|
||||
|
||||
ServerTls(SSL_CTX *ctx);
|
||||
virtual ~ServerTls();
|
||||
|
||||
static bool isTLS(const char *data, size_t size);
|
||||
|
||||
bool send(const char *data, size_t size);
|
||||
void read(const char *data, size_t size);
|
||||
|
||||
protected:
|
||||
virtual bool write(BIO *bio) = 0;
|
||||
virtual void parse(char *data, size_t size) = 0;
|
||||
virtual void shutdown() = 0;
|
||||
|
||||
private:
|
||||
void read();
|
||||
|
||||
BIO *m_read = nullptr;
|
||||
BIO *m_write = nullptr;
|
||||
bool m_ready = false;
|
||||
SSL *m_ssl = nullptr;
|
||||
SSL_CTX *m_ctx;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_SERVERTLS_H */
|
200
src/base/net/tls/TlsConfig.cpp
Normal file
200
src/base/net/tls/TlsConfig.cpp
Normal file
|
@ -0,0 +1,200 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* 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>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/tls/TlsConfig.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/tls/TlsGen.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
const char *TlsConfig::kCert = "cert";
|
||||
const char *TlsConfig::kEnabled = "enabled";
|
||||
const char *TlsConfig::kCertKey = "cert_key";
|
||||
const char *TlsConfig::kCiphers = "ciphers";
|
||||
const char *TlsConfig::kCipherSuites = "ciphersuites";
|
||||
const char *TlsConfig::kDhparam = "dhparam";
|
||||
const char *TlsConfig::kGen = "gen";
|
||||
const char *TlsConfig::kProtocols = "protocols";
|
||||
|
||||
static const char *kTLSv1 = "TLSv1";
|
||||
static const char *kTLSv1_1 = "TLSv1.1";
|
||||
static const char *kTLSv1_2 = "TLSv1.2";
|
||||
static const char *kTLSv1_3 = "TLSv1.3";
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
/**
|
||||
* "cert" load TLS certificate chain from file.
|
||||
* "cert_key" load TLS private key from file.
|
||||
* "ciphers" set list of available ciphers (TLSv1.2 and below).
|
||||
* "ciphersuites" set list of available TLSv1.3 ciphersuites.
|
||||
* "dhparam" load DH parameters for DHE ciphers from file.
|
||||
*/
|
||||
xmrig::TlsConfig::TlsConfig(const rapidjson::Value &value)
|
||||
{
|
||||
if (value.IsObject()) {
|
||||
m_enabled = Json::getBool(value, kEnabled, m_enabled);
|
||||
|
||||
setProtocols(Json::getString(value, kProtocols));
|
||||
setCert(Json::getString(value, kCert));
|
||||
setKey(Json::getString(value, kCertKey));
|
||||
setCiphers(Json::getString(value, kCiphers));
|
||||
setCipherSuites(Json::getString(value, kCipherSuites));
|
||||
setDH(Json::getString(value, kDhparam));
|
||||
|
||||
if (m_key.isNull()) {
|
||||
setKey(Json::getString(value, "cert-key"));
|
||||
}
|
||||
|
||||
if (m_enabled && !isValid()) {
|
||||
generate(Json::getString(value, kGen));
|
||||
}
|
||||
}
|
||||
else if (value.IsBool()) {
|
||||
m_enabled = value.GetBool();
|
||||
|
||||
if (m_enabled) {
|
||||
generate();
|
||||
}
|
||||
}
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
else if (value.IsNull()) {
|
||||
generate();
|
||||
}
|
||||
# endif
|
||||
else if (value.IsString()) {
|
||||
generate(value.GetString());
|
||||
}
|
||||
else {
|
||||
m_enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::TlsConfig::generate(const char *commonName)
|
||||
{
|
||||
TlsGen gen;
|
||||
|
||||
try {
|
||||
gen.generate(commonName);
|
||||
}
|
||||
catch (std::exception &ex) {
|
||||
LOG_ERR("%s", ex.what());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
setCert(gen.cert());
|
||||
setKey(gen.certKey());
|
||||
|
||||
m_enabled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::TlsConfig::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
auto &allocator = doc.GetAllocator();
|
||||
Value obj(kObjectType);
|
||||
obj.AddMember(StringRef(kEnabled), m_enabled, allocator);
|
||||
|
||||
if (m_protocols > 0) {
|
||||
std::vector<String> protocols;
|
||||
|
||||
if (m_protocols & TLSv1) {
|
||||
protocols.emplace_back(kTLSv1);
|
||||
}
|
||||
|
||||
if (m_protocols & TLSv1_1) {
|
||||
protocols.emplace_back(kTLSv1_1);
|
||||
}
|
||||
|
||||
if (m_protocols & TLSv1_2) {
|
||||
protocols.emplace_back(kTLSv1_2);
|
||||
}
|
||||
|
||||
if (m_protocols & TLSv1_3) {
|
||||
protocols.emplace_back(kTLSv1_3);
|
||||
}
|
||||
|
||||
obj.AddMember(StringRef(kProtocols), String::join(protocols, ' ').toJSON(doc), allocator);
|
||||
}
|
||||
else {
|
||||
obj.AddMember(StringRef(kProtocols), kNullType, allocator);
|
||||
}
|
||||
|
||||
obj.AddMember(StringRef(kCert), m_cert.toJSON(), allocator);
|
||||
obj.AddMember(StringRef(kCertKey), m_key.toJSON(), allocator);
|
||||
obj.AddMember(StringRef(kCiphers), m_ciphers.toJSON(), allocator);
|
||||
obj.AddMember(StringRef(kCipherSuites), m_cipherSuites.toJSON(), allocator);
|
||||
obj.AddMember(StringRef(kDhparam), m_dhparam.toJSON(), allocator);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::TlsConfig::setProtocols(const char *protocols)
|
||||
{
|
||||
const std::vector<String> vec = String(protocols).split(' ');
|
||||
|
||||
for (const String &value : vec) {
|
||||
if (value == kTLSv1) {
|
||||
m_protocols |= TLSv1;
|
||||
}
|
||||
else if (value == kTLSv1_1) {
|
||||
m_protocols |= TLSv1_1;
|
||||
}
|
||||
else if (value == kTLSv1_2) {
|
||||
m_protocols |= TLSv1_2;
|
||||
}
|
||||
else if (value == kTLSv1_3) {
|
||||
m_protocols |= TLSv1_3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::TlsConfig::setProtocols(const rapidjson::Value &protocols)
|
||||
{
|
||||
m_protocols = 0;
|
||||
|
||||
if (protocols.IsUint()) {
|
||||
return setProtocols(protocols.GetUint());
|
||||
}
|
||||
|
||||
if (protocols.IsString()) {
|
||||
return setProtocols(protocols.GetString());
|
||||
}
|
||||
}
|
92
src/base/net/tls/TlsConfig.h
Normal file
92
src/base/net/tls/TlsConfig.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* 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>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_TLSCONFIG_H
|
||||
#define XMRIG_TLSCONFIG_H
|
||||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class TlsConfig
|
||||
{
|
||||
public:
|
||||
static const char *kCert;
|
||||
static const char *kCertKey;
|
||||
static const char *kCiphers;
|
||||
static const char *kCipherSuites;
|
||||
static const char *kDhparam;
|
||||
static const char *kEnabled;
|
||||
static const char *kGen;
|
||||
static const char *kProtocols;
|
||||
|
||||
enum Versions {
|
||||
TLSv1 = 1,
|
||||
TLSv1_1 = 2,
|
||||
TLSv1_2 = 4,
|
||||
TLSv1_3 = 8
|
||||
};
|
||||
|
||||
TlsConfig() = default;
|
||||
TlsConfig(const rapidjson::Value &object);
|
||||
|
||||
inline bool isEnabled() const { return m_enabled && isValid(); }
|
||||
inline bool isValid() const { return !m_cert.isEmpty() && !m_key.isEmpty(); }
|
||||
inline const char *cert() const { return m_cert.data(); }
|
||||
inline const char *ciphers() const { return m_ciphers.isEmpty() ? nullptr : m_ciphers.data(); }
|
||||
inline const char *cipherSuites() const { return m_cipherSuites.isEmpty() ? nullptr : m_cipherSuites.data(); }
|
||||
inline const char *dhparam() const { return m_dhparam.isEmpty() ? nullptr : m_dhparam.data(); }
|
||||
inline const char *key() const { return m_key.data(); }
|
||||
inline uint32_t protocols() const { return m_protocols; }
|
||||
inline void setCert(const char *cert) { m_cert = cert; }
|
||||
inline void setCiphers(const char *ciphers) { m_ciphers = ciphers; }
|
||||
inline void setCipherSuites(const char *ciphers) { m_cipherSuites = ciphers; }
|
||||
inline void setDH(const char *dhparam) { m_dhparam = dhparam; }
|
||||
inline void setKey(const char *key) { m_key = key; }
|
||||
inline void setProtocols(uint32_t protocols) { m_protocols = protocols; }
|
||||
|
||||
bool generate(const char *commonName = nullptr);
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
void setProtocols(const char *protocols);
|
||||
void setProtocols(const rapidjson::Value &protocols);
|
||||
|
||||
private:
|
||||
bool m_enabled = true;
|
||||
uint32_t m_protocols = 0;
|
||||
String m_cert;
|
||||
String m_ciphers;
|
||||
String m_cipherSuites;
|
||||
String m_dhparam;
|
||||
String m_key;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* XMRIG_TLSCONFIG_H */
|
270
src/base/net/tls/TlsContext.cpp
Normal file
270
src/base/net/tls/TlsContext.cpp
Normal file
|
@ -0,0 +1,270 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* 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>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/tls/TlsContext.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/Env.h"
|
||||
#include "base/net/tls/TlsConfig.h"
|
||||
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
|
||||
// https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes#Compatibility_Layer
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
|
||||
{
|
||||
assert(q == nullptr);
|
||||
|
||||
dh->p = p;
|
||||
dh->g = g;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
// https://wiki.openssl.org/index.php/Diffie-Hellman_parameters
|
||||
static DH *get_dh2048()
|
||||
{
|
||||
static unsigned char dhp_2048[] = {
|
||||
0xB2, 0x91, 0xA7, 0x05, 0x31, 0xCE, 0x12, 0x9D, 0x03, 0x43,
|
||||
0xAF, 0x13, 0xAF, 0x4B, 0x8E, 0x4C, 0x04, 0x13, 0x4F, 0x72,
|
||||
0x00, 0x73, 0x2C, 0x67, 0xC3, 0xE0, 0x50, 0xBF, 0x72, 0x5E,
|
||||
0xBE, 0x45, 0x89, 0x4C, 0x01, 0x45, 0xA6, 0x5E, 0xA7, 0xA8,
|
||||
0xDC, 0x2F, 0x1D, 0x91, 0x2D, 0x58, 0x0D, 0x71, 0x97, 0x3D,
|
||||
0xAE, 0xFE, 0x86, 0x29, 0x37, 0x5F, 0x5E, 0x6D, 0x81, 0x56,
|
||||
0x07, 0x83, 0xF2, 0xF8, 0xEC, 0x4E, 0xF8, 0x7A, 0xEC, 0xEA,
|
||||
0xD9, 0xEA, 0x61, 0x3C, 0xAF, 0x51, 0x30, 0xB7, 0xA7, 0x67,
|
||||
0x3F, 0x59, 0xAD, 0x2E, 0x23, 0x57, 0x64, 0xA2, 0x99, 0x15,
|
||||
0xBD, 0xD9, 0x8D, 0xBA, 0xE6, 0x8F, 0xFB, 0xB3, 0x77, 0x3B,
|
||||
0xE6, 0x5C, 0xC1, 0x03, 0xCF, 0x38, 0xD4, 0xF6, 0x2E, 0x0B,
|
||||
0xF3, 0x20, 0xBE, 0xF0, 0xFC, 0x85, 0xEF, 0x5F, 0xCE, 0x0E,
|
||||
0x42, 0x17, 0x3B, 0x72, 0x43, 0x4C, 0x3A, 0xF5, 0xC8, 0xB4,
|
||||
0x40, 0x52, 0x03, 0x72, 0x9A, 0x2C, 0xA4, 0x23, 0x2A, 0xA2,
|
||||
0x52, 0xA3, 0xC2, 0x76, 0x08, 0x1C, 0x2E, 0x60, 0x44, 0xE4,
|
||||
0x12, 0x5D, 0x80, 0x47, 0x6C, 0x7A, 0x5A, 0x8E, 0x18, 0xC9,
|
||||
0x8C, 0x22, 0xC8, 0x07, 0x75, 0xE2, 0x77, 0x3A, 0x90, 0x2E,
|
||||
0x79, 0xC3, 0xF5, 0x4E, 0x4E, 0xDE, 0x14, 0x29, 0xA4, 0x5B,
|
||||
0x32, 0xCC, 0xE5, 0x05, 0x09, 0x2A, 0xC9, 0x1C, 0xB4, 0x8E,
|
||||
0x99, 0xCF, 0x57, 0xF2, 0x1B, 0x5F, 0x18, 0x89, 0x29, 0xF2,
|
||||
0xB0, 0xF3, 0xAC, 0x67, 0x16, 0x90, 0x4A, 0x1D, 0xD6, 0xF5,
|
||||
0x84, 0x71, 0x1D, 0x0E, 0x61, 0x5F, 0xE2, 0x2D, 0x52, 0x87,
|
||||
0x0D, 0x8F, 0x84, 0xCB, 0xFC, 0xF0, 0x5D, 0x4C, 0x9F, 0x59,
|
||||
0xA9, 0xD6, 0x83, 0x70, 0x4B, 0x98, 0x6A, 0xCA, 0x78, 0x53,
|
||||
0x27, 0x32, 0x59, 0x35, 0x0A, 0xB8, 0x29, 0x18, 0xAF, 0x58,
|
||||
0x45, 0x63, 0xEB, 0x43, 0x28, 0x7B
|
||||
};
|
||||
|
||||
static unsigned char dhg_2048[] = { 0x02 };
|
||||
|
||||
auto dh = DH_new();
|
||||
if (dh == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto p = BN_bin2bn(dhp_2048, sizeof(dhp_2048), nullptr);
|
||||
auto g = BN_bin2bn(dhg_2048, sizeof(dhg_2048), nullptr);
|
||||
|
||||
if (p == nullptr || g == nullptr || !DH_set0_pqg(dh, p, nullptr, g)) {
|
||||
DH_free(dh);
|
||||
BN_free(p);
|
||||
BN_free(g);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return dh;
|
||||
}
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::TlsContext::~TlsContext()
|
||||
{
|
||||
SSL_CTX_free(m_ctx);
|
||||
}
|
||||
|
||||
|
||||
xmrig::TlsContext *xmrig::TlsContext::create(const TlsConfig &config)
|
||||
{
|
||||
if (!config.isEnabled()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto tls = new TlsContext();
|
||||
if (!tls->load(config)) {
|
||||
delete tls;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return tls;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::TlsContext::load(const TlsConfig &config)
|
||||
{
|
||||
m_ctx = SSL_CTX_new(SSLv23_server_method());
|
||||
if (m_ctx == nullptr) {
|
||||
LOG_ERR("Unable to create SSL context");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto cert = Env::expand(config.cert());
|
||||
if (SSL_CTX_use_certificate_chain_file(m_ctx, cert) <= 0) {
|
||||
LOG_ERR("SSL_CTX_use_certificate_chain_file(\"%s\") failed.", config.cert());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto key = Env::expand(config.key());
|
||||
if (SSL_CTX_use_PrivateKey_file(m_ctx, key, SSL_FILETYPE_PEM) <= 0) {
|
||||
LOG_ERR("SSL_CTX_use_PrivateKey_file(\"%s\") failed.", config.key());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SSL_CTX_set_options(m_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
|
||||
SSL_CTX_set_options(m_ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
|
||||
|
||||
# if OPENSSL_VERSION_NUMBER >= 0x1010100fL
|
||||
SSL_CTX_set_max_early_data(m_ctx, 0);
|
||||
# endif
|
||||
|
||||
setProtocols(config.protocols());
|
||||
|
||||
return setCiphers(config.ciphers()) && setCipherSuites(config.cipherSuites()) && setDH(config.dhparam());
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::TlsContext::setCiphers(const char *ciphers)
|
||||
{
|
||||
if (ciphers == nullptr || SSL_CTX_set_cipher_list(m_ctx, ciphers) == 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_ERR("SSL_CTX_set_cipher_list(\"%s\") failed.", ciphers);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::TlsContext::setCipherSuites(const char *ciphersuites)
|
||||
{
|
||||
if (ciphersuites == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
# if OPENSSL_VERSION_NUMBER >= 0x1010100fL
|
||||
if (SSL_CTX_set_ciphersuites(m_ctx, ciphersuites) == 1) {
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
|
||||
LOG_ERR("SSL_CTX_set_ciphersuites(\"%s\") failed.", ciphersuites);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::TlsContext::setDH(const char *dhparam)
|
||||
{
|
||||
DH *dh = nullptr;
|
||||
|
||||
if (dhparam != nullptr) {
|
||||
BIO *bio = BIO_new_file(Env::expand(dhparam), "r");
|
||||
if (bio == nullptr) {
|
||||
LOG_ERR("BIO_new_file(\"%s\") failed.", dhparam);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
dh = PEM_read_bio_DHparams(bio, nullptr, nullptr, nullptr);
|
||||
if (dh == nullptr) {
|
||||
LOG_ERR("PEM_read_bio_DHparams(\"%s\") failed.", dhparam);
|
||||
|
||||
BIO_free(bio);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
}
|
||||
else {
|
||||
dh = get_dh2048();
|
||||
}
|
||||
|
||||
const int rc = SSL_CTX_set_tmp_dh(m_ctx, dh);
|
||||
|
||||
DH_free(dh);
|
||||
|
||||
if (rc == 0) {
|
||||
LOG_ERR("SSL_CTX_set_tmp_dh(\"%s\") failed.", dhparam);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::TlsContext::setProtocols(uint32_t protocols)
|
||||
{
|
||||
if (protocols == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(protocols & TlsConfig::TLSv1)) {
|
||||
SSL_CTX_set_options(m_ctx, SSL_OP_NO_TLSv1);
|
||||
}
|
||||
|
||||
# ifdef SSL_OP_NO_TLSv1_1
|
||||
SSL_CTX_clear_options(m_ctx, SSL_OP_NO_TLSv1_1);
|
||||
if (!(protocols & TlsConfig::TLSv1_1)) {
|
||||
SSL_CTX_set_options(m_ctx, SSL_OP_NO_TLSv1_1);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef SSL_OP_NO_TLSv1_2
|
||||
SSL_CTX_clear_options(m_ctx, SSL_OP_NO_TLSv1_2);
|
||||
if (!(protocols & TlsConfig::TLSv1_2)) {
|
||||
SSL_CTX_set_options(m_ctx, SSL_OP_NO_TLSv1_2);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef SSL_OP_NO_TLSv1_3
|
||||
SSL_CTX_clear_options(m_ctx, SSL_OP_NO_TLSv1_3);
|
||||
if (!(protocols & TlsConfig::TLSv1_3)) {
|
||||
SSL_CTX_set_options(m_ctx, SSL_OP_NO_TLSv1_3);
|
||||
}
|
||||
# endif
|
||||
}
|
71
src/base/net/tls/TlsContext.h
Normal file
71
src/base/net/tls/TlsContext.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* 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>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_TLSCONTEXT_H
|
||||
#define XMRIG_TLSCONTEXT_H
|
||||
|
||||
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
using SSL_CTX = struct ssl_ctx_st;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class TlsConfig;
|
||||
|
||||
|
||||
class TlsContext
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(TlsContext)
|
||||
|
||||
~TlsContext();
|
||||
|
||||
static TlsContext *create(const TlsConfig &config);
|
||||
|
||||
inline SSL_CTX *ctx() const { return m_ctx; }
|
||||
|
||||
private:
|
||||
TlsContext() = default;
|
||||
|
||||
bool load(const TlsConfig &config);
|
||||
bool setCiphers(const char *ciphers);
|
||||
bool setCipherSuites(const char *ciphersuites);
|
||||
bool setDH(const char *dhparam);
|
||||
void setProtocols(uint32_t protocols);
|
||||
|
||||
SSL_CTX *m_ctx = nullptr;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* XMRIG_TLSCONTEXT_H */
|
144
src/base/net/tls/TlsGen.cpp
Normal file
144
src/base/net/tls/TlsGen.cpp
Normal file
|
@ -0,0 +1,144 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/tls/TlsGen.h"
|
||||
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static const char *kLocalhost = "localhost";
|
||||
|
||||
|
||||
static EVP_PKEY *generate_pkey()
|
||||
{
|
||||
auto pkey = EVP_PKEY_new();
|
||||
if (!pkey) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto exponent = BN_new();
|
||||
auto rsa = RSA_new();
|
||||
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);
|
||||
RSA_free(rsa);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BN_free(exponent);
|
||||
|
||||
return pkey;
|
||||
}
|
||||
|
||||
|
||||
bool isFileExist(const char *fileName)
|
||||
{
|
||||
std::ifstream in(fileName);
|
||||
|
||||
return in.good();
|
||||
}
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::TlsGen::~TlsGen()
|
||||
{
|
||||
EVP_PKEY_free(m_pkey);
|
||||
X509_free(m_x509);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::TlsGen::generate(const char *commonName)
|
||||
{
|
||||
if (isFileExist(m_cert) && isFileExist(m_certKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_pkey = generate_pkey();
|
||||
if (!m_pkey) {
|
||||
throw std::runtime_error("RSA key generation failed.");
|
||||
}
|
||||
|
||||
if (!generate_x509(commonName == nullptr || strlen(commonName) == 0 ? kLocalhost : commonName)) {
|
||||
throw std::runtime_error("x509 certificate generation failed.");
|
||||
}
|
||||
|
||||
if (!write()) {
|
||||
throw std::runtime_error("unable to write certificate to disk.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::TlsGen::generate_x509(const char *commonName)
|
||||
{
|
||||
m_x509 = X509_new();
|
||||
if (!m_x509) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!X509_set_pubkey(m_x509, m_pkey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ASN1_INTEGER_set(X509_get_serialNumber(m_x509), 1);
|
||||
X509_gmtime_adj(X509_get_notBefore(m_x509), 0);
|
||||
X509_gmtime_adj(X509_get_notAfter(m_x509), 315360000L);
|
||||
|
||||
auto name = X509_get_subject_name(m_x509);
|
||||
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t *>(commonName), -1, -1, 0);
|
||||
|
||||
X509_set_issuer_name(m_x509, name);
|
||||
|
||||
return X509_sign(m_x509, m_pkey, EVP_sha256());
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::TlsGen::write()
|
||||
{
|
||||
auto pkey_file = fopen(m_certKey, "wb");
|
||||
if (!pkey_file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = PEM_write_PrivateKey(pkey_file, m_pkey, nullptr, nullptr, 0, nullptr, nullptr);
|
||||
fclose(pkey_file);
|
||||
|
||||
if (!ret) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto x509_file = fopen(m_cert, "wb");
|
||||
if (!x509_file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = PEM_write_X509(x509_file, m_x509);
|
||||
fclose(x509_file);
|
||||
|
||||
return ret;
|
||||
}
|
61
src/base/net/tls/TlsGen.h
Normal file
61
src/base/net/tls/TlsGen.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_TLSGEN_H
|
||||
#define XMRIG_TLSGEN_H
|
||||
|
||||
|
||||
#include "base/tools/Object.h"
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
using EVP_PKEY = struct evp_pkey_st;
|
||||
using X509 = struct x509_st;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class TlsGen
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(TlsGen)
|
||||
|
||||
TlsGen() : m_cert("cert.pem"), m_certKey("cert_key.pem") {}
|
||||
~TlsGen();
|
||||
|
||||
inline const String &cert() const { return m_cert; }
|
||||
inline const String &certKey() const { return m_certKey; }
|
||||
|
||||
void generate(const char *commonName = nullptr);
|
||||
|
||||
private:
|
||||
bool generate_x509(const char *commonName);
|
||||
bool write();
|
||||
|
||||
const String m_cert;
|
||||
const String m_certKey;
|
||||
EVP_PKEY *m_pkey = nullptr;
|
||||
X509 *m_x509 = nullptr;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_TLSGEN_H */
|
103
src/base/net/tools/LineReader.cpp
Normal file
103
src/base/net/tools/LineReader.cpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/tools/LineReader.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
#include "base/kernel/interfaces/ILineListener.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
xmrig::LineReader::~LineReader()
|
||||
{
|
||||
NetBuffer::release(m_buf);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::LineReader::parse(char *data, size_t size)
|
||||
{
|
||||
assert(m_listener != nullptr && size > 0);
|
||||
if (!m_listener || size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_buf) {
|
||||
return getline(data, size);
|
||||
}
|
||||
|
||||
add(data, size);
|
||||
getline(m_buf, m_pos);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::LineReader::reset()
|
||||
{
|
||||
if (m_buf) {
|
||||
NetBuffer::release(m_buf);
|
||||
m_buf = nullptr;
|
||||
m_pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::LineReader::add(const char *data, size_t size)
|
||||
{
|
||||
if (size > NetBuffer::kChunkSize - m_pos) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_buf) {
|
||||
m_buf = NetBuffer::allocate();
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
memcpy(m_buf + m_pos, data, size);
|
||||
m_pos += size;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::LineReader::getline(char *data, size_t size)
|
||||
{
|
||||
char *end = nullptr;
|
||||
char *start = data;
|
||||
size_t remaining = size;
|
||||
|
||||
while ((end = static_cast<char*>(memchr(start, '\n', remaining))) != nullptr) {
|
||||
*end = '\0';
|
||||
|
||||
end++;
|
||||
|
||||
const auto len = static_cast<size_t>(end - start);
|
||||
if (len > 1) {
|
||||
m_listener->onLine(start, len - 1);
|
||||
}
|
||||
|
||||
remaining -= len;
|
||||
start = end;
|
||||
}
|
||||
|
||||
if (remaining == 0) {
|
||||
return reset();
|
||||
}
|
||||
|
||||
if (!m_buf || m_buf != data) {
|
||||
add(start, remaining);
|
||||
}
|
||||
}
|
62
src/base/net/tools/LineReader.h
Normal file
62
src/base/net/tools/LineReader.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_LINEREADER_H
|
||||
#define XMRIG_LINEREADER_H
|
||||
|
||||
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ILineListener;
|
||||
|
||||
|
||||
class LineReader
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(LineReader)
|
||||
|
||||
LineReader() = default;
|
||||
LineReader(ILineListener *listener) : m_listener(listener) {}
|
||||
~LineReader();
|
||||
|
||||
inline void setListener(ILineListener *listener) { m_listener = listener; }
|
||||
|
||||
void parse(char *data, size_t size);
|
||||
void reset();
|
||||
|
||||
private:
|
||||
void add(const char *data, size_t size);
|
||||
void getline(char *data, size_t size);
|
||||
|
||||
char *m_buf = nullptr;
|
||||
ILineListener *m_listener = nullptr;
|
||||
size_t m_pos = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_NETBUFFER_H */
|
96
src/base/net/tools/MemPool.h
Normal file
96
src/base/net/tools/MemPool.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_MEMPOOL_H
|
||||
#define XMRIG_MEMPOOL_H
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
template<size_t CHUNK_SIZE, size_t INIT_SIZE>
|
||||
class MemPool
|
||||
{
|
||||
public:
|
||||
MemPool() = default;
|
||||
|
||||
|
||||
constexpr size_t chunkSize() const { return CHUNK_SIZE; }
|
||||
inline size_t freeSize() const { return m_free.size() * CHUNK_SIZE; }
|
||||
inline size_t size() const { return m_data.size() * CHUNK_SIZE * INIT_SIZE; }
|
||||
|
||||
|
||||
inline char *allocate()
|
||||
{
|
||||
if (m_free.empty()) {
|
||||
resize();
|
||||
}
|
||||
|
||||
const size_t i = *m_free.begin();
|
||||
const size_t r = i / INIT_SIZE;
|
||||
|
||||
char *ptr = m_data[r].data() + (i - r * INIT_SIZE) * CHUNK_SIZE;
|
||||
|
||||
m_used.insert({ ptr, i });
|
||||
m_free.erase(i);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
inline void deallocate(const char *ptr)
|
||||
{
|
||||
if (ptr == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(m_used.count(ptr));
|
||||
|
||||
m_free.emplace(m_used[ptr]);
|
||||
m_used.erase(ptr);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
inline void resize()
|
||||
{
|
||||
const size_t index = m_data.size();
|
||||
m_data[index];
|
||||
|
||||
for (size_t i = 0; i < INIT_SIZE; ++i) {
|
||||
m_free.emplace((index * INIT_SIZE) + i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::map<const char *, size_t> m_used;
|
||||
std::map<size_t, std::array<char, CHUNK_SIZE * INIT_SIZE> > m_data;
|
||||
std::set<size_t> m_free;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_MEMPOOL_H */
|
83
src/base/net/tools/NetBuffer.cpp
Normal file
83
src/base/net/tools/NetBuffer.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/tools/MemPool.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
|
||||
|
||||
#include <cassert>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static constexpr size_t kInitSize = 4;
|
||||
static MemPool<NetBuffer::kChunkSize, kInitSize> *pool = nullptr;
|
||||
|
||||
|
||||
inline MemPool<NetBuffer::kChunkSize, kInitSize> *getPool()
|
||||
{
|
||||
if (!pool) {
|
||||
pool = new MemPool<NetBuffer::kChunkSize, kInitSize>();
|
||||
}
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
char *xmrig::NetBuffer::allocate()
|
||||
{
|
||||
return getPool()->allocate();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::NetBuffer::destroy()
|
||||
{
|
||||
if (!pool) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(pool->freeSize() == pool->size());
|
||||
|
||||
delete pool;
|
||||
pool = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::NetBuffer::onAlloc(uv_handle_t *, size_t, uv_buf_t *buf)
|
||||
{
|
||||
buf->base = getPool()->allocate();
|
||||
buf->len = kChunkSize;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::NetBuffer::release(const char *buf)
|
||||
{
|
||||
getPool()->deallocate(buf);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::NetBuffer::release(const uv_buf_t *buf)
|
||||
{
|
||||
getPool()->deallocate(buf->base);
|
||||
}
|
49
src/base/net/tools/NetBuffer.h
Normal file
49
src/base/net/tools/NetBuffer.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_NETBUFFER_H
|
||||
#define XMRIG_NETBUFFER_H
|
||||
|
||||
|
||||
struct uv_buf_t;
|
||||
using uv_handle_t = struct uv_handle_s;
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class NetBuffer
|
||||
{
|
||||
public:
|
||||
static constexpr size_t kChunkSize = 16 * 1024;
|
||||
|
||||
static char *allocate();
|
||||
static void destroy();
|
||||
static void onAlloc(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||
static void release(const char *buf);
|
||||
static void release(const uv_buf_t *buf);
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_NETBUFFER_H */
|
|
@ -1,99 +0,0 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_RECVBUF_H
|
||||
#define XMRIG_RECVBUF_H
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/ILineListener.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
template<size_t N>
|
||||
class RecvBuf
|
||||
{
|
||||
public:
|
||||
inline RecvBuf() :
|
||||
m_buf(),
|
||||
m_pos(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline char *base() { return m_buf; }
|
||||
inline char *current() { return m_buf + m_pos; }
|
||||
inline const char *base() const { return m_buf; }
|
||||
inline const char *current() const { return m_buf + m_pos; }
|
||||
inline size_t available() const { return N - m_pos; }
|
||||
inline size_t pos() const { return m_pos; }
|
||||
inline void nread(size_t size) { m_pos += size; }
|
||||
inline void reset() { m_pos = 0; }
|
||||
|
||||
constexpr inline size_t size() const { return N; }
|
||||
|
||||
inline void getline(ILineListener *listener)
|
||||
{
|
||||
char *end;
|
||||
char *start = m_buf;
|
||||
size_t remaining = m_pos;
|
||||
|
||||
while ((end = static_cast<char*>(memchr(start, '\n', remaining))) != nullptr) {
|
||||
*end = '\0';
|
||||
|
||||
end++;
|
||||
const size_t len = static_cast<size_t>(end - start);
|
||||
|
||||
listener->onLine(start, len - 1);
|
||||
|
||||
remaining -= len;
|
||||
start = end;
|
||||
}
|
||||
|
||||
if (remaining == 0) {
|
||||
m_pos = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (start == m_buf) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(m_buf, start, remaining);
|
||||
m_pos = remaining;
|
||||
}
|
||||
|
||||
private:
|
||||
char m_buf[N];
|
||||
size_t m_pos;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_RECVBUF_H */
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue