Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit 6c659c3

Browse files
committedOct 10, 2018
Restores option to disable certificate validation
1 parent eaa8aee commit 6c659c3

File tree

3 files changed

+69
-45
lines changed

3 files changed

+69
-45
lines changed
 

‎ethminer/main.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ class MinerCLI
213213
<< ", log per GPU solutions = " << LOG_PER_GPU;
214214
#ifdef DEV_BUILD
215215
logOptions << ", log connection messages = " << LOG_CONNECT
216-
<< ", log switch delay = " << LOG_SWITCH
217-
<< ", log submit delay = " << LOG_SUBMIT
216+
<< ", log switch delay = " << LOG_SWITCH << ", log submit delay = " << LOG_SUBMIT
218217
<< ", log program flow = " << LOG_PROGRAMFLOW;
219218
#endif
220219
app.add_option("-v,--verbosity", g_logOptions, logOptions.str(), true)
@@ -539,7 +538,16 @@ class MinerCLI
539538
<< " SSL_CERT_FILE - full path to your CA certificates file if elsewhere than "
540539
"/etc/ssl/certs/ca-certificates.crt"
541540
#endif
542-
;
541+
<< endl
542+
<< " SSL_NOVERIFY - set to any value to to disable the verification chain for"
543+
<< endl
544+
<< " certificates. WARNING ! Disabling certificate validation"
545+
<< endl
546+
<< " declines every security implied in connecting to a secured"
547+
<< endl
548+
<< " SSL/TLS remote endpoint."
549+
<< endl
550+
<< " USE AT YOU OWN RISK AND ONLY IF YOU KNOW WHAT YOU'RE DOING";
543551
app.footer(ssHelp.str());
544552

545553
try
@@ -795,9 +803,7 @@ class MinerCLI
795803
&CUDAMiner::instances, [](unsigned _index) { return new CUDAMiner(_index); }};
796804
#endif
797805
Farm::f().setSealers(sealers);
798-
Farm::f().onSolutionFound([&](Solution) {
799-
return false;
800-
});
806+
Farm::f().onSolutionFound([&](Solution) { return false; });
801807

802808
Farm::f().setTStartTStop(m_tstart, m_tstop);
803809

‎libpoolprotocols/stratum/EthStratumClient.cpp

+56-39
Original file line numberDiff line numberDiff line change
@@ -84,48 +84,55 @@ void EthStratumClient::init_socket()
8484
m_io_service, ctx);
8585
m_socket = &m_securesocket->next_layer();
8686

87-
88-
m_securesocket->set_verify_mode(boost::asio::ssl::verify_peer);
89-
90-
#ifdef _WIN32
91-
HCERTSTORE hStore = CertOpenSystemStore(0, "ROOT");
92-
if (hStore == nullptr)
87+
if (getenv("SSL_NOVERIFY"))
9388
{
94-
return;
89+
m_securesocket->set_verify_callback(
90+
boost::bind(&EthStratumClient::fake_certificate_validation, this, _1, _2));
9591
}
96-
97-
X509_STORE* store = X509_STORE_new();
98-
PCCERT_CONTEXT pContext = nullptr;
99-
while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) != nullptr)
92+
else
10093
{
101-
X509* x509 = d2i_X509(
102-
nullptr, (const unsigned char**)&pContext->pbCertEncoded, pContext->cbCertEncoded);
103-
if (x509 != nullptr)
94+
m_securesocket->set_verify_mode(boost::asio::ssl::verify_peer);
95+
96+
#ifdef _WIN32
97+
HCERTSTORE hStore = CertOpenSystemStore(0, "ROOT");
98+
if (hStore == nullptr)
10499
{
105-
X509_STORE_add_cert(store, x509);
106-
X509_free(x509);
100+
return;
101+
}
102+
103+
X509_STORE* store = X509_STORE_new();
104+
PCCERT_CONTEXT pContext = nullptr;
105+
while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) != nullptr)
106+
{
107+
X509* x509 = d2i_X509(nullptr, (const unsigned char**)&pContext->pbCertEncoded,
108+
pContext->cbCertEncoded);
109+
if (x509 != nullptr)
110+
{
111+
X509_STORE_add_cert(store, x509);
112+
X509_free(x509);
113+
}
107114
}
108-
}
109115

110-
CertFreeCertificateContext(pContext);
111-
CertCloseStore(hStore, 0);
116+
CertFreeCertificateContext(pContext);
117+
CertCloseStore(hStore, 0);
112118

