Now wait until self signed certs are loaded during init

This commit is contained in:
Ming Ming 2024-06-19 16:17:24 +08:00
parent e573837b7b
commit c576b917e1
2 changed files with 12 additions and 9 deletions

View file

@ -69,7 +69,7 @@ Future<void> init(InitIsolateType isolateType) async {
await _initAccountPrefs(); await _initAccountPrefs();
_initEquatable(); _initEquatable();
if (features.isSupportSelfSignedCert) { if (features.isSupportSelfSignedCert) {
_initSelfSignedCertManager(); await _initSelfSignedCertManager();
} }
await _initDiContainer(isolateType); await _initDiContainer(isolateType);
_initVisibilityDetector(); _initVisibilityDetector();
@ -134,8 +134,13 @@ void _initEquatable() {
EquatableConfig.stringify = false; EquatableConfig.stringify = false;
} }
void _initSelfSignedCertManager() { Future<void> _initSelfSignedCertManager() async {
SelfSignedCertManager().init(); try {
return SelfSignedCertManager().init();
} catch (e, stackTrace) {
_log.shout("[_initSelfSignedCertManager] Failed to load self signed certs",
e, stackTrace);
}
} }
Future<void> _initDiContainer(InitIsolateType isolateType) async { Future<void> _initDiContainer(InitIsolateType isolateType) async {

View file

@ -16,14 +16,12 @@ part 'self_signed_cert_manager.g.dart';
class SelfSignedCertManager { class SelfSignedCertManager {
factory SelfSignedCertManager() => _inst; factory SelfSignedCertManager() => _inst;
SelfSignedCertManager._() { SelfSignedCertManager._();
_readAllCerts().then((infos) {
_whitelist = infos;
});
}
void init() { Future<void> init() async {
HttpOverrides.global = _CustomHttpOverrides(); HttpOverrides.global = _CustomHttpOverrides();
final infos = await _readAllCerts();
_whitelist = infos;
} }
/// Verify [cert] and return if it's registered in the whitelist for [host] /// Verify [cert] and return if it's registered in the whitelist for [host]