fix: pass isrg cert to http client
This commit is contained in:
parent
0047fc8fa7
commit
9f1df557df
5 changed files with 95 additions and 28 deletions
30
lib/utils/custom_http_client.dart
Normal file
30
lib/utils/custom_http_client.dart
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/io_client.dart';
|
||||
|
||||
import 'package:fluffychat/config/isrg_x1.dart';
|
||||
|
||||
class CustomHttpClient {
|
||||
static HttpClient customHttpClient(String? cert) {
|
||||
final context = SecurityContext.defaultContext;
|
||||
|
||||
try {
|
||||
if (cert != null) {
|
||||
final bytes = utf8.encode(cert);
|
||||
context.setTrustedCertificatesBytes(bytes);
|
||||
}
|
||||
} 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() => IOClient(customHttpClient(ISRG_X1));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue