@@ -84,48 +84,55 @@ void EthStratumClient::init_socket()
84
84
m_io_service, ctx);
85
85
m_socket = &m_securesocket->next_layer ();
86
86
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" ))
93
88
{
94
- return ;
89
+ m_securesocket->set_verify_callback (
90
+ boost::bind (&EthStratumClient::fake_certificate_validation, this , _1, _2));
95
91
}
96
-
97
- X509_STORE* store = X509_STORE_new ();
98
- PCCERT_CONTEXT pContext = nullptr ;
99
- while ((pContext = CertEnumCertificatesInStore (hStore, pContext)) != nullptr )
92
+ else
100
93
{
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 )
104
99
{
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
+ }
107
114
}
108
- }
109
115
110
- CertFreeCertificateContext (pContext);
111
- CertCloseStore (hStore, 0 );
116
+ CertFreeCertificateContext (pContext);
117
+ CertCloseStore (hStore, 0 );
112
118
113
- SSL_CTX_set_cert_store (ctx.native_handle (), store);
119
+ SSL_CTX_set_cert_store (ctx.native_handle (), store);
114
120
#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
+ }
128
134
#endif
135
+ }
129
136
}
130
137
else
131
138
{
@@ -151,6 +158,14 @@ void EthStratumClient::init_socket()
151
158
#endif
152
159
}
153
160
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
+
154
169
void EthStratumClient::connect ()
155
170
{
156
171
// Prevent unnecessary and potentially dangerous recursion
@@ -417,7 +432,8 @@ void EthStratumClient::workloop_timer_elapsed(const boost::system::error_code& e
417
432
if (m_response_pleas_count.load (std::memory_order_relaxed))
418
433
{
419
434
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));
421
437
422
438
// Check responses while in connection/disconnection phase
423
439
if (isPendingState ())
@@ -480,7 +496,6 @@ void EthStratumClient::workloop_timer_elapsed(const boost::system::error_code& e
480
496
m_io_service.post (
481
497
m_io_strand.wrap (boost::bind (&EthStratumClient::disconnect, this )));
482
498
}
483
-
484
499
}
485
500
486
501
// Check how old is last job received
@@ -560,6 +575,7 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec)
560
575
cwarn << " * Root certs are either not installed or not found" ;
561
576
cwarn << " * Pool uses a self-signed certificate" ;
562
577
cwarn << " Possible fixes:" ;
578
+ #ifndef _WIN32
563
579
cwarn << " * Make sure the file '/etc/ssl/certs/ca-certificates.crt' exists and "
564
580
" is accessible" ;
565
581
cwarn << " * Export the correct path via 'export "
@@ -568,6 +584,7 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec)
568
584
cwarn << " On most systems you can install the 'ca-certificates' package" ;
569
585
cwarn << " You can also get the latest file here: "
570
586
" https://curl.haxx.se/docs/caextract.html" ;
587
+ #endif
571
588
cwarn << " * Disable certificate verification all-together via command-line "
572
589
" option." ;
573
590
}
@@ -747,8 +764,8 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
747
764
// _isNotification = false)
748
765
string _errReason = " " ; // Content of the error reason
749
766
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)
752
769
753
770
754
771
// Retrieve essential values
@@ -1122,7 +1139,6 @@ void EthStratumClient::processResponse(Json::Value& responseObject)
1122
1139
1123
1140
else
1124
1141
{
1125
-
1126
1142
cnote << " Got response for unknown message id [" << _id << " ] Discarding..." ;
1127
1143
return ;
1128
1144
}
@@ -1544,7 +1560,8 @@ std::chrono::milliseconds EthStratumClient::dequeue_response_plea()
1544
1560
{
1545
1561
using namespace std ::chrono;
1546
1562
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));
1548
1565
milliseconds response_delay_ms =
1549
1566
duration_cast<milliseconds>(steady_clock::now () - response_plea_time);
1550
1567
0 commit comments