Skip to content

Commit

Permalink
update network service
Browse files Browse the repository at this point in the history
On W10 LTSC 21H2, when downloading apps via msstore, Revision Tool throws CERTIFICATE_VERIFY_FAILED. This aims to workaround the issue by disabling certificate verification.
  • Loading branch information
melo936 committed Jun 8, 2024
1 parent 0adb9b6 commit dfe4b65
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
16 changes: 7 additions & 9 deletions lib/services/msstore_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:dio/dio.dart';
import 'package:process_run/shell_run.dart';
import 'package:revitool/services/network_service.dart';
import 'package:xml/xml.dart' as xml;
import 'package:path/path.dart' as p;
import 'package:revitool/models/ms_store/non_uwp_response.dart';
import 'package:revitool/models/ms_store/search_response.dart';
import 'package:revitool/models/ms_store/packages_info.dart';
Expand Down Expand Up @@ -70,8 +69,6 @@ class MSStoreService {

static var _cookie = "";

static final _dio = Dio();
static final _shell = Shell();
static final _cancelToken = CancelToken();
static final _networkService = NetworkService();
// final RegistryUtilsService = RegistryUtilsService();
Expand Down Expand Up @@ -129,7 +126,7 @@ class MSStoreService {

Future<List<ProductsList>> searchProducts(String query, String ring) async {
//"$_filteredSearchAPI?&Query=$query&FilteredCategories=AllProducts&hl=en-us${systemLanguage.toLowerCase()}&
final response = await _dio.get(
final response = await _networkService.get(
"$_searchAPI?gl=US&hl=en-us&query=$query&mediaType=all&age=all&price=all&category=all&subscription=all",

// https://apps.microsoft.com/api/products/search?gl=GE&hl=en-us&query=xbox&cursor=
Expand All @@ -146,7 +143,7 @@ class MSStoreService {
}

Future<String> _getCookie() async {
final response = await _dio.post(
final response = await _networkService.post(
_fe3Delivery,
data: xml.XmlDocument.parse(_cookieFile.readAsStringSync()),
options: _optionsSoapXML,
Expand All @@ -167,7 +164,7 @@ class MSStoreService {

// When Windows region is set to English (World), the language code isn't compatible with the store API
//"$_storeAPI/products/$id?market=US&locale=en-us&deviceFamily=Windows.Desktop",
final response = await _dio.get(
final response = await _networkService.get(
"$_storeAPI/products/$id?market=US&locale=en-us&deviceFamily=Windows.Desktop",
cancelToken: _cancelToken);
final skus = response.data["Payload"]["Skus"];
Expand All @@ -188,7 +185,7 @@ class MSStoreService {
.replaceAll("{2}", categoryID)
.replaceAll("{3}", ring);

final response = await _dio.post(
final response = await _networkService.post(
_fe3Delivery,
data: cookie2,
options: _optionsSoapXML,
Expand All @@ -206,7 +203,8 @@ class MSStoreService {
}

Future<List<PackagesInfo>> _getNonAppxPackage(String id) async {
final response = await _dio.get("$_storeAPI/packageManifests/$id?Market=US",
final response = await _networkService.get(
"$_storeAPI/packageManifests/$id?Market=US",
cancelToken: _cancelToken);

if (response.statusCode == 200) {
Expand Down Expand Up @@ -316,7 +314,7 @@ class MSStoreService {
.replaceAll("{2}", revision)
.replaceAll("{3}", ring);

final response = await _dio.post("$_fe3Delivery/secured",
final response = await _networkService.post("$_fe3Delivery/secured",
data: httpContent,
options: Options(headers: {
HttpHeaders.contentTypeHeader: "application/soap+xml",
Expand Down
38 changes: 35 additions & 3 deletions lib/services/network_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum ApiEndpoints {
}

class NetworkService {
static final _dio = Dio();
final _dio = Dio();

NetworkService() {
(_dio.httpClientAdapter as IOHttpClientAdapter).createHttpClient = () =>
Expand All @@ -23,6 +23,38 @@ class NetworkService {
(X509Certificate cert, String host, int port) => true;
}

Future<Response<T>> get<T>(
String path, {
Object? data,
Map<String, dynamic>? queryParameters,
Options? options,
CancelToken? cancelToken,
void Function(int, int)? onReceiveProgress,
}) async {
try {
return await _dio.get(path, options: options, cancelToken: cancelToken);
} catch (e) {
throw Exception(
'Failed to connect to $path.\n\nPlease ensure you have an active internet connection and try again.\n\nError: $e');
}
}

Future<Response<T>> post<T>(
final String path, {
final Object? data,
final Map<String, dynamic>? queryParameters,
final Options? options,
final CancelToken? cancelToken,
final ProgressCallback? onReceiveProgress,
}) async {
try {
return await _dio.post(path, data: data, options: options);
} catch (e) {
throw Exception(
'Failed to connect to $path.\n\nPlease ensure you have an active internet connection and try again.\n\nError: $e');
}
}

Future<Map<String, dynamic>> getGHLatestRelease(ApiEndpoints endpoint) async {
try {
final response = await _dio.get(
Expand All @@ -31,7 +63,7 @@ class NetworkService {
return response.data as Map<String, dynamic>;
} catch (e) {
throw Exception(
'Failed to connect to the GitHub API.\n\nPlease ensure you have an active internet connection and try again.');
'Failed to connect to the GitHub API.\n\nPlease ensure you have an active internet connection and try again.\n\nError: $e');
}
}

Expand All @@ -46,7 +78,7 @@ class NetworkService {
return response;
} catch (e) {
throw Exception(
'Failed to download.\n\nPlease ensure you have an active internet connection and try again.');
'Failed to download.\n\nPlease ensure you have an active internet connection and try again.\n\nError: $e');
}
}
}
5 changes: 3 additions & 2 deletions lib/services/win_package_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ class WinPackageService {
RegistryHive.localMachine, cbsPackagesRegPath + key, 'CurrentState')!;

final int? lastError = RegistryUtilsService.readInt(
RegistryHive.localMachine, cbsPackagesRegPath + key, 'lastError');
RegistryHive.localMachine, cbsPackagesRegPath + key, 'LastError');

// installation codes - https://forums.ivanti.com/s/article/Understand-Patch-installation-failure-codes?language=en_US
return currentState != 5 || currentState != 4294967264 || lastError == null;
return (currentState != 5 || currentState != 4294967264) &&
lastError == null;
}

Future<void> downloadPackage(final WinPackageType packageType) async {
Expand Down

0 comments on commit dfe4b65

Please sign in to comment.