113-
SSL_CTX_set_cert_store(ctx.native_handle(), store);
119+
SSL_CTX_set_cert_store(ctx.native_handle(), store);
114120
#else
115-
char* certPath = getenv("SSL_CERT_FILE");
116-
try
117-
{
118-
ctx.load_verify_file(certPath ? certPath : "/etc/ssl/certs/ca-certificates.crt");
119-
}
120-
catch (...)
121-
{
122-
cwarn << "Failed to load ca certificates. Either the file "
123-
"'/etc/ssl/certs/ca-certificates.crt' does not exist";
124-
cwarn << "or the environment variable SSL_CERT_FILE is set to an invalid or "
125-
"inaccessible file.";
126-
cwarn << "It is possible that certificate verification can fail.";
127-
}
121+
char* certPath = getenv("SSL_CERT_FILE");
122+
try
123+
{
124+
ctx.load_verify_file(certPath ? certPath : "/etc/ssl/certs/ca-certificates.crt");
125+
}
126+
catch (...)
127+
{
128+
cwarn << "Failed to load ca certificates. Either the file "
129+
"'/etc/ssl/certs/ca-certificates.crt' does not exist";
130+
cwarn << "or the environment variable SSL_CERT_FILE is set to an invalid or "
131+
"inaccessible file.";
132+
cwarn << "It is possible that certificate verification can fail.";
133+
}
128134
#endif
135+
}
129136
}
130137
else
131138
{
@@ -151,6 +158,14 @@ void EthStratumClient::init_socket()
151158
#endif
152159
}
153160

161+
bool EthStratumClient::fake_certificate_validation(
162+
bool preverified, boost::asio::ssl::verify_context& ctx)
163+
{
164+
(void)preverified;
165+
(void)ctx;
166+
return true;
167+
}
168+
154169
void EthStratumClient::connect()
155170
{
156171
// Prevent unnecessary and potentially dangerous recursion
@@ -417,7 +432,8 @@ void EthStratumClient::workloop_timer_elapsed(const boost::system::error_code& e
417432
if (m_response_pleas_count.load(std::memory_order_relaxed))
418433
{
419434
milliseconds response_delay_ms(0);
420-
steady_clock::time_point m_response_plea_time(m_response_plea_older.load(std::memory_order_relaxed));
435+
steady_clock::time_point m_response_plea_time(
436+
m_response_plea_older.load(std::memory_order_relaxed));
421437

422438
// Check responses while in connection/disconnection phase
423439
if (isPendingState())
@@ -480,7 +496,6 @@ void EthStratumClient::workloop_timer_elapsed(const boost::system::error_code& e
480496
m_io_service.post(
481497
m_io_strand.wrap(boost::bind(&EthStratumClient::disconnect, this)));
482498
}
483-
484499
}
485500

486501
// Check how old is last job received
@@ -560,6 +575,7 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec)
560575
cwarn << "* Root certs are either not installed or not found";
561576
cwarn << "* Pool uses a self-signed certificate";
562577
cwarn << "Possible fixes:";
578+
#ifndef _WIN32
563579
cwarn << "* Make sure the file '/etc/ssl/certs/ca-certificates.crt' exists and "
564580
"is accessible";
565581
cwarn << "* Export the correct path via 'export "
@@ -568,6 +584,7 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec)
568584
cwarn << " On most systems you can install the 'ca-certificates' package";
569585
cwarn << " You can also get the latest file here: "
570586
"https://curl.haxx.se/docs/caextract.html";
587+
#endif
571588
cwarn << "* Disable certificate verification all-together via command-line "
572589
"option.";
573590
}
@@ -747,8 +764,8 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
747764
// _isNotification = false)
748765
string _errReason = ""; // Content of the error reason
749766
string _method = ""; // The method of the notification (or request from pool)
750-
unsigned _id = 0; // This SHOULD be the same id as the request it is responding to (known exception
751-
// is ethermine.org using 999)
767+
unsigned _id = 0; // This SHOULD be the same id as the request it is responding to (known
768+
// exception is ethermine.org using 999)
752769

753770

754771
// Retrieve essential values
@@ -1122,7 +1139,6 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
11221139

11231140
else
11241141
{
1125-
11261142
cnote << "Got response for unknown message id [" << _id << "] Discarding...";
11271143
return;
11281144
}
@@ -1544,7 +1560,8 @@ std::chrono::milliseconds EthStratumClient::dequeue_response_plea()
15441560
{
15451561
using namespace std::chrono;
15461562

1547-
steady_clock::time_point response_plea_time(m_response_plea_older.load(std::memory_order_relaxed));
1563+
steady_clock::time_point response_plea_time(
1564+
m_response_plea_older.load(std::memory_order_relaxed));
15481565
milliseconds response_delay_ms =
15491566
duration_cast<milliseconds>(steady_clock::now() - response_plea_time);
15501567

‎libpoolprotocols/stratum/EthStratumClient.h

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class EthStratumClient : public PoolClient
5656
bool current() { return static_cast<bool>(m_current); }
5757

5858
private:
59+
bool fake_certificate_validation(bool preverified, boost::asio::ssl::verify_context& ctx);
5960
void disconnect_finalize();
6061
void enqueue_response_plea();
6162
std::chrono::milliseconds dequeue_response_plea();

0 commit comments

Comments
 (0)
This repository has been archived.