From bc9130ded373475aa3d09e22e4007824d6f185f4 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 16 Sep 2018 06:35:49 +0300 Subject: [PATCH] Show TLS version. --- src/Summary.cpp | 6 +++--- src/common/net/Client.cpp | 20 ++++++++++++++++++-- src/common/net/Client.h | 3 ++- src/common/net/Tls.cpp | 30 ++++++++++++++++++------------ src/common/net/Tls.h | 3 ++- src/net/Network.cpp | 5 ++++- 6 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/Summary.cpp b/src/Summary.cpp index 5feb6d7ed..de6b1234c 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -53,18 +53,18 @@ static void print_memory(xmrig::Config *config) { static void print_cpu(xmrig::Config *config) { if (config->isColors()) { - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s (%d) %sx64 %sAES-NI", + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%d)") " %sx64 %sAES", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "\x1B[1;32m" : "\x1B[1;31m-", Cpu::hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%.1f MB/%.1f MB"), "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } else { - Log::i()->text(" * %-13s%s (%d) %sx64 %sAES-NI", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); + Log::i()->text(" * %-13s%s (%d) %sx64 %sAES", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); # ifndef XMRIG_NO_LIBCPUID Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 1057c4742..d789ac896 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -186,9 +186,15 @@ bool Client::disconnect() } -bool Client::isTLS() const +const char *Client::tlsVersion() const { - return m_pool.isTLS() && m_tls; +# ifndef XMRIG_NO_TLS + if (isTLS()) { + return m_tls->tlsVersion(); + } +# endif + + return nullptr; } @@ -277,6 +283,16 @@ bool Client::isCriticalError(const char *message) } +bool Client::isTLS() const +{ +# ifndef XMRIG_NO_TLS + return m_pool.isTLS() && m_tls; +# else + return false; +# endif +} + + bool Client::parseJob(const rapidjson::Value ¶ms, int *code) { if (!params.IsObject()) { diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 893fabfc8..b38798857 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -69,7 +69,7 @@ public: ~Client(); bool disconnect(); - bool isTLS() const; + const char *tlsVersion() const; int64_t submit(const JobResult &result); void connect(); void connect(const Pool &pool); @@ -100,6 +100,7 @@ private: bool close(); bool isCriticalError(const char *message); + bool isTLS() const; bool parseJob(const rapidjson::Value ¶ms, int *code); bool parseLogin(const rapidjson::Value &result, int *code); bool send(BIO *bio); diff --git a/src/common/net/Tls.cpp b/src/common/net/Tls.cpp index 679e5d240..2cfc0e527 100644 --- a/src/common/net/Tls.cpp +++ b/src/common/net/Tls.cpp @@ -33,6 +33,7 @@ Client::Tls::Tls(Client *client) : + m_ready(false), m_buf(), m_client(client), m_ssl(nullptr) @@ -87,26 +88,31 @@ bool Client::Tls::send(const char *data, size_t size) } +const char *Client::Tls::tlsVersion() const +{ + return m_ready ? SSL_get_version(m_ssl) : nullptr; +} + + void Client::Tls::read(const char *data, size_t size) { BIO_write(m_readBio, data, size); if (!SSL_is_init_finished(m_ssl)) { - const int rc = SSL_connect(m_ssl); + const int rc = SSL_connect(m_ssl); - if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) { - send(); - } + if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) { + send(); + } else if (rc == 1) { + if (!verify()) { + LOG_ERR("[%s] TLS certificate verification failed", m_client->m_pool.url()); + m_client->close(); - if (rc == 1) { - if (!verify()) { - LOG_ERR("[%s] TLS certificate verification failed", m_client->m_pool.url()); - m_client->close(); + return; + } - return; - } - - m_client->login(); + m_ready = true; + m_client->login(); } return; diff --git a/src/common/net/Tls.h b/src/common/net/Tls.h index 134742378..ee3b59ef0 100644 --- a/src/common/net/Tls.h +++ b/src/common/net/Tls.h @@ -39,7 +39,7 @@ public: bool handshake(); bool send(const char *data, size_t size); - + const char *tlsVersion() const; void read(const char *data, size_t size); private: @@ -48,6 +48,7 @@ private: BIO *m_readBio; BIO *m_writeBio; + bool m_ready; char m_buf[1024 * 2]; Client *m_client; SSL *m_ssl; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 7293a0ac9..9997f7e71 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -101,7 +101,10 @@ void Network::onActive(IStrategy *strategy, Client *client) m_state.setPool(client->host(), client->port(), client->ip()); - LOG_INFO(isColors() ? "\x1B[01;37muse pool \x1B[01;36m%s:%d \x1B[01;30m%s" : "use pool %s:%d %s", client->host(), client->port(), client->ip()); + const char *tlsVersion = client->tlsVersion(); + LOG_INFO(isColors() ? WHITE_BOLD("use pool ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " \x1B[01;30m%s " + : "use pool %s:%d %s %s", + client->host(), client->port(), tlsVersion ? tlsVersion : "", client->ip()); }