Skip to content

Commit c680c9d

Browse files
committed
fix(tor): status check for xmr/wow/zano
1 parent 3b5b82a commit c680c9d

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

cw_core/lib/node.dart

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,14 @@ class Node extends HiveObject with Keyable {
217217
final body = {'jsonrpc': '2.0', 'id': '0', 'method': methodName};
218218

219219
try {
220-
final authenticatingClient = ProxyWrapper().getHttpClient();
221-
authenticatingClient.badCertificateCallback =
222-
((X509Certificate cert, String host, int port) => true);
220+
final client = ProxyWrapper().getHttpIOClient();
223221

224222
final jsonBody = json.encode(body);
225223

226-
final response = await ProxyWrapper().post(
227-
clearnetUri: rpcUri,
224+
final response = await client.post(
225+
rpcUri,
228226
headers: {'Content-Type': 'application/json'},
229227
body: jsonBody,
230-
allowMitmMoneroBypassSSLCheck: true,
231228
);
232229
// Check if we received a 401 Unauthorized response
233230
if (response.statusCode == 401) {
@@ -240,7 +237,7 @@ class Node extends HiveObject with Keyable {
240237
return !(response['offline'] as bool);
241238
}
242239

243-
final responseString = await response.transform(utf8.decoder).join();
240+
final responseString = await response.body;
244241

245242
if ((responseString.contains("400 Bad Request") // Some other generic error
246243
||
@@ -459,11 +456,12 @@ class DaemonRpc {
459456

460457
/// Perform a JSON-RPC call with Digest Authentication.
461458
Future<Map<String, dynamic>> call(String method, Map<String, dynamic> params) async {
459+
final client = ProxyWrapper().getHttpIOClient();
462460
final DigestAuth digestAuth = DigestAuth(username, password);
463461

464462
// Initial request to get the `WWW-Authenticate` header.
465-
final initialResponse = await ProxyWrapper().post(
466-
clearnetUri: Uri.parse(rpcUrl),
463+
final initialResponse = await client.post(
464+
Uri.parse(rpcUrl),
467465
headers: {
468466
'Content-Type': 'application/json',
469467
},
@@ -475,26 +473,25 @@ class DaemonRpc {
475473
}),
476474
);
477475

478-
final authHeader = initialResponse.headers.value('www-authenticate');
479-
final responseString = await initialResponse.transform(utf8.decoder).join();
480-
481-
if (initialResponse.statusCode != 401 || authHeader == null) {
482-
throw Exception('Unexpected response: $responseString');
476+
if (initialResponse.statusCode != 401 ||
477+
!initialResponse.headers.containsKey('www-authenticate')) {
478+
throw Exception('Unexpected response: ${initialResponse.body}');
483479
}
484480

485481
// Extract Digest details from `WWW-Authenticate` header.
486-
digestAuth.initFromAuthorizationHeader(authHeader);
482+
final String authInfo = initialResponse.headers['www-authenticate']!;
483+
digestAuth.initFromAuthorizationHeader(authInfo);
487484

488485
// Create Authorization header for the second request.
489486
String uri = Uri.parse(rpcUrl).path;
490-
String newAuthHeader = digestAuth.getAuthString('POST', uri);
487+
String authHeader = digestAuth.getAuthString('POST', uri);
491488

492489
// Make the authenticated request.
493-
final authenticatedResponse = await ProxyWrapper().post(
494-
clearnetUri: Uri.parse(rpcUrl),
490+
final authenticatedResponse = await client.post(
491+
Uri.parse(rpcUrl),
495492
headers: {
496493
'Content-Type': 'application/json',
497-
'Authorization': newAuthHeader,
494+
'Authorization': authHeader,
498495
},
499496
body: jsonEncode({
500497
'jsonrpc': '2.0',
@@ -505,12 +502,11 @@ class DaemonRpc {
505502
);
506503

507504
if (authenticatedResponse.statusCode != 200) {
508-
final responseString = await authenticatedResponse.transform(utf8.decoder).join();
509-
throw Exception('RPC call failed: $responseString');
505+
throw Exception('RPC call failed: ${authenticatedResponse.body}');
510506
}
511507

512-
final responseString2 = await authenticatedResponse.transform(utf8.decoder).join();
513-
final result = jsonDecode(responseString2) as Map<String, dynamic>;
508+
final Map<String, dynamic> result =
509+
jsonDecode(authenticatedResponse.body) as Map<String, dynamic>;
514510
if (result['error'] != null) {
515511
throw Exception('RPC Error: ${result['error']}');
516512
}

0 commit comments

Comments
 (0)