From c576b917e1caa39dff3233513741a2ca2bbe87ca Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Wed, 19 Jun 2024 16:17:24 +0800 Subject: [PATCH] Now wait until self signed certs are loaded during init --- app/lib/app_init.dart | 11 ++++++++--- app/lib/mobile/self_signed_cert_manager.dart | 10 ++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/lib/app_init.dart b/app/lib/app_init.dart index eed97956..d1ca85ed 100644 --- a/app/lib/app_init.dart +++ b/app/lib/app_init.dart @@ -69,7 +69,7 @@ Future init(InitIsolateType isolateType) async { await _initAccountPrefs(); _initEquatable(); if (features.isSupportSelfSignedCert) { - _initSelfSignedCertManager(); + await _initSelfSignedCertManager(); } await _initDiContainer(isolateType); _initVisibilityDetector(); @@ -134,8 +134,13 @@ void _initEquatable() { EquatableConfig.stringify = false; } -void _initSelfSignedCertManager() { - SelfSignedCertManager().init(); +Future _initSelfSignedCertManager() async { + try { + return SelfSignedCertManager().init(); + } catch (e, stackTrace) { + _log.shout("[_initSelfSignedCertManager] Failed to load self signed certs", + e, stackTrace); + } } Future _initDiContainer(InitIsolateType isolateType) async { diff --git a/app/lib/mobile/self_signed_cert_manager.dart b/app/lib/mobile/self_signed_cert_manager.dart index ea24cdac..12ce89b3 100644 --- a/app/lib/mobile/self_signed_cert_manager.dart +++ b/app/lib/mobile/self_signed_cert_manager.dart @@ -16,14 +16,12 @@ part 'self_signed_cert_manager.g.dart'; class SelfSignedCertManager { factory SelfSignedCertManager() => _inst; - SelfSignedCertManager._() { - _readAllCerts().then((infos) { - _whitelist = infos; - }); - } + SelfSignedCertManager._(); - void init() { + Future init() async { HttpOverrides.global = _CustomHttpOverrides(); + final infos = await _readAllCerts(); + _whitelist = infos; } /// Verify [cert] and return if it's registered in the whitelist for [host]