Files
tatuchat/lib/utils/custom_http_client.dart
Welton Moura 0037b0b9cf
Some checks failed
Main Deploy Workflow / deploy_web (push) Has been cancelled
Main Deploy Workflow / deploy_playstore_internal (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
Initial commit
2026-09-11 15:59:56 -03:00

42 lines
1.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'dart:convert';
import 'dart:io';
import 'package:tatchat/config/isrg_x1.dart';
import 'package:tatchat/config/isrg_x2.dart';
import 'package:tatchat/utils/platform_infos.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
import 'package:http/retry.dart' as retry;
/// Custom HTTP client that adds the ISRG Root certificates used by Let's
/// Encrypt. Older Android versions may not include these roots in their
/// trust store, so we ship them ourselves to ensure TLS connections to
/// Let's Encrypt–signed servers continue to work.
class CustomHttpClient {
static HttpClient customHttpClient() {
final context = SecurityContext.defaultContext;
try {
context.setTrustedCertificatesBytes(utf8.encode(ISRG_X1));
context.setTrustedCertificatesBytes(utf8.encode(ISRG_X2));
} on TlsException catch (e) {
if (e.osError != null &&
e.osError!.message.contains('CERT_ALREADY_IN_HASH_TABLE')) {
} else {
rethrow;
}
}
return HttpClient(context: context);
}
static http.Client createHTTPClient() => retry.RetryClient(
PlatformInfos.isAndroid ? IOClient(customHttpClient()) : http.Client(),
);
}